isle-portable/3rdparty/d3drm/d3drm_main.c

151 lines
3.6 KiB
C
Raw Normal View History

Fix mingw build + copy d3drm from wine (#25) * Fix engineConfig declaration crossing jump This fixes the following error: ``` /src/isle-portable/LEGO1/omni/src/audio/mxsoundmanager.cpp: In member function 'virtual MxResult MxSoundManager::Create(MxU32, MxBool)': /src/isle-portable/LEGO1/omni/src/audio/mxsoundmanager.cpp:119:1: error: jump to label 'done' 119 | done: | ^~~~ /src/isle-portable/LEGO1/omni/src/audio/mxsoundmanager.cpp:78:22: note: from here 78 | goto done; | ^~~~ /src/isle-portable/LEGO1/omni/src/audio/mxsoundmanager.cpp:84:26: note: crosses initialization of 'ma_engine_config engineConfig' 84 | ma_engine_config engineConfig = ma_engine_config_init(); | ^~~~~~~~~~~~ ``` * Fix 'invalid conversion from 'SDL_FunctionPointer' {aka 'void (*)()'} to 'void*' * /SAFESEH:NO is a VC thing * SDL3 is still instable * Cannot forward declare and use enum * Remove MusicManager from public LEGO1.DLL interface * Copy d3d from wine git 6c5d17af07a318d754c0c21023b2d162a0d3725d * Build d3drm-wine with 32-bit mingw * cmake: move 3rd party targets to cmake script in 3rdparty directory * cmake: bump minimum required CMake version to 3.25 to allow adding a subproject with SYSTEM automatically applied An alternative would be to use SYSTEM in target_include_directories in the 3rd party cmake script. * Add a minimal Findiniparser.cmake (not all distributions carry the upstream iniparser-config.cmake files) * Add wine's d3drm headers * cmake: merge ISLE_USE_DX5_LIBS into ISLE_USE_DX5 * cmake: Build all shared libraries in the binary output directory (to avoid PATH issues) * ci: enable msys2 mingw32 build * Disable clang-tidy on d3drm wine * Thread functions must have SDLCALL call convention * cmake: disable clang-tidy for miniaudio and libsmacker as well * Hopefully fix c++ format and skip ncc naming violation * clang-format violations keep up popping out of nowhere * No need for lego/legoomni/include * ncc: define SDLCALL as empty instead
2024-06-24 10:25:51 -04:00
/*
* Copyright 2004 Ivan Leo Puoti
* Copyright 2010 Christian Costa
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "initguid.h"
#include "d3drm_private.h"
void d3drm_object_init(struct d3drm_object *object, const char *classname)
{
object->ref = 1;
object->appdata = 0;
list_init(&object->destroy_callbacks);
object->classname = classname;
object->name = NULL;
}
struct destroy_callback
{
struct list entry;
D3DRMOBJECTCALLBACK cb;
void *ctx;
};
HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
{
struct destroy_callback *callback;
if (!cb)
return D3DRMERR_BADVALUE;
if (!(callback = malloc(sizeof(*callback))))
return E_OUTOFMEMORY;
callback->cb = cb;
callback->ctx = ctx;
list_add_head(&object->destroy_callbacks, &callback->entry);
return D3DRM_OK;
}
HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
{
struct destroy_callback *callback;
if (!cb)
return D3DRMERR_BADVALUE;
LIST_FOR_EACH_ENTRY(callback, &object->destroy_callbacks, struct destroy_callback, entry)
{
if (callback->cb == cb && callback->ctx == ctx)
{
list_remove(&callback->entry);
free(callback);
break;
}
}
return D3DRM_OK;
}
HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name)
{
DWORD req_size;
if (!size)
return E_INVALIDARG;
req_size = strlen(object->classname) + 1;
if (name && *size < req_size)
return E_INVALIDARG;
*size = req_size;
if (name)
memcpy(name, object->classname, req_size);
return D3DRM_OK;
}
HRESULT d3drm_object_get_name(struct d3drm_object *object, DWORD *size, char *name)
{
DWORD req_size;
if (!size)
return E_INVALIDARG;
req_size = object->name ? strlen(object->name) + 1 : 0;
if (name && *size < req_size)
return E_INVALIDARG;
if (name)
{
if (object->name)
memcpy(name, object->name, req_size);
else if (*size)
*name = 0;
}
*size = req_size;
return D3DRM_OK;
}
HRESULT d3drm_object_set_name(struct d3drm_object *object, const char *name)
{
DWORD req_size;
free(object->name);
object->name = NULL;
if (name)
{
req_size = strlen(name) + 1;
if (!(object->name = malloc(req_size)))
return E_OUTOFMEMORY;
memcpy(object->name, name, req_size);
}
return D3DRM_OK;
}
void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
{
struct destroy_callback *callback, *callback2;
LIST_FOR_EACH_ENTRY_SAFE(callback, callback2, &object->destroy_callbacks, struct destroy_callback, entry)
{
callback->cb(iface, callback->ctx);
list_remove(&callback->entry);
free(callback);
}
free(object->name);
object->name = NULL;
}