2022-01-04 05:29:01 -08:00
|
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* This file is part of 0 A.D.
|
2013-12-05 16:42:50 -08:00
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2013-12-05 16:42:50 -08:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2013-12-05 16:42:50 -08:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2013-12-05 16:42:50 -08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "simulation2/system/Component.h"
|
|
|
|
|
|
#include "ICmpParticleManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "graphics/ParticleManager.h"
|
|
|
|
|
|
#include "renderer/Renderer.h"
|
2022-01-04 05:29:01 -08:00
|
|
|
|
#include "renderer/SceneRenderer.h"
|
|
|
|
|
|
#include "simulation2/MessageTypes.h"
|
2013-12-05 16:42:50 -08:00
|
|
|
|
|
2022-03-03 14:42:26 -08:00
|
|
|
|
class CCmpParticleManager final : public ICmpParticleManager
|
2013-12-05 16:42:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
static void ClassInit(CComponentManager& componentManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
componentManager.SubscribeToMessageType(MT_Interpolate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_COMPONENT_ALLOCATOR(ParticleManager)
|
|
|
|
|
|
|
|
|
|
|
|
bool useSimTime;
|
|
|
|
|
|
|
|
|
|
|
|
static std::string GetSchema()
|
|
|
|
|
|
{
|
|
|
|
|
|
return "<a:component type='system'/><empty/>";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Init(const CParamNode& UNUSED(paramNode)) override
|
2013-12-05 16:42:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
useSimTime = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Deinit() override
|
2013-12-05 16:42:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Serialize(ISerializer& UNUSED(serialize)) override
|
2013-12-05 16:42:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) override
|
2013-12-05 16:42:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
Init(paramNode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void HandleMessage(const CMessage& msg, bool UNUSED(global)) override
|
2013-12-05 16:42:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
switch (msg.GetType())
|
|
|
|
|
|
{
|
|
|
|
|
|
case MT_Interpolate:
|
|
|
|
|
|
{
|
|
|
|
|
|
const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
|
|
|
|
|
|
if (CRenderer::IsInitialised())
|
|
|
|
|
|
{
|
|
|
|
|
|
float time = useSimTime ? msgData.deltaSimTime : msgData.deltaRealTime;
|
2022-01-04 05:29:01 -08:00
|
|
|
|
g_Renderer.GetSceneRenderer().GetParticleManager().Interpolate(time);
|
2013-12-05 16:42:50 -08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
|
void SetUseSimTime(bool flag) override
|
2013-12-05 16:42:50 -08:00
|
|
|
|
{
|
|
|
|
|
|
useSimTime = flag;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_TYPE(ParticleManager)
|