Implement/match Lego3DView and parent classes (#412)

* Implement/match TglSurface

* Implement/match LegoView/1

* Lego3DView

* Fixes

* Lego3DManager

* Remove garbage

* Remove garbage

* Use shorthand calls
This commit is contained in:
Christian Semmler 2024-01-06 21:29:32 -05:00 committed by GitHub
parent dc3500f631
commit 8db36722d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1132 additions and 293 deletions

View File

@ -17,6 +17,7 @@ jobs:
--style=file \
ISLE/*.cpp ISLE/*.h \
LEGO1/*.cpp LEGO1/*.h \
LEGO1/3dmanager/*.cpp LEGO1/3dmanager/*.h \
LEGO1/mxdirectx/*.h \
LEGO1/mxstl/*.h \
LEGO1/realtime/*.cpp LEGO1/realtime/*.h \

View File

@ -7,6 +7,10 @@ option(ISLE_USE_SMARTHEAP "Build with SmartHeap" ${MSVC})
option(ISLE_USE_DX5 "Build with internal DirectX 5 SDK" ON)
add_library(lego1 SHARED
LEGO1/3dmanager/lego3dmanager.cpp
LEGO1/3dmanager/lego3dview.cpp
LEGO1/3dmanager/legoview1.cpp
LEGO1/3dmanager/tglsurface.cpp
LEGO1/act1state.cpp
LEGO1/act2brick.cpp
LEGO1/act2policestation.cpp
@ -47,8 +51,6 @@ add_library(lego1 SHARED
LEGO1/jukebox.cpp
LEGO1/jukeboxentity.cpp
LEGO1/jukeboxstate.cpp
LEGO1/lego3dmanager.cpp
LEGO1/lego3dview.cpp
LEGO1/legoact2state.cpp
LEGO1/legoactioncontrolpresenter.cpp
LEGO1/legoactor.cpp

View File

@ -21,6 +21,7 @@
#include "mxtimer.h"
#include "mxtransitionmanager.h"
#include "res/resource.h"
#include "viewmanager/viewmanager.h"
#include <dsound.h>

View File

@ -0,0 +1,96 @@
// Lego3DManager.cpp : implementation file
//
#include "lego3dmanager.h"
#include "../viewmanager/viewlodlist.h"
#include "decomp.h"
DECOMP_SIZE_ASSERT(Lego3DManager, 0x10);
//////////////////////////////////////////////////////////////////////////////
// FUNCTION: LEGO1 0x100ab2d0
BOOL InitializeCreateStruct(
TglSurface::CreateStruct& rTglSurfaceCreateStruct,
const Lego3DManager::CreateStruct& rCreateStruct
)
{
// initializes a TglSurface::CreateStruct from a Lego3DManager::CreateStruct
rTglSurfaceCreateStruct.m_pDriverGUID = rCreateStruct.m_pDriverGUID;
rTglSurfaceCreateStruct.m_hWnd = rCreateStruct.m_hWnd;
rTglSurfaceCreateStruct.m_pDirectDraw = rCreateStruct.m_pDirectDraw;
rTglSurfaceCreateStruct.m_pFrontBuffer = rCreateStruct.m_pFrontBuffer;
rTglSurfaceCreateStruct.m_pBackBuffer = rCreateStruct.m_pBackBuffer;
rTglSurfaceCreateStruct.m_pPalette = rCreateStruct.m_pPalette;
rTglSurfaceCreateStruct.m_isFullScreen = rCreateStruct.m_isFullScreen;
rTglSurfaceCreateStruct.m_isWideViewAngle = rCreateStruct.m_isWideViewAngle;
rTglSurfaceCreateStruct.m_direct3d = rCreateStruct.m_direct3d;
rTglSurfaceCreateStruct.m_d3dDevice = rCreateStruct.m_d3dDevice;
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
// FUNCTION: LEGO1 0x100ab320
Lego3DManager::Lego3DManager()
{
// Tgl things
m_pRenderer = 0;
m_pLego3DView = 0;
m_pViewLODListManager = 0;
}
// FUNCTION: LEGO1 0x100ab360
Lego3DManager::~Lego3DManager()
{
Destroy();
}
// FUNCTION: LEGO1 0x100ab370
BOOL Lego3DManager::Create(CreateStruct& rCreateStruct)
{
TglSurface::CreateStruct tglSurfaceCreateStruct;
BOOL result;
assert(!m_pViewLODListManager);
assert(!m_pRenderer);
assert(!m_pLego3DView);
m_pViewLODListManager = new ViewLODListManager;
assert(m_pViewLODListManager);
m_pRenderer = Tgl::CreateRenderer();
assert(m_pRenderer);
m_pLego3DView = new Lego3DView;
result = InitializeCreateStruct(tglSurfaceCreateStruct, rCreateStruct);
assert(result);
result = m_pLego3DView->Create(tglSurfaceCreateStruct, m_pRenderer);
assert(result);
return result;
}
// FUNCTION: LEGO1 0x100ab460
void Lego3DManager::Destroy()
{
delete m_pLego3DView;
m_pLego3DView = 0;
delete m_pRenderer;
m_pRenderer = 0;
delete m_pViewLODListManager;
m_pViewLODListManager = 0;
}
// FUNCTION: LEGO1 0x100ab4b0
double Lego3DManager::Render(double p_und)
{
assert(m_pLego3DView);
return m_pLego3DView->Render(p_und);
}

View File

@ -0,0 +1,117 @@
#ifndef _Lego3DManager_h
#define _Lego3DManager_h
#include "assert.h"
#include "lego3dview.h"
class Tgl::Renderer;
class Tgl::Group;
class ViewROI;
// ??? for now
class ViewLODListManager;
/////////////////////////////////////////////////////////////////////////////
//
// Lego3DManager
// VTABLE: LEGO1 0x100dbfa4
// SIZE 0x10
class Lego3DManager {
public:
// SIZE 0x28
struct CreateStruct {
const GUID* m_pDriverGUID; // 0x00
HWND m_hWnd; // 0x04
IDirectDraw* m_pDirectDraw; // 0x08
IDirectDrawSurface* m_pFrontBuffer; // 0x0c
IDirectDrawSurface* m_pBackBuffer; // 0x10
IDirectDrawPalette* m_pPalette; // 0x14
BOOL m_isFullScreen; // 0x18
BOOL m_isWideViewAngle; // 0x1c
IDirect3D2* m_direct3d; // 0x20
IDirect3DDevice2* m_d3dDevice; // 0x24
};
public:
Lego3DManager();
virtual ~Lego3DManager();
BOOL Create(CreateStruct&);
void Destroy();
BOOL Add(ViewROI&);
BOOL Remove(ViewROI&);
BOOL Moved(ViewROI&);
BOOL SetPointOfView(ViewROI&);
double Render(double p_und);
Tgl::Renderer* GetRenderer();
Tgl::Group* GetScene();
Lego3DView* GetLego3DView();
// ??? for now
ViewLODListManager* GetViewLODListManager();
private:
Tgl::Renderer* m_pRenderer; // 0x04
Lego3DView* m_pLego3DView; // 0x08
ViewLODListManager* m_pViewLODListManager; // 0x0c
};
/////////////////////////////////////////////////////////////////////////////
//
// Lego3DManager implementaion
inline BOOL Lego3DManager::Add(ViewROI& rROI)
{
assert(m_pLego3DView);
return m_pLego3DView->Add(rROI);
}
inline BOOL Lego3DManager::Remove(ViewROI& rROI)
{
assert(m_pLego3DView);
return m_pLego3DView->Remove(rROI);
}
inline BOOL Lego3DManager::SetPointOfView(ViewROI& rROI)
{
assert(m_pLego3DView);
return m_pLego3DView->SetPointOfView(rROI);
}
inline BOOL Lego3DManager::Moved(ViewROI& rROI)
{
assert(m_pLego3DView);
return m_pLego3DView->Moved(rROI);
}
inline Tgl::Renderer* Lego3DManager::GetRenderer()
{
return m_pRenderer;
}
inline Tgl::Group* Lego3DManager::GetScene()
{
assert(m_pLego3DView);
return m_pLego3DView->GetScene();
}
inline Lego3DView* Lego3DManager::GetLego3DView()
{
return m_pLego3DView;
}
inline ViewLODListManager* Lego3DManager::GetViewLODListManager()
{
return m_pViewLODListManager;
}
#endif /* _Lego3DManager_h */

View File

@ -0,0 +1,221 @@
// Lego3DView.cpp : implementation file
//
#include "lego3dview.h"
#include "../viewmanager/viewmanager.h"
DECOMP_SIZE_ASSERT(Lego3DView, 0xa8)
/////////////////////////////////////////////////////////////////////////////
// Lego3DView
// STUB: LEGO1 0x100aae90
Lego3DView::Lego3DView()
{
m_pViewManager = 0;
m_previousRenderTime = 0;
m_pPointOfView = 0;
}
// FUNCTION: LEGO1 0x100aaf30
Lego3DView::~Lego3DView()
{
Destroy();
}
// STUB: LEGO1 0x100aaf90
BOOL Lego3DView::Create(const TglSurface::CreateStruct& rCreateStruct, Tgl::Renderer* pRenderer)
{
double viewAngle = 45;
double frontClippingDistance = 1;
double backClippingDistance = 5000;
if (!LegoView1::Create(rCreateStruct, pRenderer)) {
return FALSE;
}
// assert(GetView());
// GetView()->SetFrustrum(frontClippingDistance, backClippingDistance, viewAngle);
// assert(GetScene());
// assert(!m_pViewManager);
// m_pViewManager = new ViewManager(GetScene(), 0);
// m_pViewManager->SetResolution(GetWidth(), GetHeight());
// m_pViewManager->SetFrustrum(viewAngle, -frontClippingDistance, -backClippingDistance);
// m_previousRenderTime = 0;
// // NOTE: a derived class must inform view manager when it configures
// // its (Tgl) view: calling Tgl::View::SetFrustrum() should be
// // accompanied by calling ViewManager::SetFrustrum()
return TRUE;
}
// STUB: LEGO1 0x100ab0b0
void Lego3DView::Destroy()
{
if (m_pPointOfView) {
m_pPointOfView = 0;
// m_pViewManager->SetPOVSource(0);
}
delete m_pViewManager;
m_pViewManager = 0;
LegoView1::Destroy();
}
// STUB: LEGO1 0x100ab100
BOOL Lego3DView::Add(ViewROI& rROI)
{
// assert(m_pViewManager);
// m_pViewManager->Add(rROI);
return TRUE;
}
// STUB: LEGO1 0x100ab170
BOOL Lego3DView::Remove(ViewROI& rROI)
{
// assert(m_pViewManager);
// m_pViewManager->Remove(rROI);
// if (m_pPointOfView == &rROI) {
// m_pPointOfView = 0;
// m_pViewManager->SetPOVSource(0);
// }
return TRUE;
}
// STUB: LEGO1 0x100ab1b0
BOOL Lego3DView::SetPointOfView(ViewROI& rROI)
{
// Tgl::DoubleMatrix4 transformation;
// Tgl::Result result;
// m_pPointOfView = &rROI;
// assert(m_pViewManager);
// m_pViewManager->SetPOVSource(m_pPointOfView);
// assert(GetCamera());
// SETMAT4(transformation, rROI.GetLocalTransform());
// result = GetCamera()->SetTransformation(transformation);
// assert(Tgl::Succeeded(result));
return TRUE;
}
// STUB: LEGO1 0x100ab210
BOOL Lego3DView::Moved(ViewROI& rROI)
{
// assert(m_pViewManager);
// m_pViewManager->Moved(rROI);
// if (m_pPointOfView == &rROI) {
// // move the camera
// Tgl::DoubleMatrix4 transformation;
// Tgl::Result result;
// assert(GetCamera());
// SETMAT4(transformation, rROI.GetLocalTransform());
// result = GetCamera()->SetTransformation(transformation);
// assert(Tgl::Succeeded(result));
// }
return TRUE;
}
// STUB: LEGO1 0x100ab270
double Lego3DView::Render(double p_und)
{
// assert(m_pViewManager);
// m_pViewManager->Update(m_previousRenderTime);
// m_previousRenderTime = LegoView1::Render();
return m_previousRenderTime;
}
/*
virtual Tgl::Result Tgl::View::Pick(unsigned long x,
unsigned long y,
const Tgl::Group** ppGroupsToPickFrom,
int groupsToPickFromCount,
const Tgl::Group**& rppPickedGroups,
int& rPickedGroupCount) = 0;
*/
// typedef std::map<const Tgl::Group*, const ROI*, std::less<const Tgl::Group*>> Group2ROI;
// STUB: LEGO1 0x100ab2b0
ViewROI* Lego3DView::Pick(unsigned long x, unsigned long y)
{
// const ROIList& visible_rois = m_pViewManager->GetVisibleROIs();
// int n_in = 0, n_out;
// const Tgl::Group** groups_in = new const Tgl::Group*[visible_rois.size()];
// const Tgl::Group** groups_out = NULL;
// Group2ROI roi_map;
// ViewROI* viewROI = NULL;
// // generate the list of groups to pick from which is all the geometry
// // groups of all the currently visible ROIs in the view manager.
// // Also, construct a mapping from each group back to it's ROI since that's
// // what we need to return.
// //
// WALK_STL_OBJECT(visible_rois, ROIList, vi)
// {
// ViewROI* vroi = (ViewROI*) (*vi);
// Tgl::Group* g = vroi->GetGeometry();
// assert(g);
// groups_in[n_in++] = g;
// roi_map[g] = *vi;
// }
// // perform the pick on our TglView passing the visible groups
// //
// Tgl::View* tglview = GetView();
// assert(tglview);
// tglview->Pick(x, y, groups_in, n_in, groups_out, n_out);
// // search the returned group hierarchy from the bottom for the
// // first group which was in groups_in.
// //
// for (int i = n_out - 1; i >= 0; i--) {
// const Tgl::Group* g = (const Tgl::Group*) (groups_out[i]);
// if (!g) // null entries means group node wasn't in groups_in
// continue;
// Group2ROI::iterator gi = roi_map.find(g);
// if (gi != roi_map.end()) {
// viewROI = (ViewROI*) ((*gi).second);
// break;
// }
// }
// // delete the heap allocated arrays.
// //
// delete[] groups_in;
// if (groups_out)
// delete[] groups_out;
return NULL;
}
// double Lego3DView::GetTargetRenderingRate() const
// {
// double secondsAllowed;
// assert(m_pViewManager);
// secondsAllowed = m_pViewManager->GetSecondsAllowed();
// return (secondsAllowed ? (1 / secondsAllowed) : HUGE_VAL);
// }

View File

@ -0,0 +1,62 @@
#ifndef _Lego3DView_h
#define _Lego3DView_h
#include "decomp.h"
#include "legoview1.h"
class ViewROI;
class ViewManager;
/////////////////////////////////////////////////////////////////////////////
// Lego3DView
// VTABLE: LEGO1 0x100dbf78
// SIZE 0xa8
class Lego3DView : public LegoView1 {
public:
Lego3DView();
virtual ~Lego3DView() override;
BOOL Create(const CreateStruct&, Tgl::Renderer*);
virtual void Destroy() override; // vtable+0x08
BOOL Add(ViewROI&);
BOOL Remove(ViewROI&);
BOOL Moved(ViewROI&);
BOOL SetPointOfView(ViewROI&);
double Render(double p_und);
ViewROI* Pick(unsigned long x, unsigned long y);
ViewROI* GetPointOfView();
ViewManager* GetViewManager();
// double GetTargetRenderingRate() const;
private:
ViewManager* m_pViewManager; // 0x88
double m_previousRenderTime; // 0x8c
ViewROI* m_pPointOfView; // 0x90
undefined m_unk0x94[0x0c]; // 0x94
};
// SYNTHETIC: LEGO1 0x100aaf10
// Lego3DView::`scalar deleting destructor'
/////////////////////////////////////////////////////////////////////////////
//
// Lego3DView implementation
inline ViewManager* Lego3DView::GetViewManager()
{
return m_pViewManager;
}
inline ViewROI* Lego3DView::GetPointOfView()
{
return m_pPointOfView;
}
#endif /* _Lego3DView_h */

View File

@ -0,0 +1,184 @@
// LegoView1.cpp : implementation file
//
#include "legoview1.h"
#include "../realtime/realtime.h"
#include "decomp.h"
#include <vec.h> // SETMAT4
DECOMP_SIZE_ASSERT(LegoView, 0x78);
DECOMP_SIZE_ASSERT(LegoView1, 0x88);
/////////////////////////////////////////////////////////////////////////////
// LegoView
// FUNCTION: LEGO1 0x100ab510
LegoView::LegoView()
{
m_pScene = 0;
m_pCamera = 0;
}
// FUNCTION: LEGO1 0x100ab5a0
LegoView::~LegoView()
{
Destroy();
}
// FUNCTION: LEGO1 0x100ab600
BOOL LegoView::Create(const TglSurface::CreateStruct& rCreateStruct, Tgl::Renderer* pRenderer)
{
float viewAngle = 45;
if (rCreateStruct.m_isWideViewAngle)
viewAngle = 90;
float frontClippingDistance = 0.1;
float backClippingDistance = 500;
assert(!m_pScene);
assert(!m_pCamera);
assert(pRenderer);
m_pScene = pRenderer->CreateGroup();
assert(m_pScene);
// TglSurface::Create() calls CreateView(), and we need the camera in
// CreateView(), so create camera before calling TglSurface::Create()
m_pCamera = pRenderer->CreateCamera();
assert(m_pCamera);
if (!TglSurface::Create(rCreateStruct, pRenderer, m_pScene)) {
delete m_pScene;
m_pScene = 0;
delete m_pCamera;
m_pCamera = 0;
return FALSE;
}
assert(GetView());
GetView()->SetFrustrum(frontClippingDistance, backClippingDistance, viewAngle);
GetView()->SetBackgroundColor(.223, .639, .851);
return TRUE;
}
// FUNCTION: LEGO1 0x100ab6c0
Tgl::View* LegoView::CreateView(Tgl::Renderer* pRenderer, Tgl::Device* pDevice)
{
assert(pRenderer);
assert(pDevice);
return pRenderer->CreateView(pDevice, m_pCamera, 0, 0, GetWidth(), GetHeight());
}
// FUNCTION: LEGO1 0x100ab6f0
void LegoView::Destroy()
{
delete m_pScene;
m_pScene = 0;
delete m_pCamera;
m_pCamera = 0;
TglSurface::Destroy();
}
/////////////////////////////////////////////////////////////////////////////
// LegoView1
// FUNCTION: LEGO1 0x100ab730
LegoView1::LegoView1()
{
m_pSunLight = 0;
m_pDirectionalLight = 0;
m_pAmbientLight = 0;
}
// FUNCTION: LEGO1 0x100ab7c0
LegoView1::~LegoView1()
{
Destroy();
}
// FUNCTION: LEGO1 0x100ab820
BOOL LegoView1::AddLightsToViewport()
{
GetView()->Add(m_pSunLight);
GetView()->Add(m_pDirectionalLight);
GetView()->Add(m_pAmbientLight);
return TRUE;
}
// STUB: LEGO1 0x100ab860
BOOL LegoView1::Create(const TglSurface::CreateStruct& rCreateStruct, Tgl::Renderer* pRenderer)
{
double position[3] = {0, 0, 0};
double direction[3];
double up[3] = {0, 1, 0};
if (!LegoView::Create(rCreateStruct, pRenderer)) {
return FALSE;
}
// lights
m_pSunLight = pRenderer->CreateLight(Tgl::Directional, .9, .9, .9);
m_pDirectionalLight = pRenderer->CreateLight(Tgl::Directional, .4, .4, .4);
m_pAmbientLight = pRenderer->CreateLight(Tgl::Ambient, .3, .3, .3);
#if 0
direction[0] = 1, direction[1] = -1, direction[2] = 2;
m_pSunLight->SetOrientation(direction, up);
direction[0] = -1, direction[1] = -2, direction[2] = -1;
m_pDirectionalLight->SetOrientation(direction, up);
#else
{
// Change everything to float and proper Matrix types
/*
Tgl::FloatMatrix4 transformation;
Matrix4Data transform;
direction[0] = 1, direction[1] = -1, direction[2] = 2;
CalcLocalTransform(position, direction, up, transform);
SETMAT4(transformation, transform);
m_pSunLight->SetTransformation(transformation);
direction[0] = -1, direction[1] = -2, direction[2] = -1;
CalcLocalTransform(position, direction, up, transform);
SETMAT4(transformation, transform);
m_pDirectionalLight->SetTransformation(transformation);
*/
}
#endif
assert(GetView());
AddLightsToViewport();
return TRUE;
}
// FUNCTION: LEGO1 0x100abad0
void LegoView1::Destroy()
{
if (m_pSunLight) {
GetView()->Remove(m_pSunLight);
delete m_pSunLight;
m_pSunLight = 0;
}
if (m_pDirectionalLight) {
GetView()->Remove(m_pDirectionalLight);
delete m_pDirectionalLight;
m_pDirectionalLight = 0;
}
if (m_pAmbientLight) {
GetView()->Remove(m_pAmbientLight);
delete m_pAmbientLight;
m_pAmbientLight = 0;
}
LegoView::Destroy();
}

View File

@ -0,0 +1,72 @@
#ifndef _LegoView1_h
#define _LegoView1_h
#include "compat.h"
#include "tglsurface.h"
class Tgl::Camera;
/////////////////////////////////////////////////////////////////////////////
// LegoView
// VTABLE: 0x100dc000
// SIZE 0x78
class LegoView : public TglSurface {
public:
LegoView();
virtual ~LegoView() override;
BOOL Create(const CreateStruct&, Tgl::Renderer*);
virtual void Destroy() override; // vtable+0x08
Tgl::Group* GetScene() const;
Tgl::Camera* GetCamera() const;
protected:
virtual Tgl::View* CreateView(Tgl::Renderer*, Tgl::Device*); // vtable+0x10
private:
Tgl::Group* m_pScene; // 0x70
Tgl::Camera* m_pCamera; // 0x74
};
/////////////////////////////////////////////////////////////////////////////
// LegoView implementation
inline Tgl::Group* LegoView::GetScene() const
{
return m_pScene;
}
inline Tgl::Camera* LegoView::GetCamera() const
{
return m_pCamera;
}
// SYNTHETIC: LEGO1 0x100ab580
// LegoView::`scalar deleting destructor'
/////////////////////////////////////////////////////////////////////////////
// LegoView1
// VTABLE: LEGO1 0x100dc018
// SIZE 0x88
class LegoView1 : public LegoView {
public:
LegoView1();
virtual ~LegoView1() override;
BOOL AddLightsToViewport();
BOOL Create(const TglSurface::CreateStruct&, Tgl::Renderer*);
virtual void Destroy() override; // vtable+0x08
private:
Tgl::Light* m_pSunLight; // 0x78
Tgl::Light* m_pDirectionalLight; // 0x7c
Tgl::Light* m_pAmbientLight; // 0x80
};
// SYNTHETIC: LEGO1 0x100ab7a0
// LegoView1::`scalar deleting destructor'
#endif /* _LegoView1_h */

View File

@ -0,0 +1,224 @@
// TglSurface.cpp : implementation file
#include "tglsurface.h"
#include "decomp.h"
DECOMP_SIZE_ASSERT(TglSurface, 0x70);
using namespace Tgl;
/////////////////////////////////////////////////////////////////////////////
// TglSurface
// FUNCTION: LEGO1 0x100abbf0
TglSurface::TglSurface()
{
m_pRenderer = 0;
m_pDevice = 0;
m_pView = 0;
m_pScene = 0;
m_width = 0;
m_height = 0;
m_stopRendering = FALSE;
m_isInitialized = FALSE;
// statistics
m_frameCount = 0;
#ifdef _DEBUG
m_triangleCount = 0;
#endif
}
// FUNCTION: LEGO1 0x100abd60
TglSurface::~TglSurface()
{
Destroy();
}
// FUNCTION: LEGO1 0x100abde0
void TglSurface::Destroy()
{
DestroyView();
delete m_pDevice;
m_pDevice = 0;
m_pRenderer = 0;
m_pScene = 0;
}
// ???
// FUNCTION: LEGO1 0x100abe10
int GetBitsPerPixel(IDirectDrawSurface* pSurface)
{
DDPIXELFORMAT pixelFormat;
HRESULT result;
memset(&pixelFormat, 0, sizeof(pixelFormat));
pixelFormat.dwSize = sizeof(pixelFormat);
result = pSurface->GetPixelFormat(&pixelFormat);
assert(result == DD_OK);
assert(pixelFormat.dwFlags & DDPF_RGB);
return pixelFormat.dwRGBBitCount;
}
// FUNCTION: LEGO1 0x100abe50
BOOL TglSurface::Create(const CreateStruct& rCreateStruct, Renderer* pRenderer, Group* pScene)
{
DeviceDirect3DCreateData createData = {rCreateStruct.m_direct3d, rCreateStruct.m_d3dDevice};
int bitsPerPixel = GetBitsPerPixel(rCreateStruct.m_pFrontBuffer);
ColorModel colorModel = Ramp;
ShadingModel shadingModel = Gouraud;
int shadeCount = 32;
BOOL dither = TRUE;
int textureShadeCount = -1;
int textureColorCount = -1;
Result result;
m_pRenderer = pRenderer;
m_pScene = pScene;
m_pDevice = m_pRenderer->CreateDevice(createData);
if (!m_pDevice) {
assert(0);
m_pRenderer = 0;
m_pScene = 0;
return FALSE;
}
if (bitsPerPixel == 1) {
shadeCount = 4;
textureShadeCount = 4;
}
else if (bitsPerPixel == 8) {
shadeCount = 16;
dither = FALSE;
textureShadeCount = 16;
textureColorCount = 256;
}
else if (bitsPerPixel == 16) {
shadeCount = 32;
dither = FALSE;
textureShadeCount = 32;
textureColorCount = 256;
}
else if (bitsPerPixel >= 24) {
shadeCount = 256;
dither = FALSE;
textureShadeCount = 256;
textureColorCount = 64;
}
else {
dither = FALSE;
}
if (textureShadeCount != -1) {
result = pRenderer->SetTextureDefaultShadeCount(textureShadeCount);
assert(Succeeded(result));
}
if (textureColorCount != -1) {
result = pRenderer->SetTextureDefaultColorCount(textureColorCount);
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));
result = m_pDevice->SetDither(dither);
assert(Succeeded(result));
m_width = m_pDevice->GetWidth();
m_height = m_pDevice->GetHeight();
m_pView = CreateView(m_pRenderer, m_pDevice);
if (!m_pView) {
delete m_pDevice;
m_pDevice = 0;
m_pRenderer = 0;
m_pScene = 0;
return FALSE;
}
m_frameRateMeter.Reset();
m_renderingRateMeter.Reset();
#ifdef _DEBUG
m_triangleRateMeter.Reset();
#endif
m_frameRateMeter.StartOperation();
m_isInitialized = TRUE;
return TRUE;
}
// FUNCTION: LEGO1 0x100ac030
void TglSurface::DestroyView()
{
delete m_pView;
m_pView = 0;
}
// FUNCTION: LEGO1 0x100ac050
double TglSurface::Render()
{
MxStopWatch renderTimer;
if (m_isInitialized && !m_stopRendering) {
Result result;
#ifdef _DEBUG
m_triangleRateMeter.StartOperation();
#endif
m_renderingRateMeter.StartOperation();
renderTimer.Start();
// TODO: Wrong interface
result = m_pView->Render((Tgl::Light*) m_pScene);
renderTimer.Stop();
assert(Succeeded(result));
m_renderingRateMeter.EndOperation();
#ifdef _DEBUG
m_triangleRateMeter.EndOperation();
#endif
m_frameRateMeter.EndOperation();
m_frameCount++;
#ifdef _DEBUG
{
unsigned long triangleCount = m_pDevice->GetDrawnTriangleCount();
m_triangleRateMeter.IncreaseOperationCount(triangleCount - m_triangleCount - 1);
m_triangleCount = triangleCount;
}
#endif
#if 0
// reset rate meters every 20 frames
if ((++m_frameCount % 20) == 0)
#else
// reset rate meters every 4 seconds
if (m_frameRateMeter.ElapsedSeconds() > 4.0)
#endif
{
m_frameRateMeter.Reset();
m_renderingRateMeter.Reset();
#ifdef _DEBUG
m_triangleRateMeter.Reset();
#endif
}
m_frameRateMeter.StartOperation();
}
return renderTimer.ElapsedSeconds();
}

View File

@ -0,0 +1,87 @@
#ifndef _TglSurface_h
#define _TglSurface_h
#include "../mxdirectx/mxstopwatch.h"
#include "../tgl/tgl.h"
class Tgl::Renderer;
class Tgl::Device;
class Tgl::View;
class Tgl::Group;
/////////////////////////////////////////////////////////////////////////////
// TglSurface
// VTABLE: LEGO1 0x100dc060
// SIZE 0x70
class TglSurface {
public:
// SIZE 0x28
struct CreateStruct {
const GUID* m_pDriverGUID; // 0x00
HWND m_hWnd; // 0x04
IDirectDraw* m_pDirectDraw; // 0x08
IDirectDrawSurface* m_pFrontBuffer; // 0x0c
IDirectDrawSurface* m_pBackBuffer; // 0x10
IDirectDrawPalette* m_pPalette; // 0x14
BOOL m_isFullScreen; // 0x18
BOOL m_isWideViewAngle; // 0x1c
IDirect3D2* m_direct3d; // 0x20
IDirect3DDevice2* m_d3dDevice; // 0x24
};
public:
TglSurface();
virtual ~TglSurface();
virtual BOOL Create(const CreateStruct&, Tgl::Renderer*, Tgl::Group* pScene); // vtable+0x04
virtual void Destroy(); // vtable+0x08
virtual double Render(); // render time in seconds // vtable+0x0c
Tgl::Renderer* GetRenderer() const { return m_pRenderer; }
Tgl::Device* GetDevice() const { return m_pDevice; }
Tgl::View* GetView() const { return m_pView; }
Tgl::Group* GetScene() const { return m_pScene; }
unsigned long GetWidth() const { return m_width; }
unsigned long GetHeight() const { return m_height; }
double GetRenderingRate() const { return m_renderingRateMeter.Frequency(); }
double GetFrameRate() const { return m_frameRateMeter.Frequency(); }
unsigned long GetFrameCount() const { return m_frameCount; }
#ifdef _DEBUG
double GetTriangleRate() const { return m_triangleRateMeter.Frequency(); }
#endif
protected:
virtual Tgl::View* CreateView(Tgl::Renderer*, Tgl::Device*) = 0; // vtable+0x10
virtual void DestroyView(); // vtable+0x14
private:
Tgl::Renderer* m_pRenderer; // 0x08
Tgl::Device* m_pDevice; // 0x0c
Tgl::View* m_pView; // 0x10
Tgl::Group* m_pScene; // 0x14
unsigned long m_width; // 0x18
unsigned long m_height; // 0x1c
BOOL m_isInitialized; // 0x20
BOOL m_stopRendering; // 0x24
// statistics
MxFrequencyMeter m_renderingRateMeter; // 0x28
MxFrequencyMeter m_frameRateMeter; // 0x48
unsigned long m_frameCount; // 0x68
#ifdef _DEBUG
MxFrequencyMeter m_triangleRateMeter;
unsigned long m_triangleCount;
#endif
};
/////////////////////////////////////////////////////////////////////////////
// SYNTHETIC: LEGO1 0x100abcf0
// TglSurface::`scalar deleting destructor'
#endif /* _TglSurface_h */

