Fix a bug in synchronous model similarity

This commit is contained in:
2021-12-21 15:22:26 -05:00
parent f2a20c0231
commit b4639c70db
5 changed files with 48 additions and 16 deletions

View File

@@ -1,8 +1,46 @@
#include "luastack.hpp" #include "luastack.hpp"
#include "globaldb.hpp" #include "globaldb.hpp"
LuaDefine(global_once, "string", "for a given string, returns true exactly once") {
LuaArg name;
LuaRet flag;
LuaVar oncedb, val;
LuaStack LS(L, name, flag, oncedb, val);
LuaDefine(global, "globalname", "get a table where global data can be stored") { // Get a pointer to the oncedb.
LS.rawget(oncedb, LuaRegistry, "oncedb");
if (!LS.istable(oncedb)) {
LS.set(flag, false);
return LS.result();
}
LS.checkstring(name);
LS.rawget(val, oncedb, name);
if (!LS.isnil(val)) {
LS.set(flag, false);
return LS.result();
}
LS.rawset(oncedb, name, true);
LS.set(flag, true);
return LS.result();
}
LuaDefine(global_clearonce, "name", "reset the specified once-flag") {
LuaArg name;
LuaVar oncedb;
LuaStack LS(L, name, oncedb);
// Get a pointer to the oncedb.
LS.rawget(oncedb, LuaRegistry, "oncedb");
if (!LS.istable(oncedb)) {
return LS.result();
}
LS.checkstring(name);
LS.rawset(oncedb, name, LuaNil);
return LS.result();
}
LuaDefine(global_table, "globalname", "get a table where global data can be stored") {
LuaArg globalname; LuaArg globalname;
LuaRet globaltab; LuaRet globaltab;
LuaVar globaldb; LuaVar globaldb;

View File

@@ -28,14 +28,6 @@
#include "luastack.hpp" #include "luastack.hpp"
// The lua 'global' operator.
//
// Given a global name, returns a table for that global.
//
// If you haven't enabled the global DB using globaldb_enable, this
// raises a donotpredict error.
//
int globaldb_global(lua_State *L);
#endif // GLOBALDB_HPP #endif // GLOBALDB_HPP

View File

@@ -24,18 +24,15 @@ public:
// Create the world model. // Create the world model.
world_.reset(new World(util::WORLD_TYPE_C_SYNC)); world_.reset(new World(util::WORLD_TYPE_C_SYNC));
// Snapshot the initial state.
world_->snapshot();
// Clear the unack command queue.
unack_.clear();
// This is a temporary actor that will be used only until the server sends // This is a temporary actor that will be used only until the server sends
// us the first difference transmission. We do this only to establish // us the first difference transmission. We do this only to establish
// the invariant that there's always an actor. When the first difference // the invariant that there's always an actor. When the first difference
// transmission arrives, this actor may be deleted, or it may just be // transmission arrives, this actor may be deleted, or it may just be
// ignored, at the server's discretion. // ignored, at the server's discretion.
actor_id_ = world_->create_login_actor(); actor_id_ = world_->create_login_actor();
// Clear the unack command queue.
unack_.clear();
} }

View File

@@ -61,9 +61,10 @@ World::World(util::WorldType wt) {
// Create the tangibles table in the registry. // Create the tangibles table in the registry.
LS.rawset(LuaRegistry, "tangibles", LuaNewTable); LS.rawset(LuaRegistry, "tangibles", LuaNewTable);
// Create the globaldb in the registry. // Create the globaldb and oncedb in the registry.
if (util::world_type_authoritative(wt)) { if (util::world_type_authoritative(wt)) {
LS.rawset(LuaRegistry, "globaldb", LuaNewTable); LS.rawset(LuaRegistry, "globaldb", LuaNewTable);
LS.rawset(LuaRegistry, "oncedb", LuaNewTable);
} }
// Initialize the SourceDB. At this stage, the sourcedb is // Initialize the SourceDB. At this stage, the sourcedb is

View File

@@ -169,6 +169,7 @@ void World::patch_luatabs(StreamBuffer *sb, DebugCollector *dbc) {
util::HashValue closehash = sb->read_hashvalue(); util::HashValue closehash = sb->read_hashvalue();
int ncreate = sb->read_int32(); int ncreate = sb->read_int32();
util::IdVector closetans = get_near(actor_id, RadiusClose, true, false); util::IdVector closetans = get_near(actor_id, RadiusClose, true, false);
std::cerr << "Sync closetans=" << util::id_vector_debug_string(closetans) << std::endl;
assert(closehash == util::hash_id_vector(closetans)); assert(closehash == util::hash_id_vector(closetans));
number_lua_tables(closetans); number_lua_tables(closetans);
create_new_tables(ncreate); create_new_tables(ncreate);
@@ -183,6 +184,7 @@ void World::diff_luatabs(int64_t actor_id, World *master, StreamBuffer *xsb) {
// Calculate the set of close tangibles. // Calculate the set of close tangibles.
util::IdVector closetans = master->get_near(actor_id, RadiusClose, true, false); util::IdVector closetans = master->get_near(actor_id, RadiusClose, true, false);
std::cerr << "Master closetans=" << util::id_vector_debug_string(closetans) << std::endl;
assert(get_near(actor_id, RadiusClose, true, false) == closetans); assert(get_near(actor_id, RadiusClose, true, false) == closetans);
util::HashValue closehash = util::hash_id_vector(closetans); util::HashValue closehash = util::hash_id_vector(closetans);
@@ -281,6 +283,7 @@ void World::diff_tanclass(int64_t actor_id, World *master, StreamBuffer *xsb) {
void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) { void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) {
DebugBlock dbb(dbc, "patch_source"); DebugBlock dbb(dbc, "patch_source");
std::cerr << "Before PS ids=" << tangible_ids_debug_string() << std::endl;
bool modified = source_db_.patch(sb, dbc); bool modified = source_db_.patch(sb, dbc);
if (modified) { if (modified) {
std::string errs = source_db_.rebuild(); std::string errs = source_db_.rebuild();
@@ -288,6 +291,7 @@ void World::patch_source(StreamBuffer *sb, DebugCollector *dbc) {
// TODO: I don't currently have any good place to send the // TODO: I don't currently have any good place to send the
// error messages. This is a stopgap. // error messages. This is a stopgap.
std::cerr << errs; std::cerr << errs;
std::cerr << "After PS ids=" << tangible_ids_debug_string() << std::endl;
} }
} }