Now can test smart object action on player character again
This commit is contained in:
@@ -330,6 +330,8 @@ void EditorApp::setup()
|
||||
// Wire up AnimationTreeSystem for animation state machine control
|
||||
m_smartObjectSystem->setAnimationTreeSystem(
|
||||
m_animationTreeSystem.get());
|
||||
// Wire up EditorApp for game mode detection
|
||||
m_smartObjectSystem->setEditorApp(this);
|
||||
|
||||
// Setup CellGrid system
|
||||
m_cellGridSystem =
|
||||
|
||||
@@ -8,12 +8,16 @@
|
||||
#include "../components/ActionDebug.hpp"
|
||||
#include "../components/NavMesh.hpp"
|
||||
#include "../components/AnimationTree.hpp"
|
||||
#include "../components/PlayerController.hpp"
|
||||
#include "../components/EntityName.hpp"
|
||||
#include "../EditorApp.hpp"
|
||||
#include "NavMeshSystem.hpp"
|
||||
#include "BehaviorTreeSystem.hpp"
|
||||
#include "AnimationTreeSystem.hpp"
|
||||
#include <OgreLogManager.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <unordered_set>
|
||||
|
||||
SmartObjectSystem *SmartObjectSystem::s_instance = nullptr;
|
||||
|
||||
@@ -188,6 +192,36 @@ void SmartObjectSystem::update(float deltaTime)
|
||||
db = &database;
|
||||
});
|
||||
|
||||
// Determine if we're in game mode. In game mode, player-controlled
|
||||
// characters are managed by PlayerControllerSystem and should NOT
|
||||
// be processed by SmartObjectSystem to avoid animation conflicts.
|
||||
// In editor mode, player characters can still be tested via ActionDebug.
|
||||
bool isGameMode = false;
|
||||
if (m_editorApp &&
|
||||
m_editorApp->getGameMode() == EditorApp::GameMode::Game &&
|
||||
m_editorApp->getGamePlayState() ==
|
||||
EditorApp::GamePlayState::Playing) {
|
||||
isGameMode = true;
|
||||
}
|
||||
|
||||
// Build a set of entity IDs that are player-controlled characters.
|
||||
std::unordered_set<flecs::entity_t> playerCharacterIds;
|
||||
if (isGameMode) {
|
||||
m_world.query<PlayerControllerComponent>().each(
|
||||
[&](flecs::entity, PlayerControllerComponent &pc) {
|
||||
if (pc.targetCharacterName.empty())
|
||||
return;
|
||||
m_world.query<EntityNameComponent>().each(
|
||||
[&](flecs::entity e,
|
||||
EntityNameComponent &en) {
|
||||
if (en.name ==
|
||||
pc.targetCharacterName)
|
||||
playerCharacterIds
|
||||
.insert(e.id());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Process each character with a blackboard (AI-driven characters)
|
||||
m_world.query<CharacterComponent, TransformComponent, GoapBlackboard>()
|
||||
.each([&](flecs::entity e, CharacterComponent &cc,
|
||||
@@ -196,6 +230,12 @@ void SmartObjectSystem::update(float deltaTime)
|
||||
(void)trans;
|
||||
(void)bb;
|
||||
|
||||
// Skip player-controlled characters - they are managed
|
||||
// by PlayerControllerSystem, not by SmartObjectSystem AI.
|
||||
if (playerCharacterIds.find(e.id()) !=
|
||||
playerCharacterIds.end())
|
||||
return;
|
||||
|
||||
auto &state = m_states[e.id()];
|
||||
state.scanTimer += deltaTime;
|
||||
|
||||
@@ -597,6 +637,12 @@ void SmartObjectSystem::update(float deltaTime)
|
||||
(void)trans;
|
||||
(void)debug;
|
||||
|
||||
// Skip player-controlled characters - they are managed
|
||||
// by PlayerControllerSystem, not by SmartObjectSystem AI.
|
||||
if (playerCharacterIds.find(e.id()) !=
|
||||
playerCharacterIds.end())
|
||||
return;
|
||||
|
||||
auto &state = m_states[e.id()];
|
||||
|
||||
// When the behavior tree is running (via ActionDebug),
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
class NavMeshSystem;
|
||||
class BehaviorTreeSystem;
|
||||
class AnimationTreeSystem;
|
||||
class EditorApp;
|
||||
|
||||
/**
|
||||
* System that manages Smart Object interactions.
|
||||
@@ -42,6 +43,18 @@ public:
|
||||
m_animTreeSystem = system;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the EditorApp for game mode detection.
|
||||
* When in game mode, player-controlled characters are skipped
|
||||
* to avoid animation conflicts with PlayerControllerSystem.
|
||||
* In editor mode, player characters can still be tested via
|
||||
* ActionDebug.
|
||||
*/
|
||||
void setEditorApp(EditorApp *app)
|
||||
{
|
||||
m_editorApp = app;
|
||||
}
|
||||
|
||||
void update(float deltaTime);
|
||||
|
||||
/**
|
||||
@@ -100,6 +113,7 @@ private:
|
||||
NavMeshSystem *m_navSystem;
|
||||
BehaviorTreeSystem *m_btSystem;
|
||||
AnimationTreeSystem *m_animTreeSystem;
|
||||
EditorApp *m_editorApp = nullptr;
|
||||
|
||||
std::unordered_map<flecs::entity_t, CharacterState> m_states;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user