From f00f793ab52c8c992171657ea9f38b93e83de585 Mon Sep 17 00:00:00 2001 From: disinvite Date: Fri, 18 Apr 2025 16:52:58 -0400 Subject: [PATCH] RendererImpl::CreateView --- LEGO1/tgl/d3drm/impl.h | 15 ++++++- LEGO1/tgl/d3drm/renderer.cpp | 77 ++++++++++++++++++++++++++++-------- LEGO1/tgl/d3drm/view.cpp | 66 ++++++++++++++++++++++++------- 3 files changed, 125 insertions(+), 33 deletions(-) diff --git a/LEGO1/tgl/d3drm/impl.h b/LEGO1/tgl/d3drm/impl.h index 341cddf5..a5307e1a 100644 --- a/LEGO1/tgl/d3drm/impl.h +++ b/LEGO1/tgl/d3drm/impl.h @@ -105,6 +105,15 @@ class RendererImpl : public Renderer { inline Result Create(); inline void Destroy(); inline Result CreateLight(LightType type, float r, float g, float b, LightImpl& rLight); + inline Result CreateView( + const DeviceImpl& rDevice, + const CameraImpl& rCamera, + unsigned long x, + unsigned long y, + unsigned long width, + unsigned long height, + ViewImpl& rView + ); private: RendererDataType m_data; @@ -233,8 +242,9 @@ class ViewImpl : public View { typedef IDirect3DRMViewport* ViewDataType; - // FUNCTION: BETA10 0x101711c0 const ViewDataType& ImplementationData() const { return m_data; } + + // FUNCTION: BETA10 0x101711c0 ViewDataType& ImplementationData() { return m_data; } void SetImplementationData(IDirect3DRMViewport* viewport) { m_data = viewport; } @@ -783,6 +793,9 @@ inline D3DRMLIGHTTYPE Translate(LightType tglLightType) // SYNTHETIC: BETA10 0x1016fa90 // TglImpl::MeshImpl::`scalar deleting destructor' +// SYNTHETIC: BETA10 0x10169960 +// ViewportAppData::`scalar deleting destructor' + // GLOBAL: LEGO1 0x100dd1e0 // IID_IDirect3DRMMeshBuilder diff --git a/LEGO1/tgl/d3drm/renderer.cpp b/LEGO1/tgl/d3drm/renderer.cpp index f0ab4fbb..11c387ac 100644 --- a/LEGO1/tgl/d3drm/renderer.cpp +++ b/LEGO1/tgl/d3drm/renderer.cpp @@ -71,29 +71,69 @@ Device* RendererImpl::CreateDevice(const DeviceDirectDrawCreateData& data) return device; } +// FUNCTION: BETA10 0x1016d1d0 inline Result RendererCreateView( IDirect3DRM2* pRenderer, - IDirect3DRMDevice2* pDevice, - IDirect3DRMFrame2* pCamera, - IDirect3DRMViewport*& rpView, + const IDirect3DRMDevice2* pDevice, + const IDirect3DRMFrame2* pCamera, unsigned long x, unsigned long y, unsigned long width, - unsigned long height + unsigned long height, + IDirect3DRMViewport*& rpView ) { - Result result = ResultVal(pRenderer->CreateViewport(pDevice, pCamera, x, y, width, height, &rpView)); + Result result = ResultVal(pRenderer->CreateViewport( + const_cast(pDevice), + const_cast(pCamera), + x, + y, + width, + height, + &rpView + )); + if (Succeeded(result)) { - result = ViewImpl::ViewportCreateAppData(pRenderer, rpView, pCamera); + result = ViewImpl::ViewportCreateAppData(pRenderer, rpView, const_cast(pCamera)); if (!Succeeded(result)) { rpView->Release(); rpView = NULL; } } + return result; } +// FUNCTION: BETA10 0x1016d0b0 +inline Result RendererImpl::CreateView( + const DeviceImpl& rDevice, + const CameraImpl& rCamera, + unsigned long x, + unsigned long y, + unsigned long width, + unsigned long height, + ViewImpl& rView +) +{ + assert(m_data); + assert(rDevice.ImplementationData()); + assert(rCamera.ImplementationData()); + assert(!rView.ImplementationData()); + + return RendererCreateView( + m_data, + rDevice.ImplementationData(), + rCamera.ImplementationData(), + x, + y, + width, + height, + rView.ImplementationData() + ); +} + // FUNCTION: LEGO1 0x100a1a00 +// FUNCTION: BETA10 0x10169fb0 View* RendererImpl::CreateView( const Device* pDevice, const Camera* pCamera, @@ -103,21 +143,24 @@ View* RendererImpl::CreateView( unsigned long height ) { + assert(m_data); + assert(pDevice); + assert(pCamera); + ViewImpl* view = new ViewImpl(); - Result result = RendererCreateView( - m_data, - static_cast(pDevice)->m_data, - static_cast(pCamera)->m_data, - view->m_data, - x, - y, - width, - height - ); - if (!result) { + if (!CreateView( + *static_cast(pDevice), + *static_cast(pCamera), + x, + y, + width, + height, + *view + )) { delete view; view = NULL; } + return view; } diff --git a/LEGO1/tgl/d3drm/view.cpp b/LEGO1/tgl/d3drm/view.cpp index 30970214..aba7df5a 100644 --- a/LEGO1/tgl/d3drm/view.cpp +++ b/LEGO1/tgl/d3drm/view.cpp @@ -19,9 +19,12 @@ struct ViewportAppData { DECOMP_SIZE_ASSERT(ViewportAppData, 0x18); // FUNCTION: LEGO1 0x100a10b0 +// FUNCTION: BETA10 0x10168920 ViewportAppData::ViewportAppData(IDirect3DRM2* pRenderer) { - pRenderer->CreateFrame(NULL, &m_pLightFrame); + Result result = ResultVal(pRenderer->CreateFrame(NULL, &m_pLightFrame)); + assert(Succeeded(result)); + m_pCamera = NULL; m_pLastRenderedFrame = NULL; m_backgroundColorRed = 0.0f; @@ -30,36 +33,64 @@ ViewportAppData::ViewportAppData(IDirect3DRM2* pRenderer) } // FUNCTION: LEGO1 0x100a10e0 +// FUNCTION: BETA10 0x101689bd ViewportAppData::~ViewportAppData() { + int refCount; IDirect3DRMFrameArray* pChildFrames; IDirect3DRMFrame* pChildFrame = NULL; - m_pLightFrame->GetChildren(&pChildFrames); + Result result = ResultVal(m_pLightFrame->GetChildren(&pChildFrames)); + assert(Succeeded(result)); + for (int i = 0; i < (int) pChildFrames->GetSize(); i++) { - pChildFrames->GetElement(i, &pChildFrame); - m_pLightFrame->DeleteChild(pChildFrame); - pChildFrame->Release(); // GetElement() does AddRef() + result = ResultVal(pChildFrames->GetElement(i, &pChildFrame)); + assert(Succeeded(result)); + + result = ResultVal(m_pLightFrame->DeleteChild(pChildFrame)); + assert(Succeeded(result)); + + refCount = pChildFrame->Release(); // GetElement() does AddRef() + assert(refCount >= 1); } - pChildFrames->Release(); - m_pLightFrame->Release(); + + refCount = pChildFrames->Release(); + assert(refCount == 0); + + refCount = m_pLightFrame->Release(); + assert(refCount == 0); } // Forward declare to satisfy order check void ViewportDestroyCallback(IDirect3DRMObject* pObject, void* pArg); // FUNCTION: LEGO1 0x100a1160 -Result ViewImpl::ViewportCreateAppData(IDirect3DRM2* pDevice, IDirect3DRMViewport* pView, IDirect3DRMFrame2* pCamera) +// FUNCTION: BETA10 0x10168ba5 +Result ViewImpl::ViewportCreateAppData( + IDirect3DRM2* pDevice, + IDirect3DRMViewport* pViewport, + IDirect3DRMFrame2* pCamera +) { - ViewportAppData* data = new ViewportAppData(pDevice); - data->m_pCamera = pCamera; - Result result = ResultVal(pView->SetAppData(reinterpret_cast(data))); + ViewportAppData* pViewportAppData = new ViewportAppData(pDevice); + assert(pViewportAppData); + + pViewportAppData->m_pCamera = pCamera; + assert(!pViewport->GetAppData()); + + Result result = ResultVal(pViewport->SetAppData(reinterpret_cast(pViewportAppData))); + assert(Succeeded(result)); + assert(reinterpret_cast(pViewport->GetAppData()) == pViewportAppData); + if (Succeeded(result)) { - result = ResultVal(pView->AddDestroyCallback(ViewportDestroyCallback, data)); + result = ResultVal(pViewport->AddDestroyCallback(ViewportDestroyCallback, pViewportAppData)); + assert(Succeeded(result)); } + if (!Succeeded(result)) { - delete data; - pView->SetAppData(0); + delete pViewportAppData; + pViewport->SetAppData(0); } + return result; } @@ -90,16 +121,21 @@ inline Result ViewRestoreFrameAfterRender( // FIXME: from LEGO1/tgl/d3drm/view.cpp // FUNCTION: LEGO1 0x100a1240 +// FUNCTION: BETA10 0x10168dc9 void ViewportDestroyCallback(IDirect3DRMObject* pObject, void* pArg) { ViewportAppData* pViewportAppData = reinterpret_cast(pArg); + assert(static_cast(pObject)); + assert(pViewportAppData); - ViewRestoreFrameAfterRender( + Result result = ViewRestoreFrameAfterRender( pViewportAppData->m_pLastRenderedFrame, pViewportAppData->m_pCamera, pViewportAppData->m_pLightFrame ); + assert(Succeeded(result)); + delete pViewportAppData; }