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

Fix up temporary variables being in topmost scope and bad style

This makes it so temporary variables have their scopes reduced (if
possible). I also didn't hesitate to fix style issues, such as their
names ("temp" is such a bad name), making them const if possible, and
any code it touched too.
This commit is contained in:
Misa 2022-12-29 22:23:48 -08:00
parent 5a6bc8bb9b
commit f24265f0fb
4 changed files with 45 additions and 45 deletions

View file

@ -591,7 +591,7 @@ void editorrender(void)
//Draw entities
obj.customplatformtile=game.customcol*12;
int temp2=edentat(ed.tilex+ (ed.levx*40),ed.tiley+ (ed.levy*30));
const int edent_under_cursor = edentat(ed.tilex + ed.levx*40, ed.tiley + ed.levy*30);
// Special case for drawing gray entities
bool custom_gray = room->tileset == 3 && room->tilecol == 6;
@ -730,7 +730,7 @@ void editorrender(void)
case 13://Warp tokens
graphics.drawsprite((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),18+(ed.entframe%2),196,196,196);
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),16,16,graphics.getRGB(255, 164, 164));
if(temp2==i)
if (i == edent_under_cursor)
{
graphics.bprint((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8)-8,
"("+help.String(customentities[i].p1/40 + 1)+","+help.String(customentities[i].p2/30 + 1)+")",210,210,255);
@ -793,7 +793,7 @@ void editorrender(void)
}
graphics.drawsprite((customentities[i].x*8)- (ed.levx*40*8), usethisy + 8, usethistile + 16, 96,96,96);
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),16,24,graphics.getRGB(164,164,164));
if(temp2==i)
if (i == edent_under_cursor)
{
graphics.bprint((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8)-8,customentities[i].scriptname,210,210,255);
}
@ -802,7 +802,7 @@ void editorrender(void)
case 19: //Script Triggers
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),customentities[i].p1*8,customentities[i].p2*8,graphics.getRGB(255,164,255));
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),8,8,graphics.getRGB(255,255,255));
if(temp2==i)
if (i == edent_under_cursor)
{
graphics.bprint((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8)-8,customentities[i].scriptname,210,210,255);
}

View file

