About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
[RESOLVED] Static Objects unique ID
Author Message
aceio76 Offline
Silver Supporter

Post: #1
[RESOLVED] Static Objects unique ID
Risking a silly question, but I did look at the Obj code, worldmanager code and Item code, but when an object is placed in the WE (static obj type for example), does the engine give that object a unique ID of sorts? Is there any control to how a specific obj type is loaded into the game world (ie, order from first placed in the world to last, etc)? I'd like to be able to give objects of interest a unique ID, and currently, I can see only putting a param on each object and manually incrementing the id. This can get very hard to manage manually if you have hundreds of objects of interest scattered in the world and you have to manually increment the ID count per new object.

This might be a question pointed at the world editor and having an auto-increment param of sorts...

Any thoughts?

www.thinkplaystudios.com
(This post was last modified: 10-03-2011 05:06 AM by aceio76.)
09-26-2011 04:55 AM
Visit this user's website Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #2
RE: Static Objects unique ID
So there is a randomly generated UID for when the object is created, and this object is what's used for the savegame and loadgame.

Does anyone know if this UID is re-generated at each start if the object is not loaded from a saved game? I can't seem to find where or when exactly this ID is created, whether if its during object placement through the WE or when the object is created the first time it is loaded from the world file during game time.

www.thinkplaystudios.com
09-27-2011 09:01 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #3
RE: Static Objects unique ID
(09-27-2011 09:01 PM)aceio76 Wrote:  Does anyone know if this UID is re-generated at each start if the object is not loaded from a saved game? I can't seem to find where or when exactly this ID is created, whether if its during object placement through the WE or when the object is created the first time it is loaded from the world file during game time.

From Game/Object.h:

C UID& id()C {return _id;} //get object's id, 'id' is a unique identifier different than zero for valid objects, and 0 for invalid objects (invalid object is an object which has been removed/deleted), id's are randomly generated upon object creation, they are stored in SaveGame so object's id is restored when loaded

Header Browser tool is very useful.
09-27-2011 11:14 PM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #4
RE: Static Objects unique ID
I did see this (finally), but when is it considered "object creation"? Is it during placement in the WE or when the object is instantiated in runtime? If during runtime, does it then mean that the object that made through world load (not from a savegame) will have a different random uid at each game run?

www.thinkplaystudios.com
09-28-2011 12:27 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #5
RE: Static Objects unique ID
An object's id is created at runtime during the Obj::create() method. The id will be different at each game run, unless you are loading from a saved game.

I agree that it would be better if the UID were generated in WE and saved into the world data. This way you wouldn't have to use object parameters to identify specific objects at runtime.

I ran into this problem several times now.
09-28-2011 01:00 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #6
RE: Static Objects unique ID
Right now, my only fix is exactly that: creating an Int param that will have to be read at runtime. I will have to manually increment/track the last number used if I want them to be unique.

By chance do you know how to enumerate *all* objects in a world file so I can read through all their obj params at game start?

www.thinkplaystudios.com
09-28-2011 01:07 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #7
RE: Static Objects unique ID
I believe your only option is to override the Obj::create() method as this is the only way to get ObjParams, as far as I know.

What exactly are you trying to do?
09-28-2011 02:02 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #8
RE: Static Objects unique ID
I'd like to place objects (with custom obj type) through the WE, then at game run, I'd like to go through all (enumerate) the objects in the whole game world with that specific custom obj type so that I can track them further in code.

www.thinkplaystudios.com
09-28-2011 02:49 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #9
RE: Static Objects unique ID
Like in EsenthelEngineSDK\Tutorials\Source\Advanced\4 - Demos, Game Basics\Game Basics\08 - Custom Parameters.cpp ??
09-28-2011 03:50 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #10
RE: Static Objects unique ID
Yes that's how to extend game::obj and create a custom objtype and add custom params in an obj that is using that objtype. What I am looking for is to load all world areas to find all objects of that specific object type and put them in an array. This means I have to load areas even if the actor is nowhere near them (player is in point 0,0 and i need to load objects in areas 1000,1000, for example).

www.thinkplaystudios.com
09-28-2011 04:01 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #11
RE: Static Objects unique ID
Worlds are streamed in by default, so either load the world entirely Game::World.init(Game::WORLD_FULL); or manually load/unload each area in Game::WORLD_MANUAL mode.

This is going to be slow if your world is very large and, I suppose, could potentially crash your game if using Game::WORLD_FULL. Probably best to use Game::WORLD_MANUAL in conjunction with MultiThreadedCall to get the best performance.

Why exactly do you need to do this?
09-28-2011 04:54 AM
Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #12
RE: Static Objects unique ID
So adopting from Ineisis, here is a snippet of what I've been working on:
Code:
Net::Area* GetArea(Net::World &world, C VecI2 &xy)
{
   return world.grid.get(xy)->data();
}
void ProcessAreaObjects(Net::Area *area)
{
   // enumerate all the objects in the area and do something with them  
}
void LoadWorld(Str world_dir)
{
   Str dir=Replace(world_dir, '\\', '/');
   Net::World &world  =*Net::Worlds(dir);
   Str        area_dir= world.gameDir()+"Area";
   for(FileFind ff(S+"data/"+area_dir); ff(); )
   {
      VecI2 xy=TextVecI2(ff.name);
      if(Net::Area *area=GetArea(world, xy))
      {
         Str fp=Replace(ff.pathName(), '\\', '/');
         LogInfo(S+"Objects="+area->objs()); // put into log the number of objects in the area if any
         //ProcessAreaObjects(area);
      }
   }
}
void LoadAllWorlds()
{
   for(FileFind ff("data/world"); ff(); )
      if(GetExt(ff.name)=="world")
         LoadWorld(ff.pathName());  
}

The current challenge is being able to load each area so that I can access the objects within and find the objtypes I want.

www.thinkplaystudios.com
09-28-2011 12:54 PM
Visit this user's website Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #13
RE: Static Objects unique ID
Code:
Net::World &world  =*Net::Worlds(dir);
   Str        area_dir= world.gameDir()+"Area";
   for(FileFind ff(S+"data/"+area_dir); ff(); )
   {
       Area area=LoadArea(ff.pathName());
   }
...

I can't find a way to directly load an "area" file (0, 1) into an object that I can work with. Guys, I need some advice.

Ultimately, I want to be able to read all the objects of a specific objtype and I am currently trying to do that by loading all the Areas in the world file. Is this the right way?

www.thinkplaystudios.com
(This post was last modified: 09-29-2011 02:35 AM by aceio76.)
09-29-2011 01:13 AM
Visit this user's website Find all posts by this user Quote this message in a reply
aceio76 Offline
Silver Supporter

Post: #14
RE: Static Objects unique ID
So with my latest attempt in loading the world, I get this error:
[Image: errmsg01.jpg]

Does anyone know what it is pointing to?

www.thinkplaystudios.com
09-29-2011 04:59 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #15
RE: Static Objects unique ID
That means you haven't initialized the physics engine yet:

Code:
Bool Init()
{
    Physics.create(CSS_NONE, true, "path/to/PhysX");
    // ...
}
09-29-2011 05:46 AM
Find all posts by this user Quote this message in a reply
Post Reply