Files
integration/luprex/cpp/world.hpp

119 lines
2.6 KiB
C++
Raw Normal View History

#ifndef WORLD_HPP
#define WORLD_HPP
#include "luastack.hpp"
2021-01-16 01:24:33 -05:00
#include "planemap.hpp"
#include "idalloc.hpp"
#include "animqueue.hpp"
#include "source.hpp"
#include <memory>
2021-01-16 01:24:33 -05:00
#include <unordered_map>
2021-01-16 01:24:33 -05:00
class World;
class Tangible {
public:
2021-01-17 16:23:10 -05:00
// Simple constructor initializes everything to null.
//
Tangible();
2021-01-16 01:24:33 -05:00
// Always points back to the world model.
World *world_;
2021-01-22 17:35:23 -05:00
// Animation queue.
2021-01-16 01:24:33 -05:00
//
AnimQueue anim_queue_;
2021-01-22 17:35:23 -05:00
// 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.
PlaneItem plane_item_;
2021-01-16 01:24:33 -05:00
// Player ID pool
//
// Note: this is only allocated if this Tangible is a player.
std::unique_ptr<IdPlayerPool> id_player_pool_;
2021-01-22 17:35:23 -05:00
void be_a_player();
2021-01-16 01:24:33 -05:00
};
class World {
public:
2021-01-16 01:24:33 -05:00
// 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();
2021-01-22 17:35:23 -05:00
// Initialize for single-player mode.
//
void init_standalone();
2021-01-16 01:24:33 -05:00
// get_lua_state
//
// Get the lua interpreter associated with this world model.
//
lua_State *get_lua_state() { return lua_state_; }
2021-01-22 19:10:47 -05:00
// update_view_map
2021-01-22 17:35:23 -05:00
//
2021-01-22 19:10:47 -05:00
// Update the view map with information about all the tangibles near
// the specified player.
2021-01-17 16:23:10 -05:00
//
2021-01-22 19:10:47 -05:00
void update_view_map(AnimViewMap *vm, int64_t player_id, float radius);
2021-01-22 17:35:23 -05:00
// Make a tangible.
2021-01-17 16:23:10 -05:00
//
2021-01-22 17:35:23 -05:00
// If the ID is zero, allocates an ID using the thread's ID allocator. If
// pushdb is true, pushes the tangible's database onto the lua stack.
// Otherwise, leaves the lua stack untouched.
//
Tangible *tangible_make(lua_State *L, int64_t id, bool pushdb);
2021-01-17 16:23:10 -05:00
2021-01-22 17:35:23 -05:00
// Get a pointer to the specified tangible.
//
Tangible *tangible_get(int64_t id);
2021-01-17 16:23:10 -05:00
// Delete a tangible with the specified ID.
//
// If the tangible doesn't exist, does nothing.
//
void tangible_del(int64_t id);
2021-01-16 01:24:33 -05:00
// fetch
//
// Given a lua state, fetch the world model associated with
// that lua state.
//
static World *fetch(lua_State *L);
};
#endif // WORLD_HPP