Cafu Engine
cf::GameSys::ComponentHumanPlayerT Class Reference

Entities with this component are associated with a client connection at whose ends is a human player who provides input to control the entity. More...

#include "CompHumanPlayer.hpp"

Inheritance diagram for cf::GameSys::ComponentHumanPlayerT:

Public Member Functions

 ComponentHumanPlayerT ()
 The constructor. More...
 
 ComponentHumanPlayerT (const ComponentHumanPlayerT &Comp)
 The copy constructor. More...
 
 ~ComponentHumanPlayerT ()
 The destructor. More...
 
ArrayT< PlayerCommandT > & GetPlayerCommands ()
 A temporary method for compatibility with old code. More...
 
Vector3dT GetPlayerVelocity () const
 Returns the player's current velocity (as learned from its PlayerPhysics component). More...
 
Vector3dT GetCameraOriginWS () const
 Returns the origin of the entity's camera, in world-space. More...
 
Vector3dT GetCameraViewDirWS (double Random=0.0) const
 Returns the view (forward) vector of the entity's camera, in world space, optionally deviated by some random amount. More...
 
bool TraceCameraRay (const Vector3dT &Dir, Vector3dT &HitPoint, ComponentBaseT *&HitComp) const
 Traces a ray that originates at the player camera's origin in the given direction through the world. More...
 
void CheckGUIs (bool ThinkingOnServerSide, bool HaveButtonClick) const
 A helper function for Think(). More...
 
void Think (const PlayerCommandT &PlayerCommand, bool ThinkingOnServerSide)
 A helper method (that does the actual work) for DoServerFrame() and the (re-)prediction in the client. More...
 
IntrusivePtrT
< ComponentCarriedWeaponT
GetActiveWeapon () const
 Returns the ComponentCarriedWeaponT component of the currently active weapon, or NULL if currently no weapon is active. More...
 
void SelectWeapon (uint8_t NextWeaponNr, bool Force=false)
 This method initiates the holstering of the currently active weapon and the subsequent drawing of the given weapon. More...
 
void SelectNextWeapon ()
 This method draws the next weapon as previously prepared by SelectWeapon(). More...
 
