clean up worldgen and remove verbose logging
This commit is contained in:
parent
4d84122ef3
commit
34e534b6f2
11 changed files with 359 additions and 174 deletions
|
|
@ -469,11 +469,64 @@ function pxl8.world_generate(world, params)
|
|||
c_params.density = params.density or 0.45
|
||||
c_params.iterations = params.iterations or 4
|
||||
c_params.type_params = nil
|
||||
return C.pxl8_world_generate(world, c_params)
|
||||
return C.pxl8_world_generate(world, gfx, c_params)
|
||||
end
|
||||
|
||||
pxl8.PROCGEN_CAVE = C.PXL8_PROCGEN_CAVE
|
||||
pxl8.PROCGEN_DUNGEON = C.PXL8_PROCGEN_DUNGEON
|
||||
pxl8.PROCGEN_TERRAIN = C.PXL8_PROCGEN_TERRAIN
|
||||
|
||||
function pxl8.procgen_tex(params)
|
||||
local width = params.width or 64
|
||||
local height = params.height or 64
|
||||
local buffer = ffi.new("u8[?]", width * height)
|
||||
local tex_params = ffi.new("pxl8_procgen_tex_params")
|
||||
|
||||
local name = params.name or ""
|
||||
ffi.copy(tex_params.name, name, math.min(#name, 15))
|
||||
|
||||
tex_params.seed = params.seed or 0
|
||||
tex_params.width = width
|
||||
tex_params.height = height
|
||||
tex_params.scale = params.scale or 1.0
|
||||
tex_params.roughness = params.roughness or 0.0
|
||||
tex_params.base_color = params.base_color or 0
|
||||
tex_params.variation = params.variation or 0
|
||||
|
||||
C.pxl8_procgen_tex(buffer, tex_params)
|
||||
|
||||
local tex_id = C.pxl8_gfx_create_texture(gfx, buffer, width, height)
|
||||
if tex_id < 0 then
|
||||
return nil
|
||||
end
|
||||
return tex_id
|
||||
end
|
||||
|
||||
function pxl8.world_apply_textures(world, texture_defs)
|
||||
local count = #texture_defs
|
||||
local textures = ffi.new("pxl8_world_texture[?]", count)
|
||||
local callbacks = {}
|
||||
|
||||
for i, def in ipairs(texture_defs) do
|
||||
local idx = i - 1
|
||||
ffi.copy(textures[idx].name, def.name or "", math.min(#(def.name or ""), 15))
|
||||
textures[idx].texture_id = def.texture_id or 0
|
||||
|
||||
if def.rule then
|
||||
local cb = ffi.cast("bool (*)(const pxl8_vec3*, const pxl8_bsp_face*, const pxl8_bsp*)",
|
||||
function(normal, face, bsp)
|
||||
return def.rule(normal[0], face, bsp)
|
||||
end)
|
||||
textures[idx].rule = cb
|
||||
callbacks[idx + 1] = cb
|
||||
else
|
||||
textures[idx].rule = nil
|
||||
end
|
||||
end
|
||||
|
||||
local result = C.pxl8_world_apply_textures(world, textures, count)
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return pxl8
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue