mirror of
https://github.com/isledecomp/isle.git
synced 2025-10-23 08:24:16 +00:00
Add abstraction functions to TglImpl::ViewImpl
(#1434)
* Add Destroy methods to TglImpl * Test one abstraction * More ViewImpl abstractions * Finish ViewImpl
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "impl.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
using namespace TglImpl;
|
||||
|
||||
struct ViewportAppData {
|
||||
@@ -61,6 +63,7 @@ Result ViewImpl::ViewportCreateAppData(IDirect3DRM2* pDevice, IDirect3DRMViewpor
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x1016bd80
|
||||
inline Result ViewRestoreFrameAfterRender(
|
||||
IDirect3DRMFrame* pFrame,
|
||||
IDirect3DRMFrame* pCamera,
|
||||
@@ -72,7 +75,11 @@ inline Result ViewRestoreFrameAfterRender(
|
||||
// remove camera and light frame from frame that was rendered
|
||||
// this doesn't destroy the camera as it is still the camera of the viewport...
|
||||
result = ResultVal(pFrame->DeleteChild(pCamera));
|
||||
assert(Succeeded(result));
|
||||
assert((pCamera->AddRef(), pCamera->Release()) > 0);
|
||||
|
||||
result = ResultVal(pFrame->DeleteChild(pLightFrame));
|
||||
assert(Succeeded(result));
|
||||
|
||||
// decrease frame's ref count (it was increased in ViewPrepareFrameForRender())
|
||||
pFrame->Release();
|
||||
@@ -97,11 +104,12 @@ void ViewportDestroyCallback(IDirect3DRMObject* pObject, void* pArg)
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a1290
|
||||
// FUNCTION: BETA10 0x10168eab
|
||||
Result ViewportPickImpl(
|
||||
IDirect3DRMViewport* pViewport,
|
||||
int x,
|
||||
int y,
|
||||
const Group** ppGroupsToPickFrom,
|
||||
const GroupImpl** ppGroupsToPickFrom,
|
||||
int groupsToPickFromCount,
|
||||
const Group**& rppPickedGroups,
|
||||
int& rPickedGroupCount
|
||||
@@ -116,9 +124,11 @@ inline ViewportAppData* ViewportGetData(IDirect3DRMViewport* pViewport)
|
||||
return reinterpret_cast<ViewportAppData*>(pViewport->GetAppData());
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170ab0
|
||||
inline IDirect3DRMFrame* ViewportGetLightFrame(IDirect3DRMViewport* pViewport)
|
||||
{
|
||||
return ViewportGetData(pViewport)->m_pLightFrame;
|
||||
assert(pViewport->GetAppData());
|
||||
return reinterpret_cast<ViewportAppData*>(pViewport->GetAppData())->m_pLightFrame;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2d80
|
||||
@@ -128,97 +138,216 @@ void* ViewImpl::ImplementationDataPtr()
|
||||
return reinterpret_cast<void*>(&m_data);
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170a40
|
||||
inline Result ViewAddLight(IDirect3DRMViewport* pViewport, const IDirect3DRMFrame* pLight)
|
||||
{
|
||||
IDirect3DRMFrame* pLightFrame = ViewportGetLightFrame(pViewport);
|
||||
|
||||
assert(pLightFrame);
|
||||
return ResultVal(pLightFrame->AddChild(const_cast<IDirect3DRMFrame*>(pLight)));
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x101709a0
|
||||
inline Result ViewImpl::Add(const LightImpl& rLight)
|
||||
{
|
||||
assert(m_data);
|
||||
assert(rLight.ImplementationData());
|
||||
|
||||
return ViewAddLight(m_data, rLight.ImplementationData());
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2d90
|
||||
// FUNCTION: BETA10 0x1016e690
|
||||
Result ViewImpl::Add(const Light* pLight)
|
||||
{
|
||||
const LightImpl* light = static_cast<const LightImpl*>(pLight);
|
||||
IDirect3DRMFrame* frame = light->ImplementationData();
|
||||
return ResultVal(ViewportGetLightFrame(m_data)->AddChild(frame));
|
||||
assert(m_data);
|
||||
assert(pLight);
|
||||
|
||||
return Add(*static_cast<const LightImpl*>(pLight));
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170bb0
|
||||
inline Result ViewRemoveLight(IDirect3DRMViewport* pViewport, const IDirect3DRMFrame* pLight)
|
||||
{
|
||||
IDirect3DRMFrame* pLightFrame = ViewportGetLightFrame(pViewport);
|
||||
|
||||
assert(pLightFrame);
|
||||
return ResultVal(pLightFrame->DeleteChild(const_cast<IDirect3DRMFrame*>(pLight)));
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170b10
|
||||
inline Result ViewImpl::Remove(const LightImpl& rLight)
|
||||
{
|
||||
assert(m_data);
|
||||
assert(rLight.ImplementationData());
|
||||
|
||||
return ViewRemoveLight(m_data, rLight.ImplementationData());
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2dc0
|
||||
// FUNCTION: BETA10 0x1016e710
|
||||
Result ViewImpl::Remove(const Light* pLight)
|
||||
{
|
||||
const LightImpl* light = static_cast<const LightImpl*>(pLight);
|
||||
IDirect3DRMFrame* frame = light->ImplementationData();
|
||||
return ResultVal(ViewportGetLightFrame(m_data)->DeleteChild(frame));
|
||||
assert(m_data);
|
||||
assert(pLight);
|
||||
|
||||
return Remove(*static_cast<const LightImpl*>(pLight));
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2df0
|
||||
Result ViewImpl::SetCamera(const Camera* pCamera)
|
||||
// FUNCTION: BETA10 0x10170cc0
|
||||
inline Result ViewSetCamera(IDirect3DRMViewport* pViewport, const IDirect3DRMFrame2* pCamera)
|
||||
{
|
||||
const CameraImpl* camera = static_cast<const CameraImpl*>(pCamera);
|
||||
IDirect3DRMFrame2* frame = camera->ImplementationData();
|
||||
|
||||
ViewportAppData* pViewportAppData;
|
||||
Result result;
|
||||
|
||||
pViewportAppData = reinterpret_cast<ViewportAppData*>(m_data->GetAppData());
|
||||
pViewportAppData = reinterpret_cast<ViewportAppData*>(pViewport->GetAppData());
|
||||
assert(pViewportAppData);
|
||||
|
||||
result = ViewRestoreFrameAfterRender(
|
||||
pViewportAppData->m_pLastRenderedFrame,
|
||||
pViewportAppData->m_pCamera,
|
||||
pViewportAppData->m_pLightFrame
|
||||
);
|
||||
pViewportAppData->m_pCamera = frame;
|
||||
assert(Succeeded(result));
|
||||
pViewportAppData->m_pCamera = const_cast<IDirect3DRMFrame2*>(pCamera);
|
||||
pViewportAppData->m_pLastRenderedFrame = 0;
|
||||
|
||||
return ResultVal(m_data->SetCamera(frame));
|
||||
return ResultVal(pViewport->SetCamera(const_cast<IDirect3DRMFrame2*>(pCamera)));
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170c20
|
||||
inline Result ViewImpl::SetCamera(const CameraImpl& rCamera)
|
||||
{
|
||||
assert(m_data);
|
||||
assert(rCamera.ImplementationData());
|
||||
|
||||
return ViewSetCamera(m_data, rCamera.ImplementationData());
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2df0
|
||||
// FUNCTION: BETA10 0x1016e790
|
||||
Result ViewImpl::SetCamera(const Camera* pCamera)
|
||||
{
|
||||
assert(m_data);
|
||||
assert(pCamera);
|
||||
|
||||
return SetCamera(*static_cast<const CameraImpl*>(pCamera));
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x1016e870
|
||||
inline Result ViewSetProjection(IDirect3DRMViewport* pViewport, ProjectionType type)
|
||||
{
|
||||
D3DRMPROJECTIONTYPE projectionType = Translate(type);
|
||||
|
||||
return ResultVal(pViewport->SetProjection(projectionType));
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2e70
|
||||
// FUNCTION: BETA10 0x1016e810
|
||||
Result ViewImpl::SetProjection(ProjectionType type)
|
||||
{
|
||||
return ResultVal(m_data->SetProjection(Translate(type)));
|
||||
assert(m_data);
|
||||
|
||||
return ViewSetProjection(m_data, type);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2eb0
|
||||
Result ViewImpl::SetFrustrum(float frontClippingDistance, float backClippingDistance, float degrees)
|
||||
// FUNCTION: BETA10 0x1016e920
|
||||
inline Result ViewSetFrustrum(
|
||||
IDirect3DRMViewport* pViewport,
|
||||
float frontClippingDistance,
|
||||
float backClippingDistance,
|
||||
float degrees
|
||||
)
|
||||
{
|
||||
float field = frontClippingDistance * tan(DegreesToRadians(degrees / 2));
|
||||
Result result;
|
||||
result = ResultVal(m_data->SetFront(frontClippingDistance));
|
||||
result = ResultVal(pViewport->SetFront(frontClippingDistance));
|
||||
if (Succeeded(result)) {
|
||||
result = ResultVal(m_data->SetBack(backClippingDistance));
|
||||
result = ResultVal(pViewport->SetBack(backClippingDistance));
|
||||
}
|
||||
if (Succeeded(result)) {
|
||||
result = ResultVal(m_data->SetField(field));
|
||||
result = ResultVal(pViewport->SetField(field));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2eb0
|
||||
// FUNCTION: BETA10 0x1016e8b0
|
||||
Result ViewImpl::SetFrustrum(float frontClippingDistance, float backClippingDistance, float degrees)
|
||||
{
|
||||
assert(m_data);
|
||||
|
||||
return ViewSetFrustrum(m_data, frontClippingDistance, backClippingDistance, degrees);
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x1016ea70
|
||||
inline Result ViewSetBackgroundColor(IDirect3DRMViewport* pViewport, float r, float g, float b)
|
||||
{
|
||||
Result result = Success;
|
||||
|
||||
ViewportAppData* pViewportAppData = reinterpret_cast<ViewportAppData*>(pViewport->GetAppData());
|
||||
assert(pViewportAppData);
|
||||
|
||||
pViewportAppData->m_backgroundColorRed = r;
|
||||
pViewportAppData->m_backgroundColorGreen = g;
|
||||
pViewportAppData->m_backgroundColorBlue = b;
|
||||
|
||||
if (pViewportAppData->m_pLastRenderedFrame) {
|
||||
result = ResultVal(pViewportAppData->m_pLastRenderedFrame->SetSceneBackgroundRGB(r, g, b));
|
||||
assert(Succeeded(result));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2f30
|
||||
// FUNCTION: BETA10 0x1016ea00
|
||||
Result ViewImpl::SetBackgroundColor(float r, float g, float b)
|
||||
{
|
||||
Result ret = Success;
|
||||
// Note, this method in the shipped game is very diverged from
|
||||
// the Tgl leak code.
|
||||
ViewportAppData* data = ViewportGetData(m_data);
|
||||
data->m_backgroundColorRed = r;
|
||||
data->m_backgroundColorGreen = g;
|
||||
data->m_backgroundColorBlue = b;
|
||||
if (data->m_pLastRenderedFrame) {
|
||||
ret = ResultVal(data->m_pLastRenderedFrame->SetSceneBackgroundRGB(r, g, b));
|
||||
}
|
||||
return ret;
|
||||
assert(m_data);
|
||||
|
||||
return ViewSetBackgroundColor(m_data, r, g, b);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2f80
|
||||
Result ViewImpl::GetBackgroundColor(float* r, float* g, float* b)
|
||||
// FUNCTION: BETA10 0x1016ebd0
|
||||
inline Result ViewGetBackgroundColor(IDirect3DRMViewport* pViewport, float* r, float* g, float* b)
|
||||
{
|
||||
ViewportAppData* data = ViewportGetData(m_data);
|
||||
*r = data->m_backgroundColorRed;
|
||||
*g = data->m_backgroundColorGreen;
|
||||
*b = data->m_backgroundColorBlue;
|
||||
ViewportAppData* pViewportAppData = reinterpret_cast<ViewportAppData*>(pViewport->GetAppData());
|
||||
assert(pViewportAppData);
|
||||
|
||||
*r = pViewportAppData->m_backgroundColorRed;
|
||||
*g = pViewportAppData->m_backgroundColorGreen;
|
||||
*b = pViewportAppData->m_backgroundColorBlue;
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2fb0
|
||||
Result ViewImpl::Clear()
|
||||
// FUNCTION: LEGO1 0x100a2f80
|
||||
// FUNCTION: BETA10 0x1016eb60
|
||||
Result ViewImpl::GetBackgroundColor(float* r, float* g, float* b)
|
||||
{
|
||||
return ResultVal(m_data->Clear());
|
||||
assert(m_data);
|
||||
|
||||
return ViewGetBackgroundColor(m_data, r, g, b);
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x1016ecb0
|
||||
inline Result ViewClear(IDirect3DRMViewport* pViewport)
|
||||
{
|
||||
return ResultVal(pViewport->Clear());
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2fb0
|
||||
// FUNCTION: BETA10 0x1016ec50
|
||||
Result ViewImpl::Clear()
|
||||
{
|
||||
assert(m_data);
|
||||
|
||||
return ViewClear(m_data);
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170fb0
|
||||
inline Result ViewPrepareFrameForRender(
|
||||
IDirect3DRMFrame* pFrame,
|
||||
IDirect3DRMFrame* pCamera,
|
||||
@@ -233,12 +362,15 @@ inline Result ViewPrepareFrameForRender(
|
||||
if (pFrame) {
|
||||
// set background color
|
||||
result = ResultVal(pFrame->SetSceneBackgroundRGB(backgroundRed, backgroundGreen, backgroundBlue));
|
||||
assert(Succeeded(result));
|
||||
|
||||
// add camera to frame to be rendered
|
||||
result = ResultVal(pFrame->AddChild(pCamera));
|
||||
assert(Succeeded(result));
|
||||
|
||||
// add light frame to frame to be rendered
|
||||
result = ResultVal(pFrame->AddChild(pLightFrame));
|
||||
assert(Succeeded(result));
|
||||
|
||||
// increase ref count of frame to ensure it does not get deleted underneath us
|
||||
pFrame->AddRef();
|
||||
@@ -247,12 +379,14 @@ inline Result ViewPrepareFrameForRender(
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170e30
|
||||
inline Result ViewRender(IDirect3DRMViewport* pViewport, const IDirect3DRMFrame2* pGroup)
|
||||
{
|
||||
ViewportAppData* pViewportAppData;
|
||||
Result result;
|
||||
|
||||
pViewportAppData = reinterpret_cast<ViewportAppData*>(pViewport->GetAppData());
|
||||
assert(pViewportAppData);
|
||||
|
||||
if (pViewportAppData->m_pLastRenderedFrame != pGroup) {
|
||||
result = ViewRestoreFrameAfterRender(
|
||||
@@ -261,6 +395,8 @@ inline Result ViewRender(IDirect3DRMViewport* pViewport, const IDirect3DRMFrame2
|
||||
pViewportAppData->m_pLightFrame
|
||||
);
|
||||
|
||||
assert(Succeeded(result));
|
||||
|
||||
pViewportAppData->m_pLastRenderedFrame = const_cast<IDirect3DRMFrame2*>(pGroup);
|
||||
|
||||
result = ViewPrepareFrameForRender(
|
||||
@@ -273,32 +409,66 @@ inline Result ViewRender(IDirect3DRMViewport* pViewport, const IDirect3DRMFrame2
|
||||
);
|
||||
}
|
||||
|
||||
assert(Succeeded(result));
|
||||
|
||||
result = ResultVal(pViewport->Render(const_cast<IDirect3DRMFrame2*>(pGroup)));
|
||||
assert(Succeeded(result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x10170d90
|
||||
inline Result ViewImpl::Render(const GroupImpl& rScene)
|
||||
{
|
||||
assert(m_data);
|
||||
assert(rScene.ImplementationData());
|
||||
|
||||
return ViewRender(m_data, rScene.ImplementationData());
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a2fd0
|
||||
// FUNCTION: BETA10 0x1016ece0
|
||||
Result ViewImpl::Render(const Group* pGroup)
|
||||
{
|
||||
return ViewRender(m_data, static_cast<const GroupImpl*>(pGroup)->ImplementationData());
|
||||
assert(m_data);
|
||||
assert(pGroup);
|
||||
|
||||
return Render(*static_cast<const GroupImpl*>(pGroup));
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x1016edd0
|
||||
inline Result ViewForceUpdate(
|
||||
IDirect3DRMViewport* pViewport,
|
||||
unsigned long x,
|
||||
unsigned long y,
|
||||
unsigned long width,
|
||||
unsigned long height
|
||||
)
|
||||
{
|
||||
return ResultVal(pViewport->ForceUpdate(x, y, x + width - 1, y + height - 1));
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a3080
|
||||
// FUNCTION: BETA10 0x1016ed60
|
||||
Result ViewImpl::ForceUpdate(unsigned long x, unsigned long y, unsigned long width, unsigned long height)
|
||||
{
|
||||
return ResultVal(m_data->ForceUpdate(x, y, x + width - 1, y + height - 1));
|
||||
assert(m_data);
|
||||
|
||||
return ViewForceUpdate(m_data, x, y, width, height);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a30c0
|
||||
Result ViewImpl::Pick(
|
||||
// FUNCTION: BETA10 0x101710f0
|
||||
inline Result ViewImpl::Pick(
|
||||
unsigned long x,
|
||||
unsigned long y,
|
||||
const Group** ppGroupsToPickFrom,
|
||||
const GroupImpl** ppGroupsToPickFrom,
|
||||
int groupsToPickFromCount,
|
||||
const Group**& rppPickedGroups,
|
||||
int& rPickedGroupCount
|
||||
)
|
||||
{
|
||||
assert(m_data);
|
||||
|
||||
return ViewportPickImpl(
|
||||
m_data,
|
||||
x,
|
||||
@@ -310,17 +480,38 @@ Result ViewImpl::Pick(
|
||||
);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a30f0
|
||||
Result ViewImpl::TransformWorldToScreen(const float world[3], float screen[4])
|
||||
// FUNCTION: LEGO1 0x100a30c0
|
||||
// FUNCTION: BETA10 0x1016ee10
|
||||
Result ViewImpl::Pick(
|
||||
unsigned long x,
|
||||
unsigned long y,
|
||||
const Group** ppGroupsToPickFrom,
|
||||
int groupsToPickFromCount,
|
||||
const Group**& rppPickedGroups,
|
||||
int& rPickedGroupCount
|
||||
)
|
||||
{
|
||||
assert(m_data);
|
||||
|
||||
return Pick(
|
||||
x,
|
||||
y,
|
||||
reinterpret_cast<const GroupImpl**>(ppGroupsToPickFrom),
|
||||
groupsToPickFromCount,
|
||||
rppPickedGroups,
|
||||
rPickedGroupCount
|
||||
);
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x1016eff0
|
||||
inline Result ViewTransformWorldToScreen(IDirect3DRMViewport* pViewport, const float world[3], float screen[4])
|
||||
{
|
||||
D3DRMVECTOR4D d3dRMScreen;
|
||||
D3DVECTOR d3dRMWorld;
|
||||
d3dRMWorld.x = world[0];
|
||||
d3dRMWorld.y = world[1];
|
||||
d3dRMWorld.z = world[2];
|
||||
D3DVECTOR* pD3DRMWorld = Translate(world, d3dRMWorld);
|
||||
Result result;
|
||||
|
||||
result = ResultVal(m_data->Transform(&d3dRMScreen, &d3dRMWorld));
|
||||
result = ResultVal(pViewport->Transform(&d3dRMScreen, pD3DRMWorld));
|
||||
|
||||
if (Succeeded(result)) {
|
||||
screen[0] = d3dRMScreen.x;
|
||||
@@ -332,10 +523,18 @@ Result ViewImpl::TransformWorldToScreen(const float world[3], float screen[4])
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a3160
|
||||
Result ViewImpl::TransformScreenToWorld(const float screen[4], float world[3])
|
||||
// FUNCTION: LEGO1 0x100a30f0
|
||||
// FUNCTION: BETA10 0x1016ef90
|
||||
Result ViewImpl::TransformWorldToScreen(const float world[3], float screen[4])
|
||||
{
|
||||
assert(m_data);
|
||||
|
||||
return ViewTransformWorldToScreen(m_data, world, screen);
|
||||
}
|
||||
|
||||
// FUNCTION: BETA10 0x1016f0d0
|
||||
inline Result ViewTransformScreenToWorld(IDirect3DRMViewport* pViewport, const float screen[4], float world[3])
|
||||
{
|
||||
// 100% match minus instruction reordering.
|
||||
D3DVECTOR d3dRMWorld;
|
||||
D3DRMVECTOR4D d3dScreen;
|
||||
d3dScreen.x = screen[0];
|
||||
@@ -344,7 +543,7 @@ Result ViewImpl::TransformScreenToWorld(const float screen[4], float world[3])
|
||||
d3dScreen.w = screen[3];
|
||||
Result result;
|
||||
|
||||
result = ResultVal(m_data->InverseTransform(&d3dRMWorld, &d3dScreen));
|
||||
result = ResultVal(pViewport->InverseTransform(&d3dRMWorld, &d3dScreen));
|
||||
|
||||
if (Succeeded(result)) {
|
||||
world[0] = d3dRMWorld.x;
|
||||
@@ -354,3 +553,12 @@ Result ViewImpl::TransformScreenToWorld(const float screen[4], float world[3])
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100a3160
|
||||
// FUNCTION: BETA10 0x1016f070
|
||||
Result ViewImpl::TransformScreenToWorld(const float screen[4], float world[3])
|
||||
{
|
||||
assert(m_data);
|
||||
|
||||
return ViewTransformScreenToWorld(m_data, screen, world);
|
||||
}
|
||||
|
Reference in New Issue
Block a user