From a80502bdc9360ce09c8926ef17bef4677469d53e Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 3 Jul 2020 02:54:31 -0700 Subject: [PATCH] Turn ed.contents/vmult into arrays They're always the same size, so there's no need for them to be vectors. Also made the number of elements in ed.level/kludgewarpdir controllable by maxwidth/maxheight. I removed editorclass::saveconvertor() because I didn't want to convert it to treat ed.contents like an array, because it's unused so I'd have no way of testing it, plus it's also unused so it doesn't matter. Might as well get rid of it. --- desktop_version/src/editor.cpp | 72 ++-------------------------------- desktop_version/src/editor.h | 12 +++--- 2 files changed, 10 insertions(+), 74 deletions(-) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 229a5d03..abd5b62a 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -50,21 +50,12 @@ edlevelclass::edlevelclass() editorclass::editorclass() { - maxwidth=20; - maxheight=20; - //We create a blank map - for (int j = 0; j < 30 * maxwidth; j++) - { - for (int i = 0; i < 40 * maxheight; i++) - { - contents.push_back(0); - } - } + SDL_memset(contents, 0, sizeof(contents)); - for (int i = 0; i < 30 * maxheight; i++) + for (size_t i = 0; i < SDL_arraysize(vmult); i++) { - vmult.push_back(int(i * 40 * maxwidth)); + vmult[i] = i * 40 * maxwidth; } reset(); @@ -1544,57 +1535,6 @@ void editorclass::findstartpoint() } } -void editorclass::saveconvertor() -{ - //In the case of resizing breaking a level, this function can fix it - maxwidth=20; - maxheight=20; - int oldwidth=10, oldheight=10; - - std::vector tempcontents; - for (int j = 0; j < 30 * oldwidth; j++) - { - for (int i = 0; i < 40 * oldheight; i++) - { - tempcontents.push_back(contents[i+(j*40*oldwidth)]); - } - } - - contents.clear(); - for (int j = 0; j < 30 * maxheight; j++) - { - for (int i = 0; i < 40 * maxwidth; i++) - { - contents.push_back(0); - } - } - - for (int j = 0; j < 30 * oldheight; j++) - { - for (int i = 0; i < 40 * oldwidth; i++) - { - contents[i+(j*40*oldwidth)]=tempcontents[i+(j*40*oldwidth)]; - } - } - - tempcontents.clear(); - - for (int i = 0; i < 30 * maxheight; i++) - { - vmult.push_back(int(i * 40 * maxwidth)); - } - - for (int j = 0; j < maxheight; j++) - { - for (int i = 0; i < maxwidth; i++) - { - level[i+(j*maxwidth)].tilecol=(i+j)%6; - } - } - contents.clear(); - -} - int editorclass::findtrinket(int t) { int ttrinket=0; @@ -1884,11 +1824,7 @@ bool editorclass::load(std::string& _path) if(TextString.length()) { std::vector values = split(TextString,','); - //contents.clear(); - for(size_t i = 0; i < contents.size(); i++) - { - contents[i] =0; - } + SDL_memset(contents, 0, sizeof(contents)); int x =0; int y =0; for(size_t i = 0; i < values.size(); i++) diff --git a/desktop_version/src/editor.h b/desktop_version/src/editor.h index dd2a4c83..bf12dcb4 100644 --- a/desktop_version/src/editor.h +++ b/desktop_version/src/editor.h @@ -128,7 +128,6 @@ class editorclass{ void getDirectoryData(); bool getLevelMetaData(std::string& filename, LevelMetaData& _data ); - void saveconvertor(); void reset(); void getlin(const enum textmode mode, const std::string& prompt, std::string* ptr); const int* loadlevel(int rxi, int ryi); @@ -189,12 +188,14 @@ class editorclass{ int getwarpbackground(int rx, int ry); std::vector getLevelDirFileNames( ); - std::vector contents; - std::vector vmult; + static const int maxwidth = 20, maxheight = 20; //Special; the physical max the engine allows + static const int numrooms = maxwidth * maxheight; + int contents[40 * 30 * numrooms]; + int vmult[30 * maxheight]; int numtrinkets(); int numcrewmates(); - edlevelclass level[400]; //Maxwidth*maxheight - int kludgewarpdir[400]; //Also maxwidth*maxheight + edlevelclass level[numrooms]; //Maxwidth*maxheight + int kludgewarpdir[numrooms]; //Also maxwidth*maxheight int notedelay; int oldnotedelay; @@ -236,7 +237,6 @@ class editorclass{ int levmusic; int mapwidth, mapheight; //Actual width and height of stage - int maxwidth, maxheight; //Special; the physical max the engine allows int version;