Lots of work on debugging diff xmit

This commit is contained in:
2021-11-21 13:35:39 -05:00
parent 0881e33c6f
commit b19825aaca
23 changed files with 338 additions and 99 deletions

View File

@@ -7,18 +7,21 @@ util::IdVector World::get_visible_union(int64_t actor_id, World *master) {
get_near_unsorted(actor_id, RadiusVisibility, true));
}
int64_t World::patch_actor(StreamBuffer *sb) {
int64_t World::patch_actor(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_actor");
int64_t actor_id = sb->read_int64();
Tangible *s_actor = tangible_get(actor_id);
if (s_actor == nullptr) {
DebugLine(dbc) << "create new actor " << actor_id;
s_actor = tangible_make(nullptr, actor_id, "", false);
s_actor->id_player_pool_.deserialize(sb);
s_actor->anim_queue_.deserialize(sb);
s_actor->print_buffer_.deserialize(sb);
} else {
s_actor->id_player_pool_.patch(sb);
s_actor->anim_queue_.patch(sb);
s_actor->print_buffer_.patch(sb);
DebugHeader(dbc) << "patching actor " << actor_id << ":";
s_actor->id_player_pool_.patch(sb, dbc);
s_actor->anim_queue_.patch(sb, dbc);
s_actor->print_buffer_.patch(sb, dbc);
}
s_actor->update_plane_item();
return actor_id;
@@ -46,15 +49,17 @@ void World::diff_actor(int64_t actor_id, World *master, StreamBuffer *xsb) {
// Forward to client, and apply to server-synchronous.
tsb.copy_into(xsb);
patch_actor(&tsb);
patch_actor(&tsb, nullptr);
assert(tsb.empty());
}
void World::patch_visible(StreamBuffer *sb) {
void World::patch_visible(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_visible");
// Receive create messages.
int count = sb->read_int32();
for (int i = 0; i < count; i++) {
int64_t id = sb->read_int64();
DebugLine(dbc) << "patch_visible create tan " << id;
Tangible *t = tangible_make(state(), id, "", false);
t->anim_queue_.deserialize(sb);
t->update_plane_item();
@@ -64,6 +69,7 @@ void World::patch_visible(StreamBuffer *sb) {
count = sb->read_int32();
for (int i = 0; i < count; i++) {
int64_t id = sb->read_int64();
DebugLine(dbc) << "patch_visible delete tan " << id;
tangible_delete(id);
}
@@ -71,9 +77,10 @@ void World::patch_visible(StreamBuffer *sb) {
count = sb->read_int32();
for (int i = 0; i < count; i++) {
int64_t id = sb->read_int64();
DebugLine(dbc) << "patch_visible animqueue tan " << id;
Tangible *t = tangible_get(id);
assert(t != nullptr);
t->anim_queue_.patch(sb);
t->anim_queue_.patch(sb, dbc);
}
}
@@ -126,10 +133,12 @@ void World::diff_visible(const util::IdVector &visible, World *master, StreamBuf
const Tangible *mt = mvis[i];
const Tangible *st = svis[i];
if ((mt != nullptr) && (st != nullptr)) {
if (st->anim_queue_.need_patch(mt->anim_queue_)) {
int64_t unwind = tsb.total_writes();
tsb.write_int64(st->id());
if (st->anim_queue_.diff(mt->anim_queue_, &tsb)) {
count++;
tsb.write_int64(st->id());
st->anim_queue_.diff(mt->anim_queue_, &tsb);
} else {
tsb.unwrite_to(unwind);
}
}
}
@@ -137,7 +146,7 @@ void World::diff_visible(const util::IdVector &visible, World *master, StreamBuf
// Forward to client, and apply to server-synchronous.
tsb.copy_into(xsb);
patch_visible(&tsb);
patch_visible(&tsb, nullptr);
assert(tsb.empty());
// Copy the version number from master animqueue to synch animqueue.
@@ -154,16 +163,18 @@ void World::diff_visible(const util::IdVector &visible, World *master, StreamBuf
}
}
void World::patch_luatabs(StreamBuffer *sb) {
void World::patch_luatabs(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_luatabs");
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);
assert(closehash == util::hash_id_vector(closetans));
number_lua_tables(closetans);
int nt = number_lua_tables(closetans);
create_new_tables(ncreate);
patch_tangible_databases(sb);
patch_numbered_tables(sb);
DebugLine(dbc) << "lua tables: " << nt << " existing " << ncreate << " new";
patch_tangible_databases(sb, dbc);
patch_numbered_tables(sb, dbc);
unnumber_lua_tables();
}
@@ -193,8 +204,8 @@ void World::diff_luatabs(int64_t actor_id, World *master, StreamBuffer *xsb) {
assert(tsb.read_int64() == actor_id);
assert(tsb.read_hashvalue() == closehash);
assert(tsb.read_int32() == ncreate);
patch_tangible_databases(&tsb);
patch_numbered_tables(&tsb);
patch_tangible_databases(&tsb, nullptr);
patch_numbered_tables(&tsb, nullptr);
assert(tsb.empty());
// Unnumber tables in both models.
@@ -202,7 +213,8 @@ void World::diff_luatabs(int64_t actor_id, World *master, StreamBuffer *xsb) {
master->unnumber_lua_tables();
}
void World::patch_tanclass(StreamBuffer *sb) {
void World::patch_tanclass(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_tanclass");
lua_State *L = state();
LuaVar tangibles, tab, meta, sclass;
LuaStack LS(L, tangibles, tab, meta, sclass);
@@ -262,14 +274,16 @@ void World::diff_tanclass(int64_t actor_id, World *master, StreamBuffer *xsb) {
// Forward to client, and apply to server-synchronous.
tsb.copy_into(xsb);
patch_tanclass(&tsb);
patch_tanclass(&tsb, nullptr);
assert(tsb.empty());
}
void World::patch_source(StreamBuffer *sb) {
bool modified = source_db_.patch(sb);
void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_source");
bool modified = source_db_.patch(sb, dbc);
if (modified) {
std::string errs = source_db_.rebuild();
DebugLine(dbc) << "Source DB rebuilt";
// TODO: I don't currently have any good place to send the
// error messages. This is a stopgap.
std::cerr << errs;
@@ -277,15 +291,20 @@ void World::patch_source(StreamBuffer *sb) {
}
void World::diff_source(World *master, StreamBuffer *sb) {
source_db_.diff(master->source_db_, sb);
StreamBuffer tsb;
source_db_.diff(master->source_db_, &tsb);
tsb.copy_into(sb);
patch_source(&tsb, nullptr);
assert(tsb.empty());
}
int64_t World::patch_everything(StreamBuffer *sb) {
int64_t actor_id = patch_actor(sb);
patch_visible(sb);
patch_luatabs(sb);
patch_tanclass(sb);
patch_source(sb);
int64_t World::patch_everything(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_everything");
int64_t actor_id = patch_actor(sb, dbc);
patch_visible(sb, dbc);
patch_luatabs(sb, dbc);
patch_tanclass(sb, dbc);
patch_source(sb, dbc);
return actor_id;
}