Got project saving/loading initally working
This commit is contained in:
107
code/env.odin
107
code/env.odin
@ -25,11 +25,25 @@ Memory :: struct {
|
||||
logger : Logger,
|
||||
}
|
||||
|
||||
save_snapshot :: proc( snapshot : [^]u8 ) {
|
||||
state := get_state()
|
||||
|
||||
// state.font_rec_mono_semicasual_reg
|
||||
// state.default_font
|
||||
|
||||
live_ptr := cast( ^ rawptr ) memory.live.curr_block.base
|
||||
mem.copy_non_overlapping( & snapshot[0], live_ptr, memory_chunk_size )
|
||||
}
|
||||
|
||||
load_snapshot :: proc( snapshot : [^]u8 ) {
|
||||
live_ptr := cast( ^ rawptr ) memory.live.curr_block.base
|
||||
mem.copy_non_overlapping( live_ptr, snapshot, memory_chunk_size )
|
||||
}
|
||||
|
||||
State :: struct {
|
||||
input_data : [2] InputState,
|
||||
|
||||
input_prev : ^ InputState,
|
||||
input : ^ InputState,
|
||||
input_prev : ^ InputState,
|
||||
input : ^ InputState,
|
||||
|
||||
debug : DebugData,
|
||||
|
||||
@ -48,17 +62,20 @@ State :: struct {
|
||||
default_font : Font,
|
||||
}
|
||||
|
||||
get_state :: proc() -> (^ State) {
|
||||
return cast( ^ State ) raw_data( memory.persistent.backing.data )
|
||||
}
|
||||
|
||||
Project :: struct {
|
||||
path : string,
|
||||
name : string,
|
||||
|
||||
// TODO(Ed) : Support multiple workspaces
|
||||
workspace : Workspace
|
||||
}
|
||||
|
||||
Workspace :: struct {
|
||||
|
||||
}
|
||||
|
||||
get_state :: proc() -> (^ State) {
|
||||
return cast( ^ State ) raw_data( memory.persistent.backing.data )
|
||||
name : string
|
||||
}
|
||||
|
||||
DebugData :: struct {
|
||||
@ -92,77 +109,3 @@ poll_debug_actions :: proc( actions : ^ DebugActions, input : ^ InputState )
|
||||
|
||||
show_mouse_pos = keyboard.right_alt.ended_down && pressed(keyboard.M)
|
||||
}
|
||||
|
||||
save_snapshot :: proc( snapshot : [^]u8 ) {
|
||||
state := get_state()
|
||||
|
||||
// state.font_rec_mono_semicasual_reg
|
||||
// state.default_font
|
||||
|
||||
live_ptr := cast( ^ rawptr ) memory.live.curr_block.base
|
||||
mem.copy_non_overlapping( & snapshot[0], live_ptr, memory_chunk_size )
|
||||
}
|
||||
|
||||
load_snapshot :: proc( snapshot : [^]u8 ) {
|
||||
live_ptr := cast( ^ rawptr ) memory.live.curr_block.base
|
||||
mem.copy_non_overlapping( live_ptr, snapshot, memory_chunk_size )
|
||||
}
|
||||
|
||||
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 ) {
|
||||
result := os.remove( path )
|
||||
verify( result != os.ERROR_NONE, "Failed to delete replay file before beginning a new one" )
|
||||
}
|
||||
|
||||
replay_file, open_error := os.open( path, os.O_RDWR | os.O_CREATE )
|
||||
verify( open_error != os.ERROR_NONE, "Failed to create or open the replay file" )
|
||||
|
||||
os.seek( replay_file, 0, 0 )
|
||||
|
||||
replay := & memory.replay
|
||||
replay.active_file = replay_file
|
||||
replay.mode = ReplayMode.Record
|
||||
}
|
||||
|
||||
replay_recording_end :: proc() {
|
||||
replay := & memory.replay
|
||||
replay.mode = ReplayMode.Off
|
||||
|
||||
os.seek( replay.active_file, 0, 0 )
|
||||
os.close( replay.active_file )
|
||||
}
|
||||
|
||||
replay_playback_begin :: proc( path : string )
|
||||
{
|
||||
verify( ! file_exists( path ), "Failed to find replay file" )
|
||||
|
||||
replay_file, open_error := os.open( path, os.O_RDWR | os.O_CREATE )
|
||||
verify( open_error != os.ERROR_NONE, "Failed to create or open the replay file" )
|
||||
|
||||
os.seek( replay_file, 0, 0 )
|
||||
|
||||
replay := & memory.replay
|
||||
replay.active_file = replay_file
|
||||
replay.mode = ReplayMode.Playback
|
||||
}
|
||||
|
||||
replay_playback_end :: proc() {
|
||||
input := get_state().input
|
||||
replay := & memory.replay
|
||||
replay.mode = ReplayMode.Off
|
||||
os.seek( replay.active_file, 0, 0 )
|
||||
os.close( replay.active_file )
|
||||
}
|
||||
|
Reference in New Issue
Block a user