Code2 Progress: more sokol stuff

This commit is contained in:
2025-10-18 15:01:19 -04:00
parent 5a3b8ef3b9
commit 62979b480e
12 changed files with 388 additions and 173 deletions

View File

@@ -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)
}

View File

@@ -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

View File

@@ -19,6 +19,7 @@ import "core:log"
LoggerLevel :: log.Level
import "core:mem"
AllocatorError :: mem.Allocator_Error
// Used strickly for the logger
Odin_Arena :: mem.Arena
odin_arena_allocator :: mem.arena_allocator
@@ -60,14 +61,38 @@ import "core:time"
tick_now :: time.tick_now
import "codebase:grime"
Logger :: grime.Logger
logger_init :: grime.logger_init
to_odin_logger :: grime.to_odin_logger
Array :: grime.Array
array_to_slice :: grime.array_to_slice
array_append_array :: grime.array_append_array
array_append_slice :: grime.array_append_slice
array_append_value :: grime.array_append_value
array_back :: grime.array_back
array_clear :: grime.array_clear
// Logging
Logger :: grime.Logger
logger_init :: grime.logger_init
// Memory
mem_alloc :: grime.mem_alloc
mem_copy :: grime.mem_copy
mem_copy_non_overlapping :: grime.mem_copy_non_overlapping
mem_zero :: grime.mem_zero
slice_zero :: grime.slice_zero
// Ring Buffer
FRingBuffer :: grime.FRingBuffer
FRingBufferIterator :: grime.FRingBufferIterator
ringbuf_fixed_peak_back :: grime.ringbuf_fixed_peak_back
ringbuf_fixed_push :: grime.ringbuf_fixed_push
ringbuf_fixed_push_slice :: grime.ringbuf_fixed_push_slice
iterator_ringbuf_fixed :: grime.iterator_ringbuf_fixed
next_ringbuf_fixed_iterator :: grime.next_ringbuf_fixed_iterator
// Strings
cstr_to_str_capped :: grime.cstr_to_str_capped
to_odin_logger :: grime.to_odin_logger
// Operating System
set__scheduler_granularity :: grime.set__scheduler_granularity
grime_set_profiler_module_context :: grime.set_profiler_module_context
grime_set_profiler_thread_buffer :: grime.set_profiler_thread_buffer
// grime_set_profiler_module_context :: grime.set_profiler_module_context
// grime_set_profiler_thread_buffer :: grime.set_profiler_thread_buffer
Kilo :: 1024
Mega :: Kilo * 1024
@@ -141,13 +166,24 @@ add :: proc {
add_r2f4,
add_biv3f4,
}
append :: proc {
array_append_array,
array_append_slice,
array_append_value,
}
array_append :: proc {
array_append_array,
array_append_slice,
array_append_value,
}
biv3f4 :: proc {
biv3f4_via_f32s,
v3f4_to_biv3f4,
}
bivec :: biv3f4
clear :: proc {
array_clear,
}
cross :: proc {
cross_s,
cross_v2,
@@ -156,11 +192,9 @@ cross :: proc {
cross_v3f4_uv3f4,
cross_u3f4_v3f4,
}
div :: proc {
div_biv3f4_f32,
}
dot :: proc {
sdot,
vdot,
@@ -171,75 +205,76 @@ dot :: proc {
dot_v3f4_uv3f4,
dot_uv3f4_v3f4,
}
equal :: proc {
equal_r2f4,
}
is_power_of_two :: proc {
is_power_of_two_u32,
// is_power_of_two_uintptr,
}
iterator :: proc {
iterator_ringbuf_fixed,
}
mov_avg_exp :: proc {
mov_avg_exp_f32,
mov_avg_exp_f64,
}
mul :: proc {
mul_biv3f4,
mul_biv3f4_f32,
mul_f32_biv3f4,
}
join :: proc {
join_r2f4,
}
inverse_sqrt :: proc {
inverse_sqrt_f32,
}
next :: proc {
next_ringbuf_fixed_iterator,
}
point3 :: proc {
v3f4_to_point3f4,
}
pow2 :: proc {
pow2_v3f4,
}
peek_back :: proc {
ringbuf_fixed_peak_back,
}
push :: proc {
ringbuf_fixed_push,
ringbuf_fixed_push_slice,
}
quatf4 :: proc {
quatf4_from_rotor3f4,
}
regress :: proc {
regress_biv3f4,
}
rotor3 :: proc {
rotor3f4_via_comps_f4,
rotor3f4_via_bv_s_f4,
// rotor3f4_via_from_to_v3f4,
}
size :: proc {
size_r2f4,
}
sub :: proc {
sub_r2f4,
sub_biv3f4,
// join_point3_f4,
// join_pointflat3_f4,
}
to_slice :: proc {
array_to_slice,
}
v2f4 :: proc {
v2f4_from_f32s,
v2f4_from_scalar,
v2f4_from_v2s4,
v2s4_from_v2f4,
}
v3f4 :: proc {
v3f4_via_f32s,
biv3f4_to_v3f4,
@@ -247,14 +282,12 @@ v3f4 :: proc {
pointflat3f4_to_v3f4,
uv3f4_to_v3f4,
}
v2 :: proc {
v2f4_from_f32s,
v2f4_from_scalar,
v2f4_from_v2s4,
v2s4_from_v2f4,
}
v3 :: proc {
v3f4_via_f32s,
biv3f4_to_v3f4,
@@ -262,12 +295,14 @@ v3 :: proc {
pointflat3f4_to_v3f4,
uv3f4_to_v3f4,
}
v4 :: proc {
uv4f4_to_v4f4,
}
wedge :: proc {
wedge_v3f4,
wedge_biv3f4,
}
zero :: proc {
mem_zero,
slice_zero,
}