-- $LastChangedDate: 2010-05-25 21:26:05 -0400 (Tue, 25 May 2010) $
-- LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
-- Lua Replay class (augments sim.Replay).
-- See module.txt for documentation and pitfalls.

-- EXECUTE_MODE_PHYSICS is the most realistic but vulnerable
-- to malfunctioning if system is running too slow or
-- player selects a different aircraft type.
-- EXECUTE_MODE_GRAPHICS_PHYSICS is a compromise which ensures
-- every point is replayed while replaying control (gears, brakes, etc).
sim.Replay.EXECUTE_MODE_GRAPHICS          = 1
sim.Replay.EXECUTE_MODE_PHYSICS           = 2
sim.Replay.EXECUTE_MODE_GRAPHICS_PHYSICS  = 3
sim.Replay.EXECUTE_MODE_DEFAULT           = sim.Replay.EXECUTE_MODE_GRAPHICS_PHYSICS

-- Class data members.
Replay = {
    freq = 20,   -- milliseconds
}

-- ctor.  executeMode is optional.
function Replay:New( craft, executeMode )
    self = lib.NewInstance( Replay )
    self.replay    = sim.Replay:New( craft, Replay.freq, executeMode or sim.Replay.EXECUTE_MODE_DEFAULT )
    self.recording = false
    return self
end

-- Return true if replay is playing.
function Replay:IfPlaying()
    -- Query the underlying C++ object (Replay::IfPlaying()).
    return self.replay:IfPlaying()
end

-- Return true if recording replay.
function Replay:IfRecording()
    return self.recording
end

-- Load replay from file.
function Replay:Load( filename )
    return self.replay:Load( filename )
end

-- Save replay to file.
function Replay:Save( filename )
    return self.replay:Save( filename )
end

-- Enter play mode.
function Replay:Play()
    self.recording = false
    self.replay:Play()
end

-- Start recording replay
function Replay:Record()
    self.recording = true
    self.replay:Record()
end

-- Stop playing or recording.
function Replay:Stop( object )
    self.recording = false
    self.replay:Stop()
end
