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

Username:   Password: 
 RegisterRegister   
 Timer Issues
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Clayton




PostPosted: Tue Aug 08, 2006 2:31 pm   Post subject: Timer Issues

ok, im working on a game right now and im having some problems coming up with a reliable way to keep track of n timers without screwing up the screen, and noticeably slowing down the game, at first i thought of a procedure, but couldnt get it to work quite right, so i went to a process, but its still not working, heres what i have so far, if anybody could help it would be much appreciated Very Happy

Turing:

process timer (amount : int)
    const times : int := amount * 1000
    var tim : int := Time.Elapsed
    var tim2 : int := Time.Elapsed - times
    loop
        cls
        put "Time Before Impact: ", round ((tim - tim2) / 1000)
        View.Update
        tim2 := Time.Elapsed - times
        if tim - tim2 <= 0 then
            put "BOOM"
        end if
        exit when tim - tim2 <= 0
    end loop
end timer
Sponsor
Sponsor
Sponsor
sponsor
Windsurfer




PostPosted: Tue Aug 08, 2006 3:03 pm   Post subject: (No subject)

I think the code here is mostly right, i just think there's a problem with the way this interacts with the rest of your code. I see that you are using this process to not only keep track of the seconds, but also to display the timer. Since this is a process, and you are using View.Update, this will reign hell upon earth. Why process are evil.
I reccomend that instead of having a process like this keep track of your timers, and take up 50% of your resources per timer, i suggest you develop a way to record Time.Elapsed at a certain point in your code, and then, for every iteration of your main loop, compare the old time to the new Time.Elapsed, until the desired difference is reached(eg. Time.Elapsed - old_time >= 10000 would be a ten second timer).
Also, display the timer in your main loop too, so that you don't get any unpredictable flickering when using View.Update.
Clayton




PostPosted: Tue Aug 08, 2006 3:06 pm   Post subject: (No subject)

that View.Update was in there from before when it was a proc, ive read that article many a time trust me. i just had this one process in there for now until i could figure out what was going on with my procs...
Windsurfer




PostPosted: Tue Aug 08, 2006 3:11 pm   Post subject: (No subject)

Soo.... what's your question? Confused
Clayton




PostPosted: Tue Aug 08, 2006 3:13 pm   Post subject: (No subject)

my question is how can i get that (above code) to allow me to have multiple timers going while still looking at least half decent...
Windsurfer




PostPosted: Tue Aug 08, 2006 3:20 pm   Post subject: (No subject)

Make an array? Perhaps of real numbers, that you
Quote:

...record Time.Elapsed at a certain point in your code, and then, for every iteration of your main loop, compare the old time to the new Time.Elapsed, until the desired difference is reached(eg. Time.Elapsed - old_time >= 10000 would be a ten second timer).

Start off with this, perhaps:
code:

type timers_type :
    record
        old_time : real
        time_length : real
    end record

const TIMER_NUM := 10
var timers : array 1 .. TIMER_NUM of timers_type
TokenHerbz




PostPosted: Thu Aug 10, 2006 11:30 am   Post subject: (No subject)

cant you just "fork" the process?
Windsurfer




PostPosted: Thu Aug 10, 2006 12:47 pm   Post subject: (No subject)

TokenHerbz wrote:
cant you just "fork" the process?
~slaps poster and commits suicide by keyboard ~ jgamtpgjhkn....
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: