2021-01-06 15:10:21 -05:00
|
|
|
|
|
|
|
|
#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"
|
2021-02-07 17:26:48 -05:00
|
|
|
#include "gui.hpp"
|
2021-02-09 17:15:54 -05:00
|
|
|
#include "luasnap.hpp"
|
2021-01-06 15:10:21 -05:00
|
|
|
#include <memory>
|
2021-01-16 01:24:33 -05:00
|
|
|
#include <unordered_map>
|
2021-01-06 15:10:21 -05:00
|
|
|
|
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
|
|
|
};
|
2021-01-06 15:10:21 -05:00
|
|
|
|
|
|
|
|
class World {
|
|
|
|
|
public:
|
2021-02-09 17:15:54 -05:00
|
|
|
// A lua intepreter with snapshot function.
|
2021-01-16 01:24:33 -05:00
|
|
|
//
|
2021-02-09 17:15:54 -05:00
|
|
|
LuaSnap lua_snap_;
|
|
|
|
|
|
2021-01-16 01:24:33 -05:00
|
|
|
// 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.
|
|
|
|
|
//
|
2021-01-06 15:10:21 -05:00
|
|
|
~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.
|
|
|
|
|
//
|
2021-02-09 17:15:54 -05:00
|
|
|
lua_State *state() { return lua_snap_.state(); }
|
2021-01-16 01:24:33 -05:00
|
|
|
|
2021-02-07 13:38:29 -05:00
|
|
|
// get_near
|
2021-01-22 17:35:23 -05:00
|
|
|
//
|
2021-02-07 13:38:29 -05:00
|
|
|
// Get a list of the tangibles that are near the player.
|
2021-01-17 16:23:10 -05:00
|
|
|
//
|
2021-02-07 13:38:29 -05:00
|
|
|
std::vector<int64_t> get_near(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-02-07 17:26:48 -05:00
|
|
|
// Probe the 'interface' function of the specified sprite.
|
|
|
|
|
//
|
|
|
|
|
void update_gui(int64_t actor_id, int64_t place_id, Gui *gui);
|
|
|
|
|
|
2021-01-16 01:24:33 -05:00
|
|
|
// fetch
|
|
|
|
|
//
|
|
|
|
|
// Given a lua state, fetch the world model associated with
|
|
|
|
|
// that lua state.
|
|
|
|
|
//
|
2021-01-06 15:10:21 -05:00
|
|
|
static World *fetch(lua_State *L);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // WORLD_HPP
|