Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Mynes on September 24, 2008

Title: I Need Some Help..
Post by: Mynes on September 24, 2008
Hi all,

I've been messing around with some of the source files on here and >trying< to understand what the hell I'm doing  :D However I've run into a little snag,

I played about with a sine scroller from Shockwave and added various other elements from other sources however, when i run it in a window mode it runs really fast and then in full screen its really slow,

could any one help me with this.


.exe and source attached

-
Also wanna say thanks to the people that post there source up here :D its such a great help :D
Title: Re: I Need Some Help..
Post by: Rbz on September 25, 2008
This happens because there's no vsync on windowed mode, you will need to use a delta time to make animations runs at same speed of fullscreen mode.

Seems to me that this Shockwave's scroller already have a partial delta time code that you aren't using right now -> "oldtime/ticks".
Title: Re: I Need Some Help..
Post by: Shockwave on September 25, 2008
Yep, seems like the "ticks" variable is set but not used at all.

Here's how to fix it;

Get rid of all traces of that ticks variable, and the oldtime one too.


Change all the movement variables to floating point (double or single).

then change the main loop to look like this;

Code: [Select]
    DIM SHARED AS DOUBLE GADD,SPEED
    SPEED=2
    GADD=0
    DIM SHARED AS DOUBLE OLD,NEW,DV

DO
   
    OLD=TIMER:'                            Look at the internal timer
    GADD=GADD+(DV*SPEED):'         Delta movement factor
    Clearscreen():'                         Clear The Screen.
    stars()
    SINE()
    MESSAGE():'                            Do Scroller.       
    Ptc_Update @Buffer(0):'            Update The Buffer.
    NEW = (TIMER-OLD)+.001:'        Get elapsed time
    DV=NEW*75:'                          Scale it to something useful

LOOP UNTIL INKEY$ = CHR$(27)

Now you can use the variables GADD as a variable that increases over time (useful for sine waves etc) and also DV to add to scroll texts, stars etc..

What that will do is to see how long the last frame took to draw and calculate a movement factor based on that. It's what I use (rbz will tell you to use queryperformancecounter), it's not the most complicated or accurate way but it will work well.

One tip, make sure that you change movement variables to floating point.. If you use integers it won't work. Also when you come to draw things back to the screen buffer, convert the doubles to integers or the mantissa will give your computer indigestion.