Change the creation/deletion of tangibles so that the tangible database is never really deleted.

This commit is contained in:
2023-03-16 23:31:29 -04:00
parent 86a27ef2d4
commit a8c780563f
9 changed files with 152 additions and 90 deletions

View File

@@ -1,10 +1,11 @@
#include "world.hpp"
#include <iostream>
#include "world.hpp"
util::IdVector World::get_visible_union(int64_t actor_id, World *master) {
return util::sort_union_id_vectors(
master->get_near(actor_id, RadiusVisibility, true, false, false),
get_near(actor_id, RadiusVisibility, true, false, false));
master->get_near(actor_id, RadiusVisibility, true, false, false),
get_near(actor_id, RadiusVisibility, true, false, false));
}
int64_t World::patch_actor(StreamBuffer *sb, DebugCollector *dbc) {
@@ -27,14 +28,14 @@ int64_t World::patch_actor(StreamBuffer *sb, DebugCollector *dbc) {
return actor_id;
}
void World::diff_actor(int64_t actor_id, World *master, StreamBuffer *xsb) {
void World::diff_actor(int64_t actor_id, World *master, StreamBuffer *xsb) {
StreamBuffer tsb;
// Get the actor in both models. s_actor may be nil.
const Tangible *s_actor = tangible_get(actor_id);
const Tangible *m_actor = master->tangible_get(actor_id);
assert(m_actor != nullptr);
// Calculate diffs.
tsb.write_int64(actor_id);
if (s_actor == nullptr) {
@@ -85,15 +86,17 @@ void World::patch_visible(StreamBuffer *sb, DebugCollector *dbc) {
}
}
void World::diff_visible(const util::IdVector &visible, World *master, StreamBuffer *xsb) {
void World::diff_visible(const util::IdVector &visible, World *master,
StreamBuffer *xsb) {
StreamBuffer tsb;
// Get the specified tangibles in both models.
// Some tangibles may be missing in the master, some may be missing in the sync.
// Some tangibles may be missing in the master, some may be missing in the
// sync.
TanVector mvis = master->tangible_get_all(visible);
TanVector svis = tangible_get_all(visible);
assert(mvis.size() == svis.size());
// For each tangible that exists in the master, but not
// in the synchronous model, send a create message.
tsb.write_int32(0);
@@ -169,11 +172,13 @@ void World::patch_luatabs(StreamBuffer *sb, DebugCollector *dbc) {
int64_t actor_id = sb->read_int64();
util::HashValue closehash = sb->read_hashvalue();
int ncreate = sb->read_int32();
util::IdVector closetans = get_near(actor_id, RadiusClose, true, false, true);
util::IdVector closetans =
get_near(actor_id, RadiusClose, true, false, true);
assert(closehash == util::hash_id_vector(closetans));
number_lua_tables(closetans);
create_new_tables(ncreate);
// DebugLine(dbc) << "lua tables: " << nt << " existing " << ncreate << " new";
// DebugLine(dbc) << "lua tables: " << nt << " existing " << ncreate << "
// new";
patch_tangible_databases(sb, dbc);
patch_numbered_tables(sb, dbc);
unnumber_lua_tables();
@@ -183,7 +188,8 @@ void World::diff_luatabs(int64_t actor_id, World *master, StreamBuffer *xsb) {
StreamBuffer tsb;
// Calculate the set of close tangibles.
util::IdVector closetans = master->get_near(actor_id, RadiusClose, true, false, true);
util::IdVector closetans =
master->get_near(actor_id, RadiusClose, true, false, true);
assert(get_near(actor_id, RadiusClose, true, false, true) == closetans);
util::HashValue closehash = util::hash_id_vector(closetans);
@@ -199,7 +205,7 @@ void World::diff_luatabs(int64_t actor_id, World *master, StreamBuffer *xsb) {
tsb.write_int32(ncreate);
diff_tangible_databases(closetans, master->state(), &tsb);
diff_numbered_tables(master->state(), &tsb);
// Forward to client, and apply to server-synchronous.
tsb.copy_into(xsb);
assert(tsb.read_int64() == actor_id);
@@ -207,7 +213,7 @@ void World::diff_luatabs(int64_t actor_id, World *master, StreamBuffer *xsb) {
assert(tsb.read_int32() == ncreate);
patch_tangible_databases(&tsb, nullptr);
patch_numbered_tables(&tsb, nullptr);
assert(tsb.empty());
assert(tsb.empty());
// Unnumber tables in both models.
unnumber_lua_tables();
@@ -249,8 +255,10 @@ void World::diff_tanclass(int64_t actor_id, World *master, StreamBuffer *xsb) {
MLS.rawget(mtangibles, LuaRegistry, "tangibles");
// Calculate the set of close tangibles.
// TODO: we've already calculated this in an earlier function. This is wasteful.
util::IdVector closetans = master->get_near(actor_id, RadiusClose, true, false, true);
// TODO: we've already calculated this in an earlier function. This is
// wasteful.
util::IdVector closetans =
master->get_near(actor_id, RadiusClose, true, false, true);
tsb.write_int32(0);
int write_count_after = tsb.total_writes();
@@ -310,7 +318,7 @@ int64_t World::patch_everything(StreamBuffer *sb, DebugCollector *dbc) {
return actor_id;
}
void World::diff_everything(int64_t actor_id, World *master, StreamBuffer *sb) {
void World::diff_everything(int64_t actor_id, World *master, StreamBuffer *sb) {
diff_actor(actor_id, master, sb);
util::IdVector visible = get_visible_union(actor_id, master);
diff_visible(visible, master, sb);