World serialization done (not well-tested yet)
This commit is contained in:
@@ -18,6 +18,25 @@
|
||||
class World;
|
||||
|
||||
class Tangible {
|
||||
private:
|
||||
friend class World;
|
||||
|
||||
// Serialize and deserialize
|
||||
//
|
||||
// The tangible's ID is not serialized. When you serialize a tangible, you
|
||||
// should probably serialize the ID separately.
|
||||
//
|
||||
// The Lua portion of the tangible is not serialized here. Instead, the lua
|
||||
// portion is serialized when you serialize the lua state as a whole.
|
||||
//
|
||||
// PlaneItem is not serialized. The deserialize routine rebuilds the
|
||||
// PlaneItem from the AnimQueue.
|
||||
//
|
||||
// World pointer is not serialized.
|
||||
//
|
||||
void serialize(StreamBuffer *sb);
|
||||
void deserialize(StreamBuffer *sb);
|
||||
|
||||
public:
|
||||
// Always points back to the world model.
|
||||
World *world_;
|
||||
@@ -50,15 +69,6 @@ public:
|
||||
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 {
|
||||
@@ -75,6 +85,9 @@ public:
|
||||
//
|
||||
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
|
||||
@@ -82,6 +95,9 @@ public:
|
||||
//
|
||||
Schedule thread_sched_;
|
||||
|
||||
// Serialized snapshot of world model.
|
||||
StreamBuffer snapshot_;
|
||||
|
||||
void run_scheduled_threads(int64_t clk);
|
||||
public:
|
||||
// Constructor.
|
||||
@@ -158,10 +174,15 @@ public:
|
||||
static void store_global_pointer(lua_State *L, World *w);
|
||||
static World *fetch_global_pointer(lua_State *L);
|
||||
|
||||
// Serialize and deserialize.
|
||||
//
|
||||
void serialize(StreamBuffer *sb);
|
||||
void deserialize(StreamBuffer *sb);
|
||||
|
||||
// Snapshot and rollback - temporary.
|
||||
//
|
||||
void snapshot() { lua_snap_.snapshot(); }
|
||||
void rollback() { lua_snap_.rollback(); }
|
||||
void snapshot();
|
||||
void rollback();
|
||||
};
|
||||
|
||||
#endif // WORLD_HPP
|
||||
|
||||
Reference in New Issue
Block a user