Document background stuff a little more

This commit is contained in:
Clownacy 2020-08-05 19:30:13 +01:00
parent b016b22a1e
commit a18be9c450
4 changed files with 35 additions and 22 deletions

View file

@ -16,10 +16,9 @@ static unsigned long color_black;
// TODO - Another function that has an incorrect stack frame // TODO - Another function that has an incorrect stack frame
BOOL InitBack(const char *fName, int type) BOOL InitBack(const char *fName, int type)
{ {
// Unused color_black = GetCortBoxColor(RGB(0, 0, 0x10)); // Unused. This may have once been used by background type 4 (the solid black background)
color_black = GetCortBoxColor(RGB(0, 0, 0x10));
// Get width and height // We're not actually loading the bitmap here - we're just reading its width/height and making sure it's really a BMP file
char path[MAX_PATH]; char path[MAX_PATH];
sprintf(path, "%s\\%s.pbm", gDataPath, fName); sprintf(path, "%s\\%s.pbm", gDataPath, fName);
@ -27,15 +26,15 @@ BOOL InitBack(const char *fName, int type)
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
// This is ridiculously platform-dependant: // This code is ridiculously platform-dependant:
// It should break on big-endian CPUs, and platforms where short isn't 16-bit and long isn't 32-bit. // It should break on big-endian CPUs, and platforms where short isn't 16-bit and long isn't 32-bit.
unsigned short bmp_header_buffer[7]; // These names aren't the original. This ruins the stack frame layout. unsigned short bmp_header_buffer[7]; // The original names for these variables are unknown. This ruins the stack frame layout.
unsigned long bmp_header_buffer2[10]; unsigned long bmp_header_buffer2[10];
fread(bmp_header_buffer, 14, 1, fp); fread(bmp_header_buffer, 14, 1, fp);
// Check if this is a valid bitmap file // Check if this is a valid bitmap file
if (bmp_header_buffer[0] != 0x4D42) // 'MB' (we use hex to prevent a compiler warning) if (bmp_header_buffer[0] != 0x4D42) // 'MB' (we use hex here to prevent a compiler warning)
{ {
#ifdef FIX_BUGS #ifdef FIX_BUGS
// The original game forgets to close fp // The original game forgets to close fp
@ -47,11 +46,13 @@ BOOL InitBack(const char *fName, int type)
fread(bmp_header_buffer2, 40, 1, fp); fread(bmp_header_buffer2, 40, 1, fp);
fclose(fp); fclose(fp);
// Get bitmap width and height
gBack.partsW = bmp_header_buffer2[1]; gBack.partsW = bmp_header_buffer2[1];
gBack.partsH = bmp_header_buffer2[2]; gBack.partsH = bmp_header_buffer2[2];
// Set background stuff and load texture gBack.flag = TRUE; // This variable is otherwise unused
gBack.flag = TRUE;
// *Now* we actually load the bitmap
if (!ReloadBitmap_File(fName, SURFACE_ID_LEVEL_BACKGROUND)) if (!ReloadBitmap_File(fName, SURFACE_ID_LEVEL_BACKGROUND))
return FALSE; return FALSE;
@ -64,12 +65,12 @@ void ActBack(void)
{ {
switch (gBack.type) switch (gBack.type)
{ {
case 5: case BACKGROUND_TYPE_AUTOSCROLL:
gBack.fx += 6 * 0x200; gBack.fx += 6 * 0x200;
break; break;
case 6: case BACKGROUND_TYPE_OUTSIDE_WITH_WIND:
case 7: case BACKGROUND_TYPE_OUTSIDE:
++gBack.fx; ++gBack.fx;
gBack.fx %= 640; gBack.fx %= 640;
break; break;
@ -83,36 +84,36 @@ void PutBack(int fx, int fy)
switch (gBack.type) switch (gBack.type)
{ {
case 0: case BACKGROUND_TYPE_STATIONARY:
for (y = 0; y < WINDOW_HEIGHT; y += gBack.partsH) for (y = 0; y < WINDOW_HEIGHT; y += gBack.partsH)
for (x = 0; x < WINDOW_WIDTH; x += gBack.partsW) for (x = 0; x < WINDOW_WIDTH; x += gBack.partsW)
PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND); PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND);
break; break;
case 1: case BACKGROUND_TYPE_MOVE_DISTANT:
for (y = -((fy / 2 / 0x200) % gBack.partsH); y < WINDOW_HEIGHT; y += gBack.partsH) for (y = -((fy / 2 / 0x200) % gBack.partsH); y < WINDOW_HEIGHT; y += gBack.partsH)
for (x = -((fx / 2 / 0x200) % gBack.partsW); x < WINDOW_WIDTH; x += gBack.partsW) for (x = -((fx / 2 / 0x200) % gBack.partsW); x < WINDOW_WIDTH; x += gBack.partsW)
PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND); PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND);
break; break;
case 2: case BACKGROUND_TYPE_MOVE_NEAR:
for (y = -((fy / 0x200) % gBack.partsH); y < WINDOW_HEIGHT; y += gBack.partsH) for (y = -((fy / 0x200) % gBack.partsH); y < WINDOW_HEIGHT; y += gBack.partsH)
for (x = -((fx / 0x200) % gBack.partsW); x < WINDOW_WIDTH; x += gBack.partsW) for (x = -((fx / 0x200) % gBack.partsW); x < WINDOW_WIDTH; x += gBack.partsW)
PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND); PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND);
break; break;
case 5: case BACKGROUND_TYPE_AUTOSCROLL:
for (y = -gBack.partsH; y < WINDOW_HEIGHT; y += gBack.partsH) for (y = -gBack.partsH; y < WINDOW_HEIGHT; y += gBack.partsH)
for (x = -((gBack.fx / 0x200) % gBack.partsW); x < WINDOW_WIDTH; x += gBack.partsW) for (x = -((gBack.fx / 0x200) % gBack.partsW); x < WINDOW_WIDTH; x += gBack.partsW)
PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND); PutBitmap4(&grcGame, x, y, &rect, SURFACE_ID_LEVEL_BACKGROUND);
break; break;
case 6: case BACKGROUND_TYPE_OUTSIDE_WITH_WIND:
case 7: case BACKGROUND_TYPE_OUTSIDE:
rect.top = 0; rect.top = 0;
rect.bottom = 88; rect.bottom = 88;
rect.left = 0; rect.left = 0;
@ -171,7 +172,7 @@ void PutFront(int fx, int fy)
switch (gBack.type) switch (gBack.type)
{ {
case 3: case BACKGROUND_TYPE_WATER:
x_1 = fx / (32 * 0x200); x_1 = fx / (32 * 0x200);
x_2 = x_1 + (((WINDOW_WIDTH + (32 - 1)) / 32) + 1); x_2 = x_1 + (((WINDOW_WIDTH + (32 - 1)) / 32) + 1);
y_1 = 0; y_1 = 0;

View file

@ -2,9 +2,21 @@
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
enum
{
BACKGROUND_TYPE_STATIONARY = 0, // Doesn't move at all
BACKGROUND_TYPE_MOVE_DISTANT = 1, // Moves at half the speed of the foreground
BACKGROUND_TYPE_MOVE_NEAR = 2, // Moves at the same speed as the foreground
BACKGROUND_TYPE_WATER = 3, // No background - draws a water foreground layer instead
BACKGROUND_TYPE_BLACK = 4, // No background - just black
BACKGROUND_TYPE_AUTOSCROLL = 5, // Constantly scrolls to the left (used by Ironhead)
BACKGROUND_TYPE_OUTSIDE_WITH_WIND = 6, // Fancy parallax scrolling, items are blown to the left (used by bkMoon)
BACKGROUND_TYPE_OUTSIDE = 7, // Fancy parallax scrolling (used by bkFog)
};
typedef struct BACK typedef struct BACK
{ {
BOOL flag; // Basically unused BOOL flag; // Unused - purpose unknown
int partsW; int partsW;
int partsH; int partsH;
int numX; int numX;

View file

@ -34,7 +34,7 @@ void ActNpc000(NPCHAR *npc)
void ActNpc001(NPCHAR *npc) void ActNpc001(NPCHAR *npc)
{ {
// In wind // In wind
if (gBack.type == 5 || gBack.type == 6) if (gBack.type == BACKGROUND_TYPE_AUTOSCROLL || gBack.type == BACKGROUND_TYPE_OUTSIDE_WITH_WIND)
{ {
if (npc->act_no == 0) if (npc->act_no == 0)
{ {

View file

@ -737,7 +737,7 @@ void ActNpc086(NPCHAR *npc)
npc->ani_no = 0; npc->ani_no = 0;
} }
if (gBack.type == 5 || gBack.type == 6) if (gBack.type == BACKGROUND_TYPE_AUTOSCROLL || gBack.type == BACKGROUND_TYPE_OUTSIDE_WITH_WIND)
{ {
if (npc->act_no == 0) if (npc->act_no == 0)
{ {
@ -818,7 +818,7 @@ void ActNpc087(NPCHAR *npc)
npc->ani_no = 0; npc->ani_no = 0;
} }
if (gBack.type == 5 || gBack.type == 6) if (gBack.type == BACKGROUND_TYPE_AUTOSCROLL || gBack.type == BACKGROUND_TYPE_OUTSIDE_WITH_WIND)
{ {
if (npc->act_no == 0) if (npc->act_no == 0)
{ {