Files
integration/luprex/syscpp/world.hpp

96 lines
2.1 KiB
C++

#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 World;
class Tangible {
public:
// Simple constructor initializes everything to null.
//
Tangible();
// 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:
// 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();
// get_lua_state
//
// Get the lua interpreter associated with this world model.
//
lua_State *get_lua_state() { return lua_state_; }
// Make a tangible with a generated ID.
//
// Pushes the database onto the lua stack and returns the tangible pointer.
//
Tangible *tangible_make(lua_State *L);
// Delete a tangible with the specified ID.
//
// If the tangible doesn't exist, does nothing.
//
void tangible_del(int64_t id);
// fetch
//
// Given a lua state, fetch the world model associated with
// that lua state.
//
static World *fetch(lua_State *L);
};
#endif // WORLD_HPP