View File

@ -1,72 +0,0 @@
#include "lego3dmanager.h"
#include "decomp.h"
#include "tgl/tgl.h"
#include "tglsurface.h"
#include "viewmanager/viewlodlist.h"
DECOMP_SIZE_ASSERT(Lego3DManager, 0x10);
// FUNCTION: LEGO1 0x100ab2d0
BOOL InitializeCreateStruct(TglSurface::CreateStruct& p_tglSurface, const Lego3DManager::CreateStruct& p_createStruct)
{
p_tglSurface.m_driverGUID = p_createStruct.m_driverGUID;
p_tglSurface.m_hwnd = p_createStruct.m_hwnd;
p_tglSurface.m_directDraw = p_createStruct.m_directDraw;
p_tglSurface.m_ddSurface1 = p_createStruct.m_ddSurface1;
p_tglSurface.m_ddSurface2 = p_createStruct.m_ddSurface2;
p_tglSurface.m_ddPalette = p_createStruct.m_ddPalette;
p_tglSurface.m_isFullScreen = p_createStruct.m_isFullScreen;
p_tglSurface.m_flags = p_createStruct.m_flags;
p_tglSurface.m_direct3d = p_createStruct.m_direct3d;
p_tglSurface.m_d3dDevice = p_createStruct.m_d3dDevice;
return TRUE;
}
// FUNCTION: LEGO1 0x100ab320
Lego3DManager::Lego3DManager()
{
m_renderer = NULL;
m_3dView = NULL;
m_viewLODListManager = NULL;
}
// FUNCTION: LEGO1 0x100ab360
Lego3DManager::~Lego3DManager()
{
Destroy();
}
// FUNCTION: LEGO1 0x100ab370
BOOL Lego3DManager::Create(Lego3DManager::CreateStruct& p_createStruct)
{
TglSurface::CreateStruct surfaceCreateStruct;
m_viewLODListManager = new ViewLODListManager;
m_renderer = Tgl::CreateRenderer();
m_3dView = new Lego3DView;
InitializeCreateStruct(surfaceCreateStruct, p_createStruct);
return m_3dView->Create(surfaceCreateStruct, m_renderer);
}
// FUNCTION: LEGO1 0x100ab460
void Lego3DManager::Destroy()
{
delete m_3dView;
m_3dView = NULL;
delete m_renderer;
m_renderer = NULL;
delete m_viewLODListManager;
m_viewLODListManager = NULL;
}
// STUB: LEGO1 0xx100ab4b0
double Lego3DManager::FUN_100ab4b0(double p_und)
{
// TODO
return 0.0;
}

