1-- $LastChangedDate: 2010-05-25 21:26:05 -0400 (Tue, 25 May 2010) $
2-- LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
3-- Lua Replay class (augments sim.Replay).
4-- See module.txt for documentation and pitfalls.
5
6-- EXECUTE_MODE_PHYSICS is the most realistic but vulnerable
7-- to malfunctioning if system is running too slow or
8-- player selects a different aircraft type.
9-- EXECUTE_MODE_GRAPHICS_PHYSICS is a compromise which ensures
10-- every point is replayed while replaying control (gears, brakes, etc).
11sim.Replay.EXECUTE_MODE_GRAPHICS          = 1
12sim.Replay.EXECUTE_MODE_PHYSICS           = 2
13sim.Replay.EXECUTE_MODE_GRAPHICS_PHYSICS  = 3
14sim.Replay.EXECUTE_MODE_DEFAULT           = sim.Replay.EXECUTE_MODE_GRAPHICS_PHYSICS
15
16-- Class data members.
17Replay = {
18    freq = 20,   -- milliseconds
19}
20
21-- ctor.  executeMode is optional.
22function Replay:New( craft, executeMode )
23    self = lib.NewInstance( Replay )
24    self.replay    = sim.Replay:New( craft, Replay.freq, executeMode or sim.Replay.EXECUTE_MODE_DEFAULT )
25    self.recording = false
26    return self
27end
28
29-- Return true if replay is playing.
30function Replay:IfPlaying()
31    -- Query the underlying C++ object (Replay::IfPlaying()).
32    return self.replay:IfPlaying()
33end
34
35-- Return true if recording replay.
36function Replay:IfRecording()
37    return self.recording
38end
39
40-- Load replay from file.
41function Replay:Load( filename )
42    return self.replay:Load( filename )
43end
44
45-- Save replay to file.
46function Replay:Save( filename )
47    return self.replay:Save( filename )
48end
49
50-- Enter play mode.
51function Replay:Play()
52    self.recording = false
53    self.replay:Play()
54end
55
56-- Start recording replay
57function Replay:Record()
58    self.recording = true
59    self.replay:Record()
60end
61
62-- Stop playing or recording.
63function Replay:Stop( object )
64    self.recording = false
65    self.replay:Stop()
66end
67