Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (TedMar), 1,420 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Naming entities inside C-lite (not WED) #179379
01/22/08 22:23
01/22/08 22:23
Joined: Jul 2005
Posts: 21
Lisbon, Portugal
M
mmelo Offline OP
Newbie
mmelo  Offline OP
Newbie
M

Joined: Jul 2005
Posts: 21
Lisbon, Portugal
Hi,

I would love to "mark" an entity I created via script with a name, so I could later retrieve it with ent_for_name() (or something equally simple). The reason for me needing this is so I don't have to keep arrays of pointers/handlers knocking about.

Is this in any way possible?

Thanks,

Miguel

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
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

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
M
mmelo Offline OP
Newbie
mmelo  Offline OP
Newbie
M

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
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

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
M
mmelo Offline OP
Newbie
mmelo  Offline OP
Newbie
M

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.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1