Mercurial > mm7
changeset 2410:2d3c3d1dff0c
added RenderStruct.h
author | Ritor1 |
---|---|
date | Tue, 15 Jul 2014 15:44:45 +0600 |
parents | b29880e9ee79 |
children | 4106678916e1 |
files | Build/Visual Studio 2010/World of Might and Magic.vcxproj Build/Visual Studio 2010/World of Might and Magic.vcxproj.filters DirectX11.cpp DirectX11.h Render.cpp Render.h RenderStruct.h |
diffstat | 7 files changed, 727 insertions(+), 497 deletions(-) [+] |
line wrap: on
line diff
--- a/Build/Visual Studio 2010/World of Might and Magic.vcxproj Mon Jul 14 19:48:47 2014 +0600 +++ b/Build/Visual Studio 2010/World of Might and Magic.vcxproj Tue Jul 15 15:44:45 2014 +0600 @@ -460,6 +460,7 @@ <ClInclude Include="..\..\Random.h" /> <ClInclude Include="..\..\Registry.h" /> <ClInclude Include="..\..\Render.h" /> + <ClInclude Include="..\..\RenderStruct.h" /> <ClInclude Include="..\..\resource.h" /> <ClInclude Include="..\..\SaveLoad.h" /> <ClInclude Include="..\..\Spells.h" />
--- a/Build/Visual Studio 2010/World of Might and Magic.vcxproj.filters Mon Jul 14 19:48:47 2014 +0600 +++ b/Build/Visual Studio 2010/World of Might and Magic.vcxproj.filters Tue Jul 15 15:44:45 2014 +0600 @@ -533,6 +533,7 @@ <Filter>UI</Filter> </ClInclude> <ClInclude Include="..\..\DirectX11.h" /> + <ClInclude Include="..\..\RenderStruct.h" /> </ItemGroup> <ItemGroup> <Filter Include="lib">
--- a/DirectX11.cpp Mon Jul 14 19:48:47 2014 +0600 +++ b/DirectX11.cpp Tue Jul 15 15:44:45 2014 +0600 @@ -1,6 +1,8 @@ +#define _CRT_SECURE_NO_WARNINGS #define WIN32_LEAN_AND_MEAN #include "DirectX11.h" +#include "RenderStruct.h" HRESULT D3D11::InitDevice() { @@ -54,7 +56,7 @@ // Теперь создаем задний буфер. Обратите внимание, в SDK // RenderTargetOutput - это передний буфер, а RenderTargetView - задний. - ID3D11Texture2D* pBackBuffer = NULL; + pBackBuffer = NULL; hr = g_pSwapChain->GetBuffer( 0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer ); if (FAILED(hr)) return hr; @@ -102,4 +104,4 @@ void Render() { -} \ No newline at end of file +}
--- a/DirectX11.h Mon Jul 14 19:48:47 2014 +0600 +++ b/DirectX11.h Tue Jul 15 15:44:45 2014 +0600 @@ -10,23 +10,42 @@ #include "VectorTypes.h" #include <d3d11.h> -#include <Render.h> +#include "RenderStruct.h" #pragma comment(lib, "d3d11.lib") class D3D11 { HINSTANCE g_hInst; HWND g_hWnd; - D3D_DRIVER_TYPE g_driverType; //Этот параметр указывает, производить вычисления в видеокарте или в центральном процессоре. - D3D_FEATURE_LEVEL g_featureLevel; //параметр, указывающий, какую версию DirectX поддерживает наша видеокарта. - ID3D11Device* g_pd3dDevice; - ID3D11DeviceContext* g_pImmediateContext; - IDXGISwapChain* g_pSwapChain; + D3D_DRIVER_TYPE g_driverType; //Этот параметр указывает, производить вычисления в видеокарте или в центральном процессоре. + D3D_FEATURE_LEVEL g_featureLevel; //параметр, указывающий, какую версию DirectX поддерживает наша видеокарта. + ID3D11Device* g_pd3dDevice; //устройство d3d11 + ID3D11DeviceContext* g_pImmediateContext;// контекст устройства + IDXGISwapChain* g_pSwapChain; // цепочка обмена ID3D11RenderTargetView* g_pRenderTargetView; public: + int *pActiveZBuffer; + //IDirectDraw4 *pDirectDraw4; + //IDirectDrawSurface4 *pFrontBuffer4; + //IDirectDrawSurface4 *pBackBuffer4; + ID3D11Texture2D* pBackBuffer; + void *pTargetSurface; + unsigned int uTargetSurfacePitch; + unsigned int bUseColoredLights; + unsigned int bTinting; + unsigned int bUsingSpecular; + uint32_t uFogColor; + unsigned int pHDWaterBitmapIDs[7]; + int hd_water_current_frame; + int hd_water_tile_id; + void (*pBeforePresentFunction)(); + uint32_t bFogEnabled; + RenderBillboardD3D pBillboardRenderListD3D[1000]; + unsigned int uNumBillboardsToDraw; + D3D11(): g_hInst(NULL), g_hWnd(NULL), g_driverType(D3D_DRIVER_TYPE_NULL), g_featureLevel(D3D_FEATURE_LEVEL_11_0), g_pd3dDevice(NULL), g_pImmediateContext(NULL), g_pSwapChain(NULL), g_pRenderTargetView(NULL){} @@ -34,6 +53,7 @@ HRESULT InitDevice(); // Инициализация устройств DirectX void CleanupDevice(); // Удаление созданнных устройств DirectX //void Render(); // Функция рисования + bool Initialize(OSWindow *window, bool bColoredLights, uint32_t uDetailLevel, bool bTinting); @@ -164,4 +184,14 @@ void am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3); void am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode); + + inline void ToggleTint() {bTinting = !bTinting;} + inline void ToggleColoredLights() {bUseColoredLights = !bUseColoredLights;} + + inline unsigned int GetRenderWidth() {return window->GetWidth();} + inline unsigned int GetRenderHeight() {return window->GetHeight();} + + + friend void Present_NoColorKey(); + };
--- a/Render.cpp Mon Jul 14 19:48:47 2014 +0600 +++ b/Render.cpp Tue Jul 15 15:44:45 2014 +0600 @@ -1333,9 +1333,9 @@ //IDirectDraw4 *v9; // eax@16 //IDirectDraw4 *v10; // eax@20 //IDirectDraw4 *v13; // eax@35 - const char *v23; // [sp-4h] [bp-DCh]@9 - const char *v24; // [sp-4h] [bp-DCh]@13 - const char *v25; // [sp-4h] [bp-DCh]@19 + //const char *v23; // [sp-4h] [bp-DCh]@9 + //const char *v24; // [sp-4h] [bp-DCh]@13 + //const char *v25; // [sp-4h] [bp-DCh]@19 DWORD v26; // [sp-4h] [bp-DCh]@30 DDSCAPS2 v27; // [sp+Ch] [bp-CCh]@37 DDSURFACEDESC2 ddsd2; // [sp+1Ch] [bp-BCh]@11 @@ -1370,9 +1370,7 @@ { if (FAILED(pHost->SetCooperativeLevel(hWnd, DDSCL_MULTITHREADED | DDSCL_NORMAL))) { - v23 = "Init - Failed to set cooperative level.\n"; - sprintf(pErrorMessage, v23); -LABEL_65: + sprintf(pErrorMessage, "Init - Failed to set cooperative level.\n"); if (pHost) { pHost->Release(); @@ -1390,8 +1388,18 @@ pHost->GetDisplayMode(&ddsd2); if ( FORCE_16_BITS && ddsd2.ddpfPixelFormat.dwRGBBitCount != 16 ) { - v24 = "Init - Desktop isn't in 16 bit mode.\n"; - goto LABEL_14; + sprintf(pErrorMessage, "Init - Desktop isn't in 16 bit mode.\n"); + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer = 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; @@ -1400,20 +1408,38 @@ ddsd2.dwHeight = game_height; if (pHost->CreateSurface(&ddsd2, &pBackBuffer, 0) ) { - v24 = "Init - Failed to create back buffer.\n"; -LABEL_14: - sprintf(pErrorMessage, v24); + sprintf(pErrorMessage, "Init - Failed to create back buffer.\n"); if (pFrontBuffer) { pFrontBuffer->Release(); pFrontBuffer = 0; } - goto LABEL_65; + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } if ( pHost->CreateClipper(0, &v30, 0) ) { - v25 = "Init - Failed to create clipper.\n"; - goto LABEL_45; + sprintf(pErrorMessage, "Init - Failed to create clipper.\n"); + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } v30->SetHWnd(0, hWnd); pFrontBuffer->SetClipper(v30); @@ -1431,7 +1457,25 @@ if ( pDirect3D->EnumZBufferFormats(*pAvailableDevices[uDeviceID].pGUID, (HRESULT (__stdcall *)(DDPIXELFORMAT *, void *))D3DZBufferFormatEnumerator, &ddsd2.ddpfPixelFormat) ) - goto LABEL_21; + { + sprintf(pErrorMessage, "Init - Failed to enumerate Z buffer formats.\n"); + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; + } if ( uDeviceID == 2 || uDeviceID == 3 ) ddsd2.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; @@ -1439,10 +1483,7 @@ { if ( !pBackBuffer->AddAttachedSurface(pZBuffer) ) { - if ( !pDirect3D->CreateDevice(*pAvailableDevices[uDeviceID].pGUID, - pBackBuffer, - &pDevice, - 0) ) + if ( !pDirect3D->CreateDevice(*pAvailableDevices[uDeviceID].pGUID, pBackBuffer, &pDevice, 0) ) { memset(&d3dvp2, 0, sizeof(D3DVIEWPORT2)); d3dvp2.dvClipWidth = 2.0; @@ -1452,30 +1493,82 @@ d3dvp2.dvMinZ = 0.0; goto LABEL_54; } -LABEL_51: sprintf(pErrorMessage, "Init - Failed to create D3D device.\n"); if (pDirect3D) { pDirect3D->Release(); pDirect3D = 0; } - goto LABEL_59; + if (pZBuffer) + { + pZBuffer->Release(); + pZBuffer = 0; + } + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } -LABEL_48: sprintf(pErrorMessage, "Init - Failed to attach z-buffer to back buffer.\n"); if (pZBuffer) { pZBuffer->Release(); pZBuffer = 0; } - goto LABEL_61; - } - goto LABEL_44; - } -LABEL_36: - v23 = "Init - Failed to create front buffer.\n"; - sprintf(pErrorMessage, v23); - goto LABEL_65; + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; + } + sprintf(pErrorMessage, "Init - Failed to create z-buffer.\n"); + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; + } + sprintf(pErrorMessage, "Init - Failed to create front buffer.\n"); + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } if ( uDeviceID == 1 ) v26 = 1045; @@ -1483,15 +1576,23 @@ v26 = 1041; if (pHost->SetCooperativeLevel(hWnd, v26) ) { - v23 = "Init - Failed to set cooperative level.\n"; - sprintf(pErrorMessage, v23); - goto LABEL_65; + sprintf(pErrorMessage, "Init - Failed to set cooperative level.\n"); + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } if (pHost->SetDisplayMode(window->GetWidth(), window->GetHeight(), 16, 0, 0) ) { - v23 = "Init - Failed to set display mode.\n"; - sprintf(pErrorMessage, v23); - goto LABEL_65; + sprintf(pErrorMessage, "Init - Failed to set display mode.\n"); + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } memset(&ddsd2, 0, sizeof(DDSURFACEDESC2)); @@ -1500,7 +1601,15 @@ ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd2.dwBackBufferCount = 1; if ( pHost->CreateSurface(&ddsd2, &pFrontBuffer, 0) ) - goto LABEL_36; + { + sprintf(pErrorMessage, "Init - Failed to create front buffer.\n"); + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; + } //a3a = &pBackBuffer; //v14 = *v34; memset(&v27, 0, sizeof(DDSCAPS2)); @@ -1510,8 +1619,23 @@ pHost->QueryInterface(IID_IDirect3D3, (LPVOID *)&pDirect3D); if (FAILED(pFrontBuffer->GetAttachedSurface(&v27, &pBackBuffer))) { - v25 = "Init - Failed to get D3D interface.\n"; - goto LABEL_45; + sprintf(pErrorMessage, "Init - Failed to get D3D interface.\n"); + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; @@ -1522,41 +1646,103 @@ (HRESULT (__stdcall *)(DDPIXELFORMAT *, void *))D3DZBufferFormatEnumerator, &ddsd2.ddpfPixelFormat) ) { -LABEL_21: - v25 = "Init - Failed to enumerate Z buffer formats.\n"; - goto LABEL_45; + sprintf(pErrorMessage, "Init - Failed to enumerate Z buffer formats.\n"); + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } if ( uDeviceID == 2 || uDeviceID == 3 ) BYTE1(ddsd2.ddsCaps.dwCaps) |= 8u; //uDeviceIDa = &pZBuffer; if (pHost->CreateSurface(&ddsd2, &pZBuffer, 0) ) { -LABEL_44: - v25 = "Init - Failed to create z-buffer.\n"; -LABEL_45: - sprintf(pErrorMessage, v25); + sprintf(pErrorMessage, "Init - Failed to create z-buffer.\n"); + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; + } + if (pBackBuffer->AddAttachedSurface(pZBuffer)) + { + sprintf(pErrorMessage, "Init - Failed to attach z-buffer to back buffer.\n"); + if (pZBuffer) + { + pZBuffer->Release(); + pZBuffer = 0; + } if (pBackBuffer) { pBackBuffer->Release(); pBackBuffer = 0; } -LABEL_63: - //v19 = &pFrontBuffer; if (pFrontBuffer) { pFrontBuffer->Release(); pFrontBuffer= 0; } - goto LABEL_65; - } - if (pBackBuffer->AddAttachedSurface(pZBuffer)) - goto LABEL_48; + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; + } //v33 = &pDevice; - if (pDirect3D->CreateDevice(*pAvailableDevices[uDeviceID].pGUID, - pBackBuffer, - &pDevice, - 0) ) - goto LABEL_51; + if (pDirect3D->CreateDevice(*pAvailableDevices[uDeviceID].pGUID, pBackBuffer, &pDevice, 0) ) + { + sprintf(pErrorMessage, "Init - Failed to create D3D device.\n"); + if (pDirect3D) + { + pDirect3D->Release(); + pDirect3D = 0; + } + if (pZBuffer) + { + pZBuffer->Release(); + pZBuffer = 0; + } + if (pBackBuffer) + { + pBackBuffer->Release(); + pBackBuffer = 0; + } + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; + } memset(&d3dvp2, 0, sizeof(D3DVIEWPORT2)); d3dvp2.dvClipWidth = 2.0; d3dvp2.dvClipY = 1.0; @@ -1584,19 +1770,27 @@ pDirect3D->Release(); pDirect3D = 0; } -LABEL_59: if (pZBuffer) { pZBuffer->Release(); pZBuffer = 0; } -LABEL_61: if (pBackBuffer) { pBackBuffer->Release(); pBackBuffer = 0; } - goto LABEL_63; + if (pFrontBuffer) + { + pFrontBuffer->Release(); + pFrontBuffer= 0; + } + if (pHost) + { + pHost->Release(); + pHost = 0; + } + return 0; } pDevice->AddViewport(pViewport); @@ -2769,26 +2963,26 @@ //----- (0049FD3A) -------------------------------------------------------- void Render::_49FD3A_fullscreen() { - Render *v2; // esi@1 - IDirectDrawSurface4 *v3; // eax@6 - IDirectDrawSurface4 *v4; // ST0C_4@6 + //Render *v2; // esi@1 + //IDirectDrawSurface4 *v3; // eax@6 + //IDirectDrawSurface4 *v4; // ST0C_4@6 RECT v5; // [sp+8h] [bp-10h]@6 - Render* a1 = this; - v2 = a1; - if ( a1->pRenderD3D ) + //Render* a1 = this; + //v2 = this; + if ( this->pRenderD3D ) { if (pFrontBuffer4->IsLost() == DDERR_SURFACELOST) pFrontBuffer4->Restore(); if (pBackBuffer4->IsLost() == DDERR_SURFACELOST) pBackBuffer4->Restore(); - v3 = v2->pBackBuffer4; - v4 = v2->pFrontBuffer4; + //v3 = this->pBackBuffer4; + //v4 = this->pFrontBuffer4; v5.top = 0; v5.bottom = window->GetHeight(); v5.left = 0; v5.right = window->GetWidth(); - v3->BltFast(0, 0, v4, &v5, 16u); + this->pBackBuffer4->BltFast(0, 0, this->pFrontBuffer4, &v5, 16); } } @@ -2805,7 +2999,7 @@ //----- (0049FE05) -------------------------------------------------------- void Render::Release() { - Render *v1; // esi@1 + //Render *v1; // esi@1 //RenderD3D *v2; // ecx@1 //char v3; // zf@4 //void *v4; // ebx@6 @@ -2822,22 +3016,22 @@ // unsigned __int16 **v15; // ebx@28 // void **v16; // esi@29 - v1 = this; + // v1 = this; if (pRenderD3D) { - if ( v1->using_software_screen_buffer ) + if ( this->using_software_screen_buffer ) { pRenderD3D->ClearTarget(true, 0, false, 1.0); pRenderD3D->Present(0); pRenderD3D->ClearTarget(true, 0, false, 1.0); } - //v1->pColorKeySurface4 = 0; - v1->pBackBuffer4 = nullptr; - v1->pFrontBuffer4 = nullptr; - v1->pDirectDraw4 = nullptr; - delete [] v1->pTargetSurface_unaligned; - v1->pTargetSurface = nullptr; - v1->pTargetSurface_unaligned = nullptr; + //this->pColorKeySurface4 = 0; + this->pBackBuffer4 = nullptr; + this->pFrontBuffer4 = nullptr; + this->pDirectDraw4 = nullptr; + delete [] this->pTargetSurface_unaligned; + this->pTargetSurface = nullptr; + this->pTargetSurface_unaligned = nullptr; if (pRenderD3D) { pRenderD3D->Release(); @@ -2850,72 +3044,72 @@ /*{ if ( bWinNT4_0 == 1 ) { - v5 = (IDirectDraw *)v1->pDirectDraw2; + v5 = (IDirectDraw *)this->pDirectDraw2; if ( !v5 ) return; - v5->SetCooperativeLevel(v1->hWnd, 8u); - v1->pDirectDraw2->FlipToGDISurface(); - v6 = v1->pSomeSurface2; + v5->SetCooperativeLevel(this->hWnd, 8u); + this->pDirectDraw2->FlipToGDISurface(); + v6 = this->pSomeSurface2; if ( v6 ) { v6->Release(); - v1->pSomeSurface2 = 0; - } - v7 = v1->pBackBuffer2; + this->pSomeSurface2 = 0; + } + v7 = this->pBackBuffer2; if ( v7 ) { v7->Release(); - v1->pBackBuffer2 = 0; - } - v8 = v1->pFrontBuffer2; + this->pBackBuffer2 = 0; + } + v8 = this->pFrontBuffer2; if ( v8 ) { v8->Release(); - v1->pFrontBuffer2 = 0; - } - v9 = v1->pDirectDraw2; + this->pFrontBuffer2 = 0; + } + v9 = this->pDirectDraw2; if ( v9 ) { v9->Release(); - v1->pDirectDraw2 = 0; + this->pDirectDraw2 = 0; } } else { - v10 = v1->pDirectDraw4; + v10 = this->pDirectDraw4; if ( !v10 ) return; - v10->SetCooperativeLevel(v1->hWnd, 1032u); - v1->pDirectDraw4->FlipToGDISurface(); - v11 = v1->pColorKeySurface4; + v10->SetCooperativeLevel(this->hWnd, 1032u); + this->pDirectDraw4->FlipToGDISurface(); + v11 = this->pColorKeySurface4; if ( v11 ) { v11->Release(); - v1->pColorKeySurface4 = 0; - } - v12 = v1->pBackBuffer4; + this->pColorKeySurface4 = 0; + } + v12 = this->pBackBuffer4; if ( v12 ) { v12->Release(); - v1->pBackBuffer4 = 0; - } - v13 = v1->pFrontBuffer4; + this->pBackBuffer4 = 0; + } + v13 = this->pFrontBuffer4; if ( v13 ) { v13->Release(); - v1->pFrontBuffer4 = 0; - } - v14 = v1->pDirectDraw4; + this->pFrontBuffer4 = 0; + } + v14 = this->pDirectDraw4; if ( v14 ) { v14->Release(); - v1->pDirectDraw4 = 0; - } - } - v15 = &v1->pTargetSurface; - if ( v1->pTargetSurface ) - { - v16 = (void **)&v1->ptr_400E8; + this->pDirectDraw4 = 0; + } + } + v15 = &this->pTargetSurface; + if ( this->pTargetSurface ) + { + v16 = (void **)&this->ptr_400E8; free(*v16); *v15 = 0; *v16 = 0; @@ -2923,9 +3117,6 @@ }*/ } - - - void Present32(unsigned __int32 *src, unsigned int src_pitch, unsigned __int32 *dst, unsigned int dst_pitch) { @@ -3136,12 +3327,12 @@ //HWND v3; // ebx@1 //void *v4; // eax@2 //RenderD3D *v5; // eax@3 - unsigned int v6; // edx@5 + //unsigned int v6; // edx@5 RenderD3D__DevInfo *v7; // ecx@5 bool v8; // eax@6 - RenderD3D *v9; // ecx@13 + //RenderD3D *v9; // ecx@13 unsigned int v10; // eax@13 - RenderD3D *v11; // eax@25 + //RenderD3D *v11; // eax@25 // HRESULT v12; // eax@25 int v13; // ecx@25 int v14; // eax@27 @@ -3157,7 +3348,7 @@ DDSURFACEDESC2 pDesc; // [sp+108h] [bp-204h]@40 D3DDEVICEDESC halCaps; // [sp+184h] [bp-188h]@25 // DDSURFACEDESC2 ddsd2; // [sp+280h] [bp-8Ch]@38 - void *v28; // [sp+2FCh] [bp-10h]@2 + //void *v28; // [sp+2FCh] [bp-10h]@2 int v29; // [sp+308h] [bp-4h]@2 __debugbreak(); // Nomad @@ -3185,20 +3376,16 @@ else {*/ pRenderD3D = new RenderD3D; - v28 = pRenderD3D; - v6 = uDesiredDirect3DDevice; + //v28 = pRenderD3D; + //v6 = uDesiredDirect3DDevice; v29 = -1; v7 = pRenderD3D->pAvailableDevices; - if ( v7[v6].bIsDeviceCompatible ) - { - v8 = pRenderD3D->CreateDevice(v6, /*0*/true, window); - } + if ( pRenderD3D->pAvailableDevices[uDesiredDirect3DDevice].bIsDeviceCompatible ) + v8 = pRenderD3D->CreateDevice(uDesiredDirect3DDevice, /*0*/true, window); else { if ( v7[1].bIsDeviceCompatible ) - { v8 = pRenderD3D->CreateDevice(1, /*0*/true, window); - } else { if ( !v7->bIsDeviceCompatible ) @@ -3210,10 +3397,10 @@ if ( !v8 ) Error("D3Drend->Init failed."); - v9 = pRenderD3D; - pBackBuffer4 = v9->pBackBuffer; - pFrontBuffer4 = v9->pFrontBuffer; - pDirectDraw4 = v9->pHost; + //v9 = pRenderD3D; + pBackBuffer4 = pRenderD3D->pBackBuffer; + pFrontBuffer4 = pRenderD3D->pFrontBuffer; + pDirectDraw4 = pRenderD3D->pHost; v10 = pRenderD3D->GetDeviceCaps(); if ( v10 & 1 ) { @@ -3260,9 +3447,9 @@ memset(&halCaps, 0, 0xFCu); halCaps.dwSize = 252; memset(&refCaps, 0, 0xFCu); - v11 = pRenderD3D; + //v11 = pRenderD3D; refCaps.dwSize = 252; - ErrD3D(v11->pDevice->GetCaps(&halCaps, &refCaps)); + ErrD3D(pRenderD3D->pDevice->GetCaps(&halCaps, &refCaps)); v13 = halCaps.dwMinTextureWidth; if ( (unsigned int)halCaps.dwMinTextureWidth >= halCaps.dwMinTextureHeight ) v13 = halCaps.dwMinTextureHeight; @@ -3342,7 +3529,7 @@ using_software_screen_buffer = v15; //} bWindowMode = 0; - pParty->uFlags |= 2u; + pParty->uFlags |= 2; pViewport->SetFOV(flt_6BE3A0 * 65536.0f); return v15 != 0; } @@ -3995,7 +4182,7 @@ //----- (004A121C) -------------------------------------------------------- void Render::CreateFrontBuffer() { - Render *v1; // esi@1 + //Render *v1; // esi@1 IDirectDraw *pDD; // eax@3 IDirectDrawSurface **pOutSurf; // esi@3 struct _DDSURFACEDESC *v4; // edx@3 @@ -4004,18 +4191,18 @@ unsigned int v7; // [sp-4h] [bp-88h]@3 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3 - v1 = this; + //v1 = this; //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || //pVersion->pVersionInfo.dwMajorVersion != 4 ) { memset(&a2, 0, 0x7Cu); - pDD = (IDirectDraw *)v1->pDirectDraw4; + pDD = (IDirectDraw *)this->pDirectDraw4; a2.dwSize = 124; a2.dwFlags = 1; v7 = 0; a2.ddsCaps.dwCaps = 512; v6 = 2357; - pOutSurf = (IDirectDrawSurface **)&v1->pFrontBuffer4; + pOutSurf = (IDirectDrawSurface **)&this->pFrontBuffer4; v4 = (struct _DDSURFACEDESC *)&a2; } /*else @@ -4036,7 +4223,7 @@ //----- (004A12CD) -------------------------------------------------------- void Render::CreateBackBuffer() { - Render *v1; // esi@1 + //Render *v1; // esi@1 IDirectDraw *v2; // eax@3 IDirectDrawSurface **ppBackBuffer; // esi@3 struct _DDSURFACEDESC *v4; // edx@3 @@ -4045,12 +4232,12 @@ unsigned int v7; // [sp-4h] [bp-88h]@3 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3 - v1 = this; + //v1 = this; //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || // pVersion->pVersionInfo.dwMajorVersion != 4 ) { memset(&a2, 0, 0x7Cu); - v2 = (IDirectDraw *)v1->pDirectDraw4; + v2 = (IDirectDraw *)this->pDirectDraw4; a2.dwSize = 124; a2.dwFlags = 7; v7 = 0; @@ -4058,7 +4245,7 @@ a2.dwWidth = window->GetWidth(); a2.dwHeight = window->GetHeight(); v6 = 2387; - ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer4; + ppBackBuffer = (IDirectDrawSurface **)&this->pBackBuffer4; v4 = (struct _DDSURFACEDESC *)&a2; } /*else @@ -4081,7 +4268,7 @@ //----- (004A139A) -------------------------------------------------------- void Render::CreateDirectDrawPrimarySurface() { - Render *v1; // esi@1 + //Render *v1; // esi@1 //int v2; // ebx@3 // IDirectDraw2 *v3; // eax@3 // HRESULT v4; // eax@3 @@ -4100,24 +4287,21 @@ DDSCAPS2 v17; // [sp+88h] [bp-18h]@4 // int a4; // [sp+98h] [bp-8h]@3 - v1 = this; + //v1 = this; //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || //pVersion->pVersionInfo.dwMajorVersion != 4 ) { //v2 = 0; //this->field_4004C = 1; memset(&ddsd2, 0, 0x7Cu); - v7 = v1->pDirectDraw4; + v7 = this->pDirectDraw4; ddsd2.dwBackBufferCount = 1; ddsd2.dwSize = 0x7Cu; ddsd2.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd2.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_3DDEVICE | DDSCAPS_PRIMARYSURFACE; - ErrD3D(v7->CreateSurface( - &ddsd2, - &pFrontBuffer4, - 0)); - pFrontBuffer = (IDirectDrawSurface *)v1->pFrontBuffer4; - ppBackBuffer = (IDirectDrawSurface **)&v1->pBackBuffer4; + ErrD3D(v7->CreateSurface(&ddsd2, &pFrontBuffer4, 0)); + pFrontBuffer = (IDirectDrawSurface *)this->pFrontBuffer4; + ppBackBuffer = (IDirectDrawSurface **)&this->pBackBuffer4; } /*else {
--- a/Render.h Mon Jul 14 19:48:47 2014 +0600 +++ b/Render.h Tue Jul 15 15:44:45 2014 +0600 @@ -5,282 +5,10 @@ #include "lib\legacy_dx\d3d.h" #include "OSWindow.h" +#include "RenderStruct.h" #include "VectorTypes.h" - -#define ErrD3D(hr) \ - do \ - { \ - extern void ErrHR(HRESULT, const char *, const char *, const char *, int); \ - ErrHR(hr, "Direct3D", __FUNCTION__, __FILE__, __LINE__); \ - } while(0) - -struct Polygon; -struct Texture; -struct RGBTexture; -struct RenderBillboardTransform_local0; -struct ODMFace; - - -unsigned __int16 Color16(unsigned __int32 r, unsigned __int32 g, unsigned __int32 b); -unsigned __int32 Color32(unsigned __int16 color16); - -/* 119 */ -#pragma pack(push, 1) -struct RenderVertexSoft -{ - inline RenderVertexSoft(): - flt_2C(0.0f) - {} - - Vec3_float_ vWorldPosition; - Vec3_float_ vWorldViewPosition; - float vWorldViewProjX; - float vWorldViewProjY; - float _rhw; - float u; - float v; - float flt_2C; -}; -#pragma pack(pop) - - - -/* 112 */ -#pragma pack(push, 1) -struct RenderVertexD3D3 -{ - Vec3_float_ pos; - float rhw; - signed int diffuse; - unsigned int specular; - Vec2_float_ texcoord; -}; -#pragma pack(pop) - -class Sprite; -class SpriteFrame; - -/* 161 */ -#pragma pack(push, 1) -struct RenderBillboard -{ - int _screenspace_x_scaler_packedfloat; - int _screenspace_y_scaler_packedfloat; - float fov_x; - float fov_y; - union - { - int sZValue; - struct - { - unsigned __int16 object_pid; - signed __int16 actual_z; - }; - }; - int field_14_actor_id; - signed __int16 HwSpriteID; - __int16 uPalette; - __int16 uIndoorSectorID; - __int16 field_1E; - __int16 world_x; - __int16 world_y; - __int16 world_z; - __int16 uScreenSpaceX; - __int16 uScreenSpaceY; - unsigned __int16 dimming_level; - signed int sTintColor; - SpriteFrame *pSpriteFrame; - - inline float GetFloatZ() const - { - return (float)object_pid / 65535.0f + (float)actual_z; - } -}; -#pragma pack(pop) - - -#pragma pack(push, 1) -struct RenderD3D__DevInfo -{ - unsigned int bIsDeviceCompatible; - char *pName; - char *pDescription; - GUID *pGUID; - unsigned int uCaps; - char *pDriverName; - char *pDeviceDesc; - char *pDDraw4DevDesc; - GUID *pDirectDrawGUID; - int uVideoMem; -}; -#pragma pack(pop) - - - -#pragma pack(push, 1) -struct RenderD3D_D3DDevDesc -{ - int field_0; - int field_4; - int field_8; - int field_C; - int field_10; - char *pDriverName; - char *pDeviceDesc; - char *pDDraw4DevDesc; - GUID *pGUID; - unsigned int uVideoMem; -}; -#pragma pack(pop) - - - - - - - - - -/* 280 */ -#pragma pack(push, 1) -struct HWLTexture -{ - inline HWLTexture(): - field_0(0), field_4(0), field_8(0), - field_C(0), field_10(0), field_14(0) - {} - - int field_0; - int field_4; - int field_8; - int field_C; - int field_10; - int field_14; - int uBufferWidth; - int uBufferHeight; - int uAreaWidth; - int uAreaHeigth; - unsigned int uWidth; - unsigned int uHeight; - int uAreaX; - int uAreaY; - unsigned __int16 *pPixels; -}; -#pragma pack(pop) - - -/* 185 */ -#pragma pack(push, 1) -struct RenderHWLContainer -{ - RenderHWLContainer(); - bool Load(const wchar_t *pFilename); - bool Release(); - - HWLTexture *LoadTexture(const char *pName, int bMipMaps); - - FILE *pFile; - uint32_t uSignature; - unsigned int uDataOffset; - unsigned int uNumItems; - char *pSpriteNames[50000]; - int pSpriteOffsets[50000]; - int bDumpDebug; - int scale_hwls_to_half; -}; -#pragma pack(pop) - - - -/* 242 */ -#pragma pack(push, 1) -struct RenderBillboardD3D -{ - inline RenderBillboardD3D(): - opacity(Transparent), - field_90(-1), - sParentBillboardID(-1), - uNumVertices(4) - {} - - enum OpacityType: unsigned __int32 - { - Transparent = 0, - Opaque_1 = 1, - Opaque_2 = 2, - Opaque_3 = 3, - NoBlend = 0xFFFFFFFF - }; - - IDirect3DTexture2 *pTexture; - unsigned int uNumVertices; - RenderVertexD3D3 pQuads[4]; - float z_order; - OpacityType opacity; - int field_90; - int sZValue; - signed int sParentBillboardID; -}; -#pragma pack(pop) - - - - -#pragma pack(push, 1) -struct RenderD3D_aux -{ - RenderD3D__DevInfo *pInfo; - RenderD3D_D3DDevDesc *ptr_4; -}; -#pragma pack(pop) - - - -/* 183 */ -#pragma pack(push, 1) -class RenderD3D -{ -public: - RenderD3D(); - - void GetAvailableDevices(RenderD3D__DevInfo **pOutDevices); - void Release(); - bool CreateDevice(unsigned int uDeviceID, int bWindowed, OSWindow *window); - unsigned int GetDeviceCaps(); - void ClearTarget(unsigned int bClearColor, unsigned int uClearColor, unsigned int bClearDepth, float z_clear); - void Present(bool bForceBlit); - bool CreateTexture(unsigned int uTextureWidth, unsigned int uTextureHeight, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture, bool bAlphaChannel, bool bMipmaps, unsigned int uMinDeviceTexDim); - void HandleLostResources(); - - - unsigned int bWindowed; - int field_4; - int field_8; - HWND hWindow; - int field_10; - int field_14; - int field_18; - RenderD3D__DevInfo *pAvailableDevices; - IDirectDraw4 *pHost; - IDirect3D3 *pDirect3D; - IUnknown *pUnk; - IDirectDrawSurface4 *pBackBuffer; - IDirectDrawSurface4 *pFrontBuffer; - IDirectDrawSurface4 *pZBuffer; - IDirect3DDevice3 *pDevice; - IDirect3DViewport3 *pViewport; - int field_40; - int field_44; - char pErrorMessage[48]; - char field_78[208]; -}; -#pragma pack(pop) -extern struct RenderVertexD3D3 pVertices[50]; - -/* 182 */ -#pragma pack(push, 1) struct Render { Render(); @@ -539,67 +267,3 @@ //int windowed_mode_width; //int windowed_mode_height; }; -#pragma pack(pop) - -bool PauseGameDrawing(); - -extern struct IDirectDrawClipper *pDDrawClipper; -extern struct Render *pRenderer; // idb -extern struct pUnkTerrain *Unks; - - - -/* 248 */ -#pragma pack(push, 1) -struct RenderBillboardTransform_local0 -{ - void *pTarget; - int *pTargetZ; - int uScreenSpaceX; - int uScreenSpaceY; - int _screenspace_x_scaler_packedfloat; - int _screenspace_y_scaler_packedfloat; - char field_18[8]; - unsigned __int16 *pPalette; - unsigned __int16 *pPalette2; - union - { - int sZValue; - struct - { - unsigned short object_pid; - short zbuffer_depth; - }; - }; - unsigned int uFlags; // & 4 - mirror horizontally - unsigned int uTargetPitch; - unsigned int uViewportX; - unsigned int uViewportY; - unsigned int uViewportZ; - unsigned int uViewportW; - int field_44; - int sParentBillboardID; - int sTintColor; -}; -#pragma pack(pop) - - - - -extern int uNumDecorationsDrawnThisFrame; // weak -extern RenderBillboard pBillboardRenderList[500]; -extern unsigned int uNumBillboardsToDraw; -extern int uNumSpritesDrawnThisFrame; // weak - - - - -extern RenderVertexSoft array_507D30[50]; -extern RenderVertexSoft array_50AC10[50]; -extern RenderVertexSoft array_73D150[20]; - -extern RenderVertexD3D3 d3d_vertex_buffer[50]; - - -int ODM_NearClip(unsigned int uVertexID); // idb -int ODM_FarClip(unsigned int uNumVertices); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RenderStruct.h Tue Jul 15 15:44:45 2014 +0600 @@ -0,0 +1,348 @@ +#pragma once + +#include <cstdint> +#include <cstdio> + +#include "lib\legacy_dx\d3d.h" +#include "OSWindow.h" + +#include "VectorTypes.h" + + +#define ErrD3D(hr) \ + do \ + { \ + extern void ErrHR(HRESULT, const char *, const char *, const char *, int); \ + ErrHR(hr, "Direct3D", __FUNCTION__, __FILE__, __LINE__); \ + } while(0) + +struct Polygon; +struct Texture; +struct RGBTexture; +struct RenderBillboardTransform_local0; +struct ODMFace; + + +unsigned __int16 Color16(unsigned __int32 r, unsigned __int32 g, unsigned __int32 b); +unsigned __int32 Color32(unsigned __int16 color16); + +/* 119 */ +#pragma pack(push, 1) +struct RenderVertexSoft +{ + inline RenderVertexSoft(): + flt_2C(0.0f) + {} + + Vec3_float_ vWorldPosition; + Vec3_float_ vWorldViewPosition; + float vWorldViewProjX; + float vWorldViewProjY; + float _rhw; + float u; + float v; + float flt_2C; +}; +#pragma pack(pop) + + + +/* 112 */ +#pragma pack(push, 1) +struct RenderVertexD3D3 +{ + Vec3_float_ pos; + float rhw; + signed int diffuse; + unsigned int specular; + Vec2_float_ texcoord; +}; +#pragma pack(pop) + +class Sprite; +class SpriteFrame; + +/* 161 */ +#pragma pack(push, 1) +struct RenderBillboard +{ + int _screenspace_x_scaler_packedfloat; + int _screenspace_y_scaler_packedfloat; + float fov_x; + float fov_y; + union + { + int sZValue; + struct + { + unsigned __int16 object_pid; + signed __int16 actual_z; + }; + }; + int field_14_actor_id; + signed __int16 HwSpriteID; + __int16 uPalette; + __int16 uIndoorSectorID; + __int16 field_1E; + __int16 world_x; + __int16 world_y; + __int16 world_z; + __int16 uScreenSpaceX; + __int16 uScreenSpaceY; + unsigned __int16 dimming_level; + signed int sTintColor; + SpriteFrame *pSpriteFrame; + + inline float GetFloatZ() const + { + return (float)object_pid / 65535.0f + (float)actual_z; + } +}; +#pragma pack(pop) + + +#pragma pack(push, 1) +struct RenderD3D__DevInfo +{ + unsigned int bIsDeviceCompatible; + char *pName; + char *pDescription; + GUID *pGUID; + unsigned int uCaps; + char *pDriverName; + char *pDeviceDesc; + char *pDDraw4DevDesc; + GUID *pDirectDrawGUID; + int uVideoMem; +}; +#pragma pack(pop) + + + +#pragma pack(push, 1) +struct RenderD3D_D3DDevDesc +{ + int field_0; + int field_4; + int field_8; + int field_C; + int field_10; + char *pDriverName; + char *pDeviceDesc; + char *pDDraw4DevDesc; + GUID *pGUID; + unsigned int uVideoMem; +}; +#pragma pack(pop) + + + + + + + + + +/* 280 */ +#pragma pack(push, 1) +struct HWLTexture +{ + inline HWLTexture(): + field_0(0), field_4(0), field_8(0), + field_C(0), field_10(0), field_14(0) + {} + + int field_0; + int field_4; + int field_8; + int field_C; + int field_10; + int field_14; + int uBufferWidth; + int uBufferHeight; + int uAreaWidth; + int uAreaHeigth; + unsigned int uWidth; + unsigned int uHeight; + int uAreaX; + int uAreaY; + unsigned __int16 *pPixels; +}; +#pragma pack(pop) + + +/* 185 */ +#pragma pack(push, 1) +struct RenderHWLContainer +{ + RenderHWLContainer(); + bool Load(const wchar_t *pFilename); + bool Release(); + + HWLTexture *LoadTexture(const char *pName, int bMipMaps); + + FILE *pFile; + uint32_t uSignature; + unsigned int uDataOffset; + unsigned int uNumItems; + char *pSpriteNames[50000]; + int pSpriteOffsets[50000]; + int bDumpDebug; + int scale_hwls_to_half; +}; +#pragma pack(pop) + + + +/* 242 */ +#pragma pack(push, 1) +struct RenderBillboardD3D +{ + inline RenderBillboardD3D(): + opacity(Transparent), + field_90(-1), + sParentBillboardID(-1), + uNumVertices(4) + {} + + enum OpacityType: unsigned __int32 + { + Transparent = 0, + Opaque_1 = 1, + Opaque_2 = 2, + Opaque_3 = 3, + NoBlend = 0xFFFFFFFF + }; + + IDirect3DTexture2 *pTexture; + unsigned int uNumVertices; + RenderVertexD3D3 pQuads[4]; + float z_order; + OpacityType opacity; + int field_90; + int sZValue; + signed int sParentBillboardID; +}; +#pragma pack(pop) + + + + +#pragma pack(push, 1) +struct RenderD3D_aux +{ + RenderD3D__DevInfo *pInfo; + RenderD3D_D3DDevDesc *ptr_4; +}; +#pragma pack(pop) + + + +/* 183 */ +#pragma pack(push, 1) +class RenderD3D +{ +public: + RenderD3D(); + + void GetAvailableDevices(RenderD3D__DevInfo **pOutDevices); + void Release(); + bool CreateDevice(unsigned int uDeviceID, int bWindowed, OSWindow *window); + unsigned int GetDeviceCaps(); + void ClearTarget(unsigned int bClearColor, unsigned int uClearColor, unsigned int bClearDepth, float z_clear); + void Present(bool bForceBlit); + bool CreateTexture(unsigned int uTextureWidth, unsigned int uTextureHeight, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture, bool bAlphaChannel, bool bMipmaps, unsigned int uMinDeviceTexDim); + void HandleLostResources(); + + + unsigned int bWindowed; + int field_4; + int field_8; + HWND hWindow; + int field_10; + int field_14; + int field_18; + RenderD3D__DevInfo *pAvailableDevices; + IDirectDraw4 *pHost; + IDirect3D3 *pDirect3D; + IUnknown *pUnk; + IDirectDrawSurface4 *pBackBuffer; + IDirectDrawSurface4 *pFrontBuffer; + IDirectDrawSurface4 *pZBuffer; + IDirect3DDevice3 *pDevice; + IDirect3DViewport3 *pViewport; + int field_40; + int field_44; + char pErrorMessage[48]; + char field_78[208]; +}; +#pragma pack(pop) +extern struct RenderVertexD3D3 pVertices[50]; + +/* 182 */ +#pragma pack(push, 1) + +#pragma pack(pop) + +bool PauseGameDrawing(); + +extern struct IDirectDrawClipper *pDDrawClipper; +extern struct Render *pRenderer; // idb +extern struct pUnkTerrain *Unks; + + + +/* 248 */ +#pragma pack(push, 1) +struct RenderBillboardTransform_local0 +{ + void *pTarget; + int *pTargetZ; + int uScreenSpaceX; + int uScreenSpaceY; + int _screenspace_x_scaler_packedfloat; + int _screenspace_y_scaler_packedfloat; + char field_18[8]; + unsigned __int16 *pPalette; + unsigned __int16 *pPalette2; + union + { + int sZValue; + struct + { + unsigned short object_pid; + short zbuffer_depth; + }; + }; + unsigned int uFlags; // & 4 - mirror horizontally + unsigned int uTargetPitch; + unsigned int uViewportX; + unsigned int uViewportY; + unsigned int uViewportZ; + unsigned int uViewportW; + int field_44; + int sParentBillboardID; + int sTintColor; +}; +#pragma pack(pop) + + + + +extern int uNumDecorationsDrawnThisFrame; // weak +extern RenderBillboard pBillboardRenderList[500]; +extern unsigned int uNumBillboardsToDraw; +extern int uNumSpritesDrawnThisFrame; // weak + + + + +extern RenderVertexSoft array_507D30[50]; +extern RenderVertexSoft array_50AC10[50]; +extern RenderVertexSoft array_73D150[20]; + +extern RenderVertexD3D3 d3d_vertex_buffer[50]; + + +int ODM_NearClip(unsigned int uVertexID); // idb +int ODM_FarClip(unsigned int uNumVertices); \ No newline at end of file