unsigned int GetRandom (unsigned int n)
 Returns a pseudo-random integer in range `0 ... More...
 
double GetRandom ()
 Returns a pseudo-random double in range [0.0, 1.0] (inclusive). More...
 
ComponentHumanPlayerTClone () const override
 The virtual copy constructor. More...
 
const char * GetName () const override
 Returns the name of this component. More...
 
BoundingBox3fT GetCullingBB () const override
 This method returns a bounding-box that encloses the visual representation of this component. More...
 
void PostRender (bool FirstPersonView) override
 This method provides an opportunity for another render pass. More...
 
void DoServerFrame (float t) override
 Derived classes override this method in order to implement the real work proposed by OnServerFrame(), which explicitly calls this method for this purpose. More...
 
void DoClientFrame (float t) override
 Derived classes override this method in order to implement the real work proposed by OnClientFrame(), which explicitly calls this method for this purpose. More...
 
const cf::TypeSys::TypeInfoTGetType () const override
 
- Public Member Functions inherited from cf::GameSys::ComponentBaseT
 ComponentBaseT ()
 The constructor. More...
 
 ComponentBaseT (const ComponentBaseT &Comp)
 The copy constructor. More...
 
virtual ~ComponentBaseT ()
 The virtual destructor. More...
 
EntityTGetEntity () const
 Returns the parent entity that contains this component, or NULL if this component is currently not a part of any entity. More...
 
TypeSys::VarManTGetMemberVars ()
 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 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 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...
 
- Public Member Functions inherited from RefCountedT
unsigned int GetRefCount () const
 

Static Public Member Functions

static void * CreateInstance (const cf::TypeSys::CreateParamsT &Params)
 
- Static Public Member Functions inherited from cf::GameSys::ComponentBaseT
static void * CreateInstance (const cf::TypeSys::CreateParamsT &Params)
 

Static Public Attributes

static const cf::TypeSys::TypeInfoT TypeInfo
 
- Static Public Attributes inherited from cf::GameSys::ComponentBaseT
static const cf::TypeSys::TypeInfoT TypeInfo
 

Static Protected Member Functions

static int GetActiveWeapon (lua_State *LuaState)
 
static int SelectWeapon (lua_State *LuaState)
 
static int SelectNextWeapon (lua_State *LuaState)
 
static int FireRay (lua_State *LuaState)
 
static int GetRandom (lua_State *LuaState)
 
static int SpawnWeaponChild (lua_State *LuaState)
 
static int RegisterParticle (lua_State *LuaState)
 
static int toString (lua_State *LuaState)
 
- Static Protected Member Functions inherited from cf::GameSys::ComponentBaseT
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)
 

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::VarsDocT DocVars []
 
- Static Protected Attributes inherited from cf::GameSys::ComponentBaseT
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

- Protected Member Functions inherited from RefCountedT
 RefCountedT (const RefCountedT &)
 
RefCountedToperator= (const RefCountedT &)
 

Detailed Description

Entities with this component are associated with a client connection at whose ends is a human player who provides input to control the entity.

Constructor & Destructor Documentation

ComponentHumanPlayerT::ComponentHumanPlayerT ( )

The constructor.

ComponentHumanPlayerT::ComponentHumanPlayerT ( const ComponentHumanPlayerT Comp)

The copy constructor.

Parameters
CompThe component to create a copy of.
ComponentHumanPlayerT::~ComponentHumanPlayerT ( )

The destructor.

Member Function Documentation

void ComponentHumanPlayerT::CheckGUIs ( bool  ThinkingOnServerSide,
bool  HaveButtonClick 
) const

A helper function for Think().

ComponentHumanPlayerT * ComponentHumanPlayerT::Clone ( ) const
overridevirtual

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 from cf::GameSys::ComponentBaseT.

void ComponentHumanPlayerT::DoClientFrame ( float  t)
overridevirtual

Derived classes override this method in order to implement the real work proposed by OnClientFrame(), which explicitly calls this method for this purpose.

(This follows the "Non-Virtual Interface Idiom" as described by Scott Meyers in "Effective C++, 3rd Edition", item 35 ("Consider alternatives to virtual functions.").)

Reimplemented from cf::GameSys::ComponentBaseT.

void ComponentHumanPlayerT::DoServerFrame ( float  t)
overridevirtual

Derived classes override this method in order to implement the real work proposed by OnServerFrame(), which explicitly calls this method for this purpose.

(This follows the "Non-Virtual Interface Idiom" as described by Scott Meyers in "Effective C++, 3rd Edition", item 35 ("Consider alternatives to virtual functions.").)

Reimplemented from cf::GameSys::ComponentBaseT.

IntrusivePtrT< ComponentCarriedWeaponT > ComponentHumanPlayerT::GetActiveWeapon ( ) const

Returns the ComponentCarriedWeaponT component of the currently active weapon, or NULL if currently no weapon is active.

Vector3dT ComponentHumanPlayerT::GetCameraOriginWS ( ) const

Returns the origin of the entity's camera, in world-space.

Vector3dT ComponentHumanPlayerT::GetCameraViewDirWS ( double  Random = 0.0) const

Returns the view (forward) vector of the entity's camera, in world space, optionally deviated by some random amount.

BoundingBox3fT ComponentHumanPlayerT::GetCullingBB ( ) const
overridevirtual

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 from cf::GameSys::ComponentBaseT.

const char* cf::GameSys::ComponentHumanPlayerT::GetName ( ) const
inlineoverridevirtual

Returns the name of this component.

Reimplemented from cf::GameSys::ComponentBaseT.

ArrayT<PlayerCommandT>& cf::GameSys::ComponentHumanPlayerT::GetPlayerCommands ( )
inline

A temporary method for compatibility with old code.

Vector3dT ComponentHumanPlayerT::GetPlayerVelocity ( ) const

Returns the player's current velocity (as learned from its PlayerPhysics component).

unsigned int ComponentHumanPlayerT::GetRandom ( unsigned int  n)

Returns a pseudo-random integer in range `0 ...

