aboutsummaryrefslogtreecommitdiff
path: root/src/main.odin
diff options
context:
space:
mode:
authoriamcheeseman <[hidden email]>2026-02-03 22:25:00 -0500
committeriamcheeseman <[hidden email]>2026-02-03 22:25:00 -0500
commit3d1d31538d30a7f161f9f2b6d5e075ec69d3b860 (patch)
tree8b0deceb38c288dbef361bb4f77bb681b5566525 /src/main.odin
parent1c605da3ff8dc4295d2f9a85f5b7c8891ca84464 (diff)
ditch raylib (icky, and for loser BEGINNERS)
Diffstat (limited to 'src/main.odin')
-rw-r--r--src/main.odin205
1 files changed, 93 insertions, 112 deletions
diff --git a/src/main.odin b/src/main.odin
index a0c2fcb..20ea221 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -6,30 +6,32 @@ import "core:c"
import "core:c/libc"
import "core:fmt"
import "core:log"
-import "core:mem"
import "core:math"
import "core:math/linalg"
-
-import rl "vendor:raylib"
+import "core:mem"
import "phys"
+import "fw"
-Vec2 :: [2]f32
-
-Rect :: struct {
- start: Vec2,
- size: Vec2,
-}
+Vec2 :: fw.Vec2
+Vec2i :: fw.Vec2i
+Color :: fw.Color
+Rect :: fw.Rect
ROOM_FADE_SIZE :: 8
FIXED_UPDATE_RATE :: 1.0/60
+SCREEN_WIDTH :: 256
+SCREEN_HEIGHT :: 256
+SCREEN_SIZE :: Vec2{SCREEN_WIDTH, SCREEN_HEIGHT}
+SCREEN_SIZE_INT :: Vec2i{SCREEN_WIDTH, SCREEN_HEIGHT}
+
state: struct {
debug_mode: bool,
camera_target: Vec2,
last_fixed_update: f64,
- camera: rl.Camera2D,
+ // camera: rl.Camera2D,
prop_list: Entity_List(Prop),
wiggle_prop_list: Entity_List(Wiggle_Prop),
platform_list: Entity_List(Platform),
@@ -39,46 +41,33 @@ state: struct {
logger: log.Logger
-raylib_log :: proc "c" (
- msg_type: rl.TraceLogLevel,
- fmt: cstring,
- args: ^c.va_list,
-) {
- context = runtime.default_context()
- context.logger = logger
-
- msg_bytes: [1028]u8
- libc.vsnprintf(raw_data(msg_bytes[:]), 1028, fmt, args)
-
- msg := string(msg_bytes[:])
-
- #partial switch msg_type {
- case .DEBUG: log.debug(msg)
- case .INFO: log.info(msg)
- case .WARNING: log.warn(msg)
- case .ERROR: log.error(msg)
- case .FATAL: log.fatal(msg)
- }
-}
-
init :: proc() {
- state.camera.zoom = 1
+ fw.init({
+ win_name = "Demonchime",
+ win_size = SCREEN_SIZE_INT * 3,
+ screen_size = SCREEN_SIZE_INT,
+ renderer_backend = .OpenGL,
+ })
init_keybinds()
- init_draw()
init_player()
open_room(.Carrabassett0)
}
frame :: proc() {
- if is_keybind_just_down(actions.toggle_debug_mode) {
+ if fw.is_keybind_just_down(actions.toggle_debug_mode) {
state.debug_mode = !state.debug_mode
}
- dt := rl.GetFrameTime()
+ if fw.is_keybind_just_down(actions.toggle_fullscreen) {
+ // rl.ToggleBorderlessWindowed()
+ // rl.ToggleFullscreen()
+ }
- if rl.GetTime() - state.last_fixed_update > FIXED_UPDATE_RATE {
- state.last_fixed_update = rl.GetTime()
+ dt := f32(fw.get_delta_time())
+
+ if fw.get_time() - state.last_fixed_update > FIXED_UPDATE_RATE {
+ state.last_fixed_update = fw.get_time()
for cb in fixed_update_callbacks {
cb(FIXED_UPDATE_RATE)
}
@@ -88,24 +77,21 @@ frame :: proc() {
cb(dt)
}
- state.camera.target = dt_lerp(
- state.camera.target,
- state.camera_target,
- CAMERA_ACCEL,
- )
-
- draw_new_frame()
-
- cam := state.camera
- cam.target = linalg.round(cam.target)
- rl.BeginMode2D(cam)
+ // state.camera.target = dt_lerp(
+ // state.camera.target,
+ // state.camera_target,
+ // CAMERA_ACCEL,
+ // )
- renderer.tint = get_room(current_room.id).background_color
- draw_rect({
+ // cam := state.camera
+ // cam.target = linalg.round(cam.target)
+ // rl.BeginMode2D(cam)
+
+ fw.draw_rect(
{0, 0},
{f32(current_room.width), f32(current_room.height)},
- })
- renderer.tint = {1, 1, 1, 1}
+ color = get_room(current_room.id).background_color,
+ )
for cb in draw_callbacks {
cb()
@@ -113,66 +99,63 @@ frame :: proc() {
draw_room(current_room.id)
- rl.DrawRectangleGradientH(
- 0,
- 0,
- ROOM_FADE_SIZE,
- current_room.height,
- rl.BLACK,
- rl.BLANK,
- )
- rl.DrawRectangleGradientH(
- current_room.width - ROOM_FADE_SIZE,
- 0,
- ROOM_FADE_SIZE,
- current_room.height,
- rl.BLANK,
- rl.BLACK,
- )
- rl.DrawRectangleGradientV(
- 0,
- 0,
- current_room.width,
- ROOM_FADE_SIZE,
- rl.BLACK,
- rl.BLANK,
- )
- rl.DrawRectangleGradientV(
- 0,
- current_room.height - ROOM_FADE_SIZE,
- current_room.width,
- ROOM_FADE_SIZE,
- rl.BLANK,
- rl.BLACK,
- )
+ // rl.DrawRectangleGradientH(
+ // 0,
+ // 0,
+ // ROOM_FADE_SIZE,
+ // current_room.height,
+ // rl.BLACK,
+ // rl.BLANK,
+ // )
+ // rl.DrawRectangleGradientH(
+ // current_room.width - ROOM_FADE_SIZE,
+ // 0,
+ // ROOM_FADE_SIZE,
+ // current_room.height,
+ // rl.BLANK,
+ // rl.BLACK,
+ // )
+ // rl.DrawRectangleGradientV(
+ // 0,
+ // 0,
+ // current_room.width,
+ // ROOM_FADE_SIZE,
+ // rl.BLACK,
+ // rl.BLANK,
+ // )
+ // rl.DrawRectangleGradientV(
+ // 0,
+ // current_room.height - ROOM_FADE_SIZE,
+ // current_room.width,
+ // ROOM_FADE_SIZE,
+ // rl.BLANK,
+ // rl.BLACK,
+ // )
if state.debug_mode {
// Draw all collisions
body_it: int
- renderer.tint = {1, 0.25, 0.5, 0.25}
+ color := Color{1, 0.25, 0.5, 0.25}
for body in phys.iterate_bodies(&body_it) {
rect := phys.get_rect(body)
rect.start += phys.get_position(body)
- draw_linerect(transmute(Rect)rect)
- draw_rect(transmute(Rect)rect)
+ fw.draw_rect(rect.start, rect.size, color = color, lines = true)
+ fw.draw_rect(rect.start, rect.size, color = color)
}
- renderer.tint = {1, 1, 1, 1}
- }
-
- rl.EndMode2D()
-
- fps_text := fmt.caprintf(
- "FPS: %v",
- rl.GetFPS(),
- allocator = context.temp_allocator,
- )
- rl.DrawText(fps_text, 5, 5, 8, rl.GREEN)
-
- if state.debug_mode {
- rl.DrawText("Debug Mode", 5, 5 + 8, 8, rl.YELLOW)
}
- draw_end_frame()
+ // rl.EndMode2D()
+ //
+ // fps_text := fmt.caprintf(
+ // "FPS: %v",
+ // rl.GetFPS(),
+ // allocator = context.temp_allocator,
+ // )
+ // rl.DrawText(fps_text, 5, 5, 8, rl.GREEN)
+ //
+ // if state.debug_mode {
+ // rl.DrawText("Debug Mode", 5, 5 + 8, 8, rl.YELLOW)
+ // }
}
cleanup :: proc() {
@@ -186,6 +169,8 @@ cleanup :: proc() {
delete_entity_list(state.rope_list)
phys.destroy_world()
+
+ fw.deinit()
}
main :: proc() {
@@ -222,18 +207,14 @@ main :: proc() {
context.logger = logger
defer log.destroy_console_logger(logger)
- rl.SetTraceLogCallback(raylib_log)
-
- rl.InitWindow(SCREEN_WIDTH * 3, SCREEN_HEIGHT * 3, "Demonchime")
- rl.SetWindowState({.WINDOW_RESIZABLE})
-
- rl.SetTargetFPS(240)
-
init()
- for !rl.WindowShouldClose() {
+ for fw.next_frame() {
frame()
- free_all(context.temp_allocator)
+
+ if fw.is_keybind_just_down(actions.exit) {
+ break
+ }
}
cleanup()