mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
Implement (most) IDirect3DRMObject methods
This commit is contained in:
parent
4ada014dfd
commit
89a910ab6c
@ -130,7 +130,7 @@ struct CMenu {
|
||||
|
||||
struct CWinApp {
|
||||
CWinApp();
|
||||
virtual ~CWinApp() = default;
|
||||
~CWinApp() override = default;
|
||||
virtual BOOL InitInstance() = 0;
|
||||
virtual int ExitInstance();
|
||||
};
|
||||
|
||||
@ -143,7 +143,7 @@ struct IUnknown {
|
||||
virtual HRESULT QueryInterface(const GUID& riid, void** ppvObject);
|
||||
virtual ~IUnknown() = default;
|
||||
|
||||
private:
|
||||
protected:
|
||||
int m_refCount;
|
||||
};
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#define D3DRM_OK DD_OK
|
||||
#define MAXSHORT ((short) 0x7fff)
|
||||
#define SUCCEEDED(hr) ((hr) >= D3DRM_OK)
|
||||
#define D3DRMERR_NOTFOUND MAKE_DDHRESULT(785)
|
||||
|
||||
// --- Typedefs ---
|
||||
typedef float D3DVAL;
|
||||
@ -16,6 +17,9 @@ typedef unsigned long D3DRMGROUPINDEX;
|
||||
typedef DWORD D3DCOLOR, *LPD3DCOLOR;
|
||||
typedef float D3DVALUE, *LPD3DVALUE;
|
||||
|
||||
typedef struct IDirect3DRMObject* LPDIRECT3DRMOBJECT;
|
||||
typedef void (*D3DRMOBJECTCALLBACK)(LPDIRECT3DRMOBJECT obj, LPVOID arg);
|
||||
|
||||
// --- Enums ---
|
||||
#define D3DRMCOMBINE_REPLACE D3DRMCOMBINETYPE::REPLACE
|
||||
enum class D3DRMCOMBINETYPE {
|
||||
@ -140,35 +144,32 @@ struct D3DRMVERTEX {
|
||||
float tu, tv;
|
||||
};
|
||||
|
||||
struct IDirect3DRMVisual : virtual public IUnknown {};
|
||||
typedef IDirect3DRMVisual* LPDIRECT3DRMVISUAL;
|
||||
|
||||
struct IDirect3DRMObject : virtual public IUnknown {
|
||||
struct IDirect3DRMObject : public IUnknown {
|
||||
virtual HRESULT Clone(void** ppObject) = 0;
|
||||
virtual HRESULT AddDestroyCallback(void (*cb)(IDirect3DRMObject*, void*), void* arg) = 0;
|
||||
virtual HRESULT DeleteDestroyCallback(void (*cb)(IDirect3DRMObject*, void*), void* arg) = 0;
|
||||
virtual HRESULT AddDestroyCallback(D3DRMOBJECTCALLBACK callback, void* arg) = 0;
|
||||
virtual HRESULT DeleteDestroyCallback(D3DRMOBJECTCALLBACK callback, void* arg) = 0;
|
||||
virtual HRESULT SetAppData(LPD3DRM_APPDATA appData) = 0;
|
||||
virtual LPVOID GetAppData() = 0;
|
||||
virtual HRESULT SetName(const char* name) = 0;
|
||||
virtual HRESULT GetName(DWORD* size, char* name) = 0;
|
||||
virtual HRESULT GetClassName(DWORD* size, char* name) = 0;
|
||||
};
|
||||
struct IDirect3DRMTexture : virtual public IUnknown {
|
||||
virtual HRESULT AddDestroyCallback(void (*cb)(IDirect3DRMObject*, void*), void* arg) = 0;
|
||||
virtual LPVOID GetAppData() = 0;
|
||||
virtual HRESULT SetAppData(LPD3DRM_APPDATA appData) = 0;
|
||||
virtual HRESULT SetTexture(const IDirect3DRMTexture* texture) = 0;
|
||||
virtual HRESULT Changed(BOOL arg1, BOOL arg2) = 0;
|
||||
|
||||
struct IDirect3DRMVisual : public IDirect3DRMObject {};
|
||||
typedef IDirect3DRMVisual* LPDIRECT3DRMVISUAL;
|
||||
|
||||
struct IDirect3DRMTexture : public IDirect3DRMVisual {
|
||||
// virtual HRESULT SetTexture(const IDirect3DRMTexture* texture) = 0;
|
||||
virtual HRESULT Changed(BOOL pixels, BOOL palette) = 0;
|
||||
};
|
||||
typedef IDirect3DRMTexture* LPDIRECT3DRMTEXTURE;
|
||||
|
||||
struct IDirect3DRMTexture2 : public IDirect3DRMTexture {};
|
||||
typedef IDirect3DRMTexture2* LPDIRECT3DRMTEXTURE2;
|
||||
|
||||
struct IDirect3DRMMaterial : virtual public IUnknown {};
|
||||
struct IDirect3DRMMaterial : public IDirect3DRMObject {};
|
||||
typedef IDirect3DRMMaterial *LPDIRECT3DRMMATERIAL, **LPLPDIRECT3DRMMATERIAL;
|
||||
|
||||
struct IDirect3DRMMesh : virtual public IUnknown {
|
||||
struct IDirect3DRMMesh : public IDirect3DRMVisual {
|
||||
virtual HRESULT Clone(int flags, GUID iid, void** object) = 0;
|
||||
virtual HRESULT GetBox(D3DRMBOX* box) = 0;
|
||||
virtual HRESULT AddGroup(
|
||||
@ -200,24 +201,24 @@ struct IDirect3DRMMesh : virtual public IUnknown {
|
||||
virtual HRESULT GetVertices(int groupIndex, int startIndex, int count, D3DRMVERTEX* vertices) = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMLight : virtual public IUnknown {
|
||||
struct IDirect3DRMLight : public IDirect3DRMObject {
|
||||
virtual HRESULT SetColorRGB(float r, float g, float b) = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMLightArray : virtual public IUnknown {
|
||||
struct IDirect3DRMArray : public IUnknown {
|
||||
virtual DWORD GetSize() = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMLightArray : public IDirect3DRMArray {
|
||||
virtual HRESULT GetElement(int index, IDirect3DRMLight** light) const = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMVisualArray : virtual public IUnknown {
|
||||
virtual DWORD GetSize() = 0;
|
||||
struct IDirect3DRMVisualArray : public IDirect3DRMArray {
|
||||
virtual HRESULT GetElement(int index, IDirect3DRMVisual** visual) const = 0;
|
||||
};
|
||||
|
||||
typedef struct IDirect3DRMFrameArray* LPDIRECT3DRMFRAMEARRAY;
|
||||
struct IDirect3DRMFrame : virtual public IUnknown {
|
||||
virtual HRESULT SetAppData(LPD3DRM_APPDATA appData) = 0;
|
||||
virtual LPVOID GetAppData() = 0;
|
||||
struct IDirect3DRMFrame : public IDirect3DRMVisual {
|
||||
virtual HRESULT AddChild(IDirect3DRMFrame* child) = 0;
|
||||
virtual HRESULT DeleteChild(IDirect3DRMFrame* child) = 0;
|
||||
virtual HRESULT SetSceneBackgroundRGB(float r, float g, float b) = 0;
|
||||
@ -245,8 +246,7 @@ typedef IDirect3DRMFrame* LPDIRECT3DRMFRAME;
|
||||
struct IDirect3DRMFrame2 : public IDirect3DRMFrame {};
|
||||
typedef IDirect3DRMFrame2* LPDIRECT3DRMFRAME2;
|
||||
|
||||
struct IDirect3DRMFrameArray : virtual public IUnknown {
|
||||
virtual DWORD GetSize() = 0;
|
||||
struct IDirect3DRMFrameArray : public IDirect3DRMArray {
|
||||
virtual HRESULT GetElement(DWORD index, IDirect3DRMFrame** frame) = 0;
|
||||
};
|
||||
|
||||
@ -256,8 +256,7 @@ struct D3DRMPICKDESC {
|
||||
float dist;
|
||||
};
|
||||
|
||||
struct IDirect3DRMPickedArray : virtual public IUnknown {
|
||||
virtual DWORD GetSize() = 0;
|
||||
struct IDirect3DRMPickedArray : public IDirect3DRMArray {
|
||||
virtual HRESULT GetPick(
|
||||
DWORD index,
|
||||
IDirect3DRMVisual** visual,
|
||||
@ -288,19 +287,18 @@ struct IDirect3DRMViewport : public IDirect3DRMObject {
|
||||
virtual HRESULT Pick(float x, float y, LPDIRECT3DRMPICKEDARRAY* pickedArray) = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMWinDevice : virtual public IUnknown {
|
||||
struct IDirect3DRMWinDevice : virtual public IDirect3DRMObject {
|
||||
virtual HRESULT Activate() = 0;
|
||||
virtual HRESULT Paint() = 0;
|
||||
virtual void HandleActivate(WORD wParam) = 0;
|
||||
virtual void HandlePaint(void* p_dc) = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMViewportArray : virtual public IUnknown {
|
||||
virtual DWORD GetSize() = 0;
|
||||
struct IDirect3DRMViewportArray : virtual public IDirect3DRMArray {
|
||||
virtual HRESULT GetElement(int index, IDirect3DRMViewport** viewport) = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMDevice2 : virtual public IUnknown {
|
||||
struct IDirect3DRMDevice : virtual public IDirect3DRMObject {
|
||||
virtual unsigned long GetWidth() = 0;
|
||||
virtual unsigned long GetHeight() = 0;
|
||||
virtual HRESULT SetBufferCount(int count) = 0;
|
||||
@ -319,6 +317,8 @@ struct IDirect3DRMDevice2 : virtual public IUnknown {
|
||||
virtual HRESULT GetViewports(IDirect3DRMViewportArray** ppViewportArray) = 0;
|
||||
};
|
||||
|
||||
struct IDirect3DRMDevice2 : virtual public IDirect3DRMDevice {};
|
||||
|
||||
struct IDirect3DRM : virtual public IUnknown {
|
||||
virtual HRESULT CreateDeviceFromD3D(
|
||||
const IDirect3D2* d3d,
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
|
||||
struct Direct3DRMTextureImpl : public IDirect3DRMTexture2 {
|
||||
HRESULT AddDestroyCallback(void (*cb)(IDirect3DRMObject*, void*), void* arg) override { return DD_OK; }
|
||||
@ -20,7 +21,75 @@ struct Direct3DRMTextureImpl : public IDirect3DRMTexture2 {
|
||||
LPD3DRM_APPDATA m_data;
|
||||
};
|
||||
|
||||
struct Direct3DRMDevice2Impl : public IDirect3DRMDevice2 {
|
||||
template <typename T>
|
||||
struct Direct3DRMObjectImpl : public T {
|
||||
ULONG Release() override
|
||||
{
|
||||
if (IUnknown::m_refCount == 1) {
|
||||
for (auto it = m_callbacks.cbegin(); it != m_callbacks.cend(); it++) {
|
||||
it->first(this, it->second);
|
||||
}
|
||||
}
|
||||
return this->T::Release();
|
||||
}
|
||||
HRESULT AddDestroyCallback(D3DRMOBJECTCALLBACK callback, void* arg) override
|
||||
{
|
||||
m_callbacks.push_back(std::make_pair(callback, arg));
|
||||
return D3DRM_OK;
|
||||
}
|
||||
HRESULT DeleteDestroyCallback(D3DRMOBJECTCALLBACK callback, void* arg) override
|
||||
{
|
||||
for (auto it = m_callbacks.cbegin(); it != m_callbacks.cend(); it++) {
|
||||
if (it->first == callback && it->second == arg) {
|
||||
m_callbacks.erase(it);
|
||||
return D3DRM_OK;
|
||||
}
|
||||
}
|
||||
return D3DRMERR_NOTFOUND;
|
||||
}
|
||||
HRESULT SetAppData(LPD3DRM_APPDATA appData) override
|
||||
{
|
||||
m_appData = appData;
|
||||
return D3DRM_OK;
|
||||
}
|
||||
LPVOID GetAppData() override { return m_appData; }
|
||||
HRESULT SetName(const char* name) override
|
||||
{
|
||||
SDL_free(m_name);
|
||||
m_name = NULL;
|
||||
if (name) {
|
||||
m_name = SDL_strdup(name);
|
||||
}
|
||||
return D3DRM_OK;
|
||||
}
|
||||
HRESULT GetName(DWORD* size, char* name) override
|
||||
{
|
||||
if (!size) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
const char* s = m_name ? m_name : "";
|
||||
size_t l = SDL_strlen(s);
|
||||
if (name) {
|
||||
SDL_strlcpy(name, s, *size);
|
||||
}
|
||||
else {
|
||||
*size = l + 1;
|
||||
}
|
||||
return D3DRM_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::pair<D3DRMOBJECTCALLBACK, void*>> m_callbacks;
|
||||
LPD3DRM_APPDATA m_appData = NULL;
|
||||
char* m_name = nullptr;
|
||||
};
|
||||
|
||||
struct Direct3DRMDevice2Impl : public Direct3DRMObjectImpl<IDirect3DRMDevice2> {
|
||||
HRESULT Clone(void** ppObject) override
|
||||
{
|
||||
assert(false && "unimplemented");
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
unsigned long GetWidth() override { return 640; }
|
||||
unsigned long GetHeight() override { return 480; }
|
||||
HRESULT SetBufferCount(int count) override { return DD_OK; }
|
||||
@ -43,7 +112,12 @@ struct Direct3DRMDevice2Impl : public IDirect3DRMDevice2 {
|
||||
}
|
||||
};
|
||||
|
||||
struct Direct3DRMFrameImpl : public IDirect3DRMFrame2 {
|
||||
struct Direct3DRMFrameImpl : public Direct3DRMObjectImpl<IDirect3DRMFrame2> {
|
||||
HRESULT Clone(void** ppObject) override
|
||||
{
|
||||
assert(false && "unimplemented");
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
HRESULT SetAppData(LPD3DRM_APPDATA appData) override
|
||||
{
|
||||
m_data = appData;
|
||||
@ -128,24 +202,13 @@ struct Direct3DRMFrameImpl : public IDirect3DRMFrame2 {
|
||||
LPD3DRM_APPDATA m_data;
|
||||
};
|
||||
|
||||
struct Direct3DRMViewportImpl : public IDirect3DRMViewport {
|
||||
Direct3DRMViewportImpl() : m_data(nullptr) {}
|
||||
struct Direct3DRMViewportImpl : public Direct3DRMObjectImpl<IDirect3DRMViewport> {
|
||||
Direct3DRMViewportImpl() {}
|
||||
HRESULT Clone(void** ppObject) override
|
||||
{
|
||||
assert(false && "unimplemented");
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
HRESULT AddDestroyCallback(void (*cb)(IDirect3DRMObject*, void*), void* arg) override { return DD_OK; }
|
||||
HRESULT DeleteDestroyCallback(void (*cb)(IDirect3DRMObject*, void*), void* arg) override { return DD_OK; }
|
||||
HRESULT SetAppData(LPD3DRM_APPDATA appData) override
|
||||
{
|
||||
m_data = appData;
|
||||
return DD_OK;
|
||||
}
|
||||
LPVOID GetAppData() override { return m_data; }
|
||||
HRESULT SetName(const char* name) override { return DD_OK; }
|
||||
HRESULT GetName(DWORD* size, char* name) override { return DD_OK; }
|
||||
HRESULT GetClassName(DWORD* size, char* name) override { return DD_OK; }
|
||||
HRESULT Render(IDirect3DRMFrame* group) override { return DD_OK; }
|
||||
HRESULT ForceUpdate(int x, int y, int w, int h) override { return DD_OK; }
|
||||
HRESULT Clear() override { return DD_OK; }
|
||||
@ -168,16 +231,22 @@ struct Direct3DRMViewportImpl : public IDirect3DRMViewport {
|
||||
HRESULT Transform(D3DRMVECTOR4D* screen, D3DVECTOR* world) override { return DD_OK; }
|
||||
HRESULT InverseTransform(D3DVECTOR* world, D3DRMVECTOR4D* screen) override { return DD_OK; }
|
||||
HRESULT Pick(float x, float y, LPDIRECT3DRMPICKEDARRAY* pickedArray) override { return DD_OK; }
|
||||
|
||||
private:
|
||||
LPD3DRM_APPDATA m_data;
|
||||
};
|
||||
|
||||
struct Direct3DRMLightImpl : public IDirect3DRMLight {
|
||||
struct Direct3DRMLightImpl : public Direct3DRMObjectImpl<IDirect3DRMLight> {
|
||||
HRESULT Clone(void** ppObject) override
|
||||
{
|
||||
assert(false && "unimplemented");
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
HRESULT SetColorRGB(float r, float g, float b) override { return DD_OK; }
|
||||
};
|
||||
|
||||
struct Direct3DRMImpl : public IDirect3DRM2 {
|
||||
struct Direct3DRMMaterialImpl : public Direct3DRMObjectImpl<IDirect3DRMMaterial> {
|
||||
HRESULT Clone(void** ppObject) override { return DDERR_GENERIC; }
|
||||
};
|
||||
|
||||
struct Direct3DRMImpl : virtual public IDirect3DRM2 {
|
||||
// IUnknown interface
|
||||
HRESULT QueryInterface(const GUID& riid, void** ppvObject) override
|
||||
{
|
||||
@ -223,7 +292,7 @@ struct Direct3DRMImpl : public IDirect3DRM2 {
|
||||
}
|
||||
HRESULT CreateMaterial(D3DVAL power, IDirect3DRMMaterial** outMaterial) override
|
||||
{
|
||||
*outMaterial = new IDirect3DRMMaterial;
|
||||
*outMaterial = static_cast<IDirect3DRMMaterial*>(new Direct3DRMMaterialImpl);
|
||||
return DD_OK;
|
||||
}
|
||||
HRESULT CreateLightRGB(D3DRMLIGHTTYPE type, D3DVAL r, D3DVAL g, D3DVAL b, IDirect3DRMLight** outLight) override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user