Powervessel/app.odin

66 lines
1.7 KiB
Odin
Raw Normal View History

2024-08-14 11:53:51 +00:00
package app
import "window"
2024-08-14 11:53:51 +00:00
// NOTE: Restart means it's like the program's *just* been opened. Typically happens when memory layout changes
// Reload means that the code has changed, but state is still the same. More seamless and you're in the same place in your program.
// All global data in your program MUST be in this struct
App_Memory :: struct {
current_frame: int,
}
g_mem: ^App_Memory
// Called upon first run OR full restart. Use it to set starting values (i.e. Player position, menu state)
// Return value is window settings
2024-08-14 11:53:51 +00:00
@(export)
app_init :: proc() -> window.Config {
2024-08-14 11:53:51 +00:00
g_mem = new(App_Memory)
return {
title = "Powervessel Template",
width = 1280,
height = 720,
resizable = true,
clear_color = {1.0, 0.0, 0.0, 1.0}
}
2024-08-14 11:53:51 +00:00
}
// Typical update loop
@(export)
app_update :: proc() -> bool {
g_mem.current_frame += 1
return true
}
// Called when program closes OR full restart. Primarily for clearing memory
@(export)
app_shutdown :: proc() {
free(g_mem)
}
// You can set conditions in your program for it to reload other than recompiling the DLL
// e.g. check for a keypress, or if the user clicks a button
@(export)
app_should_reload :: proc() -> bool {
return false
}
// Same as app_should_reload, but for complete restart
@(export)
app_should_restart :: proc() -> bool {
return false
}
// Returns the global memory pointer and the size of the struct. Used to tell if we need to full restart
@(export)
app_memory :: proc() -> (rawptr, int) {
return g_mem, size_of(g_mem)
}
// Replace global state. Used when reloading in order to maintain state.
@(export)
app_memory_set :: proc(mem: ^App_Memory) {
g_mem = mem
}