2024-01-21 20:38:02 -08:00
|
|
|
package sectr
|
|
|
|
|
2024-02-08 07:50:36 -08:00
|
|
|
import "base:runtime"
|
|
|
|
import "core:fmt"
|
|
|
|
import "core:mem"
|
2024-01-29 23:27:45 -08:00
|
|
|
import "core:mem/virtual"
|
2024-02-08 07:50:36 -08:00
|
|
|
import "core:os"
|
|
|
|
|
|
|
|
import rl "vendor:raylib"
|
2024-01-29 23:27:45 -08:00
|
|
|
|
|
|
|
memory : Memory
|
|
|
|
|
|
|
|
memory_chunk_size :: 2 * Gigabyte
|
2024-02-13 14:16:39 -08:00
|
|
|
memory_persistent_size :: 256 * Megabyte
|
2024-01-29 23:27:45 -08:00
|
|
|
memory_trans_temp_size :: (memory_chunk_size - memory_persistent_size ) / 2
|
|
|
|
|
2024-02-13 14:16:39 -08:00
|
|
|
// TODO(Ed): There is an issue with mutex locks on the tracking allocator..
|
|
|
|
Use_TrackingAllocator :: false
|
2024-02-08 13:05:15 -08:00
|
|
|
|
2024-02-13 14:16:39 -08:00
|
|
|
when Use_TrackingAllocator
|
|
|
|
{
|
|
|
|
Memory :: struct {
|
|
|
|
live : virtual.Arena,
|
|
|
|
snapshot : []u8,
|
|
|
|
|
|
|
|
persistent : ^ TrackedAllocator,
|
|
|
|
transient : ^ TrackedAllocator,
|
|
|
|
temp : ^ TrackedAllocator,
|
|
|
|
|
|
|
|
replay : ReplayState,
|
|
|
|
logger : Logger,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Memory :: struct {
|
|
|
|
live : virtual.Arena,
|
|
|
|
snapshot : []u8,
|
|
|
|
|
|
|
|
persistent : ^ Arena,
|
|
|
|
transient : ^ Arena,
|
|
|
|
temp : ^ Arena,
|
|
|
|
|
|
|
|
replay : ReplayState,
|
|
|
|
logger : Logger,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
persistent_allocator :: proc () -> Allocator {
|
|
|
|
when Use_TrackingAllocator {
|
|
|
|
return tracked_allocator( memory.persistent )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return arena_allocator( memory.persistent )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
transient_allocator :: proc () -> Allocator {
|
|
|
|
when Use_TrackingAllocator {
|
|
|
|
return tracked_allocator( memory.transient )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return arena_allocator( memory.transient )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
temp_allocator :: proc () -> Allocator {
|
|
|
|
when Use_TrackingAllocator {
|
|
|
|
return tracked_allocator( memory.temp )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return arena_allocator( memory.temp )
|
|
|
|
}
|
2024-01-29 23:27:45 -08:00
|
|
|
}
|
|
|
|
|
2024-02-09 10:09:58 -08:00
|
|
|
save_snapshot :: proc( snapshot : [^]u8 ) {
|
|
|
|
live_ptr := cast( ^ rawptr ) memory.live.curr_block.base
|
|
|
|
mem.copy_non_overlapping( & snapshot[0], live_ptr, memory_chunk_size )
|
|
|
|
}
|
|
|
|
|
|
|
|
load_snapshot :: proc( snapshot : [^]u8 ) {
|
|
|
|
live_ptr := cast( ^ rawptr ) memory.live.curr_block.base
|
|
|
|
mem.copy_non_overlapping( live_ptr, snapshot, memory_chunk_size )
|
|
|
|
}
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
AppConfig :: struct {
|
|
|
|
resolution_width : uint,
|
|
|
|
resolution_height : uint,
|
2024-02-13 14:16:39 -08:00
|
|
|
refresh_rate : uint,
|
|
|
|
min_zoom : uint,
|
|
|
|
max_zoom : uint,
|
2024-02-11 20:00:06 -08:00
|
|
|
}
|
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
State :: struct {
|
2024-02-13 14:16:39 -08:00
|
|
|
font_provider_data : FontProviderData,
|
|
|
|
|
2024-02-08 07:50:36 -08:00
|
|
|
input_data : [2] InputState,
|
2024-02-09 10:09:58 -08:00
|
|
|
input_prev : ^ InputState,
|
|
|
|
input : ^ InputState,
|
2024-02-08 07:50:36 -08:00
|
|
|
|
|
|
|
debug : DebugData,
|
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
project : Project,
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
config : AppConfig,
|
|
|
|
app_window : AppWindow,
|
2024-01-21 20:38:02 -08:00
|
|
|
|
|
|
|
monitor_id : i32,
|
|
|
|
monitor_refresh_hz : i32,
|
|
|
|
|
|
|
|
engine_refresh_hz : i32,
|
|
|
|
engine_refresh_target : i32,
|
|
|
|
|
2024-02-13 14:16:39 -08:00
|
|
|
font_firacode : FontID,
|
|
|
|
font_squidgy_slimes : FontID,
|
|
|
|
font_rec_mono_semicasual_reg : FontID,
|
|
|
|
default_font : FontID,
|
2024-02-22 20:15:29 -08:00
|
|
|
|
|
|
|
// There are two potential UI contextes for this prototype so far,
|
|
|
|
// the screen-space UI and the current workspace UI.
|
|
|
|
// This is used so that the ui api doesn't need to have the user pass the context every single time.
|
|
|
|
ui_context : UI_State,
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
get_state :: proc "contextless" () -> ^ State {
|
2024-02-13 14:16:39 -08:00
|
|
|
when Use_TrackingAllocator {
|
|
|
|
return cast( ^ State ) raw_data( memory.persistent.backing.data )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return cast( ^ State ) raw_data( memory.persistent. data )
|
|
|
|
}
|
2024-02-09 10:09:58 -08:00
|
|
|
}
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
AppWindow :: struct {
|
|
|
|
extent : Extents2, // Window half-size
|
|
|
|
dpi_scale : f32, // Dots per inch scale (provided by raylib via glfw)
|
2024-02-13 14:16:39 -08:00
|
|
|
ppcm : f32, // Dots per centimetre
|
2024-02-11 20:00:06 -08:00
|
|
|
}
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
// PMDB
|
|
|
|
CodeBase :: struct {
|
|
|
|
placeholder : int,
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectConfig :: struct {
|
|
|
|
placeholder : int,
|
|
|
|
}
|
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
Project :: struct {
|
2024-02-09 10:09:58 -08:00
|
|
|
path : string,
|
|
|
|
name : string,
|
|
|
|
|
2024-02-22 18:19:29 -08:00
|
|
|
config : ProjectConfig,
|
|
|
|
codebase : CodeBase,
|
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
// TODO(Ed) : Support multiple workspaces
|
2024-02-22 18:19:29 -08:00
|
|
|
workspace : Workspace,
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Workspace :: struct {
|
2024-02-10 00:40:53 -08:00
|
|
|
name : string,
|
|
|
|
|
|
|
|
cam : Camera,
|
2024-02-11 21:35:22 -08:00
|
|
|
frame_1 : Box2,
|
|
|
|
frame_2 : Box2,
|
2024-02-22 18:19:29 -08:00
|
|
|
|
|
|
|
// TODO(Ed) : The workspace is mainly a 'UI' conceptually...
|
|
|
|
ui : UI_State,
|
2024-02-08 07:50:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
DebugData :: struct {
|
|
|
|
square_size : i32,
|
|
|
|
square_pos : rl.Vector2,
|
|
|
|
|
|
|
|
draw_debug_text_y : f32,
|
|
|
|
|
2024-02-11 20:00:06 -08:00
|
|
|
cursor_locked : b32,
|
|
|
|
cursor_unlock_pos : Vec2, // Raylib changes the mose position on lock, we want restore the position the user would be in on screen
|
|
|
|
mouse_vis : b32,
|
|
|
|
last_mouse_pos : Vec2,
|
2024-02-11 21:35:22 -08:00
|
|
|
|
|
|
|
frame_1_on_top : b32,
|
2024-02-13 15:50:22 -08:00
|
|
|
zoom_target : f32,
|
2024-02-08 07:50:36 -08:00
|
|
|
}
|