mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-11-16 11:37:40 +01:00
More window cleanup
This commit is contained in:
parent
64fc585cc3
commit
da67b6ebd9
@ -23,7 +23,7 @@ static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId);
|
||||
|
||||
static const struct WindowTemplate sDummyWindowTemplate = DUMMY_WIN_TEMPLATE;
|
||||
|
||||
static void nullsub_8(void)
|
||||
static void DummyWindowBgTilemap(void)
|
||||
{
|
||||
|
||||
}
|
||||
@ -42,7 +42,7 @@ bool16 InitWindows(const struct WindowTemplate *templates)
|
||||
{
|
||||
bgTilemapBuffer = GetBgTilemapBuffer(i);
|
||||
if (bgTilemapBuffer != NULL)
|
||||
gWindowBgTilemapBuffers[i] = nullsub_8;
|
||||
gWindowBgTilemapBuffers[i] = DummyWindowBgTilemap;
|
||||
else
|
||||
gWindowBgTilemapBuffers[i] = bgTilemapBuffer;
|
||||
}
|
||||
@ -84,11 +84,11 @@ bool16 InitWindows(const struct WindowTemplate *templates)
|
||||
}
|
||||
}
|
||||
|
||||
allocatedTilemapBuffer = AllocZeroed((u16)(WINDOWS_MAX * (templates[i].width * templates[i].height)));
|
||||
allocatedTilemapBuffer = AllocZeroed((u16)(32 * (templates[i].width * templates[i].height)));
|
||||
|
||||
if (allocatedTilemapBuffer == NULL)
|
||||
{
|
||||
if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != nullsub_8))
|
||||
if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap))
|
||||
{
|
||||
Free(gWindowBgTilemapBuffers[bgLayer]);
|
||||
gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer;
|
||||
@ -127,7 +127,7 @@ u16 AddWindow(const struct WindowTemplate *template)
|
||||
}
|
||||
|
||||
if (win == WINDOWS_MAX)
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
|
||||
bgLayer = template->bg;
|
||||
allocatedBaseBlock = 0;
|
||||
@ -137,7 +137,7 @@ u16 AddWindow(const struct WindowTemplate *template)
|
||||
allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0);
|
||||
|
||||
if (allocatedBaseBlock == -1)
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
}
|
||||
|
||||
if (gWindowBgTilemapBuffers[bgLayer] == NULL)
|
||||
@ -149,7 +149,7 @@ u16 AddWindow(const struct WindowTemplate *template)
|
||||
allocatedTilemapBuffer = AllocZeroed(attrib);
|
||||
|
||||
if (allocatedTilemapBuffer == NULL)
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
|
||||
for (i = 0; i < attrib; ++i)
|
||||
allocatedTilemapBuffer[i] = 0;
|
||||
@ -159,16 +159,16 @@ u16 AddWindow(const struct WindowTemplate *template)
|
||||
}
|
||||
}
|
||||
|
||||
allocatedTilemapBuffer = AllocZeroed((u16)(WINDOWS_MAX * (template->width * template->height)));
|
||||
allocatedTilemapBuffer = AllocZeroed((u16)(32 * (template->width * template->height)));
|
||||
|
||||
if (allocatedTilemapBuffer == NULL)
|
||||
{
|
||||
if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != nullsub_8))
|
||||
if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap))
|
||||
{
|
||||
Free(gWindowBgTilemapBuffers[bgLayer]);
|
||||
gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer;
|
||||
}
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
}
|
||||
|
||||
gWindows[win].tileData = allocatedTilemapBuffer;
|
||||
@ -196,7 +196,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
|
||||
}
|
||||
|
||||
if (win == WINDOWS_MAX)
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
|
||||
bgLayer = template->bg;
|
||||
allocatedBaseBlock = 0;
|
||||
@ -206,7 +206,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template)
|
||||
allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0);
|
||||
|
||||
if (allocatedBaseBlock == -1)
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
}
|
||||
|
||||
gWindows[win].window = *template;
|
||||
@ -233,10 +233,10 @@ void RemoveWindow(u8 windowId)
|
||||
|
||||
if (GetNumActiveWindowsOnBg(bgLayer) == 0)
|
||||
{
|
||||
if (gWindowBgTilemapBuffers[bgLayer] != nullsub_8)
|
||||
if (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap)
|
||||
{
|
||||
Free(gWindowBgTilemapBuffers[bgLayer]);
|
||||
gWindowBgTilemapBuffers[bgLayer] = 0;
|
||||
gWindowBgTilemapBuffers[bgLayer] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ void FreeAllWindowBuffers(void)
|
||||
|
||||
for (i = 0; i < NUM_BACKGROUNDS; ++i)
|
||||
{
|
||||
if (gWindowBgTilemapBuffers[i] != NULL && gWindowBgTilemapBuffers[i] != nullsub_8)
|
||||
if (gWindowBgTilemapBuffers[i] != NULL && gWindowBgTilemapBuffers[i] != DummyWindowBgTilemap)
|
||||
{
|
||||
Free(gWindowBgTilemapBuffers[i]);
|
||||
gWindowBgTilemapBuffers[i] = NULL;
|
||||
@ -448,16 +448,16 @@ void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16
|
||||
void CopyToWindowPixelBuffer(u8 windowId, const void *src, u16 size, u16 tileOffset)
|
||||
{
|
||||
if (size != 0)
|
||||
CpuCopy16(src, gWindows[windowId].tileData + (0x20 * tileOffset), size);
|
||||
CpuCopy16(src, gWindows[windowId].tileData + (32 * tileOffset), size);
|
||||
else
|
||||
LZ77UnCompWram(src, gWindows[windowId].tileData + (0x20 * tileOffset));
|
||||
LZ77UnCompWram(src, gWindows[windowId].tileData + (32 * tileOffset));
|
||||
}
|
||||
|
||||
// Sets all pixels within the window to the fillValue color.
|
||||
void FillWindowPixelBuffer(u8 windowId, u8 fillValue)
|
||||
{
|
||||
int fillSize = gWindows[windowId].window.width * gWindows[windowId].window.height;
|
||||
CpuFastFill8(fillValue, gWindows[windowId].tileData, 0x20 * fillSize);
|
||||
CpuFastFill8(fillValue, gWindows[windowId].tileData, 32 * fillSize);
|
||||
}
|
||||
|
||||
#define MOVE_TILES_DOWN(a) \
|
||||
@ -599,7 +599,7 @@ static u8 GetNumActiveWindowsOnBg(u8 bgId)
|
||||
return windowsNum;
|
||||
}
|
||||
|
||||
static void nullsub_9(void)
|
||||
static void DummyWindowBgTilemap8Bit(void)
|
||||
{
|
||||
|
||||
}
|
||||
@ -616,9 +616,9 @@ u16 AddWindow8Bit(const struct WindowTemplate *template)
|
||||
break;
|
||||
}
|
||||
if (windowId == WINDOWS_MAX)
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
bgLayer = template->bg;
|
||||
if (gWindowBgTilemapBuffers[bgLayer] == 0)
|
||||
if (gWindowBgTilemapBuffers[bgLayer] == NULL)
|
||||
{
|
||||
u16 attribute = GetBgAttribute(bgLayer, BG_ATTR_METRIC);
|
||||
if (attribute != 0xFFFF)
|
||||
@ -626,22 +626,22 @@ u16 AddWindow8Bit(const struct WindowTemplate *template)
|
||||
s32 i;
|
||||
memAddress = Alloc(attribute);
|
||||
if (memAddress == NULL)
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
for (i = 0; i < attribute; i++) // if we're going to zero out the memory anyway, why not call AllocZeroed?
|
||||
memAddress[i] = 0;
|
||||
gWindowBgTilemapBuffers[bgLayer] = memAddress;
|
||||
SetBgTilemapBuffer(bgLayer, memAddress);
|
||||
}
|
||||
}
|
||||
memAddress = Alloc((u16)(0x40 * (template->width * template->height)));
|
||||
memAddress = Alloc((u16)(64 * (template->width * template->height)));
|
||||
if (memAddress == NULL)
|
||||
{
|
||||
if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gWindowBgTilemapBuffers[bgLayer] != nullsub_9)
|
||||
if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap8Bit)
|
||||
{
|
||||
Free(gWindowBgTilemapBuffers[bgLayer]);
|
||||
gWindowBgTilemapBuffers[bgLayer] = NULL;
|
||||
}
|
||||
return 0xFF;
|
||||
return WINDOW_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -656,7 +656,7 @@ void FillWindowPixelBuffer8Bit(u8 windowId, u8 fillValue)
|
||||
s32 i;
|
||||
s32 size;
|
||||
|
||||
size = (u16)(0x40 * (gWindows[windowId].window.width * gWindows[windowId].window.height));
|
||||
size = (u16)(64 * (gWindows[windowId].window.width * gWindows[windowId].window.height));
|
||||
for (i = 0; i < size; i++)
|
||||
gWindows[windowId].tileData[i] = fillValue;
|
||||
}
|
||||
@ -691,7 +691,7 @@ void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u
|
||||
void CopyWindowToVram8Bit(u8 windowId, u8 mode)
|
||||
{
|
||||
sWindowPtr = &gWindows[windowId];
|
||||
sWindowSize = 0x40 * (sWindowPtr->window.width * sWindowPtr->window.height);
|
||||
sWindowSize = 64 * (sWindowPtr->window.width * sWindowPtr->window.height);
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
|
@ -37,6 +37,8 @@ struct WindowTemplate
|
||||
0, \
|
||||
}
|
||||
|
||||
#define WINDOW_NONE 0xFF
|
||||
|
||||
struct Window
|
||||
{
|
||||
struct WindowTemplate window;
|
||||
|
Loading…
Reference in New Issue
Block a user