refactor: reorganize pxl8 into client/src/ module structure
- core/: main entry, types, logging, I/O, RNG - asset/: ase loader, cart, save, embed - gfx/: graphics, animation, atlas, fonts, tilemap, transitions - sfx/: audio - script/: lua/fennel runtime, REPL - hal/: platform abstraction (SDL3) - world/: BSP, world, procedural gen - math/: math utilities - game/: GUI, replay - lua/: Lua API modules
This commit is contained in:
parent
272e0bc615
commit
39b604b333
106 changed files with 6078 additions and 3715 deletions
|
|
@ -1,6 +1,10 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
|
||||
(var paused false)
|
||||
(var gui nil)
|
||||
|
||||
(fn init []
|
||||
(set gui (pxl8.create_gui)))
|
||||
|
||||
(fn show []
|
||||
(set paused true)
|
||||
|
|
@ -12,36 +16,39 @@
|
|||
(pxl8.set_relative_mouse_mode true))
|
||||
|
||||
(fn toggle []
|
||||
(when (not gui) (init))
|
||||
(if paused
|
||||
(hide)
|
||||
(show)))
|
||||
|
||||
(fn update []
|
||||
(let [(mx my) (pxl8.get_mouse_pos)]
|
||||
(pxl8.gui_cursor_move mx my))
|
||||
(when gui
|
||||
(let [(mx my) (pxl8.get_mouse_pos)]
|
||||
(gui:cursor_move mx my))
|
||||
|
||||
(when (pxl8.mouse_pressed 1)
|
||||
(pxl8.gui_cursor_down))
|
||||
(when (pxl8.mouse_pressed 1)
|
||||
(gui:cursor_down))
|
||||
|
||||
(when (pxl8.mouse_released 1)
|
||||
(pxl8.gui_cursor_up)))
|
||||
(when (pxl8.mouse_released 1)
|
||||
(gui:cursor_up))))
|
||||
|
||||
(fn draw []
|
||||
(pxl8.gui_begin_frame)
|
||||
(when gui
|
||||
(gui:begin_frame)
|
||||
|
||||
(pxl8.gui_window 200 100 240 140 "pxl8 demo")
|
||||
(pxl8.gui_window 200 100 240 140 "pxl8 demo")
|
||||
|
||||
(when (pxl8.gui_button 1 215 145 210 32 "Resume")
|
||||
(hide))
|
||||
(when (gui:button 1 215 145 210 32 "Resume")
|
||||
(hide))
|
||||
|
||||
(when (pxl8.gui_button 2 215 185 210 32 "Quit")
|
||||
(pxl8.quit))
|
||||
(when (gui:button 2 215 185 210 32 "Quit")
|
||||
(pxl8.quit))
|
||||
|
||||
(if (pxl8.gui_is_hovering)
|
||||
(pxl8.set_cursor :hand)
|
||||
(pxl8.set_cursor :arrow))
|
||||
(if (gui:is_hovering)
|
||||
(pxl8.set_cursor :hand)
|
||||
(pxl8.set_cursor :arrow))
|
||||
|
||||
(pxl8.gui_end_frame))
|
||||
(gui:end_frame)))
|
||||
|
||||
{:is-paused (fn [] paused)
|
||||
:toggle toggle
|
||||
|
|
|
|||
|
|
@ -64,16 +64,16 @@
|
|||
(local step-duration sixteenth)
|
||||
|
||||
(fn init []
|
||||
(set ctx (pxl8.sfx_context_create))
|
||||
(set ctx (pxl8.create_sfx_context))
|
||||
|
||||
(local reverb (pxl8.sfx_reverb_create
|
||||
(local reverb (pxl8.create_reverb
|
||||
{:room 0.5 :damping 0.4 :mix 0.35}))
|
||||
(local compressor (pxl8.sfx_compressor_create
|
||||
(local compressor (pxl8.create_compressor
|
||||
{:threshold -18 :ratio 6 :attack 3 :release 100}))
|
||||
(pxl8.sfx_context_append_node ctx reverb)
|
||||
(pxl8.sfx_context_append_node ctx compressor)
|
||||
(ctx:append_node reverb)
|
||||
(ctx:append_node compressor)
|
||||
|
||||
(pxl8.sfx_mixer_attach ctx)
|
||||
(ctx:attach)
|
||||
|
||||
(set melody-params (pxl8.sfx_voice_params
|
||||
{:waveform pxl8.SFX_WAVE_TRIANGLE
|
||||
|
|
@ -96,7 +96,7 @@
|
|||
|
||||
(fn stop []
|
||||
(set playing false)
|
||||
(pxl8.sfx_stop_all ctx))
|
||||
(ctx:stop_all))
|
||||
|
||||
(fn update [dt]
|
||||
(when playing
|
||||
|
|
@ -109,7 +109,7 @@
|
|||
(local melody-note (. melody-entry 1))
|
||||
(local melody-dur (. melody-entry 2))
|
||||
(when (> melody-note 0)
|
||||
(pxl8.sfx_play_note ctx melody-note melody-params 0.45 melody-dur))
|
||||
(ctx:play_note melody-note melody-params 0.45 melody-dur))
|
||||
|
||||
(local bass-step (math.floor (/ step 2)))
|
||||
(local bass-idx (+ 1 (% bass-step (length bass))))
|
||||
|
|
@ -117,7 +117,7 @@
|
|||
(local bass-note (. bass-entry 1))
|
||||
(local bass-dur (. bass-entry 2))
|
||||
(when (= (% step 2) 0)
|
||||
(pxl8.sfx_play_note ctx bass-note bass-params 0.55 bass-dur))
|
||||
(ctx:play_note bass-note bass-params 0.55 bass-dur))
|
||||
|
||||
(set step (+ step 1)))))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +1,41 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
|
||||
(var world nil)
|
||||
(local bob-amount 4.0)
|
||||
(local bob-speed 8.0)
|
||||
(local cam-smoothing 0.25)
|
||||
(local cell-size 64)
|
||||
(local cursor-sensitivity 0.008)
|
||||
(local gravity -800)
|
||||
(local grid-size 64)
|
||||
(local ground-y 64)
|
||||
(local jump-force 175)
|
||||
(local land-recovery-speed 20)
|
||||
(local land-squash-amount -4)
|
||||
(local max-pitch 1.5)
|
||||
(local move-speed 200)
|
||||
(local turn-speed 2.0)
|
||||
|
||||
(var auto-run? false)
|
||||
(var auto-run-cancel-key nil)
|
||||
(var bob-time 0)
|
||||
(var cam-pitch 0)
|
||||
(var cam-x 1000)
|
||||
(var cam-y 64)
|
||||
(var cam-yaw 0)
|
||||
(var cam-z 1000)
|
||||
(var camera nil)
|
||||
(var cursor-look? true)
|
||||
|
||||
(var grounded? true)
|
||||
(var land-squash 0)
|
||||
(var smooth-cam-x 1000)
|
||||
(var smooth-cam-z 1000)
|
||||
(local cam-smoothing 0.25)
|
||||
|
||||
(local bob-amount 4.0)
|
||||
(local bob-speed 8.0)
|
||||
(var bob-time 0)
|
||||
(local cell-size 64)
|
||||
(local cursor-sensitivity 0.008)
|
||||
(local gravity -800)
|
||||
(local grid-size 64)
|
||||
(var grounded? true)
|
||||
(local ground-y 64)
|
||||
(local jump-force 175)
|
||||
(local land-recovery-speed 20)
|
||||
(local land-squash-amount -4)
|
||||
(var land-squash 0)
|
||||
(local max-pitch 1.5)
|
||||
(local move-speed 200)
|
||||
(local turn-speed 2.0)
|
||||
(var velocity-y 0)
|
||||
(var world nil)
|
||||
|
||||
(fn init []
|
||||
(set world (pxl8.world_new))
|
||||
(let [result (pxl8.world_generate world {
|
||||
(set camera (pxl8.create_camera_3d))
|
||||
(set world (pxl8.create_world))
|
||||
(let [result (world:generate {
|
||||
:type pxl8.PROCGEN_ROOMS
|
||||
:width 64
|
||||
:height 64
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
:height 64
|
||||
:base_color 4})]
|
||||
|
||||
(let [result (pxl8.world_apply_textures world [
|
||||
(let [result (world:apply_textures [
|
||||
{:name "floor"
|
||||
:texture_id floor-tex
|
||||
:rule (fn [normal] (> normal.y 0.7))}
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
(when (and auto-run-cancel-key (not (pxl8.key_down auto-run-cancel-key)))
|
||||
(set auto-run-cancel-key nil))
|
||||
|
||||
(when (pxl8.world_is_loaded world)
|
||||
(when (world:is_loaded)
|
||||
(let [forward-x (- (math.sin cam-yaw))
|
||||
forward-z (- (math.cos cam-yaw))
|
||||
right-x (math.cos cam-yaw)
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
|
||||
(when (and (>= new-x 0) (<= new-x grid-max)
|
||||
(>= new-z 0) (<= new-z grid-max))
|
||||
(let [(resolved-x resolved-y resolved-z) (pxl8.world_resolve_collision world cam-x cam-y cam-z new-x cam-y new-z 5)]
|
||||
(let [(resolved-x resolved-y resolved-z) (world:resolve_collision cam-x cam-y cam-z new-x cam-y new-z 5)]
|
||||
(set cam-x resolved-x)
|
||||
(set cam-z resolved-z)))
|
||||
|
||||
|
|
@ -176,31 +176,36 @@
|
|||
(fn frame []
|
||||
(pxl8.clear 0)
|
||||
|
||||
(when (pxl8.world_is_loaded world)
|
||||
(when (not camera)
|
||||
(pxl8.error "camera is nil!"))
|
||||
|
||||
(when (not world)
|
||||
(pxl8.error "world is nil!"))
|
||||
|
||||
(when (and world (not (world:is_loaded)))
|
||||
(pxl8.text "World not loaded yet..." 5 30 12))
|
||||
|
||||
(when (and camera world (world:is_loaded))
|
||||
(let [bob-offset (* (math.sin bob-time) bob-amount)
|
||||
eye-y (+ cam-y bob-offset land-squash)
|
||||
forward-x (- (math.sin cam-yaw))
|
||||
forward-z (- (math.cos cam-yaw))
|
||||
target-x (+ smooth-cam-x forward-x)
|
||||
target-y (+ eye-y (math.sin cam-pitch))
|
||||
target-z (+ smooth-cam-z forward-z)]
|
||||
target-z (+ smooth-cam-z forward-z)
|
||||
aspect (/ (pxl8.get_width) (pxl8.get_height))]
|
||||
|
||||
(pxl8.clear_zbuffer)
|
||||
(pxl8.set_backface_culling true)
|
||||
(pxl8.set_wireframe false)
|
||||
(camera:lookat [smooth-cam-x eye-y smooth-cam-z]
|
||||
[target-x target-y target-z]
|
||||
[0 1 0])
|
||||
(camera:set_perspective 1.047 aspect 1.0 4096.0)
|
||||
|
||||
(let [aspect (/ (pxl8.get_width) (pxl8.get_height))
|
||||
fov 1.047]
|
||||
(pxl8.set_projection (pxl8.mat4_perspective fov aspect 1.0 4096.0)))
|
||||
(pxl8.begin_frame_3d camera)
|
||||
(pxl8.clear_depth)
|
||||
|
||||
(pxl8.set_view (pxl8.mat4_lookat
|
||||
[smooth-cam-x eye-y smooth-cam-z]
|
||||
[target-x target-y target-z]
|
||||
[0 1 0]))
|
||||
(world:render [smooth-cam-x eye-y smooth-cam-z])
|
||||
|
||||
(pxl8.set_model (pxl8.mat4_identity))
|
||||
|
||||
(pxl8.world_render world [smooth-cam-x eye-y smooth-cam-z])
|
||||
(pxl8.end_frame_3d)
|
||||
|
||||
(let [cx (/ (pxl8.get_width) 2)
|
||||
cy (/ (pxl8.get_height) 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue