Browse Source
- Added PlanComponentManager, which is still WIP but at a stage where it could be used in Galavant-Unreal - Removed all functions with (void) because apparently that's just a C thing (what I use I work) and is discouraged in C++ - Removed some #ifdef include guards in favor of #pragma once - Put some earlier code into the Galavant gv namespace - Fixed a small bug in EntityTypes.cpp where EntityListAppend() was actually prepending (oops!) - Started writing WorldState. This class is likely to see lots of refactoring - Tried some geo stuff out in BuildingSystemcombatComponentRefactor

22 changed files with 297 additions and 99 deletions
Binary file not shown.
@ -0,0 +1,26 @@ |
|||
#pragma once |
|||
|
|||
#include "../world/Position.hpp" |
|||
|
|||
namespace gv |
|||
{ |
|||
struct AgentState |
|||
{ |
|||
Position position; |
|||
}; |
|||
|
|||
/* --WorldState--
|
|||
WorldState represents a mutable, copyable reference to all AI-relevant data in the World. |
|||
Mutable: The data can be manipulated freely without repurcussion. Note that changing data in |
|||
WorldState is NOT expected to actually change the world - WorldState is like a mirror world |
|||
Copyable: The data can be copied without a significant amount of time. This means that in order |
|||
to support mutability, things like changelists might need to be implemented for large datasets |
|||
instead of actually copying the dataset |
|||
*/ |
|||
struct WorldState |
|||
{ |
|||
// Because an agent is almost always going to...well, maybe this shouldn't be here. For now it
|
|||
// will stay.
|
|||
AgentState SourceAgent; |
|||
}; |
|||
}; |
@ -0,0 +1,5 @@ |
|||
SubDir . src game ; |
|||
|
|||
Library libGalaGame : agent/PlanComponentManager.cpp ; |
|||
|
|||
MakeLocate libGalaGame.a : lib ; |
@ -0,0 +1,80 @@ |
|||
#include "PlanComponentManager.hpp" |
|||
|
|||
#include "../../entityComponentSystem/PooledComponentManager.hpp" |
|||
|
|||
PlanComponentManager::PlanComponentManager() : gv::PooledComponentManager<PlanComponentData>(100) |
|||
{ |
|||
} |
|||
|
|||
PlanComponentManager::~PlanComponentManager() |
|||
{ |
|||
} |
|||
|
|||
void PlanComponentManager::Initialize() |
|||
{ |
|||
} |
|||
|
|||
void PlanComponentManager::Update(float deltaSeconds) |
|||
{ |
|||
// TODO: Adding true iterator support to pool will drastically help damning this to hell
|
|||
gv::PooledComponentManager<PlanComponentData>::FragmentedPoolIterator it = |
|||
gv::PooledComponentManager<PlanComponentData>::NULL_POOL_ITERATOR; |
|||
for (gv::PooledComponent<PlanComponentData>* currentComponent = ActivePoolBegin(it); |
|||
currentComponent != nullptr && |
|||
it != gv::PooledComponentManager<PlanComponentData>::NULL_POOL_ITERATOR; |
|||
currentComponent = GetNextActivePooledComponent(it)) |
|||
{ |
|||
if (!currentComponent) |
|||
continue; |
|||
|
|||
Htn::Planner& componentPlanner = currentComponent->data.Planner; |
|||
|
|||
// For now, don't follow plan, just ignore finished/failed plans
|
|||
if (!componentPlanner.IsPlanRunning()) |
|||
continue; |
|||
|
|||
Htn::Planner::Status status = componentPlanner.PlanStep(); |
|||
if (!componentPlanner.IsPlanRunning()) |
|||
{ |
|||
if (status == Htn::Planner::Status::PlanComplete) |
|||
{ |
|||
std::cout << "PlanComponentManager: Sucessful plan for Entity " |
|||
<< currentComponent->entity << "! Final Call List:\n"; |
|||
Htn::PrintTaskCallList(componentPlanner.FinalCallList); |
|||
} |
|||
|
|||
if (status < Htn::Planner::Status::Running_EnumBegin) |
|||
{ |
|||
std::cout << "PlanComponentManager: Failed plan for Entity " |
|||
<< currentComponent->entity << "! Initial Call List:\n"; |
|||
Htn::PrintTaskCallList(componentPlanner.InitialCallList); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void PlanComponentManager::SubscribeEntitiesInternal(PlanComponentRefList& components) |
|||
{ |
|||
for (gv::PooledComponent<PlanComponentData>* currentComponent : components) |
|||
{ |
|||
if (!currentComponent) |
|||
continue; |
|||
|
|||
Htn::Planner& planner = currentComponent->data.Planner; |
|||
Htn::TaskCallList& goalCallList = currentComponent->data.Goals; |
|||
|
|||
planner.InitialCallList.insert(planner.InitialCallList.end(), goalCallList.begin(), |
|||
goalCallList.end()); |
|||
} |
|||
} |
|||
|
|||
void PlanComponentManager::UnsubscribeEntitiesInternal(PlanComponentRefList& components) |
|||
{ |
|||
for (gv::PooledComponent<PlanComponentData>* currentComponent : components) |
|||
{ |
|||
if (!currentComponent) |
|||
continue; |
|||
|
|||
// Perform unsubscription
|
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
#pragma once |
|||
|
|||
#include "../../entityComponentSystem/PooledComponentManager.hpp" |
|||
#include "../../ai/htn/HTNPlanner.cpp" |
|||
#include "../../ai/WorldState.hpp" |
|||
|
|||
struct PlanComponentData |
|||
{ |
|||
gv::WorldState state; |
|||
|
|||
Htn::TaskCallList Goals; |
|||
|
|||
protected: |
|||
friend class PlanComponentManager; |
|||
Htn::Planner Planner; |
|||
}; |
|||
|
|||
/* --PlanComponentManager--
|
|||
Prepare, manage, and execute plan(s) for Entities. |
|||
|
|||
TODO: PooledComponentManager is going to need to be discarded in order to handle Entities with many |
|||
plans. |
|||
*/ |
|||
class PlanComponentManager : public gv::PooledComponentManager<PlanComponentData> |
|||
{ |
|||
protected: |
|||
typedef std::vector<gv::PooledComponent<PlanComponentData>*> PlanComponentRefList; |
|||
|
|||
virtual void SubscribeEntitiesInternal(PlanComponentRefList& components); |
|||
virtual void UnsubscribeEntitiesInternal(PlanComponentRefList& components); |
|||
|
|||
public: |
|||
typedef std::vector<gv::PooledComponent<PlanComponentData>> PlanComponentList; |
|||
|
|||
PlanComponentManager(); |
|||
virtual ~PlanComponentManager(); |
|||
void Initialize(); |
|||
virtual void Update(float deltaSeconds); |
|||
}; |
Loading…
Reference in new issue