Numbering and pairing of lua tables

This commit is contained in:
2021-08-13 17:02:35 -04:00
parent ee16970a8a
commit 7581ac7278
7 changed files with 504 additions and 7 deletions

View File

@@ -80,6 +80,10 @@ public:
using IdVector = util::IdVector;
using TanVector = std::vector<const Tangible*>;
using Redirects = std::map<int64_t, int64_t>;
struct TablePairing {
std::vector<int> mpair;
std::vector<int> spair;
};
const float RadiusVisibility = 100.0;
const float RadiusClose = 10.0;
@@ -197,7 +201,7 @@ public:
// so that they can be sent to the client. It also applies the diffs
// to this model.
//
void difference_transmit(int64_t actor, const World *master, StreamBuffer *sb);
void difference_transmit(int64_t actor, World *master, StreamBuffer *sb);
// Apply differences.
//
@@ -227,7 +231,25 @@ public:
// Get a list of all existing tangibles as a comma-separated string.
//
std::string tangible_ids_debug_string() const;
// Shows the TID (table ID) of the tables that were numbered.
// TIDs are in alphabetical order. Any table without a TID
// shows up as "unknown"
//
std::string numbered_tables_debug_string() const;
// Paired tables debug string. Shows TID=TID pairs, sorted alphabetically.
//
std::string paired_tables_debug_string(lua_State *master, const TablePairing *pairing) const;
// Store a string in the tangible's database.
//
void tangible_set_string(int64_t id, const std::string &path, const std::string &value);
// Copy a lua global variable into the tangible's database.
//
void tangible_copy_global(int64_t id, const std::string &path, const std::string &global);
private:
// Run any threads which according to the scheduler queue are ready.
//
@@ -261,6 +283,34 @@ private:
static void diff_visible_animations(const TanVector &mvis, const TanVector &svis, StreamBuffer *sb);
void patch_visible_animations(StreamBuffer *sb);
public:
// Pass 3 of difference transmission: numbering of tables.
//
// Table-to-number mapping is stored in registry.tnmap
// Number-to-table mapping is stored in registry.ntmap
// Returns the total number of tables numbered.
//
int number_lua_tables(const IdVector &basis);
// Deletes registry.tnmap and registry.ntmap
//
void unnumber_lua_tables();
// Associates numbered tables in the master model with numbered tables in the synch model.
//
void pair_lua_tables(const IdVector &basis, lua_State *master, TablePairing *pair);
// Pairs any not-yet-paired master table to a virtually-created table in the synch model.
//
// Returns the number of new tables that need to be created in the synch model.
//
int pair_new_tables(TablePairing *pair);
// This is followup for pair_new_tables: actually create the new tables that
// were virtually created in the pair_new_tables step.
//
void create_new_tables(int n);
private:
// Type of model
util::WorldType world_type_;