View File

@ -1,46 +0,0 @@
#ifndef LEGO3DMANAGER_H
#define LEGO3DMANAGER_H
#include "lego3dview.h"
class ViewLODListManager;
// VTABLE: LEGO1 0x100dbfa4
// SIZE 0x10
class Lego3DManager {
public:
// SIZE 0x28
struct CreateStruct {
GUID* m_driverGUID; // 0x00
HWND m_hwnd; // 0x04
IDirectDraw* m_directDraw; // 0x08
IDirectDrawSurface* m_ddSurface1; // 0x0c
IDirectDrawSurface* m_ddSurface2; // 0x10
IDirectDrawPalette* m_ddPalette; // 0x14
BOOL m_isFullScreen; // 0x18
MxU32 m_flags; // 0x1c
IDirect3D2* m_direct3d; // 0x20
IDirect3DDevice2* m_d3dDevice; // 0x24
};
Lego3DManager();
virtual ~Lego3DManager();
BOOL Create(CreateStruct& p_createStruct);
double FUN_100ab4b0(double p_und);
inline Lego3DView* GetLego3DView() { return this->m_3dView; }
inline ViewLODListManager* GetViewLODListManager() { return this->m_viewLODListManager; }
private:
Tgl::Renderer* m_renderer; // 0x04
Lego3DView* m_3dView; // 0x08
ViewLODListManager* m_viewLODListManager; // 0x0c
void Destroy();
};
// SYNTHETIC: LEGO1 0x100ab340
// Lego3DManager::`scalar deleting destructor'
#endif // LEGO3DMANAGER_H

