Cafu Engine
ComponentBaseT Class Reference

This is the base class for the components that a game entity is composed/aggregated of. More...

Inheritance diagram for ComponentBaseT:

Public Member Functions

any get (string var_name)
 Returns the value of an attribute (a member variable) of this class. More...
 
 set (string var_name, any new_value)
 Sets an attribute (a member variable) of this class to a new value. More...
 
string GetExtraMessage (string var_name)
 Returns the result of VarBaseT::GetExtraMessage() for the given member variable. More...
 
 interpolate (string var_name, number start_value, number end_value, number time)
 Schedules a value for interpolation between a start and end value over a given period of time. More...
 
EntityT GetEntity ()
 Returns the entity that this component is a part of (or nil if the component is currently "stand-alone", not a part of any entity). More...
 
 InitClientApprox (string VarName)
 Registers the given attribute (a member variable) of this class for interpolation over client frames in order to bridge the larger intervals between server frames. More...
 

Event Handlers (Callbacks)

See the Event Handlers (Callbacks) overview page for additional information about the methods in this group.

 OnInit ()
 This method is called for each component of each entity as the last step of initializing a newly loaded map. More...
 
 OnClientFrame (number t)
 This method is called for each component of each entity before the client renders the next frame. More...
 

Detailed Description

This is the base class for the components that a game 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 of this type are never instantiated directly, but always indirectly through one of the derived classes.

Implementing C++ Class:
cf::GameSys::ComponentBaseT

Member Function Documentation

any get ( string  var_name)

Returns the value of an attribute (a member variable) of this class.

The variables of this class are also referred to as "Public Attributes" or "Member Data", and include the variables of the concrete, derived component class as well as those of its base classes. (However, there is currently only one base class, ComponentBaseT, which adds methods such as get() and set(), but adds no additional variables to its derived classes.)

At this time, it is not yet possible to write script code like this:

local w = border_component.Width --// We're working on it, but at this time,
local r, g, b = border_component.Color --// these two lines are not valid code.

but instead, we have to write it like this:

local w = border_component:get("Width")
local r, g, b = border_component:get("Color")
Parameters
var_nameThe name of the variable whose value is to be retrieved.
Returns
The value of the queried variable (possibly a tuple if the value itself is a tuple, see the text above for an example).
EntityT GetEntity ( )

Returns the entity that this component is a part of (or nil if the component is currently "stand-alone", not a part of any entity).

string GetExtraMessage ( string  var_name)

Returns the result of VarBaseT::GetExtraMessage() for the given member variable.

This is currently only used with ComponentModelT components, in order to learn why loading a specific model may have failed:

model_component:set("Name", "Players/Trinity/Trinity.cmdl")
local msg = model_component:GetExtraMessage("Name")
if (msg != "") then
print("There was an error when loading this model: " .. msg)
end
InitClientApprox ( string  VarName)

Registers the given attribute (a member variable) of this class for interpolation over client frames in order to bridge the larger intervals between server frames.

This method only works with variables whose related C++ type is float, double, Vector2fT or Vector3fT, and is typically used with ComponentTransform::Origin and ComponentTransform::Orientation. For example:

Butterfly.Trafo:InitClientApprox("Origin")
Butterfly.Trafo:InitClientApprox("Orientation")
interpolate ( string  var_name,
number  start_value,
number  end_value,
number  time 
)

Schedules a value for interpolation between a start and end value over a given period of time.

Only variables that are floating-point numbers and variables that are tuples whose elements are floating-point numbers can be interpolated. (These are the variables whose underlying C++ type is float, double, Vector2fT or Vector3fT.) For variables that are tuples, you must append one of the suffixes .x, .y, .z to determine the first, second or third element for interpolation. Alternatively, the suffixes .r, .g, .b are more naturally used with color tuples, and work exactly alike.

Example
function ButtonOK:OnMouseEnter()
self:GetComponent("Text"):interpolate("Scale", 0.4, 0.45, 500)
self:GetComponent("Border"):interpolate("Color.r", 0.2, 1.0, 750)
self:GetComponent("Image"):interpolate("Alpha", 1.0, 0.0, 750)
self:GetTransform():interpolate("Pos.y", 10, 220, 700)
end
Parameters
var_nameThe name of the window attribute to interpolate. Also see set() for details.
start_valueThe start value.
end_valueThe end value.
timeThe time in milliseconds to interpolate the variable from start_value to end_value.
OnClientFrame ( number  t)

This method is called for each component of each entity before the client renders the next frame.

The method is a great opportunity to add eye candy effects to a game world that are not synchronized over the network. (Such effects are not necessarily the same for every player and thus must not be relevant for the gameplay.)

As it is called for each component of each entity with the client's framerate, the implementation must be very careful to keep performance implications light.

While the implementation can generally modify any variable of any component, it is important to note that for any such variable, InitClientApprox() should be called (once beforehand). Even if the implementation is not interested in the so activated interpolation, at this time we rely on InitClientApprox() to restore the previous, original value after the client frame has been rendered. The calls to InitClientApprox() make sure that any changes that the implementation of OnClientFrame() made are properly cleaned up so that the next call to OnClientFrame() re-starts with the original, unmodified (but properly predicted and possibly interpolated) values.

OnInit ( )

This method is called for each component of each entity as the last step of initializing a newly loaded map.

set ( string  var_name,
any  new_value 
)

Sets an attribute (a member variable) of this class to a new value.

The variables of this class are also referred to as "Public Attributes" or "Member Data", and include the variables of the concrete, derived component class as well as those of its base classes. (However, there is currently only one base class, ComponentBaseT, which adds methods such as get() and set(), but adds no additional variables to its derived classes.)

At this time, it is not yet possible to write script code like this:

border_component.Width = w --// We're working on it, but at this time,
border_component.Color = r, g, b --// these two lines are not valid code.

but instead, we have to write it like this:

border_component:set("Width", w)
border_component:set("Color", r, g, b)
Parameters
var_nameThe name of the variable whose value is to be set.
new_valueThe new value that is assigned to the variable. Note that this can be a tuple if the value itself is a tuple as shown in the example above.