Skip to content

Instantly share code, notes, and snippets.

@dextercd
Created August 23, 2022 22:21
Show Gist options
  • Save dextercd/1f064064cfb1dee3a080e7a01476a9b9 to your computer and use it in GitHub Desktop.
Save dextercd/1f064064cfb1dee3a080e7a01476a9b9 to your computer and use it in GitHub Desktop.
function OnWorldPostUpdate()
if connection == nil then
return
end
if os.getenv("ROLE") == "R" then
do_receive()
return
end
local grid_world = world_ffi.get_grid_world()
local chunk_map = grid_world.vtable.get_chunk_map(grid_world)
local thread_impl = grid_world.mThreadImpl
local begin = thread_impl.updated_grid_worlds.begin
local end_ = begin + thread_impl.chunk_update_count
local count = thread_impl.chunk_update_count
local result = ''
for i = 0, count - 1 do
local it = begin[i]
local start_x = it.update_region.top_left.x
local start_y = it.update_region.top_left.y
local end_x = it.update_region.bottom_right.x
local end_y = it.update_region.bottom_right.y
start_x = start_x - 1
start_y = start_y - 1
end_x = end_x + 1
end_y = end_y + 2
if start_x < end_x and start_y < end_y then
local area = world.encode_area(chunk_map, start_x, start_y, end_x, end_y, encoded_area)
if area == nil then
return
end
local str = ffi.string(area, world.encoded_size(area))
result = result .. str
end
end
for i = 0, tonumber(thread_impl.world_update_params_count) - 1 do
local wup = thread_impl.world_update_params.begin[i]
local start_x = wup.update_region.top_left.x
local start_y = wup.update_region.top_left.y
local end_x = wup.update_region.bottom_right.x
local end_y = wup.update_region.bottom_right.y
local area = world.encode_area(chunk_map, start_x, start_y, end_x, end_y, encoded_area)
if area == nil then
return
end
local str = ffi.string(area, world.encoded_size(area))
result = result .. str
end
send_str(result)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment