2 registered members (AbrahamR, AndrewAMD),
1,278
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Can I store pointers in local variables, or entity skills?
#386873
11/10/11 08:26
11/10/11 08:26
|
Joined: Nov 2007
Posts: 50
Chaeon
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2007
Posts: 50
|
I want to attach a few passable visible entities to one invisible entity. To do this the visible entities will have to regularly read the invisible entity's position, or the invisible entity will have to regularly write to the cosmetic entities' positions (the second method is better, i think) before, i was storing handles in the invisible ent's skills and converting them back into pointers every frame, but then i looked closer at the manual and i suspect it's possible to just write pointers straight to skills (although they won't survive saving and loading which is fine) is this wrong? and if it's right what type of variable do i need to store a pointer? The manual seemed to favour float yet when i tried to copy a pointer to a global variable as a test i got an error message for float, but not short or var. i'm sorry for such a long question everyone, thank you for any help
|
|
|
Re: Can I store pointers in local variables, or entity skills?
[Re: Chaeon]
#386877
11/10/11 09:54
11/10/11 09:54
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hello, This is the way I use entity skills as entity pointers
#include <acknex.h>
VECTOR vtemp;
function main ()
{
wait(2);
level_load ( "" );
wait(3);
camera.z = 100;
camera.tilt = -90;
you = ent_create ( CUBE_MDL, nullvector, NULL );
set ( you, TRANSLUCENT );
you.alpha = 30;
you.skill1 = ent_create ( CUBE_MDL, vector(20,0,0), NULL );
while (!key_esc)
{
you.pan += time_step * 10;
you.tilt = fsin ( you.pan, 10 );
vec_set ( vtemp, vector(10,0,0) );
vec_rotate ( vtemp, you.pan );
vec_add ( vtemp, you.x );
vec_set ( ((ENTITY*)you.skill1)->x, vtemp );
vec_set ( ((ENTITY*)you.skill1)->pan, you.pan );
wait(1);
}
sys_exit ( NULL );
}
hope it helps, txes
|
|
|
Re: Can I store pointers in local variables, or entity skills?
[Re: txesmi]
#386885
11/10/11 14:03
11/10/11 14:03
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
What's wrong with handles? Granted, they're not as powerful as pointers but they should serve your purposes just fine.
Last edited by Redeemer; 11/10/11 14:04.
|
|
|
Re: Can I store pointers in local variables, or entity skills?
[Re: Chaeon]
#386975
11/12/11 02:01
11/12/11 02:01
|
Joined: Nov 2007
Posts: 50
Chaeon
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2007
Posts: 50
|
Thank you for the advice
so it is possible to store the contents of a pointer in a skill.
and i can change the x,y,z etc of the entity referred to like this:
((ENTITY*)you.skill1)->x += number
(i don't understand this, what is a "->"? i'd be grateful if someone can point me to an explanation for it but it isn't crucial now)
thank you txesmi!
redeemer, i thought that storing the handle for an object and then converting it BACK into a pointer for use was a roundabout way to do things. But if i repeatedly did the arrow thing it might end up even slower running! i don't know.
I suppose my question is, then, what would be the most efficient way of storing a reference to an object in an entity skill, and then altering the position of said object every frame thereafter?
(the efficient way *might* be to store a handle, i don't know. But the manual says that the speed of ptr_for_handle is "medium" so i don't feel like calling it dozens of times every frame)
I HEART 3DGS
|
|
|
Re: Can I store pointers in local variables, or entity skills?
[Re: Redeemer]
#386979
11/12/11 03:18
11/12/11 03:18
|
Joined: Nov 2007
Posts: 50
Chaeon
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2007
Posts: 50
|
what. doesn't that mean there's such a thing as a "local" pointer? but that would make it a hundred times easier! I thought the only "local" pointers were my and you. if i can just define a pointer inside a function and trust it to be preserved during wait(1), despite all the other entities using pointers of the same name, that would surely be the most efficient way? wow i just tested it and it works. man why did they have a section on local variables in the manual yet nothing on local pointers? okay so i'll assume this is the most efficient way, but i'll be happy to hear any further wisdom. Thank you very much for you time redeemer
I HEART 3DGS
|
|
|
Re: Can I store pointers in local variables, or entity skills?
[Re: Chaeon]
#386987
11/12/11 10:05
11/12/11 10:05
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Uh, a pointer is nothing else than a variable, so the section about local variables already covers pointers...
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Can I store pointers in local variables, or entity skills?
[Re: WretchedSid]
#386997
11/12/11 13:54
11/12/11 13:54
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
One additional note: it is OK to use local pointers and this works (like you already found out), but it is additional memory overhead, because the scheduler has to save and restore each frame for each function the local variables. So, if you just do
my->skill1 = ent_create(...)
And later in your code:
ENTITY* mySomething = (ENTITY*)my->skill1;
you are perfectly fine and don't waste memory and time. [EDIT] "." is used on structs and real objects, "->" is used on pointers. See here: http://publications.gbdirect.co.uk/c_book/
Last edited by HeelX; 11/12/11 13:55.
|
|
|
Re: Can I store pointers in local variables, or entity skills?
[Re: HeelX]
#387032
11/13/11 00:56
11/13/11 00:56
|
Joined: Nov 2007
Posts: 50
Chaeon
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2007
Posts: 50
|
Thanks HeelX, i think i get it now, i'll use that way then..
I HEART 3DGS
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|