From d703eb71657713348c317b35e1490c02e67cb8b1 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 16 Aug 2015 00:06:27 +0200 Subject: [PATCH] Compile fixes for MSVC2013 --- CMakeLists.txt | 2 +- src/app/input.cpp | 2 +- src/common/event.h | 34 ++++++++++++++++++++++--- src/graphics/engine/engine.cpp | 10 ++++---- src/graphics/engine/engine.h | 2 +- src/graphics/engine/particle.h | 4 +-- src/graphics/engine/pyro.h | 2 +- src/graphics/engine/terrain.h | 4 +-- src/graphics/engine/water.h | 2 +- src/graphics/model/model_io_structs.h | 8 +++--- src/graphics/opengl/gl21device.h | 4 +-- src/level/robotmain.h | 4 +-- src/sound/oalsound/alsound.h | 20 +++++++++++++++ src/sound/oalsound/channel.h | 2 +- src/ui/controls/list.h | 2 +- src/ui/screen/screen_setup_graphics.cpp | 4 +-- 16 files changed, 77 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed74bcfe..96b99e68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") message(STATUS "Detected MSVC compiler") - set(NORMAL_CXX_FLAGS "/wd\"4244\" /wd\"4309\" /wd\"4800\" /wd\"4996\"") # disable some useless warnings + set(NORMAL_CXX_FLAGS "/wd\"4244\" /wd\"4309\" /wd\"4800\" /wd\"4996\" /wd\"4351\"") # disable some useless warnings set(RELEASE_CXX_FLAGS "") set(DEBUG_CXX_FLAGS "") set(TEST_CXX_FLAGS "") diff --git a/src/app/input.cpp b/src/app/input.cpp index e5b0f5b4..a0aadf41 100644 --- a/src/app/input.cpp +++ b/src/app/input.cpp @@ -37,7 +37,7 @@ template<> CInput* CSingleton::m_instance = nullptr; CInput::CInput() : m_keyPresses() { - m_keyTable = + m_keyTable = std::map { { INPUT_SLOT_LEFT, "left" }, { INPUT_SLOT_RIGHT, "right" }, diff --git a/src/common/event.h b/src/common/event.h index 5ebe5faf..aed4ac5f 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -570,7 +570,7 @@ struct KeyEventData : public EventData //! NOTE: applicable only to EVENT_KEY_DOWN events! unsigned int unicode = 0; //! Input binding slot for this key - InputSlot slot = {}; + InputSlot slot = INPUT_SLOT_LEFT; }; /** @@ -600,7 +600,7 @@ struct MouseButtonEventData : public EventData } //! The mouse button - MouseButton button = {}; + MouseButton button = MOUSE_BUTTON_LEFT; }; /** @@ -625,7 +625,7 @@ struct MouseWheelEventData : public EventData } //! Wheel direction - WheelDirection dir = {}; + WheelDirection dir = WHEEL_UP; }; /** @@ -713,6 +713,34 @@ struct Event customParam(0) {} + Event(const Event&) = delete; + Event& operator=(const Event&) = delete; + + // Workaround for MSVC2013 + Event(Event&& other) + : type(std::move(other.type)), + rTime(std::move(other.rTime)), + motionInput(std::move(other.motionInput)), + kmodState(std::move(other.kmodState)), + mousePos(std::move(other.mousePos)), + mouseButtonsState(std::move(other.mouseButtonsState)), + customParam(std::move(other.customParam)), + data(std::move(other.data)) + {} + + Event& operator=(Event&& other) + { + type = std::move(other.type); + rTime = std::move(other.rTime); + motionInput = std::move(other.motionInput); + kmodState = std::move(other.kmodState); + mousePos = std::move(other.mousePos); + mouseButtonsState = std::move(other.mouseButtonsState); + customParam = std::move(other.customParam); + data = std::move(other.data); + return *this; + } + //! Convenience function for getting appropriate EventData subclass template EventDataSubclass* GetData() diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 6b329af5..797f7980 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -4758,7 +4758,7 @@ void CEngine::DrawStats() std::stringstream str; - auto drawStatsLine = [&](const std::string& name = "", const std::string& value = "") + auto drawStatsLine = [&](const std::string& name, const std::string& value) { if (!name.empty()) { @@ -4799,13 +4799,13 @@ void CEngine::DrawStats() m_app->GetPerformanceCounterData(PCNT_RENDER_SHADOW_MAP); drawStatsCounter("Event processing", PCNT_EVENT_PROCESSING); - drawStatsLine(); + drawStatsLine("", ""); drawStatsCounter("Frame update", PCNT_UPDATE_ALL); drawStatsValue (" Engine update", engineUpdate); drawStatsCounter(" Particle update", PCNT_UPDATE_PARTICLE); drawStatsCounter(" Game update", PCNT_UPDATE_GAME); drawStatsValue( " Other update", otherUpdate); - drawStatsLine(); + drawStatsLine("", ""); drawStatsCounter("Frame render", PCNT_RENDER_ALL); drawStatsCounter(" Particle render", PCNT_RENDER_PARTICLE); drawStatsCounter(" Water render", PCNT_RENDER_WATER); @@ -4815,10 +4815,10 @@ void CEngine::DrawStats() drawStatsCounter(" Shadow map render", PCNT_RENDER_SHADOW_MAP); drawStatsValue( " Other render", otherRender); drawStatsCounter("Swap buffers & VSync", PCNT_SWAP_BUFFERS); - drawStatsLine(); + drawStatsLine("", ""); drawStatsLine( "Triangles", StrUtils::ToString(m_statisticTriangle)); drawStatsValue( "FPS", m_fps); - drawStatsLine(); + drawStatsLine("", ""); str.str(""); str << std::fixed << std::setprecision(2) << m_statisticPos.x << "; " << m_statisticPos.z; drawStatsLine( "Position", str.str()); diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 2e4ab688..d2d93892 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -395,7 +395,7 @@ struct EngineGroundMark //! Phase of life EngineGroundMarkPhase phase = ENG_GR_MARK_PHASE_NULL; //! Times for 3 life phases - float delay[3] = { 0.0f }; + float delay[3] = {}; //! Fixed time float fix = 0.0f; //! Position for marks diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 3da88d82..bc0d8db2 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -220,7 +220,7 @@ struct Track int posUsed = 0.0f; // number of positions in "pos" int head = 0; // head to write index Math::Vector pos[MAXTRACKLEN]; - float len[MAXTRACKLEN] = {0.0f}; + float len[MAXTRACKLEN] = {}; }; struct WheelTrace @@ -360,7 +360,7 @@ protected: int m_wheelTraceIndex = 0; WheelTrace m_wheelTrace[MAXWHEELTRACE]; int m_totalInterface[MAXPARTITYPE][SH_MAX] = {}; - bool m_frameUpdate[SH_MAX] = {false}; + bool m_frameUpdate[SH_MAX] = {}; int m_fogTotal = 0; int m_fog[MAXPARTIFOG] = {}; int m_uniqueStamp = 0; diff --git a/src/graphics/engine/pyro.h b/src/graphics/engine/pyro.h index e5ce6f71..dde3ffa3 100644 --- a/src/graphics/engine/pyro.h +++ b/src/graphics/engine/pyro.h @@ -174,7 +174,7 @@ protected: Math::Vector finalAngle; }; PyroBurnPart m_burnPart[10]; - int m_burnKeepPart[10] = {0}; + int m_burnKeepPart[10] = {}; float m_burnFall = 0.0f; float m_fallFloor = 0.0f; diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h index 1f4d02d1..dc4375af 100644 --- a/src/graphics/engine/terrain.h +++ b/src/graphics/engine/terrain.h @@ -336,7 +336,7 @@ protected: //! Terrain hardness (defines e.g. sound of walking) float hardness = 0.0f; //! IDs of neighbor materials: up, right, down, left - char mat[4] = {0}; + char mat[4] = {}; }; //! Terrain materials std::vector m_materials; @@ -350,7 +350,7 @@ protected: //! ID of material short id = 0; //! IDs of neighbor materials: up, right, down, left - char mat[4] = {0}; + char mat[4] = {}; }; diff --git a/src/graphics/engine/water.h b/src/graphics/engine/water.h index d485dd57..b1b8831d 100644 --- a/src/graphics/engine/water.h +++ b/src/graphics/engine/water.h @@ -131,7 +131,7 @@ protected: CParticle* m_particle = nullptr; CSoundInterface* m_sound = nullptr; - WaterType m_type[2] = {WATER_NULL, WATER_NULL}; + WaterType m_type[2] = {}; std::string m_fileName; //! Overall level float m_level = 0.0f; diff --git a/src/graphics/model/model_io_structs.h b/src/graphics/model/model_io_structs.h index a5366e69..fdf29b5d 100644 --- a/src/graphics/model/model_io_structs.h +++ b/src/graphics/model/model_io_structs.h @@ -170,7 +170,7 @@ struct OldModelHeader //! Total number of triangles int totalTriangles = 0; //! Reserved area - int reserved[10] = {0}; + int reserved[10] = {}; }; @@ -188,7 +188,7 @@ struct OldModelTriangleV1 Vertex p2; Vertex p3; Material material; - char texName[20] = {0}; + char texName[20] = {}; float min = 0; float max = 0; }; @@ -207,7 +207,7 @@ struct OldModelTriangleV2 Vertex p2; Vertex p3; Material material; - char texName[20] = {0}; + char texName[20] = {}; float min = 0.0f; float max = 0.0f; long state = 0; @@ -231,7 +231,7 @@ struct OldModelTriangleV3 VertexTex2 p2; VertexTex2 p3; Material material; - char texName[20] = {0}; + char texName[20] = {}; float min = 0.0f; float max = 0.0f; long state = 0; diff --git a/src/graphics/opengl/gl21device.h b/src/graphics/opengl/gl21device.h index 42d846f7..dca505f1 100644 --- a/src/graphics/opengl/gl21device.h +++ b/src/graphics/opengl/gl21device.h @@ -268,7 +268,7 @@ private: GLint uni_ShadowTexture = 0; //! true enables texture - GLint uni_TextureEnabled[3] = {0}; + GLint uni_TextureEnabled[3] = {}; // Alpha test parameters //! true enables alpha test @@ -289,7 +289,7 @@ private: //! true enables lighting GLint uni_LightingEnabled = 0; //! true enables light source - GLint uni_LightEnabled[8] = {0}; + GLint uni_LightEnabled[8] = {}; }; diff --git a/src/level/robotmain.h b/src/level/robotmain.h index df1b511d..021d8f32 100644 --- a/src/level/robotmain.h +++ b/src/level/robotmain.h @@ -117,7 +117,7 @@ struct NewScriptName { bool used = false; ObjectType type = OBJECT_NULL; - char name[40] = {0}; + char name[40] = {}; }; @@ -133,7 +133,7 @@ struct ShowLimit Math::Vector pos; float radius = 0.0f; int total = 0; - int parti[MAXSHOWPARTI] = {0}; + int parti[MAXSHOWPARTI] = {}; CObject* link = nullptr; float duration = 0.0f; float time = 0.0f; diff --git a/src/sound/oalsound/alsound.h b/src/sound/oalsound/alsound.h index fb68672b..bab7053c 100644 --- a/src/sound/oalsound/alsound.h +++ b/src/sound/oalsound/alsound.h @@ -40,6 +40,26 @@ struct OldMusic { + OldMusic() = default; + + OldMusic(const OldMusic&) = delete; + OldMusic& operator=(const OldMusic&) = delete; + + // Workaround for MSVC2013 + OldMusic(OldMusic&& other) + : music(std::move(other.music)), + fadeTime(std::move(other.fadeTime)), + currentTime(std::move(other.currentTime)) + {} + + OldMusic& operator=(OldMusic&& other) + { + music = std::move(other.music); + fadeTime = std::move(other.fadeTime); + currentTime = std::move(other.currentTime); + return *this; + } + std::unique_ptr music; float fadeTime = 0.0f; float currentTime = 0.0f; diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h index b501b95a..93e6b225 100644 --- a/src/sound/oalsound/channel.h +++ b/src/sound/oalsound/channel.h @@ -42,7 +42,7 @@ struct SoundOper float finalFrequency = 0.0f; float totalTime = 0.0f; float currentTime = 0.0f; - SoundNext nextOper = {}; + SoundNext nextOper = SOPER_CONTINUE; }; diff --git a/src/ui/controls/list.h b/src/ui/controls/list.h index d3d43460..680bfb07 100644 --- a/src/ui/controls/list.h +++ b/src/ui/controls/list.h @@ -118,7 +118,7 @@ protected: struct Item { - char text[100] = {0}; + char text[100] = {}; bool check = false; bool enable = true; }; diff --git a/src/ui/screen/screen_setup_graphics.cpp b/src/ui/screen/screen_setup_graphics.cpp index a99044dc..0da14188 100644 --- a/src/ui/screen/screen_setup_graphics.cpp +++ b/src/ui/screen/screen_setup_graphics.cpp @@ -447,8 +447,8 @@ void CScreenSetupGraphics::ChangeSetupButtons() pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_FILTER)); if ( pes != 0 ) { - value = pes->GetVisibleValue(); - m_engine->SetTextureFilterMode(static_cast(value)); + int valueIndex = pes->GetVisibleValueIndex(); + m_engine->SetTextureFilterMode(static_cast(valueIndex)); } pes = static_cast(pw->SearchControl(EVENT_INTERFACE_TEXTURE_MIPMAP));