Well, both have their pros and cons. Affecting every variable will take a hell lot of time to implement, especially considering the amount of code you have in SoulHunter (You are over 10'000, right?). But affecting variables is more stable than affecting the synchronization.
I wrote a little function that affects the syncs. The upside is, that it is very easy to implement, because you just have to replace every sync command with the function, the downside is, that it takes up to 3 seconds to stabilize. Anyway, let's just see how you go.
Here's the function:
cometSYNC()
This function will affect the synchronization so your main loop will run at a constant speed of a given value. You can use this function instead of using "sync", but never use both! The sync rate must be specified using an integer value, the update value must be specified using an integer value, and the return value is specified using an integer value.
cometSYNC() will count the loops actually performed, and subtract the result from the loops it should have done. From that it calculates which synchronizations should be evenly skipped the next loop.
Pros
-Very easy to implement
-variable function
Cons
-Too unstable for Net Games
SYNTAX
return value=cometSYNC(sync rate,update)
how to use
the return value returns the FPS rate. The sync rate is the rate you want your loop to run at. The update value specifies after how long the function should update the counter. The more objects you have in your game, the higher this value should be. I found a value of 500 runs well.
Function Code
rem comet sync function ----------------------------------------------------------------------------------
function cometSYNC(syncrate,update)
syncrate=syncrate/(1000/update):ssync=syncrate:inc syncrate,offset:time=timer():time_elapsed=time-oldtimer:inc cloop:if time_elapsed>=update:lastloopsmissed=loopsmissed:loopsmissed=((syncrate-cloop)+lastloopsmissed)/2:result=cloop
cloop=1:oldtimer=time:if loopsmissed<1:skip#=0:incskip#=0:else:x#=syncrate:y#=loopsmissed:skip#=x#/y#:incskip#=skip#:endif:inc offset,(ssync-result):result=result*(1000/update):endif:if int(skip#)=cloop then inc skip#,incskip# else sync
endfunction result
Example
rem comet sync
rem by TheComet
rem setup screen
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
rem make some cubes
for t=1 to 180
make object cube t,20
position object t,rnd(300)-150,rnd(300)-150,rnd(300)-150
color object t,rgb(rnd(255),rnd(255),rnd(255))
next t
rem main loop
position camera 0,0,0
point camera 0,0,0
do
rotate camera wrapvalue(camera angle x()+mousemovey()),wrapvalue(camera angle y()+mousemovex()),0
if spacekey()=1 then move camera 1
rem print fps
ink rgb(0,255,0),0
if mode=0 then text 0,40,"Comet SYNC - Constantly runs at 60 FPS"
if mode=1 then text 0,40,"Normal SYNC - notice how it lags"
ink rgb(255,255,255),0
text 0,0,"Screen FPS : "+str$(screen fps())
text 0,20,"Comet FPS : "+str$(cometfps)
text 0,60,"Move mouse to view/Space to move"
text 0,80,"Press Enter to switch sync modes."
rem change mode
if returnkey()=1
inc mode:if mode>1 then mode=0
repeat:until returnkey()=0
endif
rem rotate cube
for t=1 to 180
rotate object t,wrapvalue(object angle x(t)+3),wrapvalue(object angle y(t)+4),0
next t
rem refresh screen with comet sync
if mode=0
cometfps=cometSYNC(60,500)
else
sync
endif
rem end of main loop
loop
rem comet sync function ----------------------------------------------------------------------------------
function cometSYNC(syncrate,update)
syncrate=syncrate/(1000/update):ssync=syncrate:inc syncrate,offset:time=timer():time_elapsed=time-oldtimer:inc cloop:if time_elapsed>=update:lastloopsmissed=loopsmissed:loopsmissed=((syncrate-cloop)+lastloopsmissed)/2:result=cloop
cloop=1:oldtimer=time:if loopsmissed<1:skip#=0:incskip#=0:else:x#=syncrate:y#=loopsmissed:skip#=x#/y#:incskip#=skip#:endif:inc offset,(ssync-result):result=result*(1000/update):endif:if int(skip#)=cloop then inc skip#,incskip# else sync
endfunction result
Enjoy!
I think I'll go over to the code snippet board and post this there...
TheComet
Make the paths of your enemies easier with WaypointPro!