|
0 registered members (),
9,630
guests, and 4
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Perfect copy of an entity
[Re: Superku]
#328177
06/10/10 20:33
06/10/10 20:33
|
Joined: Sep 2009
Posts: 1,035 Budapest
Aku_Aku
OP
Serious User
|
OP
Serious User
Joined: Sep 2009
Posts: 1,035
Budapest
|
As you want to have two unique objects with the same attributes, there is always going to be some process of copying. I knew, but if it is possible, i would save as much coding as possible. When you use ent_create and the entity is already in your level, ent_create does not load from hard disk. This is good news.
|
|
|
Re: Perfect copy of an entity
[Re: EvilSOB]
#328179
06/10/10 20:38
06/10/10 20:38
|
Joined: Sep 2009
Posts: 1,035 Budapest
Aku_Aku
OP
Serious User
|
OP
Serious User
Joined: Sep 2009
Posts: 1,035
Budapest
|
you = ent_create(me.type, nullvector, NULL);
According to the manual the first parameter of the ent_create() function is STRING* filename. Please explain to me how and why will work with me.type. Can i instance the new entity with a function name instead of NULL?
|
|
|
Re: Perfect copy of an entity
[Re: Aku_Aku]
#328181
06/10/10 20:46
06/10/10 20:46
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
(Assuming you are using lite-c...)
When you create an entity the filename of the model/sprite is stored in the 'type' property. ie :: me = ent_create("sphere.mdl", ....); //now me.type=="sphere.mdl" so by saying ent_create(me.type, ....);, you are using the same model as 'me' has...
And, yes, you can assign an action to the entity, but I dont know of any way to find out what action is assigned to the source entity. In theory there can be more than one...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Perfect copy of an entity
[Re: Superku]
#328182
06/10/10 20:47
06/10/10 20:47
|
Joined: Sep 2009
Posts: 1,035 Budapest
Aku_Aku
OP
Serious User
|
OP
Serious User
Joined: Sep 2009
Posts: 1,035
Budapest
|
When you use ent_create and the entity is already in your level, ent_create does not load from hard disk. 3D GS uses a cache technology to do that? Is there a threshold for that? Perhaps it is able to cache 1000 entities? It could happen i'll use more than 2000 objects.
|
|
|
Re: Perfect copy of an entity
[Re: EvilSOB]
#328185
06/10/10 20:54
06/10/10 20:54
|
Joined: Sep 2009
Posts: 1,035 Budapest
Aku_Aku
OP
Serious User
|
OP
Serious User
Joined: Sep 2009
Posts: 1,035
Budapest
|
When you create an entity the filename of the model/sprite is stored in the 'type' property. That is half solution for me, but i appreciate that. I use alternate paths to load entities. Fortunately i stored the needful info of that. And, yes, you can assign an action to the entity, but I dont know of any way to find out what action is assigned to the source entity. In theory there can be more than one... That could cause some problems. If i have two identical entities with differing functions, ent1-func1, ent2-func2. How can i guess out which function have to use? Yes, i use lite-C.
Last edited by Aku_Aku; 06/10/10 20:55.
|
|
|
Re: Perfect copy of an entity
[Re: Aku_Aku]
#328187
06/10/10 20:58
06/10/10 20:58
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Don't think too complicated, f.i. you could set some skill to a specified value that indicates its action. The watched entity displays its functions, so there is some way to retrieve them without skills.
Last edited by Superku; 06/10/10 20:58.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Perfect copy of an entity
[Re: Aku_Aku]
#328188
06/10/10 20:58
06/10/10 20:58
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Pick an un-used entity skill to store some form of "reference number" to your action. So when you load an entity, its action stores an identification number in the skill.
Then when you do the entity-duplication, look to that number to know what action is attached...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Perfect copy of an entity
[Re: EvilSOB]
#328193
06/10/10 21:32
06/10/10 21:32
|
Joined: Sep 2009
Posts: 1,035 Budapest
Aku_Aku
OP
Serious User
|
OP
Serious User
Joined: Sep 2009
Posts: 1,035
Budapest
|
Thanks Superku and EvilSOB for the advices. So there isn't elegant way.
Last edited by Aku_Aku; 06/10/10 21:32.
|
|
|
Re: Perfect copy of an entity
[Re: Aku_Aku]
#328203
06/10/10 22:23
06/10/10 22:23
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
The problem is how to determine the action of the entity. The only way to have a control over it without adding superfluous stuff like assigning (by yourself) numbers for action indication is assigning a function to the my.event of an event and setting ENABLE_FRAME. This way you can duplicate the entity easily:
ENTITY* createEntity (char* filename, VECTOR* position, void* fnc)
{
ENTITY* ent = ent_create(filename, position, NULL);
ent->emask |= ENABLE_FRAME;
ent->event = fnc;
return(ent);
}
ENTITY* duplicate (ENTITY* src)
{
// Duplicate model
ENTITY* clone = ent_create(src->type, src->x, NULL);
// Assign event function
clone->event = src->event;
clone->emask |= ENABLE_FRAME;
// Copy attributes
{
vec_set(clone->pan, src->pan); // Orientation
vec_set(clone->scale_x, src->scale_x); // Scale
//... and the rest
}
return(clone);
}
This way, you can't work with wait(1) but this is a low price for this neat and self-build feature!
|
|
|
Re: Perfect copy of an entity
[Re: HeelX]
#328218
06/11/10 02:01
06/11/10 02:01
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
If you're still interested Aku, here is an ALMOST elegant way of doing it... Complete duplication, including "prime" action, and its fully tested too.
action MyAction()
{
my.skill99 = (void*)MyAction;
...
}
action YourAction()
{
my.skill99 = (void*)YourAction;
...
}
ENTITY* ent_duplicate(ENTITY* source_ent)
{
ENTITY* target_ent = ent_create(source_ent.type, 0, (void*)source_ent.skill99);
memcpy(&target_ent.x, &source_ent.x, sizeof(ENTITY)-(sizeof(C_LINK)+sizeof(var)));
// ent_clone(target_ent); //if required
return(target_ent);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|