Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpParticleManager.cpp
Show All 11 Lines | |||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "CCmpParticleManager.h" | |||||
#include "simulation2/system/Component.h" | #include "simulation2/system/Component.h" | ||||
#include "ICmpParticleManager.h" | |||||
#include "graphics/ParticleManager.h" | #include "graphics/ParticleManager.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/SceneRenderer.h" | #include "renderer/SceneRenderer.h" | ||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
class CCmpParticleManager final : public ICmpParticleManager | void CCmpParticleManager::ClassInit(CComponentManager& componentManager) | ||||
{ | |||||
public: | |||||
static void ClassInit(CComponentManager& componentManager) | |||||
{ | { | ||||
componentManager.SubscribeToMessageType(MT_Interpolate); | componentManager.SubscribeToMessageType(MT_Interpolate); | ||||
} | } | ||||
DEFAULT_COMPONENT_ALLOCATOR(ParticleManager) | IComponent* CCmpParticleManager::Allocate(const ScriptInterface&, JS::HandleValue) | ||||
bool useSimTime; | |||||
static std::string GetSchema() | |||||
{ | { | ||||
return "<a:component type='system'/><empty/>"; | return nullptr; | ||||
} | } | ||||
void Init(const CParamNode& UNUSED(paramNode)) override | void CCmpParticleManager::Deallocate(IComponent*) | ||||
{} | |||||
int CCmpParticleManager::GetComponentTypeId() const | |||||
{ | { | ||||
useSimTime = true; | return CID_ParticleManager; | ||||
} | } | ||||
void Deinit() override | std::string CCmpParticleManager::GetSchema() | ||||
{ | { | ||||
return "<a:component type='system'/><empty/>"; | |||||
} | } | ||||
void Serialize(ISerializer& UNUSED(serialize)) override | void CCmpParticleManager::Init(const CParamNode& UNUSED(paramNode)) | ||||
{ | { | ||||
useSimTime = true; | |||||
} | } | ||||
void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) override | void CCmpParticleManager::Deinit() | ||||
{} | |||||
void CCmpParticleManager::Serialize(ISerializer& UNUSED(serialize)) | |||||
{} | |||||
void CCmpParticleManager::Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) | |||||
{ | { | ||||
Init(paramNode); | Init(paramNode); | ||||
} | } | ||||
void HandleMessage(const CMessage& msg, bool UNUSED(global)) override | void CCmpParticleManager::HandleMessage(const CMessage& msg, bool UNUSED(global)) | ||||
{ | { | ||||
switch (msg.GetType()) | switch (msg.GetType()) | ||||
{ | { | ||||
case MT_Interpolate: | case MT_Interpolate: | ||||
{ | { | ||||
const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); | const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg); | ||||
if (CRenderer::IsInitialised()) | if (CRenderer::IsInitialised()) | ||||
{ | { | ||||
float time = useSimTime ? msgData.deltaSimTime : msgData.deltaRealTime; | float time = useSimTime ? msgData.deltaSimTime : msgData.deltaRealTime; | ||||
g_Renderer.GetSceneRenderer().GetParticleManager().Interpolate(time); | g_Renderer.GetSceneRenderer().GetParticleManager().Interpolate(time); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void SetUseSimTime(bool flag) override | void CCmpParticleManager::SetUseSimTime(bool flag) | ||||
{ | { | ||||
useSimTime = flag; | useSimTime = flag; | ||||
} | } | ||||
}; | |||||
REGISTER_COMPONENT_TYPE(ParticleManager) | REGISTER_COMPONENT_TYPE(ParticleManager) |
Wildfire Games · Phabricator