View File

@ -1,50 +0,0 @@
#include "lego3dview.h"
#include "legoroi.h"
#include "tgl/tgl.h"
DECOMP_SIZE_ASSERT(Lego3DView, 0xa8)
// STUB: LEGO1 0x100aae90
Lego3DView::Lego3DView()
{
}
// STUB: LEGO1 0x100aaf30
Lego3DView::~Lego3DView()
{
}
// STUB: LEGO1 0x100aaf90
BOOL Lego3DView::Create(TglSurface::CreateStruct& p_createStruct, Tgl::Renderer* p_renderer)
{
Tgl::DeviceDirectDrawCreateData createData = {
p_createStruct.m_driverGUID,
p_createStruct.m_hwnd,
p_createStruct.m_directDraw,
p_createStruct.m_ddSurface1,
p_createStruct.m_ddSurface2
};
m_device = p_renderer->CreateDevice(createData);
return TRUE;
}
// STUB: LEGO1 0x100ab100
void Lego3DView::FUN_100ab100(LegoROI* p_roi)
{
// TODO
}
// STUB: LEGO1 0x100ab1b0
void Lego3DView::FUN_100ab1b0(LegoROI* p_roi)
{
// TODO
}
// STUB: LEGO1 0x100ab2b0
LegoROI* Lego3DView::PickROI(MxLong p_a, MxLong p_b)
{
// TODO
return NULL;
}