n-1`.

The important aspect of this method is that it returns pseudo-random numbers that are reproducible in the context of the "client prediction" feature of the Cafu Engine. All random numbers that are used in human player code must be obtained from one of the GetRandom() methods in this class.

double ComponentHumanPlayerT::GetRandom ( )

Returns a pseudo-random double in range [0.0, 1.0] (inclusive).

The important aspect of this method is that it returns pseudo-random numbers that are reproducible in the context of the "client prediction" feature of the Cafu Engine. All random numbers that are used in human player code must be obtained from one of the GetRandom() methods in this class.

void ComponentHumanPlayerT::PostRender ( bool  FirstPersonView)
overridevirtual

This method provides an opportunity for another render pass.

Reimplemented from cf::GameSys::ComponentBaseT.

void ComponentHumanPlayerT::SelectNextWeapon ( )

This method draws the next weapon as previously prepared by SelectWeapon().

It is intended to be called at the end of the holstering sequence of the previous weapon, either directly from SelectWeapon() when it found that holstering can entirely be skipped, or indirectly when SelectWeapon() calls the previous weapon's Holster() callback, the end of the holster sequence is detected in the OnSequenceWrap_Sv() script callback, and its implementation in turn calls this method.

void ComponentHumanPlayerT::SelectWeapon ( uint8_t  NextWeaponNr,
bool  Force = false 
)

This method initiates the holstering of the currently active weapon and the subsequent drawing of the given weapon.

If the current weapon is none, unknown or not available to the player (e.g. because it has never been picked up), or if it turns out that the weapon does not support holstering (e.g. because there is no holstering sequence available), the holstering is skipped and the next weapon is drawn immediately. If the current weapon is fine but is not idle at the time that this method is called (e.g. reloading or firing), the call is ignored, that is, the weapon is not changed.

Parameters
NextWeaponNrThe index number into the CarriedWeapon components of this entity, starting at 1. Use 0 to select "no" weapon.
ForceIf true, forces the drawing of the next weapon immediately, ignoring the idle state and holstering sequence of the current weapon. This is normally only used if, for example, the last hand grenade has been thrown and bare-handed animation sequences for idle and holster are not available.
void ComponentHumanPlayerT::Think ( const PlayerCommandT PlayerCommand,
bool  ThinkingOnServerSide 
)

A helper method (that does the actual work) for DoServerFrame() and the (re-)prediction in the client.

bool ComponentHumanPlayerT::TraceCameraRay ( const Vector3dT Dir,
Vector3dT HitPoint,
ComponentBaseT *&  HitComp 
) const

Traces a ray that originates at the player camera's origin in the given direction through the world.

Member Data Documentation

const char * ComponentHumanPlayerT::DocClass
staticprotected
Initial value:
=
"Entities with this component are associated with a client connection\n"
"at whose end is a human player who provides input to control the entity."
const cf::TypeSys::MethsDocT ComponentHumanPlayerT::DocMethods
staticprotected
Initial value:
=
{
META_GetActiveWeapon,
META_SelectWeapon,
META_SelectNextWeapon,
META_FireRay,
META_GetRandom,
META_SpawnWeaponChild,
META_RegisterParticle,
META_toString,
{ NULL, NULL, NULL, NULL }
}
const cf::TypeSys::VarsDocT ComponentHumanPlayerT::DocVars
staticprotected
Initial value:
=
{
{ "PlayerName", "The name that the player chose for himself." },
{ "RandomCount", "Keeps track of the next random number that is returned by the GetRandom() method." },
{ "State", "For the player's main state machine, e.g. spectator, dead, alive, ..." },
{ "Health", "Health." },
{ "Armor", "Armor." },
{ "Frags", "Frags." },
{ "ActiveWeaponNr", "The index number into the CarriedWeapon components of this entity, starting at 1, indicating the currently active weapon. The weapon must also be available (have been picked up) before the player can use it. A value of 0 means that \"no\" weapon is currently active." },
{ "NextWeaponNr", "The next weapon to be drawn by SelectNextWeapon(). Like ActiveWeaponNr, this is an index number into the CarriedWeapon components of this entity, starting at 1. A value of 0 means \"none\"." },
{ "HeadSway", "The progress of one \"head swaying\" cycle in state FrozenSpectator." },
{ NULL, NULL }
}
const luaL_Reg ComponentHumanPlayerT::MethodsList
staticprotected
Initial value:
=
{
{ "GetActiveWeapon", GetActiveWeapon },
{ "SelectWeapon", SelectWeapon },
{ "SelectNextWeapon", SelectNextWeapon },
{ "FireRay", FireRay },
{ "GetRandom", GetRandom },
{ "SpawnWeaponChild", SpawnWeaponChild },
{ "RegisterParticle", RegisterParticle },
{ "__tostring", toString },
{ NULL, NULL }
}

The list of Lua methods for this class.


The documentation for this class was generated from the following files: