From 01ae5c6c708d126381ce35a8d630910b2253938d Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 22 Aug 2021 21:30:53 -0700 Subject: [PATCH] Allow custom levels to use 2 billion tile numbers once again Ever since tilesheets got expanded, custom levels could use as many tiles as they wanted, as long as it fit under the 32-bit signed integer limit. Until 6c85fae339f83f032230eafaf8ee7742f03dbbac happened and they were reduced to 32,767 tiles. So I'm being generous again and changing the type of the contents array (in mapclass and editorclass) back to int. This won't affect the existing tilemaps of the main game, they'll still stay short arrays. But it means level makers can use 2 billion tiles once again. --- desktop_version/src/Map.cpp | 23 ++++++++++++++++------- desktop_version/src/Map.h | 2 +- desktop_version/src/editor.cpp | 4 ++-- desktop_version/src/editor.h | 4 ++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 23357046..385cbc64 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -1138,6 +1138,15 @@ std::string mapclass::currentarea(int t) return "???"; } +static void copy_short_to_int(int* dest, const short* src, const size_t size) +{ + size_t i; + for (i = 0; i < size; ++i) + { + dest[i] = src[i]; + } +} + void mapclass::loadlevel(int rx, int ry) { int t; @@ -1289,7 +1298,7 @@ void mapclass::loadlevel(int rx, int ry) tileset = 1; extrarow = 1; const short* tmap = otherlevel.loadlevel(rx, ry); - SDL_memcpy(contents, tmap, sizeof(contents)); + copy_short_to_int(contents, tmap, SDL_arraysize(contents)); roomname = otherlevel.roomname; hiddenname = otherlevel.hiddenname; tileset = otherlevel.roomtileset; @@ -1298,7 +1307,7 @@ void mapclass::loadlevel(int rx, int ry) case 2: //The Lab { const short* tmap = lablevel.loadlevel(rx, ry); - SDL_memcpy(contents, tmap, sizeof(contents)); + copy_short_to_int(contents, tmap, SDL_arraysize(contents)); roomname = lablevel.roomname; tileset = 1; background = 2; @@ -1345,7 +1354,7 @@ void mapclass::loadlevel(int rx, int ry) case 4: //The Warpzone { const short* tmap = warplevel.loadlevel(rx, ry); - SDL_memcpy(contents, tmap, sizeof(contents)); + copy_short_to_int(contents, tmap, SDL_arraysize(contents)); roomname = warplevel.roomname; tileset = 1; background = 3; @@ -1363,7 +1372,7 @@ void mapclass::loadlevel(int rx, int ry) case 5: //Space station { const short* tmap = spacestation2.loadlevel(rx, ry); - SDL_memcpy(contents, tmap, sizeof(contents)); + copy_short_to_int(contents, tmap, SDL_arraysize(contents)); roomname = spacestation2.roomname; tileset = 0; break; @@ -1371,7 +1380,7 @@ void mapclass::loadlevel(int rx, int ry) case 6: //final level { const short* tmap = finallevel.loadlevel(rx, ry); - SDL_memcpy(contents, tmap, sizeof(contents)); + copy_short_to_int(contents, tmap, SDL_arraysize(contents)); roomname = finallevel.roomname; tileset = 1; background = 3; @@ -1530,7 +1539,7 @@ void mapclass::loadlevel(int rx, int ry) case 11: //Tower Hallways //Content is held in final level routine { const short* tmap = finallevel.loadlevel(rx, ry); - SDL_memcpy(contents, tmap, sizeof(contents)); + copy_short_to_int(contents, tmap, SDL_arraysize(contents)); roomname = finallevel.roomname; tileset = 2; if (rx == 108) @@ -1616,7 +1625,7 @@ void mapclass::loadlevel(int rx, int ry) roomname = room->roomname; extrarow = 1; - const short* tmap = ed.loadlevel(rx, ry); + const int* tmap = ed.loadlevel(rx, ry); SDL_memcpy(contents, tmap, sizeof(contents)); diff --git a/desktop_version/src/Map.h b/desktop_version/src/Map.h index cf7814d5..cdc9ecdd 100644 --- a/desktop_version/src/Map.h +++ b/desktop_version/src/Map.h @@ -91,7 +91,7 @@ public: int roomdeaths[20 * 20]; int roomdeathsfinal[20 * 20]; static const int areamap[20 * 20]; - short contents[40 * 30]; + int contents[40 * 30]; bool explored[20 * 20]; int vmult[30]; diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 9aeeddcc..2b14eddd 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -539,7 +539,7 @@ void editorclass::getlin(const enum textmode mode, const std::string& prompt, st oldenttext = key.keybuffer; } -const short* editorclass::loadlevel( int rxi, int ryi ) +const int* editorclass::loadlevel( int rxi, int ryi ) { //Set up our buffer array to be picked up by mapclass rxi -= 100; @@ -549,7 +549,7 @@ const short* editorclass::loadlevel( int rxi, int ryi ) if(rxi>=mapwidth)rxi-=mapwidth; if(ryi>=mapheight)ryi-=mapheight; - static short result[1200]; + static int result[1200]; for (int j = 0; j < 30; j++) { diff --git a/desktop_version/src/editor.h b/desktop_version/src/editor.h index ac3eecd3..8de6c189 100644 --- a/desktop_version/src/editor.h +++ b/desktop_version/src/editor.h @@ -132,7 +132,7 @@ class editorclass{ void reset(void); void getlin(const enum textmode mode, const std::string& prompt, std::string* ptr); - const short* loadlevel(int rxi, int ryi); + const int* loadlevel(int rxi, int ryi); int gettileidx( const int rx, @@ -217,7 +217,7 @@ class editorclass{ std::vector getLevelDirFileNames( ); static const int maxwidth = 20, maxheight = 20; //Special; the physical max the engine allows static const int numrooms = maxwidth * maxheight; - short contents[40 * 30 * numrooms]; + int contents[40 * 30 * numrooms]; int vmult[30 * maxheight]; int numtrinkets(void); int numcrewmates(void);