2024-02-09 10:09:58 -08:00
|
|
|
package sectr
|
|
|
|
|
|
|
|
import "core:os"
|
|
|
|
|
|
|
|
ReplayMode :: enum {
|
|
|
|
Off,
|
|
|
|
Record,
|
|
|
|
Playback,
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplayState :: struct {
|
|
|
|
loop_active : b32,
|
|
|
|
mode : ReplayMode,
|
|
|
|
active_file : os.Handle
|
|
|
|
}
|
|
|
|
|
|
|
|
replay_recording_begin :: proc( path : string )
|
|
|
|
{
|
|
|
|
if file_exists( path ) {
|
2024-02-27 04:50:57 -08:00
|
|
|
result := file_remove( path )
|
2024-02-09 10:09:58 -08:00
|
|
|
verify( result != os.ERROR_NONE, "Failed to delete replay file before beginning a new one" )
|
|
|
|
}
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
replay_file, open_error := file_open( path, FileFlag_ReadWrite | FileFlag_Create )
|
2024-02-09 10:09:58 -08:00
|
|
|
verify( open_error != os.ERROR_NONE, "Failed to create or open the replay file" )
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
file_seek( replay_file, 0, 0 )
|
2024-02-09 10:09:58 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
replay := & Memory_App.replay
|
2024-02-09 10:09:58 -08:00
|
|
|
replay.active_file = replay_file
|
|
|
|
replay.mode = ReplayMode.Record
|
|
|
|
}
|
|
|
|
|
|
|
|
replay_recording_end :: proc() {
|
2024-02-27 04:50:57 -08:00
|
|
|
replay := & Memory_App.replay
|
2024-02-09 10:09:58 -08:00
|
|
|
replay.mode = ReplayMode.Off
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
file_seek( replay.active_file, 0, 0 )
|
|
|
|
file_close( replay.active_file )
|
2024-02-09 10:09:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
replay_playback_begin :: proc( path : string )
|
|
|
|
{
|
|
|
|
verify( ! file_exists( path ), "Failed to find replay file" )
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
replay_file, open_error := file_open( path, FileFlag_ReadWrite | FileFlag_Create )
|
2024-02-09 10:09:58 -08:00
|
|
|
verify( open_error != os.ERROR_NONE, "Failed to create or open the replay file" )
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
file_seek( replay_file, 0, 0 )
|
2024-02-09 10:09:58 -08:00
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
replay := & Memory_App.replay
|
2024-02-09 10:09:58 -08:00
|
|
|
replay.active_file = replay_file
|
|
|
|
replay.mode = ReplayMode.Playback
|
|
|
|
}
|
|
|
|
|
|
|
|
replay_playback_end :: proc() {
|
|
|
|
input := get_state().input
|
2024-02-27 04:50:57 -08:00
|
|
|
replay := & Memory_App.replay
|
2024-02-09 10:09:58 -08:00
|
|
|
replay.mode = ReplayMode.Off
|
2024-02-27 04:50:57 -08:00
|
|
|
file_seek( replay.active_file, 0, 0 )
|
|
|
|
file_close( replay.active_file )
|
2024-02-09 10:09:58 -08:00
|
|
|
}
|