Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse cli arguments + log with SDL_Log #30

Merged
merged 9 commits into from
Jun 26, 2024
6 changes: 1 addition & 5 deletions 3rdparty/d3drm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@ add_library(d3drm-wine SHARED
texture.c
version.rc
viewport.c
d3drm.def
)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
target_sources(d3drm-wine PRIVATE d3drm32.def)
else()
target_sources(d3drm-wine PRIVATE d3drm64.def)
endif()
if(WINE_D3DRM_DYNAMIC_D3DXOF)
target_sources(d3drm-wine PRIVATE dyn_d3dxof.c dyn_d3dxof.h)
target_compile_definitions(d3drm-wine PRIVATE DYNAMIC_D3DXOF)
Expand Down
2 changes: 2 additions & 0 deletions 3rdparty/d3drm/d3drm64.def → 3rdparty/d3drm/d3drm.def
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ EXPORTS
D3DRMVectorScale
D3DRMVectorSubtract
Direct3DRMCreate
; DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
22 changes: 0 additions & 22 deletions 3rdparty/d3drm/d3drm32.def

This file was deleted.

6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ foreach(tgt IN LISTS lego1_targets)
target_include_directories(${tgt} PRIVATE $<$<BOOL:${ISLE_D3DRM_FROM_WINE}>:$<TARGET_PROPERTY:d3drm-wine,INTERFACE_INCLUDE_DIRECTORIES>>)
target_link_libraries(${tgt} PRIVATE $<$<BOOL:${ISLE_USE_DX5}>:DirectX5::DirectX5> SDL3::SDL3)
target_compile_definitions(${tgt} PRIVATE $<$<BOOL:${ISLE_USE_DX5}>:DIRECTX5_SDK>)
target_compile_definitions(${tgt} PRIVATE $<$<BOOL:${ISLE_D3DRM_FROM_WINE}>:D3DRM_WINE>)
endforeach()

# Make sure filenames are ALL CAPS
Expand All @@ -482,6 +483,10 @@ if (ISLE_BUILD_APP)
ISLE/res/isle.rc
ISLE/isleapp.cpp
)
add_custom_command(TARGET isle POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_RUNTIME_DLLS:isle> "$<TARGET_FILE_DIR:isle>"
COMMAND_EXPAND_LISTS
)

target_compile_definitions(isle PRIVATE ISLE_APP)

Expand Down Expand Up @@ -518,6 +523,7 @@ if (ISLE_BUILD_CONFIG)
target_link_libraries(config PRIVATE DirectX5::DirectX5)
endif()
target_compile_definitions(config PRIVATE DIRECT3D_VERSION=0x500)
target_link_libraries(config PRIVATE SDL3::SDL3)
target_link_libraries(config PRIVATE ddraw dxguid)
set_property(TARGET config PROPERTY OUTPUT_NAME "CONFIG")
set_property(TARGET config PROPERTY SUFFIX ".EXE")
Expand Down
65 changes: 52 additions & 13 deletions ISLE/isleapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@
#include "viewmanager/viewmanager.h"

#define SDL_MAIN_USE_CALLBACKS
#include <SDL3/SDL_filesystem.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_messagebox.h>
#include <SDL3/SDL_timer.h>
#include <iniparser.h>
#include <time.h>

Expand Down Expand Up @@ -116,6 +113,8 @@ IsleApp::IsleApp()
m_cursorCurrent = NULL;

LegoOmni::CreateInstance();

m_iniPath = NULL;
}

// FUNCTION: ISLE 0x4011a0
Expand Down Expand Up @@ -254,6 +253,16 @@ int SDL_AppInit(void** appstate, int argc, char** argv)
// Create global app instance
g_isle = new IsleApp();

if (g_isle->ParseArguments(argc, argv) != SUCCESS) {
SDL_ShowSimpleMessageBox(
SDL_MESSAGEBOX_ERROR,
"LEGO® Island Error",
"\"LEGO® Island\" failed to start. Invalid CLI arguments.",
NULL
);
return SDL_APP_FAILURE;
}

