2016-02-13 09:02:47 +00:00
|
|
|
#ifndef __PSHAG_CSTATICINTERFERENCE_HPP__
|
|
|
|
#define __PSHAG_CSTATICINTERFERENCE_HPP__
|
2015-08-17 20:33:58 +00:00
|
|
|
|
2015-08-20 02:52:07 +00:00
|
|
|
#include <vector>
|
|
|
|
#include "RetroTypes.hpp"
|
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
namespace pshag
|
2015-08-17 22:05:00 +00:00
|
|
|
{
|
2015-08-20 02:52:07 +00:00
|
|
|
class CStateManager;
|
|
|
|
|
|
|
|
struct CStaticInterferenceSource
|
|
|
|
{
|
|
|
|
TUniqueId id;
|
|
|
|
float magnitude;
|
|
|
|
float timeLeft;
|
|
|
|
};
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2015-08-17 20:33:58 +00:00
|
|
|
class CStaticInterference
|
|
|
|
{
|
2015-08-20 02:52:07 +00:00
|
|
|
std::vector<CStaticInterferenceSource> m_sources;
|
|
|
|
public:
|
|
|
|
CStaticInterference(int sourceCount)
|
|
|
|
{
|
|
|
|
m_sources.reserve(sourceCount);
|
|
|
|
}
|
|
|
|
void AddSource(TUniqueId id, float magnitude, float duration)
|
|
|
|
{
|
|
|
|
for (CStaticInterferenceSource& src : m_sources)
|
|
|
|
{
|
|
|
|
if (src.id == id)
|
|
|
|
{
|
|
|
|
src.magnitude = magnitude;
|
|
|
|
src.timeLeft = duration;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_sources.push_back({id, magnitude, duration});
|
|
|
|
}
|
|
|
|
void Update(CStateManager&, float dt)
|
|
|
|
{
|
|
|
|
std::vector<CStaticInterferenceSource> newSources;
|
|
|
|
newSources.reserve(m_sources.size());
|
|
|
|
for (CStaticInterferenceSource& src : m_sources)
|
|
|
|
{
|
|
|
|
if (src.timeLeft >= 0.0)
|
|
|
|
{
|
|
|
|
src.timeLeft -= dt;
|
|
|
|
newSources.push_back(src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_sources = std::move(newSources);
|
|
|
|
}
|
|
|
|
float GetTotalInterference() const
|
|
|
|
{
|
|
|
|
float validAccum = 0.0;
|
|
|
|
float invalidAccum = 0.0;
|
|
|
|
for (const CStaticInterferenceSource& src : m_sources)
|
|
|
|
{
|
|
|
|
if (src.id == kInvalidUniqueId)
|
|
|
|
invalidAccum += src.magnitude;
|
|
|
|
else
|
|
|
|
validAccum += src.magnitude;
|
|
|
|
}
|
|
|
|
if (validAccum > 0.80000001)
|
|
|
|
validAccum = 0.80000001;
|
|
|
|
validAccum += invalidAccum;
|
|
|
|
if (validAccum > 1.0)
|
|
|
|
return 1.0;
|
|
|
|
return validAccum;
|
|
|
|
}
|
2015-08-17 20:33:58 +00:00
|
|
|
};
|
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
#endif // __PSHAG_CSTATICINTERFERENCE_HPP__
|