Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/View.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// | ||||
AtlasViewGame::AtlasViewGame() | AtlasViewGame::AtlasViewGame() | ||||
: m_SpeedMultiplier(0.f), m_IsTesting(false), m_DrawMoveTool(false) | : m_SpeedMultiplier(0.f), m_IsTesting(false), m_DrawMoveTool(false) | ||||
{ | { | ||||
ENSURE(g_Game); | ENSURE(CGame::getGame()); | ||||
} | } | ||||
AtlasViewGame::~AtlasViewGame() | AtlasViewGame::~AtlasViewGame() | ||||
{ | { | ||||
for (const std::pair<std::wstring, SimState*>& p : m_SavedStates) | for (const std::pair<std::wstring, SimState*>& p : m_SavedStates) | ||||
delete p.second; | delete p.second; | ||||
} | } | ||||
CSimulation2* AtlasViewGame::GetSimulation2() | CSimulation2* AtlasViewGame::GetSimulation2() | ||||
{ | { | ||||
return g_Game->GetSimulation2(); | return CGame::getGame()->GetSimulation2(); | ||||
} | } | ||||
void AtlasViewGame::Update(float realFrameLength) | void AtlasViewGame::Update(float realFrameLength) | ||||
{ | { | ||||
const float actualFrameLength = realFrameLength * m_SpeedMultiplier; | const float actualFrameLength = realFrameLength * m_SpeedMultiplier; | ||||
// Clean up any entities destroyed during UI message processing | // Clean up any entities destroyed during UI message processing | ||||
g_Game->GetSimulation2()->FlushDestroyedEntities(); | CGame::getGame()->GetSimulation2()->FlushDestroyedEntities(); | ||||
if (m_SpeedMultiplier == 0.f) | if (m_SpeedMultiplier == 0.f) | ||||
{ | { | ||||
// Update unit interpolation | // Update unit interpolation | ||||
g_Game->Interpolate(0.0, realFrameLength); | CGame::getGame()->Interpolate(0.0, realFrameLength); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// Update the whole world | // Update the whole world | ||||
// (Tell the game update not to interpolate graphics - we'll do that | // (Tell the game update not to interpolate graphics - we'll do that | ||||
// ourselves) | // ourselves) | ||||
g_Game->Update(actualFrameLength, false); | CGame::getGame()->Update(actualFrameLength, false); | ||||
// Interpolate the graphics - we only want to do this once per visual frame, | // Interpolate the graphics - we only want to do this once per visual frame, | ||||
// not in every call to g_Game->Update | // not in every call to CGame::getGame()->Update | ||||
g_Game->Interpolate(actualFrameLength, realFrameLength); | CGame::getGame()->Interpolate(actualFrameLength, realFrameLength); | ||||
} | } | ||||
// Cinematic motion should be independent of simulation update, so we can | // Cinematic motion should be independent of simulation update, so we can | ||||
// preview the cinematics by themselves | // preview the cinematics by themselves | ||||
g_Game->GetView()->GetCinema()->Update(realFrameLength); | CGame::getGame()->GetView()->GetCinema()->Update(realFrameLength); | ||||
} | } | ||||
void AtlasViewGame::Render() | void AtlasViewGame::Render() | ||||
{ | { | ||||
SViewPort vp = { 0, 0, g_xres, g_yres }; | SViewPort vp = { 0, 0, g_xres, g_yres }; | ||||
CCamera& camera = GetCamera(); | CCamera& camera = GetCamera(); | ||||
camera.SetViewPort(vp); | camera.SetViewPort(vp); | ||||
camera.SetProjection(g_Game->GetView()->GetNear(), g_Game->GetView()->GetFar(), g_Game->GetView()->GetFOV()); | camera.SetProjection(CGame::getGame()->GetView()->GetNear(), CGame::getGame()->GetView()->GetFar(), CGame::getGame()->GetView()->GetFOV()); | ||||
camera.UpdateFrustum(); | camera.UpdateFrustum(); | ||||
::Render(); | ::Render(); | ||||
Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas); | Atlas_GLSwapBuffers((void*)g_AtlasGameLoop->glCanvas); | ||||
} | } | ||||
void AtlasViewGame::DrawCinemaPathTool() | void AtlasViewGame::DrawCinemaPathTool() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | void AtlasViewGame::SetParam(const std::wstring& name, const std::wstring& value) | ||||
else if (name == L"renderpath") | else if (name == L"renderpath") | ||||
{ | { | ||||
g_Renderer.SetRenderPath(g_Renderer.GetRenderPathByName(CStrW(value).ToUTF8())); | g_Renderer.SetRenderPath(g_Renderer.GetRenderPathByName(CStrW(value).ToUTF8())); | ||||
} | } | ||||
} | } | ||||
CCamera& AtlasViewGame::GetCamera() | CCamera& AtlasViewGame::GetCamera() | ||||
{ | { | ||||
return *g_Game->GetView()->GetCamera(); | return *CGame::getGame()->GetView()->GetCamera(); | ||||
} | } | ||||
bool AtlasViewGame::WantsHighFramerate() | bool AtlasViewGame::WantsHighFramerate() | ||||
{ | { | ||||
if (g_Game->GetView()->GetCinema()->IsPlaying()) | if (CGame::getGame()->GetView()->GetCinema()->IsPlaying()) | ||||
return true; | return true; | ||||
if (m_SpeedMultiplier != 0.f) | if (m_SpeedMultiplier != 0.f) | ||||
return true; | return true; | ||||
return false; | return false; | ||||
} | } | ||||
Show All 26 Lines | void AtlasViewGame::RestoreState(const std::wstring& label) | ||||
simState->Thaw(); | simState->Thaw(); | ||||
} | } | ||||
std::wstring AtlasViewGame::DumpState(bool binary) | std::wstring AtlasViewGame::DumpState(bool binary) | ||||
{ | { | ||||
std::stringstream stream; | std::stringstream stream; | ||||
if (binary) | if (binary) | ||||
{ | { | ||||
if (! g_Game->GetSimulation2()->SerializeState(stream)) | if (! CGame::getGame()->GetSimulation2()->SerializeState(stream)) | ||||
return L"(internal error)"; | return L"(internal error)"; | ||||
// We can't return raw binary data, because we want to handle it with wxJS which | // We can't return raw binary data, because we want to handle it with wxJS which | ||||
// doesn't like \0 bytes in strings, so return it as hex | // doesn't like \0 bytes in strings, so return it as hex | ||||
static const char digits[] = "0123456789abcdef"; | static const char digits[] = "0123456789abcdef"; | ||||
std::string str = stream.str(); | std::string str = stream.str(); | ||||
std::wstring ret; | std::wstring ret; | ||||
ret.reserve(str.length()*3); | ret.reserve(str.length()*3); | ||||
for (size_t i = 0; i < str.length(); ++i) | for (size_t i = 0; i < str.length(); ++i) | ||||
{ | { | ||||
ret += digits[(unsigned char)str[i] >> 4]; | ret += digits[(unsigned char)str[i] >> 4]; | ||||
ret += digits[(unsigned char)str[i] & 0x0f]; | ret += digits[(unsigned char)str[i] & 0x0f]; | ||||
ret += ' '; | ret += ' '; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (! g_Game->GetSimulation2()->DumpDebugState(stream)) | if (! CGame::getGame()->GetSimulation2()->DumpDebugState(stream)) | ||||
return L"(internal error)"; | return L"(internal error)"; | ||||
return wstring_from_utf8(stream.str()); | return wstring_from_utf8(stream.str()); | ||||
} | } | ||||
} | } | ||||
void AtlasViewGame::SetBandbox(bool visible, float x0, float y0, float x1, float y1) | void AtlasViewGame::SetBandbox(bool visible, float x0, float y0, float x1, float y1) | ||||
{ | { | ||||
m_BandboxArray.clear(); | m_BandboxArray.clear(); | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator