builtin/voxelworld, games/digger: Proper synchronization for using voxelworld's registries on the client
This commit is contained in:
parent
ee1df4fd40
commit
aff341b135
@ -44,6 +44,22 @@ M.chunk_size_voxels = nil
|
||||
M.section_size_chunks = nil
|
||||
M.section_size_voxels = nil
|
||||
|
||||
-- voxelworld is ready once the init and voxel_registry packets (and in the
|
||||
-- future possibly some other ones) have been received)
|
||||
local is_ready = false
|
||||
local on_ready_callbacks = {}
|
||||
|
||||
function on_ready()
|
||||
if is_ready then
|
||||
error("on_ready(): already ready")
|
||||
end
|
||||
is_ready = true
|
||||
for _, v in ipairs(on_ready_callbacks) do
|
||||
v()
|
||||
end
|
||||
on_ready_callbacks = nil
|
||||
end
|
||||
|
||||
function M.init()
|
||||
log:info("voxelworld.init()")
|
||||
|
||||
@ -86,6 +102,7 @@ function M.init()
|
||||
|
||||
buildat.sub_packet("voxelworld:voxel_registry", function(data)
|
||||
voxel_reg:deserialize(data)
|
||||
on_ready() -- This is the last packet
|
||||
end)
|
||||
|
||||
buildat.sub_packet("voxelworld:node_voxel_data_updated", function(data)
|
||||
@ -310,6 +327,14 @@ function M.get_atlas_registry()
|
||||
return atlas_reg
|
||||
end
|
||||
|
||||
function M.sub_ready(cb)
|
||||
if is_ready then
|
||||
cb()
|
||||
else
|
||||
table.insert(on_ready_callbacks, cb)
|
||||
end
|
||||
end
|
||||
|
||||
function send_get_section(p)
|
||||
local data = cereal.binary_output({
|
||||
p = {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "interface/voxel_volume.h"
|
||||
#include <PolyVoxCore/RawVolume.h>
|
||||
#include <cereal/archives/portable_binary.hpp>
|
||||
#include <cereal/types/string.hpp>
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#include <Node.h>
|
||||
@ -400,10 +401,29 @@ struct Module: public interface::Module, public voxelworld::Interface
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Store voxel registry and stuff
|
||||
std::ostringstream os(std::ios::binary);
|
||||
{
|
||||
cereal::PortableBinaryOutputArchive ar(os);
|
||||
ar(m_voxel_reg->serialize());
|
||||
}
|
||||
m_server->tmp_store_data("voxelworld:restore_info", os.str());
|
||||
}
|
||||
|
||||
void on_continue()
|
||||
{
|
||||
// Restore voxel registry and stuff
|
||||
ss_ data = m_server->tmp_restore_data("voxelworld:restore_info");
|
||||
ss_ voxel_reg_data;
|
||||
{
|
||||
std::istringstream is(data, std::ios::binary);
|
||||
cereal::PortableBinaryInputArchive ar(is);
|
||||
ar(voxel_reg_data);
|
||||
}
|
||||
m_voxel_reg->deserialize(voxel_reg_data);
|
||||
|
||||
// Start up normally
|
||||
on_start();
|
||||
}
|
||||
|
||||
|
@ -230,11 +230,15 @@ function setup_simple_voxel_data(node)
|
||||
node:SetScale(magic.Vector3(1, 1, 1))
|
||||
end
|
||||
|
||||
replicate.sub_sync_node_added({}, function(node)
|
||||
if not node:GetVar("simple_voxel_data"):IsEmpty() then
|
||||
setup_simple_voxel_data(node)
|
||||
end
|
||||
local name = node:GetName()
|
||||
voxelworld.sub_ready(function()
|
||||
-- Subscribe to this only after the voxelworld is ready because we are using
|
||||
-- voxelworld's registries
|
||||
replicate.sub_sync_node_added({}, function(node)
|
||||
if not node:GetVar("simple_voxel_data"):IsEmpty() then
|
||||
setup_simple_voxel_data(node)
|
||||
end
|
||||
local name = node:GetName()
|
||||
end)
|
||||
end)
|
||||
|
||||
-- vim: set noet ts=4 sw=4:
|
||||
|
Loading…
x
Reference in New Issue
Block a user