Some of you don't use the entity's user data
It's such an awesome feature!!
Maybe this example will help you
It's an example i pasted together from my code, so don't expect it to work
via copy&paste.
In the ProccessScene function you can call
CPlayer* NewPlayer = new CPlayer (_Entity, _RootEntity);
assuming that _Entity is the currently processed entity and _RootEntity is some
global entity for message handling.
After executing that line, the player has a pointer to it's own CPlayer class instance
as it's entity user data. It can access that user data (CPlayer class) on every callback.
Actually this is why i love Leadwerks
/////////////////////////////////////////////////////////////////////////////
/// This class represents the user data (UD) of the player.
/////////////////////////////////////////////////////////////////////////////
class CPlayer
{
public:
/////////////////////////////////////////////////////////////////////////
/// Do everything needed to get the entity ready.
///
/// \param _Entity The entity the user data corresponds to
/// \param _RootEntity The main entity of the game
/////////////////////////////////////////////////////////////////////////
CPlayer (TEntity _Entity, TEntity _RootEntity)
{
this->Init ();
// Remember the entity, this class belongs to
this->m_Entity = _Entity;
// Remember the game global root entity
this->m_RootEntity = _RootEntity;
// Set this class as the user data of the entity
SetEntityUserData (this->m_Entity, (byte*)this);
// Enable callbacks, which will further control the entity and it's
// behaviour. ENTITYCALLBACK_FREE should always be used, to free
// dynamically allocated memory. Just comment out he ones not needed, or
// leave them as they are.
// Called when the entity is freed for some reason.
SetEntityCallback (this->m_Entity,
(byte*)GECPlayer::CBFree, ENTITYCALLBACK_FREE);
// Called once per frame.
SetEntityCallback (this->m_Entity,
(byte*)GECPlayer::CBUpdate, ENTITYCALLBACK_UPDATE);
// Called whenever the entity moves or rotates.
SetEntityCallback (this->m_Entity,
(byte*)GECPlayer::CBUpdateMatrix, ENTITYCALLBACK_UPDATEMATRIX);
// Called 60 times per second, independent of the framerate.
SetEntityCallback (this->m_Entity,
(byte*)GECPlayer::CBUpdatePhysics, ENTITYCALLBACK_UPDATEPHYSICS);
// Called whenever a collision occurs.
SetEntityCallback (this->m_Entity,
(byte*)GECPlayer::CBCollision, ENTITYCALLBACK_COLLISION);
// Called when the entity Receives a message.
SetEntityCallback (this->m_Entity,
(byte*)GECPlayer::CBMessageReceive, ENTITYCALLBACK_MESSAGERECEIVE);
// Do whatever needed to initialize
}
/////////////////////////////////////////////////////////////////////////
/// Standard destructor.
/////////////////////////////////////////////////////////////////////////
~CPlayer ();
private:
/////////////////////////////////////////////////////////////////////////
/// Called when the entity is freed for some reason.
/////////////////////////////////////////////////////////////////////////
static void _stdcall CBFree (TEntity entity)
{
GECPlayer* pUD = (GECPlayer*)GetEntityUserData (entity);
if (NULL != pUD)
{
delete pUD;
}
}
/////////////////////////////////////////////////////////////////////////
/// Called once per frame.
/////////////////////////////////////////////////////////////////////////
static void _stdcall CBUpdate (TEntity entity)
{
CPlayer* pUD = (CPlayer*)GetEntityUserData (entity);
if (NULL != pUD)
{
}
}
/////////////////////////////////////////////////////////////////////////
/// Called whenever the entity moves or rotates.
/////////////////////////////////////////////////////////////////////////
static void _stdcall CBUpdateMatrix (TEntity entity)
{
CPlayer* pUD = (CPlayer*)GetEntityUserData (entity);
if (NULL != pUD)
{
}
}
/////////////////////////////////////////////////////////////////////////
/// Called 60 times per second, independent of the framerate.
/////////////////////////////////////////////////////////////////////////
static void _stdcall CBUpdatePhysics (TEntity entity)
{
CPlayer* pUD = (CPlayer*)GetEntityUserData (entity);
if (NULL != pUD)
{
}
}
/////////////////////////////////////////////////////////////////////////
/// Called whenever a colision occurs.
/////////////////////////////////////////////////////////////////////////
static void _stdcall CBCollision ( TEntity entity0,
TEntity entity1,
byte* position,
byte* normal,
byte* force,
flt speed )
{
CPlayer* pUD = (CPlayer*)GetEntityUserData (entity0);
if (NULL != pUD)
{
TVec3 VecPosition; memcpy (&VecPosition, position, sizeof (TVec3));
TVec3 VecForce; memcpy (&VecForce, force, sizeof (TVec3));
TVec3 VecNormal; memcpy (&VecNormal, normal, sizeof (TVec3));
}
}
/////////////////////////////////////////////////////////////////////////
/// Called when the entity Receives a message.
/////////////////////////////////////////////////////////////////////////
static void _stdcall CBMessageReceive ( TEntity entity,
char* message,
byte* extra)
{
CPlayer* pUD = (CPlayer*)GetEntityUserData (entity);
if (NULL != pUD)
{
}
}
/////////////////////////////////////////////////////////////////////////
/// Initializes all member variables with default values.
/////////////////////////////////////////////////////////////////////////
void Init ();
/// The entity this user data class belongs to.
TEntity m_Entity;
/// The game global root entity.
TEntity m_RootEntity;
};