From ef6a2886e962d1ee550cb65b71838832ed68e75c Mon Sep 17 00:00:00 2001 From: AllyTally Date: Fri, 25 Nov 2022 16:39:35 -0400 Subject: [PATCH 01/19] Fix #892 --- desktop_version/src/Input.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index b1842ccd..1d3da34a 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -2379,6 +2379,10 @@ void gameinput(void) { //Do nothing if we're in a Time Trial but a fade animation is playing } + else if (map.custommode && !map.custommodeforreal) + { + // We're playtesting in the editor so don't do anything + } else { //Normal map screen, do transition later From 63b8c712649a5e486c7fe60aa0c0d635568a3ef8 Mon Sep 17 00:00:00 2001 From: fraZ0R <30442287+f-raZ0R@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:04:46 -0500 Subject: [PATCH 02/19] Actually fix #913 oops --- desktop_version/src/Script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 6a2cfc77..3e0ac4bf 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -3543,7 +3543,7 @@ void scriptclass::loadcustom(const std::string& t) break; } int ti=help.Int(words[1].c_str()); - int nti = ti>=0 && ti<=50 ? ti : 1; + int nti = ti>=0 ? ti : 1; for(int ti2=0; ti2=0 && ti<=50 ? ti : 1; + int nti = ti>=0 ? ti : 1; for(int ti2=0; ti2 Date: Wed, 30 Nov 2022 11:22:50 -0800 Subject: [PATCH 03/19] Add fraZ0R to the list of contributors fraZ0R's PR #915 was merged. --- desktop_version/CONTRIBUTORS.txt | 1 + desktop_version/src/Credits.h | 1 + 2 files changed, 2 insertions(+) diff --git a/desktop_version/CONTRIBUTORS.txt b/desktop_version/CONTRIBUTORS.txt index e61cc849..194d015d 100644 --- a/desktop_version/CONTRIBUTORS.txt +++ b/desktop_version/CONTRIBUTORS.txt @@ -14,6 +14,7 @@ Contributors * Elijah Stone (@moon-chilled) * Elliott Saltar (@eboyblue3) * Emmanuel Vadot (@evadot) +* fraZ0R (@f-raZ0R) * Fredrik Ljungdahl (@FredrIQ) * Jules de Sartiges (@strikersh) * Keith Stellyes (@keithstellyes) diff --git a/desktop_version/src/Credits.h b/desktop_version/src/Credits.h index 01884d95..f81631ac 100644 --- a/desktop_version/src/Credits.h +++ b/desktop_version/src/Credits.h @@ -96,6 +96,7 @@ static const char* githubfriends[] = { "Elijah Stone", "Elliott Saltar", "Emmanuel Vadot", + "fraZ0R", "Fredrik Ljungdahl", "Keith Stellyes", "KyoZM", From a5939a888af82c130e9914c4b3a8b041fb8a71d6 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Sun, 6 Nov 2022 20:51:07 -0400 Subject: [PATCH 04/19] deduplicate a lot of map code --- desktop_version/src/Render.cpp | 472 ++++++++++++++------------------- 1 file changed, 203 insertions(+), 269 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index b1c9e315..96c5029b 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2040,6 +2040,166 @@ static void draw_roomname_menu(void) * the same in Flip Mode. */ #define FLIP(y, h) (graphics.flipmode ? 220 - (y) - (h) : (y)) +void rendermap(void) +{ +#ifndef NO_CUSTOM_LEVELS + if (map.custommode) + { + //draw the map image + graphics.drawpixeltextbox(35 + map.custommmxoff, 16 + map.custommmyoff, map.custommmxsize + 10, map.custommmysize + 10, 65, 185, 207); + graphics.drawpartimage(graphics.minimap_mounted ? 1 : 12, 40 + map.custommmxoff, 21 + map.custommmyoff, map.custommmxsize, map.custommmysize); + return; + } +#endif /* NO_CUSTOM_LEVELS */ + + //draw the map image + graphics.drawpixeltextbox(35, 16, 250, 190, 65, 185, 207); + graphics.drawimage(1, 40, 21, false); +} + +void rendermapfog(void) +{ + int mapwidth = map.custommode ? map.customheight : 20; + int mapheight = map.custommode ? map.customheight : 20; + int mapzoom = map.custommode ? map.customzoom : 1; + int mapxoff = map.custommode ? map.custommmxoff : 0; + int mapyoff = map.custommode ? map.custommmyoff : 0; + + // Draw the fog of war + for (int j = 0; j < mapheight; j++) + { + for (int i = 0; i < mapwidth; i++) + { + if (!map.isexplored(i, j)) + { + // Draw the fog, depending on the custom zoom size + for (int x = 0; x < mapzoom; x++) + { + for (int y = 0; y < mapzoom; y++) + { + graphics.drawimage(2, mapxoff + 40 + (x * 12) + (i * (12 * mapzoom)), mapyoff + 21 + (y * 9) + (j * (9 * mapzoom)), false); + } + } + } + } + } +} + +void rendermaplegend(void) +{ + // Draw the map legend, aka teleports/targets/trinkets + + int zoom_offset_x; + int zoom_offset_y; + int zoom_mult = map.custommode ? map.customzoom : 1; + + switch (zoom_mult) + { + case 4: + zoom_offset_x = 60; + zoom_offset_y = 35; + break; + case 2: + zoom_offset_x = 48; + zoom_offset_y = 26; + break; + default: + zoom_offset_x = 43; + zoom_offset_y = 22; + break; + } + + int tile_offset = graphics.flipmode ? 3 : 0; + + for (size_t i = 0; i < map.teleporters.size(); i++) + { + if (map.showteleporters && map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) + { + graphics.drawtile(zoom_offset_x + (map.teleporters[i].x * 12 * zoom_mult), zoom_offset_y + (map.teleporters[i].y * 9 * zoom_mult), 1127 + tile_offset); + } + else if (map.showtargets && !map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) + { + graphics.drawtile(zoom_offset_x + (map.teleporters[i].x * 12 * zoom_mult), zoom_offset_y + (map.teleporters[i].y * 9 * zoom_mult), 1126 + tile_offset); + } + } + + if (map.showtrinkets) + { + for (size_t i = 0; i < map.shinytrinkets.size(); i++) + { + if (!obj.collect[i]) + { + graphics.drawtile(zoom_offset_x + (map.shinytrinkets[i].x * 12 * zoom_mult), zoom_offset_y + (map.shinytrinkets[i].y * 9 * zoom_mult), 1086 + tile_offset); + } + } + } +} + +void rendermapcursor(bool flashing) +{ + int mapwidth = map.custommode ? map.customheight : 20; + int mapheight = map.custommode ? map.customheight : 20; + int mapzoom = map.custommode ? map.customzoom : 1; + int mapxoff = map.custommode ? map.custommmxoff : 0; + int mapyoff = map.custommode ? map.custommmyoff : 0; + + if (!map.custommode && game.roomx == 109) + { + // Draw the tower specially + if (!flashing) + { + graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + 2, 12 - 4, 180 - 4, 16, 245 - (help.glow * 2), 245 - (help.glow * 2)); + } + else if (map.cursorstate == 1) + { + if (int(map.cursordelay / 4) % 2 == 0) + { + graphics.drawrect(40 + ((game.roomx - 100) * 12), 21, 12, 180, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + 2, 12 - 4, 180 - 4, 255, 255, 255); + } + if (map.cursordelay > 30) map.cursorstate = 2; + } + else if (map.cursorstate == 2 && (int(map.cursordelay / 15) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + 2, 12 - 4, 180 - 4, 16, 245 - (help.glow), 245 - (help.glow)); + } + return; + } + + if (mapzoom == 4) { + if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) { + graphics.drawrect(40 + ((game.roomx - 100) * 48) + 2 + mapxoff, 21 + ((game.roomy - 100) * 36) + 2 + mapyoff, 48 - 4, 36 - 4, 16, 245 - (help.glow), 245 - (help.glow)); + } + else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 48) + mapxoff, 21 + ((game.roomy - 100) * 36) + mapyoff, 48, 36, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 48) + 2 + mapxoff, 21 + ((game.roomy - 100) * 36) + 2 + mapyoff, 48 - 4, 36 - 4, 255, 255, 255); + } + } + else if (mapzoom == 2) { + if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 24) + 2 + mapxoff, 21 + ((game.roomy - 100) * 18) + 2 + mapyoff, 24 - 4, 18 - 4, 16, 245 - (help.glow), 245 - (help.glow)); + } + else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 24) + mapxoff, 21 + ((game.roomy - 100) * 18) + mapyoff, 24, 18, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 24) + 2 + mapxoff, 21 + ((game.roomy - 100) * 18) + 2 + mapyoff, 24 - 4, 18 - 4, 255, 255, 255); + } + } + else { + if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9) + 2 + mapyoff, 12 - 4, 9 - 4, 16, 245 - (help.glow), 245 - (help.glow)); + } + else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 12) + mapxoff, 21 + ((game.roomy - 100) * 9) + mapyoff, 12, 9, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9) + 2 + mapyoff, 12 - 4, 9 - 4, 255, 255, 255); + } + } +} + void maprender(void) { ClearSurface(graphics.backBuffer); @@ -2049,12 +2209,10 @@ void maprender(void) //Background color FillRect(graphics.backBuffer,0, 12, 320, 240, 10, 24, 26 ); - - //Menubar: graphics.drawtextbox( -10, 212, 43, 3, 65, 185, 207); - // Draw the selected page name at the bottom + // Draw the selected page name at the bottomtele // menupage 0 - 3 is the pause screen if (script.running && game.menupage == 3) { @@ -2108,11 +2266,11 @@ void maprender(void) switch(game.menupage) { case 0: + rendermap(); + if (map.finalmode || (map.custommode&&!map.customshowmm)) { - //draw the map image - graphics.drawpixeltextbox(35, 16, 250, 190, 65, 185, 207); - graphics.drawimage(1, 40, 21, false); + // Cover the whole map for (int j = 0; j < 20; j++) { for (int i = 0; i < 20; i++) @@ -2121,212 +2279,10 @@ void maprender(void) } } graphics.bprint(-1, 105, "NO SIGNAL", 245, 245, 245, true); - } -#ifndef NO_CUSTOM_LEVELS - else if(map.custommode) - { - //draw the map image - graphics.drawpixeltextbox(35+map.custommmxoff, 16+map.custommmyoff, map.custommmxsize+10, map.custommmysize+10, 65, 185, 207); - if (graphics.minimap_mounted) - { - graphics.drawpartimage(1, 40+map.custommmxoff, 21+map.custommmyoff, map.custommmxsize, map.custommmysize); - } - else - { - graphics.drawpartimage(12, 40+map.custommmxoff, 21+map.custommmyoff, map.custommmxsize,map.custommmysize); - } - - //Black out here - if(map.customzoom==4){ - for (int j = 0; j < map.customheight; j++){ - for (int i = 0; i < map.customwidth; i++){ - if(!map.isexplored(i, j)){ - //Draw the fog of war on the map - graphics.drawimage(2, map.custommmxoff+40 + (i * 48), map.custommmyoff+21 + (j * 36), false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48), map.custommmyoff+21 + (j * 36), false); - graphics.drawimage(2, map.custommmxoff+40 + (i * 48), map.custommmyoff+21 + 9 + (j * 36), false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48), map.custommmyoff+21 + 9+ (j * 36), false); - - graphics.drawimage(2, map.custommmxoff+40 + (i * 48) + 24, map.custommmyoff+21 + (j * 36), false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48) + 24, map.custommmyoff+21 + (j * 36), false); - graphics.drawimage(2, map.custommmxoff+40 + (i * 48) + 24, map.custommmyoff+ 21 + 9 + (j * 36), false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48) + 24, map.custommmyoff+21 + 9+ (j * 36), false); - - graphics.drawimage(2, map.custommmxoff+40 + (i * 48), map.custommmyoff+21 + (j * 36)+18, false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48), map.custommmyoff+21 + (j * 36)+18, false); - graphics.drawimage(2, map.custommmxoff+40 + (i * 48), map.custommmyoff+21 + 9 + (j * 36)+18, false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48), map.custommmyoff+21 + 9+ (j * 36)+18, false); - - graphics.drawimage(2, map.custommmxoff+40 + (i * 48) + 24, map.custommmyoff+21 + (j * 36)+18, false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48) + 24, map.custommmyoff+21 + (j * 36)+18, false); - graphics.drawimage(2, map.custommmxoff+40 + (i * 48) + 24, map.custommmyoff+21 + 9 + (j * 36)+18, false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 48) + 24, map.custommmyoff+21 + 9+ (j * 36)+18, false); - } - } - } - }else if(map.customzoom==2){ - for (int j = 0; j < map.customheight; j++){ - for (int i = 0; i < map.customwidth; i++){ - if(!map.isexplored(i, j)){ - //Draw the fog of war on the map - graphics.drawimage(2, map.custommmxoff+40 + (i * 24), map.custommmyoff+21 + (j * 18), false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 24), map.custommmyoff+21 + (j * 18), false); - graphics.drawimage(2, map.custommmxoff+40 + (i * 24), map.custommmyoff+21 + 9 + (j * 18), false); - graphics.drawimage(2, map.custommmxoff+40 + 12 + (i * 24), map.custommmyoff+21 + 9+ (j * 18), false); - } - } - } - }else{ - for (int j = 0; j < map.customheight; j++){ - for (int i = 0; i < map.customwidth; i++){ - if(!map.isexplored(i, j)){ - //Draw the fog of war on the map - graphics.drawimage(2, map.custommmxoff+40 + (i * 12), map.custommmyoff+21 + (j * 9), false); - } - } - } - } - - //normal size maps - if(map.customzoom==4){ - if(map.cursorstate==1){ - if (int(map.cursordelay / 4) % 2 == 0){ - graphics.drawrect(40 + ((game.roomx - 100) * 48) +map.custommmxoff, 21 + ((game.roomy - 100) * 36)+map.custommmyoff , 48 , 36 , 255,255,255); - graphics.drawrect(40 + ((game.roomx - 100) * 48) + 2+map.custommmxoff, 21 + ((game.roomy - 100) * 36) + 2+map.custommmyoff, 48 - 4, 36 - 4, 255,255,255); - } - }else if (map.cursorstate == 2){ - if (int(map.cursordelay / 15) % 2 == 0){ - graphics.drawrect(40 + ((game.roomx - 100) * 48) + 2+map.custommmxoff, 21 + ((game.roomy - 100) * 36) + 2+map.custommmyoff, 48 - 4, 36 - 4, 16, 245 - (help.glow), 245 - (help.glow)); - } - } - }else if(map.customzoom==2){ - if(map.cursorstate==1){ - if (int(map.cursordelay / 4) % 2 == 0){ - graphics.drawrect(40 + ((game.roomx - 100) * 24)+map.custommmxoff , 21 + ((game.roomy - 100) * 18)+map.custommmyoff , 24 , 18 , 255,255,255); - graphics.drawrect(40 + ((game.roomx - 100) * 24) + 2+map.custommmxoff, 21 + ((game.roomy - 100) * 18) + 2+map.custommmyoff, 24 - 4, 18 - 4, 255,255,255); - } - }else if (map.cursorstate == 2){ - if (int(map.cursordelay / 15) % 2 == 0){ - graphics.drawrect(40 + ((game.roomx - 100) * 24) + 2+map.custommmxoff, 21 + ((game.roomy - 100) * 18) + 2+map.custommmyoff, 24 - 4, 18 - 4, 16, 245 - (help.glow), 245 - (help.glow)); - } - } - }else{ - if(map.cursorstate==1){ - if (int(map.cursordelay / 4) % 2 == 0){ - graphics.drawrect(40 + ((game.roomx - 100) * 12)+map.custommmxoff , 21 + ((game.roomy - 100) * 9)+map.custommmyoff , 12 , 9 , 255,255,255); - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2+map.custommmxoff, 21 + ((game.roomy - 100) * 9) + 2+map.custommmyoff, 12 - 4, 9 - 4, 255,255,255); - } - }else if (map.cursorstate == 2){ - if (int(map.cursordelay / 15) % 2 == 0){ - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2+map.custommmxoff, 21 + ((game.roomy - 100) * 9) + 2+map.custommmyoff, 12 - 4, 9 - 4, 16, 245 - (help.glow), 245 - (help.glow)); - } - } - } - - if(map.showtrinkets){ - for(size_t i=0; i 30) map.cursorstate = 2; - } - else if (map.cursorstate == 2) - { - if (int(map.cursordelay / 15) % 2 == 0) - { - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2 , 21 + 2, 12 - 4, 180 - 4,16, 245 - (help.glow), 245 - (help.glow)); - } - } - } - else - { - if (map.cursorstate == 1) - { - if (int(map.cursordelay / 4) % 2 == 0) - { - graphics.drawrect(40 + ((game.roomx - 100) * 12) , 21 + ((game.roomy - 100) * 9) , 12 , 9 , 255,255,255); - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + ((game.roomy - 100) * 9) + 2, 12 - 4, 9 - 4, 255,255,255); - } - } - else if (map.cursorstate == 2) - { - if (int(map.cursordelay / 15) % 2 == 0) - { - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + ((game.roomy - 100) * 9) + 2, 12 - 4, 9 - 4, 16, 245 - (help.glow), 245 - (help.glow)); - } - } - } - - //draw legend details - for (size_t i = 0; i < map.teleporters.size(); i++) - { - if (map.showteleporters && map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) - { - int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); - if (graphics.flipmode) temp += 3; - graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp); - } - else if(map.showtargets && !map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) - { - int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); - if (graphics.flipmode) temp += 3; - graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp); - } - } - - if (map.showtrinkets) - { - for (size_t i = 0; i < map.shinytrinkets.size(); i++) - { - if (!obj.collect[i]) - { - int temp = 1086; - if (graphics.flipmode) temp += 3; - graphics.drawtile(40 + 3 + (map.shinytrinkets[i].x * 12), 22 + (map.shinytrinkets[i].y * 9), temp); - } - } - } + } else { + rendermapfog(); + rendermapcursor(true); + rendermaplegend(); } break; case 1: @@ -2736,31 +2692,17 @@ void teleporterrender(void) //Background color FillRect(graphics.backBuffer, 0, 12, 320, 240, 10, 24, 26); - //draw the map image - graphics.drawpixeltextbox(35, 16, 250, 190, 65, 185, 207); - graphics.drawimage(1, 40, 21, false); - //black out areas we can't see yet - for (int j = 0; j < 20; j++) - { - for (int i = 0; i < 20; i++) - { - if(!map.isexplored(i, j)) - { - graphics.drawimage(2, 40 + (i * 12), 21 + (j * 9), false); - } - } - } + rendermap(); + rendermapfog(); + rendermapcursor(false); - //draw the coordinates //current - if (game.roomx == 109) - { - //tower!instead of room y, scale map.ypos - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + 2, 12 - 4, 180 - 4, 16, 245 - (help.glow * 2), 245 - (help.glow * 2)); - } - else - { - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + ((game.roomy - 100) * 9) + 2, 12 - 4, 9 - 4, 16, 245 - (help.glow * 2), 245 - (help.glow * 2)); - } + // Draw a box around the currently selected teleporter + + int mapwidth = map.custommode ? map.customheight : 20; + int mapheight = map.custommode ? map.customheight : 20; + int mapzoom = map.custommode ? map.customzoom : 1; + int mapxoff = map.custommode ? map.custommmxoff : 0; + int mapyoff = map.custommode ? map.custommmyoff : 0; if (game.useteleporter) { @@ -2769,48 +2711,40 @@ void teleporterrender(void) //draw the coordinates //destination int tempx_ = map.teleporters[game.teleport_to_teleporter].x; int tempy_ = map.teleporters[game.teleport_to_teleporter].y; - graphics.drawrect(40 + (tempx_ * 12) + 1, 21 + (tempy_ * 9) + 1, 12 - 2, 9 - 2, 245 - (help.glow * 2), 16, 16); - graphics.drawrect(40 + (tempx_ * 12) + 3, 21 + (tempy_ * 9) + 3, 12 - 6, 9 - 6, 245 - (help.glow * 2), 16, 16); + graphics.drawrect(40 + mapxoff + (tempx_ * 12 * mapzoom) + 1, 21 + mapyoff + (tempy_ * 9 * mapzoom) + 1, 12 * mapzoom - 2, 9 * mapzoom - 2, 245 - (help.glow * 2), 16, 16); + graphics.drawrect(40 + mapxoff + (tempx_ * 12 * mapzoom) + 3, 21 + mapyoff + (tempy_ * 9 * mapzoom) + 3, 12 * mapzoom - 6, 9 * mapzoom - 6, 245 - (help.glow * 2), 16, 16); } - //draw legend details - for (size_t i = 0; i < map.teleporters.size(); i++) - { - if (map.showteleporters && map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) - { - int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); - if (graphics.flipmode) temp += 3; - graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp); - } - else if(map.showtargets && !map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) - { - int temp = 1126 + (int) map.isexplored(map.teleporters[i].x, map.teleporters[i].y); - if (graphics.flipmode) temp += 3; - graphics.drawtile(40 + 3 + (map.teleporters[i].x * 12), 22 + (map.teleporters[i].y * 9), temp); - } - } + // Draw the legend itself - if (map.showtrinkets) + rendermaplegend(); + + // Highlight the currently selected teleporter + + int zoom_offset_x; + int zoom_offset_y; + + switch (mapzoom) { - for (size_t i = 0; i < map.shinytrinkets.size(); i++) - { - if (!obj.collect[i]) - { - int temp = 1086; - if (graphics.flipmode) temp += 3; - graphics.drawtile(40 + 3 + (map.shinytrinkets[i].x * 12), 22 + (map.shinytrinkets[i].y * 9), temp); - } - } + case 4: + zoom_offset_x = 60; + zoom_offset_y = 35; + break; + case 2: + zoom_offset_x = 48; + zoom_offset_y = 26; + break; + default: + zoom_offset_x = 43; + zoom_offset_y = 22; + break; } tempx = map.teleporters[game.teleport_to_teleporter].x; tempy = map.teleporters[game.teleport_to_teleporter].y; - if (game.useteleporter && ((help.slowsine%16)>8)) + if (game.useteleporter && ((help.slowsine % 16) > 8)) { - //colour in the legend - int temp = 1128; - if (graphics.flipmode) temp += 3; - graphics.drawtile(40 + 3 + (tempx * 12), 22 + (tempy * 9), temp); + graphics.drawtile(zoom_offset_x + mapxoff + (tempx * 12 * mapzoom), zoom_offset_y + mapyoff + (tempy * 9 * mapzoom), 1128 + (graphics.flipmode ? 3 : 0)); } graphics.cutscenebars(); From f2e2ae591abc9f459a5ecabcd8cfd4eb7ad58cd3 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Sun, 6 Nov 2022 21:03:33 -0400 Subject: [PATCH 05/19] dedupe another piece of code --- desktop_version/src/Render.cpp | 37 +++++++--------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 96c5029b..010d118b 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2166,37 +2166,14 @@ void rendermapcursor(bool flashing) return; } - if (mapzoom == 4) { - if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) { - graphics.drawrect(40 + ((game.roomx - 100) * 48) + 2 + mapxoff, 21 + ((game.roomy - 100) * 36) + 2 + mapyoff, 48 - 4, 36 - 4, 16, 245 - (help.glow), 245 - (help.glow)); - } - else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) - { - graphics.drawrect(40 + ((game.roomx - 100) * 48) + mapxoff, 21 + ((game.roomy - 100) * 36) + mapyoff, 48, 36, 255, 255, 255); - graphics.drawrect(40 + ((game.roomx - 100) * 48) + 2 + mapxoff, 21 + ((game.roomy - 100) * 36) + 2 + mapyoff, 48 - 4, 36 - 4, 255, 255, 255); - } + if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9 * mapzoom) + 2 + mapyoff, (12 * mapzoom) - 4, (9 * mapzoom) - 4, 16, 245 - (help.glow), 245 - (help.glow)); } - else if (mapzoom == 2) { - if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) - { - graphics.drawrect(40 + ((game.roomx - 100) * 24) + 2 + mapxoff, 21 + ((game.roomy - 100) * 18) + 2 + mapyoff, 24 - 4, 18 - 4, 16, 245 - (help.glow), 245 - (help.glow)); - } - else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) - { - graphics.drawrect(40 + ((game.roomx - 100) * 24) + mapxoff, 21 + ((game.roomy - 100) * 18) + mapyoff, 24, 18, 255, 255, 255); - graphics.drawrect(40 + ((game.roomx - 100) * 24) + 2 + mapxoff, 21 + ((game.roomy - 100) * 18) + 2 + mapyoff, 24 - 4, 18 - 4, 255, 255, 255); - } - } - else { - if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) - { - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9) + 2 + mapyoff, 12 - 4, 9 - 4, 16, 245 - (help.glow), 245 - (help.glow)); - } - else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) - { - graphics.drawrect(40 + ((game.roomx - 100) * 12) + mapxoff, 21 + ((game.roomy - 100) * 9) + mapyoff, 12, 9, 255, 255, 255); - graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9) + 2 + mapyoff, 12 - 4, 9 - 4, 255, 255, 255); - } + else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) + { + graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + mapxoff, 21 + ((game.roomy - 100) * 9) + mapyoff, 12 * mapzoom, 9 * mapzoom, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9 * mapzoom) + 2 + mapyoff, (12 * mapzoom) - 4, (9 * mapzoom) - 4, 255, 255, 255); } } From ca506a7bb58880f51439bca404953c3f859aabb7 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Thu, 17 Nov 2022 13:56:32 -0400 Subject: [PATCH 06/19] Fix a missing mapzoom multiplication --- desktop_version/src/Render.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 010d118b..28c10685 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2172,7 +2172,7 @@ void rendermapcursor(bool flashing) } else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) { - graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + mapxoff, 21 + ((game.roomy - 100) * 9) + mapyoff, 12 * mapzoom, 9 * mapzoom, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + mapxoff, 21 + ((game.roomy - 100) * 9 * mapzoom) + mapyoff, 12 * mapzoom, 9 * mapzoom, 255, 255, 255); graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9 * mapzoom) + 2 + mapyoff, (12 * mapzoom) - 4, (9 * mapzoom) - 4, 255, 255, 255); } } From 1cf8f1503a1f9115727da3352e25921115115007 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Fri, 25 Nov 2022 16:53:07 -0400 Subject: [PATCH 07/19] Generate the minimap when entering editor playtesting --- desktop_version/src/Script.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 3e0ac4bf..831a0bbe 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2857,6 +2857,10 @@ void scriptclass::startgamemode( int t ) map.resetplayer(); map.gotoroom(game.saverx, game.savery); map.initmapdata(); + + cl.generatecustomminimap(); + map.customshowmm = true; + graphics.fademode = FADE_START_FADEIN; break; case 21: //play custom level (in editor) From 1837fe8abffda48840b4e9d830df29882d6ec2dc Mon Sep 17 00:00:00 2001 From: AllyTally Date: Fri, 25 Nov 2022 17:32:16 -0400 Subject: [PATCH 08/19] Remove accidental comment change --- desktop_version/src/Render.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 28c10685..1d45f5a4 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2189,7 +2189,7 @@ void maprender(void) //Menubar: graphics.drawtextbox( -10, 212, 43, 3, 65, 185, 207); - // Draw the selected page name at the bottomtele + // Draw the selected page name at the bottom // menupage 0 - 3 is the pause screen if (script.running && game.menupage == 3) { From f7bbf4670c1bb62b0b50fda7010b900c814ec2a5 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Fri, 25 Nov 2022 20:32:37 -0400 Subject: [PATCH 09/19] Fix copy-paste error --- desktop_version/src/Render.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 1d45f5a4..a863c9cb 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2059,7 +2059,7 @@ void rendermap(void) void rendermapfog(void) { - int mapwidth = map.custommode ? map.customheight : 20; + int mapwidth = map.custommode ? map.customwidth : 20; int mapheight = map.custommode ? map.customheight : 20; int mapzoom = map.custommode ? map.customzoom : 1; int mapxoff = map.custommode ? map.custommmxoff : 0; @@ -2137,7 +2137,7 @@ void rendermaplegend(void) void rendermapcursor(bool flashing) { - int mapwidth = map.custommode ? map.customheight : 20; + int mapwidth = map.custommode ? map.customwidth : 20; int mapheight = map.custommode ? map.customheight : 20; int mapzoom = map.custommode ? map.customzoom : 1; int mapxoff = map.custommode ? map.custommmxoff : 0; @@ -2675,7 +2675,7 @@ void teleporterrender(void) // Draw a box around the currently selected teleporter - int mapwidth = map.custommode ? map.customheight : 20; + int mapwidth = map.custommode ? map.customwidth : 20; int mapheight = map.custommode ? map.customheight : 20; int mapzoom = map.custommode ? map.customzoom : 1; int mapxoff = map.custommode ? map.custommmxoff : 0; From 0bf1e1494b676545032cb465d4673fdd27942f59 Mon Sep 17 00:00:00 2001 From: Ally Date: Wed, 30 Nov 2022 12:10:27 -0400 Subject: [PATCH 10/19] Apply suggestions from code review Co-authored-by: Misa Elizabeth Kai --- desktop_version/src/Render.cpp | 44 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index a863c9cb..c1c8ed7b 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2040,24 +2040,22 @@ static void draw_roomname_menu(void) * the same in Flip Mode. */ #define FLIP(y, h) (graphics.flipmode ? 220 - (y) - (h) : (y)) -void rendermap(void) +static void rendermap(void) { #ifndef NO_CUSTOM_LEVELS if (map.custommode) { - //draw the map image graphics.drawpixeltextbox(35 + map.custommmxoff, 16 + map.custommmyoff, map.custommmxsize + 10, map.custommmysize + 10, 65, 185, 207); graphics.drawpartimage(graphics.minimap_mounted ? 1 : 12, 40 + map.custommmxoff, 21 + map.custommmyoff, map.custommmxsize, map.custommmysize); return; } #endif /* NO_CUSTOM_LEVELS */ - //draw the map image graphics.drawpixeltextbox(35, 16, 250, 190, 65, 185, 207); graphics.drawimage(1, 40, 21, false); } -void rendermapfog(void) +static void rendermapfog(void) { int mapwidth = map.custommode ? map.customwidth : 20; int mapheight = map.custommode ? map.customheight : 20; @@ -2065,7 +2063,6 @@ void rendermapfog(void) int mapxoff = map.custommode ? map.custommmxoff : 0; int mapyoff = map.custommode ? map.custommmyoff : 0; - // Draw the fog of war for (int j = 0; j < mapheight; j++) { for (int i = 0; i < mapwidth; i++) @@ -2085,7 +2082,7 @@ void rendermapfog(void) } } -void rendermaplegend(void) +static void rendermaplegend(void) { // Draw the map legend, aka teleports/targets/trinkets @@ -2095,21 +2092,21 @@ void rendermaplegend(void) switch (zoom_mult) { - case 4: - zoom_offset_x = 60; - zoom_offset_y = 35; - break; - case 2: - zoom_offset_x = 48; - zoom_offset_y = 26; - break; - default: - zoom_offset_x = 43; - zoom_offset_y = 22; - break; + case 4: + zoom_offset_x = 60; + zoom_offset_y = 35; + break; + case 2: + zoom_offset_x = 48; + zoom_offset_y = 26; + break; + default: + zoom_offset_x = 43; + zoom_offset_y = 22; + break; } - int tile_offset = graphics.flipmode ? 3 : 0; + const int tile_offset = graphics.flipmode ? 3 : 0; for (size_t i = 0; i < map.teleporters.size(); i++) { @@ -2135,7 +2132,7 @@ void rendermaplegend(void) } } -void rendermapcursor(bool flashing) +static void rendermapcursor(const bool flashing) { int mapwidth = map.custommode ? map.customwidth : 20; int mapheight = map.custommode ? map.customheight : 20; @@ -2157,7 +2154,6 @@ void rendermapcursor(bool flashing) graphics.drawrect(40 + ((game.roomx - 100) * 12), 21, 12, 180, 255, 255, 255); graphics.drawrect(40 + ((game.roomx - 100) * 12) + 2, 21 + 2, 12 - 4, 180 - 4, 255, 255, 255); } - if (map.cursordelay > 30) map.cursorstate = 2; } else if (map.cursorstate == 2 && (int(map.cursordelay / 15) % 2 == 0)) { @@ -2256,7 +2252,9 @@ void maprender(void) } } graphics.bprint(-1, 105, "NO SIGNAL", 245, 245, 245, true); - } else { + } + else + { rendermapfog(); rendermapcursor(true); rendermaplegend(); @@ -2719,7 +2717,7 @@ void teleporterrender(void) tempx = map.teleporters[game.teleport_to_teleporter].x; tempy = map.teleporters[game.teleport_to_teleporter].y; - if (game.useteleporter && ((help.slowsine % 16) > 8)) + if (game.useteleporter && help.slowsine % 16 > 8) { graphics.drawtile(zoom_offset_x + mapxoff + (tempx * 12 * mapzoom), zoom_offset_y + mapyoff + (tempy * 9 * mapzoom), 1128 + (graphics.flipmode ? 3 : 0)); } From 7cdfe6e9a382e0bd2ba2b215a3c38d98aa5526c7 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Wed, 30 Nov 2022 12:17:05 -0400 Subject: [PATCH 11/19] Move generatecustomminimap to case 21 --- desktop_version/src/Script.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 831a0bbe..73a3a0dd 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2857,10 +2857,6 @@ void scriptclass::startgamemode( int t ) map.resetplayer(); map.gotoroom(game.saverx, game.savery); map.initmapdata(); - - cl.generatecustomminimap(); - map.customshowmm = true; - graphics.fademode = FADE_START_FADEIN; break; case 21: //play custom level (in editor) @@ -2892,10 +2888,18 @@ void scriptclass::startgamemode( int t ) map.resetplayer(); map.gotoroom(game.saverx, game.savery); map.initmapdata(); - if(cl.levmusic>0){ + + + cl.generatecustomminimap(); + map.customshowmm = true; + + if (cl.levmusic > 0) + { music.play(cl.levmusic); - }else{ - music.currentsong=-1; + } + else + { + music.currentsong = -1; } break; # endif /* NO_EDITOR */ From c16fe04519ec1a3d6bc1a818f21af6c62989c24d Mon Sep 17 00:00:00 2001 From: AllyTally Date: Wed, 30 Nov 2022 12:37:41 -0400 Subject: [PATCH 12/19] Deduplicate map render data calcuations --- desktop_version/src/Render.cpp | 124 +++++++++++++++------------------ 1 file changed, 57 insertions(+), 67 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index c1c8ed7b..2713e03c 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -24,6 +24,16 @@ static int tr; static int tg; static int tb; +struct MapRenderData { + int width; + int height; + int zoom; + int xoff; + int yoff; + int legendxoff; + int legendyoff; +}; + static inline void drawslowdowntext(void) { switch (game.slowdown) @@ -2040,6 +2050,35 @@ static void draw_roomname_menu(void) * the same in Flip Mode. */ #define FLIP(y, h) (graphics.flipmode ? 220 - (y) - (h) : (y)) +static MapRenderData getmaprenderdata() +{ + MapRenderData data; + + data.width = map.custommode ? map.customwidth : 20; + data.height = map.custommode ? map.customheight : 20; + data.zoom = map.custommode ? map.customzoom : 1; + data.xoff = map.custommode ? map.custommmxoff : 0; + data.yoff = map.custommode ? map.custommmyoff : 0; + + switch (data.zoom) + { + case 4: + data.legendxoff = 60; + data.legendyoff = 35; + break; + case 2: + data.legendxoff = 48; + data.legendyoff = 26; + break; + default: + data.legendxoff = 43; + data.legendyoff = 22; + break; + } + + return data; +} + static void rendermap(void) { #ifndef NO_CUSTOM_LEVELS @@ -2057,24 +2096,20 @@ static void rendermap(void) static void rendermapfog(void) { - int mapwidth = map.custommode ? map.customwidth : 20; - int mapheight = map.custommode ? map.customheight : 20; - int mapzoom = map.custommode ? map.customzoom : 1; - int mapxoff = map.custommode ? map.custommmxoff : 0; - int mapyoff = map.custommode ? map.custommmyoff : 0; + MapRenderData data = getmaprenderdata(); - for (int j = 0; j < mapheight; j++) + for (int j = 0; j < data.height; j++) { - for (int i = 0; i < mapwidth; i++) + for (int i = 0; i < data.width; i++) { if (!map.isexplored(i, j)) { // Draw the fog, depending on the custom zoom size - for (int x = 0; x < mapzoom; x++) + for (int x = 0; x < data.zoom; x++) { - for (int y = 0; y < mapzoom; y++) + for (int y = 0; y < data.zoom; y++) { - graphics.drawimage(2, mapxoff + 40 + (x * 12) + (i * (12 * mapzoom)), mapyoff + 21 + (y * 9) + (j * (9 * mapzoom)), false); + graphics.drawimage(2, data.xoff + 40 + (x * 12) + (i * (12 * data.zoom)), data.yoff + 21 + (y * 9) + (j * (9 * data.zoom)), false); } } } @@ -2086,25 +2121,7 @@ static void rendermaplegend(void) { // Draw the map legend, aka teleports/targets/trinkets - int zoom_offset_x; - int zoom_offset_y; - int zoom_mult = map.custommode ? map.customzoom : 1; - - switch (zoom_mult) - { - case 4: - zoom_offset_x = 60; - zoom_offset_y = 35; - break; - case 2: - zoom_offset_x = 48; - zoom_offset_y = 26; - break; - default: - zoom_offset_x = 43; - zoom_offset_y = 22; - break; - } + MapRenderData data = getmaprenderdata(); const int tile_offset = graphics.flipmode ? 3 : 0; @@ -2112,11 +2129,11 @@ static void rendermaplegend(void) { if (map.showteleporters && map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) { - graphics.drawtile(zoom_offset_x + (map.teleporters[i].x * 12 * zoom_mult), zoom_offset_y + (map.teleporters[i].y * 9 * zoom_mult), 1127 + tile_offset); + graphics.drawtile(data.legendxoff + (map.teleporters[i].x * 12 * data.zoom), data.legendyoff + (map.teleporters[i].y * 9 * data.zoom), 1127 + tile_offset); } else if (map.showtargets && !map.isexplored(map.teleporters[i].x, map.teleporters[i].y)) { - graphics.drawtile(zoom_offset_x + (map.teleporters[i].x * 12 * zoom_mult), zoom_offset_y + (map.teleporters[i].y * 9 * zoom_mult), 1126 + tile_offset); + graphics.drawtile(data.legendxoff + (map.teleporters[i].x * 12 * data.zoom), data.legendyoff + (map.teleporters[i].y * 9 * data.zoom), 1126 + tile_offset); } } @@ -2126,7 +2143,7 @@ static void rendermaplegend(void) { if (!obj.collect[i]) { - graphics.drawtile(zoom_offset_x + (map.shinytrinkets[i].x * 12 * zoom_mult), zoom_offset_y + (map.shinytrinkets[i].y * 9 * zoom_mult), 1086 + tile_offset); + graphics.drawtile(data.legendxoff + (map.shinytrinkets[i].x * 12 * data.zoom), data.legendyoff + (map.shinytrinkets[i].y * 9 * data.zoom), 1086 + tile_offset); } } } @@ -2134,11 +2151,7 @@ static void rendermaplegend(void) static void rendermapcursor(const bool flashing) { - int mapwidth = map.custommode ? map.customwidth : 20; - int mapheight = map.custommode ? map.customheight : 20; - int mapzoom = map.custommode ? map.customzoom : 1; - int mapxoff = map.custommode ? map.custommmxoff : 0; - int mapyoff = map.custommode ? map.custommmyoff : 0; + MapRenderData data = getmaprenderdata(); if (!map.custommode && game.roomx == 109) { @@ -2164,12 +2177,12 @@ static void rendermapcursor(const bool flashing) if (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) { - graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9 * mapzoom) + 2 + mapyoff, (12 * mapzoom) - 4, (9 * mapzoom) - 4, 16, 245 - (help.glow), 245 - (help.glow)); + graphics.drawrect(40 + ((game.roomx - 100) * 12 * data.zoom) + 2 + data.xoff, 21 + ((game.roomy - 100) * 9 * data.zoom) + 2 + data.yoff, (12 * data.zoom) - 4, (9 * data.zoom) - 4, 16, 245 - (help.glow), 245 - (help.glow)); } else if (map.cursorstate == 1 && (int(map.cursordelay / 4) % 2 == 0)) { - graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + mapxoff, 21 + ((game.roomy - 100) * 9 * mapzoom) + mapyoff, 12 * mapzoom, 9 * mapzoom, 255, 255, 255); - graphics.drawrect(40 + ((game.roomx - 100) * 12 * mapzoom) + 2 + mapxoff, 21 + ((game.roomy - 100) * 9 * mapzoom) + 2 + mapyoff, (12 * mapzoom) - 4, (9 * mapzoom) - 4, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 12 * data.zoom) + data.xoff, 21 + ((game.roomy - 100) * 9 * data.zoom) + data.yoff, 12 * data.zoom, 9 * data.zoom, 255, 255, 255); + graphics.drawrect(40 + ((game.roomx - 100) * 12 * data.zoom) + 2 + data.xoff, 21 + ((game.roomy - 100) * 9 * data.zoom) + 2 + data.yoff, (12 * data.zoom) - 4, (9 * data.zoom) - 4, 255, 255, 255); } } @@ -2673,11 +2686,7 @@ void teleporterrender(void) // Draw a box around the currently selected teleporter - int mapwidth = map.custommode ? map.customwidth : 20; - int mapheight = map.custommode ? map.customheight : 20; - int mapzoom = map.custommode ? map.customzoom : 1; - int mapxoff = map.custommode ? map.custommmxoff : 0; - int mapyoff = map.custommode ? map.custommmyoff : 0; + MapRenderData data = getmaprenderdata(); if (game.useteleporter) { @@ -2686,8 +2695,8 @@ void teleporterrender(void) //draw the coordinates //destination int tempx_ = map.teleporters[game.teleport_to_teleporter].x; int tempy_ = map.teleporters[game.teleport_to_teleporter].y; - graphics.drawrect(40 + mapxoff + (tempx_ * 12 * mapzoom) + 1, 21 + mapyoff + (tempy_ * 9 * mapzoom) + 1, 12 * mapzoom - 2, 9 * mapzoom - 2, 245 - (help.glow * 2), 16, 16); - graphics.drawrect(40 + mapxoff + (tempx_ * 12 * mapzoom) + 3, 21 + mapyoff + (tempy_ * 9 * mapzoom) + 3, 12 * mapzoom - 6, 9 * mapzoom - 6, 245 - (help.glow * 2), 16, 16); + graphics.drawrect(40 + data.xoff + (tempx_ * 12 * data.zoom) + 1, 21 + data.yoff + (tempy_ * 9 * data.zoom) + 1, 12 * data.zoom - 2, 9 * data.zoom - 2, 245 - (help.glow * 2), 16, 16); + graphics.drawrect(40 + data.xoff + (tempx_ * 12 * data.zoom) + 3, 21 + data.yoff + (tempy_ * 9 * data.zoom) + 3, 12 * data.zoom - 6, 9 * data.zoom - 6, 245 - (help.glow * 2), 16, 16); } // Draw the legend itself @@ -2696,30 +2705,11 @@ void teleporterrender(void) // Highlight the currently selected teleporter - int zoom_offset_x; - int zoom_offset_y; - - switch (mapzoom) - { - case 4: - zoom_offset_x = 60; - zoom_offset_y = 35; - break; - case 2: - zoom_offset_x = 48; - zoom_offset_y = 26; - break; - default: - zoom_offset_x = 43; - zoom_offset_y = 22; - break; - } - tempx = map.teleporters[game.teleport_to_teleporter].x; tempy = map.teleporters[game.teleport_to_teleporter].y; if (game.useteleporter && help.slowsine % 16 > 8) { - graphics.drawtile(zoom_offset_x + mapxoff + (tempx * 12 * mapzoom), zoom_offset_y + mapyoff + (tempy * 9 * mapzoom), 1128 + (graphics.flipmode ? 3 : 0)); + graphics.drawtile(data.legendxoff + data.xoff + (tempx * 12 * data.zoom), data.legendyoff + data.yoff + (tempy * 9 * data.zoom), 1128 + (graphics.flipmode ? 3 : 0)); } graphics.cutscenebars(); From cbfef2eb5384b1c3dbc7f5cf8e4db04cc1d02a94 Mon Sep 17 00:00:00 2001 From: Ally Date: Wed, 30 Nov 2022 14:31:36 -0400 Subject: [PATCH 13/19] Apply suggestions from code review Co-authored-by: Misa Elizabeth Kai --- desktop_version/src/Render.cpp | 11 ++++++----- desktop_version/src/Script.cpp | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 2713e03c..9e6dbec9 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -24,7 +24,8 @@ static int tr; static int tg; static int tb; -struct MapRenderData { +struct MapRenderData +{ int width; int height; int zoom; @@ -2096,7 +2097,7 @@ static void rendermap(void) static void rendermapfog(void) { - MapRenderData data = getmaprenderdata(); + const MapRenderData data = getmaprenderdata(); for (int j = 0; j < data.height; j++) { @@ -2121,7 +2122,7 @@ static void rendermaplegend(void) { // Draw the map legend, aka teleports/targets/trinkets - MapRenderData data = getmaprenderdata(); + const MapRenderData data = getmaprenderdata(); const int tile_offset = graphics.flipmode ? 3 : 0; @@ -2151,7 +2152,7 @@ static void rendermaplegend(void) static void rendermapcursor(const bool flashing) { - MapRenderData data = getmaprenderdata(); + const MapRenderData data = getmaprenderdata(); if (!map.custommode && game.roomx == 109) { @@ -2686,7 +2687,7 @@ void teleporterrender(void) // Draw a box around the currently selected teleporter - MapRenderData data = getmaprenderdata(); + const MapRenderData data = getmaprenderdata(); if (game.useteleporter) { diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 73a3a0dd..7287ede7 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2889,7 +2889,6 @@ void scriptclass::startgamemode( int t ) map.gotoroom(game.saverx, game.savery); map.initmapdata(); - cl.generatecustomminimap(); map.customshowmm = true; From 88142ea8395266ebaec508e9fde3dc76b0f67bc0 Mon Sep 17 00:00:00 2001 From: AllyTally Date: Wed, 30 Nov 2022 15:02:05 -0400 Subject: [PATCH 14/19] Fix legend positions --- desktop_version/src/Render.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 9e6dbec9..33fb5b95 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -2060,20 +2060,23 @@ static MapRenderData getmaprenderdata() data.zoom = map.custommode ? map.customzoom : 1; data.xoff = map.custommode ? map.custommmxoff : 0; data.yoff = map.custommode ? map.custommmyoff : 0; + data.legendxoff = 40 + data.xoff; + data.legendyoff = 21 + data.yoff; + // Magic numbers for centering legend tiles. switch (data.zoom) { case 4: - data.legendxoff = 60; - data.legendyoff = 35; + data.legendxoff += 21; + data.legendyoff += 16; break; case 2: - data.legendxoff = 48; - data.legendyoff = 26; + data.legendxoff += 9; + data.legendyoff += 5; break; default: - data.legendxoff = 43; - data.legendyoff = 22; + data.legendxoff += 3; + data.legendyoff += 1; break; } From d183ea6367180acec073c7915d560c73b1a8e4c4 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 30 Nov 2022 13:25:28 -0800 Subject: [PATCH 15/19] Clean up the code style of `generatecustomminimap` The existing code was allergic to putting spaces between tokens, and had some minor code duplication that I took the time to clean up as well. The logic should be easier to follow now that the for-loops are no longer duplicated for each of the map zoom levels. I tested this by temporarily disabling map fog entirely and going through a couple different custom levels to compare their minimap with the existing code. These were A New Dimension and 333333 for 1x, Golden Spiral and VVVV 4k for 2x, and VVVVVV is NP-Hard for 4x. There was no difference in the output, not even a single pixel. --- desktop_version/src/CustomLevels.cpp | 161 ++++++++++++--------------- 1 file changed, 70 insertions(+), 91 deletions(-) diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 21742fdf..b76ad961 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -1483,116 +1483,95 @@ bool customlevelclass::save(const std::string& _path) void customlevelclass::generatecustomminimap(void) { - map.customwidth=mapwidth; - map.customheight=mapheight; + map.customwidth = mapwidth; + map.customheight = mapheight; - map.customzoom=1; - if(map.customwidth<=10 && map.customheight<=10) map.customzoom=2; - if(map.customwidth<=5 && map.customheight<=5) map.customzoom=4; - - //Set minimap offsets - if(map.customzoom==4) + map.customzoom = 1; + if (map.customwidth <= 10 && map.customheight <= 10) { - map.custommmxoff=24*(5-map.customwidth); - map.custommmxsize=240-(map.custommmxoff*2); - - map.custommmyoff=18*(5-map.customheight); - map.custommmysize=180-(map.custommmyoff*2); + map.customzoom = 2; } - else if(map.customzoom==2) + if (map.customwidth <= 5 && map.customheight <= 5) { - map.custommmxoff=12*(10-map.customwidth); - map.custommmxsize=240-(map.custommmxoff*2); - - map.custommmyoff=9*(10-map.customheight); - map.custommmysize=180-(map.custommmyoff*2); + map.customzoom = 4; } - else + + // Set minimap offsets + switch (map.customzoom) { - map.custommmxoff=6*(20-map.customwidth); - map.custommmxsize=240-(map.custommmxoff*2); - - map.custommmyoff=int(4.5*(20-map.customheight)); - map.custommmysize=180-(map.custommmyoff*2); + case 4: + map.custommmxoff = 24 * (5 - map.customwidth); + map.custommmyoff = 18 * (5 - map.customheight); + break; + case 2: + map.custommmxoff = 12 * (10 - map.customwidth); + map.custommmyoff = 9 * (10 - map.customheight); + break; + default: + map.custommmxoff = 6 * (20 - map.customwidth); + map.custommmyoff = int(4.5 * (20 - map.customheight)); + break; } + map.custommmxsize = 240 - (map.custommmxoff * 2); + map.custommmysize = 180 - (map.custommmyoff * 2); + FillRect(graphics.images[12], graphics.getRGB(0, 0, 0)); - int tm=0; - int temp=0; - //Scan over the map size - if(mapheight<=5 && mapwidth<=5) + // Scan over the map size + for (int j2 = 0; j2 < mapheight; j2++) { - //4x map - for(int j2=0; j2tileset == 1) { - //Ok, now scan over each square - tm=196; - if(getroomprop(i2, j2)->tileset==1) tm=96; - - for(int j=0; j<36; j++) - { - for(int i=0; i<48; i++) - { - temp=absfree(int(i*0.83) + (i2*40),int(j*0.83)+(j2*30)); - if(temp>=1) - { - //Fill in this pixel - FillRect(graphics.images[12], (i2*48)+i, (j2*36)+j, 1, 1, graphics.getRGB(tm, tm, tm)); - } - } - } + tm = 96; } - } - } - else if(mapheight<=10 && mapwidth<=10) - { - //2x map - for(int j2=0; j2tileset==1) tm=96; - - for(int j=0; j<18; j++) - { - for(int i=0; i<24; i++) - { - temp=absfree(int(i*1.6) + (i2*40),int(j*1.6)+(j2*30)); - if(temp>=1) - { - //Fill in this pixel - FillRect(graphics.images[12], (i2*24)+i, (j2*18)+j, 1, 1, graphics.getRGB(tm, tm, tm)); - } - } - } + tm = 196; } - } - } - else - { - for(int j2=0; j2tileset==1) tm=96; - for(int j=0; j<9; j++) + // Ok, now scan over each square + for (int j = 0; j < 9 * map.customzoom; j++) + { + for (int i = 0; i < 12 * map.customzoom; i++) { - for(int i=0; i<12; i++) + int tile; + switch (map.customzoom) { - temp=absfree(3+(i*3) + (i2*40),(j*3)+(j2*30)); - if(temp>=1) - { - //Fill in this pixel - FillRect(graphics.images[12], (i2*12)+i, (j2*9)+j, 1, 1, graphics.getRGB(tm, tm, tm)); - } + case 4: + tile = absfree( + int(i * 0.83) + (i2 * 40), + int(j * 0.83) + (j2 * 30) + ); + break; + case 2: + tile = absfree( + int(i * 1.6) + (i2 * 40), + int(j * 1.6) + (j2 * 30) + ); + break; + default: + tile = absfree( + 3 + (i * 3) + (i2 * 40), + (j * 3) + (j2 * 30) + ); + break; + } + + if (tile >= 1) + { + // Fill in this pixel + FillRect( + graphics.images[12], + (i2 * 12 * map.customzoom) + i, + (j2 * 9 * map.customzoom) + j, + 1, + 1, + graphics.getRGB(tm, tm, tm) + ); } } } From de38b6b55cdeecb2bec127bd31f4bf07a9a0bfc3 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 30 Nov 2022 13:35:14 -0800 Subject: [PATCH 16/19] Unify all queries to map size to `map.getwidth` and `map.getheight` It's becoming pretty clear that the size of the map is important enough to be queried a lot, but each time it's something like `map.custommode ? map.customwidth : 20` and `map.custommode ? map.customheight : 20` which is not ideal because of copy-pasting. Furthermore, even `map.customwidth` and `map.customheight` are just duplicates of `cl.mapwidth` and `cl.mapheight`, which are only set in `customlevelclass::generatecustomminimap`. This is a bit annoying if you want to, say, add checks that depend on the width and height of the custom map in `mapclass::initcustommapdata`, but `map.customwidth` and `map.customheight` are out of date because `generatecustomminimap` hasn't been called yet. And doing the ternary there requires a `#ifndef NO_CUSTOM_LEVELS` to reference `cl.mapwidth` and `cl.mapheight` which is just awful. So I'm axing `map.customwidth` and `map.customheight`, and I'm axing all the ternaries that are duplicating the source of truth in `MapRenderData`. Instead, there will just be one function to call for the width and height, `mapclass::getwidth` and `mapclass::getheight`, and everyone can simply call those without needing to do ternaries or duplication. --- desktop_version/src/CustomLevels.cpp | 19 ++++++++----------- desktop_version/src/Map.cpp | 25 ++++++++++++++++++++++++- desktop_version/src/Map.h | 5 ++++- desktop_version/src/Render.cpp | 8 ++------ 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index b76ad961..465279a5 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -1483,15 +1483,12 @@ bool customlevelclass::save(const std::string& _path) void customlevelclass::generatecustomminimap(void) { - map.customwidth = mapwidth; - map.customheight = mapheight; - map.customzoom = 1; - if (map.customwidth <= 10 && map.customheight <= 10) + if (mapwidth <= 10 && mapheight <= 10) { map.customzoom = 2; } - if (map.customwidth <= 5 && map.customheight <= 5) + if (mapwidth <= 5 && mapheight <= 5) { map.customzoom = 4; } @@ -1500,16 +1497,16 @@ void customlevelclass::generatecustomminimap(void) switch (map.customzoom) { case 4: - map.custommmxoff = 24 * (5 - map.customwidth); - map.custommmyoff = 18 * (5 - map.customheight); + map.custommmxoff = 24 * (5 - mapwidth); + map.custommmyoff = 18 * (5 - mapheight); break; case 2: - map.custommmxoff = 12 * (10 - map.customwidth); - map.custommmyoff = 9 * (10 - map.customheight); + map.custommmxoff = 12 * (10 - mapwidth); + map.custommmyoff = 9 * (10 - mapheight); break; default: - map.custommmxoff = 6 * (20 - map.customwidth); - map.custommmyoff = int(4.5 * (20 - map.customheight)); + map.custommmxoff = 6 * (20 - mapwidth); + map.custommmyoff = int(4.5 * (20 - mapheight)); break; } diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 74d6a943..78a4cd72 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -48,7 +48,6 @@ mapclass::mapclass(void) custommode=false; custommodeforreal=false; - customwidth=20; customheight=20; custommmxoff=0; custommmyoff=0; custommmxsize=0; custommmysize=0; customzoom=0; customshowmm=true; @@ -109,6 +108,30 @@ const int mapclass::areamap[] = { 2,2,2,2,2,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0, }; +int mapclass::getwidth(void) +{ +#ifndef NO_CUSTOM_LEVELS + if (custommode) + { + return cl.mapwidth; + } +#endif + + return 20; +} + +int mapclass::getheight(void) +{ +#ifndef NO_CUSTOM_LEVELS + if (custommode) + { + return cl.mapheight; + } +#endif + + return 20; +} + int mapclass::intpol(int a, int b, float c) { return static_cast(a + ((b - a) * c)); diff --git a/desktop_version/src/Map.h b/desktop_version/src/Map.h index dcd2e2df..3a439f3e 100644 --- a/desktop_version/src/Map.h +++ b/desktop_version/src/Map.h @@ -23,6 +23,10 @@ class mapclass public: mapclass(void); + int getwidth(void); + + int getheight(void); + int intpol(int a, int b, float c); void setteleporter(int x, int y); @@ -129,7 +133,6 @@ public: //Variables for playing custom levels bool custommode; bool custommodeforreal; - int customwidth, customheight; int custommmxoff, custommmyoff, custommmxsize, custommmysize; int customzoom; bool customshowmm; diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 33fb5b95..bda5fdbb 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -26,8 +26,6 @@ static int tb; struct MapRenderData { - int width; - int height; int zoom; int xoff; int yoff; @@ -2055,8 +2053,6 @@ static MapRenderData getmaprenderdata() { MapRenderData data; - data.width = map.custommode ? map.customwidth : 20; - data.height = map.custommode ? map.customheight : 20; data.zoom = map.custommode ? map.customzoom : 1; data.xoff = map.custommode ? map.custommmxoff : 0; data.yoff = map.custommode ? map.custommmyoff : 0; @@ -2102,9 +2098,9 @@ static void rendermapfog(void) { const MapRenderData data = getmaprenderdata(); - for (int j = 0; j < data.height; j++) + for (int j = 0; j < map.getheight(); j++) { - for (int i = 0; i < data.width; i++) + for (int i = 0; i < map.getwidth(); i++) { if (!map.isexplored(i, j)) { From 6e583d949bccca82d949f65f4efd1f08ad618242 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 30 Nov 2022 13:42:10 -0800 Subject: [PATCH 17/19] Don't set legends if out of bounds Trinket and teleporter legends would be drawn even if they were out of bounds. Trinket legends in particular were easy to do because you can just place a trinket in a custom level and resize the map to not include the room of the trinket. Now, there are checks added so they won't be added if they are out of bounds. This is in line with the fact that, since 2.3, if a trinket exists outside of the map in custom levels, it won't count towards the number of trinkets. --- desktop_version/src/Map.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 78a4cd72..d278c28c 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -139,6 +139,11 @@ int mapclass::intpol(int a, int b, float c) void mapclass::setteleporter(int x, int y) { + if (x < 0 || x >= getwidth() || y < 0 || y >= getheight()) + { + return; + } + point temp; temp.x = x; temp.y = y; @@ -147,6 +152,11 @@ void mapclass::setteleporter(int x, int y) void mapclass::settrinket(int x, int y) { + if (x < 0 || x >= getwidth() || y < 0 || y >= getheight()) + { + return; + } + point temp; temp.x = x; temp.y = y; From a926ce98513f04b751f22907e9ce324da82b30d8 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 30 Nov 2022 22:30:16 -0800 Subject: [PATCH 18/19] Replace all free calls with `VVV_free[func]` This replaces all calls to SDL_free with a new macro, VVV_free, that nulls the pointer afterwards. This mitigates any use-after-frees and also completely eliminates double-frees. The same is done for any function to free specific objects such as SDL_FreeSurface, with the VVV_freefunc macro. No exceptions for any of these calls, even if the pointer is discarded or zeroed afterwards anyway. Better safe than sorry. This is a macro rather than a function that takes in a pointer-to-pointer because such a function would have type issues that require casting and that's just not safe. Even though SDL_free and other SDL functions already check for NULL, the macro has a NULL check for other functions that don't. For example, FAudioVoice_DestroyVoice does not check for NULL. FILESYSTEM_freeMemory has been axed in favor of VVV_free because it functionally does the same thing except for `unsigned char*` only. --- desktop_version/src/Alloc.h | 19 ++++++++++ desktop_version/src/BinaryBlob.cpp | 3 +- desktop_version/src/CWrappers.cpp | 2 +- desktop_version/src/CustomLevels.cpp | 3 +- desktop_version/src/FileSystemUtils.cpp | 22 +++--------- desktop_version/src/FileSystemUtils.h | 1 - desktop_version/src/Graphics.cpp | 40 ++++++++++----------- desktop_version/src/GraphicsResources.cpp | 14 ++++---- desktop_version/src/GraphicsUtil.cpp | 7 ++-- desktop_version/src/KeyPoll.cpp | 3 +- desktop_version/src/Music.cpp | 43 +++++++++-------------- desktop_version/src/Screen.cpp | 19 ++++------ desktop_version/src/ThirdPartyDeps.c | 4 ++- desktop_version/src/VFormat.c | 13 +++---- desktop_version/src/VFormat.h | 2 +- 15 files changed, 95 insertions(+), 100 deletions(-) create mode 100644 desktop_version/src/Alloc.h diff --git a/desktop_version/src/Alloc.h b/desktop_version/src/Alloc.h new file mode 100644 index 00000000..042cffb4 --- /dev/null +++ b/desktop_version/src/Alloc.h @@ -0,0 +1,19 @@ +#ifndef ALLOCGAME_H +#define ALLOCGAME_H + +/* TODO: VVV_malloc, VVV_realloc, etc. */ + +#define VVV_freefunc(func, obj) \ + do \ + { \ + if (obj != NULL) \ + { \ + func(obj); \ + obj = NULL; \ + } \ + } \ + while (0) + +#define VVV_free(obj) VVV_freefunc(SDL_free, obj) + +#endif /* ALLOCGAME_H */ diff --git a/desktop_version/src/BinaryBlob.cpp b/desktop_version/src/BinaryBlob.cpp index 78a68814..62d99f19 100644 --- a/desktop_version/src/BinaryBlob.cpp +++ b/desktop_version/src/BinaryBlob.cpp @@ -5,6 +5,7 @@ #include #endif +#include "Alloc.h" #include "Exit.h" #include "FileSystemUtils.h" #include "UtilityClass.h" @@ -91,7 +92,7 @@ void binaryBlob::clear(void) { if (m_memblocks[i] != NULL) { - SDL_free(m_memblocks[i]); + VVV_free(m_memblocks[i]); } } SDL_zeroa(m_memblocks); diff --git a/desktop_version/src/CWrappers.cpp b/desktop_version/src/CWrappers.cpp index 57ff38c0..32ee9c6a 100644 --- a/desktop_version/src/CWrappers.cpp +++ b/desktop_version/src/CWrappers.cpp @@ -5,7 +5,7 @@ extern "C" char* HELP_number_words(int _t) { /* C wrapper for UtilityClass::number_words. - * Caller must SDL_free. */ + * Caller must VVV_free. */ std::string str = help.number_words(_t); diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 465279a5..ff03132c 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -9,6 +9,7 @@ #include #include +#include "Alloc.h" #include "Constants.h" #include "Editor.h" #include "Enums.h" @@ -267,7 +268,7 @@ bool customlevelclass::getLevelMetaDataAndPlaytestArgs(const std::string& _path, std::string buf((char*) uMem); - FILESYSTEM_freeMemory(&uMem); + VVV_free(uMem); if (find_metadata(buf) == "") { diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 72dc8069..d9402882 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -4,6 +4,7 @@ #include #include +#include "Alloc.h" #include "BinaryBlob.h" #include "Exit.h" #include "Graphics.h" @@ -201,13 +202,8 @@ void FILESYSTEM_deinit(void) { PHYSFS_deinit(); } - if (stdin_buffer != NULL) - { - SDL_free(stdin_buffer); - stdin_buffer = NULL; - } - SDL_free(basePath); - basePath = NULL; + VVV_free(stdin_buffer); + VVV_free(basePath); isInit = false; } @@ -505,8 +501,6 @@ bool FILESYSTEM_isAssetMounted(const char* filename) return SDL_strcmp(assetDir, realDir) == 0; } -void FILESYSTEM_freeMemory(unsigned char **mem); - static void load_stdin(void) { size_t pos = 0; @@ -636,7 +630,7 @@ void FILESYSTEM_loadFileToMemory( success = PHYSFS_readBytes(handle, *mem, length); if (success == -1) { - FILESYSTEM_freeMemory(mem); + VVV_free(*mem); } PHYSFS_close(handle); return; @@ -665,12 +659,6 @@ void FILESYSTEM_loadAssetToMemory( FILESYSTEM_loadFileToMemory(path, mem, len, addnull); } -void FILESYSTEM_freeMemory(unsigned char **mem) -{ - SDL_free(*mem); - *mem = NULL; -} - bool FILESYSTEM_loadBinaryBlob(binaryBlob* blob, const char* filename) { PHYSFS_sint64 size; @@ -817,7 +805,7 @@ bool FILESYSTEM_loadTiXml2Document(const char *name, tinyxml2::XMLDocument& doc) return false; } doc.Parse((const char*) mem); - FILESYSTEM_freeMemory(&mem); + VVV_free(mem); return true; } diff --git a/desktop_version/src/FileSystemUtils.h b/desktop_version/src/FileSystemUtils.h index bac5b444..7358673b 100644 --- a/desktop_version/src/FileSystemUtils.h +++ b/desktop_version/src/FileSystemUtils.h @@ -32,7 +32,6 @@ void FILESYSTEM_loadAssetToMemory( size_t* len, const bool addnull ); -void FILESYSTEM_freeMemory(unsigned char **mem); bool FILESYSTEM_loadBinaryBlob(binaryBlob* blob, const char* filename); diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index c340d8c6..8bf44e0c 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -4,6 +4,7 @@ #include #include +#include "Alloc.h" #include "Constants.h" #include "CustomLevels.h" #include "Entity.h" @@ -158,7 +159,7 @@ void Graphics::destroy(void) #define CLEAR_ARRAY(name) \ for (size_t i = 0; i < name.size(); i += 1) \ { \ - SDL_FreeSurface(name[i]); \ + VVV_freefunc(SDL_FreeSurface, name[i]); \ } \ name.clear(); @@ -228,22 +229,20 @@ void Graphics::create_buffers(const SDL_PixelFormat* fmt) void Graphics::destroy_buffers(void) { -#define FREE_SURFACE(SURFACE) \ - SDL_FreeSurface(SURFACE); \ - SURFACE = NULL; +#define FREE_SURFACE(SURFACE) VVV_freefunc(SDL_FreeSurface, SURFACE) - FREE_SURFACE(backBuffer) - FREE_SURFACE(footerbuffer) - FREE_SURFACE(ghostbuffer) - FREE_SURFACE(foregroundBuffer) - FREE_SURFACE(menubuffer) - FREE_SURFACE(warpbuffer) - FREE_SURFACE(warpbuffer_lerp) - FREE_SURFACE(towerbg.buffer) - FREE_SURFACE(towerbg.buffer_lerp) - FREE_SURFACE(titlebg.buffer) - FREE_SURFACE(titlebg.buffer_lerp) - FREE_SURFACE(tempBuffer) + FREE_SURFACE(backBuffer); + FREE_SURFACE(footerbuffer); + FREE_SURFACE(ghostbuffer); + FREE_SURFACE(foregroundBuffer); + FREE_SURFACE(menubuffer); + FREE_SURFACE(warpbuffer); + FREE_SURFACE(warpbuffer_lerp); + FREE_SURFACE(towerbg.buffer); + FREE_SURFACE(towerbg.buffer_lerp); + FREE_SURFACE(titlebg.buffer); + FREE_SURFACE(titlebg.buffer_lerp); + FREE_SURFACE(tempBuffer); #undef FREE_SURFACE } @@ -347,8 +346,7 @@ void Graphics::updatetitlecolours(void) } \ } \ \ - SDL_FreeSurface(grphx.im_##tilesheet); \ - grphx.im_##tilesheet = NULL; \ + VVV_freefunc(SDL_FreeSurface, grphx.im_##tilesheet); \ } #define PROCESS_TILESHEET(tilesheet, tile_square, extra_code) \ @@ -376,7 +374,7 @@ bool Graphics::Makebfont(void) font_positions[codepoint] = pos; ++pos; } - FILESYSTEM_freeMemory(&charmap); + VVV_free(charmap); } else { @@ -502,7 +500,7 @@ static void print_char( if (scale > 1) { - SDL_FreeSurface(surface); + VVV_freefunc(SDL_FreeSurface, surface); } } @@ -2179,7 +2177,7 @@ void Graphics::drawentity(const int i, const int yoff) setRect(drawRect, xp, yp - yoff, sprites_rect.x * 6, sprites_rect.y * 6); SDL_Surface* TempSurface = ScaleSurface( spritesvec[obj.entities[i].drawframe], 6 * sprites_rect.w,6* sprites_rect.h ); BlitSurfaceColoured(TempSurface, NULL , backBuffer, &drawRect, ct ); - SDL_FreeSurface(TempSurface); + VVV_freefunc(SDL_FreeSurface, TempSurface); diff --git a/desktop_version/src/GraphicsResources.cpp b/desktop_version/src/GraphicsResources.cpp index 743f9f39..4d742bd5 100644 --- a/desktop_version/src/GraphicsResources.cpp +++ b/desktop_version/src/GraphicsResources.cpp @@ -1,5 +1,6 @@ #include "GraphicsResources.h" +#include "Alloc.h" #include "FileSystemUtils.h" #include "Vlogging.h" @@ -37,7 +38,7 @@ SDL_Surface* LoadImage(const char *filename) return NULL; } error = lodepng_decode32(&data, &width, &height, fileIn, length); - FILESYSTEM_freeMemory(&fileIn); + VVV_free(fileIn); if (error != 0) { @@ -61,14 +62,14 @@ SDL_Surface* LoadImage(const char *filename) SDL_PIXELFORMAT_ARGB8888, 0 ); - SDL_FreeSurface( loadedImage ); - SDL_free(data); + VVV_freefunc(SDL_FreeSurface, loadedImage); + VVV_free(data); SDL_SetSurfaceBlendMode(optimizedImage, SDL_BLENDMODE_BLEND); return optimizedImage; } else { - SDL_free(data); + VVV_free(data); vlog_error("Image not found: %s", filename); SDL_assert(0 && "Image not found! See stderr."); return NULL; @@ -104,10 +105,7 @@ void GraphicsResources::init(void) void GraphicsResources::destroy(void) { -#define CLEAR(img) \ - SDL_FreeSurface(img); \ - img = NULL; - +#define CLEAR(img) VVV_freefunc(SDL_FreeSurface, img) CLEAR(im_tiles); CLEAR(im_tiles2); CLEAR(im_tiles3); diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index 9c86a4ec..54698116 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -4,6 +4,7 @@ #include #include +#include "Alloc.h" #include "Graphics.h" #include "Maths.h" @@ -226,7 +227,7 @@ void BlitSurfaceColoured( } SDL_BlitSurface(tempsurface, _srcRect, _dest, tempRect); - SDL_FreeSurface(tempsurface); + VVV_freefunc(SDL_FreeSurface, tempsurface); } void BlitSurfaceTinted( @@ -287,7 +288,7 @@ void BlitSurfaceTinted( } SDL_BlitSurface(tempsurface, _srcRect, _dest, tempRect); - SDL_FreeSurface(tempsurface); + VVV_freefunc(SDL_FreeSurface, tempsurface); } @@ -489,7 +490,7 @@ void ScrollSurface( SDL_Surface* _src, int _pX, int _pY ) //Cleanup temp surface if (part1) { - SDL_FreeSurface(part1); + VVV_freefunc(SDL_FreeSurface, part1); } } diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index cd777849..91bc82cd 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -4,6 +4,7 @@ #include #include +#include "Alloc.h" #include "Exit.h" #include "Game.h" #include "GlitchrunnerMode.h" @@ -183,7 +184,7 @@ void KeyPoll::Poll(void) if (text != NULL) { keybuffer += text; - SDL_free(text); + VVV_free(text); } } } diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 3e52c667..9c9ee0aa 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -5,6 +5,7 @@ #include #include +#include "Alloc.h" #include "BinaryBlob.h" #include "FileSystemUtils.h" #include "Game.h" @@ -21,7 +22,7 @@ #define malloc SDL_malloc #define realloc SDL_realloc -#define free SDL_free +#define free VVV_free #ifdef memset /* Thanks, Apple! */ #undef memset #endif @@ -121,12 +122,12 @@ public: format.cbSize = 0; valid = true; end: - FILESYSTEM_freeMemory(&mem); + VVV_free(mem); } void Dispose() { - SDL_free(wav_buffer); + VVV_free(wav_buffer); } void Play() @@ -146,7 +147,7 @@ end: FAudioVoice_GetVoiceDetails(voices[i], &details); if (details.InputChannels != format.nChannels) { - FAudioVoice_DestroyVoice(voices[i]); + VVV_freefunc(FAudioVoice_DestroyVoice, voices[i]); FAudio_CreateSourceVoice(faudioctx, &voices[i], &format, 0, 2.0f, NULL, NULL, NULL); } const FAudioBuffer faudio_buffer = { @@ -221,10 +222,9 @@ end: { for (int i = 0; i < VVV_MAX_CHANNELS; i++) { - FAudioVoice_DestroyVoice(voices[i]); + VVV_freefunc(FAudioVoice_DestroyVoice, voices[i]); } - SDL_free(voices); - voices = NULL; + VVV_free(voices); } } @@ -263,8 +263,7 @@ public: if (vorbis == NULL) { vlog_error("Unable to create Vorbis handle, error %d", err); - SDL_free(read_buf); - read_buf = NULL; + VVV_free(read_buf); goto end; } vorbis_info = stb_vorbis_get_info(vorbis); @@ -295,13 +294,12 @@ end: void Dispose() { stb_vorbis_close(vorbis); - SDL_free(read_buf); - SDL_free(decoded_buf_playing); - SDL_free(decoded_buf_reserve); + VVV_free(read_buf); + VVV_free(decoded_buf_playing); + VVV_free(decoded_buf_reserve); if (!IsHalted()) { - FAudioVoice_DestroyVoice(musicVoice); - musicVoice = NULL; + VVV_freefunc(FAudioVoice_DestroyVoice, musicVoice); } } @@ -358,8 +356,7 @@ end: if (!IsHalted()) { FAudioSourceVoice_FlushSourceBuffers(musicVoice); - FAudioVoice_DestroyVoice(musicVoice); - musicVoice = NULL; + VVV_freefunc(FAudioVoice_DestroyVoice, musicVoice); paused = true; } } @@ -535,11 +532,11 @@ end: t->loopbegin = 0; t->looplength = 0; loopend = 0; - SDL_free(param); + VVV_free(param); break; } - SDL_free(param); + VVV_free(param); } if (loopend != 0) { @@ -792,14 +789,8 @@ void musicclass::destroy(void) pppppp_blob.clear(); mmmmmm_blob.clear(); - if (masteringvoice != NULL) - { - FAudioVoice_DestroyVoice(masteringvoice); - } - if (faudioctx != NULL) - { - FAudio_Release(faudioctx); - } + VVV_freefunc(FAudioVoice_DestroyVoice, masteringvoice); + VVV_freefunc(FAudio_Release, faudioctx); } void musicclass::play(int t) diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index 29a17720..2f09574d 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -3,6 +3,7 @@ #include +#include "Alloc.h" #include "Constants.h" #include "FileSystemUtils.h" #include "Game.h" @@ -81,17 +82,11 @@ void Screen::init(const struct ScreenSettings* settings) void Screen::destroy(void) { -#define X(CLEANUP, POINTER) \ - CLEANUP(POINTER); \ - POINTER = NULL; - /* Order matters! */ - X(SDL_DestroyTexture, m_screenTexture); - X(SDL_FreeSurface, m_screen); - X(SDL_DestroyRenderer, m_renderer); - X(SDL_DestroyWindow, m_window); - -#undef X + VVV_freefunc(SDL_DestroyTexture, m_screenTexture); + VVV_freefunc(SDL_FreeSurface, m_screen); + VVV_freefunc(SDL_DestroyRenderer, m_renderer); + VVV_freefunc(SDL_DestroyWindow, m_window); } void Screen::GetSettings(struct ScreenSettings* settings) @@ -126,7 +121,7 @@ void Screen::LoadIcon(void) return; } SDL_SetWindowIcon(m_window, icon); - SDL_FreeSurface(icon); + VVV_freefunc(SDL_FreeSurface, icon); } #endif /* __APPLE__ */ @@ -279,7 +274,7 @@ void Screen::UpdateScreen(SDL_Surface* buffer, SDL_Rect* rect ) if(badSignalEffect) { - SDL_FreeSurface(buffer); + VVV_freefunc(SDL_FreeSurface, buffer); } } diff --git a/desktop_version/src/ThirdPartyDeps.c b/desktop_version/src/ThirdPartyDeps.c index 93ab76e5..c0c7b406 100644 --- a/desktop_version/src/ThirdPartyDeps.c +++ b/desktop_version/src/ThirdPartyDeps.c @@ -1,5 +1,7 @@ #include +#include "Alloc.h" + /* Handle third-party dependencies' needs here */ void* lodepng_malloc(size_t size) @@ -14,5 +16,5 @@ void* lodepng_realloc(void* ptr, size_t new_size) void lodepng_free(void* ptr) { - SDL_free(ptr); + VVV_free(ptr); } diff --git a/desktop_version/src/VFormat.c b/desktop_version/src/VFormat.c index 9676d7e2..f71766ea 100644 --- a/desktop_version/src/VFormat.c +++ b/desktop_version/src/VFormat.c @@ -4,6 +4,7 @@ #include #include +#include "Alloc.h" #include "CWrappers.h" @@ -64,8 +65,8 @@ static inline void call_with_upper(format_callback callback, void* userdata, con /* Never mind the capitalization then! Better than nothing. */ callback(userdata, string, bytes); - SDL_free(utf32); - SDL_free(utf8); + VVV_free(utf32); + VVV_free(utf8); return; } @@ -78,8 +79,8 @@ static inline void call_with_upper(format_callback callback, void* userdata, con callback(userdata, utf8, SDL_strlen(utf8)); - SDL_free(utf32); - SDL_free(utf8); + VVV_free(utf32); + VVV_free(utf8); } @@ -263,7 +264,7 @@ void vformat_cb_valist( { callback(userdata, number, SDL_strlen(number)); } - SDL_free(number); + VVV_free(number); } else { @@ -458,7 +459,7 @@ char* vformat_alloc( ) { /* Format to an automatically allocated and resized buffer. - * Caller must SDL_free. */ + * Caller must VVV_free. */ va_list args; va_start(args, args_index); diff --git a/desktop_version/src/VFormat.h b/desktop_version/src/VFormat.h index 44918531..3723524b 100644 --- a/desktop_version/src/VFormat.h +++ b/desktop_version/src/VFormat.h @@ -5,7 +5,7 @@ * - vformat_cb Calls a user-supplied callback function for each part of * the resulting string. * - vformat_buf Fills a user-supplied buffer with the result. - * - vformat_alloc Allocates a buffer with the result (caller must SDL_free). + * - vformat_alloc Allocates a buffer with the result (caller must VVV_free). * * All include the following parameters: * - format_string The string which needs placeholders to be filled in From 43bebecf3bb37b2aeacbfb5d635d1bc73e7b5f73 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 30 Nov 2022 22:35:42 -0800 Subject: [PATCH 19/19] Make room names own their own memory This makes it so room names are no longer pointers to someone else's memory, and instead to set them you use `mapclass::setroomname`. If the string is short enough to fit in a static, no-alloc buffer, then it gets copied there. Otherwise, a new heap allocation is made that duplicates the string, and the new pointer is used instead. This makes it possible for room names to contain arbitrary data whose origin is temporary (e.g. from a script command that could be added in the future). --- desktop_version/src/Map.cpp | 56 +++++++++++++++++++++++++++--------- desktop_version/src/Map.h | 3 ++ desktop_version/src/main.cpp | 1 + 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index d278c28c..674e464f 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -1,6 +1,7 @@ #define MAP_DEFINITION #include "Map.h" +#include "Alloc.h" #include "Constants.h" #include "CustomLevels.h" #include "Entity.h" @@ -80,10 +81,18 @@ mapclass::mapclass(void) nexttowercolour_set = false; - roomname = ""; + setroomname(""); hiddenname = ""; } +static char roomname_static[SCREEN_WIDTH_CHARS]; +static char* roomname_heap; + +void mapclass::destroy(void) +{ + VVV_free(roomname_heap); +} + //Areamap starts at 100,100 and extends 20x20 const int mapclass::areamap[] = { 1,2,2,2,2,2,2,2,0,3,0,0,0,4,4,4,4,4,4,4, @@ -163,6 +172,25 @@ void mapclass::settrinket(int x, int y) shinytrinkets.push_back(temp); } +void mapclass::setroomname(const char* name) +{ + VVV_free(roomname_heap); + + const size_t size = SDL_strlcpy( + roomname_static, name, sizeof(roomname_static) + ) + 1; + roomname = roomname_static; + + if (size > sizeof(roomname_static)) + { + roomname_heap = SDL_strdup(name); + if (roomname_heap != NULL) + { + roomname = roomname_heap; + } + } +} + void mapclass::resetmap(void) { //clear the explored area of the map @@ -1386,7 +1414,7 @@ void mapclass::loadlevel(int rx, int ry) obj.customplatformtile=0; obj.vertplatforms = false; obj.horplatforms = false; - roomname = ""; + setroomname(""); hiddenname = ""; background = 1; warpx = false; @@ -1518,7 +1546,7 @@ void mapclass::loadlevel(int rx, int ry) extrarow = 1; const short* tmap = otherlevel.loadlevel(rx, ry); copy_short_to_int(contents, tmap, SDL_arraysize(contents)); - roomname = otherlevel.roomname; + setroomname(otherlevel.roomname); hiddenname = otherlevel.hiddenname; tileset = otherlevel.roomtileset; break; @@ -1527,7 +1555,7 @@ void mapclass::loadlevel(int rx, int ry) { const short* tmap = lablevel.loadlevel(rx, ry); copy_short_to_int(contents, tmap, SDL_arraysize(contents)); - roomname = lablevel.roomname; + setroomname(lablevel.roomname); tileset = 1; background = 2; graphics.rcol = lablevel.rcol; @@ -1540,7 +1568,7 @@ void mapclass::loadlevel(int rx, int ry) graphics.towerbg.scrolldir = 0; setbgobjlerp(graphics.towerbg); - roomname = "The Tower"; + setroomname("The Tower"); tileset = 1; background = 3; towermode = true; @@ -1574,7 +1602,7 @@ void mapclass::loadlevel(int rx, int ry) { const short* tmap = warplevel.loadlevel(rx, ry); copy_short_to_int(contents, tmap, SDL_arraysize(contents)); - roomname = warplevel.roomname; + setroomname(warplevel.roomname); tileset = 1; background = 3; graphics.rcol = warplevel.rcol; @@ -1592,7 +1620,7 @@ void mapclass::loadlevel(int rx, int ry) { const short* tmap = spacestation2.loadlevel(rx, ry); copy_short_to_int(contents, tmap, SDL_arraysize(contents)); - roomname = spacestation2.roomname; + setroomname(spacestation2.roomname); tileset = 0; break; } @@ -1600,7 +1628,7 @@ void mapclass::loadlevel(int rx, int ry) { const short* tmap = finallevel.loadlevel(rx, ry); copy_short_to_int(contents, tmap, SDL_arraysize(contents)); - roomname = finallevel.roomname; + setroomname(finallevel.roomname); tileset = 1; background = 3; graphics.backgrounddrawn = false; @@ -1630,7 +1658,7 @@ void mapclass::loadlevel(int rx, int ry) graphics.towerbg.scrolldir = 1; setbgobjlerp(graphics.towerbg); - roomname = "Panic Room"; + setroomname("Panic Room"); tileset = 1; background = 3; towermode = true; @@ -1652,7 +1680,7 @@ void mapclass::loadlevel(int rx, int ry) graphics.towerbg.scrolldir = 1; setbgobjlerp(graphics.towerbg); - roomname = "Panic Room"; + setroomname("Panic Room"); tileset = 1; background = 3; towermode = true; @@ -1681,7 +1709,7 @@ void mapclass::loadlevel(int rx, int ry) graphics.towerbg.scrolldir = 0; setbgobjlerp(graphics.towerbg); - roomname = "The Final Challenge"; + setroomname("The Final Challenge"); tileset = 1; background = 3; towermode = true; @@ -1726,7 +1754,7 @@ void mapclass::loadlevel(int rx, int ry) graphics.towerbg.scrolldir = 0; setbgobjlerp(graphics.towerbg); - roomname = "The Final Challenge"; + setroomname("The Final Challenge"); tileset = 1; background = 3; towermode = true; @@ -1759,7 +1787,7 @@ void mapclass::loadlevel(int rx, int ry) { const short* tmap = finallevel.loadlevel(rx, ry); copy_short_to_int(contents, tmap, SDL_arraysize(contents)); - roomname = finallevel.roomname; + setroomname(finallevel.roomname); tileset = 2; if (rx == 108) { @@ -1842,7 +1870,7 @@ void mapclass::loadlevel(int rx, int ry) break; } - roomname = room->roomname.c_str(); + setroomname(room->roomname.c_str()); extrarow = 1; const int* tmap = cl.loadlevel(rx, ry); SDL_memcpy(contents, tmap, sizeof(contents)); diff --git a/desktop_version/src/Map.h b/desktop_version/src/Map.h index 3a439f3e..8268e7bf 100644 --- a/desktop_version/src/Map.h +++ b/desktop_version/src/Map.h @@ -22,6 +22,7 @@ class mapclass { public: mapclass(void); + void destroy(void); int getwidth(void); @@ -33,6 +34,8 @@ public: void settrinket(int x, int y); + void setroomname(const char* name); + void resetmap(void); void resetnames(void); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 25d4779f..b3fda94d 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -755,6 +755,7 @@ static void cleanup(void) graphics.destroy_buffers(); graphics.destroy(); music.destroy(); + map.destroy(); NETWORK_shutdown(); SDL_Quit(); FILESYSTEM_deinit();