2024-01-21 20:38:02 -08:00
|
|
|
package sectr
|
|
|
|
|
2024-02-08 07:50:36 -08:00
|
|
|
import "base:runtime"
|
2024-02-22 18:19:29 -08:00
|
|
|
import c "core:c/libc"
|
2024-01-21 20:38:02 -08:00
|
|
|
import "core:dynlib"
|
|
|
|
import "core:mem"
|
2024-01-29 22:29:48 -08:00
|
|
|
import "core:mem/virtual"
|
2024-01-21 20:38:02 -08:00
|
|
|
import "core:os"
|
2024-01-29 22:29:48 -08:00
|
|
|
import "core:slice"
|
2024-01-21 20:38:02 -08:00
|
|
|
import "core:strings"
|
2024-03-08 15:45:08 -08:00
|
|
|
import "core:time"
|
2024-03-10 23:05:18 -07:00
|
|
|
import "core:prof/spall"
|
2024-01-21 20:38:02 -08:00
|
|
|
import rl "vendor:raylib"
|
|
|
|
|
2024-02-08 07:50:36 -08:00
|
|
|
Path_Assets :: "../assets/"
|
2024-05-14 08:47:44 -07:00
|
|
|
Path_Shaders :: "../shaders/"
|
2024-02-08 07:50:36 -08:00
|
|
|
Path_Input_Replay :: "scratch.sectr_replay"
|
2024-01-21 20:38:02 -08:00
|
|
|
|
2024-05-06 20:29:47 -07:00
|
|
|
Persistent_Slab_DBG_Name := "Peristent Slab"
|
|
|
|
Frame_Slab_DBG_Name := "Frame Slab"
|
|
|
|
Transient_Slab_DBG_Name := "Transient Slab"
|
2024-03-19 22:23:50 -07:00
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
ModuleAPI :: struct {
|
|
|
|
lib : dynlib.Library,
|
2024-02-27 04:50:57 -08:00
|
|
|
write_time : FileTime,
|
2024-01-21 20:38:02 -08:00
|
|
|
lib_version : i32,
|
|
|
|
|
2024-03-07 12:57:05 -08:00
|
|
|
startup : type_of( startup ),
|
|
|
|
shutdown : type_of( sectr_shutdown ),
|
|
|
|
reload : type_of( reload ),
|
|
|
|
tick : type_of( tick ),
|
|
|
|
clean_frame : type_of( clean_frame ),
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
2024-03-19 05:36:58 -07:00
|
|
|
startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem, files_buffer_mem : ^VArena, host_logger : ^Logger )
|
2024-01-21 20:38:02 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
spall.SCOPED_EVENT( & prof.ctx, & prof.buffer, #procedure )
|
|
|
|
Memory_App.profiler = prof
|
|
|
|
|
2024-03-08 15:45:08 -08:00
|
|
|
startup_tick := time.tick_now()
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
logger_init( & Memory_App.logger, "Sectr", host_logger.file_path, host_logger.file )
|
|
|
|
context.logger = to_odin_logger( & Memory_App.logger )
|
2024-02-08 19:33:53 -08:00
|
|
|
|
2024-01-29 22:29:48 -08:00
|
|
|
// Setup memory for the first time
|
|
|
|
{
|
2024-02-27 04:50:57 -08:00
|
|
|
using Memory_App;
|
2024-03-07 12:57:05 -08:00
|
|
|
persistent = persistent_mem
|
|
|
|
frame = frame_mem
|
|
|
|
transient = transient_mem
|
|
|
|
files_buffer = files_buffer_mem
|
2024-02-13 14:16:39 -08:00
|
|
|
|
2024-03-07 12:57:05 -08:00
|
|
|
context.allocator = persistent_allocator()
|
|
|
|
context.temp_allocator = transient_allocator()
|
2024-03-08 15:45:08 -08:00
|
|
|
// TODO(Ed) : Put on the transient allocator a slab allocator (transient slab)
|
2024-01-29 22:29:48 -08:00
|
|
|
}
|
2024-02-08 19:33:53 -08:00
|
|
|
|
2024-02-13 14:16:39 -08:00
|
|
|
state := new( State, persistent_allocator() )
|
2024-05-06 20:29:47 -07:00
|
|
|
Memory_App.state = state
|
2024-01-29 22:29:48 -08:00
|
|
|
using state
|
2024-01-21 20:38:02 -08:00
|
|
|
|
2024-03-10 07:31:21 -07:00
|
|
|
// Setup Persistent Slab
|
2024-03-07 12:57:05 -08:00
|
|
|
{
|
|
|
|
alignment := uint(mem.DEFAULT_ALIGNMENT)
|
|
|
|
|
2024-03-10 07:31:21 -07:00
|
|
|
policy_ptr := & default_slab_policy
|
2024-05-13 18:53:08 -07:00
|
|
|
push( policy_ptr, SlabSizeClass { 128 * Kilobyte, 1 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 256 * Kilobyte, 2 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 512 * Kilobyte, 4 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 1 * Megabyte, 16 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 1 * Megabyte, 32 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 1 * Megabyte, 64 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 2 * Megabyte, 128 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 2 * Megabyte, 256 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 2 * Megabyte, 512 * Kilobyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 2 * Megabyte, 1 * Megabyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 2 * Megabyte, 2 * Megabyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 4 * Megabyte, 4 * Megabyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 8 * Megabyte, 8 * Megabyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 16 * Megabyte, 16 * Megabyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 32 * Megabyte, 32 * Megabyte, alignment })
|
|
|
|
push( policy_ptr, SlabSizeClass { 64 * Megabyte, 64 * Megabyte, alignment })
|
|
|
|
// push( policy_ptr, SlabSizeClass { 128 * Megabyte, 128 * Megabyte, alignment })
|
|
|
|
// push( policy_ptr, SlabSizeClass { 256 * Megabyte, 256 * Megabyte, alignment })
|
|
|
|
// push( policy_ptr, SlabSizeClass { 512 * Megabyte, 512 * Megabyte, alignment })
|
2024-03-07 12:57:05 -08:00
|
|
|
|
|
|
|
alloc_error : AllocatorError
|
2024-03-19 22:23:50 -07:00
|
|
|
persistent_slab, alloc_error = slab_init( policy_ptr, allocator = persistent_allocator(), dbg_name = Persistent_Slab_DBG_Name )
|
2024-03-10 17:09:04 -07:00
|
|
|
verify( alloc_error == .None, "Failed to allocate the persistent slab" )
|
|
|
|
|
2024-03-19 22:23:50 -07:00
|
|
|
transient_slab, alloc_error = slab_init( & default_slab_policy, allocator = transient_allocator(), dbg_name = Transient_Slab_DBG_Name )
|
2024-03-10 17:09:04 -07:00
|
|
|
verify( alloc_error == .None, "Failed to allocate transient slab" )
|
|
|
|
|
|
|
|
transient_clear_time = 120 // Seconds, 2 Minutes
|
2024-03-07 12:57:05 -08:00
|
|
|
}
|
|
|
|
|
2024-03-08 20:20:49 -08:00
|
|
|
string_cache = str_cache_init()
|
|
|
|
|
2024-02-08 07:50:36 -08:00
|
|
|
input = & input_data[1]
|
|
|
|
input_prev = & input_data[0]
|
|
|
|
|
2024-03-08 00:34:21 -08:00
|
|
|
// Configuration Load
|
|
|
|
{
|
|
|
|
using config
|
2024-05-06 20:29:47 -07:00
|
|
|
resolution_width = 1000
|
|
|
|
resolution_height = 600
|
2024-03-08 00:34:21 -08:00
|
|
|
refresh_rate = 0
|
|
|
|
|
2024-05-12 22:52:55 -07:00
|
|
|
cam_min_zoom = 0.10
|
2024-03-19 05:36:58 -07:00
|
|
|
cam_max_zoom = 30.0
|
2024-03-08 00:34:21 -08:00
|
|
|
cam_zoom_mode = .Smooth
|
|
|
|
cam_zoom_smooth_snappiness = 4.0
|
|
|
|
cam_zoom_sensitivity_digital = 0.2
|
|
|
|
cam_zoom_sensitivity_smooth = 4.0
|
|
|
|
|
2024-03-08 15:45:08 -08:00
|
|
|
engine_refresh_hz = 30
|
|
|
|
|
2024-03-14 21:02:28 -07:00
|
|
|
timing_fps_moving_avg_alpha = 0.9
|
|
|
|
|
2024-03-09 11:24:02 -08:00
|
|
|
ui_resize_border_width = 5
|
2024-03-08 00:34:21 -08:00
|
|
|
}
|
|
|
|
|
2024-03-08 15:45:08 -08:00
|
|
|
Desired_OS_Scheduler_MS :: 1
|
|
|
|
sleep_is_granular = set__scheduler_granularity( Desired_OS_Scheduler_MS )
|
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
// Rough setup of window with rl stuff
|
2024-03-19 05:36:58 -07:00
|
|
|
{
|
|
|
|
// rl.Odin_SetMalloc( RL_MALLOC )
|
|
|
|
|
|
|
|
rl.SetConfigFlags( {
|
|
|
|
rl.ConfigFlag.WINDOW_RESIZABLE,
|
2024-05-06 20:29:47 -07:00
|
|
|
// rl.ConfigFlag.WINDOW_TOPMOST,
|
2024-03-19 05:36:58 -07:00
|
|
|
})
|
|
|
|
|
2024-05-04 09:10:30 -07:00
|
|
|
window_width : i32 = cast(i32) config.resolution_width
|
|
|
|
window_height : i32 = cast(i32) config.resolution_height
|
2024-03-19 05:36:58 -07:00
|
|
|
win_title : cstring = "Sectr Prototype"
|
|
|
|
rl.InitWindow( window_width, window_height, win_title )
|
|
|
|
log( "Raylib initialized and window opened" )
|
|
|
|
|
|
|
|
window := & state.app_window
|
|
|
|
window.extent.x = f32(window_width) * 0.5
|
|
|
|
window.extent.y = f32(window_height) * 0.5
|
|
|
|
|
|
|
|
// We do not support non-uniform DPI.
|
|
|
|
window.dpi_scale = rl.GetWindowScaleDPI().x
|
|
|
|
window.ppcm = os_default_ppcm * window.dpi_scale
|
|
|
|
|
|
|
|
// Determining current monitor and setting the target frametime based on it..
|
|
|
|
monitor_id = rl.GetCurrentMonitor()
|
|
|
|
monitor_refresh_hz = rl.GetMonitorRefreshRate( monitor_id )
|
|
|
|
log( str_fmt_tmp( "Set target FPS to: %v", monitor_refresh_hz ) )
|
|
|
|
}
|
2024-01-21 20:38:02 -08:00
|
|
|
|
|
|
|
// Basic Font Setup
|
|
|
|
{
|
2024-02-13 14:16:39 -08:00
|
|
|
font_provider_startup()
|
2024-02-13 15:50:22 -08:00
|
|
|
// path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
|
|
|
|
// font_rec_mono_semicasual_reg = font_load( path_rec_mono_semicasual_reg, 24.0, "RecMonoSemiCasual_Regular" )
|
2024-02-13 14:16:39 -08:00
|
|
|
|
2024-02-13 15:50:22 -08:00
|
|
|
// path_squidgy_slimes := strings.concatenate( { Path_Assets, "Squidgy Slimes.ttf" } )
|
|
|
|
// font_squidgy_slimes = font_load( path_squidgy_slimes, 24.0, "Squidgy_Slime" )
|
2024-02-12 17:52:56 -08:00
|
|
|
|
2024-03-08 20:20:49 -08:00
|
|
|
path_firacode := strings.concatenate( { Path_Assets, "FiraCode-Regular.ttf" }, transient_allocator() )
|
2024-02-13 14:16:39 -08:00
|
|
|
font_firacode = font_load( path_firacode, 24.0, "FiraCode" )
|
|
|
|
default_font = font_firacode
|
2024-02-08 19:33:53 -08:00
|
|
|
log( "Default font loaded" )
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
2024-02-09 10:09:58 -08:00
|
|
|
|
2024-05-10 22:30:54 -07:00
|
|
|
// Setup the screen ui state
|
2024-05-10 16:20:50 -07:00
|
|
|
{
|
2024-05-10 16:50:37 -07:00
|
|
|
ui_startup( & screen_ui.base, cache_allocator = persistent_slab_allocator() )
|
2024-05-15 00:34:52 -07:00
|
|
|
ui_floating_startup( & screen_ui.floating, persistent_slab_allocator(), 1 * Kilobyte, 1 * Kilobyte, "screen ui floating manager" )
|
2024-05-10 16:20:50 -07:00
|
|
|
|
2024-05-10 16:50:37 -07:00
|
|
|
using screen_ui
|
2024-05-12 22:56:39 -07:00
|
|
|
menu_bar.pos = { -60, 0 }
|
|
|
|
// menu_bar.pos = Vec2(app_window.extent) * { -1, 1 }
|
2024-05-10 16:20:50 -07:00
|
|
|
menu_bar.size = {200, 40}
|
|
|
|
|
2024-05-12 22:52:55 -07:00
|
|
|
settings_menu.min_size = {250, 200}
|
2024-05-10 16:20:50 -07:00
|
|
|
}
|
2024-05-07 23:26:39 -07:00
|
|
|
|
2024-02-12 17:52:56 -08:00
|
|
|
// Demo project setup
|
2024-02-10 00:40:53 -08:00
|
|
|
{
|
|
|
|
using project
|
2024-03-08 20:20:49 -08:00
|
|
|
path = str_intern("./")
|
|
|
|
name = str_intern( "First Project" )
|
|
|
|
workspace.name = str_intern( "First Workspace" )
|
2024-02-10 00:40:53 -08:00
|
|
|
{
|
|
|
|
using project.workspace
|
|
|
|
cam = {
|
2024-02-13 14:16:39 -08:00
|
|
|
target = { 0, 0 },
|
2024-03-19 05:36:58 -07:00
|
|
|
offset = transmute(Vec2) app_window.extent,
|
2024-02-10 00:40:53 -08:00
|
|
|
rotation = 0,
|
2024-02-13 14:16:39 -08:00
|
|
|
zoom = 1.0,
|
2024-02-10 00:40:53 -08:00
|
|
|
}
|
|
|
|
// cam = {
|
|
|
|
// position = { 0, 0, -100 },
|
|
|
|
// target = { 0, 0, 0 },
|
|
|
|
// up = { 0, 1, 0 },
|
|
|
|
// fovy = 90,
|
|
|
|
// projection = rl.CameraProjection.ORTHOGRAPHIC,
|
|
|
|
// }
|
|
|
|
|
2024-02-22 20:15:29 -08:00
|
|
|
// Setup workspace UI state
|
2024-03-10 07:31:21 -07:00
|
|
|
ui_startup( & workspace.ui, cache_allocator = persistent_slab_allocator() )
|
2024-02-10 00:40:53 -08:00
|
|
|
}
|
2024-03-10 07:31:21 -07:00
|
|
|
|
2024-03-19 20:25:48 -07:00
|
|
|
debug.path_lorem = str_fmt_alloc("C:/projects/SectrPrototype/examples/Lorem Ipsum.txt", allocator = persistent_slab_allocator())
|
2024-03-10 17:09:04 -07:00
|
|
|
|
|
|
|
alloc_error : AllocatorError; success : bool
|
|
|
|
debug.lorem_content, success = os.read_entire_file( debug.path_lorem, persistent_slab_allocator() )
|
|
|
|
|
|
|
|
debug.lorem_parse, alloc_error = pws_parser_parse( transmute(string) debug.lorem_content, persistent_slab_allocator() )
|
|
|
|
verify( alloc_error == .None, "Faield to parse due to allocation failure" )
|
2024-03-18 08:44:58 -07:00
|
|
|
|
|
|
|
// Render texture test
|
2024-05-13 18:53:08 -07:00
|
|
|
// debug.viewport_rt = rl.LoadRenderTexture( 1280, 720 )
|
|
|
|
|
|
|
|
// debug.proto_text_shader = rl.LoadShader( "C:/projects/SectrPrototype/code/shaders/text_shader.vs", "C:/projects/SectrPrototype/code/shaders/text_shader.fs" )
|
2024-02-10 00:40:53 -08:00
|
|
|
}
|
2024-03-08 15:45:08 -08:00
|
|
|
|
|
|
|
startup_ms := duration_ms( time.tick_lap_time( & startup_tick))
|
|
|
|
log( str_fmt_tmp("Startup time: %v ms", startup_ms) )
|
|
|
|
|
|
|
|
// Make sure to cleanup transient before continuing...
|
|
|
|
// From here on, tarnsinet usage has to be done with care.
|
|
|
|
// For most cases, the frame allocator should be more than enough.
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// For some reason odin's symbols conflict with native foreign symbols...
|
|
|
|
@export
|
|
|
|
sectr_shutdown :: proc()
|
|
|
|
{
|
2024-03-10 17:09:04 -07:00
|
|
|
context.logger = to_odin_logger( & Memory_App.logger )
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
if Memory_App.persistent == nil {
|
2024-01-22 00:47:53 -08:00
|
|
|
return
|
|
|
|
}
|
2024-01-29 22:29:48 -08:00
|
|
|
state := get_state()
|
2024-02-08 07:50:36 -08:00
|
|
|
|
|
|
|
// Replay
|
|
|
|
{
|
2024-03-07 12:57:05 -08:00
|
|
|
file_close( Memory_App.replay.active_file )
|
2024-02-08 07:50:36 -08:00
|
|
|
}
|
|
|
|
|
2024-02-13 14:16:39 -08:00
|
|
|
font_provider_shutdown()
|
|
|
|
|
2024-02-08 19:33:53 -08:00
|
|
|
log("Module shutdown complete")
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
2024-03-10 23:05:18 -07:00
|
|
|
reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem, files_buffer_mem : ^VArena, host_logger : ^ Logger )
|
2024-01-21 20:38:02 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
spall.SCOPED_EVENT( & prof.ctx, & prof.buffer, #procedure )
|
|
|
|
Memory_App.profiler = prof
|
|
|
|
|
2024-03-10 17:09:04 -07:00
|
|
|
context.logger = to_odin_logger( & Memory_App.logger )
|
2024-02-27 04:50:57 -08:00
|
|
|
using Memory_App;
|
2024-01-29 22:29:48 -08:00
|
|
|
|
2024-03-07 12:57:05 -08:00
|
|
|
persistent = persistent_mem
|
|
|
|
frame = frame_mem
|
|
|
|
transient = transient_mem
|
|
|
|
files_buffer = files_buffer_mem
|
2024-02-08 13:05:15 -08:00
|
|
|
|
2024-03-07 12:57:05 -08:00
|
|
|
context.allocator = persistent_allocator()
|
|
|
|
context.temp_allocator = transient_allocator()
|
2024-02-13 15:50:22 -08:00
|
|
|
|
2024-05-07 23:26:39 -07:00
|
|
|
Memory_App.state = get_state()
|
2024-05-06 20:29:47 -07:00
|
|
|
using state
|
2024-03-10 17:09:04 -07:00
|
|
|
|
2024-02-13 23:29:08 -08:00
|
|
|
// Procedure Addresses are not preserved on hot-reload. They must be restored for persistent data.
|
|
|
|
// The only way to alleviate this is to either do custom handles to allocators
|
|
|
|
// Or as done below, correct containers using allocators on reload.
|
|
|
|
// Thankfully persistent dynamic allocations are rare, and thus we know exactly which ones they are.
|
|
|
|
|
2024-03-19 22:23:50 -07:00
|
|
|
slab_reload( persistent_slab, persistent_allocator() )
|
|
|
|
|
2024-05-15 00:34:52 -07:00
|
|
|
hmap_chained_reload( font_provider_data.font_cache, persistent_allocator())
|
2024-03-13 21:00:44 -07:00
|
|
|
|
2024-03-19 21:44:43 -07:00
|
|
|
slab_reload( string_cache.slab, persistent_allocator() )
|
2024-05-14 08:47:44 -07:00
|
|
|
zpl_hmap_reload( & string_cache.table, persistent_slab_allocator())
|
2024-02-13 15:50:22 -08:00
|
|
|
|
2024-03-19 22:23:50 -07:00
|
|
|
slab_reload( frame_slab, frame_allocator())
|
2024-03-19 21:44:43 -07:00
|
|
|
slab_reload( transient_slab, transient_allocator())
|
|
|
|
|
2024-03-10 07:31:21 -07:00
|
|
|
ui_reload( & get_state().project.workspace.ui, cache_allocator = persistent_slab_allocator() )
|
2024-02-22 20:15:29 -08:00
|
|
|
|
2024-02-08 19:33:53 -08:00
|
|
|
log("Module reloaded")
|
2024-02-08 07:50:36 -08:00
|
|
|
}
|
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
@export
|
2024-03-08 15:45:08 -08:00
|
|
|
tick :: proc( host_delta_time : f64, host_delta_ns : Duration ) -> b32
|
2024-01-21 20:38:02 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile( "Client Tick" )
|
2024-03-10 17:09:04 -07:00
|
|
|
context.logger = to_odin_logger( & Memory_App.logger )
|
2024-03-10 07:31:21 -07:00
|
|
|
state := get_state(); using state
|
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
should_close : b32
|
2024-03-10 17:09:04 -07:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
client_tick := time.tick_now()
|
2024-03-10 07:31:21 -07:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
profile("Work frame")
|
2024-02-13 15:50:22 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
// Setup Frame Slab
|
|
|
|
{
|
|
|
|
alloc_error : AllocatorError
|
2024-04-07 22:35:53 -07:00
|
|
|
frame_slab, alloc_error = slab_init( & default_slab_policy, bucket_reserve_num = 0,
|
|
|
|
allocator = frame_allocator(),
|
|
|
|
dbg_name = Frame_Slab_DBG_Name,
|
|
|
|
should_zero_buckets = true )
|
2024-03-10 23:05:18 -07:00
|
|
|
verify( alloc_error == .None, "Failed to allocate frame slab" )
|
|
|
|
}
|
2024-03-02 07:24:09 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
context.allocator = frame_allocator()
|
|
|
|
context.temp_allocator = transient_allocator()
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
rl.PollInputEvents()
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-05-15 15:48:20 -07:00
|
|
|
debug.draw_ui_box_bounds_points = true
|
2024-05-15 00:34:52 -07:00
|
|
|
debug.draw_UI_padding_bounds = false
|
2024-05-15 15:48:20 -07:00
|
|
|
debug.draw_ui_content_bounds = true
|
2024-05-12 22:52:55 -07:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
should_close = update( host_delta_time )
|
|
|
|
render()
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
rl.SwapScreenBuffer()
|
|
|
|
}
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
// Timing
|
2024-03-08 15:45:08 -08:00
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile("Client tick timing processing")
|
2024-05-15 00:34:52 -07:00
|
|
|
config.engine_refresh_hz = uint(monitor_refresh_hz)
|
|
|
|
// config.engine_refresh_hz = 6
|
2024-03-10 23:05:18 -07:00
|
|
|
frametime_target_ms = 1.0 / f64(config.engine_refresh_hz) * S_To_MS
|
|
|
|
sub_ms_granularity_required := frametime_target_ms <= Frametime_High_Perf_Threshold_MS
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
frametime_delta_ns = time.tick_lap_time( & client_tick )
|
|
|
|
frametime_delta_ms = duration_ms( frametime_delta_ns )
|
|
|
|
frametime_delta_seconds = duration_seconds( frametime_delta_ns )
|
|
|
|
frametime_elapsed_ms = frametime_delta_ms + host_delta_time
|
|
|
|
|
|
|
|
if frametime_elapsed_ms < frametime_target_ms
|
|
|
|
{
|
|
|
|
sleep_ms := frametime_target_ms - frametime_elapsed_ms
|
|
|
|
pre_sleep_tick := time.tick_now()
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
if sleep_ms > 0 {
|
|
|
|
thread_sleep( cast(Duration) sleep_ms * MS_To_NS )
|
|
|
|
// thread__highres_wait( sleep_ms )
|
|
|
|
}
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
sleep_delta_ns := time.tick_lap_time( & pre_sleep_tick)
|
|
|
|
sleep_delta_ms := duration_ms( sleep_delta_ns )
|
2024-03-08 15:45:08 -08:00
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
if sleep_delta_ms < sleep_ms {
|
|
|
|
// log( str_fmt_tmp("frametime sleep was off by: %v ms", sleep_delta_ms - sleep_ms ))
|
|
|
|
}
|
2024-03-08 15:45:08 -08:00
|
|
|
|
|
|
|
frametime_elapsed_ms += sleep_delta_ms
|
2024-03-10 23:05:18 -07:00
|
|
|
for ; frametime_elapsed_ms < frametime_target_ms; {
|
|
|
|
sleep_delta_ns = time.tick_lap_time( & pre_sleep_tick)
|
|
|
|
sleep_delta_ms = duration_ms( sleep_delta_ns )
|
|
|
|
|
|
|
|
frametime_elapsed_ms += sleep_delta_ms
|
|
|
|
}
|
2024-03-08 15:45:08 -08:00
|
|
|
}
|
|
|
|
|
2024-03-14 21:02:28 -07:00
|
|
|
config.timing_fps_moving_avg_alpha = 0.99
|
|
|
|
frametime_avg_ms = mov_avg_exp( f64(config.timing_fps_moving_avg_alpha), frametime_elapsed_ms, frametime_avg_ms )
|
|
|
|
fps_avg = 1 / (frametime_avg_ms * MS_To_S)
|
|
|
|
|
2024-03-10 23:05:18 -07:00
|
|
|
if frametime_elapsed_ms > 60.0 {
|
|
|
|
log( str_fmt_tmp("Big tick! %v ms", frametime_elapsed_ms), LogLevel.Warning )
|
|
|
|
}
|
2024-03-08 15:45:08 -08:00
|
|
|
}
|
2024-03-10 23:05:18 -07:00
|
|
|
return should_close
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
2024-01-29 22:29:48 -08:00
|
|
|
|
|
|
|
@export
|
2024-03-10 17:09:04 -07:00
|
|
|
clean_frame :: proc()
|
|
|
|
{
|
2024-03-10 23:05:18 -07:00
|
|
|
// profile( #procedure)
|
2024-03-10 17:09:04 -07:00
|
|
|
state := get_state(); using state
|
|
|
|
context.logger = to_odin_logger( & Memory_App.logger )
|
|
|
|
|
2024-03-07 12:57:05 -08:00
|
|
|
free_all( frame_allocator() )
|
2024-03-10 17:09:04 -07:00
|
|
|
|
|
|
|
transient_clear_elapsed += frametime_delta32()
|
|
|
|
if transient_clear_elapsed >= transient_clear_time && ! transinet_clear_lock
|
|
|
|
{
|
|
|
|
transient_clear_elapsed = 0
|
|
|
|
free_all( transient_allocator() )
|
|
|
|
|
|
|
|
alloc_error : AllocatorError
|
2024-03-19 22:23:50 -07:00
|
|
|
transient_slab, alloc_error = slab_init( & default_slab_policy, allocator = transient_allocator(), dbg_name = Transient_Slab_DBG_Name )
|
2024-03-10 17:09:04 -07:00
|
|
|
verify( alloc_error == .None, "Failed to allocate transient slab" )
|
|
|
|
}
|
2024-01-29 22:29:48 -08:00
|
|
|
}
|