View File

@ -1,41 +0,0 @@
#ifndef LEGO3DVIEW_H
#define LEGO3DVIEW_H
#include "mxtypes.h"
#include "tgl/d3drm/impl.h"
#include "tglsurface.h"
#include "viewmanager/viewmanager.h"
class LegoROI;
// VTABLE: LEGO1 0x100dbf78
// SIZE 0xa8
class Lego3DView {
public:
Lego3DView();
virtual ~Lego3DView();
BOOL Create(TglSurface::CreateStruct& p_createStruct, Tgl::Renderer* p_renderer);
LegoROI* PickROI(MxLong p_a, MxLong p_b);
void FUN_100ab100(LegoROI* p_roi);
void FUN_100ab1b0(LegoROI* p_roi);
inline ViewManager* GetViewManager() { return this->m_viewManager; }
inline Tgl::Device* GetDevice() { return this->m_device; }
inline Tgl::View* GetView() { return this->m_view; }
private:
// TODO: all of these fields are in various base classes
undefined4 m_unk0x4; // 0x04
Tgl::Renderer* m_renderer; // 0x08
Tgl::Device* m_device; // 0x0c
Tgl::View* m_view; // 0x10
undefined m_unk0x14[0x74]; // 0x14
ViewManager* m_viewManager; // 0x88
undefined m_unk0x8c[0x1c]; // 0x8c
};
// SYNTHETIC: LEGO1 0x100aaf10
// Lego3DView::`scalar deleting destructor'
#endif // LEGO3DVIEW_H

