98 lines
2.6 KiB
C++
98 lines
2.6 KiB
C++
#pragma once
|
|
#include"EffectTypes.h"
|
|
|
|
#define EFF(variant) EffectManager::GetEffect(variant)
|
|
|
|
using EffectT=std::variant<
|
|
Effect,
|
|
Meteor,
|
|
PulsatingFire,
|
|
SwordSlash,
|
|
ForegroundEffect,
|
|
SpellCircle,
|
|
RockLaunch,
|
|
ShineEffect,
|
|
MonsterSoul,
|
|
FadeInOutEffect,
|
|
LingeringEffect,
|
|
Ink,
|
|
FlipCoinEffect,
|
|
CollectCoinEffect,
|
|
Blizzard,
|
|
FreezeGround,
|
|
TrailEffect,
|
|
BlackHole,
|
|
ExpandingRing,
|
|
FallEffect,
|
|
FallWShadowEffect,
|
|
GroundSlamEffect
|
|
>;
|
|
|
|
struct EffectOverloads{
|
|
template<typename T>
|
|
bool operator()(T&eff,float fElapsedTime){return eff.Update(fElapsedTime);}
|
|
template<typename T>
|
|
void operator()(T&eff,const Pixel blendCol){eff.Draw(blendCol);}
|
|
};
|
|
|
|
struct EffectManager{
|
|
friend class AiL;
|
|
struct EffectData{
|
|
EffectData();
|
|
EffectData(int effectId,const EffectT&effect);
|
|
int effectId{};
|
|
std::optional<EffectT>effect{};
|
|
};
|
|
static void Reset();
|
|
static std::array<EffectData,EFFECT_LIMIT>&GetForegroundEffects();
|
|
static std::array<EffectData,EFFECT_LIMIT>&GetBackgroundEffects();
|
|
static size_t GetForegroundEffectCount();
|
|
static size_t GetBackgroundEffectCount();
|
|
struct funcName_Overloads {
|
|
template<typename T>
|
|
const Effect& operator()(T&obj) {
|
|
return obj;
|
|
};
|
|
};
|
|
template<typename T>
|
|
static Effect& GetEffect(T& eff) {
|
|
return const_cast<Effect&>(std::visit(funcName_Overloads{},eff));
|
|
};
|
|
private:
|
|
inline static int GLOBAL_EFFECT_ID{0};
|
|
inline static std::array<EffectData,EFFECT_LIMIT>foregroundEffectList{};
|
|
inline static size_t activeForegroundEffectCount{};
|
|
inline static std::array<EffectData,EFFECT_LIMIT>backgroundEffectList{};
|
|
inline static size_t activeBackgroundEffectCount{};
|
|
};
|
|
|
|
using EffectData=EffectManager::EffectData;
|
|
|
|
template<typename T>
|
|
struct EffectRef{
|
|
public:
|
|
inline EffectRef(int slotId,int effectId,bool foregroundEffect):slotId(slotId),effectId(effectId),foregroundEffect(foregroundEffect){}
|
|
|
|
inline bool expired()const{
|
|
const std::array<EffectManager::EffectData,EFFECT_LIMIT>&effectList{foregroundEffect?EffectManager::GetForegroundEffects():EffectManager::GetBackgroundEffects()};
|
|
return !effectList.at(slotId).effect||effectList.at(slotId).effectId!=effectId;
|
|
};
|
|
|
|
inline bool operator==(const EffectRef&ref){
|
|
return !expired();
|
|
};
|
|
|
|
T&get(){
|
|
std::array<EffectManager::EffectData,1000>&effectList{foregroundEffect?EffectManager::GetForegroundEffects():EffectManager::GetBackgroundEffects()};
|
|
if(expired())ERR("WARNING! This effect was not properly checked for expiration! THIS IS NOT ALLOWED!");
|
|
return dynamic_cast<T&>(EFF(*effectList.at(slotId).effect));
|
|
};
|
|
#ifndef UNIT_TESTING
|
|
private:
|
|
#else
|
|
public:
|
|
#endif
|
|
int slotId;
|
|
int effectId;
|
|
bool foregroundEffect{false};
|
|
}; |