Refactor some references to CRobotMain from CEngine

dev-time-step
krzys-h 2016-03-26 18:55:39 +01:00
parent 640c0297ef
commit 6585ee9ae8
7 changed files with 35 additions and 34 deletions

View File

@ -822,7 +822,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig)
m_device->ConfigChanged(m_deviceConfig); m_device->ConfigChanged(m_deviceConfig);
m_engine->ResetAfterVideoConfigChanged(); m_eventQueue->AddEvent(Event(EVENT_RESOLUTION_CHANGED));
return true; return true;
} }

View File

@ -68,6 +68,8 @@ void InitializeEventTypeTexts()
EVENT_TYPE_TEXT[EVENT_UPDINTERFACE] = "EVENT_UPDINTERFACE"; EVENT_TYPE_TEXT[EVENT_UPDINTERFACE] = "EVENT_UPDINTERFACE";
EVENT_TYPE_TEXT[EVENT_RESOLUTION_CHANGED]= "EVENT_RESOLUTION_CHANGED";
EVENT_TYPE_TEXT[EVENT_RELOAD_TEXTURES] = "EVENT_RELOAD_TEXTURES";
EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN"; EVENT_TYPE_TEXT[EVENT_WIN] = "EVENT_WIN";
EVENT_TYPE_TEXT[EVENT_LOST] = "EVENT_LOST"; EVENT_TYPE_TEXT[EVENT_LOST] = "EVENT_LOST";

View File

@ -95,6 +95,10 @@ enum EventType
//! Event sent on user quit request //! Event sent on user quit request
EVENT_QUIT = 20, EVENT_QUIT = 20,
EVENT_UPDINTERFACE = 21, EVENT_UPDINTERFACE = 21,
//! Event sent on resolution change
EVENT_RESOLUTION_CHANGED = 22,
//! Event sent when textures have to be reloaded
EVENT_RELOAD_TEXTURES = 23,
EVENT_WIN = 30, EVENT_WIN = 30,
EVENT_LOST = 31, EVENT_LOST = 31,

View File

@ -359,8 +359,6 @@ void CEngine::ResetAfterVideoConfigChanged()
m_size = m_app->GetVideoConfig().size; m_size = m_app->GetVideoConfig().size;
m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast<float>(m_size.x) / static_cast<float>(m_size.y))); m_mouseSize = Math::Point(0.04f, 0.04f * (static_cast<float>(m_size.x) / static_cast<float>(m_size.y)));
CRobotMain::GetInstancePointer()->ResetAfterVideoConfigChanged(); //TODO: Remove cross-reference to CRobotMain
// Update the camera projection matrix for new aspect ratio // Update the camera projection matrix for new aspect ratio
SetFocus(m_focus); SetFocus(m_focus);
@ -373,13 +371,18 @@ void CEngine::ReloadAllTextures()
FlushTextureCache(); FlushTextureCache();
m_text->FlushCache(); m_text->FlushCache();
CRobotMain::GetInstancePointer()->ReloadAllTextures(); //TODO: Remove cross-reference to CRobotMain m_app->GetEventQueue()->AddEvent(Event(EVENT_RELOAD_TEXTURES));
UpdateGroundSpotTextures(); UpdateGroundSpotTextures();
LoadAllTextures(); LoadAllTextures();
} }
bool CEngine::ProcessEvent(const Event &event) bool CEngine::ProcessEvent(const Event &event)
{ {
if (event.type == EVENT_RESOLUTION_CHANGED)
{
ResetAfterVideoConfigChanged();
}
if (event.type == EVENT_KEY_DOWN) if (event.type == EVENT_KEY_DOWN)
{ {
auto data = event.GetData<KeyEventData>(); auto data = event.GetData<KeyEventData>();

View File

@ -655,9 +655,6 @@ public:
//! Frees all resources before exit //! Frees all resources before exit
void Destroy(); void Destroy();
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
void ResetAfterVideoConfigChanged();
//! Called once per frame, the call is the entry point for rendering //! Called once per frame, the call is the entry point for rendering
void Render(); void Render();
@ -1188,6 +1185,10 @@ public:
void AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres); void AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres);
protected: protected:
//! Resets some states and flushes textures after device was changed (e.g. resoulution changed)
/** Instead of calling this directly, send EVENT_RESOLUTION_CHANGED event **/
void ResetAfterVideoConfigChanged();
//! Prepares the interface for 3D scene //! Prepares the interface for 3D scene
void Draw3DScene(); void Draw3DScene();
//! Renders shadow map //! Renders shadow map
@ -1281,6 +1282,7 @@ protected:
static void WriteScreenShotThread(std::unique_ptr<WriteScreenShotData> data); static void WriteScreenShotThread(std::unique_ptr<WriteScreenShotData> data);
//! Reloads all textures //! Reloads all textures
/** This additionally sends EVENT_RELOAD_TEXTURES to reload all textures not maintained by CEngine **/
void ReloadAllTextures(); void ReloadAllTextures();
protected: protected:

View File

@ -303,30 +303,6 @@ CPauseManager* CRobotMain::GetPauseManager()
return m_pause.get(); return m_pause.get();
} }
void CRobotMain::ResetAfterVideoConfigChanged()
{
// Recreate the interface (needed if the aspect ratio changes)
// TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring.
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
CreateShortcuts();
}
void CRobotMain::ReloadAllTextures()
{
if (m_phase == PHASE_SETUPds ||
m_phase == PHASE_SETUPgs ||
m_phase == PHASE_SETUPps ||
m_phase == PHASE_SETUPcs ||
m_phase == PHASE_SETUPss ||
m_phase == PHASE_SIMUL ||
m_phase == PHASE_WIN ||
m_phase == PHASE_LOST)
{
ChangeColor();
UpdateMap();
}
}
std::string PhaseToString(Phase phase) std::string PhaseToString(Phase phase)
{ {
if (phase == PHASE_WELCOME1) return "PHASE_WELCOME1"; if (phase == PHASE_WELCOME1) return "PHASE_WELCOME1";
@ -693,6 +669,23 @@ bool CRobotMain::ProcessEvent(Event &event)
return EventFrame(event); return EventFrame(event);
} }
if (event.type == EVENT_RELOAD_TEXTURES)
{
if (IsPhaseWithWorld(m_phase))
{
ChangeColor();
UpdateMap();
}
}
if (event.type == EVENT_RESOLUTION_CHANGED)
{
// Recreate the interface (needed if the aspect ratio changes)
// TODO: This can sometimes cause unwanted side effects, like hidden windows reappearing. To be fixed during CEGUI refactoring.
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
CreateShortcuts();
}
if (event.type == EVENT_FOCUS_LOST) if (event.type == EVENT_FOCUS_LOST)
{ {
GetLogger()->Trace("Window unfocused\n"); GetLogger()->Trace("Window unfocused\n");

View File

@ -161,9 +161,6 @@ public:
Ui::CDisplayText* GetDisplayText(); Ui::CDisplayText* GetDisplayText();
CPauseManager* GetPauseManager(); CPauseManager* GetPauseManager();
void ResetAfterVideoConfigChanged();
void ReloadAllTextures();
void ChangePhase(Phase phase); void ChangePhase(Phase phase);
bool ProcessEvent(Event &event); bool ProcessEvent(Event &event);
Phase GetPhase(); Phase GetPhase();