Gamestudio Links
Zorro Links
Newest Posts
How to select between IB accounts by script?
by AndrewAMD. 06/13/26 15:44
Zorro tutorial ideas?
by AndrewAMD. 06/13/26 15:01
Zorro 3.01 recoded MMI function issue
by 11honza11. 06/13/26 11:40
Max Number of Strategies in /Strategy folder
by Martin_HH. 06/12/26 08:50
Stooq now requires an API key
by AndrewAMD. 06/11/26 17:55
Z9 getting Error 058
by k_ivan. 06/10/26 14:38
ZorroGPT
by TipmyPip. 06/10/26 13:07
Z12 live performance
by alx. 06/09/26 20:42
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (Quad), 1,951 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Student_64151, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Member
frankjiang  Offline 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:
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:
Code:
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: frankjiang] #334710
07/24/10 19:46
07/24/10 19:46
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
I never used the SDK, but I know enough to tell you that you can't use wait() from the SDK. You can write a function that executes the content of the loop and call if from Lite-C each frame.

Re: any C++ function likes [wait( )]?who know [Re: Lukas] #334717
07/24/10 20:40
07/24/10 20:40
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
You can look up 'coroutines' and see if you can write a simple scheduler.

Re: any C++ function likes [wait( )]?who know [Re: DJBMASTER] #334726
07/24/10 22:00
07/24/10 22:00
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
the wait function is actually very special to gamestudio.

Normally when writing games in other engines you will have a gameloop,
which does not have any wait that will continue other functions.

(unless you use Threats)

It will normally have only one single wait in the gameloop,
(totally pausing the game to keep a constant framerate or
let the OS do its stuff)
with other function only runny fully and then returning
within the same frame.

Maybe the SDK supports some "function scheduler" code to implement.

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
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

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] #334755
07/25/10 01:04
07/25/10 01:04
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom

Re: any C++ function likes [wait( )]?who know [Re: DJBMASTER] #334757
07/25/10 01:14
07/25/10 01:14
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Aren't they overly too complicated for this kind of task? It's one thing to point to a modern co-routine'esque way to do programming (like it is done in Lite-C) but it is another to explain how to use them easily (-> fibers).

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 Offline OP
Member
frankjiang  Offline OP
Member

Joined: Dec 2009
Posts: 128
China
thank you for your help.i know how to do that,like this code:
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!

Moderated by  TWO 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1