mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Merge pull request #174 from IntQuant/faster_world_sync
Made chunk upload in world sync ~3 times faster.
This commit is contained in:
commit
fe4cf3f4bc
11 changed files with 359 additions and 116 deletions
19
quant.ew/files/system/ewext_init/ewext_init.lua
Normal file
19
quant.ew/files/system/ewext_init/ewext_init.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
local ffi = require("ffi")
|
||||
local world_ffi = require("noitapatcher.nsew.world_ffi")
|
||||
|
||||
local module = {}
|
||||
|
||||
function module.on_world_initialized()
|
||||
local grid_world = world_ffi.get_grid_world()
|
||||
local chunk_map = grid_world.vtable.get_chunk_map(grid_world)
|
||||
grid_world = tonumber(ffi.cast("intptr_t", grid_world))
|
||||
chunk_map = tonumber(ffi.cast("intptr_t", chunk_map))
|
||||
local material_list = tonumber(ffi.cast("intptr_t", world_ffi.get_material_ptr(0)))
|
||||
ewext.init_particle_world_state(grid_world, chunk_map, material_list)
|
||||
end
|
||||
|
||||
function module.on_local_player_spawn()
|
||||
|
||||
end
|
||||
|
||||
return module
|
|
@ -5,6 +5,8 @@ local world = {}
|
|||
local ffi = require("ffi")
|
||||
local world_ffi = require("noitapatcher.nsew.world_ffi")
|
||||
|
||||
print("get_cell: " .. tostring(world_ffi.get_cell))
|
||||
|
||||
local C = ffi.C
|
||||
|
||||
ffi.cdef([[
|
||||
|
@ -66,11 +68,11 @@ end
|
|||
-- @tparam EncodedArea encoded_area memory to use, if nil this function allocates its own memory
|
||||
-- @return returns an EncodedArea or nil if the area could not be encoded
|
||||
-- @see decode
|
||||
function world.encode_area(chunk_map, start_x, start_y, end_x, end_y, encoded_area)
|
||||
start_x = ffi.cast('int32_t', start_x)
|
||||
start_y = ffi.cast('int32_t', start_y)
|
||||
end_x = ffi.cast('int32_t', end_x)
|
||||
end_y = ffi.cast('int32_t', end_y)
|
||||
function world.encode_area(chunk_map, start_x_ini, start_y_ini, end_x_ini, end_y_ini, encoded_area)
|
||||
start_x = ffi.cast('int32_t', start_x_ini)
|
||||
start_y = ffi.cast('int32_t', start_y_ini)
|
||||
end_x = ffi.cast('int32_t', end_x_ini)
|
||||
end_y = ffi.cast('int32_t', end_y_ini)
|
||||
|
||||
encoded_area = encoded_area or world.EncodedArea()
|
||||
|
||||
|
@ -82,8 +84,8 @@ function world.encode_area(chunk_map, start_x, start_y, end_x, end_y, encoded_ar
|
|||
return nil
|
||||
end
|
||||
|
||||
if width > 256 or height > 256 then
|
||||
print("Invalid world part, dimension greater than 256")
|
||||
if width > 128 or height > 128 then
|
||||
print("Invalid world part, dimension greater than 128")
|
||||
return nil
|
||||
end
|
||||
|
||||
|
@ -92,74 +94,7 @@ function world.encode_area(chunk_map, start_x, start_y, end_x, end_y, encoded_ar
|
|||
encoded_area.header.width = width - 1
|
||||
encoded_area.header.height = height - 1
|
||||
|
||||
local run_count = 1
|
||||
|
||||
local current_run = encoded_area.pixel_runs[0]
|
||||
local run_length = 0
|
||||
local current_material = 0
|
||||
local current_flags = 0
|
||||
|
||||
local y = start_y
|
||||
while y < end_y do
|
||||
local x = start_x
|
||||
while x < end_x do
|
||||
local material_number = 0
|
||||
local flags = 0
|
||||
|
||||
local ppixel = world_ffi.get_cell(chunk_map, x, y)
|
||||
local pixel = ppixel[0]
|
||||
if pixel ~= nil then
|
||||
local cell_type = pixel.vtable.get_cell_type(pixel)
|
||||
|
||||
if cell_type ~= C.CELL_TYPE_SOLID then
|
||||
local material_ptr = pixel.vtable.get_material(pixel)
|
||||
material_number = world_ffi.get_material_id(material_ptr)
|
||||
end
|
||||
|
||||
if cell_type == C.CELL_TYPE_LIQUID then
|
||||
local liquid_cell = ffi.cast(pliquid_cell, pixel)
|
||||
if liquid_cell.is_static then
|
||||
flags = bit.bor(flags, C.LIQUID_FLAG_STATIC)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if x == start_x and y == start_y then
|
||||
-- Initial run
|
||||
current_material = material_number
|
||||
current_flags = flags
|
||||
elseif current_material ~= material_number or current_flags ~= flags then
|
||||
-- Next run
|
||||
current_run.length = run_length - 1
|
||||
current_run.material = current_material
|
||||
current_run.flags = current_flags
|
||||
|
||||
if run_count == C.PIXEL_RUN_MAX then
|
||||
print("Area too complicated to encode")
|
||||
return nil
|
||||
end
|
||||
|
||||
current_run = encoded_area.pixel_runs[run_count]
|
||||
run_count = run_count + 1
|
||||
|
||||
run_length = 0
|
||||
current_material = material_number
|
||||
current_flags = flags
|
||||
end
|
||||
|
||||
run_length = run_length + 1
|
||||
|
||||
x = x + 1
|
||||
end
|
||||
y = y + 1
|
||||
end
|
||||
|
||||
current_run.length = run_length - 1
|
||||
current_run.material = current_material
|
||||
current_run.flags = current_flags
|
||||
|
||||
encoded_area.header.pixel_run_count = run_count
|
||||
|
||||
encoded_area.header.pixel_run_count = ewext.encode_area(start_x_ini, start_y_ini, end_x_ini, end_y_ini, tonumber(ffi.cast("intptr_t", encoded_area.pixel_runs)))
|
||||
return encoded_area
|
||||
end
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ function world_sync.on_world_initialized()
|
|||
c = c - 1
|
||||
print("Last material id: "..c)
|
||||
world.last_material_id = c
|
||||
do_benchmark()
|
||||
end
|
||||
|
||||
local function send_chunks(cx, cy, chunk_map)
|
||||
|
|
|
@ -5,9 +5,6 @@ package.cpath = package.cpath .. ";./mods/quant.ew/?.dll"
|
|||
package.path = package.path .. ";./mods/quant.ew/?.lua"
|
||||
print(package.cpath)
|
||||
|
||||
-- ewext = require("ewext")
|
||||
-- ewext()
|
||||
|
||||
dofile_once( "data/scripts/lib/utilities.lua" )
|
||||
|
||||
dofile_once("mods/quant.ew/files/system/player/player_cosmetics.lua")
|
||||
|
@ -17,6 +14,8 @@ np.EnableGameSimulatePausing(false)
|
|||
np.InstallDamageDetailsPatch()
|
||||
np.SilenceLogs("Warning - streaming didn\'t find any chunks it could stream away...\n")
|
||||
|
||||
ewext = require("ewext")
|
||||
|
||||
-- Make some stuff global, as it's way too annoying to import each time.
|
||||
ctx = dofile_once("mods/quant.ew/files/core/ctx.lua")
|
||||
player_fns = dofile_once("mods/quant.ew/files/core/player_fns.lua")
|
||||
|
@ -42,6 +41,8 @@ np.CrossCallAdd("ew_per_peer_seed", function()
|
|||
end)
|
||||
|
||||
local function load_modules()
|
||||
ctx.load_system("ewext_init")
|
||||
|
||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/system/item_sync.lua")
|
||||
|
||||
ctx.dofile_and_add_hooks("mods/quant.ew/files/system/player_sync.lua")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue