From 463944b143263456f6db1939090280b0e9a3dbcb Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Wed, 27 Sep 2017 14:52:06 +0200 Subject: [PATCH] fix code pattern mistakes and warnings --- src/engine/client/backend_sdl.cpp | 31 ++++++----- src/engine/client/graphics_threaded.cpp | 7 ++- src/engine/client/opengl_sl.cpp | 31 +++++++---- src/engine/client/opengl_sl_program.cpp | 3 +- src/engine/client/text.cpp | 5 +- src/game/client/components/maplayers.cpp | 65 +++++++++++++++--------- 6 files changed, 88 insertions(+), 54 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index ad853f2f5..4e3a44b2e 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -521,7 +521,8 @@ void CCommandProcessorFragment_OpenGL3_3::SetState(const CCommandBuffer::SState glBindTexture(GL_TEXTURE_2D, m_aTextures[State.m_Texture].m_Tex); glBindSampler(Slot, m_aTextures[State.m_Texture].m_Sampler); } - } else { + } else + { Slot = 0; glBindTexture(GL_TEXTURE_2D, m_aTextures[State.m_Texture].m_Tex); glBindSampler(Slot, m_aTextures[State.m_Texture].m_Sampler); @@ -547,7 +548,8 @@ void CCommandProcessorFragment_OpenGL3_3::SetState(const CCommandBuffer::SState m_TextureSlotBoundToUnit[Slot].m_LastWrapMode = State.m_WrapMode; } } - else { + else + { if(pProgram->m_LocIsTextured != -1) pProgram->SetUniform(pProgram->m_LocIsTextured, (int)0); } @@ -798,7 +800,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Shutdown(const SCommand_Shutdown * DestroyTexture(i); } - for(int i = 0; i < m_VisualObjects.size(); ++i) + for(size_t i = 0; i < m_VisualObjects.size(); ++i) { DestroyVisualObjects(i); } @@ -1073,7 +1075,8 @@ bool CCommandProcessorFragment_OpenGL3_3::RunCommand(const CCommandBuffer::SComm bool CCommandProcessorFragment_OpenGL3_3::IsAndUpdateTextureSlotBound(int IDX, int Slot) { if(m_TextureSlotBoundToUnit[IDX].m_TextureSlot == Slot) return true; - else { + else + { //the texture slot uses this index now m_TextureSlotBoundToUnit[IDX].m_TextureSlot = Slot; m_TextureSlotBoundToUnit[IDX].m_LastWrapMode = -1; @@ -1108,7 +1111,7 @@ void CCommandProcessorFragment_OpenGL3_3::AppendIndices(unsigned int NewIndicesC unsigned int AddCount = NewIndicesCount - m_CurrentIndicesInBuffer; unsigned int* Indices = new unsigned int[AddCount]; int Primq = (m_CurrentIndicesInBuffer/6) * 4; - for(int i = 0; i < AddCount; i+=6) + for(unsigned int i = 0; i < AddCount; i+=6) { Indices[i] = Primq; Indices[i+1] = Primq + 1; @@ -1142,7 +1145,7 @@ void CCommandProcessorFragment_OpenGL3_3::AppendIndices(unsigned int NewIndicesC void CCommandProcessorFragment_OpenGL3_3::Cmd_DestroyVertexArray(const CCommandBuffer::SCommand_DestroyVisual *pCommand) { int Index = pCommand->m_VisualObjectIDX; - if(Index >= m_VisualObjects.size()) + if((size_t)Index >= m_VisualObjects.size()) return; DestroyVisualObjects(Index); @@ -1152,7 +1155,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderBorderTile(const CCommandBuf { int Index = pCommand->m_VisualObjectIDX; //if space not there return - if(Index >= m_VisualObjects.size()) + if((size_t)Index >= m_VisualObjects.size()) return; SVisualObject& VisualObject = m_VisualObjects[Index]; @@ -1183,7 +1186,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderBorderTileLine(const CComman { int Index = pCommand->m_VisualObjectIDX; //if space not there return - if(Index >= m_VisualObjects.size()) + if((size_t)Index >= m_VisualObjects.size()) return; SVisualObject& VisualObject = m_VisualObjects[Index]; @@ -1211,7 +1214,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderVertexArray(const CCommandBu { int Index = pCommand->m_VisualObjectIDX; //if space not there return - if(Index >= m_VisualObjects.size()) + if((size_t)Index >= m_VisualObjects.size()) return; SVisualObject& VisualObject = m_VisualObjects[Index]; @@ -1249,7 +1252,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_CreateVertBuffer(const CCommandBuf { int Index = pCommand->m_VisualObjectIDX; //create necessary space - if(Index >= m_VisualObjects.size()) + if((size_t)Index >= m_VisualObjects.size()) { for(int i = m_VisualObjects.size(); i < Index + 1; ++i) { @@ -1274,7 +1277,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_AppendVertBuffer(const CCommandBuf int Index = pCommand->m_VisualObjectIDX; //if space not there return - if(Index >= m_VisualObjects.size()) + if((size_t)Index >= m_VisualObjects.size()) { return; } @@ -1302,7 +1305,7 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_CreateVertArray(const CCommandBuff { int Index = pCommand->m_VisualObjectIDX; //if space not there return - if(Index >= m_VisualObjects.size()) + if((size_t)Index >= m_VisualObjects.size()) return; if(pCommand->m_RequiredIndicesCount > m_CurrentIndicesInBuffer) @@ -1691,7 +1694,9 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt CmdBuffer.AddCommand(CmdOpenGL); RunBuffer(&CmdBuffer); WaitForIdle(); - } else { + } + else + { CCommandProcessorFragment_OpenGL::SCommand_Init CmdOpenGL; CmdOpenGL.m_pTextureMemoryUsage = &m_TextureMemoryUsage; CmdBuffer.AddCommand(CmdOpenGL); diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 765adaf1d..7492a1eec 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -565,7 +565,8 @@ void CGraphics_Threaded::QuadsSetRotation(float Angle) m_Rotation = Angle; } -inline void clampf(float& Value, float Min, float Max){ +inline void clampf(float& Value, float Min, float Max) +{ if(Value > Max) Value = Max; else if(Value < Min) Value = Min; } @@ -1023,7 +1024,9 @@ int CGraphics_Threaded::CreateVisualObjects(float* pVertices, unsigned char* pTe { index = m_VertexArrayIndices.size(); m_VertexArrayIndices.push_back(index); - } else { + } + else + { index = m_FirstFreeVertexArrayIndex; m_FirstFreeVertexArrayIndex = m_VertexArrayIndices[index]; m_VertexArrayIndices[index] = index; diff --git a/src/engine/client/opengl_sl.cpp b/src/engine/client/opengl_sl.cpp index a473a2eb9..199a57cc8 100644 --- a/src/engine/client/opengl_sl.cpp +++ b/src/engine/client/opengl_sl.cpp @@ -4,18 +4,20 @@ #include #include -bool CGLSL::LoadShader(const char* pFile, int Type) { +bool CGLSL::LoadShader(const char* pFile, int Type) +{ if (m_IsLoaded) return true; IOHANDLE f; f = io_open(pFile, IOFLAG_READ); std::vector Lines; - char buff[500]; - if (f) { + if (f) + { CLineReader LineReader; LineReader.Init(f); char* ReadLine = NULL; - while ((ReadLine = LineReader.Get())) { + while ((ReadLine = LineReader.Get())) + { Lines.push_back(ReadLine); Lines.back().append("\r\n"); } @@ -23,7 +25,8 @@ bool CGLSL::LoadShader(const char* pFile, int Type) { const char** ShaderCode = new const char*[Lines.size()]; - for (int i = 0; i < Lines.size(); ++i) { + for (size_t i = 0; i < Lines.size(); ++i) + { ShaderCode[i] = Lines[i].c_str(); } @@ -37,7 +40,8 @@ bool CGLSL::LoadShader(const char* pFile, int Type) { int CompilationStatus; glGetShaderiv(shader, GL_COMPILE_STATUS, &CompilationStatus); - if (CompilationStatus == GL_FALSE) { + if (CompilationStatus == GL_FALSE) + { char buff[3000]; GLint maxLength = 0; @@ -60,24 +64,29 @@ bool CGLSL::LoadShader(const char* pFile, int Type) { } -void CGLSL::DeleteShader() { +void CGLSL::DeleteShader() +{ if (!IsLoaded()) return; m_IsLoaded = false; glDeleteShader(m_ShaderID); } -bool CGLSL::IsLoaded() { +bool CGLSL::IsLoaded() +{ return m_IsLoaded; } -GLuint CGLSL::GetShaderID() { +GLuint CGLSL::GetShaderID() +{ return m_ShaderID; } -CGLSL::CGLSL(){ +CGLSL::CGLSL() +{ m_IsLoaded = false; } -CGLSL::~CGLSL(){ +CGLSL::~CGLSL() +{ DeleteShader(); } \ No newline at end of file diff --git a/src/engine/client/opengl_sl_program.cpp b/src/engine/client/opengl_sl_program.cpp index ab5a0e5c0..54ebc3b48 100644 --- a/src/engine/client/opengl_sl_program.cpp +++ b/src/engine/client/opengl_sl_program.cpp @@ -57,7 +57,8 @@ void CGLSLProgram::LinkProgram() DetachAllShaders(); } -void CGLSLProgram::DetachAllShaders(){ +void CGLSLProgram::DetachAllShaders() +{ GLuint aShaders[100]; GLsizei ReturnedCount = 0; while(1) diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index 697e91044..c529c63e1 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -772,7 +772,8 @@ public: MinSize = 8; FontSize = MinSize; - while(!FoundMaxFontSize){ + while(!FoundMaxFontSize) + { int WidthOfText = 0; while(pCurrent < pEnd) @@ -828,7 +829,7 @@ public: int MaxSize = (MaxWidth - WidthLastChars); if (MaxSize > 0) { - int SlotW = (MaxSize < pBitmap->width ? MaxSize : pBitmap->width); + int SlotW = ((unsigned int)MaxSize < pBitmap->width ? MaxSize : pBitmap->width); int SlotH = pBitmap->rows; int SlotSize = SlotW*SlotH; diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 9c335472a..3e0e5a0d0 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -335,11 +335,13 @@ bool CMapLayers::STileLayerVisuals::Init(unsigned int Width, unsigned int Height m_TilesOfLayer[i] = new CMapLayers::STileLayerVisuals::STileVisual[Width]; } - if(Width > 2) { + if(Width > 2) + { m_BorderTop = new CMapLayers::STileLayerVisuals::STileVisual[Width-2]; m_BorderBottom = new CMapLayers::STileLayerVisuals::STileVisual[Width-2]; } - if(Height > 2) { + if(Height > 2) + { m_BorderLeft = new CMapLayers::STileLayerVisuals::STileVisual[Height-2]; m_BorderRight = new CMapLayers::STileLayerVisuals::STileVisual[Height-2]; } @@ -348,7 +350,8 @@ bool CMapLayers::STileLayerVisuals::Init(unsigned int Width, unsigned int Height CMapLayers::STileLayerVisuals::~STileLayerVisuals() { - if(m_TilesOfLayer) { + if(m_TilesOfLayer) + { for(unsigned int i = 0; i < m_Height; ++i) { delete[] m_TilesOfLayer[i]; @@ -485,7 +488,7 @@ void CMapLayers::OnMapLoad() int DataIndex = 0; - int TileSize = 0; + unsigned int TileSize = 0; int OverlayCount = 0; if (IsFrontLayer) { @@ -830,17 +833,17 @@ void CMapLayers::RenderTileLayer(int LayerIndex, vec4* pColor, CMapItemLayerTile if(DrawLayer) { //create the indice buffers we want to draw -- reuse them - static std::vector IndexOffsets; - static std::vector DrawCounts; - static unsigned long long maxRes = (IndexOffsets.max_size() > DrawCounts.max_size() ? DrawCounts.max_size() : IndexOffsets.max_size()); + static std::vector s_IndexOffsets; + static std::vector s_DrawCounts; + static unsigned long long s_MaxRes = (s_IndexOffsets.max_size() > s_DrawCounts.max_size() ? s_DrawCounts.max_size() : s_IndexOffsets.max_size()); - IndexOffsets.clear(); - DrawCounts.clear(); + s_IndexOffsets.clear(); + s_DrawCounts.clear(); unsigned long long Reserve = absolute(Y1 - Y0) + 1; - if(Reserve > maxRes) Reserve = maxRes; - IndexOffsets.reserve(Reserve); - DrawCounts.reserve(Reserve); + if(Reserve > s_MaxRes) Reserve = s_MaxRes; + s_IndexOffsets.reserve(Reserve); + s_DrawCounts.reserve(Reserve); for(int y = Y0; y <= Y1; ++y) { @@ -850,9 +853,10 @@ void CMapLayers::RenderTileLayer(int LayerIndex, vec4* pColor, CMapItemLayerTile unsigned int NumVertices = (Visuals.m_TilesOfLayer[y][X1].m_TilesHandledCount - Visuals.m_TilesOfLayer[y][X0].m_TilesHandledCount) * 6lu + (Visuals.m_TilesOfLayer[y][X1].m_Draw ? 6lu : 0lu); - if(NumVertices) { - IndexOffsets.push_back(Visuals.m_TilesOfLayer[y][X0].m_IndexBufferByteOffset); - DrawCounts.push_back(NumVertices); + if(NumVertices) + { + s_IndexOffsets.push_back(Visuals.m_TilesOfLayer[y][X0].m_IndexBufferByteOffset); + s_DrawCounts.push_back(NumVertices); } } @@ -861,9 +865,10 @@ void CMapLayers::RenderTileLayer(int LayerIndex, vec4* pColor, CMapItemLayerTile pColor->z *= b; pColor->w *= a; - int DrawCount = IndexOffsets.size(); - if(DrawCount != 0) { - Graphics()->DrawVisualObject(Visuals.m_VisualObjectsIndex, (float*)pColor, &IndexOffsets[0], &DrawCounts[0], DrawCount); + int DrawCount = s_IndexOffsets.size(); + if(DrawCount != 0) + { + Graphics()->DrawVisualObject(Visuals.m_VisualObjectsIndex, (float*)pColor, &s_IndexOffsets[0], &s_DrawCounts[0], DrawCount); } } if(DrawBorder) DrawTileBorder(LayerIndex, pColor, pTileLayer, pGroup, BorderX0, BorderY0, BorderX1, BorderY1); @@ -1150,7 +1155,7 @@ int CMapLayers::TileLayersOfGroup(CMapItemGroup* pGroup) { CMapItemLayerTilemap *pTMap = (CMapItemLayerTilemap *)pLayer; int DataIndex = 0; - int TileSize = 0; + unsigned int TileSize = 0; int TileLayerAndOverlayCount = 0; if (IsFrontLayer) { @@ -1330,7 +1335,7 @@ void CMapLayers::OnRender() { CMapItemLayerTilemap *pTMap = (CMapItemLayerTilemap *)pLayer; int DataIndex = 0; - int TileSize = 0; + unsigned int TileSize = 0; int TileLayerAndOverlayCount = 0; if (IsFrontLayer) { @@ -1491,7 +1496,9 @@ void CMapLayers::OnRender() Graphics()->BlendNormal(); RenderTools()->RenderTilemap(pFrontTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT, EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset); - } else { + } + else + { Graphics()->BlendNormal(); RenderTileLayer(TileLayerCounter-1, &Color, pTMap, pGroup); } @@ -1515,7 +1522,9 @@ void CMapLayers::OnRender() Graphics()->BlendNormal(); RenderTools()->RenderSwitchmap(pSwitchTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT); RenderTools()->RenderSwitchOverlay(pSwitchTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, g_Config.m_ClOverlayEntities/100.0f); - } else { + } + else + { Graphics()->BlendNormal(); RenderTileLayer(TileLayerCounter-3, &Color, pTMap, pGroup); if(g_Config.m_ClTextEntities) @@ -1546,7 +1555,9 @@ void CMapLayers::OnRender() Graphics()->BlendNormal(); RenderTools()->RenderTelemap(pTeleTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT); RenderTools()->RenderTeleOverlay(pTeleTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, g_Config.m_ClOverlayEntities/100.0f); - } else { + } + else + { Graphics()->BlendNormal(); RenderTileLayer(TileLayerCounter-2, &Color, pTMap, pGroup); if(g_Config.m_ClTextEntities) @@ -1575,7 +1586,9 @@ void CMapLayers::OnRender() Graphics()->BlendNormal(); RenderTools()->RenderSpeedupmap(pSpeedupTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT); RenderTools()->RenderSpeedupOverlay(pSpeedupTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, g_Config.m_ClOverlayEntities/100.0f); - } else { + } + else + { Graphics()->BlendNormal(); // draw arrow Graphics()->TextureSet(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_Id); @@ -1608,7 +1621,9 @@ void CMapLayers::OnRender() Graphics()->BlendNormal(); RenderTools()->RenderTunemap(pTuneTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT); //RenderTools()->RenderTuneOverlay(pTuneTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, g_Config.m_ClOverlayEntities/100.0f); - } else { + } + else + { Graphics()->BlendNormal(); RenderTileLayer(TileLayerCounter-1, &Color, pTMap, pGroup); }