Browse Source

Lazy initialize ResourceDictionary, test deaths

- ResourceDictionary static list is lazy initialized in case of weird static initialization
- Added test code for deaths to make it quicker
master
Macoy Madson 6 years ago
parent
commit
26fca82947
  1. 3
      Notes.md
  2. 33
      TODO.txt
  3. 9
      src/game/agent/AgentComponentManager.cpp
  4. 2
      src/game/agent/combat/CombatComponentManager.hpp
  5. 3
      src/util/ResourceDictionary.cpp
  6. 13
      src/util/ResourceDictionary.hpp

3
Notes.md

@ -15,4 +15,5 @@ you get the latest Galavant changes when using Unreal's hot reloading
- TODO: Something needs to get done. I use TodoReview for Sublime to find all of these easily.
- @Performance: Not justifiable as a TODO, but could be looked at when thinking about performance
- @Purity: Look into changing the code for code purity/cleanliness' sake
- @Callback: The marked function is used as a callback. Preferably @Callback [Callback type name]
- @Callback: The marked function is used as a callback. Preferably @Callback [Callback type name]
- @Stability: Should be changed in order to make the code more stable (segfault protection etc.)

33
TODO.txt

@ -30,9 +30,6 @@ Position vs GlobalPosition
How large? I'd have to do the math (yes, the monster math)
Combat System
Input
Make callbacks in player character which talk to combat system/do things. For now, maybe
make this step control timing and pull it out into combat later
Animations
This is going to be tricky. Procedural would be cool, but difficult. At least shoot for
procedural impact effects
@ -64,13 +61,25 @@ Fix debug text over AgentCharacter for combat test
Automatic apply UEngine patch script
Goal retrying needs rethinking (goal retry status is forgotten once goal completely fails)
After extended period of time, PlanComponentManager is constantly trying to unsubscribe things
Replaying in editor seems to do strange things with needs/timers. Are things being reset properly?
------------------
Doing
------------------
UnrealMovementComponent segfault
https://wiki.unrealengine.com/How_To_Prevent_Crashes_Due_To_Dangling_Actor_Pointers
https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/SmartPointerLibrary/WeakPointer/
Combat System
------------------
Done
------------------
Combat System
Input
Make callbacks in player character which talk to combat system/do things. For now, maybe
make this step control timing and pull it out into combat later
Spawning very, very broken
Seemed to see multiple actors spawned for a single berry
@ -82,16 +91,10 @@ Spawning very, very broken
Only call ActorOnDestroy if it wasn't previously marked for destruction (in Actor.h)
Current lifetime management doesn't prevent segfault. Wait until agents all group up for repro
Combat
After extended period of time, PlanComponentManager is constantly trying to unsubscribe things
Goal retrying needs rethinking (goal retry status is forgotten once goal completely fails)
UnrealMovementComponent segfault
https://wiki.unrealengine.com/How_To_Prevent_Crashes_Due_To_Dangling_Actor_Pointers
https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/SmartPointerLibrary/WeakPointer/
------------------
Done
------------------
Remember to put Galavant-specific UE code into a patch or something
Agent goals are broken after refactor

9
src/game/agent/AgentComponentManager.cpp

@ -4,6 +4,7 @@
#include "entityComponentSystem/PooledComponentManager.hpp"
#include "entityComponentSystem/EntityComponentManager.hpp"
#include "game/agent/combat/CombatComponentManager.hpp"
#include "util/Math.hpp"
@ -78,7 +79,7 @@ void AgentComponentManager::Update(float deltaSeconds)
if (!currentComponent->data.IsAlive)
{
// TODO: Figure out what to do about dead agents/bodies
entitiesToDestroy.push_back(currentEntity);
// entitiesToDestroy.push_back(currentEntity);
continue;
}
@ -127,6 +128,12 @@ void AgentComponentManager::Update(float deltaSeconds)
currentComponent->data.IsAlive = false;
LOGD_IF(DebugPrint) << "Agent Entity " << currentEntity
<< " has died from need " << need.Def->Name;
// temporary
static CombatActionDef deathActionDef;
deathActionDef.Die = true;
CombatAction deathAction{&deathActionDef, nullptr, 0.f};
g_CombatComponentManager.ActivateCombatAction(currentComponent->entity,
deathAction);
}
}

2
src/game/agent/combat/CombatComponentManager.hpp

@ -38,6 +38,8 @@ struct CombatActionDef
};
CombatActionKnockback Knockback;
bool Die;
};
extern ResourceDictionary<CombatActionDef> g_CombatActionDefDictionary;

3
src/util/ResourceDictionary.cpp

@ -2,5 +2,6 @@
namespace gv
{
std::vector<ResourceDictionaryBase*> ResourceDictionaryBase::s_AllResourceDictionaries;
ResourceDictionaryBase::ResourceDictionaryList* ResourceDictionaryBase::s_AllResourceDictionaries =
nullptr;
}

13
src/util/ResourceDictionary.hpp

@ -15,13 +15,17 @@ typedef int ResourceKey;
// This base is required because we want to store pointers to many types of ResourceDictionary
struct ResourceDictionaryBase
{
static std::vector<ResourceDictionaryBase*> s_AllResourceDictionaries;
typedef std::vector<ResourceDictionaryBase*> ResourceDictionaryList;
static ResourceDictionaryList* s_AllResourceDictionaries;
virtual ~ResourceDictionaryBase() = default;
virtual void ClearResources() = 0;
static void ClearAllDictionaries()
{
for (ResourceDictionaryBase* dictionary : s_AllResourceDictionaries)
if (!s_AllResourceDictionaries)
return;
for (ResourceDictionaryBase* dictionary : (*s_AllResourceDictionaries))
dictionary->ClearResources();
}
};
@ -33,7 +37,10 @@ struct ResourceDictionary : public ResourceDictionaryBase
ResourceDictionary()
{
s_AllResourceDictionaries.push_back(this);
// Lazy initialize for static initialization support
if (!s_AllResourceDictionaries)
s_AllResourceDictionaries = new ResourceDictionaryList;
s_AllResourceDictionaries->push_back(this);
}
virtual ~ResourceDictionary() = default;

Loading…
Cancel
Save