Tangible serialization and design improvements

This commit is contained in:
2021-03-14 18:17:34 -04:00
parent 4426fa157a
commit 7c9fd1e46b
7 changed files with 108 additions and 44 deletions

View File

@@ -19,10 +19,6 @@ class World;
class Tangible {
public:
// Simple constructor initializes everything to null.
//
Tangible();
// Always points back to the world model.
World *world_;
@@ -33,17 +29,36 @@ public:
// Plane Item.
//
// The PlaneItem also contains this tangible's ID.
// To move this Tangible, update the anim_queue first, then update
// this plane_item_ from the anim_queue.
// To move this PlaneItem, update the anim_queue first, then call
// update_plane_item, which copies the data from the anim_queue.
//
PlaneItem plane_item_;
// Player ID pool
//
// Note: this is only allocated if this Tangible is a player.
std::unique_ptr<IdPlayerPool> id_player_pool_;
// This is present in every tangible, whether a player or not.
// However, the fifo is only enabled in logged-in players.
//
IdPlayerPool id_player_pool_;
// constructor.
//
Tangible(World *w, int64_t id);
// Get the ID
//
int64_t id() { return plane_item_.id(); }
void be_a_player();
void update_plane_item();
// Serialize and deserialize
//
// PlaneItem is not serialized except the ID. The deserialize routine
// rebuilds the PlaneItem from the AnimQueue. World pointer is not
// serialized.
//
void serialize(StreamBuffer *sb);
void deserialize(StreamBuffer *sb);
};
class World {
@@ -60,7 +75,7 @@ public:
//
SourceDB source_db_;
PlaneMap plane_map_;
std::unordered_map<int64_t, Tangible> tangibles_;
std::unordered_map<int64_t, std::unique_ptr<Tangible>> tangibles_;
// Thread schedule: must include every thread, except
// for the one currently-executing thread.