Persistence of continuous accelerations.

This commit is contained in:
yaw-man 2023-01-27 13:24:53 -04:00
parent 7a1533a6a7
commit e1e00dce4c
2 changed files with 13 additions and 27 deletions

View File

@ -1,6 +1,7 @@
function love.conf( t ) function love.conf( t )
t.version = "11.4" t.version = "11.4"
t.identity = "Your Own Drum" t.identity = "Your Own Drum"
t.console = true
t.modules.joystick = false t.modules.joystick = false
t.modules.physics = false t.modules.physics = false

View File

@ -2,6 +2,7 @@
local love = love local love = love
local recorder = {} local recorder = {}
recorder.isLoaded = false recorder.isLoaded = false
local ddxs, ddys
local i = 0 local i = 0
function recorder.Reset() function recorder.Reset()
@ -9,15 +10,12 @@ function recorder.Reset()
for k, _ in ipairs( recorder ) do recorder[k] = nil end for k, _ in ipairs( recorder ) do recorder[k] = nil end
end end
function recorder.UpdateCts( ddx, ddy ) function recorder.Update( ddx, ddy )
local xByte = 0 i = i + 1
local yByte = 0 recorder[i] = love.data.pack( "string", "!16<dd", ddx, ddy )
--i = i + 1
recorder[i] = love.data.pack( "data", "dd", ddx, ddy )
end end
function recorder.Update( ddx, ddy ) --[[function recorder.Update( ddx, ddy )
local byte = 0 local byte = 0
if ddx > 0.5 then byte = byte + 1 end if ddx > 0.5 then byte = byte + 1 end
if ddy > 0.5 then byte = byte + 2 end if ddy > 0.5 then byte = byte + 2 end
@ -26,15 +24,16 @@ function recorder.Update( ddx, ddy )
i = i + 1 i = i + 1
recorder[i] = string.char( byte + 48 ) recorder[i] = string.char( byte + 48 )
end end]]
function recorder.Load( filename ) function recorder.Load( filename )
ddxs, ddys = {}, {}
local s = love.filesystem.read( filename ) local s = love.filesystem.read( filename )
print( filename )
if not s then return end if not s then return end
local j = 1 local k, j = 1, 1
for c in s:gmatch( "." ) do local n = s:len()
recorder[j] = string.byte( c ) - 48 while k < n do
ddxs[j], ddys[j], k = love.data.unpack( "!16<dd", s, k)
j = j + 1 j = j + 1
end end
recorder.isLoaded = true recorder.isLoaded = true
@ -44,22 +43,8 @@ function recorder.Load( filename )
end end
function recorder.NextTick( ) function recorder.NextTick( )
local byte = recorder[ i + 1 ]
if not byte then return end
i = i + 1 i = i + 1
return ddxs[i], ddys[i]
local a, b, c, d =
math.floor( byte ) % 2,
math.floor( byte / 2 ) % 2,
math.floor( byte / 4 ) % 2,
math.floor( byte / 8 ) % 2
local ddx, ddy = a - c, b - d
local n = math.sqrt( ddx * ddx + ddy * ddy )
if n < 0.001 then return 0, 0 end
ddx, ddy = ddx / n, ddy / n
return ddx, ddy
end end
function recorder.Save( ) function recorder.Save( )