This is the base class for the components that an entity is composed/aggregated of. More...
#include "CompBase.hpp"
Public Member Functions | |
ComponentBaseT () | |
The constructor. More... | |
ComponentBaseT (const ComponentBaseT &Comp) | |
The copy constructor. More... | |
virtual ComponentBaseT * | Clone () const |
The virtual copy constructor. More... | |
virtual | ~ComponentBaseT () |
The virtual destructor. More... | |
virtual const char * | GetName () const |
Returns the name of this component. More... | |
EntityT * | GetEntity () const |
Returns the parent entity that contains this component, or NULL if this component is currently not a part of any entity. More... | |
TypeSys::VarManT & | GetMemberVars () |
Returns the variable manager that keeps generic references to our member variables, providing a simple kind of "reflection" or "type introspection" feature. More... | |
template<class T > | |
void | SetMember (const char *Name, const T &Value) |
Sets the member variable with the given name to the given value. More... | |
ArrayT< ApproxBaseT * > & | GetInterpolators () |
Returns the interpolators that have been registered with this component. More... | |
bool | InitClientApprox (const char *VarName) |
Registers the member variable with the given name for interpolation over client frames in order to bridge the larger intervals between server frames. More... | |
void | Serialize (cf::Network::OutStreamT &Stream) const |
Writes the current state of this component into the given stream. More... | |
void | Deserialize (cf::Network::InStreamT &Stream, bool IsIniting) |
Reads the state of this component from the given stream, and updates the component accordingly. More... | |
bool | CallLuaMethod (const char *MethodName, int NumExtraArgs, const char *Signature="",...) |
Calls the given Lua method of this component. More... | |
virtual void | UpdateDependencies (EntityT *Entity) |
This method is called whenever something "external" to this component has changed: More... | |
virtual unsigned int | GetEditorColor () const |
Returns a color that the Map Editor can use to render the representation of this component's entity. More... | |
virtual BoundingBox3fT | GetEditorBB () const |
Returns a bounding-box that the Map Editor can use to render the representation of this component's entity and for related hit tests in the 2D and 3D views after mouse clicks. More... | |
virtual BoundingBox3fT | GetCullingBB () const |
This method returns a bounding-box that encloses the visual representation of this component. More... | |
virtual const cf::ClipSys::ClipModelT * | GetClipModel () |
This method returns the clip model of this component, if any. More... | |
virtual void | PreCache () |
Initializes any resources that may be needed on the client or server ahead of time. More... | |
virtual bool | Render (bool FirstPersonView, float LodDist) const |
This method implements the graphical output of this component. More... | |
virtual void | PostRender (bool FirstPersonView) |
This method provides an opportunity for another render pass. More... | |
virtual void | OnPostLoad (bool OnlyStatic) |
This method is called after all entities and their components have been loaded. More... | |
virtual bool | OnInputEvent (const CaKeyboardEventT &KE) |
This method handles keyboard input events. More... | |
virtual bool | OnInputEvent (const CaMouseEventT &ME, float PosX, float PosY) |
This method handles mouse input events. More... | |
void | OnServerFrame (float t) |
Advances the component one frame (one "clock-tick") on the server. More... | |
void | OnClientFrame (float t) |
Advances the component one frame (one "clock-tick") on the client. More... | |
virtual const cf::TypeSys::TypeInfoT * | GetType () const |
![]() | |
unsigned int | GetRefCount () const |
Static Public Member Functions | |
static void * | CreateInstance (const cf::TypeSys::CreateParamsT &Params) |
Static Public Attributes | |
static const cf::TypeSys::TypeInfoT | TypeInfo |
Static Protected Attributes | |
static const luaL_Reg | MethodsList [] |
The list of Lua methods for this class. More... | |
static const char * | DocClass |
static const cf::TypeSys::MethsDocT | DocMethods [] |
static const cf::TypeSys::MethsDocT | DocCallbacks [] |
Additional Inherited Members | |
![]() | |
RefCountedT (const RefCountedT &) | |
RefCountedT & | operator= (const RefCountedT &) |
This is the base class for the components that an entity is composed/aggregated of.
Components are the basic building blocks of an entity: their composition defines the properties, the behaviour, and thus virtually every aspect of the entity.
Components can exist in two invariants:
Stand-alone components typically occur when they're newly instantiated, for example when they are loaded from disk, when they are instantiated in scripts, or when they are kept in the clipboard or managed in the Undo/Redo system of the Map Editor. Newly created, copied or cloned components are initially stand-alone.
A component becomes a part of an entity via the EntityT::AddComponent() method. The entity then knows the component, because it hosts it, and reversely, the component then knows the parent entity that it is a component of.
ComponentBaseT::ComponentBaseT | ( | ) |
The constructor.
The newly created component is initially not a part of any entity.
ComponentBaseT::ComponentBaseT | ( | const ComponentBaseT & | Comp | ) |
The copy constructor.
The newly copied component is initially not a part of any entity, even if the source component was.
Comp | The component to create a copy of. |
|
virtual |
The virtual destructor.
bool ComponentBaseT::CallLuaMethod | ( | const char * | MethodName, |
int | NumExtraArgs, | ||
const char * | Signature = "" , |
||
... | |||
) |
Calls the given Lua method of this component.
This method is analogous to UniScriptStateT::CallMethod(), see there for details.
MethodName | The name of the Lua method to call. |
NumExtraArgs | The number of extra arguments that have been pushed on the stack. |
Signature | See UniScriptStateT::Call() for details. |
|
virtual |
The virtual copy constructor.
Callers can use this method to create a copy of this component without knowing its concrete type. Overrides in derived classes use a covariant return type to facilitate use when the concrete type is known. The newly cloned component is initially not a part of any entity, even if the source component was.
Reimplemented in cf::GameSys::ComponentHumanPlayerT, cf::GameSys::ComponentTransformT, cf::GameSys::ComponentMoverT, MapEditor::CompMapEntityT, cf::GameSys::ComponentPlayerPhysicsT, cf::GameSys::ComponentPointLightT, cf::GameSys::ComponentScriptT, cf::GameSys::ComponentModelT, cf::GameSys::ComponentBasicsT, cf::GameSys::ComponentPhysicsT, cf::GameSys::ComponentCollisionModelT, CompGameEntityT, cf::GameSys::ComponentParticleSystemOldT, cf::GameSys::ComponentPlayerStartT, cf::GameSys::ComponentTargetT, cf::GameSys::ComponentCarriedWeaponT, cf::GameSys::ComponentSoundT, cf::GameSys::ComponentRadiosityLightT, cf::GameSys::ComponentInventoryT, and cf::GameSys::ComponentLightT.
void ComponentBaseT::Deserialize | ( | cf::Network::InStreamT & | Stream, |
bool | IsIniting | ||
) |
Reads the state of this component from the given stream, and updates the component accordingly.
This method is called after the state of the component has been received over the network, has been loaded from disk, has been read from the clipboard, or must be "reset" for the purpose of (re-)prediction. The implementation calls DoDeserialize() that derived classes can override to read their own data, or to run any post-deserialization code.
Stream | The stream to read the state data from. |
IsIniting | Used to indicate that the call is part of the construction / first-time initialization of the component. The implementation will use this to not wrongly process the event counters, interpolation, etc. |
|
inlinevirtual |
This method returns the clip model of this component, if any.
Reimplemented in cf::GameSys::ComponentCollisionModelT, and CompGameEntityT.
|
inlinevirtual |
This method returns a bounding-box that encloses the visual representation of this component.
It is used to determine if the entity is in the view-frustum of a camera, how large a region must be updated in the 2D views of a Map Editor, if the entity is in the potentially-visibility-set (PVS) of another entity, and similar purposes.
The returned bounding-box is in local space, i.e. typically centered around the origin (0, 0, 0). If the component doesn't have a visual representation, the returned bounding-box may be uninitialized (!IsInited()
). Also see EntityT::GetCullingBB() for additional details.
Reimplemented in cf::GameSys::ComponentHumanPlayerT, cf::GameSys::ComponentModelT, cf::GameSys::ComponentPointLightT, and CompGameEntityT.
|
inlinevirtual |
Returns a bounding-box that the Map Editor can use to render the representation of this component's entity and for related hit tests in the 2D and 3D views after mouse clicks.
The Map Editor may use the bounding-box of an entity's first component as returned by this method to render the visual representation of the entity.
Note that the returned bounding-box is often smaller than the bounding-box returned by GetCullingBB(), e.g. for light sources (whose radius and thus their indirect effects on other objects it may not cover), for trees (whose trunk it usually covers, but maybe not their crown), or for models (that, when animated, may break the limits of the static bounding-box).
On the other hand, the returned bounding-box may also be larger than the bounding-box returned by GetCullingBB(), e.g. for models that are not initialized. Such models would be "invisible" in the 2D and 3D views of the Map Editor if we didn't return "dummy" bounding-boxes for them so that users can see and work with them.
The returned bounding-box is in local entity space and is always initialized (IsInited() == true
).
Reimplemented in cf::GameSys::ComponentMoverT, cf::GameSys::ComponentModelT, cf::GameSys::ComponentPlayerStartT, and cf::GameSys::ComponentTargetT.
|
inlinevirtual |
Returns a color that the Map Editor can use to render the representation of this component's entity.
The Map Editor may use the color of an entity's first component as returned by this method to render the visual representation of the entity.
Reimplemented in cf::GameSys::ComponentMoverT, cf::GameSys::ComponentModelT, cf::GameSys::ComponentScriptT, cf::GameSys::ComponentCollisionModelT, cf::GameSys::ComponentParticleSystemOldT, cf::GameSys::ComponentPlayerStartT, cf::GameSys::ComponentTargetT, cf::GameSys::ComponentSoundT, and cf::GameSys::ComponentLightT.
|
inline |
Returns the parent entity that contains this component, or NULL
if this component is currently not a part of any entity.
|
inline |
Returns the interpolators that have been registered with this component.
|
inline |
Returns the variable manager that keeps generic references to our member variables, providing a simple kind of "reflection" or "type introspection" feature.
|
inlinevirtual |
Returns the name of this component.
Reimplemented in cf::GameSys::ComponentHumanPlayerT, cf::GameSys::ComponentTransformT, cf::GameSys::ComponentMoverT, MapEditor::CompMapEntityT, cf::GameSys::ComponentPlayerPhysicsT, cf::GameSys::ComponentPointLightT, cf::GameSys::ComponentScriptT, cf::GameSys::ComponentModelT, cf::GameSys::ComponentBasicsT, cf::GameSys::ComponentPhysicsT, cf::GameSys::ComponentCollisionModelT, CompGameEntityT, cf::GameSys::ComponentParticleSystemOldT, cf::GameSys::ComponentPlayerStartT, cf::GameSys::ComponentTargetT, cf::GameSys::ComponentCarriedWeaponT, cf::GameSys::ComponentSoundT, cf::GameSys::ComponentRadiosityLightT, cf::GameSys::ComponentInventoryT, and cf::GameSys::ComponentLightT.
bool ComponentBaseT::InitClientApprox | ( | const char * | VarName | ) |
Registers the member variable with the given name for interpolation over client frames in order to bridge the larger intervals between server frames.
This method only works with variables whose related type is float
, double
, Vector2fT
, Vector3fT
or Vector3dT
.
void ComponentBaseT::OnClientFrame | ( | float | t | ) |
Advances the component one frame (one "clock-tick") on the client.
It typically updates eye-candy that is not sync'ed over the network. (State that is sync'ed over the network must be updated in OnServerFrame() instead.)
Note that the implementation calls DoClientFrame() that derived classes can override to implement their own custom behaviour.
t | The time in seconds since the last client frame. |
|
inlinevirtual |
This method handles keyboard input events.
KE | Keyboard event instance. |
|
inlinevirtual |
This method handles mouse input events.
ME | Mouse event instance. |
PosX | x-coordinate of the mouse cursor position. |
PosY | y-coordinate of the mouse cursor position. |
|
inlinevirtual |
This method is called after all entities and their components have been loaded.
It is called only once when the static part of world initializatzion is complete, i.e. after the initial values of all entities and their components have been set. Components can override this method in order act / do something / add custom behaviour at that time.
For example, a choice component can use it to set the associated text component to the initial selection, a script component can forward it to the script by calling a related script function, a component that for backwards-compatibility supports reading old variables can convert to new ones, etc.
OnlyStatic | true if only the loading of static data is desired, e.g. when the world is instantiated in the Map Editor, false if also user-defined scripts with custom, initial behaviour should be loaded. Also see WorldT::InitFlagsT::InitFlag_OnlyStatic for related information. |
Reimplemented in cf::GameSys::ComponentScriptT, and cf::GameSys::ComponentCarriedWeaponT.
void ComponentBaseT::OnServerFrame | ( | float | t | ) |
Advances the component one frame (one "clock-tick") on the server.
It typically updates all game-relevant state that is sync'ed over the network to all connected game clients.
Note that the implementation calls DoServerFrame() that derived classes can override to implement their own custom behaviour.
t | The time in seconds since the last server frame. |
|
inlinevirtual |
This method provides an opportunity for another render pass.
Reimplemented in cf::GameSys::ComponentHumanPlayerT.
|
inlinevirtual |
Initializes any resources that may be needed on the client or server ahead of time.
The goal is to avoid in-game disruptions on frame-rate caused by lazily loaded assets.
Reimplemented in cf::GameSys::ComponentCarriedWeaponT.
|
inlinevirtual |
This method implements the graphical output of this component.
FirstPersonView | If the world is rendered from the perspective of this component's entity. |
LodDist | The distance of the viewer entity to this component's entity. |
true
if "something" was rendered, false
otherwise (in this case the Map Editor may choose to render another visual representation of this component's entity). Reimplemented in cf::GameSys::ComponentModelT.
void ComponentBaseT::Serialize | ( | cf::Network::OutStreamT & | Stream | ) | const |
Writes the current state of this component into the given stream.
This method is called to send the state of the component over the network, to save it to disk, or to store it in the clipboard. The implementation calls DoSerialize() that derived classes can override to add their own data.
Stream | The stream to write the state data to. |
|
inline |
Sets the member variable with the given name to the given value.
The purpose of this method is to allow C++ code an easier access to the m_MemberVars
, especially when initializing newly created components (e.g. in the Map Editor). (Alternatively, most derived classes had to provide some SetXY()
methods on their own, and thereby clutter their own public interfaces with quasi unimportant methods, or the user code had to deal cumbersomely with the TypeSys::VarManT instance itself.)
|
virtual |
This method is called whenever something "external" to this component has changed:
Entity | The parent entity that contains this component, or NULL to indicate that this component is removed from the entity that it used to be a part of. |
Reimplemented in cf::GameSys::ComponentPlayerPhysicsT, cf::GameSys::ComponentModelT, cf::GameSys::ComponentPhysicsT, cf::GameSys::ComponentCollisionModelT, and CompGameEntityT.
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
The list of Lua methods for this class.