Getting view entities...

Posted By: HeelX

Getting view entities... - 08/22/10 09:11

Hi folks,

I didn't work with view entities a long time, maybe I am doing something terribly wrong. I have a static mesh level and one static view entity which is my sky entity. What I want to do is to get this entity after loading the level:

Code:
ENTITY* entSkycube =
{
   type = "skycube+6.tga";
   flags = UNLIT;
   flags2 = SKY | CUBE | SHOW;
}

int main ()
{
   //...

   level_load("test_0001.wmb");
   
   //...
   
   int ents = 0;
   ENTITY* ent = ptr_first(level_ent);
   while (ent)
   {
      ents++;
      ent = ent.link.next;
   }

   printf("ents = %d", ents);
   //out: "ents = 0"
}



But all I get are 0 entities... how do I access the list of static entities here?

Bye,
-Chris
Posted By: LemmyTheSlayer

Re: Getting view entities... - 08/22/10 09:23

try the ent_next function.

ENTITY* ent = ent_next(NULL);
while (ent)
{
ents++;
ent = ent_next(ent);
}
Posted By: HeelX

Re: Getting view entities... - 08/22/10 10:27

Doesn't work either, because ent_next is for level entities only and ptr_first is for all entities... or should be.
Posted By: flits

Re: Getting view entities... - 08/22/10 17:53

i gues its removed because of level_load

just try to create a entity by ent_createlayer after te level_load

(maby even a wait(1); after it)
Posted By: EvilSOB

Re: Getting view entities... - 08/22/10 18:52

HeelX,
ptr_first is not for ALL entities, it is for ALL objects OF THE SAME TYPE...

Take a look in the manual at the "handle" entry, and you'll see there are three
'different' types of entity. 'lobal', 'local', and 'layer'.

So if you wantr to find all "layer" entities (a view-entity), then you will
need to 'prime' the ptr-first function with another view-entiy.
You aren't, you are priming it with the "level_ent" whis is not a view-entity.

Try this instead (untested)....
Code:
...
   int ents = 0;
   ENTITY* seed = ent_createlocal(CUBE_MDL, nullvector, NULL);
   ENTITY* ent = ptr_first(seed);
   while (ent)
   {
      if(ent != seed)  //dont count the seed-entity
      {   ents++;   }
      ent = ent.link.next;
   }

   ent_remove(seed);
   printf("ents = %d", ents);
   //out: "ents = 0"

...



Posted By: HeelX

Re: Getting view entities... - 08/23/10 08:18

Ha, that shall be the trick? Thanks!

Unfortunately the manual says

Quote:
Returns a pointer to the first object for a given engine object.
Parameters:
object - ENTITY*, STRING*, BMAP*, VIEW*, PANEL*, TEXT*, FONT*, SOUND*, or MATERIAL* pointer.


So I expected that if I pass an entity, I get all entities. Didn't knew that the function differentiates between global, local and view entities... :-(

I test it out today and give feedback here! I hope it works grin
Posted By: EvilSOB

Re: Getting view entities... - 08/23/10 09:36

I hope it helps, as it is only an educated guess that ptr_first DOES differentiate.

It my conclusion it will because your flow is like so...
A> ptr_first is retrieves the first object of a given type.
B> then you step through using ent.link.next

Now, seeing as the "link" data in any object is primarily its handle,
then anything else in the link data will "most likely" recognise the same types.

So ... if you are stepping through the "handles", and the handle function sees a
difference between the three entity types, then ptr_first PROBABLY does too.

That the logic I followed anyways...
Posted By: HeelX

Re: Getting view entities... - 08/23/10 18:30

Ha, it works!!!

Here is how you iterate through all sky entities:

Code:
int ents = 0;
ENTITY* seed = ent_createlayer("", SKY, 0);
ENTITY* ent = ptr_first(seed);
while (ent)
{
   if (ent != seed)
   {
      error(ent->type); // "skycube+6.tga"
      ents++;
   }

   ent = ent.link.next;
}

if (seed)
   ptr_remove(seed);

printf("sky entities = %d", ents);



Many thanks to you, EvilSOB!
Posted By: EvilSOB

Re: Getting view entities... - 08/23/10 19:38

No problem dude. Glad to be of service.
© 2024 lite-C Forums