diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index a23c2adce5..06e7183862 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -305,11 +305,6 @@ bool CGame::Update(const double deltaRealTime, bool doInterpolate) g_SoundManager->IdleTask(); #endif } - - // TODO: maybe we should add a CCmpParticleInterface that passes the interpolation commands - // etc to CParticleManager. But in the meantime just handle it explicitly here. - if (doInterpolate && CRenderer::IsInitialised()) - g_Renderer.GetParticleManager().Interpolate(deltaSimTime); return ok; } @@ -320,9 +315,6 @@ void CGame::Interpolate(float simFrameLength, float realFrameLength) return; m_TurnManager->Interpolate(simFrameLength, realFrameLength); - - if (CRenderer::IsInitialised()) - g_Renderer.GetParticleManager().Interpolate(simFrameLength); } diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 6efe4b0492..6adb6002b4 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -102,6 +102,7 @@ public: componentManager.AddComponent(SYSTEM_ENTITY, CID_CommandQueue, noParam); componentManager.AddComponent(SYSTEM_ENTITY, CID_ObstructionManager, noParam); + componentManager.AddComponent(SYSTEM_ENTITY, CID_ParticleManager, noParam); componentManager.AddComponent(SYSTEM_ENTITY, CID_Pathfinder, noParam); componentManager.AddComponent(SYSTEM_ENTITY, CID_ProjectileManager, noParam); componentManager.AddComponent(SYSTEM_ENTITY, CID_RangeManager, noParam); diff --git a/source/simulation2/TypeList.h b/source/simulation2/TypeList.h index fc54a9da6c..c1f98d9fdd 100644 --- a/source/simulation2/TypeList.h +++ b/source/simulation2/TypeList.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -105,6 +105,9 @@ COMPONENT(OverlayRenderer) INTERFACE(Ownership) COMPONENT(Ownership) +INTERFACE(ParticleManager) +COMPONENT(ParticleManager) + INTERFACE(Pathfinder) COMPONENT(Pathfinder) diff --git a/source/simulation2/components/CCmpParticleManager.cpp b/source/simulation2/components/CCmpParticleManager.cpp new file mode 100644 index 0000000000..eacb95bc05 --- /dev/null +++ b/source/simulation2/components/CCmpParticleManager.cpp @@ -0,0 +1,86 @@ +/* Copyright (C) 2013 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * 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. + * + * 0 A.D. is distributed in the hope that it will be useful, + * 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 + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "simulation2/system/Component.h" +#include "ICmpParticleManager.h" + +#include "simulation2/MessageTypes.h" + +#include "graphics/ParticleManager.h" +#include "renderer/Renderer.h" + +class CCmpParticleManager : public ICmpParticleManager +{ +public: + static void ClassInit(CComponentManager& componentManager) + { + componentManager.SubscribeToMessageType(MT_Interpolate); + } + + DEFAULT_COMPONENT_ALLOCATOR(ParticleManager) + + bool useSimTime; + + static std::string GetSchema() + { + return ""; + } + + virtual void Init(const CParamNode& UNUSED(paramNode)) + { + useSimTime = true; + } + + virtual void Deinit() + { + } + + virtual void Serialize(ISerializer& UNUSED(serialize)) + { + } + + virtual void Deserialize(const CParamNode& paramNode, IDeserializer& UNUSED(deserialize)) + { + Init(paramNode); + } + + virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) + { + switch (msg.GetType()) + { + case MT_Interpolate: + { + const CMessageInterpolate& msgData = static_cast (msg); + if (CRenderer::IsInitialised()) + { + float time = useSimTime ? msgData.deltaSimTime : msgData.deltaRealTime; + g_Renderer.GetParticleManager().Interpolate(time); + } + break; + } + } + } + + virtual void SetUseSimTime(bool flag) + { + useSimTime = flag; + } +}; + +REGISTER_COMPONENT_TYPE(ParticleManager) diff --git a/source/simulation2/components/ICmpParticleManager.cpp b/source/simulation2/components/ICmpParticleManager.cpp new file mode 100644 index 0000000000..471cbb3713 --- /dev/null +++ b/source/simulation2/components/ICmpParticleManager.cpp @@ -0,0 +1,25 @@ +/* Copyright (C) 2013 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * 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. + * + * 0 A.D. is distributed in the hope that it will be useful, + * 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 + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "ICmpParticleManager.h" + +#include "simulation2/system/InterfaceScripted.h" + +BEGIN_INTERFACE_WRAPPER(ParticleManager) +END_INTERFACE_WRAPPER(ParticleManager) diff --git a/source/simulation2/components/ICmpParticleManager.h b/source/simulation2/components/ICmpParticleManager.h new file mode 100644 index 0000000000..73d8d7a2cc --- /dev/null +++ b/source/simulation2/components/ICmpParticleManager.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2013 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * 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. + * + * 0 A.D. is distributed in the hope that it will be useful, + * 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 + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_ICMPPARTICLEMANAGER +#define INCLUDED_ICMPPARTICLEMANAGER + +#include "simulation2/system/Interface.h" + +/** + * Minimal interface for particle rendering + */ +class ICmpParticleManager : public IComponent +{ +public: + + /** + * Set whether particle rendering should use sim time + * If false, it uses real time and updates even during paused game + */ + virtual void SetUseSimTime(bool flag) = 0; + + DECLARE_INTERFACE_TYPE(ParticleManager) +}; + +#endif // INCLUDED_ICMPPARTICLEMANAGER diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index f903bff583..5cdca8fc8e 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -522,6 +522,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac // Start with a blank map (so that the editor can assume there's always // a valid map loaded) POST_MESSAGE(LoadMap, (_T("_default"))); + POST_MESSAGE(SimPlay, (0.f, false)); // Select the initial sidebar (after the map has loaded) m_SectionLayout.SelectPage(_T("MapSidebar")); diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp index 92ef788980..bd79d7e801 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -387,6 +387,12 @@ void MapSidebar::OnFirstDisplay() void MapSidebar::OnMapReload() { m_MapSettingsCtrl->ReadFromEngine(); + + // Reset sim test buttons + POST_MESSAGE(SimPlay, (0.f, false)); + POST_MESSAGE(GuiSwitchPage, (L"page_atlas.xml")); + m_SimState = SimInactive; + UpdateSimButtons(); } void MapSidebar::UpdateSimButtons() @@ -436,12 +442,12 @@ void MapSidebar::OnSimPlay(wxCommandEvent& event) POST_MESSAGE(SimStateSave, (L"default")); POST_MESSAGE(GuiSwitchPage, (L"page_session.xml")); - POST_MESSAGE(SimPlay, (speed)); + POST_MESSAGE(SimPlay, (speed, true)); m_SimState = newState; } else // paused or already playing at a different speed { - POST_MESSAGE(SimPlay, (speed)); + POST_MESSAGE(SimPlay, (speed, true)); m_SimState = newState; } UpdateSimButtons(); @@ -451,7 +457,7 @@ void MapSidebar::OnSimPause(wxCommandEvent& WXUNUSED(event)) { if (IsPlaying(m_SimState)) { - POST_MESSAGE(SimPlay, (0.f)); + POST_MESSAGE(SimPlay, (0.f, true)); m_SimState = SimPaused; } UpdateSimButtons(); @@ -461,14 +467,17 @@ void MapSidebar::OnSimReset(wxCommandEvent& WXUNUSED(event)) { if (IsPlaying(m_SimState)) { - POST_MESSAGE(SimPlay, (0.f)); + POST_MESSAGE(SimPlay, (0.f, true)); POST_MESSAGE(SimStateRestore, (L"default")); + POST_MESSAGE(SimPlay, (0.f, false)); POST_MESSAGE(GuiSwitchPage, (L"page_atlas.xml")); m_SimState = SimInactive; } else if (m_SimState == SimPaused) { + POST_MESSAGE(SimPlay, (0.f, true)); POST_MESSAGE(SimStateRestore, (L"default")); + POST_MESSAGE(SimPlay, (0.f, false)); POST_MESSAGE(GuiSwitchPage, (L"page_atlas.xml")); m_SimState = SimInactive; } diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index b93a93464b..072f9385d4 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -529,7 +529,6 @@ void ActorViewer::Update(float simFrameLength, float realFrameLength) { m.Simulation2.Update((int)(simFrameLength*1000)); m.Simulation2.Interpolate(simFrameLength, 0, realFrameLength); - g_Renderer.GetParticleManager().Interpolate(simFrameLength); if (m.WalkEnabled && m.CurrentSpeed) { diff --git a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp index 7fb78be805..78485ca081 100644 --- a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -143,6 +143,7 @@ QUERYHANDLER(SimStateDebugDump) MESSAGEHANDLER(SimPlay) { AtlasView::GetView_Game()->SetSpeedMultiplier(msg->speed); + AtlasView::GetView_Game()->SetTesting(msg->simTest); } MESSAGEHANDLER(JavaScript) diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 86489f63ad..2c836d7883 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -117,6 +117,7 @@ QUERY(SimStateDebugDump, MESSAGE(SimPlay, ((float, speed)) // 0 for pause, 1 for normal speed + ((bool, simTest)) // true if we're in simulation test mode, false otherwise ); ////////////////////////////////////////////////////////////////////////// diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 93be78c88a..95000388f8 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -38,6 +38,7 @@ #include "renderer/Renderer.h" #include "simulation2/Simulation2.h" #include "simulation2/components/ICmpObstructionManager.h" +#include "simulation2/components/ICmpParticleManager.h" #include "simulation2/components/ICmpPathfinder.h" extern void (*Atlas_GLSwapBuffers)(void* context); @@ -168,7 +169,7 @@ static void delete_pair_2nd(std::pair v) } AtlasViewGame::AtlasViewGame() - : m_SpeedMultiplier(0.f) + : m_SpeedMultiplier(0.f), m_IsTesting(false) { ENSURE(g_Game); } @@ -194,14 +195,6 @@ void AtlasViewGame::Update(float realFrameLength) { // Update unit interpolation g_Game->Interpolate(0.0, realFrameLength); - - // Update particles even when the game is paused, so people can see - // what they look like (i.e., use real time to simulate them). - // (TODO: maybe it'd be nice if this only applied in - // the not-testing-game editor state, not the testing-game-but-currently-paused - // state. Or maybe display a static snapshot of the particles (at some time - // later than 0 so they're actually visible) instead of animation, or something.) - g_Renderer.GetParticleManager().Interpolate(realFrameLength); } else { @@ -355,6 +348,15 @@ void AtlasViewGame::SetSpeedMultiplier(float speed) m_SpeedMultiplier = speed; } +void AtlasViewGame::SetTesting(bool testing) +{ + m_IsTesting = testing; + // If we're testing, particles should freeze on pause (like in-game), otherwise they keep going + CmpPtr cmpParticleManager(*GetSimulation2(), SYSTEM_ENTITY); + if (cmpParticleManager) + cmpParticleManager->SetUseSimTime(m_IsTesting); +} + void AtlasViewGame::SaveState(const std::wstring& label) { delete m_SavedStates[label]; // in case it already exists diff --git a/source/tools/atlas/GameInterface/View.h b/source/tools/atlas/GameInterface/View.h index 509013d8f7..57a9dc36ff 100644 --- a/source/tools/atlas/GameInterface/View.h +++ b/source/tools/atlas/GameInterface/View.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2013 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -94,6 +94,7 @@ public: virtual void SetParam(const std::wstring& name, const std::wstring& value); void SetSpeedMultiplier(float speedMultiplier); + void SetTesting(bool testing); void SaveState(const std::wstring& label); void RestoreState(const std::wstring& label); std::wstring DumpState(bool binary); @@ -101,6 +102,7 @@ public: private: float m_SpeedMultiplier; + bool m_IsTesting; std::map m_SavedStates; std::string m_DisplayPassability;