From 64505273a9dff09e59946e972fecab13da7031a6 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Mon, 6 May 2024 17:42:14 +0800 Subject: [PATCH] Remove redundant casts --- src/engine/client/backend/backend_base.cpp | 4 ++-- .../client/backend/vulkan/backend_vulkan.cpp | 16 ++++++++-------- src/engine/client/client.cpp | 4 ++-- src/engine/client/graphics_threaded.cpp | 2 +- src/engine/client/text.cpp | 12 ++++++------ src/game/client/components/menus_demo.cpp | 4 ++-- src/game/client/prediction/gameworld.cpp | 2 +- src/game/collision.cpp | 2 +- src/game/editor/editor.cpp | 10 +++++----- src/tools/map_replace_area.cpp | 2 +- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/engine/client/backend/backend_base.cpp b/src/engine/client/backend/backend_base.cpp index 451373ba0..37d3b3178 100644 --- a/src/engine/client/backend/backend_base.cpp +++ b/src/engine/client/backend/backend_base.cpp @@ -17,10 +17,10 @@ bool CCommandProcessorFragment_GLBase::Texture2DTo3D(uint8_t *pImageBuffer, int int DepthIndex = X + Y * SplitCountWidth; size_t TargetImageFullWidth = (size_t)Target3DImageWidth * PixelSize; - size_t TargetImageFullSize = (size_t)TargetImageFullWidth * Target3DImageHeight; + size_t TargetImageFullSize = TargetImageFullWidth * Target3DImageHeight; ptrdiff_t ImageOffset = (ptrdiff_t)(((size_t)Y * FullImageWidth * (size_t)Target3DImageHeight) + ((size_t)Y3D * FullImageWidth) + ((size_t)X * TargetImageFullWidth)); ptrdiff_t TargetImageOffset = (ptrdiff_t)(TargetImageFullSize * (size_t)DepthIndex + ((size_t)Y3D * TargetImageFullWidth)); - mem_copy(pTarget3DImageData + TargetImageOffset, pImageBuffer + (ptrdiff_t)(ImageOffset), TargetImageFullWidth); + mem_copy(pTarget3DImageData + TargetImageOffset, pImageBuffer + ImageOffset, TargetImageFullWidth); } } } diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp index edc9eda4d..36c6d171d 100644 --- a/src/engine/client/backend/vulkan/backend_vulkan.cpp +++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp @@ -218,7 +218,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase else { // check if there is enough space in this instance - if(bool(SMemoryHeapQueueElement::SMemoryHeapQueueElementFind{}(*m_Elements.begin(), std::make_pair(AllocSize, AllocAlignment)))) + if(SMemoryHeapQueueElement::SMemoryHeapQueueElementFind{}(*m_Elements.begin(), std::make_pair(AllocSize, AllocAlignment))) { return false; } @@ -1984,7 +1984,7 @@ protected: if(IsVerbose()) { - VerboseDeallocatedMemory(BufferMem.m_Size, (size_t)ImageIndex, BufferMem.m_UsageType); + VerboseDeallocatedMemory(BufferMem.m_Size, ImageIndex, BufferMem.m_UsageType); } BufferMem.m_Mem = VK_NULL_HANDLE; @@ -2081,7 +2081,7 @@ protected: m_pStagingMemoryUsage->store(m_pStagingMemoryUsage->load(std::memory_order_relaxed) - FreeedMemory, std::memory_order_relaxed); if(IsVerbose()) { - dbg_msg("vulkan", "deallocated chunks of memory with size: %" PRIzu " from all frames (staging buffer)", (size_t)FreeedMemory); + dbg_msg("vulkan", "deallocated chunks of memory with size: %" PRIzu " from all frames (staging buffer)", FreeedMemory); } } FreeedMemory = 0; @@ -2091,7 +2091,7 @@ protected: m_pBufferMemoryUsage->store(m_pBufferMemoryUsage->load(std::memory_order_relaxed) - FreeedMemory, std::memory_order_relaxed); if(IsVerbose()) { - dbg_msg("vulkan", "deallocated chunks of memory with size: %" PRIzu " from all frames (buffer)", (size_t)FreeedMemory); + dbg_msg("vulkan", "deallocated chunks of memory with size: %" PRIzu " from all frames (buffer)", FreeedMemory); } } FreeedMemory = 0; @@ -2102,7 +2102,7 @@ protected: m_pTextureMemoryUsage->store(m_pTextureMemoryUsage->load(std::memory_order_relaxed) - FreeedMemory, std::memory_order_relaxed); if(IsVerbose()) { - dbg_msg("vulkan", "deallocated chunks of memory with size: %" PRIzu " from all frames (texture)", (size_t)FreeedMemory); + dbg_msg("vulkan", "deallocated chunks of memory with size: %" PRIzu " from all frames (texture)", FreeedMemory); } } } @@ -3285,7 +3285,7 @@ protected: else { Scissor.offset = {0, 0}; - Scissor.extent = {(uint32_t)ScissorViewport.width, (uint32_t)ScissorViewport.height}; + Scissor.extent = {ScissorViewport.width, ScissorViewport.height}; } // if there is a dynamic viewport make sure the scissor data is scaled down to that @@ -3401,7 +3401,7 @@ protected: vkCmdPushConstants(CommandBuffer, PipeLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, VertexPushConstantSize, &VertexPushConstants); vkCmdPushConstants(CommandBuffer, PipeLayout, VK_SHADER_STAGE_FRAGMENT_BIT, sizeof(SUniformTileGPosBorder) + sizeof(SUniformTileGVertColorAlign), FragPushConstantSize, &FragPushConstants); - size_t DrawCount = (size_t)IndicesDrawNum; + size_t DrawCount = IndicesDrawNum; vkCmdBindIndexBuffer(CommandBuffer, ExecBuffer.m_IndexBuffer, 0, VK_INDEX_TYPE_UINT32); for(size_t i = 0; i < DrawCount; ++i) { @@ -6333,7 +6333,7 @@ public: } { - mem_copy(pMem + Offset, pData, (size_t)DataSize); + mem_copy(pMem + Offset, pData, DataSize); } NewBuffer = Buffer; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 4eefceb12..08c17e6c9 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -4419,7 +4419,7 @@ int main(int argc, const char **argv) delete pEngine; }); - IStorage *pStorage = CreateStorage(IStorage::STORAGETYPE_CLIENT, argc, (const char **)argv); + IStorage *pStorage = CreateStorage(IStorage::STORAGETYPE_CLIENT, argc, argv); pKernel->RegisterInterface(pStorage); pFutureAssertionLogger->Set(CreateAssertionLogger(pStorage, GAME_NAME)); @@ -4529,7 +4529,7 @@ int main(int argc, const char **argv) // parse the command line arguments pConsole->SetUnknownCommandCallback(UnknownArgumentCallback, pClient); - pConsole->ParseArguments(argc - 1, (const char **)&argv[1]); + pConsole->ParseArguments(argc - 1, &argv[1]); pConsole->SetUnknownCommandCallback(IConsole::EmptyUnknownCommandCallback, nullptr); if(pSteam->GetConnectAddress()) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 4d7ab860a..1e40d81a7 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -2022,7 +2022,7 @@ void *CGraphics_Threaded::AllocCommandBufferData(size_t AllocSize) if(pData == nullptr) { char aError[256]; - str_format(aError, sizeof(aError), "graphics: failed to allocate data (size %" PRIzu ") for command buffer", (size_t)AllocSize); + str_format(aError, sizeof(aError), "graphics: failed to allocate data (size %" PRIzu ") for command buffer", AllocSize); dbg_assert(false, aError); } } diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index c2872bd16..8c16fe289 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -1838,13 +1838,13 @@ public: } if(pCursor->m_CalculateSelectionMode == TEXT_CURSOR_SELECTION_MODE_SET) { - if((int)pCursor->m_GlyphCount == pCursor->m_SelectionStart) + if(pCursor->m_GlyphCount == pCursor->m_SelectionStart) { SelectionStarted = !SelectionStarted; SelectionStartChar = pCursor->m_GlyphCount; SelectionUsedPress = true; } - if((int)pCursor->m_GlyphCount == pCursor->m_SelectionEnd) + if(pCursor->m_GlyphCount == pCursor->m_SelectionEnd) { SelectionStarted = !SelectionStarted; SelectionEndChar = pCursor->m_GlyphCount; @@ -1854,7 +1854,7 @@ public: if(pCursor->m_CursorMode != TEXT_CURSOR_CURSOR_MODE_NONE) { - if((int)pCursor->m_GlyphCount == pCursor->m_CursorCharacter) + if(pCursor->m_GlyphCount == pCursor->m_CursorCharacter) { HasCursor = true; aCursorQuads[0] = IGraphics::CQuadItem(SelX - CursorOuterInnerDiff, DrawY, CursorOuterWidth, pCursor->m_AlignedFontSize); @@ -1936,13 +1936,13 @@ public: } else if(pCursor->m_CalculateSelectionMode == TEXT_CURSOR_SELECTION_MODE_SET) { - if((int)pCursor->m_GlyphCount == pCursor->m_SelectionStart) + if(pCursor->m_GlyphCount == pCursor->m_SelectionStart) { SelectionStarted = !SelectionStarted; SelectionStartChar = pCursor->m_GlyphCount; SelectionUsedPress = true; } - if((int)pCursor->m_GlyphCount == pCursor->m_SelectionEnd) + if(pCursor->m_GlyphCount == pCursor->m_SelectionEnd) { SelectionStarted = !SelectionStarted; SelectionEndChar = pCursor->m_GlyphCount; @@ -1957,7 +1957,7 @@ public: pCursor->m_CursorCharacter = pCursor->m_GlyphCount; } - if((int)pCursor->m_GlyphCount == pCursor->m_CursorCharacter) + if(pCursor->m_GlyphCount == pCursor->m_CursorCharacter) { HasCursor = true; aCursorQuads[0] = IGraphics::CQuadItem((LastSelX + LastSelWidth) - CursorOuterInnerDiff, DrawY, CursorOuterWidth, pCursor->m_AlignedFontSize); diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 2201be2c9..6aaae19b4 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -461,7 +461,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) else { static float s_PrevAmount = 0.0f; - float AmountSeek = clamp((Ui()->MouseX() - SeekBar.x - Rounding) / (float)(SeekBar.w - 2 * Rounding), 0.0f, 1.0f); + float AmountSeek = clamp((Ui()->MouseX() - SeekBar.x - Rounding) / (SeekBar.w - 2 * Rounding), 0.0f, 1.0f); if(Input()->ShiftIsPressed()) { @@ -494,7 +494,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView) if(Ui()->HotItem() == pId) { - const int HoveredTick = (int)(clamp((Ui()->MouseX() - SeekBar.x - Rounding) / (float)(SeekBar.w - 2 * Rounding), 0.0f, 1.0f) * TotalTicks); + const int HoveredTick = (int)(clamp((Ui()->MouseX() - SeekBar.x - Rounding) / SeekBar.w - 2 * Rounding, 0.0f, 1.0f) * TotalTicks); static char s_aHoveredTime[32]; str_time((int64_t)HoveredTick / Client()->GameTickSpeed() * 100, TIME_HOURS, s_aHoveredTime, sizeof(s_aHoveredTime)); GameClient()->m_Tooltips.DoToolTip(pId, &SeekBar, s_aHoveredTime); diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index ec5f6234a..cecffb9b8 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -640,7 +640,7 @@ CEntity *CGameWorld::FindMatch(int ObjId, int ObjType, const void *pObjData) case NETOBJTYPE_CHARACTER: { CCharacter *pEnt = (CCharacter *)GetEntity(ObjId, ENTTYPE_CHARACTER); - if(pEnt && CCharacter(this, ObjId, (CNetObj_Character *)pObjData).Match((CCharacter *)pEnt)) + if(pEnt && CCharacter(this, ObjId, (CNetObj_Character *)pObjData).Match(pEnt)) { return pEnt; } diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 0b796e8be..9fb53ce4f 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -1155,7 +1155,7 @@ int CCollision::IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 for(int i = 0, id = std::ceil(d); i < id; i++) { - float a = (int)i / d; + float a = i / d; vec2 Pos = mix(Pos0, Pos1, a); int Nx = clamp(round_to_int(Pos.x) / 32, 0, m_Width - 1); int Ny = clamp(round_to_int(Pos.y) / 32, 0, m_Height - 1); diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index a8471b5d0..767c8a6f7 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -986,7 +986,7 @@ void CEditor::DoAudioPreview(CUIRect View, const void *pPlayPauseButtonId, const } else { - const float AmountSeek = clamp((Ui()->MouseX() - SeekBar.x - Rounding) / (float)(SeekBar.w - 2 * Rounding), 0.0f, 1.0f); + const float AmountSeek = clamp((Ui()->MouseX() - SeekBar.x - Rounding) / (SeekBar.w - 2 * Rounding), 0.0f, 1.0f); Sound()->SetSampleCurrentTime(SampleId, AmountSeek); } } @@ -6491,7 +6491,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) if(Value / m_ZoomEnvelopeY.GetValue() * View.h < 40.0f) UnitsPerLineY = Value; } - int NumLinesY = m_ZoomEnvelopeY.GetValue() / static_cast(UnitsPerLineY) + 1; + int NumLinesY = m_ZoomEnvelopeY.GetValue() / UnitsPerLineY + 1; Ui()->ClipEnable(&View); Graphics()->TextureClear(); @@ -6536,7 +6536,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) if(Value.AsSeconds() / m_ZoomEnvelopeX.GetValue() * View.w < 160.0f) UnitsPerLineX = Value; } - int NumLinesX = m_ZoomEnvelopeX.GetValue() / static_cast(UnitsPerLineX.AsSeconds()) + 1; + int NumLinesX = m_ZoomEnvelopeX.GetValue() / UnitsPerLineX.AsSeconds() + 1; Ui()->ClipEnable(&View); Graphics()->TextureClear(); @@ -8390,8 +8390,8 @@ void CEditor::HandleCursorMovement() } // update positions for ui, but only update ui when rendering - m_MouseX = Ui()->Screen()->w * ((float)s_MouseX / Graphics()->WindowWidth()); - m_MouseY = Ui()->Screen()->h * ((float)s_MouseY / Graphics()->WindowHeight()); + m_MouseX = Ui()->Screen()->w * (s_MouseX / Graphics()->WindowWidth()); + m_MouseY = Ui()->Screen()->h * (s_MouseY / Graphics()->WindowHeight()); // fix correct world x and y std::shared_ptr pGroup = GetSelectedGroup(); diff --git a/src/tools/map_replace_area.cpp b/src/tools/map_replace_area.cpp index 7ad30c9ba..8dbe9dd9c 100644 --- a/src/tools/map_replace_area.cpp +++ b/src/tools/map_replace_area.cpp @@ -634,7 +634,7 @@ bool GetLineIntersection(const float aLine1[2], const float aLine2[2], float aIn std::min(aLine1[1], aLine2[1])}; if(aIntersection) - SetInexistent((float *)aIntersection, 2); + SetInexistent(aIntersection, 2); if(aBorders[0] - aBorders[1] > 0.01f) return false;