Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (Ayumi, NewbieZorro, TipmyPip), 13,887 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
when will the engine render? #54393
09/07/05 04:44
09/07/05 04:44
Joined: Aug 2005
Posts: 152
E
edisontsui Offline OP
Member
edisontsui  Offline OP
Member
E

Joined: Aug 2005
Posts: 152
Hi all,

I want to make a framecounter so I have written a loop in the main func which add 1 to a var and wait 1 frame and call some dllfunction. I use a panel and put the var in it and find it increase slowly but I hit F11 and find the fps is more than 60fps. Then I have a question in mind. When will the engine render? At the end of the main loop? Or it is totally independent? Or else?

Many thx,
ET

Re: when will the engine render? [Re: edisontsui] #54394
09/07/05 04:50
09/07/05 04:50
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
If you use the wait(1) instruction at the end of the while loop, then the count will happen once every frame. I have something similar myself in my 2D game based strictly on 60 fps, but it counts frames, seconds, and minutes. It behaves exactly as I expected it to (although it's slightly a little on the fast side as I can't lock the frame rate exactly on 60 for some reason).


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials
Re: when will the engine render? [Re: ulillillia] #54395
09/07/05 05:55
09/07/05 05:55
Joined: Aug 2005
Posts: 152
E
edisontsui Offline OP
Member
edisontsui  Offline OP
Member
E

Joined: Aug 2005
Posts: 152
Thx, so do you mean that all the functions called (no matter how costly they are) in the while loop will be executed within 1 frame? And is it the case the functions inside action.

Re: when will the engine render? [Re: edisontsui] #54396
09/07/05 06:55
09/07/05 06:55
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
What I'm saying is that the function is executed once every frame and within that frame. At the end of all the functions, the view is updated and the process begins again for the next frame. After all functions currently running are done, the view is updated again. They're run again and the view is updated. At this point, the variable would now have a value of 3 as three frames have passed. Copy this into your script and see for yourself:

var frame_count = 0;

function count_for_me()
{
frame_count += 1;
}



Now add this at the very top of the main function:

fps_max = 10; // 10 frames per second maximum
fps_lock = on; // locks it
count_for_me(); // begins the count



Try playing around with the fps_max value. I prefer you do this in a very simple and empty-looking level or you might run into problems. If you want to toggle the frame rate, add this above the main function:

var max_frame_rate = 10;

function toggle_frame_rate()
{
if (max_frame_rate == 10)
{
max_frame_rate = 15;
fps_max = 15;
return(0);
}

if (max_frame_rate == 15)
{
max_frame_rate = 20;
fps_max = 20;
return(0);
}

if (max_frame_rate == 20)
{
max_frame_rate = 30;
fps_max = 30;
return(0);
}

if (max_frame_rate == 30)
{
max_frame_rate = 60;
fps_max = 60;
return(0);
}

if (max_frame_rate == 60)
{
max_frame_rate = 10;
fps_max = 10;
return(0);
}
}
on_f = toggle_frame_rate();



And when you run your level, press the F key to switch between the different frame rates and see how it affects your value. Of course, to see it, you'll need a panel (add this anywhere above the main function):

panel show_frame_count
{
pos_x = 8; // top left corner
pos_y = 8;
layer = 15;
digits = 0, 0, 7, _a4font, 1, frame_count;
flags = visible; // make it visible
}



From there, you should be set. If you have a moving object visible that moves constantly in your level, you can monitor the frame rate that way. The jerkier it is, the lower the frame rate and the slower the count should increase. The smoother it is, the higher the frame rate and the faster the count should increase.

Hopefully that'll get you somewhere. You might need to modify the code to fix any syntax errors I might've left out.


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials
Re: when will the engine render? [Re: ulillillia] #54397
09/07/05 07:05
09/07/05 07:05
Joined: Aug 2005
Posts: 152
E
edisontsui Offline OP
Member
edisontsui  Offline OP
Member
E

Joined: Aug 2005
Posts: 152
thx, it is very clear.
I have performed similar tests and i have written to actions, one calling lot of junk dllfunc and one just loop and wait(1). I have put a counter in each action and the results is the two counter is exactly the same which suggested, it will wait till all functions in all loops are finished before moving to next frame.

Thx and with that I can share load in diff frames.

Re: when will the engine render? [Re: edisontsui] #54398
09/07/05 07:10
09/07/05 07:10
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
No problem. I use this with my 2D game for the clock, challenge timers and other things and I've got a few functions running constantly (8 in normal mode, 3 in frame advance mode).


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials

Moderated by  HeelX, Spirit 

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