Automation events.

This commit is contained in:
jussi
2024-03-01 23:11:54 +02:00
parent 625e4e0e4d
commit ca238975dc
12 changed files with 676 additions and 10 deletions

View File

@@ -0,0 +1,97 @@
package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
Vec2 = require( "vector2" )
local eventList = nil
local evenRecording = false
local eventPlaying = false
local frameCounter = 0
local playFrameCounter = 0
local currentPlayFrame = 0
local player = {
pos = Vec2:new( 160, 200 ),
speed = 100.0,
}
function RL.init()
RL.SetWindowTitle( "Automation Events" )
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetTextLineSpacing( 25 )
eventList = RL.LoadAutomationEventList( nil )
RL.SetAutomationEventList( eventList )
end
function RL.update( delta )
local moveDir = Vec2:new()
if RL.IsKeyDown( RL.KEY_RIGHT ) then
moveDir.x = 1
elseif RL.IsKeyDown( RL.KEY_LEFT ) then
moveDir.x = -1
end
if RL.IsKeyDown( RL.KEY_DOWN ) then
moveDir.y = 1
elseif RL.IsKeyDown( RL.KEY_UP ) then
moveDir.y = -1
end
player.pos:addEq( moveDir:scale( player.speed * delta ) )
-- Events.
if RL.IsKeyPressed( RL.KEY_S ) then
evenRecording = not evenRecording
if evenRecording then
RL.StartAutomationEventRecording()
else
RL.StopAutomationEventRecording()
end
end
if RL.IsKeyPressed( RL.KEY_A ) then
eventPlaying = not eventPlaying
evenRecording = false
playFrameCounter = 0
currentPlayFrame = 0
end
if eventPlaying then
while playFrameCounter == RL.GetAutomationEventFrame( RL.GetAutomationEvent( eventList, currentPlayFrame ) ) do
RL.TraceLog( RL.LOG_INFO, "playFrameCounter: "..playFrameCounter.."\tcurrentPlayFrame: "..currentPlayFrame )
RL.PlayAutomationEvent( RL.GetAutomationEvent( eventList, currentPlayFrame ) )
currentPlayFrame = currentPlayFrame + 1
if currentPlayFrame == RL.GetAutomationEventListCount( eventList ) then
eventPlaying = false
currentPlayFrame = 0
playFrameCounter = 0
RL.TraceLog( RL.LOG_INFO, "FINISH PLAYING!" )
break
end
end
playFrameCounter = playFrameCounter + 1
end
end
function RL.draw()
RL.ClearBackground( RL.RAYWHITE )
RL.DrawCircle( player.pos, 8.0, RL.BLUE )
local text = "Toggle recording: S\nToggle play: A\n"
local textColor = RL.GREEN
if evenRecording then
text = text.."Recording"
textColor = RL.RED
elseif eventPlaying then
text = text.."Playing"
textColor = RL.BLUE
end
RL.DrawText( text, { 20, 20 }, 20, textColor )
end

View File

@@ -153,4 +153,32 @@ function Quaternion:transform( mat )
return Quaternion:new( RL.QuaternionTransform( self, mat ) )
end
function Quaternion:addEq( q2 )
self.x = self.x + q2.x
self.y = self.y + q2.y
self.z = self.z + q2.z
self.w = self.w + q2.w
end
function Quaternion:subEq( q2 )
self.x = self.x - q2.x
self.y = self.y - q2.y
self.z = self.z - q2.z
self.w = self.w - q2.w
end
function Quaternion:mulEq( q2 )
self.x = self.x * q2.x
self.y = self.y * q2.y
self.z = self.z * q2.z
self.w = self.w * q2.w
end
function Quaternion:divEq( q2 )
self.x = self.x / q2.x
self.y = self.y / q2.y
self.z = self.z / q2.z
self.w = self.w / q2.w
end
return Quaternion

View File

@@ -181,4 +181,24 @@ function Vector2:equals( v2 )
return RL.Vector2Equals( self, v2 )
end
function Vector2:addEq( v2 )
self.x = self.x + v2.x
self.y = self.y + v2.y
end
function Vector2:subEq( v2 )
self.x = self.x - v2.x
self.y = self.y - v2.y
end
function Vector2:mulEq( v2 )
self.x = self.x * v2.x
self.y = self.y * v2.y
end
function Vector2:divEq( v2 )
self.x = self.x / v2.x
self.y = self.y / v2.y
end
return Vector2

View File

@@ -208,4 +208,28 @@ function Vector3:equals( v2 )
return RL.Vector3Equals( self, v2 )
end
function Vector3:addEq( v2 )
self.x = self.x + v2.x
self.y = self.y + v2.y
self.z = self.z + v2.z
end
function Vector3:subEq( v2 )
self.x = self.x - v2.x
self.y = self.y - v2.y
self.z = self.z - v2.z
end
function Vector3:mulEq( v2 )
self.x = self.x * v2.x
self.y = self.y * v2.y
self.z = self.z * v2.z
end
function Vector3:divEq( v2 )
self.x = self.x / v2.x
self.y = self.y / v2.y
self.z = self.z / v2.z
end
return Vector3