Code2 Progress: more sokol stuff
This commit is contained in:
@@ -35,12 +35,11 @@ then prepare for multi-threaded "laned" tick: thread_wide_startup.
|
||||
@export
|
||||
startup :: proc(host_mem: ^ProcessMemory, thread_mem: ^ThreadMemory)
|
||||
{
|
||||
// Rad Debugger driving me crazy..
|
||||
// NOTE(Ed): This is not necessary, they're just loops for my sanity.
|
||||
for ; memory == nil; { memory = host_mem }
|
||||
for ; thread == nil; { thread = thread_mem }
|
||||
grime_set_profiler_module_context(& memory.spall_context)
|
||||
grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
// (Ignore RAD Debugger's values being null)
|
||||
memory = host_mem
|
||||
thread = thread_mem
|
||||
// grime_set_profiler_module_context(& memory.spall_context)
|
||||
// grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
profile(#procedure)
|
||||
|
||||
startup_tick := tick_now()
|
||||
@@ -126,14 +125,14 @@ hot_reload :: proc(host_mem: ^ProcessMemory, thread_mem: ^ThreadMemory)
|
||||
thread = thread_mem
|
||||
if thread.id == .Master_Prepper {
|
||||
sync_store(& memory, host_mem, .Release)
|
||||
grime_set_profiler_module_context(& memory.spall_context)
|
||||
// grime_set_profiler_module_context(& memory.spall_context)
|
||||
}
|
||||
else {
|
||||
// NOTE(Ed): This is problably not necessary, they're just loops for my sanity.
|
||||
for ; memory == nil; { sync_load(& memory, .Acquire) }
|
||||
for ; thread == nil; { thread = thread_mem }
|
||||
}
|
||||
grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
// grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
}
|
||||
profile(#procedure)
|
||||
// Do hot-reload stuff...
|
||||
@@ -177,7 +176,7 @@ tick_lane_startup :: proc(thread_mem: ^ThreadMemory)
|
||||
{
|
||||
if thread_mem.id != .Master_Prepper {
|
||||
thread = thread_mem
|
||||
grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
// grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
}
|
||||
profile(#procedure)
|
||||
}
|
||||
@@ -187,7 +186,7 @@ job_worker_startup :: proc(thread_mem: ^ThreadMemory)
|
||||
{
|
||||
if thread_mem.id != .Master_Prepper {
|
||||
thread = thread_mem
|
||||
grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
// grime_set_profiler_thread_buffer(& thread.spall_buffer)
|
||||
}
|
||||
profile(#procedure)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package sectr
|
||||
|
||||
import sokol_app "thirdparty:sokol/app"
|
||||
|
||||
//region Sokol App
|
||||
|
||||
sokol_app_init_callback :: proc "c" () {
|
||||
context = memory.client_memory.sokol_context
|
||||
log_print("sokol_app: Confirmed initialization")
|
||||
}
|
||||
|
||||
// This is being filled in but we're directly controlling the lifetime of sokol_app's execution.
|
||||
// So this will only get called during window pan or resize events (on Win32 at least)
|
||||
sokol_app_frame_callback :: proc "c" ()
|
||||
@@ -37,3 +40,220 @@ sokol_app_frame_callback :: proc "c" ()
|
||||
tick_lane_frametime( & client_tick, sokol_delta_ms, sokol_delta_ns, can_sleep = false )
|
||||
window.resized = false
|
||||
}
|
||||
|
||||
sokol_app_cleanup_callback :: proc "c" () {
|
||||
context = memory.client_memory.sokol_context
|
||||
log_print("sokol_app: Confirmed cleanup")
|
||||
}
|
||||
|
||||
sokol_app_alloc :: proc "c" ( size : uint, user_data : rawptr ) -> rawptr {
|
||||
context = memory.client_memory.sokol_context
|
||||
// block, error := mem_alloc( int(size), allocator = persistent_slab_allocator() )
|
||||
// ensure(error == AllocatorError.None, "sokol_app allocation failed")
|
||||
// return block
|
||||
// TODO(Ed): Implement
|
||||
return nil
|
||||
}
|
||||
|
||||
sokol_app_free :: proc "c" ( data : rawptr, user_data : rawptr ) {
|
||||
context = memory.client_memory.sokol_context
|
||||
// mem_free(data, allocator = persistent_slab_allocator() )
|
||||
// TODO(Ed): Implement
|
||||
}
|
||||
|
||||
sokol_app_log_callback :: proc "c" (
|
||||
tag: cstring,
|
||||
log_level: u32,
|
||||
log_item_id: u32,
|
||||
message_or_null: cstring,
|
||||
line_nr: u32,
|
||||
filename_or_null: cstring,
|
||||
user_data: rawptr)
|
||||
{
|
||||
context = memory.client_memory.sokol_context
|
||||
odin_level: LoggerLevel
|
||||
switch log_level {
|
||||
case 0: odin_level = .Fatal
|
||||
case 1: odin_level = .Error
|
||||
case 2: odin_level = .Warning
|
||||
case 3: odin_level = .Info
|
||||
}
|
||||
clone_backing: [16 * Kilo]byte
|
||||
|
||||
cloned_msg: string = "";
|
||||
if message_or_null != nil {
|
||||
cloned_msg = cstr_to_str_capped(message_or_null, clone_backing[:])
|
||||
}
|
||||
cloned_fname: string = ""
|
||||
if filename_or_null != nil {
|
||||
cloned_fname = cstr_to_str_capped(filename_or_null, clone_backing[len(cloned_msg):])
|
||||
}
|
||||
cloned_tag := cstr_to_str_capped(tag, clone_backing[len(cloned_msg) + len(cloned_fname):])
|
||||
log_print_fmt( "%-80s %s::%v", cloned_msg, cloned_tag, line_nr, level = odin_level )
|
||||
}
|
||||
|
||||
// TODO(Ed): Does this need to be queued to a separate thread?
|
||||
sokol_app_event_callback :: proc "c" (sokol_event: ^sokol_app.Event)
|
||||
{
|
||||
context = memory.client_memory.sokol_context
|
||||
event: InputEvent
|
||||
using event
|
||||
|
||||
_sokol_frame_id = sokol_event.frame_count
|
||||
frame_id = get_frametime().current_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:
|
||||
log_print_fmt("sokol_app - event: INVALID?")
|
||||
log_print_fmt("%v", sokol_event)
|
||||
|
||||
case .KEY_DOWN:
|
||||
if sokol_event.key_repeat do return
|
||||
|
||||
type = .Key_Pressed
|
||||
key = to_key_from_sokol( sokol_event.key_code )
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
// logf("Key pressed(sokol): %v", key)
|
||||
// logf("frame (sokol): %v", frame_id )
|
||||
|
||||
case .KEY_UP:
|
||||
if sokol_event.key_repeat do return
|
||||
|
||||
type = .Key_Released
|
||||
key = to_key_from_sokol( sokol_event.key_code )
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
// logf("Key released(sokol): %v", key)
|
||||
// logf("frame (sokol): %v", frame_id )
|
||||
|
||||
case .CHAR:
|
||||
if sokol_event.key_repeat do return
|
||||
|
||||
type = .Unicode
|
||||
codepoint = transmute(rune) sokol_event.char_code
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
|
||||
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 )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
|
||||
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 )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
|
||||
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 )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
|
||||
case .MOUSE_MOVE:
|
||||
type = .Mouse_Move
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
|
||||
case .MOUSE_ENTER:
|
||||
type = .Mouse_Enter
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
|
||||
case .MOUSE_LEAVE:
|
||||
type = .Mouse_Leave
|
||||
modifiers = to_modifiers_code_from_sokol( sokol_event.modifiers )
|
||||
sokol_app.consume_event()
|
||||
append_staged_input_events( event )
|
||||
|
||||
// TODO(Ed): Add support
|
||||
case .TOUCHES_BEGAN:
|
||||
case .TOUCHES_MOVED:
|
||||
case .TOUCHES_ENDED:
|
||||
case .TOUCHES_CANCELLED:
|
||||
|
||||
case .RESIZED: sokol_app.consume_event()
|
||||
case .ICONIFIED: sokol_app.consume_event()
|
||||
case .RESTORED: sokol_app.consume_event()
|
||||
case .FOCUSED: sokol_app.consume_event()
|
||||
case .UNFOCUSED: sokol_app.consume_event()
|
||||
case .SUSPENDED: sokol_app.consume_event()
|
||||
case .RESUMED: sokol_app.consume_event()
|
||||
case .QUIT_REQUESTED: sokol_app.consume_event()
|
||||
case .CLIPBOARD_PASTED: sokol_app.consume_event()
|
||||
case .FILES_DROPPED: sokol_app.consume_event()
|
||||
|
||||
case .DISPLAY_CHANGED:
|
||||
log_print_fmt("sokol_app - event: Display changed")
|
||||
log_print_fmt("refresh rate: %v", sokol_app.refresh_rate())
|
||||
monitor_refresh_hz := sokol_app.refresh_rate()
|
||||
sokol_app.consume_event()
|
||||
}
|
||||
}
|
||||
|
||||
//endregion Sokol App
|
||||
|
||||
//region Sokol GFX
|
||||
|
||||
sokol_gfx_alloc :: proc "c" ( size : uint, user_data : rawptr ) -> rawptr {
|
||||
context = memory.client_memory.sokol_context
|
||||
// block, error := mem_alloc( int(size), allocator = persistent_slab_allocator() )
|
||||
// ensure(error == AllocatorError.None, "sokol_gfx allocation failed")
|
||||
// return block
|
||||
// TODO(Ed): Implement
|
||||
return nil
|
||||
}
|
||||
|
||||
sokol_gfx_free :: proc "c" ( data : rawptr, user_data : rawptr ) {
|
||||
context = memory.client_memory.sokol_context
|
||||
// TODO(Ed): Implement
|
||||
// free(data, allocator = persistent_slab_allocator() )
|
||||
}
|
||||
|
||||
sokol_gfx_log_callback :: proc "c" (
|
||||
tag: cstring,
|
||||
log_level: u32,
|
||||
log_item_id: u32,
|
||||
message_or_null: cstring,
|
||||
line_nr: u32,
|
||||
filename_or_null: cstring,
|
||||
user_data: rawptr)
|
||||
{
|
||||
context = memory.client_memory.sokol_context
|
||||
odin_level : LoggerLevel
|
||||
switch log_level {
|
||||
case 0: odin_level = .Fatal
|
||||
case 1: odin_level = .Error
|
||||
case 2: odin_level = .Warning
|
||||
case 3: odin_level = .Info
|
||||
}
|
||||
clone_backing: [16 * Kilo]byte
|
||||
|
||||
cloned_msg : string = ""
|
||||
if message_or_null != nil {
|
||||
cloned_msg = cstr_to_str_capped(message_or_null, clone_backing[:])
|
||||
}
|
||||
cloned_fname : string = ""
|
||||
if filename_or_null != nil {
|
||||
cloned_fname = cstr_to_str_capped(filename_or_null, clone_backing[len(cloned_msg):])
|
||||
}
|
||||
cloned_tag := cstr_to_str_capped(tag, clone_backing[len(cloned_msg) + len(cloned_fname):])
|
||||
log_print_fmt( "%-80s %s::%v", cloned_msg, cloned_tag, line_nr, level = odin_level )
|
||||
}
|
||||
|
||||
//endregion Sokol GFX
|
||||
|
||||
Reference in New Issue
Block a user