80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
#ifndef PLAYERACTIONMODULE_H
|
|
#define PLAYERACTIONMODULE_H
|
|
#include <flecs.h>
|
|
#include <nlohmann/json.hpp>
|
|
#include <lua.h>
|
|
#include <Ogre.h>
|
|
|
|
namespace ECS {
|
|
|
|
struct ActionNodeList {
|
|
struct indexObject;
|
|
struct ActionNode {
|
|
Ogre::String action;
|
|
Ogre::String action_text;
|
|
Ogre::Vector3 position;
|
|
Ogre::Quaternion rotation;
|
|
float height;
|
|
float radius;
|
|
nlohmann::json props;
|
|
};
|
|
struct UIData {
|
|
std::shared_ptr<std::mutex> mutex;
|
|
int selected;
|
|
std::vector<size_t> points;
|
|
std::vector<float> distances;
|
|
UIData()
|
|
: mutex(std::make_shared<std::mutex>())
|
|
, selected(-1)
|
|
{
|
|
}
|
|
};
|
|
|
|
private:
|
|
bool dirty;
|
|
bool busy;
|
|
std::shared_ptr<indexObject> indexObj;
|
|
struct UIData uidata;
|
|
bool _query(const Ogre::Vector3 &position, std::vector<size_t> &points,
|
|
std::vector<float> &distances);
|
|
|
|
public:
|
|
std::shared_ptr<std::mutex> nodeMutex;
|
|
std::vector<ActionNode> nodes, dynamicNodes;
|
|
void updateDynamicNodes();
|
|
void build();
|
|
bool query_ai(const Ogre::Vector3 &position, float distance,
|
|
std::vector<size_t> &points,
|
|
std::vector<float> &distances);
|
|
int addNode(struct ActionNodeList::ActionNode &node);
|
|
void removeNode(int index);
|
|
const UIData &getUIData();
|
|
void setUISelected(int selected);
|
|
void setUIPoints(const std::vector<size_t> &points,
|
|
const std::vector<float> &distances);
|
|
void UIquery(const Ogre::Vector3 &position);
|
|
void setDirty(); // node was added or removed
|
|
void setReady();
|
|
void setBusy();
|
|
bool isBusy();
|
|
};
|
|
struct PlayerActionModule {
|
|
struct ActionWordHandler {
|
|
virtual void operator()(flecs::entity town, int index,
|
|
const Ogre::String &word) = 0;
|
|
};
|
|
|
|
std::multimap<Ogre::String, ActionWordHandler *>
|
|
actionWords;
|
|
|
|
PlayerActionModule(flecs::world &ecs);
|
|
void addWordHandler(const Ogre::String &word, ActionWordHandler *handler);
|
|
void removeWordHandler(const Ogre::String &word, ActionWordHandler *handler);
|
|
void addLuaWordHandler(const Ogre::String &word, lua_State *L, int ref);
|
|
void removeLuaWordHandler(const Ogre::String &word, lua_State *L, int ref);
|
|
int setupLuaActionHandler(lua_State *L);
|
|
};
|
|
}
|
|
|
|
#endif // PLAYERACTIONMODULE_H
|