View File

@ -255,7 +255,7 @@ void FUN_1001a700()
// FUNCTION: LEGO1 0x1003dd70
LegoROI* PickROI(MxLong p_a, MxLong p_b)
{
return VideoManager()->Get3DManager()->GetLego3DView()->PickROI(p_a, p_b);
return (LegoROI*) VideoManager()->Get3DManager()->GetLego3DView()->Pick(p_a, p_b);
}
// STUB: LEGO1 0x1003ddc0

View File

@ -5,6 +5,7 @@
#include "mxtimer.h"
#include "mxtransitionmanager.h"
#include "realtime/matrix.h"
#include "tgl/d3drm/impl.h"
#include "viewmanager/viewroi.h"
DECOMP_SIZE_ASSERT(LegoVideoManager, 0x590);
@ -149,13 +150,13 @@ MxResult LegoVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyM
Lego3DManager::CreateStruct createStruct;
memset(&createStruct, 0, sizeof(createStruct));
createStruct.m_hwnd = LegoOmni::GetInstance()->GetWindowHandle();
createStruct.m_directDraw = m_pDirectDraw;
createStruct.m_ddSurface1 = m_displaySurface->GetDirectDrawSurface1();
createStruct.m_ddSurface2 = m_displaySurface->GetDirectDrawSurface2();
createStruct.m_ddPalette = m_videoParam.GetPalette()->CreateNativePalette();
createStruct.m_hWnd = LegoOmni::GetInstance()->GetWindowHandle();
createStruct.m_pDirectDraw = m_pDirectDraw;
createStruct.m_pFrontBuffer = m_displaySurface->GetDirectDrawSurface1();
createStruct.m_pBackBuffer = m_displaySurface->GetDirectDrawSurface2();
createStruct.m_pPalette = m_videoParam.GetPalette()->CreateNativePalette();
createStruct.m_isFullScreen = FALSE;
createStruct.m_flags = m_videoParam.Flags().GetWideViewAngle();
createStruct.m_isWideViewAngle = m_videoParam.Flags().GetWideViewAngle();
createStruct.m_direct3d = m_direct3d->GetDirect3D();
createStruct.m_d3dDevice = m_direct3d->GetDirect3DDevice();
@ -174,8 +175,8 @@ MxResult LegoVideoManager::Create(MxVideoParam& p_videoParam, MxU32 p_frequencyM
CalcLocalTransform(posVec, dirVec, upVec, outMatrix);
m_viewROI->WrappedSetLocalTransform(outMatrix);
m_3dManager->GetLego3DView()->FUN_100ab100(m_viewROI);
m_3dManager->GetLego3DView()->FUN_100ab1b0(m_viewROI);
m_3dManager->Add(*m_viewROI);
m_3dManager->SetPointOfView(*m_viewROI);
m_unk0x100d9d00 = new MxUnknown100d9d00;
m_unk0xe4 = FALSE;
@ -224,31 +225,6 @@ void LegoVideoManager::MoveCursor(MxS32 p_cursorX, MxS32 p_cursorY)
m_cursorY = 463;
}
inline void LegoVideoManager::DrawCursor()
{
if (m_cursorX != m_cursorXCopy || m_cursorY != m_cursorYCopy) {
if (m_cursorX >= 0 && m_cursorY >= 0) {
m_cursorXCopy = m_cursorX;
m_cursorYCopy = m_cursorY;
}
}
LPDIRECTDRAWSURFACE ddSurface2 = m_displaySurface->GetDirectDrawSurface2();
if (!m_unk0x514) {
m_unk0x518.top = 0;
m_unk0x518.left = 0;
m_unk0x518.bottom = 16;
m_unk0x518.right = 16;
m_unk0x514 = MxDisplaySurface::FUN_100bc070();
if (!m_unk0x514)
m_drawCursor = FALSE;
}
ddSurface2->BltFast(m_cursorXCopy, m_cursorYCopy, m_unk0x514, &m_unk0x518, DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY);
}
// FUNCTION: LEGO1 0x1007b770
MxResult LegoVideoManager::Tickle()
{
@ -284,7 +260,7 @@ MxResult LegoVideoManager::Tickle()
presenter->PutData();
if (!m_unk0xe5) {
m_3dManager->FUN_100ab4b0(0.0);
m_3dManager->Render(0.0);
m_3dManager->GetLego3DView()->GetDevice()->Update();
}
@ -321,6 +297,31 @@ MxResult LegoVideoManager::Tickle()
return SUCCESS;
}
inline void LegoVideoManager::DrawCursor()
{
if (m_cursorX != m_cursorXCopy || m_cursorY != m_cursorYCopy) {
if (m_cursorX >= 0 && m_cursorY >= 0) {
m_cursorXCopy = m_cursorX;
m_cursorYCopy = m_cursorY;
}
}
LPDIRECTDRAWSURFACE ddSurface2 = m_displaySurface->GetDirectDrawSurface2();
if (!m_unk0x514) {
m_unk0x518.top = 0;
m_unk0x518.left = 0;
m_unk0x518.bottom = 16;
m_unk0x518.right = 16;
m_unk0x514 = MxDisplaySurface::FUN_100bc070();
if (!m_unk0x514)
m_drawCursor = FALSE;
}
ddSurface2->BltFast(m_cursorXCopy, m_cursorYCopy, m_unk0x514, &m_unk0x518, DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY);
}
// STUB: LEGO1 0x1007bbc0
void LegoVideoManager::DrawFPS()
{

View File

@ -1,8 +1,8 @@
#ifndef LEGOVIDEOMANAGER_H
#define LEGOVIDEOMANAGER_H
#include "3dmanager/lego3dmanager.h"
#include "decomp.h"
#include "lego3dmanager.h"
#include "mxdirect3d.h"
#include "mxdirectx/mxstopwatch.h"
#include "mxunknown100d9d00.h"
@ -10,6 +10,8 @@
#include <ddraw.h>
class LegoROI;
// VTABLE: LEGO1 0x100d9c88
// SIZE 0x590
class LegoVideoManager : public MxVideoManager {

View File

@ -2,7 +2,9 @@
#define _MxStopWatch_h
#include "assert.h"
#include "winbase.h"
#include <math.h>
#include <windows.h>
//////////////////////////////////////////////////////////////////////////////
//
@ -13,6 +15,7 @@
#define HUGE_VAL_IMMEDIATE 1.7976931348623157e+308
// SIZE 0x18
class MxStopWatch {
public:
MxStopWatch();
@ -28,11 +31,11 @@ protected:
unsigned long TicksPerSeconds() const;
private:
LARGE_INTEGER m_startTick;
LARGE_INTEGER m_startTick; // 0x00
// ??? when we provide LARGE_INTEGER arithmetic, use a
// LARGE_INTEGER m_elapsedTicks rather than m_elapsedSeconds
double m_elapsedSeconds;
unsigned long m_ticksPerSeconds;
double m_elapsedSeconds; // 0x0c
unsigned long m_ticksPerSeconds; // 0x14
};
inline MxStopWatch::MxStopWatch()
@ -99,6 +102,7 @@ inline double MxStopWatch::ElapsedSeconds() const
// MxFrequencyMeter
//
// SIZE 0x20
class MxFrequencyMeter {
public:
MxFrequencyMeter();
@ -114,8 +118,8 @@ public:
void IncreaseOperationCount(unsigned long);
private:
unsigned long m_operationCount;
MxStopWatch m_stopWatch;
unsigned long m_operationCount; // 0x00
MxStopWatch m_stopWatch; // 0x08
};
//////////////////////////////////////////////////////////////////////////////

View File

@ -1,5 +1,6 @@
#include "../tgl.h"
#include "compat.h"
#include "decomp.h"
#include <d3drm.h>
@ -41,11 +42,11 @@ public:
RendererImpl() : m_data(0) {}
~RendererImpl() { Destroy(); };
virtual void* ImplementationDataPtr();
virtual void* ImplementationDataPtr() override;
// vtable+0x08
virtual Device* CreateDevice(const DeviceDirect3DCreateData&);
virtual Device* CreateDevice(const DeviceDirectDrawCreateData&);
virtual Device* CreateDevice(const DeviceDirectDrawCreateData&) override;
virtual Device* CreateDevice(const DeviceDirect3DCreateData&) override;
// vtable+0x10
virtual View* CreateView(
@ -55,14 +56,14 @@ public:
unsigned long y,
unsigned long width,
unsigned long height
);
virtual Camera* CreateCamera();
virtual Light* CreateLight(LightType, float r, float g, float b);
virtual Group* CreateGroup(const Group* pParent);
) override;
virtual Camera* CreateCamera() override;
virtual Light* CreateLight(LightType, float r, float g, float b) override;
virtual Group* CreateGroup(const Group* pParent) override;
// vtable+0x20
virtual Unk* CreateUnk();
virtual Texture* CreateTexture();
virtual Unk* CreateUnk() override;
virtual Texture* CreateTexture() override;
virtual Texture* CreateTexture(
int width,
int height,
@ -71,11 +72,11 @@ public:
int pTexelsArePersistent,
int paletteEntryCount,
const PaletteEntry* pEntries
);
virtual Result SetTextureDefaultShadeCount(unsigned long);
) override;
virtual Result SetTextureDefaultShadeCount(unsigned long) override;
// vtable+0x30
virtual Result SetTextureDefaultColorCount(unsigned long);
virtual Result SetTextureDefaultColorCount(unsigned long) override;
public:
inline Result Create();

View File

@ -110,8 +110,8 @@ public:
class Renderer : public Object {
public:
// vtable+0x08
virtual Device* CreateDevice(const DeviceDirect3DCreateData&) = 0;
virtual Device* CreateDevice(const DeviceDirectDrawCreateData&) = 0;
virtual Device* CreateDevice(const DeviceDirect3DCreateData&) = 0;
// vtable+0x10
virtual View* CreateView(

View File

@ -1,27 +0,0 @@
#ifndef TGLSURFACE_H
#define TGLSURFACE_H
#include "decomp.h"
#include "mxtypes.h"
#include <d3d.h>
#include <windows.h>
class TglSurface {
public:
// SIZE 0x28
struct CreateStruct {
GUID* m_driverGUID; // 0x00
HWND m_hwnd; // 0x04
IDirectDraw* m_directDraw; // 0x08
IDirectDrawSurface* m_ddSurface1; // 0x0c
IDirectDrawSurface* m_ddSurface2; // 0x10
IDirectDrawPalette* m_ddPalette; // 0x14
BOOL m_isFullScreen; // 0x18
MxU32 m_flags; // 0x1c
IDirect3D2* m_direct3d; // 0x20
IDirect3DDevice2* m_d3dDevice; // 0x24
};
};
#endif // TGLSURFACE_H