This component runs custom Lua script code, implementing the behaviour of the entity in the game world.
More...
|
| ComponentScriptT () |
| The constructor. More...
|
|
| ComponentScriptT (const ComponentScriptT &Comp) |
| The copy constructor. More...
|
|
void | PostEvent (unsigned int EventType) |
| This function is used for posting an event of the given type. More...
|
|
ComponentScriptT * | Clone () const |
| The virtual copy constructor. More...
|
|
const char * | GetName () const |
| Returns the name of this component. More...
|
|
unsigned int | GetEditorColor () const |
| Returns a color that the Map Editor can use to render the representation of this component's entity. More...
|
|
void | OnPostLoad (bool OnlyStatic) |
| This method is called after all entities and their components have been loaded. More...
|
|
const cf::TypeSys::TypeInfoT * | GetType () const |
|
| ComponentBaseT () |
| The constructor. More...
|
|
| ComponentBaseT (const ComponentBaseT &Comp) |
| The copy constructor. More...
|
|
virtual | ~ComponentBaseT () |
| The virtual destructor. 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 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 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...
|
|
unsigned int | GetRefCount () const |
|
|
static int | InitEventTypes (lua_State *LuaState) |
|
static int | PostEvent (lua_State *LuaState) |
|
static int | DamageAll (lua_State *LuaState) |
|
static int | toString (lua_State *LuaState) |
|
static int | Get (lua_State *LuaState) |
|
static int | Set (lua_State *LuaState) |
|
static int | GetExtraMessage (lua_State *LuaState) |
|
static int | Interpolate (lua_State *LuaState) |
|
static int | GetEntity (lua_State *LuaState) |
|
static int | InitClientApprox (lua_State *LuaState) |
|
static int | toString (lua_State *LuaState) |
|
This component runs custom Lua script code, implementing the behaviour of the entity in the game world.
The script code can be loaded from a separate file, or it can be entered and kept directly in the component.
Keeping the script code in a separate file is useful when it is re-used with several entity instances or in several maps. Keeping the script code directly in the component is useful for short scripts that are unique to a single map and entity instance. Note that both options can also be combined: The script code from a file is loaded first, and immediate code can be used to augment it (for example to "configure" it).
void ComponentScriptT::OnPostLoad |
( |
bool |
OnlyStatic | ) |
|
|
virtual |
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.
- Parameters
-
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 from cf::GameSys::ComponentBaseT.
void ComponentScriptT::PostEvent |
( |
unsigned int |
EventType | ) |
|
This function is used for posting an event of the given type.
It's the twin of PostEvent(lua_State* LuaState)
below, but allows also C++ code to post events. It is assumed that in the script (e.g. "HumanPlayer.lua"), script method InitEventTypes() has been called.
The event is automatically sent from the entity instance on the server to the entity instances on the clients, and causes a matching call to the ProcessEvent() callback there. The meaning of the event type is up to the script code that implements ProcessEvent(). Note that events are fully predictable: they work well even in the presence of client prediction.