move _countof, impove up to 96.90%

This commit is contained in:
Roman Masanin 2023-07-06 00:37:31 +02:00
parent 41604832cf
commit 475270451c
3 changed files with 34 additions and 25 deletions

View File

@ -4,6 +4,10 @@
#define DECOMP_STATIC_ASSERT(V) namespace { typedef int foo[(V)?1:-1]; }
#define DECOMP_SIZE_ASSERT(T, S) DECOMP_STATIC_ASSERT(sizeof(T) == S)
#ifndef _countof
#define _countof(arr) sizeof(arr) / sizeof(arr[0])
#endif
typedef unsigned char undefined;
typedef unsigned short undefined2;
typedef unsigned int undefined4;

View File

@ -1,10 +1,7 @@
#include "mxdirectdraw.h"
#include "decomp.h"
//TODO: make commonn place for defines like that
#ifndef _countof
#define _countof(arr) sizeof(arr) / sizeof(arr[0])
#endif
#ifndef DDSCAPS_3DDEVICE
#define DDSCAPS_3DDEVICE 0x00002000l
@ -32,6 +29,20 @@ void EnableResizing(HWND hwnd, BOOL flag)
}
}
// OFFSET: LEGO1 0x1009EFD0
MxDirectDraw::DeviceModesInfo::~DeviceModesInfo()
{
if (p_guid != NULL)
{
free(p_guid);
}
if (m_mode_ARRAY != NULL)
{
free(m_mode_ARRAY);
}
}
// OFFSET: LEGO1 0x1009D490
MxDirectDraw::MxDirectDraw()
{
@ -1038,49 +1049,54 @@ BOOL MxDirectDraw::SetPaletteEntries(
int paletteEntryCount,
BOOL fullscreen)
{
HRESULT result;
int reservedLowEntryCount = 10;
int reservedHighEntryCount = 10;
int arraySize = _countof(m_paletteEntries);
HDC hdc;
int i;
if (g_is_PALETTEINDEXED8)
{
hdc = GetDC(NULL);
GetSystemPaletteEntries(hdc, 0, _countof(m_paletteEntries), m_paletteEntries);
GetSystemPaletteEntries(hdc, 0, arraySize, m_paletteEntries);
ReleaseDC(NULL, hdc);
}
for (i = 0; i < 10; i++)
for (i = 0; i < reservedLowEntryCount; i++)
{
m_paletteEntries[i].peFlags = 0x80;
}
for (i = 10; i < 142; i++)
for (i = reservedLowEntryCount; i < 142; i++)
{
m_paletteEntries[i].peFlags = 0x44;
}
for (i = 142; i < 246; i++)
for (i = 142; i < arraySize - reservedHighEntryCount; i++)
{
m_paletteEntries[i].peFlags = 0x84;
}
for (i = 246; i < 256; i++)
for (i = arraySize - reservedHighEntryCount; i < arraySize; i++)
{
m_paletteEntries[i].peFlags = 0x80;
}
if (paletteEntryCount != 0)
{
for (i = 10; (i < paletteEntryCount) && (i < 246); i++)
for (i = reservedLowEntryCount;
(i < paletteEntryCount) && (i < arraySize - reservedHighEntryCount);
i++)
{
m_paletteEntries[i].peRed = pPaletteEntries[i].peRed;
m_paletteEntries[i].peRed = pPaletteEntries[i].peRed;
m_paletteEntries[i].peGreen = pPaletteEntries[i].peGreen;
m_paletteEntries[i].peBlue = pPaletteEntries[i].peBlue;
m_paletteEntries[i].peBlue = pPaletteEntries[i].peBlue;
}
}
if (m_pPalette != NULL)
{
HRESULT result;
result = m_pPalette->SetEntries(0, 0, _countof(m_paletteEntries), m_paletteEntries);
if (result != DD_OK)
{

View File

@ -37,18 +37,7 @@ class MxDirectDraw
DDCAPS m_ddcaps;
void* a_178;
~DeviceModesInfo()
{
if (p_guid != NULL)
{
free(p_guid);
}
if (m_mode_ARRAY != NULL)
{
free(m_mode_ARRAY);
}
}
~DeviceModesInfo();
};