Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A type of frame rate control
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kingnoz




PostPosted: Fri Jul 23, 2004 12:57 pm   Post subject: A type of frame rate control

This is a type of frame rate control that i am using now that works rather well for me. I'm using it for my RPG game. What this allows u to do is set the time u want things to delay for. It will figure out how much time passed during processing of graphics so ur program runs at the same speed everytime.
Ok now for the code...

The following variables should be placed at the top of ur program as global variables.
code:

var changedelay : int
var delay_defined : int := 100
var processtime : int
var delaytime : int
var starttime : int
var endtime : int


Variable Purposes

changedelay - during testing this comes in handy because if u want to adjust the delay time to see how different speeds work then u can. (I'll show an example of this separately because it is not directly used in the main frame rate control code.)

delay_defined - this is the overall time you want a designated set of instructions to delay for (the time elasped between the starttime and endtime variables...i'll explain further on this in the example)

processtime - this is the amount of time that elapsed between the starttime and endtime

delaytime - this is the variable placed in a Time.Delay, it is the balancing delay that makes things run the same.

starttime - this is used at the start of wherever you want, i usually put it before multiple calculations and picture drawing processes are done.

endtime - this is used at the end to finish the starttime.



Now for an example of where to put everything...


first thing to do is place the "starttime" variable - this is best placed before heavy processing like ur drawings.

code:

starttime := Time.Elapsed % time before calculations, drawings
calculate this                    % a possible calculation
calculate that                   % another possible calculation
draw background              % a possible background drawing
draw menu somewhere     % a possible menu drawing
draw player                      % a possible player drawing
endtime := Time.Elapsed                   % time after calculations, drawings
processtime := endtime - starttime     % time to do calculations, drawings
delaytime := delay_defined - processtime % time your delay needs to be         
                                                         % offset to be the same each time
Time.Delay (delaytime) % finally the delay



this example was made to have the exact same delay everywhere...
if u want delays to be different for different instruction sets then just put this line of code before the starttime instantiation.
code:

delay_defined := putyourdelaytimehere



and finally if you want to change your delay time in game for testing purposes then use this

code:

Input.KeyDown (userinput) % or use whatever input statement you want, this is the most popular for games with animation etc
if userinput (KEY_TAB) then % i like tab as a value changing key
        % change the screen to nooffscreenonly only if it is currently
        % offscreenonly
        View.Set ("nooffscreenonly")
        % location can be anywhere you want
        locate (6, 1)
        % ask for a different delay value
        put "Enter in the new delay value! then press <ENTER>" ..
        % get the new delay value
        get changedelay
        % change the delay to be used in your frame rate control code to be
        % equal to the new delay value
        delay_defined := changedelay
        % change the screen back to offscreenonly if you changed it
        View.Set ("offscreenonly")
end if



I have tested this code, using a game of mine, with my brothers computer which is a pentium II 233 with 192 Mb RAM and worst graphics card ever and it worked pretty good. It was relatively the same as my computer, except for the fact that his computer is crap so the pictures don't look as good (but that is just a hardware thing)

If you guys want i can post my rpg game that uses this method so you can see a practical example of my method at work...just pm me saying you want to see it and i will post it if there is enough interest to see it.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Jul 23, 2004 4:22 pm   Post subject: (No subject)

nice simple and creative use of Time.Elapsed.
+20 bits
Kingnoz




PostPosted: Fri Jul 23, 2004 5:23 pm   Post subject: (No subject)

thanks for the bits, greatly appreciated
beard0




PostPosted: Wed Sep 01, 2004 8:32 am   Post subject: (No subject)

there is a much easier way of doing this:
Turing Reference Manual wrote:

Time.DelaySinceLast Part of Time module

Syntax Time.DelaySinceLast ( duration : int )

Description The Time.DelaySinceLast procedure is used to cause the program to pause for a given time since the last call to Time.DelaySinceLast. The time duration is in milliseconds.

Cervantes




PostPosted: Wed Sep 01, 2004 8:42 am   Post subject: (No subject)

Isn't that feature new with Turing 4.0.5?
And how does that incorporate the time it takes for the computer to process and draw all the stuff?
beard0




PostPosted: Wed Sep 01, 2004 8:00 pm   Post subject: (No subject)

Yes, that is new to turing 4.0.5
Cervantes wrote:
And how does that incorporate the time it takes for the computer to process and draw all the stuff?

beard0 wrote:
pause for a given time since the last call to Time.DelaySinceLast

You use it like:
code:
loop
    %all your drawing, calculating code
    Time.DelaySinceLast(NumOfMilliSecsPerFrame)
end loop
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: