From 46c95f2c7be6a3f968a277c21a2ed2a7fc4869e6 Mon Sep 17 00:00:00 2001 From: staphen Date: Sat, 17 May 2025 17:46:04 -0400 Subject: [PATCH] Use range-based for loops --- Source/msg.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/msg.cpp b/Source/msg.cpp index c1dd2accf..ba9a0a4b4 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -699,18 +699,18 @@ std::byte *DeltaExportJunk(std::byte *dst) const std::byte *DeltaImportJunk(const std::byte *src, const std::byte *end) { - for (int i = 0; i < MAXPORTAL; i++) { + for (DPortal &portal : sgJunk.portal) { if (src >= end) return nullptr; if (*src == std::byte { 0xFF }) { - memset(&sgJunk.portal[i], 0xFF, sizeof(DPortal)); + memset(&portal, 0xFF, sizeof(DPortal)); src++; } else { if (src + sizeof(DPortal) > end) return nullptr; - memcpy(&sgJunk.portal[i], src, sizeof(DPortal)); - if (!IsPortalDeltaValid(sgJunk.portal[i])) - memset(&sgJunk.portal[i], 0xFF, sizeof(DPortal)); + memcpy(&portal, src, sizeof(DPortal)); + if (!IsPortalDeltaValid(portal)) + memset(&portal, 0xFF, sizeof(DPortal)); src += sizeof(DPortal); } } @@ -2858,15 +2858,15 @@ void DeltaLoadLevel() } } - for (int i = 0; i < MAXITEMS; i++) { - if (deltaLevel.item[i].bCmd == CMD_INVALID) + for (const TCmdPItem &deltaItem : deltaLevel.item) { + if (deltaItem.bCmd == CMD_INVALID) continue; - if (deltaLevel.item[i].bCmd == TCmdPItem::PickedUpItem) { + if (deltaItem.bCmd == TCmdPItem::PickedUpItem) { int activeItemIndex = FindGetItem( - SDL_SwapLE32(deltaLevel.item[i].def.dwSeed), - static_cast<_item_indexes>(SDL_SwapLE16(deltaLevel.item[i].def.wIndx)), - SDL_SwapLE16(deltaLevel.item[i].def.wCI)); + SDL_SwapLE32(deltaItem.def.dwSeed), + static_cast<_item_indexes>(SDL_SwapLE16(deltaItem.def.wIndx)), + SDL_SwapLE16(deltaItem.def.wCI)); if (activeItemIndex != -1) { const auto &position = Items[ActiveItems[activeItemIndex]].position; if (dItem[position.x][position.y] == ActiveItems[activeItemIndex] + 1) @@ -2874,13 +2874,13 @@ void DeltaLoadLevel() DeleteItem(activeItemIndex); } } - if (deltaLevel.item[i].bCmd == TCmdPItem::DroppedItem) { + if (deltaItem.bCmd == TCmdPItem::DroppedItem) { int ii = AllocateItem(); auto &item = Items[ii]; - RecreateItem(*MyPlayer, deltaLevel.item[i], item); + RecreateItem(*MyPlayer, deltaItem, item); - int x = deltaLevel.item[i].x; - int y = deltaLevel.item[i].y; + int x = deltaItem.x; + int y = deltaItem.y; item.position = GetItemPosition({ x, y }); dItem[item.position.x][item.position.y] = static_cast(ii + 1); RespawnItem(Items[ii], false);