Refactor: remove references to class World from util and luastack. These are low-level modules that should not reference class World.

This commit is contained in:
2026-02-21 21:42:53 -05:00
parent 7e7f9bf147
commit e9d185acb0
5 changed files with 21 additions and 43 deletions

View File

@@ -94,8 +94,8 @@ lua_State *LuaCoreStack::newstate (lua_Alloc allocf) {
lua_pushstring(L, "tangibles"); lua_pushstring(L, "tangibles");
lua_newtable(L); lua_newtable(L);
lua_rawset(L, LUA_REGISTRYINDEX); lua_rawset(L, LUA_REGISTRYINDEX);
lua_pushstring(L, "worldtype"); lua_pushstring(L, "is_authoritative");
lua_pushnumber(L, WORLD_TYPE_MASTER); lua_pushboolean(L, 1);
lua_rawset(L, LUA_REGISTRYINDEX); lua_rawset(L, LUA_REGISTRYINDEX);
return L; return L;
@@ -687,24 +687,19 @@ void LuaCoreStack::setvisited(LuaSlot tab, bool visited) const {
lua_modflagbits(L_, tab.index(), 0x0010, visited ? 0x0010 : 0); lua_modflagbits(L_, tab.index(), 0x0010, visited ? 0x0010 : 0);
} }
WorldType LuaCoreStack::get_world_type() const { void LuaCoreStack::set_authoritative(bool auth) const {
lua_pushstring(L_, "worldtype"); lua_pushstring(L_, "is_authoritative");
lua_rawget(L_, LUA_REGISTRYINDEX); lua_pushboolean(L_, auth ? 1 : 0);
lua_Integer n = lua_tointeger(L_, -1);
lua_pop(L_, 1);
assert(n != 0);
return (WorldType)n;
}
void LuaCoreStack::set_world_type(WorldType t) const {
lua_pushstring(L_, "worldtype");
lua_pushnumber(L_, (int)t);
lua_rawset(L_, LUA_REGISTRYINDEX); lua_rawset(L_, LUA_REGISTRYINDEX);
} }
void LuaCoreStack::guard_nopredict(const char *fn) { void LuaCoreStack::guard_nopredict(const char *fn) {
if (lua_isyieldable(L_)) { if (lua_isyieldable(L_)) {
if (!is_authoritative()) { lua_pushstring(L_, "is_authoritative");
lua_rawget(L_, LUA_REGISTRYINDEX);
bool auth = lua_toboolean(L_, -1);
lua_pop(L_, 1);
if (!auth) {
lua_yield(L_, 0); lua_yield(L_, 0);
luaL_error(L_, "unexplained nopredict failure in %s", fn); luaL_error(L_, "unexplained nopredict failure in %s", fn);
} }

View File

@@ -989,24 +989,10 @@ public:
// //
void setvisited(LuaSlot tab, bool visited) const; void setvisited(LuaSlot tab, bool visited) const;
// Store the world type in the registry. // Store whether the world is authoritative in the
// registry. This is used to implement guard_nopredict.
// //
// This just stores the enum value in the registry key "worldtype". void set_authoritative(bool auth) const;
//
void set_world_type(WorldType t) const;
// Return the world type from the registry.
//
// This just fetches the enum value from the registry key "worldtype".
//
WorldType get_world_type() const;
// Return true if this world is authoritative.
//
// This fetches the enum value from the registry key "worldtype",
// then it checks if the world type is authoritative.
//
bool is_authoritative() { return util::is_authoritative(get_world_type()); }
// Yield this thread with zero if in a nonauth model, and not a probe. // Yield this thread with zero if in a nonauth model, and not a probe.
// //

View File

@@ -33,11 +33,6 @@
#include "spookyv2.hpp" #include "spookyv2.hpp"
enum WorldType {
WORLD_TYPE_MASTER = 1,
WORLD_TYPE_PREDICTIVE = 2,
};
namespace sv { namespace sv {
@@ -355,9 +350,6 @@ double distance_squared(double x1, double y1, double x2, double y2);
// Make a LuaSourceVec with one element, for unit testing. // Make a LuaSourceVec with one element, for unit testing.
LuaSourcePtr make_lua_source(const eng::string &code); LuaSourcePtr make_lua_source(const eng::string &code);
// Return true if the worldtype is authoritative.
inline bool is_authoritative(WorldType t) { return (t == WORLD_TYPE_MASTER); }
// Remove items from a vector that are nullptr. // Remove items from a vector that are nullptr.
template<class T> template<class T>
void remove_nullptrs(T &vec) { void remove_nullptrs(T &vec) {

View File

@@ -131,8 +131,8 @@ World::World(WorldType wt) {
LS.getglobaltable(globtab); LS.getglobaltable(globtab);
LS.settabletype(globtab, LUA_TT_GLOBALENV); LS.settabletype(globtab, LUA_TT_GLOBALENV);
// Store the world type in the registry. // Store whether the world is authoritative in the registry.
LS.set_world_type(wt); LS.set_authoritative(wt == WORLD_TYPE_MASTER);
// Create the globaldb in the registry. // Create the globaldb in the registry.
LS.rawset(LuaRegistry, "globaldb", LuaNewTable); LS.rawset(LuaRegistry, "globaldb", LuaNewTable);

View File

@@ -22,6 +22,11 @@
#include "source.hpp" #include "source.hpp"
#include "luasnap.hpp" #include "luasnap.hpp"
enum WorldType {
WORLD_TYPE_MASTER = 1,
WORLD_TYPE_PREDICTIVE = 2,
};
class World; class World;
class Tangible : public eng::opnew { class Tangible : public eng::opnew {
@@ -313,7 +318,7 @@ public:
// Check if the world is authoritative. // Check if the world is authoritative.
// //
bool is_authoritative() const { return util::is_authoritative(world_type_); } bool is_authoritative() const { return world_type_ == WORLD_TYPE_MASTER; }
// Get a table showing all outstanding HTTP requests. // Get a table showing all outstanding HTTP requests.
// //