Replace roomnames/hiddennames/glitchnames with `const char*`

Since those are all downstream recipients of either static storage or
memory that doesn't move for the duration of the custom level, it's okay
to make these be `const char*`s without having to redo any of the RAII
memory management.

mapclass::currentarea() is included in this as well. I also cleaned up
Tower.cpp's headers to fix some transitive includes because I was
removing UtilityClass.h includes from all other level files too.

The "Untitled room" names no longer show any coordinates, because doing
so would require complicated memory management that's completely
unneeded. No one will ever see them, and if they do they already know
they have a problem anyway. The only time they might be able to see them
is if they corrupted the areamap, but this was only possible in 2.2 and
previous by dying outside the room deaths array in Outside Dimension
VVVVVV, which has since been patched out. Besides, sometimes the
"Untitled room" gets overwritten by something else anyway (especially in
Finalclass.cpp), so it really, really doesn't matter.
This commit is contained in:
Misa 2021-09-12 12:48:15 -07:00
parent a10342f5e6
commit a50e8ecf48
14 changed files with 69 additions and 80 deletions

View File

@ -3,7 +3,6 @@
#include "Game.h"
#include "Entity.h"
#include "MakeAndPlay.h"
#include "UtilityClass.h"
const short* finalclass::loadlevel(int rx, int ry)
{
@ -14,8 +13,6 @@ const short* finalclass::loadlevel(int rx, int ry)
warpx = false;
warpy = false;
roomname = "Untitled room ["+help.String(rx) + "," + help.String(ry)+"]";
switch(t)
{
#if !defined(MAKEANDPLAY)

View File

@ -1,14 +1,12 @@
#ifndef FINALCLASS_H
#define FINALCLASS_H
#include <string>
class finalclass
{
public:
const short* loadlevel(int rx, int ry);
std::string roomname;
const char* roomname;
bool warpx, warpy;
};

View File

@ -3934,7 +3934,7 @@ void Game::gethardestroom(void)
{
hardestroomdeaths = currentroomdeaths;
hardestroom = map.roomname;
if (map.roomname == "glitch")
if (SDL_strcmp(map.roomname, "glitch") == 0)
{
if (roomx == 42 && roomy == 51)
{
@ -3949,7 +3949,7 @@ void Game::gethardestroom(void)
hardestroom = "The Untouchavles";
}
}
else if (map.roomname == "change")
else if (SDL_strcmp(map.roomname, "change") == 0)
{
if (roomx == 45 && roomy == 51) hardestroom =map.specialnames[3];
if (roomx == 46 && roomy == 51) hardestroom =map.specialnames[4];
@ -3957,7 +3957,7 @@ void Game::gethardestroom(void)
if (roomx == 50 && roomy == 53) hardestroom =map.specialnames[6];
if (roomx == 50 && roomy == 54) hardestroom = map.specialnames[7];
}
else if (map.roomname == "")
else if (SDL_strcmp(map.roomname, "") == 0)
{
hardestroom = map.hiddenname;
}

View File

@ -3,7 +3,6 @@
#include "Game.h"
#include "Entity.h"
#include "MakeAndPlay.h"
#include "UtilityClass.h"
const short* labclass::loadlevel(int rx, int ry)
{
@ -25,7 +24,7 @@ const short* labclass::loadlevel(int rx, int ry)
t = rx + (ry * 100);
const short* result;
rcol = 0;
roomname = "Untitled room ["+help.String(rx) + "," + help.String(ry)+"]";
roomname = "";
switch(t)
{

View File

@ -1,14 +1,12 @@
#ifndef LABCLASS_H
#define LABCLASS_H
#include <string>
class labclass
{
public:
const short* loadlevel(int rx, int ry);
std::string roomname;
const char* roomname;
int rcol;
};
#endif /* LABCLASS_H */

View File

@ -84,6 +84,9 @@ mapclass::mapclass(void)
roomtexton = false;
nexttowercolour_set = false;
roomname = "";
hiddenname = "";
}
//Areamap starts at 100,100 and extends 20x20
@ -164,159 +167,159 @@ void mapclass::transformname(int t)
{
case 3:
//Television Newsveel -> The 9 O'Clock News
if (specialnames[3] == "Television Newsveel")
if (SDL_strcmp(specialnames[3], "Television Newsveel") == 0)
{
specialnames[3] = "Television Newsvel";
}
else if (specialnames[3] == "Television Newsvel")
else if (SDL_strcmp(specialnames[3], "Television Newsvel") == 0)
{
specialnames[3] = "TelevisvonvNewsvel";
}
else if (specialnames[3] == "TelevisvonvNewsvel")
else if (SDL_strcmp(specialnames[3], "TelevisvonvNewsvel") == 0)
{
specialnames[3] = "TvlvvvsvonvNevsvel";
}
else if (specialnames[3] == "TvlvvvsvonvNevsvel")
else if (SDL_strcmp(specialnames[3], "TvlvvvsvonvNevsvel") == 0)
{
specialnames[3] = "vvvvvvsvovvNe svel";
}
else if (specialnames[3] == "vvvvvvsvovvNe svel")
else if (SDL_strcmp(specialnames[3], "vvvvvvsvovvNe svel") == 0)
{
specialnames[3] = "vhv vvv'vvovv vevl";
}
else if (specialnames[3] == "vhv vvv'vvovv vevl")
else if (SDL_strcmp(specialnames[3], "vhv vvv'vvovv vevl") == 0)
{
specialnames[3] = "vhv V v'Cvovv vewv";
}
else if (specialnames[3] == "vhv V v'Cvovv vewv")
else if (SDL_strcmp(specialnames[3], "vhv V v'Cvovv vewv") == 0)
{
specialnames[3] = "vhe 9 v'Cvovv vewv";
}
else if (specialnames[3] == "vhe 9 v'Cvovv vewv")
else if (SDL_strcmp(specialnames[3], "vhe 9 v'Cvovv vewv") == 0)
{
specialnames[3] = "vhe 9 v'Cvovv Newv";
}
else if (specialnames[3] == "vhe 9 v'Cvovv Newv")
else if (SDL_strcmp(specialnames[3], "vhe 9 v'Cvovv Newv") == 0)
{
specialnames[3] = "The 9 O'Cvovk Newv";
}
else if (specialnames[3] == "The 9 O'Cvovk Newv")
else if (SDL_strcmp(specialnames[3], "The 9 O'Cvovk Newv") == 0)
{
specialnames[3] = "The 9 O'Clock News";
}
break;
case 4:
//Vwitched -> Dial M for Murder
if (specialnames[4] == "Vwitched")
if (SDL_strcmp(specialnames[4], "Vwitched") == 0)
{
specialnames[4] = "Vwitvhed";
}
else if (specialnames[4] == "Vwitvhed")
else if (SDL_strcmp(specialnames[4], "Vwitvhed") == 0)
{
specialnames[4] = "vVwivcvedv";
}
else if (specialnames[4] == "vVwivcvedv")
else if (SDL_strcmp(specialnames[4], "vVwivcvedv") == 0)
{
specialnames[4] = "vvvwMvcvMdvv";
}
else if (specialnames[4] == "vvvwMvcvMdvv")
else if (SDL_strcmp(specialnames[4], "vvvwMvcvMdvv") == 0)
{
specialnames[4] = "DvvvwMvfvvMdvvv";
}
else if (specialnames[4] == "DvvvwMvfvvMdvvv")
else if (SDL_strcmp(specialnames[4], "DvvvwMvfvvMdvvv") == 0)
{
specialnames[4] = "Dvav Mvfvr Mdvvvv";
}
else if (specialnames[4] == "Dvav Mvfvr Mdvvvv")
else if (SDL_strcmp(specialnames[4], "Dvav Mvfvr Mdvvvv") == 0)
{
specialnames[4] = "Diav M for Mdrver";
}
else if (specialnames[4] == "Diav M for Mdrver")
else if (SDL_strcmp(specialnames[4], "Diav M for Mdrver") == 0)
{
specialnames[4] = "Dial M for Murder";
}
break;
case 5:
//Gvnsmoke -> Gunsmoke 1966
if (specialnames[5] == "Gvnsmoke")
if (SDL_strcmp(specialnames[5], "Gvnsmoke") == 0)
{
specialnames[5] = "Gvnsmove";
}
else if (specialnames[5] == "Gvnsmove")
else if (SDL_strcmp(specialnames[5], "Gvnsmove") == 0)
{
specialnames[5] = "Gvnvmovevv";
}
else if (specialnames[5] == "Gvnvmovevv")
else if (SDL_strcmp(specialnames[5], "Gvnvmovevv") == 0)
{
specialnames[5] = "Gunvmove1vv6";
}
else if (specialnames[5] == "Gunvmove1vv6")
else if (SDL_strcmp(specialnames[5], "Gunvmove1vv6") == 0)
{
specialnames[5] = "Vunsmoke 19v6";
}
else if (specialnames[5] == "Vunsmoke 19v6")
else if (SDL_strcmp(specialnames[5], "Vunsmoke 19v6") == 0)
{
specialnames[5] = "Gunsmoke 1966";
}
break;
case 6:
//Please enjoy these repeats -> In the Margins
if (specialnames[6] == "Please enjoy these repeats")
if (SDL_strcmp(specialnames[6], "Please enjoy these repeats") == 0)
{
specialnames[6] = "Please envoy theve repeats";
}
else if (specialnames[6] == "Please envoy theve repeats")
else if (SDL_strcmp(specialnames[6], "Please envoy theve repeats") == 0)
{
specialnames[6] = "Plse envoy tse rvpvas";
}
else if (specialnames[6] == "Plase envoy these rvpeas")
else if (SDL_strcmp(specialnames[6], "Plase envoy these rvpeas") == 0)
{
specialnames[6] = "Plse envoy tse rvpvas";
}
else if (specialnames[6] == "Plse envoy tse rvpvas")
else if (SDL_strcmp(specialnames[6], "Plse envoy tse rvpvas") == 0)
{
specialnames[6] = "Vl envoy te rvevs";
}
else if (specialnames[6] == "Vl envoy te rvevs")
else if (SDL_strcmp(specialnames[6], "Vl envoy te rvevs") == 0)
{
specialnames[6] = "Vv evo tv vevs";
}
else if (specialnames[6] == "Vv evo tv vevs")
else if (SDL_strcmp(specialnames[6], "Vv evo tv vevs") == 0)
{
specialnames[6] = "Iv vhv Mvrvivs";
}
else if (specialnames[6] == "Iv vhv Mvrvivs")
else if (SDL_strcmp(specialnames[6], "Iv vhv Mvrvivs") == 0)
{
specialnames[6] = "In the Margins";
}
break;
case 7:
//Try Jiggling the Antenna -> Heaven's Gate
if (specialnames[7] == "Try Jiggling the Antenna")
if (SDL_strcmp(specialnames[7], "Try Jiggling the Antenna") == 0)
{
specialnames[7] = "Try Viggling the Antenna";
}
else if (specialnames[7] == "Try Viggling the Antenna")
else if (SDL_strcmp(specialnames[7], "Try Viggling the Antenna") == 0)
{
specialnames[7] = "TryJivglvng theAvtevna";
}
else if (specialnames[7] == "TryJivglvng theAvtevna")
else if (SDL_strcmp(specialnames[7], "TryJivglvng theAvtevna") == 0)
{
specialnames[7] = "Tvvivglvng thAvtvvv";
}
else if (specialnames[7] == "Tvvivglvng thAvtvvv")
else if (SDL_strcmp(specialnames[7], "Tvvivglvng thAvtvvv") == 0)
{
specialnames[7] = "Vvvgglvnv tvnvva";
}
else if (specialnames[7] == "Vvvgglvnv tvnvva")
else if (SDL_strcmp(specialnames[7], "Vvvgglvnv tvnvva") == 0)
{
specialnames[7] = "Vvavvnvs vvtv";
}
else if (specialnames[7] == "Vvavvnvs vvtv")
else if (SDL_strcmp(specialnames[7], "Vvavvnvs vvtv") == 0)
{
specialnames[7] = "Veavvn's Gvte";
}
else if (specialnames[7] == "Veavvn's Gvte")
else if (SDL_strcmp(specialnames[7], "Veavvn's Gvte") == 0)
{
specialnames[7] = "Heaven's Gate";
}
@ -331,10 +334,10 @@ void mapclass::transformname(int t)
}
}
std::string mapclass::getglitchname(int x, int y)
const char* mapclass::getglitchname(int x, int y)
{
//Returns the name in the final area.
if (roomname == "glitch")
if (SDL_strcmp(roomname, "glitch") == 0)
{
//8 Cases!
//First, the three "glitches"
@ -371,7 +374,7 @@ std::string mapclass::getglitchname(int x, int y)
else return "The Untouchavles";
}
}
else if (roomname == "change")
else if (SDL_strcmp(roomname, "change") == 0)
{
if (finalstretch)
{
@ -1282,7 +1285,7 @@ void mapclass::spawncompanion(void)
}
}
std::string mapclass::currentarea(int t)
const char* mapclass::currentarea(int t)
{
switch(t)
{
@ -1811,7 +1814,7 @@ void mapclass::loadlevel(int rx, int ry)
break;
}
roomname = room->roomname;
roomname = room->roomname.c_str();
extrarow = 1;
const int* tmap = cl.loadlevel(rx, ry);
SDL_memcpy(contents, tmap, sizeof(contents));
@ -1921,7 +1924,7 @@ void mapclass::loadlevel(int rx, int ry)
Roomtext text;
text.x = ex / 8;
text.y = ey / 8;
text.text = ent.scriptname;
text.text = ent.scriptname.c_str();
roomtext.push_back(text);
break;
}

View File

@ -15,7 +15,7 @@
struct Roomtext
{
int x, y;
std::string text;
const char* text;
};
class mapclass
@ -35,7 +35,7 @@ public:
void transformname(int t);
std::string getglitchname(int x, int y);
const char* getglitchname(int x, int y);
void initmapdata(void);
void initcustommapdata(void);
@ -83,7 +83,7 @@ public:
void spawncompanion(void);
std::string currentarea(int t);
const char* currentarea(int t);
void loadlevel(int rx, int ry);
@ -107,8 +107,8 @@ public:
bool warpy;
std::string roomname;
std::string hiddenname;
const char* roomname;
const char* hiddenname;
//Special tower stuff
bool towermode;
@ -135,10 +135,10 @@ public:
int customzoom;
bool customshowmm;
std::string specialnames[8];
const char* specialnames[8];
int glitchmode;
int glitchdelay;
std::string glitchname;
const char* glitchname;
//final level colour cycling stuff
bool final_colormode;

View File

@ -1,15 +1,13 @@
#ifndef OTHERLEVEL_H
#define OTHERLEVEL_H
#include <string>
class otherlevelclass
{
public:
const short* loadlevel(int rx, int ry);
std::string roomname;
std::string hiddenname;
const char* roomname;
const char* hiddenname;
int roomtileset;
};

View File

@ -1739,7 +1739,7 @@ void gamerender(void)
graphics.bprint(46, 6, game.timestring(), 196, 196, 196);
}
if(map.extrarow==0 || (map.custommode && map.roomname!=""))
if(map.extrarow==0 || (map.custommode && SDL_strcmp(map.roomname, "") != 0))
{
graphics.footerrect.y = 230;
if (graphics.translucentroomname)
@ -2017,7 +2017,7 @@ void maprender(void)
//draw screen alliteration
//Roomname:
if (map.hiddenname != "")
if (SDL_strcmp(map.hiddenname, "") != 0)
{
graphics.Print(5, 2, map.hiddenname, 196, 196, 255 - help.glow, true);
}

View File

@ -3,7 +3,6 @@
#include "Game.h"
#include "Entity.h"
#include "MakeAndPlay.h"
#include "UtilityClass.h"
const short* spacestation2class::loadlevel(int rx, int ry)
{
@ -17,7 +16,7 @@ const short* spacestation2class::loadlevel(int rx, int ry)
t = rx + (ry * 100);
const short* result;
roomname = "Untitled room ["+help.String(rx) + "," + help.String(ry)+"]";
roomname = "Untitled room";
switch(t)
{

View File

@ -1,13 +1,11 @@
#ifndef SPACESTATION2_H
#define SPACESTATION2_H
#include <string>
class spacestation2class
{
public:
const short* loadlevel(int rx, int ry);
std::string roomname;
const char* roomname;
};
#endif /* SPACESTATION2_H */

View File

@ -1,7 +1,9 @@
#include "Tower.h"
#include <SDL_stdinc.h>
#include <stddef.h>
#include "MakeAndPlay.h"
#include "UtilityClass.h"
towerclass::towerclass(void)
{

View File

@ -3,7 +3,6 @@
#include "Game.h"
#include "Entity.h"
#include "MakeAndPlay.h"
#include "UtilityClass.h"
const short* warpclass::loadlevel(int rx, int ry)
{
@ -20,7 +19,7 @@ const short* warpclass::loadlevel(int rx, int ry)
warpx = false;
warpy = false;
roomname = "Untitled room ["+help.String(rx) + "," + help.String(ry)+"]";
roomname = "Untitled room";
switch(t)
{

View File

@ -1,13 +1,11 @@
#ifndef WARPCLASS_H
#define WARPCLASS_H
#include <string>
class warpclass
{
public:
const short* loadlevel(int rx, int ry);
std::string roomname;
const char* roomname;
int rcol;
bool warpx, warpy;
};