More-accurate Map.cpp variable arrangement
This commit is contained in:
parent
d83665ff2a
commit
86412f0528
1 changed files with 37 additions and 38 deletions
75
src/Map.cpp
75
src/Map.cpp
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
MAP_DATA gMap;
|
MAP_DATA gMap;
|
||||||
|
|
||||||
static const char *code_pxma = "PXM";
|
const char *code_pxma = "PXM";
|
||||||
|
|
||||||
BOOL InitMapData2(void)
|
BOOL InitMapData2(void)
|
||||||
{
|
{
|
||||||
|
@ -26,19 +26,19 @@ BOOL InitMapData2(void)
|
||||||
|
|
||||||
BOOL LoadMapData2(const char *path_map)
|
BOOL LoadMapData2(const char *path_map)
|
||||||
{
|
{
|
||||||
unsigned char dum;
|
FILE *fp;
|
||||||
|
char check[3];
|
||||||
|
char path[MAX_PATH];
|
||||||
|
|
||||||
// Get path
|
// Get path
|
||||||
char path[MAX_PATH];
|
|
||||||
sprintf(path, "%s\\%s", gDataPath, path_map);
|
sprintf(path, "%s\\%s", gDataPath, path_map);
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
FILE *fp = fopen(path, "rb");
|
fp = fopen(path, "rb");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// Make sure file begins with "PXM"
|
// Make sure file begins with "PXM"
|
||||||
char check[3];
|
|
||||||
fread(check, 1, 3, fp);
|
fread(check, 1, 3, fp);
|
||||||
|
|
||||||
if (memcmp(check, code_pxma, 3))
|
if (memcmp(check, code_pxma, 3))
|
||||||
|
@ -47,6 +47,7 @@ BOOL LoadMapData2(const char *path_map)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned char dum;
|
||||||
fread(&dum, 1, 1, fp);
|
fread(&dum, 1, 1, fp);
|
||||||
// Get width and height
|
// Get width and height
|
||||||
// This fails on big-endian hardware, and platforms where short is not two bytes long.
|
// This fails on big-endian hardware, and platforms where short is not two bytes long.
|
||||||
|
@ -67,11 +68,13 @@ BOOL LoadMapData2(const char *path_map)
|
||||||
|
|
||||||
BOOL LoadAttributeData(const char *path_atrb)
|
BOOL LoadAttributeData(const char *path_atrb)
|
||||||
{
|
{
|
||||||
// Open file
|
FILE *fp;
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
|
|
||||||
|
// Open file
|
||||||
sprintf(path, "%s\\%s", gDataPath, path_atrb);
|
sprintf(path, "%s\\%s", gDataPath, path_atrb);
|
||||||
|
|
||||||
FILE *fp = fopen(path, "rb");
|
fp = fopen(path, "rb");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -105,10 +108,12 @@ void GetMapData(unsigned char **data, short *mw, short *ml)
|
||||||
|
|
||||||
unsigned char GetAttribute(int x, int y)
|
unsigned char GetAttribute(int x, int y)
|
||||||
{
|
{
|
||||||
|
size_t a;
|
||||||
|
|
||||||
if (x < 0 || y < 0 || x >= gMap.width || y >= gMap.length)
|
if (x < 0 || y < 0 || x >= gMap.width || y >= gMap.length)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const size_t a = *(gMap.data + x + (y * gMap.width)); // Yes, the original code really does do this instead of a regular array access
|
a = *(gMap.data + x + (y * gMap.width)); // Yes, the original code really does do this instead of a regular array access
|
||||||
return gMap.atrb[a];
|
return gMap.atrb[a];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,21 +144,17 @@ BOOL ChangeMapParts(int x, int y, unsigned char no)
|
||||||
|
|
||||||
void PutStage_Back(int fx, int fy)
|
void PutStage_Back(int fx, int fy)
|
||||||
{
|
{
|
||||||
int num_y;
|
int i, j;
|
||||||
int put_x;
|
|
||||||
int put_y;
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
int offset;
|
|
||||||
int atrb;
|
|
||||||
RECT rect;
|
RECT rect;
|
||||||
int num_x;
|
int offset;
|
||||||
|
|
||||||
// Get range to draw
|
// Get range to draw
|
||||||
num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
|
int num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
|
||||||
num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
|
int num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
|
||||||
put_x = ((fx / 0x200) + 8) / 16;
|
int put_x = ((fx / 0x200) + 8) / 16;
|
||||||
put_y = ((fy / 0x200) + 8) / 16;
|
int put_y = ((fy / 0x200) + 8) / 16;
|
||||||
|
|
||||||
|
int atrb;
|
||||||
|
|
||||||
for (j = put_y; j < put_y + num_y; ++j)
|
for (j = put_y; j < put_y + num_y; ++j)
|
||||||
{
|
{
|
||||||
|
@ -180,21 +181,17 @@ void PutStage_Back(int fx, int fy)
|
||||||
void PutStage_Front(int fx, int fy)
|
void PutStage_Front(int fx, int fy)
|
||||||
{
|
{
|
||||||
RECT rcSnack = {256, 48, 272, 64};
|
RECT rcSnack = {256, 48, 272, 64};
|
||||||
int num_y;
|
int i, j;
|
||||||
int put_x;
|
|
||||||
int put_y;
|
|
||||||
int j;
|
|
||||||
int i;
|
|
||||||
int offset;
|
|
||||||
int atrb;
|
|
||||||
RECT rect;
|
RECT rect;
|
||||||
int num_x;
|
int offset;
|
||||||
|
|
||||||
// Get range to draw
|
// Get range to draw
|
||||||
num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
|
int num_x = ((WINDOW_WIDTH + (16 - 1)) / 16) + 1;
|
||||||
num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
|
int num_y = ((WINDOW_HEIGHT + (16 - 1)) / 16) + 1;
|
||||||
put_x = ((fx / 0x200) + 8) / 16;
|
int put_x = ((fx / 0x200) + 8) / 16;
|
||||||
put_y = ((fy / 0x200) + 8) / 16;
|
int put_y = ((fy / 0x200) + 8) / 16;
|
||||||
|
|
||||||
|
int atrb;
|
||||||
|
|
||||||
for (j = put_y; j < put_y + num_y; ++j)
|
for (j = put_y; j < put_y + num_y; ++j)
|
||||||
{
|
{
|
||||||
|
@ -223,18 +220,20 @@ void PutStage_Front(int fx, int fy)
|
||||||
|
|
||||||
void PutMapDataVector(int fx, int fy)
|
void PutMapDataVector(int fx, int fy)
|
||||||
{
|
{
|
||||||
|
int i, j;
|
||||||
|
RECT rect;
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
int num_x;
|
||||||
int num_y;
|
int num_y;
|
||||||
int put_x;
|
int put_x;
|
||||||
int put_y;
|
int put_y;
|
||||||
int i;
|
|
||||||
int j;
|
static unsigned char count = 0;
|
||||||
int offset;
|
|
||||||
int atrb;
|
int atrb;
|
||||||
RECT rect;
|
|
||||||
int num_x;
|
|
||||||
|
|
||||||
// Animate the wind
|
// Animate the wind
|
||||||
static unsigned char count = 0;
|
|
||||||
count += 2;
|
count += 2;
|
||||||
|
|
||||||
// Get range to draw
|
// Get range to draw
|
||||||
|
|
Loading…
Add table
Reference in a new issue