Baseline input and replay setup done. Needs testing and fixes
This commit is contained in:
119
code/api.odin
119
code/api.odin
@ -1,5 +1,6 @@
|
||||
package sectr
|
||||
|
||||
import "base:runtime"
|
||||
import "core:dynlib"
|
||||
import "core:fmt"
|
||||
import "core:mem"
|
||||
@ -9,7 +10,8 @@ import "core:slice"
|
||||
import "core:strings"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
Path_Assets :: "../assets/"
|
||||
Path_Assets :: "../assets/"
|
||||
Path_Input_Replay :: "scratch.sectr_replay"
|
||||
|
||||
ModuleAPI :: struct {
|
||||
lib : dynlib.Library,
|
||||
@ -25,7 +27,7 @@ ModuleAPI :: struct {
|
||||
}
|
||||
|
||||
@export
|
||||
startup :: proc( live_mem, snapshot_mem : ^ virtual.Arena )
|
||||
startup :: proc( live_mem : virtual.Arena, snapshot_mem : []u8 )
|
||||
{
|
||||
// Setup memory for the first time
|
||||
{
|
||||
@ -51,6 +53,9 @@ startup :: proc( live_mem, snapshot_mem : ^ virtual.Arena )
|
||||
state := new( State, tracked_allocator( memory.persistent ) )
|
||||
using state
|
||||
|
||||
input = & input_data[1]
|
||||
input_prev = & input_data[0]
|
||||
|
||||
// Rough setup of window with rl stuff
|
||||
screen_width = 1280
|
||||
screen_height = 1000
|
||||
@ -58,7 +63,7 @@ startup :: proc( live_mem, snapshot_mem : ^ virtual.Arena )
|
||||
rl.InitWindow( screen_width, screen_height, win_title )
|
||||
|
||||
// Determining current monitor and setting the target frametime based on it..
|
||||
monitor_id = rl.GetCurrentMonitor()
|
||||
monitor_id = rl.GetCurrentMonitor ()
|
||||
monitor_refresh_hz = rl.GetMonitorRefreshRate( monitor_id )
|
||||
rl.SetTargetFPS( monitor_refresh_hz )
|
||||
fmt.println( "Set target FPS to: %v", monitor_refresh_hz )
|
||||
@ -83,12 +88,21 @@ sectr_shutdown :: proc()
|
||||
return
|
||||
}
|
||||
state := get_state()
|
||||
rl.UnloadFont( state.font_rec_mono_semicasual_reg )
|
||||
rl.CloseWindow()
|
||||
|
||||
// Replay
|
||||
{
|
||||
os.close( state.replay.active_file )
|
||||
}
|
||||
|
||||
// Raylib
|
||||
{
|
||||
rl.UnloadFont ( state.font_rec_mono_semicasual_reg )
|
||||
rl.CloseWindow()
|
||||
}
|
||||
}
|
||||
|
||||
@export
|
||||
reload :: proc( live_mem, snapshot_mem : ^ virtual.Arena )
|
||||
reload :: proc( live_mem : virtual.Arena, snapshot_mem : []u8 )
|
||||
{
|
||||
using memory;
|
||||
block := live_mem.curr_block
|
||||
@ -100,6 +114,13 @@ reload :: proc( live_mem, snapshot_mem : ^ virtual.Arena )
|
||||
persistent = cast( ^TrackedAllocator ) & persistent_slice[0]
|
||||
transient = cast( ^TrackedAllocator ) & transient_slice[0]
|
||||
temp = cast( ^TrackedAllocator ) & temp_slice[0]
|
||||
|
||||
snapshot = snapshot_mem
|
||||
}
|
||||
|
||||
// TODO(Ed) : This lang really not have a fucking swap?
|
||||
swap :: proc( a, b : ^ $Type ) -> ( ^ Type, ^ Type ) {
|
||||
return b, a
|
||||
}
|
||||
|
||||
@export
|
||||
@ -107,6 +128,56 @@ update :: proc() -> b32
|
||||
{
|
||||
state := get_state(); using state
|
||||
|
||||
state.input, state.input_prev = swap( state.input, state.input_prev )
|
||||
poll_input( state.input_prev, state.input )
|
||||
|
||||
debug_actions : DebugActions
|
||||
poll_debug_actions( & debug_actions, state.input )
|
||||
|
||||
// Input Replay
|
||||
{
|
||||
if debug_actions.record_replay { #partial switch replay.mode
|
||||
{
|
||||
case ReplayMode.Off : {
|
||||
save_snapshot( & memory.snapshot[0] )
|
||||
replay_recording_begin( Path_Input_Replay )
|
||||
}
|
||||
case ReplayMode.Record : {
|
||||
replay_recording_end()
|
||||
}
|
||||
}}
|
||||
|
||||
if debug_actions.play_replay { switch replay.mode
|
||||
{
|
||||
case ReplayMode.Off : {
|
||||
replay_playback_begin( Path_Input_Replay )
|
||||
}
|
||||
case ReplayMode.Playback : {
|
||||
replay_playback_end()
|
||||
load_snapshot( & memory.snapshot[0] )
|
||||
}
|
||||
case ReplayMode.Record : {
|
||||
replay_recording_end( )
|
||||
load_snapshot( & memory.snapshot[0] )
|
||||
replay_playback_begin( Path_Input_Replay )
|
||||
}
|
||||
}}
|
||||
|
||||
if replay.loop_active
|
||||
{
|
||||
if replay.mode == ReplayMode.Record {
|
||||
record_input( replay.active_file, input )
|
||||
}
|
||||
else if replay.mode == ReplayMode.Playback {
|
||||
play_input( replay.active_file, input )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if debug_actions.show_mouse_pos {
|
||||
debug.mouse_vis = !debug.mouse_vis
|
||||
}
|
||||
|
||||
should_shutdown : b32 = ! cast(b32) rl.WindowShouldClose()
|
||||
return should_shutdown
|
||||
}
|
||||
@ -129,20 +200,39 @@ render :: proc()
|
||||
@static draw_text_scratch : [Kilobyte * 64]u8
|
||||
|
||||
state := get_state(); using state
|
||||
if ( draw_debug_text_y > 800 ) {
|
||||
draw_debug_text_y = 50
|
||||
if debug.draw_debug_text_y > 800 {
|
||||
debug.draw_debug_text_y = 50
|
||||
}
|
||||
|
||||
content := fmt.bprintf( draw_text_scratch[:], format, ..args )
|
||||
debug_text( content, 25, draw_debug_text_y )
|
||||
debug_text( content, 25, debug.draw_debug_text_y )
|
||||
|
||||
draw_debug_text_y += 16
|
||||
debug.draw_debug_text_y += 16
|
||||
}
|
||||
|
||||
draw_text( "Screen Width : %v", rl.GetScreenWidth() )
|
||||
draw_text( "Screen Width : %v", rl.GetScreenWidth () )
|
||||
draw_text( "Screen Height: %v", rl.GetScreenHeight() )
|
||||
|
||||
draw_debug_text_y = 50
|
||||
if pressed( input.keyboard.M ) {
|
||||
draw_text( "M Prssed" )
|
||||
}
|
||||
if pressed( input.keyboard.right_alt ) {
|
||||
draw_text( "Alt Pressed")
|
||||
}
|
||||
|
||||
if debug.mouse_vis {
|
||||
width : f32 = 32
|
||||
pos := debug.mouse_pos
|
||||
|
||||
mouse_rect : rl.Rectangle
|
||||
mouse_rect.x = pos.x - width/2
|
||||
mouse_rect.y = pos.y - width/2
|
||||
mouse_rect.width = width
|
||||
mouse_rect.height = width
|
||||
rl.DrawRectangleRec( mouse_rect, Color_White )
|
||||
}
|
||||
|
||||
debug.draw_debug_text_y = 50
|
||||
}
|
||||
|
||||
@export
|
||||
@ -150,8 +240,3 @@ clean_temp :: proc()
|
||||
{
|
||||
mem.tracking_allocator_clear( & memory.temp.tracker )
|
||||
}
|
||||
|
||||
get_state :: proc() -> (^ State)
|
||||
{
|
||||
return cast(^ State) raw_data( memory.persistent.backing.data )
|
||||
}
|
||||
|
Reference in New Issue
Block a user