Move MxDirectDraw and MxDirect3D to mxdirectx (#413)

This commit is contained in:
Christian Semmler 2024-01-07 12:07:22 -05:00 committed by GitHub
parent 8db36722d8
commit bb7e4df11b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 94 deletions

View file

@ -18,7 +18,7 @@ jobs:
ISLE/*.cpp ISLE/*.h \
LEGO1/*.cpp LEGO1/*.h \
LEGO1/3dmanager/*.cpp LEGO1/3dmanager/*.h \
LEGO1/mxdirectx/*.h \
LEGO1/mxdirectx/*.cpp LEGO1/mxdirectx/*.h \
LEGO1/mxstl/*.h \
LEGO1/realtime/*.cpp LEGO1/realtime/*.h \
LEGO1/tgl/*.h \

View file

@ -116,8 +116,8 @@ add_library(lego1 SHARED
LEGO1/mxcontrolpresenter.cpp
LEGO1/mxcore.cpp
LEGO1/mxcriticalsection.cpp
LEGO1/mxdirect3d.cpp
LEGO1/mxdirectdraw.cpp
LEGO1/mxdirectx/mxdirect3d.cpp
LEGO1/mxdirectx/mxdirectdraw.cpp
LEGO1/mxdiskstreamcontroller.cpp
LEGO1/mxdiskstreamprovider.cpp
LEGO1/mxdisplaysurface.cpp

View file

@ -12,7 +12,6 @@
#include "legovideomanager.h"
#include "legoworldpresenter.h"
#include "mxbackgroundaudiomanager.h"
#include "mxdirectdraw.h"
#include "mxdsaction.h"
#include "mxomnicreateflags.h"
#include "mxomnicreateparam.h"

View file

@ -3,7 +3,7 @@
#include "3dmanager/lego3dmanager.h"
#include "decomp.h"
#include "mxdirect3d.h"
#include "mxdirectx/mxdirect3d.h"
#include "mxdirectx/mxstopwatch.h"
#include "mxunknown100d9d00.h"
#include "mxvideomanager.h"

View file

@ -38,7 +38,6 @@ BOOL MxDirect3D::Create(
)
{
BOOL success = FALSE;
BOOL ret = MxDirectDraw::Create(
hWnd,
fullscreen_1,
@ -101,7 +100,7 @@ void MxDirect3D::DestroyButNotDirectDraw()
// FUNCTION: LEGO1 0x1009b2d0
BOOL MxDirect3D::CreateIDirect3D()
{
MxResult ret = IDirect3D_QueryInterface(m_pDirectDraw, IID_IDirect3D2, (LPVOID*) &m_pDirect3d);
HRESULT ret = IDirect3D_QueryInterface(m_pDirectDraw, IID_IDirect3D2, (LPVOID*) &m_pDirect3d);
if (ret) {
Error("Creation of IDirect3D failed", ret);
@ -149,7 +148,7 @@ BOOL MxDirect3D::D3DSetMode()
MxDirectDraw::Mode mode = m_currentMode;
if (m_bFullScreen && !IsSupportedMode(mode.m_width, mode.m_height, mode.m_bitsPerPixel)) {
if (m_bFullScreen && !IsSupportedMode(mode.width, mode.height, mode.bitsPerPixel)) {
Error("This device cannot support the current display mode", DDERR_GENERIC);
return FALSE;
}
@ -162,10 +161,10 @@ BOOL MxDirect3D::D3DSetMode()
desc.dwSize = sizeof(desc);
if (backBuffer->Lock(NULL, &desc, DDLOCK_WAIT, NULL) == DD_OK) {
MxU8* surface = (MxU8*) desc.lpSurface;
unsigned char* surface = (unsigned char*) desc.lpSurface;
for (MxS32 i = mode.m_height; i > 0; i--) {
memset(surface, 0, mode.m_width * desc.ddpfPixelFormat.dwRGBBitCount / 8);
for (int i = mode.height; i > 0; i--) {
memset(surface, 0, mode.width * desc.ddpfPixelFormat.dwRGBBitCount / 8);
surface += desc.lPitch;
}
@ -180,10 +179,10 @@ BOOL MxDirect3D::D3DSetMode()
desc.dwSize = sizeof(desc);
if (frontBuffer->Lock(NULL, &desc, DDLOCK_WAIT, NULL) == DD_OK) {
MxU8* surface = (MxU8*) desc.lpSurface;
unsigned char* surface = (unsigned char*) desc.lpSurface;
for (MxS32 i = mode.m_height; i > 0; i--) {
memset(surface, 0, mode.m_width * desc.ddpfPixelFormat.dwRGBBitCount / 8);
for (int i = mode.height; i > 0; i--) {
memset(surface, 0, mode.width * desc.ddpfPixelFormat.dwRGBBitCount / 8);
surface += desc.lPitch;
}
@ -229,7 +228,7 @@ BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_dri
}
MxAssignedDevice* assignedDevice = new MxAssignedDevice;
MxS32 i = 0;
int i = 0;
for (list<MxDriver>::iterator it = p_deviceEnumerate.m_list.begin(); it != p_deviceEnumerate.m_list.end(); it++) {
MxDriver& driver = *it;
@ -248,13 +247,13 @@ BOOL MxDirect3D::SetDevice(MxDeviceEnumerate& p_deviceEnumerate, MxDriver* p_dri
assignedDevice->m_deviceInfo->m_modeArray =
new MxDirectDraw::Mode[assignedDevice->m_deviceInfo->m_count];
MxS32 j = 0;
int j = 0;
for (list<MxDisplayMode>::iterator it2 = driver.m_displayModes.begin();
it2 != driver.m_displayModes.end();
it2++) {
assignedDevice->m_deviceInfo->m_modeArray[j].m_width = (*it2).m_width;
assignedDevice->m_deviceInfo->m_modeArray[j].m_height = (*it2).m_height;
assignedDevice->m_deviceInfo->m_modeArray[j].m_bitsPerPixel = (*it2).m_bitsPerPixel;
assignedDevice->m_deviceInfo->m_modeArray[j].width = (*it2).m_width;
assignedDevice->m_deviceInfo->m_modeArray[j].height = (*it2).m_height;
assignedDevice->m_deviceInfo->m_modeArray[j].bitsPerPixel = (*it2).m_bitsPerPixel;
j++;
}
}
@ -556,19 +555,19 @@ HRESULT MxDeviceEnumerate::EnumDevicesCallback(
}
// FUNCTION: LEGO1 0x1009c6c0
MxResult MxDeviceEnumerate::DoEnumerate()
int MxDeviceEnumerate::DoEnumerate()
{
if (m_initialized)
return FAILURE;
return -1;
HRESULT ret = DirectDrawEnumerate(DirectDrawEnumerateCallback, this);
if (ret) {
if (ret != DD_OK) {
BuildErrorString("DirectDrawEnumerate returned error %s\n", EnumerateErrorToString(ret));
return FAILURE;
return -1;
}
m_initialized = TRUE;
return SUCCESS;
return 0;
}
// FUNCTION: LEGO1 0x1009c710
@ -589,13 +588,13 @@ const char* MxDeviceEnumerate::EnumerateErrorToString(HRESULT p_error)
}
// FUNCTION: LEGO1 0x1009ce60
MxS32 MxDeviceEnumerate::ParseDeviceName(const char* p_deviceId)
int MxDeviceEnumerate::ParseDeviceName(const char* p_deviceId)
{
if (!m_initialized)
return -1;
MxS32 num = -1;
MxS32 hex[4];
int num = -1;
int hex[4];
if (sscanf(p_deviceId, "%d 0x%x 0x%x 0x%x 0x%x", &num, &hex[0], &hex[1], &hex[2], &hex[3]) != 5)
return -1;
@ -606,7 +605,7 @@ MxS32 MxDeviceEnumerate::ParseDeviceName(const char* p_deviceId)
GUID guid;
memcpy(&guid, hex, sizeof(guid));
MxS32 result = ProcessDeviceBytes(num, guid);
int result = ProcessDeviceBytes(num, guid);
if (result < 0)
return ProcessDeviceBytes(-1, guid);
@ -614,19 +613,19 @@ MxS32 MxDeviceEnumerate::ParseDeviceName(const char* p_deviceId)
}
// FUNCTION: LEGO1 0x1009cf20
MxS32 MxDeviceEnumerate::ProcessDeviceBytes(MxS32 p_deviceNum, GUID& p_guid)
int MxDeviceEnumerate::ProcessDeviceBytes(int p_deviceNum, GUID& p_guid)
{
if (!m_initialized)
return -1;
MxS32 i = 0;
MxS32 j = 0;
int i = 0;
int j = 0;
struct GUID4 {
MxS32 m_data1;
MxS32 m_data2;
MxS32 m_data3;
MxS32 m_data4;
int m_data1;
int m_data2;
int m_data3;
int m_data4;
};
static_assert(sizeof(GUID4) == sizeof(GUID), "Equal size");
@ -658,10 +657,10 @@ MxS32 MxDeviceEnumerate::ProcessDeviceBytes(MxS32 p_deviceNum, GUID& p_guid)
}
// FUNCTION: LEGO1 0x1009d030
MxResult MxDeviceEnumerate::GetDevice(MxS32 p_deviceNum, MxDriver*& p_driver, MxDevice*& p_device)
int MxDeviceEnumerate::GetDevice(int p_deviceNum, MxDriver*& p_driver, MxDevice*& p_device)
{
if (p_deviceNum >= 0 && m_initialized) {
MxS32 i = 0;
int i = 0;
for (list<MxDriver>::iterator it = m_list.begin(); it != m_list.end(); it++) {
p_driver = &*it;
@ -669,20 +668,20 @@ MxResult MxDeviceEnumerate::GetDevice(MxS32 p_deviceNum, MxDriver*& p_driver, Mx
for (list<MxDevice>::iterator it2 = p_driver->m_devices.begin(); it2 != p_driver->m_devices.end(); it2++) {
if (i == p_deviceNum) {
p_device = &*it2;
return SUCCESS;
return 0;
}
i++;
}
}
return FAILURE;
return -1;
}
return FAILURE;
return -1;
}
// FUNCTION: LEGO1 0x1009d0d0
MxS32 MxDeviceEnumerate::FUN_1009d0d0()
int MxDeviceEnumerate::FUN_1009d0d0()
{
if (!m_initialized)
return -1;
@ -690,10 +689,10 @@ MxS32 MxDeviceEnumerate::FUN_1009d0d0()
if (m_list.empty())
return -1;
MxS32 i = 0;
MxS32 j = 0;
MxS32 k = -1;
MxU32 und = FUN_1009d1a0();
int i = 0;
int j = 0;
int k = -1;
unsigned int und = FUN_1009d1a0();
for (list<MxDriver>::iterator it = m_list.begin();; it++) {
if (it == m_list.end())
@ -729,10 +728,10 @@ undefined4 MxDeviceEnumerate::FUN_1009d1e0()
}
// FUNCTION: LEGO1 0x1009d210
MxResult MxDeviceEnumerate::FUN_1009d210()
int MxDeviceEnumerate::FUN_1009d210()
{
if (!m_initialized)
return FAILURE;
return -1;
for (list<MxDriver>::iterator it = m_list.begin(); it != m_list.end();) {
MxDriver& driver = *it;
@ -756,11 +755,11 @@ MxResult MxDeviceEnumerate::FUN_1009d210()
}
}
return m_list.empty() ? FAILURE : SUCCESS;
return m_list.empty() ? -1 : 0;
}
// FUNCTION: LEGO1 0x1009d370
MxBool MxDeviceEnumerate::FUN_1009d370(MxDriver& p_driver)
unsigned char MxDeviceEnumerate::FUN_1009d370(MxDriver& p_driver)
{
for (list<MxDisplayMode>::iterator it = p_driver.m_displayModes.begin(); it != p_driver.m_displayModes.end();
it++) {
@ -774,7 +773,7 @@ MxBool MxDeviceEnumerate::FUN_1009d370(MxDriver& p_driver)
}
// FUNCTION: LEGO1 0x1009d3d0
MxBool MxDeviceEnumerate::FUN_1009d3d0(MxDevice& p_device)
unsigned char MxDeviceEnumerate::FUN_1009d3d0(MxDevice& p_device)
{
if (m_list.size() <= 0)
return FALSE;

View file

@ -1,10 +1,9 @@
#ifndef MXDIRECT3D_H
#define MXDIRECT3D_H
#include "../mxstl/stlcompat.h"
#include "decomp.h"
#include "mxdirectdraw.h"
#include "mxstl/stlcompat.h"
#include "mxtypes.h"
#include <d3d.h>
@ -21,14 +20,14 @@ class MxAssignedDevice {
MxAssignedDevice();
~MxAssignedDevice();
inline MxU32 GetFlags() { return m_flags; }
inline unsigned int GetFlags() { return m_flags; }
inline D3DDEVICEDESC& GetDesc() { return m_desc; }
friend class MxDirect3D;
private:
GUID m_guid; // 0x00
MxU32 m_flags; // 0x10
unsigned int m_flags; // 0x10
D3DDEVICEDESC m_desc; // 0x14
MxDirectDraw::DeviceModesInfo* m_deviceInfo; // 0xe0
};
@ -101,8 +100,8 @@ struct MxDevice {
D3DDEVICEDESC m_HWDesc; // 0x0c
D3DDEVICEDESC m_HELDesc; // 0xd8
MxBool operator==(MxDevice) const { return TRUE; }
MxBool operator<(MxDevice) const { return TRUE; }
int operator==(MxDevice) const { return 0; }
int operator<(MxDevice) const { return 0; }
};
// SIZE 0x0c
@ -111,8 +110,8 @@ struct MxDisplayMode {
DWORD m_height; // 0x04
DWORD m_bitsPerPixel; // 0x08
MxBool operator==(MxDisplayMode) const { return TRUE; }
MxBool operator<(MxDisplayMode) const { return TRUE; }
int operator==(MxDisplayMode) const { return 0; }
int operator<(MxDisplayMode) const { return 0; }
};
// SIZE 0x190
@ -130,8 +129,8 @@ struct MxDriver {
list<MxDevice> m_devices; // 0x178
list<MxDisplayMode> m_displayModes; // 0x184
MxBool operator==(MxDriver) const { return TRUE; }
MxBool operator<(MxDriver) const { return TRUE; }
int operator==(MxDriver) const { return 0; }
int operator<(MxDriver) const { return 0; }
};
// clang-format off
@ -178,7 +177,7 @@ class MxDeviceEnumerate {
// FUNCTION: LEGO1 0x1009c010
~MxDeviceEnumerate() {}
virtual MxResult DoEnumerate(); // vtable+0x00
virtual int DoEnumerate(); // vtable+0x00
BOOL EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName);
HRESULT EnumDisplayModesCallback(LPDDSURFACEDESC p_ddsd);
@ -190,13 +189,13 @@ class MxDeviceEnumerate {
LPD3DDEVICEDESC p_HELDesc
);
const char* EnumerateErrorToString(HRESULT p_error);
MxS32 ParseDeviceName(const char* p_deviceId);
MxS32 ProcessDeviceBytes(MxS32 p_deviceNum, GUID& p_guid);
MxResult GetDevice(MxS32 p_deviceNum, MxDriver*& p_driver, MxDevice*& p_device);
MxS32 FUN_1009d0d0();
MxResult FUN_1009d210();
MxBool FUN_1009d370(MxDriver& p_driver);
MxBool FUN_1009d3d0(MxDevice& p_device);
int ParseDeviceName(const char* p_deviceId);
int ProcessDeviceBytes(int p_deviceNum, GUID& p_guid);
int GetDevice(int p_deviceNum, MxDriver*& p_driver, MxDevice*& p_device);
int FUN_1009d0d0();
int FUN_1009d210();
unsigned char FUN_1009d370(MxDriver& p_driver);
unsigned char FUN_1009d3d0(MxDevice& p_device);
static void BuildErrorString(const char*, ...);
static BOOL CALLBACK
@ -216,8 +215,8 @@ class MxDeviceEnumerate {
friend class MxDirect3D;
private:
list<MxDriver> m_list; // 0x04
MxBool m_initialized; // 0x10
list<MxDriver> m_list; // 0x04
unsigned char m_initialized; // 0x10
};
// VTABLE: LEGO1 0x100d9cc8

View file

@ -348,9 +348,9 @@ BOOL MxDirectDraw::DDSetMode(int width, int height, int bpp)
}
if (!IsSupportedMode(width, height, bpp)) {
width = m_pCurrentDeviceModesList->m_modeArray[0].m_width;
height = m_pCurrentDeviceModesList->m_modeArray[0].m_height;
bpp = m_pCurrentDeviceModesList->m_modeArray[0].m_bitsPerPixel;
width = m_pCurrentDeviceModesList->m_modeArray[0].width;
height = m_pCurrentDeviceModesList->m_modeArray[0].height;
bpp = m_pCurrentDeviceModesList->m_modeArray[0].bitsPerPixel;
}
m_bIgnoreWMSIZE = TRUE;
@ -396,9 +396,9 @@ BOOL MxDirectDraw::DDSetMode(int width, int height, int bpp)
m_bIgnoreWMSIZE = FALSE;
}
m_currentMode.m_width = width;
m_currentMode.m_height = height;
m_currentMode.m_bitsPerPixel = bpp;
m_currentMode.width = width;
m_currentMode.height = height;
m_currentMode.bitsPerPixel = bpp;
if (!DDCreateSurfaces()) {
return FALSE;
@ -506,8 +506,8 @@ BOOL MxDirectDraw::DDCreateSurfaces()
Error("CreateSurface for window front buffer failed", result);
return FALSE;
}
ddsd.dwHeight = m_currentMode.m_height;
ddsd.dwWidth = m_currentMode.m_width;
ddsd.dwHeight = m_currentMode.height;
ddsd.dwWidth = m_currentMode.width;
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
if (m_bOnlySystemMemory)
@ -640,7 +640,7 @@ BOOL MxDirectDraw::CreateTextSurfaces()
}
m_hFont = CreateFontA(
m_currentMode.m_width <= 600 ? 12 : 24,
m_currentMode.width <= 600 ? 12 : 24,
0,
0,
0,
@ -774,8 +774,8 @@ BOOL MxDirectDraw::CreateZBuffer(DWORD memorytype, DWORD depth)
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwHeight = m_currentMode.m_height;
ddsd.dwWidth = m_currentMode.m_width;
ddsd.dwHeight = m_currentMode.height;
ddsd.dwWidth = m_currentMode.width;
ddsd.dwZBufferBitDepth = depth;
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_ZBUFFERBITDEPTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | memorytype;
@ -889,7 +889,7 @@ int MxDirectDraw::FlipToGDISurface()
}
// FUNCTION: LEGO1 0x1009e830
void MxDirectDraw::Error(const char* p_message, MxS32 p_error)
void MxDirectDraw::Error(const char* p_message, int p_error)
{
// GLOBAL: LEGO1 0x10100c70
static BOOL g_isInsideError = FALSE;

View file

@ -1,8 +1,6 @@
#ifndef MXDIRECTDRAW_H
#define MXDIRECTDRAW_H
#include "mxtypes.h"
#include <ddraw.h>
#include <windows.h>
@ -14,17 +12,14 @@ class MxDirectDraw {
// SIZE 0x0c
struct Mode {
MxS32 operator==(const Mode& p_mode) const
int operator==(const Mode& p_mode) const
{
return (
(m_width == p_mode.m_width) && (m_height == p_mode.m_height) &&
(m_bitsPerPixel == p_mode.m_bitsPerPixel)
);
return ((width == p_mode.width) && (height == p_mode.height) && (bitsPerPixel == p_mode.bitsPerPixel));
}
MxS32 m_width; // 0x00
MxS32 m_height; // 0x04
MxS32 m_bitsPerPixel; // 0x08
int width; // 0x00
int height; // 0x04
int bitsPerPixel; // 0x08
};
// SIZE 0x17c
@ -34,7 +29,7 @@ class MxDirectDraw {
GUID* m_guid; // 0x00
Mode* m_modeArray; // 0x04
MxS32 m_count; // 0x08
int m_count; // 0x08
DDCAPS m_ddcaps; // 0x0c
void* m_unk0x178; // 0x178
};
@ -68,7 +63,7 @@ class MxDirectDraw {
BOOL DDCreateSurfaces();
BOOL DDInit(BOOL fullscreen);
BOOL DDSetMode(int width, int height, int bpp);
void Error(const char* p_message, MxS32 p_error);
void Error(const char* p_message, int p_error);
BOOL GetDDSurfaceDesc(LPDDSURFACEDESC lpDDSurfDesc, LPDIRECTDRAWSURFACE lpDDSurf);
BOOL IsSupportedMode(int width, int height, int bpp);