2024-01-21 20:38:02 -08:00
|
|
|
package sectr
|
|
|
|
|
|
|
|
import "core:dynlib"
|
|
|
|
import "core:fmt"
|
|
|
|
import "core:mem"
|
|
|
|
import "core:os"
|
|
|
|
import "core:strings"
|
|
|
|
import rl "vendor:raylib"
|
|
|
|
|
|
|
|
Path_Assets :: "../assets/"
|
|
|
|
|
|
|
|
ModuleAPI :: struct {
|
|
|
|
lib : dynlib.Library,
|
2024-01-22 00:47:53 -08:00
|
|
|
write_time : os.File_Time,
|
2024-01-21 20:38:02 -08:00
|
|
|
lib_version : i32,
|
|
|
|
|
|
|
|
startup : type_of( startup ),
|
|
|
|
shutdown : type_of( sectr_shutdown),
|
|
|
|
reload : type_of( reload ),
|
|
|
|
update : type_of( update ),
|
|
|
|
render : type_of( render )
|
|
|
|
}
|
|
|
|
|
|
|
|
Memory :: struct {
|
|
|
|
persistent : ^ mem.Arena,
|
2024-01-21 21:22:06 -08:00
|
|
|
transient : ^ mem.Arena,
|
|
|
|
temp : ^ mem.Arena
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
memory : Memory
|
|
|
|
|
|
|
|
@export
|
2024-01-21 21:22:06 -08:00
|
|
|
startup :: proc( persistent, transient, temp : ^ mem.Arena )
|
2024-01-21 20:38:02 -08:00
|
|
|
{
|
2024-01-21 21:22:06 -08:00
|
|
|
memory.persistent = persistent
|
2024-01-22 00:47:53 -08:00
|
|
|
state := cast(^State) memory.persistent; using state
|
2024-01-21 21:22:06 -08:00
|
|
|
|
|
|
|
// Anything allocated by default is considered transient.
|
2024-01-25 08:24:52 -08:00
|
|
|
// context.allocator = mem.arena_allocator( transient )
|
|
|
|
// context.temp_allocator = mem.arena_allocator( temp )
|
2024-01-21 20:38:02 -08:00
|
|
|
|
|
|
|
// Rough setup of window with rl stuff
|
2024-01-22 00:47:53 -08:00
|
|
|
screen_width = 1280
|
|
|
|
screen_height = 1000
|
2024-01-21 20:38:02 -08:00
|
|
|
win_title : cstring = "Sectr Prototype"
|
|
|
|
rl.InitWindow( screen_width, screen_height, win_title )
|
|
|
|
|
|
|
|
// Determining current monitor and setting the target frametime based on it..
|
2024-01-22 00:47:53 -08:00
|
|
|
monitor_id = rl.GetCurrentMonitor()
|
|
|
|
monitor_refresh_hz = rl.GetMonitorRefreshRate( monitor_id )
|
2024-01-21 20:38:02 -08:00
|
|
|
rl.SetTargetFPS( monitor_refresh_hz )
|
|
|
|
fmt.println( "Set target FPS to: %v", monitor_refresh_hz )
|
|
|
|
|
|
|
|
// Basic Font Setup
|
|
|
|
{
|
|
|
|
path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
|
2024-01-21 21:22:06 -08:00
|
|
|
cstr := strings.clone_to_cstring( path_rec_mono_semicasual_reg )
|
2024-01-21 20:38:02 -08:00
|
|
|
font_rec_mono_semicasual_reg = rl.LoadFontEx( cstr, 24, nil, 0 )
|
|
|
|
delete( cstr)
|
|
|
|
|
|
|
|
rl.GuiSetFont( font_rec_mono_semicasual_reg ) // TODO(Ed) : Does this do anything?
|
|
|
|
default_font = font_rec_mono_semicasual_reg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For some reason odin's symbols conflict with native foreign symbols...
|
|
|
|
@export
|
|
|
|
sectr_shutdown :: proc()
|
|
|
|
{
|
2024-01-22 00:47:53 -08:00
|
|
|
if memory.persistent == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
state := cast( ^ State ) memory.persistent
|
|
|
|
rl.UnloadFont( state.font_rec_mono_semicasual_reg )
|
2024-01-21 20:38:02 -08:00
|
|
|
rl.CloseWindow()
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
2024-01-21 21:22:06 -08:00
|
|
|
reload :: proc( persistent, transient, temp : ^ mem.Arena )
|
2024-01-21 20:38:02 -08:00
|
|
|
{
|
|
|
|
memory.persistent = persistent
|
|
|
|
memory.transient = transient
|
2024-01-22 00:47:53 -08:00
|
|
|
memory.temp = temp
|
|
|
|
context.allocator = mem.arena_allocator( transient )
|
|
|
|
context.temp_allocator = mem.arena_allocator( temp )
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
update :: proc() -> b32
|
|
|
|
{
|
2024-01-22 00:47:53 -08:00
|
|
|
state := cast( ^ State ) memory.persistent
|
|
|
|
|
|
|
|
should_shutdown : b32 = ! cast(b32) rl.WindowShouldClose()
|
2024-01-21 20:38:02 -08:00
|
|
|
return should_shutdown
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
render :: proc()
|
|
|
|
{
|
2024-01-22 00:47:53 -08:00
|
|
|
state := cast( ^ State ) memory.persistent; using state
|
|
|
|
|
2024-01-21 20:38:02 -08:00
|
|
|
rl.BeginDrawing()
|
|
|
|
rl.ClearBackground( Color_BG )
|
|
|
|
defer {
|
|
|
|
rl.DrawFPS( 0, 0 )
|
|
|
|
rl.EndDrawing()
|
|
|
|
// Note(Ed) : Polls input as well.
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_text :: proc( format : string, args : ..any )
|
|
|
|
{
|
2024-01-22 00:47:53 -08:00
|
|
|
@static draw_text_scratch : [Kilobyte * 64]u8
|
|
|
|
|
|
|
|
state := cast( ^ State ) memory.persistent; using state
|
|
|
|
if ( draw_debug_text_y > 800 ) {
|
|
|
|
draw_debug_text_y = 50
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
content := fmt.bprintf( draw_text_scratch[:], format, ..args )
|
2024-01-22 00:47:53 -08:00
|
|
|
debug_text( content, 25, draw_debug_text_y )
|
2024-01-21 20:38:02 -08:00
|
|
|
|
2024-01-22 00:47:53 -08:00
|
|
|
draw_debug_text_y += 16
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
draw_text( "Monitor : %v", rl.GetMonitorName(0) )
|
|
|
|
draw_text( "Screen Width : %v", rl.GetScreenWidth() )
|
|
|
|
draw_text( "Screen Height: %v", rl.GetScreenHeight() )
|
2024-01-25 08:31:21 -08:00
|
|
|
// draw_text( "HOT RELOAD BITCHES" )
|
2024-01-21 20:38:02 -08:00
|
|
|
|
2024-01-22 00:47:53 -08:00
|
|
|
draw_debug_text_y = 50
|
2024-01-21 20:38:02 -08:00
|
|
|
}
|