 |
Entity ID's
In the mangalore SDK there are several ID's around. You can have a hard time using the right ID at the right place so I wrote this small summary of the currently used ID's.
ID's based on properties
The world.db file stores all properties of your entities some of them seem to be identifiers. The field _ID and GUID in your database would seem like usable ID's but most of the time they are not.
_ID
The field _ID is a string and thus absolutely unsuitable as a fast lookup ID and the database just contains redundant data composed of the name of the object and the level in parenthesis the object belongs too. In the mangallore application you will normally not use this field (besides displaying in your level builder).
GUID
The field GUID is a globaly unique identifier based on the microsoft windows guid. It is a true unique identifier and you should not be able to find two guid's in the database looking alike. Having a fact like that around you will be surprised to not being used in mangalore for id lookup. I assume it was just created to distinguish objects in the world.db file. They are not really used in a mangalore based application
ID's based on objects
The ID's one works the most in mangalore as they are also the usable (you will need them to lookup objects) ones are Game::Entity::EntityID and Physics::Entity:Id. They are pure runtime id's and will not be the same between two starts of your application. They are not persisted on load or save of your level.
Game::Entity::EntityId
The entity id can be looked up from a Game::Entity with the method
/// get unique id of entity
EntityId GetUniqueId() const;
|
The entity id is given to the entity on creation by the EntityManager. The EntityManager increments an internal counter for this.
In addition you can get the Game::Entity::EntityId from a Physics::Entity if you are on the physics side with this method
/// get user data
int GetUserData() const;
|
Its documentation is not clear enough in this place as mangalore does not just store used data but the Game::Entity::EntityId as a dirty reference.
Physics::Entity::Id
The physics entity id can be looked up from a Physics::Entity with the method
/// get the entity's unique id
Id GetUniqueId() const;
|
The physics entity id is given to the entity on creation by the PhysicsServer. The PhysicsServer increments an internal counter for this.
So what's the problem?
Physics::Entity keeps a reference to his Game:Entity, you can use it straight out of the box if you are moving around in the physical world and would like to access some of the properties attached to the game entity. The other way round is not that easy. The documentation about entities or id's is not clear in each place. For starters it will be very confusing which id they are really holding in their hand. To give beginners an overview I have summarized the usecases. If you have only the id's you need to use the corresponding manager/server to get the corresponding entity. For game entity id's use the EntityManger, for physics entiy id's use the PhysicsServer.
The easiest way is to get the game entity from a physics entity. Ths is done by retrieving the userdata from the physics entity and feeding the EntityManager to lookup the game entity with this id.
The hard way is to get a physics entity from a game entity. The only place this information is present is in the attached properties of a game entity. Here we get to the drawbacks of named properties, you must know exactly which property has your physics entity reference stored. Mangalore so far has only two possible properties you need to query:
PhysicsProperty and ActorPhysicsProperty
They are both derived from AbstractPhysicsProperty, but only the derived concrete classes are attached as properties. So if you have an entity it is best to query both properties and early out if you find a physics entity.
Code would be as follows:
Lookup of Game::Entities based on collision and Physics::Entity
//physics entity from contact phys ID
Ptr pentity = physicsServer->
FindEntityByUniqueId(CollideContacts[i].GetEntityId());
//game entity
Ptr entity;
//only on a valid physics entity
if(pentity.isvalid())
{
//use physics entity user data to lookup a game entity,
//can be invalid if no entity found for example in the
//case no userdata was set on the physics entity
entity = Managers::EntityManager::Instance()->
FindEntityById(pentity->GetUserData());
}
|
Lookup of Physics::Entity based on Game::Entity
//capital is a Game::Entity loaded or created before
//Here it gets dirty, you can only query properties
//you know in advance possible ones would be PhysicsProperty,
//ActorPhysicsProperty (all derived from AbstractPhysicsroperty
//But that one cannot be attached to an entity ...
if(capital->HasProperty(PhysicsProperty::RTTI))
{
//it has this property so now we retriev it
//from the entiy
PhysicsProperty *p = (PhysicsProperty *)capital->
FindProperty(PhysicsProperty::RTTI);
//now you can get the Physics::Entity::Id by
//lookup via the stored Physics::Entity
excludeSet.AddEntityId(p->GetPhysicsEntity()->
GetUniqueId());
}
else if(capital->HasProperty(ActorPhysicsProperty::RTTI))
{
...
...
}
|
Something missing? Mail to
|
 |
 | 2009-06-01 WoW Importer for Max |
The World of Warcraft tool for 3D Studio has been updated. It now converts model files from WoW Client version 2.x (upto 2.7) and displays correct animations for multi mesh models. The script can be found here.... |
 | 2007-03-07 nGUI explained |
If you ever wanted some more details on the nebula2 nGUI System you can find it in the nGUI System article. |
 | 2006-10-17 Mangalore entity ID's |
If you need information about the mangalore entity ID usage have a look here.. |
 | 2006-08-06 Mangalore Articles |
Added a new section about the mangalore game framework from radonlabs. The section contains some articles about my experience with mangalore. Read more here: |
 | 2006-03-10 Free models |
Finally some free models for the Radonlabs SDK. You can download them here. |
 | 2006-03-10 nmax for radonlabs SDK |
Now you can also use 3D Studio Max for the official nebula radonlabs sdk. You can grab the port here. |
 | 2004-10-29 Quake 2 Interpolator |
The quake 2 interpolator has been updated to work with Nebula2 Grab the source including source for water package here... |
 | 2004-10-29 Water package |
The water algorithms package has been updated to work with Nebula 2. Grab the source including source for MD2 package here... | |
 |