A little cleanup, and some work on LpxClient
This commit is contained in:
@@ -178,6 +178,7 @@ private:
|
||||
bool readline_enabled_;
|
||||
friend class DrivenEngine;
|
||||
};
|
||||
|
||||
using UniqueChannel = std::unique_ptr<Channel>;
|
||||
|
||||
class DrivenEngine {
|
||||
@@ -206,7 +207,14 @@ public:
|
||||
//
|
||||
double get_clock();
|
||||
|
||||
// Create a channel and open an outgoing connection.
|
||||
// Create a channel and open an outgoing connection. The channel creation
|
||||
// always succeeds. You can write to the channel immediately. You can
|
||||
// read, too, but of course there won't be anything in the incoming buffer
|
||||
// yet. In future update events, data will show up in the incoming buffer,
|
||||
// and will have been sent from the outgoing buffer. In future update
|
||||
// events, the channel may get closed by the remote. If the connection
|
||||
// fails (say, the remote host doesn't exist), then the Channel will get
|
||||
// closed with an error.
|
||||
//
|
||||
// DRIVER: The channel object is created instantly, but it does nothing
|
||||
// until the driver notices the new channel. The driver is responsible for
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
class LpxClient : public DrivenEngine {
|
||||
public:
|
||||
using StringVec = LuaConsole::StringVec;
|
||||
std::unique_ptr<World> world_;
|
||||
UniqueWorld world_;
|
||||
int64_t actor_id_;
|
||||
InvocationQueue unack_;
|
||||
Channel *channel_;
|
||||
UniqueChannel channel_;
|
||||
LuaConsole console_;
|
||||
Gui gui_;
|
||||
int64_t gui_place_;
|
||||
@@ -26,6 +26,18 @@ public:
|
||||
|
||||
public:
|
||||
virtual void event_init(int argc, char *argv[]) {
|
||||
// Create the world model.
|
||||
world_.reset(new World(util::WORLD_TYPE_C_SYNC));
|
||||
|
||||
// This is a temporary actor that will be used only until the server sends
|
||||
// us the first difference transmission. We do this only to establish
|
||||
// the invariant that there's always an actor. When the first difference
|
||||
// transmission arrives, this actor may be deleted, or it may just be
|
||||
// ignored, at the server's discretion.
|
||||
actor_id_ = world_->create_login_actor();
|
||||
|
||||
// Establish a connection to the server.
|
||||
channel_ = new_outgoing_channel("localhost:8085");
|
||||
}
|
||||
|
||||
virtual void event_update() {
|
||||
|
||||
@@ -8,12 +8,12 @@ class ServerClient {
|
||||
public:
|
||||
int64_t actor_id_;
|
||||
Channel *channel_;
|
||||
std::unique_ptr<World> sync_;
|
||||
UniqueWorld sync_;
|
||||
};
|
||||
|
||||
class LpxServer : public DrivenEngine {
|
||||
public:
|
||||
std::unique_ptr<World> master_;
|
||||
UniqueWorld master_;
|
||||
std::vector<std::unique_ptr<ServerClient>> clients_;
|
||||
|
||||
public:
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
class TextGame : public DrivenEngine {
|
||||
private:
|
||||
using StringVec = LuaConsole::StringVec;
|
||||
std::unique_ptr<World> world_;
|
||||
UniqueWorld world_;
|
||||
LuaConsole console_;
|
||||
Gui gui_;
|
||||
int64_t gui_place_;
|
||||
|
||||
@@ -161,7 +161,7 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, const std::string &plan
|
||||
LuaStack LS(L, tangibles, database, metatab);
|
||||
|
||||
// Create the C++ part of the structure.
|
||||
std::unique_ptr<Tangible> &t = tangibles_[id];
|
||||
UniqueTangible &t = tangibles_[id];
|
||||
assert (t == nullptr);
|
||||
t.reset(new Tangible(this, id));
|
||||
|
||||
@@ -564,7 +564,7 @@ void World::deserialize(StreamBuffer *sb) {
|
||||
size_t ntan = sb->read_uint32();
|
||||
for (size_t i = 0; i < ntan; i++) {
|
||||
int64_t id = sb->read_int64();
|
||||
std::unique_ptr<Tangible> &t = tangibles_[id];
|
||||
UniqueTangible &t = tangibles_[id];
|
||||
if (t == nullptr) {
|
||||
t.reset(new Tangible(this, id));
|
||||
} else {
|
||||
|
||||
@@ -216,7 +216,7 @@ std::string World::tangible_get_class(int64_t id) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool worlds_identical(const std::unique_ptr<World> &w1, const std::unique_ptr<World> &w2) {
|
||||
static bool worlds_identical(const UniqueWorld &w1, const UniqueWorld &w2) {
|
||||
StreamBuffer sbw1, sbw2;
|
||||
w1->serialize(&sbw1);
|
||||
w2->serialize(&sbw2);
|
||||
@@ -225,9 +225,9 @@ static bool worlds_identical(const std::unique_ptr<World> &w1, const std::unique
|
||||
|
||||
|
||||
LuaDefine(unittests_world1animdiff, "c") {
|
||||
std::unique_ptr<World> m(new World(util::WORLD_TYPE_MASTER));
|
||||
std::unique_ptr<World> ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
std::unique_ptr<World> cs(new World(util::WORLD_TYPE_C_SYNC));
|
||||
UniqueWorld m(new World(util::WORLD_TYPE_MASTER));
|
||||
UniqueWorld ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
UniqueWorld cs(new World(util::WORLD_TYPE_C_SYNC));
|
||||
StreamBuffer sb;
|
||||
util::IdVector ids = util::id_vector_create(123, 345);
|
||||
|
||||
@@ -295,8 +295,8 @@ LuaDefine(unittests_world1animdiff, "c") {
|
||||
}
|
||||
|
||||
LuaDefine(unittests_world2pairtab, "c") {
|
||||
std::unique_ptr<World> m(new World(util::WORLD_TYPE_MASTER));
|
||||
std::unique_ptr<World> ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
UniqueWorld m(new World(util::WORLD_TYPE_MASTER));
|
||||
UniqueWorld ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
StreamBuffer sb;
|
||||
int ncreate;
|
||||
|
||||
@@ -343,9 +343,9 @@ LuaDefine(unittests_world2pairtab, "c") {
|
||||
}
|
||||
|
||||
LuaDefine(unittests_world3diffluatab, "c") {
|
||||
std::unique_ptr<World> m(new World(util::WORLD_TYPE_MASTER));
|
||||
std::unique_ptr<World> ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
std::unique_ptr<World> cs(new World(util::WORLD_TYPE_C_SYNC));
|
||||
UniqueWorld m(new World(util::WORLD_TYPE_MASTER));
|
||||
UniqueWorld ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
UniqueWorld cs(new World(util::WORLD_TYPE_C_SYNC));
|
||||
StreamBuffer sb;
|
||||
|
||||
// Initialize all three models so that a tangible exists.
|
||||
@@ -397,9 +397,9 @@ LuaDefine(unittests_world3diffluatab, "c") {
|
||||
}
|
||||
|
||||
LuaDefine(unittests_world4difftanclass, "c") {
|
||||
std::unique_ptr<World> m(new World(util::WORLD_TYPE_MASTER));
|
||||
std::unique_ptr<World> ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
std::unique_ptr<World> cs(new World(util::WORLD_TYPE_C_SYNC));
|
||||
UniqueWorld m(new World(util::WORLD_TYPE_MASTER));
|
||||
UniqueWorld ss(new World(util::WORLD_TYPE_S_SYNC));
|
||||
UniqueWorld cs(new World(util::WORLD_TYPE_C_SYNC));
|
||||
StreamBuffer sb;
|
||||
|
||||
// Initialize all three models so that a tangible exists.
|
||||
|
||||
@@ -75,6 +75,8 @@ public:
|
||||
void configure_id_pool_for_actor() { id_player_pool_.set_fifo_capacity(20); }
|
||||
};
|
||||
|
||||
using UniqueTangible = std::unique_ptr<Tangible>;
|
||||
|
||||
class World {
|
||||
public:
|
||||
using IdVector = util::IdVector;
|
||||
@@ -415,7 +417,7 @@ private:
|
||||
|
||||
// Tangibles table.
|
||||
//
|
||||
std::unordered_map<int64_t, std::unique_ptr<Tangible>> tangibles_;
|
||||
std::unordered_map<int64_t, UniqueTangible> tangibles_;
|
||||
|
||||
// Thread schedule: must include every thread, except
|
||||
// for the one currently-executing thread.
|
||||
@@ -443,4 +445,7 @@ private:
|
||||
friend int lfn_tangible_place(lua_State *L);
|
||||
};
|
||||
|
||||
using UniqueWorld = std::unique_ptr<World>;
|
||||
|
||||
|
||||
#endif // WORLD_HPP
|
||||
|
||||
Reference in New Issue
Block a user