// Create window
if (g_isle->SetupWindow() != SUCCESS) {
SDL_ShowSimpleMessageBox(
Expand Down Expand Up @@ -449,12 +458,15 @@ MxResult IsleApp::SetupWindow()
m_cursorNo = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED);
SDL_SetCursor(m_cursorCurrent);

if (m_fullScreen) {
m_windowHandle = SDL_CreateWindow(WINDOW_TITLE, g_targetWidth, g_targetHeight, SDL_WINDOW_FULLSCREEN);
}
else {
m_windowHandle = SDL_CreateWindow(WINDOW_TITLE, g_targetWidth, g_targetHeight, 0);
}
SDL_PropertiesID props = SDL_CreateProperties();
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, g_targetWidth);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, g_targetHeight);
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_FULLSCREEN_BOOLEAN, m_fullScreen);
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, WINDOW_TITLE);

m_windowHandle = SDL_CreateWindowWithProperties(props);

SDL_DestroyProperties(props);

if (!m_windowHandle) {
return FAILURE;
Expand Down Expand Up @@ -502,9 +514,18 @@ void IsleApp::LoadConfig()
{
char* basePath = SDL_GetBasePath();
char* prefPath = SDL_GetPrefPath("isledecomp", "isle");
char* iniConfig = new char[strlen(prefPath) + strlen("isle.ini") + 1]();
strcat(iniConfig, prefPath);
strcat(iniConfig, "isle.ini");
char* iniConfig;
if (m_iniPath) {
iniConfig = new char[strlen(m_iniPath) + 1];
strcpy(iniConfig, m_iniPath);
}
else {
iniConfig = new char[strlen(prefPath) + strlen("isle.ini") + 1]();
strcat(iniConfig, prefPath);
strcat(iniConfig, "isle.ini");
}
SDL_Log("Reading configuration from \"%s\"", iniConfig);

dictionary* dict = iniparser_load(iniConfig);

const char* hdPath = iniparser_getstring(dict, "isle:diskpath", basePath);
Expand Down Expand Up @@ -677,3 +698,21 @@ void IsleApp::SetupCursor(Cursor p_cursor)
SDL_HideCursor();
}
}

