1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Replace hardcoded temp buffer sizes with a named constant

Constants.h will house constants like the screen size and others. But
basically only the screen size for now.

Now we don't have to type that "4 bytes per 40 chars (whole screen)"
comment everywhere...
This commit is contained in:
Misa 2021-09-12 21:39:07 -07:00
parent ffe53746bc
commit ddff461a6c
3 changed files with 27 additions and 13 deletions

View file

@ -0,0 +1,18 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
/*
* FIXME: These should be used everywhere...
* FIXME: This should include more constants!
*/
#define SCREEN_WIDTH_TILES 40
#define SCREEN_HEIGHT_TILES 30
#define SCREEN_WIDTH_PIXELS (SCREEN_WIDTH_TILES * 8)
#define SCREEN_HEIGHT_PIXELS (SCREEN_WIDTH_TILES * 8)
/* 4 bytes per char, for UTF-8 encoding. */
#define SCREEN_WIDTH_CHARS (SCREEN_WIDTH_TILES * 4)
#endif /* CONSTANTS_H */

View file

@ -6,6 +6,7 @@
#include <string.h> #include <string.h>
#include <tinyxml2.h> #include <tinyxml2.h>
#include "Constants.h"
#include "CustomLevels.h" #include "CustomLevels.h"
#include "DeferCallbacks.h" #include "DeferCallbacks.h"
#include "Editor.h" #include "Editor.h"
@ -658,7 +659,7 @@ void Game::remaining_textbox(void)
{ {
const int remaining = 6 - crewrescued(); const int remaining = 6 - crewrescued();
const char* string; const char* string;
char buffer[161]; /* 4 bytes per 40 chars (whole screen) plus 1 for null terminator */ char buffer[SCREEN_WIDTH_CHARS + 1];
if (remaining == 1) if (remaining == 1)
{ {
string = " One remains "; string = " One remains ";

View file

@ -1,5 +1,6 @@
#include <SDL.h> #include <SDL.h>
#include "Constants.h"
#include "Credits.h" #include "Credits.h"
#include "CustomLevels.h" #include "CustomLevels.h"
#include "Editor.h" #include "Editor.h"
@ -113,8 +114,7 @@ static void inline drawglitchrunnertext(void)
int tempg = tg; int tempg = tg;
int tempb = tb; int tempb = tb;
/* Screen width 40 chars, 4 per char */ char buffer[SCREEN_WIDTH_CHARS + 1];
char buffer[160 + 1];
const char* mode_string; const char* mode_string;
@ -406,8 +406,7 @@ static void menurender(void)
break; break;
} }
{ {
/* Screen width 40 chars, 4 per char */ char buffer[SCREEN_WIDTH_CHARS + 1];
char buffer[160 + 1];
char soundtrack[6 + 1]; char soundtrack[6 + 1];
char letter; char letter;
if (music.usingmmmmmm) if (music.usingmmmmmm)
@ -628,8 +627,7 @@ static void menurender(void)
break; break;
case 2: case 2:
{ {
/* Screen width 40 chars, 4 per char */ char buffer[SCREEN_WIDTH_CHARS + 1];
char buffer[160 + 1];
const char* button; const char* button;
graphics.bigprint(-1, 30, "Interact Button", tr, tg, tb, true); graphics.bigprint(-1, 30, "Interact Button", tr, tg, tb, true);
@ -1793,8 +1791,7 @@ void gamerender(void)
if (game.readytotele > 100 || game.oldreadytotele > 100) if (game.readytotele > 100 || game.oldreadytotele > 100)
{ {
/* Screen width 40 chars, 4 per char */ char buffer[SCREEN_WIDTH_CHARS + 1];
char buffer[160 + 1];
static const char raw[] = "- Press %s to Teleport - "; static const char raw[] = "- Press %s to Teleport - ";
const char* final_string = interact_prompt( const char* final_string = interact_prompt(
buffer, buffer,
@ -1990,8 +1987,7 @@ void gamerender(void)
float act_alpha = graphics.lerp(game.prev_act_fade, game.act_fade) / 10.0f; float act_alpha = graphics.lerp(game.prev_act_fade, game.act_fade) / 10.0f;
if(game.act_fade>5 || game.prev_act_fade>5) if(game.act_fade>5 || game.prev_act_fade>5)
{ {
/* Screen width 40 chars, 4 per char */ char buffer[SCREEN_WIDTH_CHARS + 1];
char buffer[160 + 1];
const char* final_string = interact_prompt( const char* final_string = interact_prompt(
buffer, buffer,
sizeof(buffer), sizeof(buffer),
@ -2882,8 +2878,7 @@ void teleporterrender(void)
if (game.useteleporter) if (game.useteleporter)
{ {
/* Screen width 40 chars, 4 per char */ char buffer[SCREEN_WIDTH_CHARS + 1];
char buffer[160 + 1];
static const char raw[] = "Press %s to Teleport"; static const char raw[] = "Press %s to Teleport";
const char* final_string = interact_prompt( const char* final_string = interact_prompt(
buffer, buffer,