Hi all, just the results of a little experiment.
Move the mouse to look around, the camera moves forward constantly. Avoid the cubes, if you get hit, press the mouse button to rewind.
Could be good for a prince of persia type game, or even a sports game where you want instant replays. It currently uses 100,000 indices to record onto, it overwrites, so at 60fps you get about 17 seconds, thats with 100 entities being tracked. So if you had a racing game with 8 cars, it could probably record a good couple of minutes gameplay.
sync on
sync rate 60
type entitytype
x as float y as float z as float
xs as float ys as float zs as float
xa as float ya as float za as float
xas as float yas as float zas as float
mode as integer
stamp as integer
id as integer
endtype
global timelines=100000
global timelinecur=0
dim entity(256) as entitytype
dim timeline(timelines) as entitytype
`Make some spheres to avoid
for e=1 to 100
entity(e).x=rnd(20)-10
entity(e).y=rnd(20)-10
entity(e).z=rnd(20)-10
entity(e).xa=rnd(360)
entity(e).ya=rnd(360)
entity(e).za=rnd(360)
entity(e).xs=sin(rnd(360))/10.0
entity(e).ys=sin(rnd(360))/10.0
entity(e).zs=sin(rnd(360))/10.0
entity(e).xas=sin(rnd(360))
entity(e).yas=sin(rnd(360))
entity(e).zas=sin(rnd(360))
entity(e).mode=1
entity(e).stamp=0
if e=1
`Player object
entity(e).x=-95
entity(e).y=-95
entity(e).z=-95
make object sphere e,0.3
color object e,rgb(255,0,0)
ghost object on e
set object collision to spheres e
else
make object cube e,15+rnd(30)
color object e,rgb(55,0,45)
set object collision on e
endif
next e
`Make outside border
make object cube 500,200
scale object 500,-100,-100,-100
color object 500,rgb(100,50,0)
fog on
fog color 0
fog distance 30.0,250.0
global record=1
global gametime=0
global recordtime=0
do
if mouseclick()=1 then record=2 else record=1
if record=1 and gametime>100
if object collision(1,0)>0 then record=0 : center text screen width()/2,300,"HIT - Click mouse to rewind"
endif
if record=1
`cheap movement speed calc
move object 1,1.0
entity(1).xs=(object position x(1)-entity(1).x)/3.0
entity(1).ys=(object position y(1)-entity(1).y)/3.0
entity(1).zs=(object position z(1)-entity(1).z)/3.0
move object 1,-1.0
`Rotation according to mouse moves
entity(1).xas=curvevalue(mousemovey(),entity(1).xas,10.0)
entity(1).yas=curvevalue(mousemovex(),entity(1).yas,10.0)
entity(1).zas=0
entity(1).za=0
update()
record()
endif
`Rewind with left mouseclick
if record=2 then playback()
position camera entity(1).x,entity(1).y,entity(1).z
rotate camera entity(1).xa,entity(1).ya,entity(1).za
move camera -2.0
sync
loop
function update()
for e=1 to 100
m=entity(e).mode
if m>0
`Affect position and angle based on speed
inc entity(e).x,entity(e).xs
inc entity(e).y,entity(e).ys
inc entity(e).z,entity(e).zs
inc entity(e).xa,entity(e).xas
inc entity(e).ya,entity(e).yas
inc entity(e).za,entity(e).zas
`Increase speed slowly
entity(e).xs=entity(e).xs*1.0001
entity(e).ys=entity(e).ys*1.0001
entity(e).zs=entity(e).zs*1.0001
`Bounce against walls
if entity(e).x<-100 then entity(e).xs=abs(entity(e).xs)
if entity(e).x>100 then entity(e).xs=-abs(entity(e).xs)
if entity(e).y<-100 then entity(e).ys=abs(entity(e).ys)
if entity(e).y>100 then entity(e).ys=-abs(entity(e).ys)
if entity(e).z<-100 then entity(e).zs=abs(entity(e).zs)
if entity(e).z>100 then entity(e).zs=-abs(entity(e).zs)
`Update and show object
position object e,entity(e).x,entity(e).y,entity(e).z
rotate object e,entity(e).xa,entity(e).ya,entity(e).za
show object e
else
hide object e
endif
next e
endfunction
`Increases gametime and sets timeline to objects state
function record()
inc gametime,1
for e=1 to 100
m=entity(e).mode
if m>0
timeline(timelinecur).x=entity(e).x
timeline(timelinecur).y=entity(e).y
timeline(timelinecur).z=entity(e).z
timeline(timelinecur).xa=entity(e).xa
timeline(timelinecur).ya=entity(e).ya
timeline(timelinecur).za=entity(e).za
timeline(timelinecur).xs=entity(e).xs
timeline(timelinecur).ys=entity(e).ys
timeline(timelinecur).zs=entity(e).zs
timeline(timelinecur).xas=entity(e).xas
timeline(timelinecur).yas=entity(e).yas
timeline(timelinecur).zas=entity(e).zas
timeline(timelinecur).mode=entity(e).mode
timeline(timelinecur).stamp=gametime
timeline(timelinecur).id=e
inc timelinecur,1
inc recordtime,1
if recordtime>timelines then recordtime=timelines
if timelinecur>timelines then timelinecur=0
endif
next e
endfunction
`Play back, rewinds gametime and sets objects to previous state
function playback()
if gametime<1 or recordtime<5 then exitfunction
dec gametime,1
dec timelinecur,1
dec recordtime,1
while timeline(timelinecur).stamp>=gametime
e=timeline(timelinecur).id
entity(e).x=timeline(timelinecur).x
entity(e).y=timeline(timelinecur).y
entity(e).z=timeline(timelinecur).z
entity(e).xa=timeline(timelinecur).xa
entity(e).ya=timeline(timelinecur).ya
entity(e).za=timeline(timelinecur).za
entity(e).xs=timeline(timelinecur).xs
entity(e).ys=timeline(timelinecur).ys
entity(e).zs=timeline(timelinecur).zs
entity(e).xas=timeline(timelinecur).xas
entity(e).yas=timeline(timelinecur).yas
entity(e).zas=timeline(timelinecur).zas
entity(e).mode=timeline(timelinecur).mode
position object e,entity(e).x,entity(e).y,entity(e).z
rotate object e,entity(e).xa,entity(e).ya,entity(e).za
if entity(e).mode>0
show object e
else
hide object e
endif
dec timelinecur,1
if timelinecur<0 then timelinecur=timelines
dec recordtime,1
endwhile
endfunction