Hello
I revised some code to create a GameObject component so it can hold a object lifetime, creation date/time, and additional information once added.
The question, I have is how do test the time between the creation time and the lifetime, based on Urho3d built in timers. I was thinking in the main Postupdate event. It can loop through the nodes and test for a object lifetime.
/// Base code
GameObject::GameObject(Context* context) :
LogicComponent(context),
GameObjectType(0),
GameObjectLifetime(0),
GameObjectLifetimeCreated(0)
{
/// Only the physics update event is needed: unsubscribe from the rest for optimization
SetUpdateEventMask(USE_FIXEDUPDATE);
}
Part of the code for the GameObject
[code]/// Registering a object
void GameObject::RegisterObject(Context* context)
{
context->RegisterFactory();
/// These macros register the class attributes to the Context for automatic load / save handling.
// We specify the Default attribute mode which means it will be used both for saving into file, and network replication
ATTRIBUTE(GameObject, VAR_INT, "Game Object Type", GameObjectType, 0, AM_DEFAULT);
ATTRIBUTE(GameObject, VAR_INT, "Game Lifetime", GameObjectLifetime, 0, AM_DEFAULT);
ATTRIBUTE(GameObject, VAR_INT, "Game Lifetime Created", GameObjectLifetimeCreated, 0, AM_DEFAULT);
return;[/code]
}
Code I can probably move to test lifetime in a eventupdate of either the individual object or the whole scene which I prefer.
[code]/// Get node list
PODVector <Node *> NodesVector;
scene_ -> GetChildren (NodesVector, true);
/// Set necessary objects
Node * OrphanNode;
String Nodename;
/// loop nodes
for(int i=0; i < NodesVector.Size(); i++)
{
/// Do nothing like copy the node vector to a node
OrphanNode = NodesVector[i];
/// Add a component
GameObject * OrphanNodeGameObject = OrphanNode-> CreateComponent <GameObject>();
OrphanNodeGameObject -> SetLifetime(0);
}[/code]
Vivienne