MxResult IsleApp::ParseArguments(int argc, char** argv)
{

for (int i = 1, consumed; i < argc; i += consumed) {
consumed = -1;

if (strcmp(argv[i], "--ini") == 0 && i + 1 < argc) {
m_iniPath = argv[i + 1];
consumed = 2;
}
if (consumed <= 0) {
SDL_Log("Invalid argument(s): %s", argv[i]);
return FAILURE;
}
}
return SUCCESS;
}
4 changes: 4 additions & 0 deletions ISLE/isleapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class IsleApp {

inline void SetWindowActive(MxS32 p_windowActive) { m_windowActive = p_windowActive; }

MxResult ParseArguments(int argc, char** argv);

private:
char* m_hdPath; // 0x00
char* m_cdPath; // 0x04
Expand Down Expand Up @@ -75,6 +77,8 @@ class IsleApp {
SDL_Cursor* m_cursorBusy; // 0x80
SDL_Cursor* m_cursorNo; // 0x84
SDL_Cursor* m_cursorCurrent; // 0x88

char* m_iniPath;
};

#endif // ISLEAPP_H
25 changes: 22 additions & 3 deletions LEGO1/lego/sources/3dmanager/tglsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ DECOMP_SIZE_ASSERT(TglSurface, 0x70);

using namespace Tgl;

#ifdef D3DRM_WINE

#include <SDL3/SDL.h>

#define d3drm_wine_assert(COND) \
do { \
if (!(COND)) { \
SDL_Log( \
"%s:%d Assertion failed: \"%s\" (ignored because wine-d3d does not implement it)", \
__FILE__, \
__LINE__, \
#COND \
); \
} \
} while (0)
#else
#define d3drm_wine_assert(X) assert(X)
#endif

/////////////////////////////////////////////////////////////////////////////
// TglSurface

Expand Down Expand Up @@ -126,19 +145,19 @@ BOOL TglSurface::Create(const CreateStruct& rCreateStruct, Renderer* pRenderer,

if (textureShadeCount != -1) {
result = pRenderer->SetTextureDefaultShadeCount(textureShadeCount);
assert(Succeeded(result));
d3drm_wine_assert(Succeeded(result));
}
if (textureColorCount != -1) {
result = pRenderer->SetTextureDefaultColorCount(textureColorCount);
assert(Succeeded(result));
d3drm_wine_assert(Succeeded(result));
}

result = m_pDevice->SetColorModel(colorModel);
assert(Succeeded(result));
result = m_pDevice->SetShadingModel(shadingModel);
assert(Succeeded(result));
result = m_pDevice->SetShadeCount(shadeCount);
assert(Succeeded(result));
d3drm_wine_assert(Succeeded(result));
result = m_pDevice->SetDither(dither);
assert(Succeeded(result));

Expand Down
11 changes: 7 additions & 4 deletions LEGO1/mxdirectx/mxdirect3d.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mxdirect3d.h"

#include <stdio.h> // for vsprintf
#include <SDL3/SDL.h> // for SDL_Log
#include <stdio.h> // for vsprintf

#if !defined(MXDIRECTX_FOR_CONFIG)
DECOMP_SIZE_ASSERT(MxAssignedDevice, 0xe4);
Expand Down Expand Up @@ -176,7 +177,7 @@ BOOL MxDirect3D::D3DSetMode()
backBuffer->Unlock(desc.lpSurface);
}
else {
OutputDebugString("MxDirect3D::D3DSetMode() back lock failed\n");
SDL_Log("MxDirect3D::D3DSetMode() back lock failed\n");
}

if (m_bFullScreen) {
Expand All @@ -194,7 +195,7 @@ BOOL MxDirect3D::D3DSetMode()
frontBuffer->Unlock(desc.lpSurface);
}
else {
OutputDebugString("MxDirect3D::D3DSetMode() front lock failed\n");
SDL_Log("MxDirect3D::D3DSetMode() front lock failed\n");
}
}

Expand Down Expand Up @@ -550,7 +551,7 @@ void MxDeviceEnumerate::BuildErrorString(const char* p_format, ...)
vsprintf(buf, p_format, args);
va_end(args);

OutputDebugString(buf);
SDL_Log("%s", buf);
}

// FUNCTION: CONFIG 0x00401bf0
Expand Down Expand Up @@ -639,6 +640,8 @@ const char* MxDeviceEnumerate::EnumerateErrorToString(HRESULT p_error)
switch (p_error) {
case DD_OK:
return "No error.";
case E_NOINTERFACE:
return "No such interface supported";
case DDERR_GENERIC:
return "Generic failure.";
case DDERR_UNSUPPORTED:
Expand Down
2 changes: 1 addition & 1 deletion LEGO1/tgl/d3drm/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <d3drm.h>

#ifdef DIRECTX5_SDK
#ifndef D3DRM_WINE
typedef DWORD LPD3DRM_APPDATA;
#else
typedef LPVOID LPD3DRM_APPDATA;
Expand Down
4 changes: 2 additions & 2 deletions cmake/Findiniparser.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if(WIN32)
set(__iniparser_shared_names "libiniparser.dll.a" "libiniparser.lib")
set(__iniparser_static_names "libiniparser.a" "iniparser.lib")
set(__iniparser_shared_names "libiniparser.dll.a" "iniparser.lib")
set(__iniparser_static_names "libiniparser.a" "libiniparser.lib")
else()
if(APPLE)
set(__iniparser_shared_names "libiniparser.dylib")
Expand Down
Loading