Fixed AIs and crashes
This commit is contained in:
@@ -271,6 +271,7 @@ public:
|
||||
};
|
||||
ActionNodeActions(int node, const Blackboard &prereq, int cost)
|
||||
{
|
||||
ZoneScoped;
|
||||
OgreAssert(
|
||||
node < ECS::get<ActionNodeList>().dynamicNodes.size(),
|
||||
"bad node " + Ogre::StringConverter::toString(node));
|
||||
@@ -347,6 +348,7 @@ public:
|
||||
have_bits = true;
|
||||
}
|
||||
if (!have_bits) {
|
||||
ZoneScopedN("Use");
|
||||
std::cout << "use: " << props.dump(4)
|
||||
<< std::endl;
|
||||
// OgreAssert(false, "props: " + props.dump(4));
|
||||
@@ -396,8 +398,8 @@ private:
|
||||
}
|
||||
void activate() override
|
||||
{
|
||||
std::cout << action->get_name();
|
||||
std::cout << "!";
|
||||
ZoneScoped;
|
||||
ZoneTextF("%s", action->get_name().c_str());
|
||||
delay = 1.0f;
|
||||
}
|
||||
|
||||
@@ -414,6 +416,7 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
static std::mutex ecs_mutex;
|
||||
ecs.module<CharacterAIModule>();
|
||||
ecs.import <CharacterManagerModule>();
|
||||
ecs.import <PlayerActionModule>();
|
||||
ecs.component<Blackboard>();
|
||||
ecs.component<TownAI>().on_add([](flecs::entity e, TownAI &ai) {
|
||||
std::lock_guard<std::mutex> lock(ecs_mutex);
|
||||
@@ -512,6 +515,7 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
const TownNPCs &npcs) {
|
||||
ZoneScopedN("CreateBlackboards");
|
||||
std::lock_guard<std::mutex> lock(ecs_mutex);
|
||||
OgreAssert(npcs.npcs.size() > 0, "npcs not crated");
|
||||
createBlackboards(town, npcs, ai);
|
||||
});
|
||||
ecs.system<ActionNodeList, TownAI, TownNPCs>("UpdateDynamicActions")
|
||||
@@ -520,11 +524,15 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
TownNPCs &npcs) {
|
||||
ZoneScopedN("UpdateDynamicActions");
|
||||
std::lock_guard<std::mutex> lock(ecs_mutex);
|
||||
OgreAssert(npcs.npcs.size() > 0, "npcs not crated");
|
||||
if (ai.nodeActions.size() > 0)
|
||||
return;
|
||||
if (alist.dynamicNodes.size() == 0)
|
||||
ECS::get_mut<ActionNodeList>()
|
||||
.updateDynamicNodes();
|
||||
OgreAssert(alist.nodes.size() > 0, "bad nodes");
|
||||
if (alist.dynamicNodes.size() == 0)
|
||||
return;
|
||||
OgreAssert(alist.dynamicNodes.size() > 0,
|
||||
"bad dynamic nodes");
|
||||
int nodeIndex;
|
||||
@@ -550,6 +558,7 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
.each([this](flecs::entity town, ActionNodeList &alist,
|
||||
TownAI &ai, TownNPCs &npcs) {
|
||||
ZoneScopedN("UpdateDynamicNodes");
|
||||
OgreAssert(npcs.npcs.size() > 0, "npcs not crated");
|
||||
std::lock_guard<std::mutex> lock(ecs_mutex);
|
||||
ECS::get_mut<ActionNodeList>().updateDynamicNodes();
|
||||
});
|
||||
@@ -574,6 +583,7 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
.kind(flecs::OnUpdate)
|
||||
.each([](flecs::entity e, TownNPCs &npcs) {
|
||||
ZoneScopedN("UpdateNPCPositions");
|
||||
OgreAssert(npcs.npcs.size() > 0, "npcs not crated");
|
||||
for (auto it = npcs.npcs.begin(); it != npcs.npcs.end();
|
||||
it++) {
|
||||
auto &npc = npcs.npcs.at(it->first);
|
||||
@@ -591,6 +601,7 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
.each([this](flecs::entity town, ActionNodeList &alist,
|
||||
TownAI &ai, const TownNPCs &npcs) {
|
||||
ZoneScopedN("UpdateBlackboards");
|
||||
OgreAssert(npcs.npcs.size() > 0, "npcs not crated");
|
||||
|
||||
Ogre::Root::getSingleton().getWorkQueue()->addTask([this,
|
||||
town,
|
||||
@@ -624,6 +635,10 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
.each([&](flecs::entity town, TownAI &ai,
|
||||
const TownNPCs &npcs) {
|
||||
ZoneScopedN("PlanAI");
|
||||
OgreAssert(npcs.npcs.size() > 0, "npcs not crated");
|
||||
OgreAssert(ai.blackboards.size() > 0,
|
||||
"blackboards not crated");
|
||||
OgreAssert(ai.memory.size() > 0, "memory not crated");
|
||||
Ogre::Root::getSingleton().getWorkQueue()->addTask([this,
|
||||
town,
|
||||
npcs,
|
||||
@@ -646,6 +661,10 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
.each([&](flecs::entity town, const EngineData &eng,
|
||||
TownNPCs &npcs, TownAI &ai) {
|
||||
ZoneScopedN("RunPLAN");
|
||||
OgreAssert(npcs.npcs.size() > 0, "npcs not crated");
|
||||
OgreAssert(ai.blackboards.size() > 0,
|
||||
"blackboards not crated");
|
||||
OgreAssert(ai.memory.size() > 0, "memory not crated");
|
||||
for (const auto &plans : ai.plans) {
|
||||
if (plan_exec.find(plans.first) !=
|
||||
plan_exec.end()) {
|
||||
@@ -668,13 +687,19 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
|
||||
// std::cout << " Goal: ";
|
||||
plan.goal->goal.dump_bits();
|
||||
for (const auto &action : plan.plan) {
|
||||
ActionExec::PlanExecData data({
|
||||
TownNPCs::NPCData &npc =
|
||||
npcs.npcs.at(
|
||||
plans.first),
|
||||
plans.first);
|
||||
Blackboard &bb =
|
||||
ai.blackboards.at(
|
||||
plans.first),
|
||||
plans.first);
|
||||
nlohmann::json &mem =
|
||||
ai.memory.at(
|
||||
plans.first),
|
||||
plans.first);
|
||||
ActionExec::PlanExecData data({
|
||||
npc,
|
||||
bb,
|
||||
mem,
|
||||
|
||||
});
|
||||
// TODO: executor factory is needed
|
||||
@@ -773,19 +798,26 @@ void CharacterAIModule::buildPlans(flecs::entity town, const TownNPCs &npcs,
|
||||
if (plan_tasks.size() > 0) {
|
||||
bool created = (plan_tasks.front())();
|
||||
if (created) {
|
||||
std::cout << plan_tasks.front().blackboard.index << " ";
|
||||
std::cout << "Goal: "
|
||||
<< plan_tasks.front().goal.get_name();
|
||||
plan_tasks.front().goal.goal.dump_bits();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Path: ";
|
||||
for (auto &action : plan_tasks.front().plan.plan) {
|
||||
OgreAssert(action, "No action");
|
||||
std::cout << action->get_name() + " ";
|
||||
ZoneTextF("%d: Goal: %s",
|
||||
plan_tasks.front().blackboard.index,
|
||||
plan_tasks.front().goal.get_name().c_str());
|
||||
{
|
||||
std::cout << plan_tasks.front().blackboard.index
|
||||
<< " ";
|
||||
std::cout << "Goal: "
|
||||
<< plan_tasks.front().goal.get_name();
|
||||
plan_tasks.front().goal.goal.dump_bits();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Path: ";
|
||||
for (auto &action :
|
||||
plan_tasks.front().plan.plan) {
|
||||
OgreAssert(action, "No action");
|
||||
std::cout << action->get_name() + " ";
|
||||
}
|
||||
std::cout << " size: "
|
||||
<< plan_tasks.front().plan.plan.size()
|
||||
<< std::endl;
|
||||
}
|
||||
std::cout << " size: "
|
||||
<< plan_tasks.front().plan.plan.size()
|
||||
<< std::endl;
|
||||
ai.plans[plan_tasks.front().blackboard.index].push_back(
|
||||
plan_tasks.front().plan);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user