|
1 registered members (Quad),
1,951
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
any C++ function likes [wait( )]?who know
#334693
07/24/10 17:27
07/24/10 17:27
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
hey,guys. i used sdk(vs2005) to development 3dgs, and i can`t find function [wait()] from sdk, so i used C++ function [Sleep()] to do that, but it`s false. --------------------------------------------------------------
code:main.cpp
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow){
...
p_ent= ent_create("baul_armed.mdl",_vec(0,0,0),(EVENT)monster_evt);
...
while (engine_frame()){
...
}
}
void monster_evt(void){
while(1){
Sleep(2000);
g_v = 2;
v(my).pan+=_VAR(20);
//programme well be stop here
}
}
like this code: could convert cpp?how to do that? lite-c:
action rotator()
{
my.ambient = 100; // increase brightness
wait(-0.5); // wait 0.5 seconds
my.ambient = 0; // normal brightness
while (1) {
my.pan += 3*time_step; // rotate entity by 3 degrees per tick
wait(1); // wait one frame, then repeat
}
}
did [EVENT form sdk] just initialization any variable or function and cound`t did message loop?
Last edited by frankjiang; 07/24/10 18:05.
development 3d game is interesting!
|
|
|
Re: any C++ function likes [wait( )]?who know
[Re: Damocles_]
#334748
07/25/10 00:32
07/25/10 00:32
|
Joined: Jul 2001
Posts: 6,904
HeelX
Senior Expert
|
Senior Expert
Joined: Jul 2001
Posts: 6,904
|
Well, a Lite-C function that is littered with wait(1) statements is nothing more than a state machine (the code segments that are divided by wait(1) are hereby states) that is called from outside - when the active state of the machine gets called, the code of it gets executed and following state changes can be invoked (like leaving a while or so). Another thing which you'll need to successfully emulate Lite-C functions in C++ is that you have to save A) the parameters and B) the local variables. One possible solution is the use of function objects. Function objects (or more commonly: functors) are similar to function pointers in C, but with a state. Basically, you set up a special class construct in which you can have arbitrary data members (local variables, etc.) and one specific public method (most commonly denominated as "::Call()") is the execution entry point. You could now implement a simple switch/case statemachine in such a function object and use the private data members to guarantee persistence to your local variables and parameters independent from each call. Then in a scheduler class you could use a std::vector to store all function objects and use the global engine event (EVENT_FRAME, isn't it?) to let the schedular call on each wait(1) all ::Call() methods of all available function objects. A simple to understand introduction for functors can be found here: http://www.newty.de/fpt/functor.html [EDIT] by "simple to understand" I expect you to have knowledge about basic inheritance, abstract classes and function pointer usage.Actually, it should be pretty easy to do this. I already thought much about it and this is a neat solution I think. The only drawback is that switch/case statemachine are NOT NEAT, they are evil!! No kidding!!! :-P But it should be sufficient at the beginning. Regards, -Christian
Last edited by HeelX; 07/25/10 00:34.
|
|
|
Re: any C++ function likes [wait( )]?who know
[Re: HeelX]
#334759
07/25/10 01:54
07/25/10 01:54
|
Joined: Dec 2009
Posts: 128 China
frankjiang
OP
Member
|
OP
Member
Joined: Dec 2009
Posts: 128
China
|
thank you for your help.i know how to do that,like this code:
void monster_evt(ENTITY *e){
e->pan+=_VAR(5);
g_per+=v(time_step)*0.006;
ent_animate(e,"run",_VAR(g_per),_VAR(ANM_CYCLE));
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow){
...
ENTITY *p_ent=ent_create("baul_armed.mdl",_vec(0,0,0),NULL);
while (engine_frame()){
vec_set((VECTOR*)&v(mouse_pos).x,(VECTOR*)&v(mouse_cursor).x);
VECTOR vMove;
vMove.x =_VAR(0.01)*(v(key_w) - v(key_s));
vMove.y = _VAR(0.01) * (v(key_a) - v(key_d));
vMove.z = 0;
vec_add ((VECTOR*)&v(camera).x, &vMove);
monster_evt(p_ent);
}
}
Last edited by frankjiang; 07/25/10 01:58.
development 3d game is interesting!
|
|
|
|