@ -1428,7 +1428,7 @@ void Graphics::drawpartimage( int t, int xp, int yp, int wp, int hp)
void Graphics::cutscenebars(void)
{
int usethispos = lerp(oldcutscenebarspos, cutscenebarspos);
const int usethispos = lerp(oldcutscenebarspos, cutscenebarspos);
if (showcutscenebars)
{
FillRect(backBuffer, 0, 0, usethispos, 16, 0x000000);
@ -1692,7 +1692,7 @@ void Graphics::createtextboxflipme(
void Graphics::drawfade(void)
{
int usethisamount = lerp(oldfadeamount, fadeamount);
const int usethisamount = lerp(oldfadeamount, fadeamount);
switch (fademode)
{
case FADE_FULLY_BLACK:
@ -1997,7 +1997,7 @@ void Graphics::drawtrophytext(void)
if (obj.trophytext < 15)
{
int usethismult = lerp(obj.oldtrophytext, obj.trophytext);
const int usethismult = lerp(obj.oldtrophytext, obj.trophytext);
temp = (196 * usethismult) / 15;
temp2 = (196 * usethismult) / 15;
temp3 = ((255 - help.glow) * usethismult) / 15;
@ -2478,8 +2478,6 @@ void Graphics::drawentity(const int i, const int yoff)
void Graphics::drawbackground( int t )
{
int temp = 0;
switch(t)
{
case 1:
@ -2704,7 +2702,7 @@ void Graphics::drawbackground( int t )
for (int i = 10 ; i >= 0; i--)
{
temp = (i << 4) + backoffset;
const int temp = (i * 16) + backoffset;
setwarprect(160 - temp, 120 - temp, temp * 2, temp * 2);
if (i % 2 == warpskip)
{
@ -2833,7 +2831,7 @@ void Graphics::updatebackground(int t)
break;
case 3: //Warp zone (horizontal)
{
int temp = 680 + (rcol * 3);
const int temp = 680 + (rcol * 3);
backoffset+=3;
if (backoffset >= 16) backoffset -= 16;
@ -2872,7 +2870,7 @@ void Graphics::updatebackground(int t)
}
case 4: //Warp zone (vertical)
{
int temp = 760 + (rcol * 3);
const int temp = 760 + (rcol * 3);
backoffset+=3;
if (backoffset >= 16) backoffset -= 16;
@ -3008,14 +3006,16 @@ void Graphics::drawfinalmap(void)
void Graphics::drawtowermap(void)
{
int temp;
int yoff = lerp(map.oldypos, map.ypos);
const int yoff = lerp(map.oldypos, map.ypos);
for (int j = 0; j < 31; j++)
{
for (int i = 0; i < 40; i++)
{
temp = map.tower.at(i, j, yoff);
if (temp > 0) drawtile3(i * 8, (j * 8) - (yoff % 8), temp, towerbg.colstate);
const int temp = map.tower.at(i, j, yoff);
if (temp > 0)
{
drawtile3(i * 8, (j * 8) - (yoff % 8), temp, towerbg.colstate);
}
}
}
}
@ -3041,8 +3041,6 @@ void Graphics::drawtowerbackground(const TowerBG& bg_obj)
void Graphics::updatetowerbackground(TowerBG& bg_obj)
{
int temp;
if (bg_obj.bypos < 0) bg_obj.bypos += 120 * 8;
if (bg_obj.tdrawback)
@ -3053,7 +3051,7 @@ void Graphics::updatetowerbackground(TowerBG& bg_obj)
{
for (int i = 0; i < 40; i++)
{
temp = map.tower.backat(i, j, bg_obj.bypos);
const int temp = map.tower.backat(i, j, bg_obj.bypos);
drawtowertile3(i * 8, (j * 8) - (bg_obj.bypos % 8) - off, temp, bg_obj);
}
}
@ -3068,7 +3066,7 @@ void Graphics::updatetowerbackground(TowerBG& bg_obj)
{
for (int i = 0; i < 40; i++)
{
temp = map.tower.backat(i, -1, bg_obj.bypos);
int temp = map.tower.backat(i, -1, bg_obj.bypos);
drawtowertile3(i * 8, -1*8 - (bg_obj.bypos % 8), temp, bg_obj);
temp = map.tower.backat(i, 0, bg_obj.bypos);
drawtowertile3(i * 8, -(bg_obj.bypos % 8), temp, bg_obj);
@ -3078,7 +3076,7 @@ void Graphics::updatetowerbackground(TowerBG& bg_obj)
{
for (int i = 0; i < 40; i++)
{
temp = map.tower.backat(i, 29, bg_obj.bypos);
int temp = map.tower.backat(i, 29, bg_obj.bypos);
drawtowertile3(i * 8, 29*8 - (bg_obj.bypos % 8) - bg_obj.bscroll, temp, bg_obj);
temp = map.tower.backat(i, 30, bg_obj.bypos);
drawtowertile3(i * 8, 30*8 - (bg_obj.bypos % 8) - bg_obj.bscroll, temp, bg_obj);
@ -3093,8 +3091,6 @@ void Graphics::updatetowerbackground(TowerBG& bg_obj)
void Graphics::setcol( int t )
{
int temp;
//Setup predefinied colours as per our zany palette
switch(t)
{
@ -3121,9 +3117,11 @@ void Graphics::setcol( int t )
ct.colour = getRGB(trinketr, trinketg, trinketb);
break;
case 4: //Inactive savepoint
temp = (help.glow/2) + (fRandom() * 8);
{
const int temp = (help.glow/2) + (fRandom() * 8);
ct.colour = getRGB(80 + temp, 80 + temp, 80 + temp);
break;
}
case 5: //Active savepoint
ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
break;
@ -3240,7 +3238,8 @@ void Graphics::setcol( int t )
break;
//Awesome
case 40: //Teleporter in action!
temp = fRandom() * 150;
{
const int temp = fRandom() * 150;
if(temp<33)
{
ct.colour = RGBf(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
@ -3258,16 +3257,20 @@ void Graphics::setcol( int t )
ct.colour = RGBf(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
}
break;
}
case 100: //Inactive Teleporter
temp = (help.glow/2) + (fRandom() * 8);
{
const int temp = (help.glow/2) + (fRandom() * 8);
ct.colour = getRGB(42 + temp, 42 + temp, 42 + temp);
break;
}
case 101: //Active Teleporter
ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
break;
case 102: //Teleporter in action!
temp = fRandom() * 150;
{
const int temp = fRandom() * 150;
if(temp<33)
{
ct.colour = getRGB(255 - (fRandom() * 64), 64 + (fRandom() * 64), 64 + (fRandom() * 64));
@ -3285,6 +3288,7 @@ void Graphics::setcol( int t )
ct.colour = getRGB(164+(fRandom()*64),164+(fRandom()*64), 255-(fRandom()*64));
}
break;
}
default:
ct.colour = getRGB(255, 255, 255);

View file

@ -609,7 +609,7 @@ void mapclass::changefinalcol(int t)
//change the map to colour t - for the game's final stretch.
//First up, the tiles. This is just a setting:
final_mapcol = t;
int temp = 6 - t;
const int temp = 6 - t;
//Next, entities
for (size_t i = 0; i < obj.entities.size(); i++)
{
@ -1079,7 +1079,6 @@ void mapclass::gotoroom(int rx, int ry)
//Alright, change music depending on where we are:
music.changemusicarea(game.roomx - 100, game.roomy - 100);
}
int temp = rx + (ry * 100);
loadlevel(game.roomx, game.roomy);
@ -1115,13 +1114,14 @@ void mapclass::gotoroom(int rx, int ry)
//Alright! So, let's look at our lines from the previous rooms, and determine if any of them are actually
//continuations!
temp = obj.getplayer();
if(INBOUNDS_VEC(temp, obj.entities))
const int player_idx = obj.getplayer();
if (INBOUNDS_VEC(player_idx, obj.entities))
{
obj.entities[temp].oldxp = obj.entities[temp].xp;
obj.entities[temp].oldyp = obj.entities[temp].yp;
obj.entities[temp].lerpoldxp = obj.entities[temp].xp - int(obj.entities[temp].vx);
obj.entities[temp].lerpoldyp = obj.entities[temp].yp - int(obj.entities[temp].vy);
entclass* player = &obj.entities[player_idx];
player->oldxp = player->xp;
player->oldyp = player->yp;
player->lerpoldxp = player->xp - int(player->vx);
player->lerpoldyp = player->yp - int(player->vy);
}
for (size_t i = 0; i < obj.entities.size(); i++)

View file

@ -141,12 +141,12 @@ static void inline drawglitchrunnertext(const int y)
static void menurender(void)
{
int temp = 50;
switch (game.currentmenuname)
{
case Menu::mainmenu:
{
const int temp = 50;
graphics.drawsprite((160 - 96) + 0 * 32, temp, 23, tr, tg, tb);
graphics.drawsprite((160 - 96) + 1 * 32, temp, 23, tr, tg, tb);
graphics.drawsprite((160 - 96) + 2 * 32, temp, 23, tr, tg, tb);
@ -2879,8 +2879,8 @@ void maprender(void)
void teleporterrender(void)
{
ClearSurface(graphics.backBuffer);
int tempx;
int tempy;
const int telex = map.teleporters[game.teleport_to_teleporter].x;
const int teley = map.teleporters[game.teleport_to_teleporter].y;
draw_roomname_menu();
@ -2900,10 +2900,8 @@ void teleporterrender(void)
//Draw the chosen destination coordinate!
//TODO
//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 + 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);
graphics.drawrect(40 + data.xoff + (telex * 12 * data.zoom) + 1, 21 + data.yoff + (teley * 9 * data.zoom) + 1, 12 * data.zoom - 2, 9 * data.zoom - 2, 245 - (help.glow * 2), 16, 16);
graphics.drawrect(40 + data.xoff + (telex * 12 * data.zoom) + 3, 21 + data.yoff + (teley * 9 * data.zoom) + 3, 12 * data.zoom - 6, 9 * data.zoom - 6, 245 - (help.glow * 2), 16, 16);
}
// Draw the legend itself
@ -2912,11 +2910,9 @@ void teleporterrender(void)
// 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)
{
graphics.drawtile(data.legendxoff + data.xoff + (tempx * 12 * data.zoom), data.legendyoff + data.yoff + (tempy * 9 * data.zoom), 1128 + (graphics.flipmode ? 3 : 0));
graphics.drawtile(data.legendxoff + data.xoff + (telex * 12 * data.zoom), data.legendyoff + data.yoff + (teley * 9 * data.zoom), 1128 + (graphics.flipmode ? 3 : 0));
}
graphics.cutscenebars();