Created Event_Queue and moved to a more correct windows architecture.

This commit is contained in:
2025-11-21 03:40:01 +01:00
parent 0748bd7a7a
commit 0c61dd1de5
2 changed files with 172 additions and 137 deletions

View File

@@ -1,13 +1,19 @@
package window
import "core:container/queue"
import "core:fmt"
Window :: struct {
title: string,
width, height: u16,
backend: Backend_Info,
event_queue: Event_Queue,
}
Event_Queue :: queue.Queue(Event)
Event :: union {
Event_Quit,
Event_Input,
@@ -54,7 +60,6 @@ Event_Input :: union {
}
Event_Resize :: struct {
old_width, old_height: u16,
new_width, new_height: u16,
}
@@ -64,6 +69,7 @@ create :: proc(width, height: u16) -> (^Window, bool) {
w := new(Window)
w.width = width
w.height = height
queue.init(&w.event_queue, 1024)
when ODIN_OS == .Windows {
if !init_window_windows(w) {
@@ -95,7 +101,7 @@ set_title :: proc(window: ^Window, title: string) {
get_pointer_to_surface :: proc(window: ^Window) -> rawptr {
when ODIN_OS == .Windows {
// fmt.printfln("HWND: %v.", window.backend.hwnd)
fmt.printfln("HWND: %v.", window.backend.hwnd)
return window.backend.hwnd
}
else {
@@ -105,29 +111,38 @@ get_pointer_to_surface :: proc(window: ^Window) -> rawptr {
update :: proc(window: ^Window, out_event: ^Event) -> bool {
assert(window != nil)
assert(out_event != nil)
event: Event
when ODIN_OS == .Windows {
event = update_windows(window)
update_windows(window)
}
else {
#assert(false, "Missing implementation for 'set_title'.")
}
out_event^ = nil
out_event^ = event
if out_event^ == nil {
event, ok := queue.pop_front_safe(&window.event_queue)
if !ok {
return false
}
assert(event != nil)
out_event^ = event
return true
}
destroy :: proc(window: ^Window) {
assert(window != nil)
destroy_windows(window)
when ODIN_OS == .Windows {
destroy_windows(window)
}
else {
#assert(false, "Missing implementation for 'destroy'.")
}
queue.destroy(&window.event_queue)
free(window)
window^ = {}
}