World model is now operational

This commit is contained in:
2021-01-16 01:24:33 -05:00
parent d7d633bd96
commit 313e78067a
11 changed files with 313 additions and 188 deletions

View File

@@ -1,30 +1,78 @@
// Note about header file dependencies:
//
// world.hpp contains a lot of forward declarations.
// That's because it is at the bottom of the dependency stack:
// everyone includes world.hpp.
//
// However, world.cpp is at the top of the dependency stack,
// it includes everyone else.
//
#ifndef WORLD_HPP
#define WORLD_HPP
#include "luastack.hpp"
#include "planemap.hpp"
#include "idalloc.hpp"
#include "animqueue.hpp"
#include "source.hpp"
#include <memory>
#include <unordered_map>
class IdGlobalPool;
class World;
class Tangible {
public:
// Always points back to the world model.
World *world_;
// Animation queue and plane item.
//
// To update the position of this tangible, first add an animation in which
// the tangible moves, then call plane_item.set_pos_from(anim_queue_).
PlaneItem plane_item_;
AnimQueue anim_queue_;
// Player ID pool
//
// Note: this is only allocated if this Tangible is a player.
std::unique_ptr<IdPlayerPool> id_player_pool_;
};
class World {
public:
int id_;
std::unique_ptr<IdGlobalPool> id_pool_;
World() : id_(0) {};
// A pointer to the lua State.
//
lua_State *lua_state_;
// The Global ID Pool.
//
IdGlobalPool id_global_pool_;
// Source Database.
//
SourceDB source_db_;
PlaneMap plane_map_;
std::unordered_map<int64_t, Tangible> tangibles_;
public:
// Constructor.
//
// The constructor also calls 'lua_open' to create a new
// lua interpreter for this world model. The lua interpreter
// is stored in world::lua_state_. A significant amount of
// initial setup is done by this constructor.
//
World();
// Destructor.
//
// Not currently functional.
//
~World();
static void init(lua_State *L);
// get_lua_state
//
// Get the lua interpreter associated with this world model.
//
lua_State *get_lua_state() { return lua_state_; }
// fetch
//
// Given a lua state, fetch the world model associated with
// that lua state.
//
static World *fetch(lua_State *L);
};