feat(gui): add toolbar widget

feat(gui): add grid_select, toggle, panel, status_bar, image widgets
fix(bsp): fill in exterior cells
This commit is contained in:
asrael 2026-02-27 06:50:49 -06:00
parent 5a565844dd
commit 8d491612ab
63 changed files with 3150 additions and 1686 deletions

View file

@ -1,4 +1,3 @@
{:title "pxl8 demo"
:pixel-mode "indexed"
:resolution "640x360"
:window-size [1280 720]}

View file

@ -1,36 +1,9 @@
(local pxl8 (require :pxl8))
(local DOOR_HEIGHT 96)
(local DOOR_WIDTH 48)
(local DOOR_X 892)
(local DOOR_Z 416)
(local FIREBALL_COLOR 218)
(var door-mesh nil)
(var door-tex nil)
(var fireball-mesh nil)
(fn create-door-mesh [bsp ambient]
(let [verts []
indices []
hw (/ DOOR_WIDTH 2)
y0 0
y1 DOOR_HEIGHT
x DOOR_X
sample (fn [vx vy vz]
(if bsp (bsp:light_at vx vy vz (or ambient 0)) 200))]
(table.insert verts {:x x :y y0 :z (- DOOR_Z hw) :u 0 :v 1 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y0 (- DOOR_Z hw))})
(table.insert verts {:x x :y y0 :z (+ DOOR_Z hw) :u 1 :v 1 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y0 (+ DOOR_Z hw))})
(table.insert verts {:x x :y y1 :z (+ DOOR_Z hw) :u 1 :v 0 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y1 (+ DOOR_Z hw))})
(table.insert verts {:x x :y y1 :z (- DOOR_Z hw) :u 0 :v 0 :nx -1 :ny 0 :nz 0 :color 80 :light (sample x y1 (- DOOR_Z hw))})
(table.insert indices 0)
(table.insert indices 1)
(table.insert indices 2)
(table.insert indices 0)
(table.insert indices 2)
(table.insert indices 3)
(set door-mesh (pxl8.create_mesh verts indices))))
(fn create-fireball-mesh []
(let [verts []
indices []
@ -145,40 +118,15 @@
(set fireball-mesh (pxl8.create_mesh verts indices))))
(fn get-door-position []
(values DOOR_X DOOR_Z))
(fn get-door-radius []
20)
(fn init [textures]
(when (not fireball-mesh)
(create-fireball-mesh))
(when (and (not door-tex) textures)
(set door-tex (textures.door))))
(create-fireball-mesh)))
(fn setup-lighting [bsp ambient]
(when (and (not door-mesh) bsp)
(create-door-mesh bsp ambient)))
(fn render-door [wireframe floor-y]
(when (and door-mesh door-tex)
(pxl8.draw_mesh door-mesh {:x 0 :y (or floor-y 0) :z 0
:texture door-tex
:lighting true
:double_sided true
:wireframe wireframe})))
(fn render-fireball [x y z wireframe]
(fn render-fireball [x y z]
(when fireball-mesh
(pxl8.draw_mesh fireball-mesh {:x x :y y :z z
:emissive true
:wireframe wireframe})))
:emissive true})))
{:FIREBALL_COLOR FIREBALL_COLOR
:get-door-position get-door-position
:get-door-radius get-door-radius
:init init
:render-door render-door
:render-fireball render-fireball
:setup-lighting setup-lighting}
:render-fireball render-fireball}

View file

