diff --git a/demo/mod/worldgen.fnl b/demo/mod/worldgen.fnl index a10a8fc..d3be007 100644 --- a/demo/mod/worldgen.fnl +++ b/demo/mod/worldgen.fnl @@ -1,28 +1,27 @@ (local pxl8 (require :pxl8)) -(var world nil) +(local bob-amount 4.0) +(local bob-speed 8.0) +(var bob-time 0) (var cam-x 1000) (var cam-y 64) (var cam-z 1000) -(var cam-yaw 0) (var cam-pitch 0) -(var bob-time 0) -(var velocity-y 0) -(var grounded? true) -(var land-squash 0) - -(local move-speed 200) -(local turn-speed 2.0) -(local bob-speed 8.0) -(local bob-amount 4.0) -(local max-pitch 1.5) +(var cam-yaw 0) (local cell-size 64) -(local grid-size 32) (local gravity -800) -(local jump-force 175) +(local grid-size 32) +(var grounded? true) (local ground-y 64) +(local jump-force 175) +(var land-squash 0) (local land-squash-amount -4) (local land-recovery-speed 20) +(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)) diff --git a/pxl8.sh b/pxl8.sh index 3096771..adb1612 100755 --- a/pxl8.sh +++ b/pxl8.sh @@ -284,6 +284,8 @@ else BINDIR="$BINDIR/debug" fi +DEP_CFLAGS="-O3 -ffast-math -funroll-loops" + case "$COMMAND" in build) mkdir -p "$BUILDDIR" @@ -333,7 +335,8 @@ case "$COMMAND" in INCLUDES="-Isrc -Ilib -Ilib/microui/src -Ilib/luajit/src -Ilib/linenoise -Ilib/miniz" COMPILE_FLAGS="$CFLAGS $INCLUDES" - + DEP_COMPILE_FLAGS="$DEP_CFLAGS $INCLUDES" + EXECUTABLE="$BINDIR/pxl8" LIB_SOURCE_FILES="lib/linenoise/linenoise.c lib/microui/src/microui.c lib/miniz/miniz.c" @@ -376,7 +379,7 @@ case "$COMMAND" in if [[ "$src_file" -nt "$obj_file" ]]; then NEED_LINK=true - compile_source_file "$src_file" "$obj_file" "$COMPILE_FLAGS" + compile_source_file "$src_file" "$obj_file" "$DEP_COMPILE_FLAGS" SOURCES_COMPILED="yes" fi done diff --git a/src/pxl8_gfx.c b/src/pxl8_gfx.c index dd7f71b..b3cb16d 100644 --- a/src/pxl8_gfx.c +++ b/src/pxl8_gfx.c @@ -810,8 +810,9 @@ void pxl8_3d_clear_zbuffer(pxl8_gfx* gfx) { i32 count = gfx->zbuffer_width * gfx->zbuffer_height; const f32 far_z = 1e30f; + f32* ptr = gfx->zbuffer; for (i32 i = 0; i < count; i++) { - gfx->zbuffer[i] = far_z; + ptr[i] = far_z; } } @@ -1002,11 +1003,13 @@ static inline u32 pxl8_sample_texture(pxl8_gfx* gfx, u32 texture_id, f32 u, f32 return 0; } - u = u - floorf(u); - v = v - floorf(v); + i32 tex_u = (i32)(u * entry->w); + i32 tex_v = (i32)(v * entry->h); - i32 tx = (i32)(u * entry->w) % entry->w; - i32 ty = (i32)(v * entry->h) % entry->h; + i32 tx = tex_u % entry->w; + if (tx < 0) tx += entry->w; + i32 ty = tex_v % entry->h; + if (ty < 0) ty += entry->h; i32 atlas_x = entry->x + tx; i32 atlas_y = entry->y + ty;