Jeff-20 wrote:Line 6, part of my main loop, has a long number. Replacing it with a variable should make movement more fast/smooth. [...] Speed isn't really so important in this game, but I like smoother movement. I need to set a variable for 129.
I instrumented line 2 as follows:
Code: Select all
2 T1=T2:T2=TI:I=PEEK(J):T=((IAND4)=.)*L-((IAND8)=.)*L+((IANDP)=.)-1*((PEEK(K)ANDQ)=.)
This allows to measure the time of one game loop by assigning TI of the current loop entry to T2, and the preceding one to T1. Of course, only accurate to jiffy clock steps, and may fail if one unluckily stops the program between 'T1=T2', and 'T2=TI', but this results in T2-T1 = 0, so is easily noticed.
If the dots aren't moved, PRINT T2-T1 gives 4 jiffies.
Moving the dots (also in different directions) got me 7, 7, 7, 7, and 6 jiffies in 5 tries, i.e. ~6.8 jiffies -> 113 milliseconds per game loop.
I then benched this program:
Code: Select all
10 P=1:Q=128:R=129
11 T1=TI:FORT=1TO1000:NEXT:T2=TI
12 T3=TI:FORT=1TO1000:S=R:NEXT:T4=TI
13 T5=TI:FORT=1TO1000:S=R:S=R:NEXT:T6=TI
14 PRINT (T6-T5)-(T4-T3)
15 :
16 REM S=129 -> 213 (3.55 ms)
17 REM S=Q+1 -> 166 (2.77 ms)
18 REM S=Q+P -> 146 (2.43 ms)
19 REM S=R -> 78 (1.30 ms)
I inserted line 11 so the user can lift off his finger from the RETURN key, so the key scan doesn't slow down the benchmark. Line 12 measures the FOR loop + one assignment, line 13 measures FOR loop + two assignments. Line 14 subtracts those two times taken, effectively giving the time for that extra assignment only, times 1000.
Replacing 129 with a predefined variable gains 2 ms for the main loop of 113 ms. I doubt you'll see any difference.
...
If you want smoother movement, you should consider redesigning the game so the player's figures are moved one pixel at a time rather than one character. One pixel every 20 or 16 ms would give roughly the same pace as with character based movement.
Most probably this requires the game main loop be translated to ML, and maybe also a +3K expansion. If you're interested, I'd take a shot at it. Even though, how should diagonal movements be handled?