Finished code for globals, but something's not working with client/server

This commit is contained in:
2023-04-10 16:00:47 -04:00
parent ef7d0ec365
commit ac383c616f
9 changed files with 230 additions and 55 deletions

View File

@@ -287,6 +287,18 @@ public:
std::ostream *lthread_print_stream() const;
// Set a global variable.
//
// This will throw lua errors if there's a problem.
//
void set_global(LuaCoreStack &LS0, const eng::string &gvar, LuaSlot value);
// Get the serialized value of a global variable.
//
// This accessor is used during difference transmission.
//
const eng::string &get_gvname_serial(const eng::string &gvar);
// Allocate a single ID.
//
// The rules are as follows:
@@ -397,7 +409,14 @@ public:
//
eng::string tangible_get_class(int64_t id) const;
// Store json in a global variable.
//
void set_global_json(const eng::string &gvar, const eng::string &json);
// Get a global variable as json.
//
eng::string get_global_json(const eng::string &gvar);
public:
///////////////////////////////////////////////////////////
//
@@ -442,6 +461,9 @@ public:
void patch_source(StreamBuffer *sb, DebugCollector *dbc);
void diff_source(World *master, StreamBuffer *sb);
void patch_globals(StreamBuffer *sb, DebugCollector *dbc);
void diff_globals(World *master, StreamBuffer *sb);
// This is the main entry point for difference transmission.
//
int64_t patch_everything(StreamBuffer *sb, DebugCollector *dbc);
@@ -518,13 +540,20 @@ private:
SourceDB source_db_;
PlaneMap plane_map_;
// Lua Globals
// Lua Global Variables
//
int64_t next_gvar_assign_;
eng::map<eng::string, int64_t> gvar_to_assign_;
eng::map<eng::string, eng::string> gvar_to_serial_;
eng::map<int64_t, eng::string> assign_to_gvar_;
// assign_seqno: sequence number generator for global variable assignments (master and client)
// gvname_to_serial: global variable name to serialized data. (master and client)
// gvname_to_seqno: global variable name to sequence number. (master only)
// seqno_to_gvname: sequence number to global variable name. (master only)
// gvname_modified: set of global variables recently locally modified. (client only)
//
int64_t assign_seqno_;
eng::map<eng::string, eng::string> gvname_to_serial_;
eng::map<eng::string, int64_t> gvname_to_seqno_;
eng::map<int64_t, eng::string> seqno_to_gvname_;
eng::set<eng::string> gvname_modified_;
// Tangibles table.
//
eng::unordered_map<int64_t, UniqueTangible> tangibles_;