1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 14:38:30 +02:00

De-duplicate number of menu text bytes

I've moved this to a define that gets declared in Game.h. I could've
made it a const int, but that's only legal in C++ mode.
This commit is contained in:
Misa 2021-03-06 18:14:44 -08:00 committed by Ethan Lee
parent 40c6a01917
commit 22d71affba
3 changed files with 7 additions and 6 deletions

View File

@ -6327,7 +6327,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
static const char tmp[] = " "; static const char tmp[] = " ";
prefix = tmp; prefix = tmp;
} }
char text[menutextbytes]; char text[MENU_TEXT_BYTES];
SDL_snprintf(text, sizeof(text), "%s%s", prefix, ed.ListOfMetaData[i].title.c_str()); SDL_snprintf(text, sizeof(text), "%s%s", prefix, ed.ListOfMetaData[i].title.c_str());
for (size_t ii = 0; text[ii] != '\0'; ++ii) for (size_t ii = 0; text[ii] != '\0'; ++ii)
{ {

View File

@ -14,10 +14,12 @@ namespace tinyxml2
class XMLElement; class XMLElement;
} }
/* 40 chars (160 bytes) covers the entire screen, + 1 more for null terminator */
#define MENU_TEXT_BYTES 161
struct MenuOption struct MenuOption
{ {
char text[161]; // 40 chars (160 bytes) covers the entire screen, + 1 more for null terminator char text[MENU_TEXT_BYTES];
// WARNING: should match Game::menutextbytes below
bool active; bool active;
}; };
@ -252,7 +254,6 @@ public:
int current_credits_list_index; int current_credits_list_index;
int menuxoff, menuyoff; int menuxoff, menuyoff;
int menuspacing; int menuspacing;
static const int menutextbytes = 161; // this is just sizeof(MenuOption::text), but doing that is non-standard
std::vector<MenuStackFrame> menustack; std::vector<MenuStackFrame> menustack;
void inline option(const char* text, bool active = true) void inline option(const char* text, bool active = true)

View File

@ -1420,10 +1420,10 @@ void Graphics::drawmenu( int cr, int cg, int cb, bool levelmenu /*= false*/ )
} }
} }
char tempstring[Game::menutextbytes]; char tempstring[MENU_TEXT_BYTES];
SDL_strlcpy(tempstring, opt.text, sizeof(tempstring)); SDL_strlcpy(tempstring, opt.text, sizeof(tempstring));
char buffer[Game::menutextbytes]; char buffer[MENU_TEXT_BYTES];
if ((int) i == game.currentmenuoption) if ((int) i == game.currentmenuoption)
{ {
if (opt.active) if (opt.active)