Threads and tasks
This commit is contained in:
101
src/gamedata/CharacterAIModule.h
Normal file
101
src/gamedata/CharacterAIModule.h
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifndef CHARACTERAIMODULE_H
|
||||
#define CHARACTERAIMODULE_H
|
||||
#include <vector>
|
||||
#include <flecs.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "goap.h"
|
||||
|
||||
namespace ECS
|
||||
{
|
||||
|
||||
struct Blackboard {
|
||||
nlohmann::json stats;
|
||||
int object;
|
||||
int index;
|
||||
flecs::entity town;
|
||||
std::shared_ptr<std::mutex> mutex;
|
||||
|
||||
private:
|
||||
std::vector<goap::BaseAction<Blackboard> *> actionRef;
|
||||
int actionRefCount;
|
||||
int actionRefPtr;
|
||||
Ogre::Vector3 position;
|
||||
std::vector<size_t> points;
|
||||
std::vector<float> distances;
|
||||
void _actionRefResize(int count);
|
||||
void _actionRefAddActions(
|
||||
const std::vector<goap::BaseAction<Blackboard> *> &actions);
|
||||
|
||||
public:
|
||||
Blackboard();
|
||||
Blackboard(const nlohmann::json &stats);
|
||||
bool operator==(const Blackboard &other) const;
|
||||
bool operator!=(const Blackboard &other) const;
|
||||
void apply(const Blackboard &other);
|
||||
Ogre::String dumpActions();
|
||||
void printActions();
|
||||
void fixupBooleanKeys();
|
||||
void actionRefResize(int count);
|
||||
void actionRefAddAction(goap::BaseAction<Blackboard> *action);
|
||||
void actionRefAddActions(
|
||||
const std::vector<goap::BaseAction<Blackboard> *> &actions);
|
||||
void actionRefAddActions(goap::BaseAction<Blackboard> **actions,
|
||||
int count);
|
||||
goap::BaseAction<Blackboard> **getActionsData()
|
||||
{
|
||||
return actionRef.data();
|
||||
}
|
||||
int getActionsCount()
|
||||
{
|
||||
return actionRefCount;
|
||||
}
|
||||
|
||||
private:
|
||||
static bool is_satisfied_by(const nlohmann::json ¤t,
|
||||
const nlohmann::json &target,
|
||||
float epsilon = 1e-4);
|
||||
|
||||
public:
|
||||
int distance_to(const Blackboard &goal) const;
|
||||
void setPosition(const Ogre::Vector3 &position);
|
||||
const Ogre::Vector3 &getPosition() const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
void query_ai();
|
||||
};
|
||||
|
||||
struct TownNPCs;
|
||||
struct ActionNodeList;
|
||||
|
||||
struct TownAI {
|
||||
std::shared_ptr<std::mutex> mutex;
|
||||
std::vector<goap::BasePlanner<Blackboard,
|
||||
goap::BaseAction<Blackboard> >::BaseGoal>
|
||||
goals;
|
||||
std::vector<goap::BaseAction<Blackboard> *> actions;
|
||||
std::shared_ptr<
|
||||
goap::BasePlanner<Blackboard, goap::BaseAction<Blackboard> > >
|
||||
planner;
|
||||
std::unordered_map<int, Blackboard> blackboards;
|
||||
struct Plan {
|
||||
const goap::BasePlanner<Blackboard,
|
||||
goap::BaseAction<Blackboard> >::BaseGoal *goal;
|
||||
std::vector<goap::BaseAction<Blackboard> *> plan;
|
||||
};
|
||||
std::unordered_map<int, std::vector<struct Plan> > plans;
|
||||
std::unordered_map<int, std::vector<goap::BaseAction<Blackboard> *> > nodeActions;
|
||||
};
|
||||
|
||||
struct CharacterAIModule {
|
||||
CharacterAIModule(flecs::world &ecs);
|
||||
void createAI(flecs::entity town);
|
||||
void buildPlans(flecs::entity town, const TownNPCs &npcs, TownAI &ai);
|
||||
void createBlackboards(flecs::entity town, const TownNPCs &npcs, TownAI &ai);
|
||||
void updateBlackboardsBits(flecs::entity town, ActionNodeList &alist, const TownNPCs &npcs, TownAI &ai);
|
||||
void updateBlackboards(flecs::entity town, const ActionNodeList &alist, const TownNPCs &npcs, TownAI &ai);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CHARACTERAIMODULE_H
|
||||
Reference in New Issue
Block a user