1
0
forked from 0ad/0ad

Moves particle interpolation to its own simulation component.

Fixes inconsistency between Atlas and in-game particle rendering during
pauses.
Fixes some issues related to Atlas simulation test and map loading.

This was SVN commit r13184.
This commit is contained in:
historic_bruno 2013-02-22 23:20:59 +00:00
parent 9e1b4a4370
commit 92fdbb49b6
13 changed files with 191 additions and 30 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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)

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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 "<a:component type='system'/><empty/>";
}
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<const CMessageInterpolate&> (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)

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "ICmpParticleManager.h"
#include "simulation2/system/InterfaceScripted.h"
BEGIN_INTERFACE_WRAPPER(ParticleManager)
END_INTERFACE_WRAPPER(ParticleManager)

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -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"));

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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)

View File

@ -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
);
//////////////////////////////////////////////////////////////////////////

View File

@ -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<T,S> 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<ICmpParticleManager> 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

View File

@ -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<std::wstring, SimState*> m_SavedStates;
std::string m_DisplayPassability;