Posted By: Walori
Function pointer - 05/14/11 18:41
GS version 7.86.2
This one's killing me, how can I use functions pointers they way that I have pointer x (let's say function xys(parameters) ) which I put to void* function_array[0] place and then call "xys" from the array void? Currectly I get the function called but it causes problems with movement. Below are the code parts that are relevant, to check full code file check the links.
MOVEMENT:
https://bitbucket.org/WinKIller0/acknexproject/src/424d047ac418/Data/movement.c
EFFECT
https://bitbucket.org/WinKIller0/acknexproject/src/424d047ac418/Data/effects.c
ACTUAL EFFECT FUNCTION CALLED
THE CALLER CODE
https://bitbucket.org/WinKIller0/acknexproject/src/424d047ac418/Data/scene_functions.c
Does anyone what may cause the c_move stop working? I have narrowed down the following that may have caused it:
*movement vector doesn't get values anymore(WORKS)
*Loop doesn't continue to next spawn anymore(WORKS)
*Loop inside the function that gets called causes movement freeze(tested,even with nothing inside the function, movement freezes)
*Movement code itself is freezing itself (WORKS, even if movement doesn't happen the c_mve inside the function is called)
+I have animations, sound and lod functions also which continue working when movement freezes
This one's killing me, how can I use functions pointers they way that I have pointer x (let's say function xys(parameters) ) which I put to void* function_array[0] place and then call "xys" from the array void? Currectly I get the function called but it causes problems with movement. Below are the code parts that are relevant, to check full code file check the links.
MOVEMENT:
https://bitbucket.org/WinKIller0/acknexproject/src/424d047ac418/Data/movement.c
Code:
//SPAWN is a predefined struct which has VECTOR movement in it //Me is a pointer to a entity inside SPAWN struct ... if(vec_valid(spawn->movement) != 0 && me->anim_attack == 0)//If there's movement and no attack { spawn->distance_moved = c_move(me,vector(spawn->movement.x*time_step,spawn->movement.y*time_step,spawn->movement.z*time_step),nullvector,GLIDE | IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES | IGNORE_CONTENT | IGNORE_MAPS | IGNORE_FLAG2);//Move entity by movement vector in characte struct } else spawn->distance_moved = 0;
EFFECT
https://bitbucket.org/WinKIller0/acknexproject/src/424d047ac418/Data/effects.c
Code:
//Based on aum99 example of hollogram effect, nothing weird here function hollogram_effect(PARTICLE*p) { set(p,UNLIT | BRIGHT | TRANSLUCENT); p.bmap = NULL; p.size = 1; p.lifespan = 0.1; // vec_set(p.x,vector(p.x-1+random(2),p.y-1+random(2),p.z-1+random(2))); p.alpha = random(100); p.event = NULL; }
ACTUAL EFFECT FUNCTION CALLED
Code:
float hollogram(ENTITY* ent) { //This function is passed to void* array outside of the function. This is called from the function below ent.alpha = 10; me = ent; for(scn_effect_i=0;scn_effect_i<ent.vertices;scn_effect_i++) { vec_for_vertex (effect_align, ent, scn_effect_i); effect(hollogram_effect,1,effect_align,nullvector); } return 1; }
THE CALLER CODE
https://bitbucket.org/WinKIller0/acknexproject/src/424d047ac418/Data/scene_functions.c
Code:
float function_effect(ENTITY* ent);//Defined function pointer void* spawn_effect[200];//Array for functions me = ent_next(NULL); while(me)//Loop until breaked internally { ... spawn_move(spawn_cur);//Call movement function (the first code) ... me.my_effect = 1; if(spawn_effect[me.my_effect] != 0) { function_effect = spawn_effect[1];//Get "hollogram" function_effect(me); //Call hollogram // function_effect = NULL; uu1++; } ... me = ent_next(me); }
Does anyone what may cause the c_move stop working? I have narrowed down the following that may have caused it:
*movement vector doesn't get values anymore(WORKS)
*Loop doesn't continue to next spawn anymore(WORKS)
*Loop inside the function that gets called causes movement freeze(tested,even with nothing inside the function, movement freezes)
*Movement code itself is freezing itself (WORKS, even if movement doesn't happen the c_mve inside the function is called)
+I have animations, sound and lod functions also which continue working when movement freezes