1 registered members (TedMar),
1,420
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Naming entities inside C-lite (not WED)
[Re: mmelo]
#179380
01/22/08 23:31
01/22/08 23:31
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Of course. Make a linked list which holds instances of structs. In these structs, you save a char array with the name (or a STRING, if you like) and an entity pointer. Then you write these functions: - putEnt(ENTITY* ent, char* name) //register an entity
- getEnt (char* name) //returns an entity pointer to the entity
- delEnt(char* name) // deletes the entity with the name
- delEnt(ENTITY* ent) //deletes the entity just from the list, but not from memory (the entity is still available)
- renEnt (char* name, char* newName) //renames the entity with given name into the new name
- renName(ENTITY* ent, char* newName) //renames the entity with the given new name
If you don't know how to do this, contact me via pm/email. Cheers, Christian
Last edited by HeelX; 01/22/08 23:31.
|
|
|
Re: Naming entities inside C-lite (not WED)
[Re: HeelX]
#179381
01/23/08 00:22
01/23/08 00:22
|
Joined: Jul 2005
Posts: 21 Lisbon, Portugal
mmelo
OP
Newbie
|
OP
Newbie
Joined: Jul 2005
Posts: 21
Lisbon, Portugal
|
Hi Christian, Thanks for your answer! I appreciate that you can do that, but that way you are handling the entity cache yourself rather than letting the engine do it. I was trying to find if there was any way out of the box to do it. Furthermore, with a linked list like that, getEnt() is bound to need to scan through the list to find what you want which could be costly. If 3dgs did it internally, they would probably implement it as an Hashmap that would make it a lot more performant. Miguel
|
|
|
Re: Naming entities inside C-lite (not WED)
[Re: mmelo]
#179382
01/23/08 06:42
01/23/08 06:42
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Well, if you are not handling 1 million entities, this is quiet fast, even if you scan through the list with an average duration of O(n).
You can also create a binary tree and search in it - which is approx O(log (m) to base 2)... which is super fast if you have LOTS of entities. Even, in the worst case, a binary tree could have a in the worst case a O(n), when your first Item is an entity with the name "a" and then you always sort-in names with a higher rank. You can circumvent that even by implementing an AVL tree.
And if even this is not enough, you can try to make a hash list or hash tree, but this will give you only very little performance boost.
The point is: even if the developers of GS would implement this, they would take a similar approach. And since the fact that you can do this on yourself, I doubt there will be a faster implementation soon by their side.
I'm sorry. You have to write yourself these 100 lines.
Last edited by HeelX; 01/23/08 06:43.
|
|
|
Re: Naming entities inside C-lite (not WED)
[Re: HeelX]
#179383
01/23/08 09:05
01/23/08 09:05
|
Joined: Jul 2005
Posts: 21 Lisbon, Portugal
mmelo
OP
Newbie
|
OP
Newbie
Joined: Jul 2005
Posts: 21
Lisbon, Portugal
|
Quote:
I'm sorry. You have to write yourself these 100 lines.
Don't be...
I was really just wondering if it was in there somewhere but I was just missing it. Writing it myself is no problem whatsoever.
Once again, many thanks for your help.
|
|
|
|