@ -8,8 +8,8 @@
(local sky (require :mod.sky))
(local textures (require :mod.textures))
(local bob-amount 4.0)
(local bob-speed 8.0)
(local bob-amount 3.0)
(local bob-speed 6.0)
(local cam-smoothing 0.25)
(local land-recovery-speed 20)
(local land-squash-amount -4)
@ -31,7 +31,6 @@
(var auto-run-cancel-key nil)
(var auto-run? false)
(var was-auto-running false)
(var bob-time 0)
(var cam-pitch 0)
(var day-time 0)
@ -40,29 +39,29 @@
(var cam-yaw 0)
(var cam-z 416)
(var camera nil)
(var ceiling-tex nil)
(var floor-tex nil)
(var land-squash 0)
(var last-dt 0.016)
(var light-time 0)
(var glows nil)
(var lights nil)
(var bsp-materials-setup false)
(var materials-set? false)
(var network nil)
(var portal-cooldown 0)
(var real-time 0)
(var smooth-cam-x 416)
(var smooth-cam-z 416)
(var was-grounded true)
(var trim-tex nil)
(var wall-tex nil)
(var world nil)
(local MOSS_COLOR 200)
(local PLASTER_COLOR 16)
(local GRASS_COLOR 200)
(local STONE_WALL_START 2)
(local WOOD_COLOR 88)
(local ASHLAR_COLOR 64)
(local ASHLAR_MOSS 68)
(local STONE_FLOOR_COLOR 72)
(local STONE_TRIM_COLOR 72)
(fn preload []
(when (not network)
(set network (net.get))
@ -71,8 +70,7 @@
(when (not world)
(set world (pxl8.get_world))
(when world
(world:set_sim_config sim-cfg)
(world:init_local_player cam-x cam-y cam-z))))
(world:set_sim_config sim-cfg))))
(fn is-connected []
(and network (network:connected)))
@ -111,29 +109,38 @@
(when world
(world:init_local_player cam-x cam-y cam-z)
(set smooth-cam-x cam-x)
(set smooth-cam-z cam-z))
(when (not ceiling-tex)
(set ceiling-tex (textures.plaster-wall 66666 PLASTER_COLOR)))
(when (not floor-tex)
(set floor-tex (textures.wood-planks 44444 WOOD_COLOR)))
(when (not trim-tex)
(set trim-tex (textures.wood-trim 77777 WOOD_COLOR)))
(when (not wall-tex)
(set wall-tex (textures.cobble-timber 55555 STONE_WALL_START MOSS_COLOR WOOD_COLOR))))
(set smooth-cam-z cam-z)))
(fn setup-materials []
(when (and world (not bsp-materials-setup) floor-tex trim-tex wall-tex)
(let [chunk (world:active_chunk)]
(when (and chunk (chunk:ready))
(let [floor-mat (pxl8.create_material {:texture floor-tex :lighting true :double_sided true})
trim-mat (pxl8.create_material {:texture trim-tex :lighting true :double_sided true})
wall-mat (pxl8.create_material {:texture wall-tex :lighting true :double_sided true})]
(world:set_bsp_material 0 floor-mat)
(world:set_bsp_material 1 wall-mat)
(world:set_bsp_material 3 trim-mat)
(entities.setup-lighting (chunk:bsp) 2)
(set bsp-materials-setup true))))))
(when (not world) (lua "return"))
(when (not network) (lua "return"))
(when materials-set? (lua "return"))
(when (not (network:has_chunk)) (lua "return"))
(let [chunk (world:active_chunk)]
(when (not chunk) (lua "return"))
(when (not (chunk:ready)) (lua "return"))
(let [dungeon-floor-tex (textures.wood-planks 44444 WOOD_COLOR)
dungeon-wall-tex (textures.cobble-timber 55555 STONE_WALL_START MOSS_COLOR WOOD_COLOR)
dungeon-trim-tex (textures.wood-trim 77777 WOOD_COLOR)
court-floor-tex (textures.rough-stone 44442 STONE_FLOOR_COLOR)
court-wall-tex (textures.ashlar-wall 55552 ASHLAR_COLOR ASHLAR_MOSS)
court-trim-tex (textures.rough-stone 77772 STONE_TRIM_COLOR)
grass-tex (textures.grass-top 44447 GRASS_COLOR)
dungeon-floor-mat (pxl8.create_material {:texture dungeon-floor-tex :lighting true :double_sided true})
dungeon-wall-mat (pxl8.create_material {:texture dungeon-wall-tex :lighting true :double_sided true})
dungeon-trim-mat (pxl8.create_material {:texture dungeon-trim-tex :lighting true :double_sided true})
court-floor-mat (pxl8.create_material {:texture court-floor-tex :lighting true :double_sided true})
court-wall-mat (pxl8.create_material {:texture court-wall-tex :lighting true :double_sided true})
court-trim-mat (pxl8.create_material {:texture court-trim-tex :lighting true :double_sided true})
grass-mat (pxl8.create_material {:texture grass-tex :lighting true :double_sided true})]
(world:set_bsp_material 0 dungeon-floor-mat)
(world:set_bsp_material 1 dungeon-wall-mat)
(world:set_bsp_material 3 dungeon-trim-mat)
(world:set_bsp_material 4 court-floor-mat)
(world:set_bsp_material 5 court-wall-mat)
(world:set_bsp_material 6 court-trim-mat)
(world:set_bsp_material 7 grass-mat)
(set materials-set? true))))
(fn sample-input []
(when (pxl8.key_pressed "`")
@ -147,8 +154,6 @@
(when (and auto-run-cancel-key (not (pxl8.key_down auto-run-cancel-key)))
(set auto-run-cancel-key nil))
(set was-auto-running auto-run?)
(pxl8.make_input_msg
{:move_x (+ (if (pxl8.key_down "d") 1 0) (if (pxl8.key_down "a") -1 0))
:move_y (+ (if (or (pxl8.key_down "w") auto-run?) 1 0)
@ -161,41 +166,6 @@
(set last-dt dt)
(setup-materials)
(when (> portal-cooldown 0)
(set portal-cooldown (- portal-cooldown dt)))
(when (and world network (<= portal-cooldown 0))
(let [(door-x door-z) (entities.get-door-position)
door-radius (entities.get-door-radius)
dist-to-door (math.sqrt (+ (* (- cam-x door-x) (- cam-x door-x))
(* (- cam-z door-z) (- cam-z door-z))))]
(when (< dist-to-door door-radius)
(let [current-id (network:chunk_id)]
(if (= current-id 1)
(do
(pxl8.info "Door: BSP 1 -> BSP 2")
(network:enter_scene 1 2 416 0 416)
(world:init_local_player 416 0 416)
(set cam-x 416)
(set cam-y 0)
(set cam-z 416)
(set smooth-cam-x 416)
(set smooth-cam-z 416)
(set bsp-materials-setup false)
(set portal-cooldown 2.0))
(= current-id 2)
(do
(pxl8.info "Door: BSP 2 -> BSP 1")
(network:enter_scene 1 1 416 0 416)
(world:init_local_player 416 0 416)
(set cam-x 416)
(set cam-y 0)
(set cam-z 416)
(set smooth-cam-x 416)
(set smooth-cam-z 416)
(set bsp-materials-setup false)
(set portal-cooldown 2.0)))))))
(when world
(let [input-msg (sample-input)
player (world:local_player)]
@ -286,9 +256,7 @@
(world:render [smooth-cam-x eye-y smooth-cam-z])
(when chunk
(entities.render-fireball light-x light-y light-z (menu.is-wireframe)))
(entities.render-door (menu.is-wireframe) 0)
(entities.render-fireball light-x light-y light-z))
(pxl8.end_frame_3d)