mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 01:48:15 +03:00
Remove vmult lookup tables
There's really no need to put the y-multiplication in a lookup table. The compiler will optimize the multiplication better than putting it in a lookup table will. To improve readability and to hardcode things less, the new SCREEN_WIDTH_TILES and SCREEN_HEIGHT_TILES constant names are used, as well as adding a new TILE_IDX macro to calculate the index of a tile in a concatenated-rows (row-major in formal parlance) array. Also, tile numbers are stored in a temporary variable to improve readability as well (no more copy-pasting `contents[i + vmult[j]]` over and over again).
This commit is contained in:
@@ -3,16 +3,12 @@
|
||||
#include <SDL_stdinc.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "MakeAndPlay.h"
|
||||
|
||||
towerclass::towerclass(void)
|
||||
{
|
||||
minitowermode = false;
|
||||
//We init the lookup table:
|
||||
for (size_t i = 0; i < SDL_arraysize(vmult); i++)
|
||||
{
|
||||
vmult[i] = i * 40;
|
||||
}
|
||||
//We create a blank map
|
||||
SDL_memset(contents, 0, sizeof(contents));
|
||||
SDL_memset(back, 0, sizeof(back));
|
||||
@@ -33,7 +29,7 @@ int towerclass::backat(int xp, int yp, int yoff)
|
||||
{
|
||||
while (yp < 0) yp += 120;
|
||||
while (yp >= 120) yp -= 120;
|
||||
return back[xp + vmult[yp]];
|
||||
return back[TILE_IDX(xp, yp)];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -55,15 +51,15 @@ int towerclass::at(int xp, int yp, int yoff)
|
||||
while (yp >= 700) yp -= 700;
|
||||
if (xp >= 0 && xp < 40)
|
||||
{
|
||||
return contents[xp + vmult[yp]];
|
||||
return contents[TILE_IDX(xp, yp)];
|
||||
}
|
||||
else if (xp == -1)
|
||||
{
|
||||
return contents[vmult[yp]];
|
||||
return contents[TILE_IDX(0, yp)];
|
||||
}
|
||||
else if (xp == 40)
|
||||
{
|
||||
return contents[39 + vmult[yp]];
|
||||
return contents[TILE_IDX(39, yp)];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -80,15 +76,15 @@ int towerclass::miniat(int xp, int yp, int yoff)
|
||||
while (yp >= 100) yp -= 100;
|
||||
if (xp >= 0 && xp < 40)
|
||||
{
|
||||
return minitower[xp + vmult[yp]];
|
||||
return minitower[TILE_IDX(xp, yp)];
|
||||
}
|
||||
else if (xp == -1)
|
||||
{
|
||||
return minitower[vmult[yp]];
|
||||
return minitower[TILE_IDX(0, yp)];
|
||||
}
|
||||
else if (xp == 40)
|
||||
{
|
||||
return minitower[39 + vmult[yp]];
|
||||
return minitower[TILE_IDX(39, yp)];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user