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/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/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", diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 21742fdf..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) == "") { @@ -1483,116 +1484,92 @@ 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) map.customzoom=2; - if(map.customwidth<=5 && map.customheight<=5) map.customzoom=4; - - //Set minimap offsets - if(map.customzoom==4) + map.customzoom = 1; + if (mapwidth <= 10 && mapheight <= 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 (mapwidth <= 5 && mapheight <= 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 - mapwidth); + map.custommmyoff = 18 * (5 - mapheight); + break; + case 2: + map.custommmxoff = 12 * (10 - mapwidth); + map.custommmyoff = 9 * (10 - mapheight); + break; + default: + map.custommmxoff = 6 * (20 - mapwidth); + map.custommmyoff = int(4.5 * (20 - mapheight)); + 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) + ); } } } 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/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 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/Map.cpp b/desktop_version/src/Map.cpp index 74d6a943..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" @@ -48,7 +49,6 @@ mapclass::mapclass(void) custommode=false; custommodeforreal=false; - customwidth=20; customheight=20; custommmxoff=0; custommmyoff=0; custommmxsize=0; custommmysize=0; customzoom=0; customshowmm=true; @@ -81,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, @@ -109,6 +117,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)); @@ -116,6 +148,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; @@ -124,12 +161,36 @@ 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; 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 @@ -1353,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; @@ -1485,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; @@ -1494,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; @@ -1507,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; @@ -1541,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; @@ -1559,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; } @@ -1567,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; @@ -1597,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; @@ -1619,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; @@ -1648,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; @@ -1693,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; @@ -1726,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) { @@ -1809,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 dcd2e2df..8268e7bf 100644 --- a/desktop_version/src/Map.h +++ b/desktop_version/src/Map.h @@ -22,6 +22,11 @@ class mapclass { public: mapclass(void); + void destroy(void); + + int getwidth(void); + + int getheight(void); int intpol(int a, int b, float c); @@ -29,6 +34,8 @@ public: void settrinket(int x, int y); + void setroomname(const char* name); + void resetmap(void); void resetnames(void); @@ -129,7 +136,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/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/Render.cpp b/desktop_version/src/Render.cpp index b1c9e315..bda5fdbb 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -24,6 +24,15 @@ static int tr; static int tg; static int tb; +struct MapRenderData +{ + int zoom; + int xoff; + int yoff; + int legendxoff; + int legendyoff; +}; + static inline void drawslowdowntext(void) { switch (game.slowdown) @@ -2040,6 +2049,143 @@ 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.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 += 21; + data.legendyoff += 16; + break; + case 2: + data.legendxoff += 9; + data.legendyoff += 5; + break; + default: + data.legendxoff += 3; + data.legendyoff += 1; + break; + } + + return data; +} + +static void rendermap(void) +{ +#ifndef NO_CUSTOM_LEVELS + if (map.custommode) + { + 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 */ + + graphics.drawpixeltextbox(35, 16, 250, 190, 65, 185, 207); + graphics.drawimage(1, 40, 21, false); +} + +static void rendermapfog(void) +{ + const MapRenderData data = getmaprenderdata(); + + for (int j = 0; j < map.getheight(); j++) + { + for (int i = 0; i < map.getwidth(); i++) + { + if (!map.isexplored(i, j)) + { + // Draw the fog, depending on the custom zoom size + for (int x = 0; x < data.zoom; x++) + { + for (int y = 0; y < data.zoom; y++) + { + graphics.drawimage(2, data.xoff + 40 + (x * 12) + (i * (12 * data.zoom)), data.yoff + 21 + (y * 9) + (j * (9 * data.zoom)), false); + } + } + } + } + } +} + +static void rendermaplegend(void) +{ + // Draw the map legend, aka teleports/targets/trinkets + + const MapRenderData data = getmaprenderdata(); + + const 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(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(data.legendxoff + (map.teleporters[i].x * 12 * data.zoom), data.legendyoff + (map.teleporters[i].y * 9 * data.zoom), 1126 + tile_offset); + } + } + + if (map.showtrinkets) + { + for (size_t i = 0; i < map.shinytrinkets.size(); i++) + { + if (!obj.collect[i]) + { + graphics.drawtile(data.legendxoff + (map.shinytrinkets[i].x * 12 * data.zoom), data.legendyoff + (map.shinytrinkets[i].y * 9 * data.zoom), 1086 + tile_offset); + } + } + } +} + +static void rendermapcursor(const bool flashing) +{ + const MapRenderData data = getmaprenderdata(); + + 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); + } + } + 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 (!flashing || (map.cursorstate == 2 && int(map.cursordelay / 15) % 2 == 0)) + { + 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 * 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); + } +} + void maprender(void) { ClearSurface(graphics.backBuffer); @@ -2049,8 +2195,6 @@ 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); @@ -2108,11 +2252,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++) @@ -2122,211 +2266,11 @@ 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); - } - } - } + rendermapfog(); + rendermapcursor(true); + rendermaplegend(); } break; case 1: @@ -2736,31 +2680,13 @@ 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 + + const MapRenderData data = getmaprenderdata(); if (game.useteleporter) { @@ -2769,48 +2695,21 @@ 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 + 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 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) - { - 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); - } - } - } + rendermaplegend(); + + // Highlight the currently selected teleporter 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(data.legendxoff + data.xoff + (tempx * 12 * data.zoom), data.legendyoff + data.yoff + (tempy * 9 * data.zoom), 1128 + (graphics.flipmode ? 3 : 0)); } graphics.cutscenebars(); 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/Script.cpp b/desktop_version/src/Script.cpp index 6a2cfc77..7287ede7 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2888,10 +2888,17 @@ 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 */ @@ -3543,7 +3550,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 +#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 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();