More work on table diff xmit

This commit is contained in:
2021-09-07 14:38:46 -04:00
parent 5cefa4f1e2
commit 2165bb578c
3 changed files with 74 additions and 13 deletions

View File

@@ -3,8 +3,15 @@
// This file contains the code to compare the contents of tables.
// The top level functions in this file are:
//
// World::diff_lua_tables
// World::diff_numbered_tables
// World::diff_tangible_databases
// World::patch_numbered_tables
// World::patch_tangible_databases
//
// It also contains these unit testing support routines:
//
// table.diffcompare
// table.diffapply
//
// This file also contains all the support code needed to implement
// this stuff.
@@ -321,6 +328,7 @@ void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
MLS.rawgeti(mtab, mntmap, id);
if (MLS.istable(mtab)) {
SLS.rawgeti(stab, sntmap, id);
assert(SLS.istable(stab));
int tw = sb->total_writes();
sb->write_int32(id);
nmodified += 1;
@@ -367,6 +375,44 @@ void World::diff_tangible_databases(const IdVector &basis, lua_State *master, St
sb->overwrite_int32(write_count_after, nmodified);
}
void World::patch_numbered_tables(StreamBuffer *sb) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
assert(LS.istable(ntmap));
int nmodified = sb->read_int32();
for (int i = 0; i < nmodified; i++) {
int index = sb->read_int32();
LS.rawgeti(tab, ntmap, index);
assert(LS.istable(tab));
patch_table(LS, tangibles, ntmap, tab, sb);
}
LS.result();
}
void World::patch_tangible_databases(StreamBuffer *sb) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
assert(LS.istable(ntmap));
int nmodified = sb->read_int32();
for (int i = 0; i < nmodified; i++) {
int64_t id = sb->read_int64();
LS.rawgeti(tab, tangibles, id);
assert(LS.istable(tab));
patch_table(LS, tangibles, ntmap, tab, sb);
}
LS.result();
}
LuaDefine(table_diffcompare, "c") {
LuaArg mtnmap, mtab, mstnmap, mstab, stnmap, stab;
LuaRet dbgstring;

View File

@@ -59,7 +59,7 @@ World::World(util::WorldType wt) {
// Create the globaldb in the registry.
LS.rawset(LuaRegistry, "globaldb", LuaNewTable);
// Initialize the SourceDB. At this stage, the sourcedb is
// empty, so it's just populating the lua builtins.
source_db_.init(state());
@@ -1072,7 +1072,7 @@ static bool worlds_identical(const std::unique_ptr<World> &w1, const std::unique
return sbw1.contents_equal(&sbw2);
}
LuaDefine(unittests_world, "c") {
LuaDefine(unittests_worlddiffs, "c") {
std::unique_ptr<World> m, ss, cs;
StreamBuffer sb;
int ncreate;
@@ -1188,4 +1188,4 @@ LuaDefine(unittests_world, "c") {
LuaAssert(L, worlds_identical(ss, cs));
return 0;
}
}

View File

@@ -285,18 +285,10 @@ private:
static void diff_visible_animations(const TanVector &mvis, const TanVector &svis, StreamBuffer *sb);
void patch_visible_animations(StreamBuffer *sb);
// Compare the numbered general tables.
//
void diff_numbered_tables(lua_State *master, StreamBuffer *sb);
// Compare the tangible databases.
//
void diff_tangible_databases(const IdVector &basis, lua_State *master, StreamBuffer *sb);
public:
///////////////////////////////////////////////////////////
//
// Numbering and pairing of lua tables.
// world-pairtab: Numbering and pairing of lua tables.
//
// The following routines pair up tables in the synchronous
// model with tables in the master model, by assigning matching
@@ -347,6 +339,29 @@ public:
//
void unnumber_lua_tables();
public:
///////////////////////////////////////////////////////////
//
// world-difftab: Nonrecursive table comparison
//
// These routines compare tables in the master lua to the corresponding
// tables in the synchronous lua. This is a nonrecursive process, because
// the recursion has already been done during the table enumeration process.
//
///////////////////////////////////////////////////////////
// Compare the numbered general tables.
//
void diff_numbered_tables(lua_State *master, StreamBuffer *sb);
// Compare the tangible databases.
//
void diff_tangible_databases(const IdVector &basis, lua_State *master, StreamBuffer *sb);
void patch_numbered_tables(StreamBuffer *sb);
void patch_tangible_databases(StreamBuffer *sb);
private:
// Type of model
util::WorldType world_type_;