Started to setup input events based off sokol
Will replace the input polling done with raylib. Going to also provide the more robust input tracking for consuming events with the UI interactions
This commit is contained in:
@ -110,19 +110,30 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
for & input in input_data {
|
||||
using input
|
||||
error : AllocatorError
|
||||
keyboard_events.keys_pressed, error = make( Array(KeyCode), Kilo, persistent_slab_allocator() )
|
||||
ensure(error == AllocatorError.None, "Failed to allocate input.keyboard_events.keys_pressed array")
|
||||
keyboard_events.chars_pressed, error = make( Array(rune), Kilo, persistent_slab_allocator() )
|
||||
ensure(error == AllocatorError.None, "Failed to allocate input.keyboard_events.chars_pressed array")
|
||||
|
||||
events, error = make( Array(InputEvent), Kilo, persistent_slab_allocator() )
|
||||
ensure(error == AllocatorError.None, "Failed to allocate input.events array")
|
||||
|
||||
key_events, error = make( Array(InputKeyEvent), Kilo, persistent_slab_allocator() )
|
||||
ensure(error == AllocatorError.None, "Failed to allocate key_events array")
|
||||
|
||||
mouse_events, error = make( Array(InputMouseEvent), Kilo, persistent_slab_allocator() )
|
||||
ensure(error == AllocatorError.None, "Failed to allocate mouse_events array")
|
||||
|
||||
codes_pressed, error = make( Array(rune), Kilo, persistent_slab_allocator() )
|
||||
ensure(error == AllocatorError.None, "Failed to allocate codes_pressed array")
|
||||
}
|
||||
|
||||
input_staged_events, error := make( Array(InputEvent), Kilo, persistent_slab_allocator() )
|
||||
ensure(error == AllocatorError.None, "Failed to allocate input_staged_events array")
|
||||
}
|
||||
|
||||
// Configuration Load
|
||||
// TODO(Ed): Make this actually load from an ini
|
||||
{
|
||||
using config
|
||||
resolution_width = 1000
|
||||
resolution_height = 600
|
||||
resolution_width = 1600
|
||||
resolution_height = 900
|
||||
refresh_rate = 0
|
||||
|
||||
cam_min_zoom = 0.10
|
||||
@ -281,19 +292,19 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
|
||||
// path_squidgy_slimes := strings.concatenate( { Path_Assets, "Squidgy Slimes.ttf" } )
|
||||
// font_squidgy_slimes = font_load( path_squidgy_slimes, 24.0, "Squidgy_Slime" )
|
||||
|
||||
// path_firacode := strings.concatenate( { Path_Assets, "FiraCode-Regular.ttf" } )
|
||||
// font_firacode = font_load( path_firacode, 24.0, "FiraCode" )
|
||||
path_firacode := strings.concatenate( { Path_Assets, "FiraCode-Regular.ttf" } )
|
||||
font_firacode = font_load( path_firacode, 24.0, "FiraCode" )
|
||||
|
||||
// path_open_sans := strings.concatenate( { Path_Assets, "OpenSans-Regular.ttf" } )
|
||||
// font_open_sans = font_load( path_open_sans, 24.0, "OpenSans" )
|
||||
|
||||
path_noto_sans := strings.concatenate( { Path_Assets, "NotoSans-Regular.ttf" } )
|
||||
font_noto_sans = font_load( path_noto_sans, 24.0, "NotoSans" )
|
||||
// path_noto_sans := strings.concatenate( { Path_Assets, "NotoSans-Regular.ttf" } )
|
||||
// font_noto_sans = font_load( path_noto_sans, 24.0, "NotoSans" )
|
||||
|
||||
path_arial_unicode_ms := strings.concatenate( { Path_Assets, "Arial Unicode MS.ttf" } )
|
||||
font_arial_unicode_ms = font_load( path_arial_unicode_ms, 24.0, "Arial_Unicode_MS" )
|
||||
// path_arial_unicode_ms := strings.concatenate( { Path_Assets, "Arial Unicode MS.ttf" } )
|
||||
// font_arial_unicode_ms = font_load( path_arial_unicode_ms, 24.0, "Arial_Unicode_MS" )
|
||||
|
||||
default_font = font_arial_unicode_ms
|
||||
default_font = font_firacode
|
||||
log( "Default font loaded" )
|
||||
}
|
||||
|
||||
@ -391,18 +402,19 @@ reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem,
|
||||
set_profiler_module_context( prof )
|
||||
|
||||
context.logger = to_odin_logger( & Memory_App.logger )
|
||||
using Memory_App;
|
||||
|
||||
persistent = persistent_mem
|
||||
frame = frame_mem
|
||||
transient = transient_mem
|
||||
files_buffer = files_buffer_mem
|
||||
{
|
||||
using Memory_App;
|
||||
|
||||
persistent = persistent_mem
|
||||
frame = frame_mem
|
||||
transient = transient_mem
|
||||
files_buffer = files_buffer_mem
|
||||
}
|
||||
context.allocator = transient_allocator()
|
||||
context.temp_allocator = transient_allocator()
|
||||
|
||||
Memory_App.state = get_state()
|
||||
using state
|
||||
using Memory_App.state
|
||||
|
||||
sokol_context = context
|
||||
|
||||
@ -503,7 +515,7 @@ tick_work_frame :: #force_inline proc( host_delta_time_ms : f64 ) -> b32
|
||||
debug.draw_UI_padding_bounds = false
|
||||
debug.draw_ui_content_bounds = false
|
||||
|
||||
config.engine_refresh_hz = 165
|
||||
// config.engine_refresh_hz = 165
|
||||
|
||||
// config.color_theme = App_Thm_Light
|
||||
// config.color_theme = App_Thm_Dusk
|
||||
@ -535,8 +547,9 @@ tick_frametime :: #force_inline proc( client_tick : ^time.Tick, host_delta_time_
|
||||
context.temp_allocator = transient_allocator()
|
||||
|
||||
// profile("Client tick timing processing")
|
||||
// config.engine_refresh_hz = uint(monitor_refresh_hz)
|
||||
// config.engine_refresh_hz = 6
|
||||
|
||||
config.engine_refresh_hz = uint(monitor_refresh_hz)
|
||||
// config.engine_refresh_hz = 10
|
||||
frametime_target_ms = 1.0 / f64(config.engine_refresh_hz) * S_To_MS
|
||||
sub_ms_granularity_required := frametime_target_ms <= Frametime_High_Perf_Threshold_MS
|
||||
|
||||
@ -578,6 +591,8 @@ tick_frametime :: #force_inline proc( client_tick : ^time.Tick, host_delta_time_
|
||||
if frametime_elapsed_ms > 60.0 {
|
||||
log( str_fmt("Big tick! %v ms", frametime_elapsed_ms), LogLevel.Warning )
|
||||
}
|
||||
|
||||
frame += 1
|
||||
}
|
||||
|
||||
@export
|
||||
|
@ -93,14 +93,99 @@ sokol_app_log_callback :: proc "c" (
|
||||
logf( "%-80s %s::%v", cloned_msg, cloned_tag, line_nr, level = odin_level )
|
||||
}
|
||||
|
||||
sokol_app_event_callback :: proc "c" (event : ^sokol_app.Event)
|
||||
// TODO(Ed): This needs to queue to a job stask for a event callback handling thread to deal with.
|
||||
sokol_app_event_callback :: proc "c" (sokol_event : ^sokol_app.Event)
|
||||
{
|
||||
state := get_state(); using state
|
||||
context = sokol_context
|
||||
if event.type == sokol_app.Event_Type.DISPLAY_CHANGED {
|
||||
logf("sokol_app - event: Display changed")
|
||||
logf("refresh rate: %v", sokol_app.refresh_rate());
|
||||
monitor_refresh_hz := sokol_app.refresh_rate()
|
||||
|
||||
event : InputEvent
|
||||
using event
|
||||
|
||||
_sokol_frame_id = sokol_event.frame_count
|
||||
frame_id = frame
|
||||
|
||||
mouse.pos = { sokol_event.mouse_x, sokol_event.mouse_y }
|
||||
mouse.delta = { sokol_event.mouse_dx, sokol_event.mouse_dy }
|
||||
|
||||
switch sokol_event.type
|
||||
{
|
||||
case .INVALID:
|
||||
logf("sokol_app - event: INVALID?")
|
||||
logf("%v", sokol_event)
|
||||
|
||||
case .KEY_DOWN:
|
||||
type = .Key_Pressed
|
||||
key = to_key_from_sokol( sokol_event.key_code )
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .KEY_UP:
|
||||
type = .Key_Released
|
||||
key = to_key_from_sokol( sokol_event.key_code )
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .CHAR:
|
||||
type = .Unicode
|
||||
codepoint = transmute(rune) sokol_event.char_code
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .MOUSE_DOWN:
|
||||
type = .Mouse_Pressed
|
||||
mouse.btn = to_mouse_btn_from_sokol( sokol_event.mouse_button )
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .MOUSE_UP:
|
||||
type = .Mouse_Released
|
||||
mouse.btn = to_mouse_btn_from_sokol( sokol_event.mouse_button )
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .MOUSE_SCROLL:
|
||||
type = .Mouse_Scroll
|
||||
mouse.scroll = { sokol_event.scroll_x, sokol_event.scroll_y }
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .MOUSE_MOVE:
|
||||
type = .Mouse_Move
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .MOUSE_ENTER:
|
||||
type = .Mouse_Enter
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
case .MOUSE_LEAVE:
|
||||
type = .Mouse_Leave
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
|
||||
// TODO(Ed): Add support
|
||||
case .TOUCHES_BEGAN:
|
||||
case .TOUCHES_MOVED:
|
||||
case .TOUCHES_ENDED:
|
||||
case .TOUCHES_CANCELLED:
|
||||
|
||||
case .RESIZED:
|
||||
|
||||
case .ICONIFIED:
|
||||
|
||||
case .RESTORED:
|
||||
|
||||
case .FOCUSED:
|
||||
|
||||
case .UNFOCUSED:
|
||||
|
||||
case .SUSPENDED:
|
||||
|
||||
case .RESUMED:
|
||||
|
||||
case .QUIT_REQUESTED:
|
||||
|
||||
case .CLIPBOARD_PASTED:
|
||||
|
||||
case .FILES_DROPPED:
|
||||
|
||||
case .DISPLAY_CHANGED:
|
||||
logf("sokol_app - event: Display changed")
|
||||
logf("refresh rate: %v", sokol_app.refresh_rate())
|
||||
monitor_refresh_hz := sokol_app.refresh_rate()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package sectr
|
||||
|
||||
import ve "codebase:font/VEFontCache"
|
||||
import sokol_app "thirdparty:sokol/app"
|
||||
import sokol_gfx "thirdparty:sokol/gfx"
|
||||
import sokol_glue "thirdparty:sokol/glue"
|
||||
import "core:time"
|
||||
@ -80,8 +81,7 @@ render :: proc()
|
||||
// "Draw text" using immediate mode api
|
||||
{
|
||||
@static index : i32
|
||||
index += 1
|
||||
text_test_str := str_fmt("frametime: %0.2f\nframe id : %d", frametime_avg_ms, index )
|
||||
text_test_str := str_fmt("frametime : %0.6f\nframe id : %d\nsokol_frame: %d", frametime_avg_ms, frame, sokol_app.frame_count() )
|
||||
// log(text_test_str)
|
||||
// text_test_str := str_fmt("HELLO VE FONT CACHE!")
|
||||
// text_test_str := str_fmt("C")
|
||||
@ -95,7 +95,7 @@ render :: proc()
|
||||
ve.set_colour( & ve_font_cache, { 1.0, 1.0, 1.0, 1.0 } )
|
||||
ve.configure_snap( & ve_font_cache, u32(state.app_window.extent.x * 2.0), u32(state.app_window.extent.y * 2.0) )
|
||||
|
||||
ve.draw_text( & ve_font_cache, fdef.ve_id, text_test_str, {0.1, 0.2}, Vec2{1 / width, 1 / height} )
|
||||
ve.draw_text( & ve_font_cache, fdef.ve_id, text_test_str, {0.0, 0.975}, Vec2{1 / width, 1 / height} )
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ update :: proc( delta_time : f64 ) -> b32
|
||||
}
|
||||
|
||||
state.input, state.input_prev = swap( state.input, state.input_prev )
|
||||
// poll_input( state.input_prev, state.input )
|
||||
pull_staged_input_events( state.input, & state.staged_input_events )
|
||||
|
||||
debug_actions : DebugActions = {}
|
||||
// poll_debug_actions( & debug_actions, state.input )
|
||||
|
Reference in New Issue
Block a user