3 registered members (AndrewAMD, VoroneTZ, dpn),
1,346
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Updating Attached Entities
#331232
07/02/10 19:13
07/02/10 19:13
|
Joined: Feb 2005
Posts: 647 Williamsburg, VA USA
draculaFactory
OP
User
|
OP
User
Joined: Feb 2005
Posts: 647
Williamsburg, VA USA
|
I need some advice. I placed bone joints around a model and use script to attach other models to the joints in my game. Is it better to have each attached entity run in a loop to update its position or is it better to have one function that updates them all? I have done it both ways and wanted to know which sounds faster.
Currently, a handle is set to a created entity; later, in the main loop, the handle is restored to a temporary pointer; the script then uses vec_for_bone and ang_for_bone to update the position. This repeats for every attachment down the list.
Making dreams come true... And being erroneously accused of software piracy by Conitec in the process.
|
|
|
Re: Updating Attached Entities
[Re: Superku]
#331295
07/03/10 08:01
07/03/10 08:01
|
Joined: Feb 2005
Posts: 647 Williamsburg, VA USA
draculaFactory
OP
User
|
OP
User
Joined: Feb 2005
Posts: 647
Williamsburg, VA USA
|
What I meant was, is the constant use of ptr_for_handle in a single loop better or worse than running a loop for each attachment? Both methods seem about the same, but would there be problems later if I use, say, 15 attachments. I would basically be using ptr_for_handle 15 times in a row.
Making dreams come true... And being erroneously accused of software piracy by Conitec in the process.
|
|
|
Re: Updating Attached Entities
[Re: draculaFactory]
#331311
07/03/10 10:59
07/03/10 10:59
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
I might have the syntax wrong (if I do hopefully someone will correct me) but you can store a pointer's address in a var and restore it with a cast operation (lite C).
((ENTITY*)you) = var_x; you = ((ENTITY*)var_x);
Pros and cons vs a handle, I'm not sure...
Last edited by Rich; 07/03/10 11:01.
A8 com / A7 free
|
|
|
Re: Updating Attached Entities
[Re: Rich]
#331354
07/03/10 18:12
07/03/10 18:12
|
Joined: Feb 2005
Posts: 647 Williamsburg, VA USA
draculaFactory
OP
User
|
OP
User
Joined: Feb 2005
Posts: 647
Williamsburg, VA USA
|
I get no errors, but the attachment doesn't update either; we're probably doing it wrong, but thanks for the help. As it is right now, I have no problems, I was just curious if anyone had done this in a similar way before. I was trying to avoid using loops at all costs.
Making dreams come true... And being erroneously accused of software piracy by Conitec in the process.
|
|
|
Re: Updating Attached Entities
[Re: draculaFactory]
#331463
07/04/10 12:16
07/04/10 12:16
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
Hmmm... This little snip of code is from my project, and it is working. Just to give you another example. This piece of code stores a pointer (address) of an entity in one of it's skills.
if(platform.skill[i] == 0) //cycle through the allocated slots
{
platform.skill[i] = (ENTITY*)me; //store my pointer for later manipulation
return(0);
}
i++; //move up one skill slot
In this piece, the stored pointer is used.
vec_add(((ENTITY*)my.skill[i]).x,vector(0,0,-1000));
The manual lists ptr_for_handle as having a speed of medium. I'm not sure if using a cast is actually faster, but I would guess so. A good way to test the speed is to use the timer() function. Good luck!
A8 com / A7 free
|
|
|
|