From e7cc9350355b537549484dd4e86dabd38ba43ee8 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 14 Sep 2026 23:00:24 +0200 Subject: [PATCH] lol --- docs/odin.md | 22 ++++++++++++++++++++++ game/game.odin | 19 +++++++++++++------ src/event/event.odin | 13 +++++++------ src/main.odin | 4 ++++ src/test/test.odin | 5 +++++ 5 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 docs/odin.md create mode 100644 src/test/test.odin diff --git a/docs/odin.md b/docs/odin.md new file mode 100644 index 0000000..d09b5b2 --- /dev/null +++ b/docs/odin.md @@ -0,0 +1,22 @@ +# Odin + +This document contains specifics about the workings of the Odin programming +language, dynamic linking and state management design patterns. These are +tested and validated findings, for continued reference by me. + +## Dynamic Library Memory + +When a program loads in a dynamic library, what happens with package globals? + +Findings (macOS): +- The package globals are shared between the host and the lib +- After hot reloading the lib, the memory of the packge is not refreshed, + it keeps pointing to the package global of the host + +The clanker states this is due to "flat-namespace symbol interposition". + +Linux "ELF has symbol preemption: when resolving references, ld.so searches +globals scope in order — executable first, then loaded shared objects". + +Windows PE has no interposition at all, every module (exe and each DLL) has its +own symbol table. diff --git a/game/game.odin b/game/game.odin index fd3e969..1975a45 100644 --- a/game/game.odin +++ b/game/game.odin @@ -5,11 +5,12 @@ import "core:time" import "core:fmt" import "sindri:core" +import "sindri:test" // ----------------------------------------- Game_Memory :: struct { - should_close: bool + should_close: bool, } g: ^Game_Memory @@ -54,6 +55,8 @@ settings :: proc() -> core.Settings { @(export) init_once :: proc() { fmt.println("init once") + + test.test_proc = proc() {} } @(export) @@ -62,6 +65,8 @@ init :: proc() { g = new(Game_Memory) memory_set(g) + + test.test_proc = proc() { asd := 2 } } @(export) @@ -71,6 +76,10 @@ update :: proc(dt: f32) { if input.key_state(.Key_Escape) == .Press { g.should_close = true } + + fmt.println("GAME:", test.test) + fmt.printf("pointer: %p | %p\n", &test.test, &test.test_proc) + test.test += 1 } @(export) @@ -84,19 +93,17 @@ start := time.tick_now() should_close :: proc() -> bool { elapsed := time.tick_since(start) seconds := time.duration_seconds(elapsed) - if seconds > 4 do return true + // if seconds > 4 do return true return g.should_close } @(export) force_reload :: proc() -> bool { - // TODO: read keypress - return false + return input.key_state(.Key_F5) == .Press } @(export) force_restart :: proc() -> bool { - // TODO: read keypress - return false + return input.key_state(.Key_F6) == .Press } diff --git a/src/event/event.odin b/src/event/event.odin index 4384446..512fbb8 100644 --- a/src/event/event.odin +++ b/src/event/event.odin @@ -9,7 +9,8 @@ import "sindri:input" // event category, bitfield (?) -Event_Data :: union { +// Event_Data :: union { +Event :: union { Window_Close_Event, Window_Resize_Event, Joystick_Connect_Event, @@ -23,10 +24,10 @@ Event_Data :: union { Mouse_Scroll_Event, } -Event :: struct { - data: Event_Data, - handled: bool, -} +// Event :: struct { +// data: Event_Data, +// handled: bool, +// } Window_Close_Event :: struct { handled: bool, @@ -94,7 +95,7 @@ Mouse_Scroll_Event :: struct { // Variables // I want to have a list of Listeners per Event type, but this is state -listeners: map[typeid][dynamic]Listener +// listeners: map[typeid][dynamic]Listener // ----------------------------------------- // Public functions diff --git a/src/main.odin b/src/main.odin index 59b82c1..9398dc4 100644 --- a/src/main.odin +++ b/src/main.odin @@ -2,6 +2,7 @@ package sindri import "core:fmt" import "core:time" +import "sindri:test" import "sindri:hot_reload" import "sindri:platform" @@ -41,6 +42,9 @@ main :: proc() { platform.os_poll_events() api.update(dt) + fmt.println("MAIN:", test.test) + fmt.printf("pointer: %p | %p\n", &test.test, &test.test_proc) + platform.frame(dt) dt = f32(time.duration_seconds(time.tick_since(start))) diff --git a/src/test/test.odin b/src/test/test.odin new file mode 100644 index 0000000..02a5fbe --- /dev/null +++ b/src/test/test.odin @@ -0,0 +1,5 @@ +package test + +test: int = 0 + +test_proc: proc()