diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-04-14 16:28:08 +0200 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2019-04-15 22:52:50 +0100 |
commit | 4e85ccf3c049cb508873bb8320f770c328e76513 (patch) | |
tree | 9e1e144e2f77f5c31a3bd32f19158e8db4e0b2b2 /src/saveload/map_sl.cpp | |
parent | 79343762a4ec02cc78efcec4b38b8ffda4910772 (diff) | |
download | openttd-4e85ccf3c049cb508873bb8320f770c328e76513.tar.xz |
Codechange: Replace SmallStackSafeStackAlloc with std::array.
The only port that ever used it to make heap allocations instead of stack ones was the NDS port, which got thrown out some time ago.
Diffstat (limited to 'src/saveload/map_sl.cpp')
-rw-r--r-- | src/saveload/map_sl.cpp | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/src/saveload/map_sl.cpp b/src/saveload/map_sl.cpp index 17a793a09..a857d5b15 100644 --- a/src/saveload/map_sl.cpp +++ b/src/saveload/map_sl.cpp @@ -13,6 +13,7 @@ #include "../map_func.h" #include "../core/bitmath_func.hpp" #include "../fios.h" +#include <array> #include "saveload.h" @@ -51,80 +52,80 @@ static const uint MAP_SL_BUF_SIZE = 4096; static void Load_MAPT() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type = buf[j]; } } static void Save_MAPT() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].type; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAPH() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].height = buf[j]; } } static void Save_MAPH() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].height; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAP1() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m1 = buf[j]; } } static void Save_MAP1() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m1; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAP2() { - SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf; + std::array<uint16, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, + SlArray(buf.data(), MAP_SL_BUF_SIZE, /* In those versions the m2 was 8 bits */ IsSavegameVersionBefore(SLV_5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16 ); @@ -134,94 +135,94 @@ static void Load_MAP2() static void Save_MAP2() { - SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf; + std::array<uint16, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size * sizeof(uint16)); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m2; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16); } } static void Load_MAP3() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m3 = buf[j]; } } static void Save_MAP3() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m3; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAP4() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m4 = buf[j]; } } static void Save_MAP4() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m4; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAP5() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m5 = buf[j]; } } static void Save_MAP5() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m5; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAP6() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); if (IsSavegameVersionBefore(SLV_42)) { for (TileIndex i = 0; i != size;) { /* 1024, otherwise we overflow on 64x64 maps! */ - SlArray(buf, 1024, SLE_UINT8); + SlArray(buf.data(), 1024, SLE_UINT8); for (uint j = 0; j != 1024; j++) { _me[i++].m6 = GB(buf[j], 0, 2); _me[i++].m6 = GB(buf[j], 2, 2); @@ -231,7 +232,7 @@ static void Load_MAP6() } } else { for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m6 = buf[j]; } } @@ -239,59 +240,59 @@ static void Load_MAP6() static void Save_MAP6() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m6; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAP7() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m7 = buf[j]; } } static void Save_MAP7() { - SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf; + std::array<byte, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m7; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8); } } static void Load_MAP8() { - SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf; + std::array<uint16, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); for (TileIndex i = 0; i != size;) { - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16); for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m8 = buf[j]; } } static void Save_MAP8() { - SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf; + std::array<uint16, MAP_SL_BUF_SIZE> buf; TileIndex size = MapSize(); SlSetLength(size * sizeof(uint16)); for (TileIndex i = 0; i != size;) { for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m8; - SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16); + SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16); } } |