in-progress map things...

This commit is contained in:
asrael 2025-10-07 10:32:48 -05:00
parent cfe7501fe2
commit 3c54e379d4
10 changed files with 753 additions and 14 deletions

53
demo/mod/bsp_world.fnl Normal file
View file

@ -0,0 +1,53 @@
(local pxl8 (require :pxl8))
(var camera-angle 0)
(local camera-height 0)
(local camera-distance 300)
(var fps 0)
(var world nil)
(fn init []
(set world (pxl8.world_new))
(let [result (pxl8.world_load world "res/maps/test.bsp")]
(if (< result 0)
(pxl8.error (.. "Failed to load test.bsp - result: " result))
(pxl8.info "Loaded world successfully!"))))
(fn update [dt]
(when (> dt 0)
(set fps (math.floor (/ 1.0 dt))))
(when (pxl8.world_is_loaded world)
(set camera-angle (+ camera-angle (* dt 0.5)))))
(fn frame []
(pxl8.clr 0)
(pxl8.text (.. "FPS: " fps) 10 40 14)
(if (pxl8.world_is_loaded world)
(let [cam-x (* camera-distance (math.cos camera-angle))
cam-z (* camera-distance (math.sin camera-angle))]
(pxl8.text (.. "Camera: " (string.format "%.0f" cam-x) ","
(string.format "%.0f" camera-height) ","
(string.format "%.0f" cam-z)) 10 55 12)
(pxl8.clear_zbuffer)
(pxl8.set_backface_culling true)
(pxl8.set_wireframe true)
(let [aspect (/ (pxl8.get_width) (pxl8.get_height))
fov 1.047]
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 1.0 4096.0)))
(pxl8.set_view (pxl8.mat4_lookat
[cam-x camera-height cam-z]
[0 0 0]
[0 1 0]))
(pxl8.set_model (pxl8.mat4_identity))
(pxl8.world_render world [cam-x camera-height cam-z]))))
{:init init
:update update
:frame frame}

View file

@ -20,7 +20,6 @@
(var cam-pitch -0.2)
(var show-debug-ui false)
(var fps 0)
(var fps-timer 0)
(var fps-accumulator 0)
(var fps-frame-count 0)
@ -174,7 +173,7 @@
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 0.1 100.0))))
(let [target-x (* (math.sin cam-yaw) (math.cos cam-pitch))
target-y (* (math.sin cam-pitch))
target-y (math.sin cam-pitch)
target-z (* (- (math.cos cam-yaw)) (math.cos cam-pitch))
look-x (+ cam-x target-x)
look-y (+ cam-y target-y)
@ -213,13 +212,13 @@
(pxl8.draw_triangle_3d v0 v1 v2 color))))))
(let [new-state (debug-ui.render {:show-debug-ui show-debug-ui
:fps fps
:wireframe wireframe
:auto-rotate auto-rotate
:orthographic orthographic
:use-texture use-texture
:affine affine
:init-texture init-texture})]
:fps fps
:wireframe wireframe
:auto-rotate auto-rotate
:orthographic orthographic
:use-texture use-texture
:affine affine
:init-texture init-texture})]
(when (not= new-state.show-debug-ui nil) (set show-debug-ui new-state.show-debug-ui))
(when (not= new-state.wireframe nil) (set wireframe new-state.wireframe))
(when (not= new-state.auto-rotate nil) (set auto-rotate new-state.auto-rotate))
@ -229,5 +228,5 @@
(when use-texture (init-texture)))
(when (not= new-state.affine nil) (set affine new-state.affine))))
{: update
: frame}
{:update update
:frame frame}