2025-11-15 11:40:27 -06:00
|
|
|
local ffi = require("ffi")
|
|
|
|
|
local C = ffi.C
|
|
|
|
|
local core = require("pxl8.core")
|
|
|
|
|
|
|
|
|
|
local world = {}
|
|
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
world.CHUNK_VXL = 0
|
|
|
|
|
world.CHUNK_BSP = 1
|
2025-11-15 11:40:27 -06:00
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
local Bsp = {}
|
|
|
|
|
Bsp.__index = Bsp
|
2025-11-15 11:40:27 -06:00
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
function Bsp:face_count()
|
|
|
|
|
return C.pxl8_bsp_face_count(self._ptr)
|
2025-11-15 11:40:27 -06:00
|
|
|
end
|
|
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
function Bsp:face_normal(face_id)
|
|
|
|
|
return C.pxl8_bsp_face_normal(self._ptr, face_id)
|
|
|
|
|
end
|
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
2026-01-12 21:46:31 -06:00
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
function Bsp:face_set_material(face_id, material_id)
|
|
|
|
|
C.pxl8_bsp_face_set_material(self._ptr, face_id, material_id)
|
2025-11-15 11:40:27 -06:00
|
|
|
end
|
|
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
world.Bsp = Bsp
|
|
|
|
|
|
|
|
|
|
local Chunk = {}
|
|
|
|
|
Chunk.__index = Chunk
|
|
|
|
|
|
|
|
|
|
function Chunk:bsp()
|
|
|
|
|
if self._ptr == nil then return nil end
|
|
|
|
|
if self._ptr.type ~= world.CHUNK_BSP then return nil end
|
|
|
|
|
local ptr = self._ptr.bsp
|
|
|
|
|
if ptr == nil then return nil end
|
|
|
|
|
return setmetatable({ _ptr = ptr }, Bsp)
|
2025-11-15 11:40:27 -06:00
|
|
|
end
|
|
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
function Chunk:ready()
|
|
|
|
|
if self._ptr == nil then return false end
|
|
|
|
|
if self._ptr.type == world.CHUNK_BSP then
|
|
|
|
|
return self._ptr.bsp ~= nil
|
|
|
|
|
elseif self._ptr.type == world.CHUNK_VXL then
|
2026-01-31 09:31:17 -06:00
|
|
|
return self._ptr.voxels ~= nil
|
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
2026-01-12 21:46:31 -06:00
|
|
|
end
|
2026-01-25 09:26:30 -06:00
|
|
|
return false
|
2025-11-15 11:40:27 -06:00
|
|
|
end
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
function Chunk:type()
|
|
|
|
|
if self._ptr == nil then return nil end
|
|
|
|
|
return self._ptr.type
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Chunk:version()
|
|
|
|
|
if self._ptr == nil then return 0 end
|
|
|
|
|
return self._ptr.version
|
|
|
|
|
end
|
|
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
world.Chunk = Chunk
|
|
|
|
|
|
|
|
|
|
local World = {}
|
|
|
|
|
World.__index = World
|
|
|
|
|
|
|
|
|
|
function World.get()
|
|
|
|
|
local w = C.pxl8_get_world(core.sys)
|
|
|
|
|
if w == nil then return nil end
|
|
|
|
|
return setmetatable({ _ptr = w }, World)
|
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
2026-01-12 21:46:31 -06:00
|
|
|
end
|
|
|
|
|
|
2026-01-25 09:26:30 -06:00
|
|
|
function World:active_chunk()
|
|
|
|
|
local ptr = C.pxl8_world_active_chunk(self._ptr)
|
|
|
|
|
if ptr == nil then return nil end
|
|
|
|
|
return setmetatable({ _ptr = ptr }, Chunk)
|
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
2026-01-12 21:46:31 -06:00
|
|
|
end
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
function World:get_render_distance()
|
|
|
|
|
return C.pxl8_world_get_render_distance(self._ptr)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:get_sim_distance()
|
|
|
|
|
return C.pxl8_world_get_sim_distance(self._ptr)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:init_local_player(x, y, z)
|
|
|
|
|
C.pxl8_world_init_local_player(self._ptr, x, y, z)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:local_player()
|
|
|
|
|
local ptr = C.pxl8_world_local_player(self._ptr)
|
|
|
|
|
if ptr == nil then return nil end
|
|
|
|
|
return ptr
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:point_solid(x, y, z)
|
|
|
|
|
return C.pxl8_world_point_solid(self._ptr, x, y, z)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:ray(from_x, from_y, from_z, to_x, to_y, to_z)
|
|
|
|
|
local from = ffi.new("pxl8_vec3", {x = from_x, y = from_y, z = from_z})
|
|
|
|
|
local to = ffi.new("pxl8_vec3", {x = to_x, y = to_y, z = to_z})
|
|
|
|
|
return C.pxl8_world_ray(self._ptr, from, to)
|
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
2026-01-12 21:46:31 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:render(camera_pos)
|
|
|
|
|
local vec = ffi.new("pxl8_vec3", {x = camera_pos[1], y = camera_pos[2], z = camera_pos[3]})
|
|
|
|
|
C.pxl8_world_render(self._ptr, core.gfx, vec)
|
|
|
|
|
end
|
|
|
|
|
|
2026-01-31 09:31:17 -06:00
|
|
|
function World:set_bsp_material(material_id, material)
|
|
|
|
|
C.pxl8_world_set_bsp_material(self._ptr, material_id, material._ptr)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:set_render_distance(distance)
|
|
|
|
|
C.pxl8_world_set_render_distance(self._ptr, distance)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:set_sim_distance(distance)
|
|
|
|
|
C.pxl8_world_set_sim_distance(self._ptr, distance)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function World:sweep(from_x, from_y, from_z, to_x, to_y, to_z, radius)
|
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
2026-01-12 21:46:31 -06:00
|
|
|
local from = ffi.new("pxl8_vec3", {x = from_x, y = from_y, z = from_z})
|
|
|
|
|
local to = ffi.new("pxl8_vec3", {x = to_x, y = to_y, z = to_z})
|
2026-01-31 09:31:17 -06:00
|
|
|
return C.pxl8_world_sweep(self._ptr, from, to, radius)
|
2025-11-15 11:40:27 -06:00
|
|
|
end
|
|
|
|
|
|
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
2026-01-12 21:46:31 -06:00
|
|
|
world.World = World
|
|
|
|
|
|
2025-11-15 11:40:27 -06:00
|
|
|
return world
|