More work on diff xmit, not finished yet

This commit is contained in:
2021-07-25 19:22:39 -04:00
parent 49a4ec220d
commit 9f342854e1
13 changed files with 304 additions and 100 deletions

View File

@@ -7,6 +7,7 @@
#include "idalloc.hpp"
#include "animqueue.hpp"
#include "invocation.hpp"
#include "streambuffer.hpp"
#include "sched.hpp"
#include "source.hpp"
#include "gui.hpp"
@@ -76,49 +77,10 @@ public:
class World {
public:
// Type of model
util::WorldType world_type_;
// A lua intepreter with snapshot function.
//
LuaSnap lua_snap_;
// The Global ID Pool.
//
IdGlobalPool id_global_pool_;
// Source Database.
//
SourceDB source_db_;
PlaneMap plane_map_;
// Tangibles table.
//
std::unordered_map<int64_t, std::unique_ptr<Tangible>> tangibles_;
// Thread schedule: must include every thread, except
// for the one currently-executing thread.
//
Schedule thread_sched_;
// Serialized snapshot of world model.
StreamBuffer snapshot_;
// Redirects.
//
using IdVector = util::IdVector;
using TangibleVector = std::vector<Tangible*>;
using Redirects = std::map<int64_t, int64_t>;
Redirects redirects_;
void run_scheduled_threads(int64_t clk);
static void store_global_pointer(lua_State *L, World *w);
// Check if main thread has nothing on the stack
bool stack_is_clear() const { return lua_gettop(state()) == 0; }
// Invoke an action plan.
//
void invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &idata);
public:
// Constructor.
//
// The constructor also calls 'lua_open' to create a new
@@ -145,7 +107,7 @@ public:
// Get a list of the tangibles that are near the player. If 'exclude_nowhere' is
// true, exclude any tangibles on the nowhere plane.
//
std::vector<int64_t> get_near(int64_t player_id, float radius, bool exclude_nowhere);
IdVector get_near(int64_t player_id, float radius, bool exclude_nowhere);
// Make a tangible.
//
@@ -159,6 +121,10 @@ public:
//
Tangible *tangible_get(int64_t id);
// Get pointers to many tangibles.
//
TangibleVector tangible_get_all(const IdVector &ids);
// Get a pointer to the specified tangible.
//
// The value on the lua stack should be a valid lua tangible. If not,
@@ -209,6 +175,92 @@ public:
//
void snapshot();
void rollback();
// Difference transmission.
//
// This generates diffs and stores them in the specified buffer,
// so that they can be sent to the client. It also applies the diffs
// to this model.
//
void difference_transmit(int64_t actor, World *master, StreamBuffer *sb);
// Apply differences.
//
// Note that difference_transmit applies the differences to the server
// synchronous model, so this is only used by the client synchronous model.
//
void apply_differences(int64_t actor, StreamBuffer *sb);
private:
// Run any threads which according to the scheduler queue are ready.
//
void run_scheduled_threads(int64_t clk);
// Store a pointer to a world model into a lua registry.
//
static void store_global_pointer(lua_State *L, World *w);
// Check that the main thread has nothing on the stack
//
bool stack_is_clear() const { return lua_gettop(state()) == 0; }
// Invoke a plan.
//
void invoke_plan(int64_t actor_id, int64_t place_id, const std::string &action, const InvocationData &idata);
// pass 1 of difference transmission: actor essentials.
//
// Before we do anything else, we need to get the actor in the right place.
// We also update the actor's ID allocation pipeline.
//
void diff_actor_essentials(int64_t actor_id, World *master, StreamBuffer *sb);
void patch_actor_essentials(StreamBuffer *sb);
// Pass 2 of difference transmission: visible animations.
//
// Synchronizes the animation status of every tangible inside the visibility
// radius of either model. Creates missing tangibles and deletes excess tangibles.
//
void diff_visible_animations(int64_t actor_id, World *master, StreamBuffer *sb);
void patch_visible_animations(StreamBuffer *sb);
private:
// Type of model
util::WorldType world_type_;
// A lua intepreter with snapshot function.
//
LuaSnap lua_snap_;
// The Global ID Pool.
//
IdGlobalPool id_global_pool_;
// Source Database.
//
SourceDB source_db_;
PlaneMap plane_map_;
// Tangibles table.
//
std::unordered_map<int64_t, std::unique_ptr<Tangible>> tangibles_;
// Thread schedule: must include every thread, except
// for the one currently-executing thread.
//
Schedule thread_sched_;
// Serialized snapshot of world model.
StreamBuffer snapshot_;
// Redirects.
//
Redirects redirects_;
friend class Tangible;
friend int tangible_animate(lua_State *L);
friend int tangible_build(lua_State *L);
friend int tangible_redirect(lua_State *L);
};
#endif // WORLD_HPP