Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 2 secconds, real time

Author
Message
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 20th Apr 2005 02:08
Want to create a day/night system for my FPS, but I need to base it on the computer clock (else time would go slower on slower machines).
I was creating a test program that draws a box (random collor) every 2 secconds.
now the problem is, the only thing I can do with the get time$() command is print it. and I don't understand the timer() command.

could somebody give me a timer demo that draws a box every 2 secc?
Kohaku
21
Years of Service
User Offline
Joined: 3rd May 2004
Location: The not very United Kingdom
Posted: 20th Apr 2005 02:16 Edited at: 20th Apr 2005 04:07
Well, this example rotates a cube every 2 seconds.



You are not alone.
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 20th Apr 2005 02:46
here's a little snippet for getting time data:

Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 20th Apr 2005 04:05
don`t use time$(), use timer, the timer tics 1000 times a second, so to do something every two seconds just get the current timer...

t=timer()


then add two seconds so that the variable t is two seconds larger than timer.....

t=t+2000

then inside the main loop just keep checking for the timer catching up with t....

if timer()>=t

note that we check for the timer being equal or greater (overshoot) than t, this is because in a real program some large calculation (say multiple collision tests) may mean that last time through the loop timer() was at t-1, then by the next loop it would be at t+1, if you just checked for it being equal then that would fail to trigger.
then inside the if-endif structure draw (as in your example) a box in a random colour and position

ink rgb(rnd(255),rnd(255),rnd(255)),0
x=rnd(600)
y=rnd(400)
w=rnd(200)+1
h=rnd(200)+1
box x,y,x+w,y+h

then reset the timer to start counting again, in this example I have assumed that just adding 2000 to t will suffice, if the action took a significant amount of time then this would show perceptable errors, but in this example the time lag will be not noticeable, although after drawing several thousand boxs the time may be out by one second from what it should be, but I have assumed this does not matter, never make code more elaborate than you need for the job in hand.

t=t+2000

then just end the decision structure

endif

heres the code made into a working example....



hope thats some help to you

Mentor.

PC1:XP, P4 3ghz, 1gig mem, 3x160gig hd`s, Radeon 9800pro, 6 way sound.
PC2: Linux, AMD 2ghz, 512mb ram, Nvidia GeForce4mx, 16 bit SB.
PC3: XP, laptop, intel 2.6ghz celeron, ATI 9000igp, 256mb
Kohaku
21
Years of Service
User Offline
Joined: 3rd May 2004
Location: The not very United Kingdom
Posted: 20th Apr 2005 04:06
Would you believe that I was about to correct my mistake of leaving out the +2000 bit, just as you post?

You are not alone.
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 21st Apr 2005 03:46 Edited at: 21st Apr 2005 03:49
Quote: "Well, this example rotates a cube every 2 seconds."


here you go, a unfinished code of a cube rotator
every 2 secconds it checks if the cube isn't rotating and if it isn't, it rotates the cube in a random direction. Or at least that's what it's created for. (BTW, smoothnes is everything)


Quote: "here's a little snippet for getting time data:"


thank you , no time without a clock

Quote: "t=timer()
t=t+2000
do
if timer()>=t
ink rgb(rnd(255),rnd(255),rnd(255)),0
x=rnd(600)
y=rnd(400)
w=rnd(200)+1
h=rnd(200)+1
box x,y,x+w,y+h
t=t+2000
endif
loop"

my test code was exactly like that, exept for the ">=", it means equal or bigger than right? What symbol was not bigger than?

thank you all , I'm going to try to post a test of the day/night code once I get it finished.
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 21st Apr 2005 03:50
I thought you needed a real time day/night system...
Why do you need timer() then?
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 21st Apr 2005 04:34 Edited at: 21st Apr 2005 04:36
Quote: "but I need to base it on the computer clock (else time would go slower on slower machines)."

(quoted from my first post.)

I discoverd this when I was tinkering with a lens flare fuction, wich realy slowed the program down. Now for the jumping part of my code, I have acceleration set to 60 when you lift off, but every time the code loops it dicreases it by 1, and so a slow code/computer will get the days out of ballance.(BTW: the function is now deleted, and I will create a new one when I get the time going)
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 23rd Apr 2005 20:32 Edited at: 24th Apr 2005 05:28
well this is the code I've been stumbling over the past few days

it's designed to got to a new RGB value everytime the clocks mach.
And every time they do that, the code works out, the difrence betwen the two values, devides that by 20 and then ads or detracts that to the current values.
Ultimatly I would like a coulour change that takes a minute
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 24th Apr 2005 02:59
less than is

<

greater than is

>

greater or less than is

<>

greater than or equal too is

>=

less than or equal too is

<=

if you look at the brace the narrow end points to the lesser side of the compare and the broader side to the greater... eg

less<greater=true
greater<less=false

or

1<2 returns 1
2<1 returns 0

hope thats some help..

cheers.

Mentor.

PC1:XP, P4 3ghz, 1gig mem, 3x160gig hd`s, Radeon 9800pro, 6 way sound.
PC2: Linux, AMD 2ghz, 512mb ram, Nvidia GeForce4mx, 16 bit SB.
PC3: XP, laptop, intel 2.6ghz celeron, ATI 9000igp, 256mb
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 24th Apr 2005 03:05
I always think of '<>' as 'Not', i.e.,

sec=rnd(3)

if sec<>2
..something
endif

How's my typing? Phone 0800-GO-TO-HELL
Link102
20
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 24th Apr 2005 05:26 Edited at: 24th Apr 2005 05:29
that is usefull, I needed that, but somehow the fogR# value overshoots and then continues adding the difrence value:
if ufogR#=199 and ofogR#=190 then (ufogR#-ofogR#)/20=0.45
0.45*20=9 witch means it souldn't overshoot.
does anybody know the correct ecuasion?

I edited the code in my previous post, no media used.

Login to post a reply

Server time is: 2025-05-23 10:51:49
Your offset time is: 2025-05-23 10:51:49