comparison Render.cpp @ 1832:f3b106aff057

Merge
author Ritor1
date Mon, 07 Oct 2013 21:57:01 +0600
parents d7791af42deb 6de366add757
children f017f8e79aa1
comparison
equal deleted inserted replaced
1831:d7791af42deb 1832:f3b106aff057
175 } 175 }
176 } 176 }
177 } 177 }
178 178
179 //----- (004A16A5) -------------------------------------------------------- 179 //----- (004A16A5) --------------------------------------------------------
180 bool AreRenderSurfacesOk() 180 bool AreRenderSurfacesOk()
181 { 181 {
182 char v0; // zf@4 182 char v0; // zf@4
183 bool result; // eax@8 183 bool result; // eax@8
184 184
185 if (!pRenderer)
186 return true;
185 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 187 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 )
186 { 188 {
187 if ( !pRenderer->pBackBuffer4 ) 189 if ( !pRenderer->pBackBuffer4 )
188 goto LABEL_9; 190 goto LABEL_9;
189 v0 = pRenderer->pFrontBuffer4 == 0; 191 v0 = pRenderer->pFrontBuffer4 == 0;
2092 2094
2093 hd_water_tile_id = -1; 2095 hd_water_tile_id = -1;
2094 hd_water_current_frame = 0; 2096 hd_water_current_frame = 0;
2095 } 2097 }
2096 2098
2097 bool Render::Initialize(bool bWindowed, int windowed_width, int windowed_height, uint32_t uDefaultDevice, 2099 bool Render::Initialize(bool bWindowed, OSWindow *window, bool bColoredLights, uint32_t uDetailLevel, bool bTinting)
2098 bool bColoredLights, uint32_t uDetailLevel, bool bTinting) 2100 {
2099 { 2101 //bUserDirect3D = true;//ReadWindowsRegistryInt("Use D3D", 0);
2100 bUserDirect3D = true;//ReadWindowsRegistryInt("Use D3D", 0); 2102
2101 2103 this->window = window;
2102 bStartInWindow = bWindowed; 2104 bStartInWindow = bWindowed;
2103 windowed_mode_width = windowed_width; 2105 //windowed_mode_width = windowed_width;
2104 windowed_mode_height = windowed_height; 2106 //windowed_mode_height = windowed_height;
2105 2107
2106 uDesiredDirect3DDevice = uDefaultDevice;//ReadWindowsRegistryInt("D3D Device", 1); 2108 uDesiredDirect3DDevice = 0;//ReadWindowsRegistryInt("D3D Device", 1);
2107 2109
2108 bUseColoredLights = bColoredLights;//ReadWindowsRegistryInt("Colored Lights", 0); 2110 bUseColoredLights = bColoredLights;//ReadWindowsRegistryInt("Colored Lights", 0);
2109 uLevelOfDetail = uDetailLevel;//ReadWindowsRegistryInt("Detail Level", 1); 2111 uLevelOfDetail = uDetailLevel;//ReadWindowsRegistryInt("Detail Level", 1);
2110 2112
2111 this->bTinting = bTinting; 2113 this->bTinting = bTinting;
2184 IDirectDrawSurface *v2; // eax@3 2186 IDirectDrawSurface *v2; // eax@3
2185 DDBLTFX v3; // [sp+4h] [bp-74h]@5 2187 DDBLTFX v3; // [sp+4h] [bp-74h]@5
2186 RECT x; // [sp+68h] [bp-10h]@3 2188 RECT x; // [sp+68h] [bp-10h]@3
2187 2189
2188 memset(&v3, 0, sizeof(DDBLTFX)); 2190 memset(&v3, 0, sizeof(DDBLTFX));
2189 GetWindowRect(hWnd, &x); 2191 GetWindowRect(window->GetApiHandle(), &x);
2190 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || 2192 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
2191 pVersion->pVersionInfo.dwMajorVersion >= 5) 2193 pVersion->pVersionInfo.dwMajorVersion >= 5)
2192 { 2194 {
2193 v2 = (IDirectDrawSurface *)this->pBackBuffer4; 2195 v2 = (IDirectDrawSurface *)this->pBackBuffer4;
2194 } 2196 }
2907 if ( v1->field_40110 ) 2909 if ( v1->field_40110 )
2908 { 2910 {
2909 pRenderD3D->Present(false); 2911 pRenderD3D->Present(false);
2910 } 2912 }
2911 } 2913 }
2912 else 2914 else __debugbreak(); // no sr
2913 { 2915 /*{
2914 if ( v1->bWindowMode ) 2916 if ( v1->bWindowMode )
2915 { 2917 {
2916 RestoreFrontBuffer(); 2918 RestoreFrontBuffer();
2917 GetClientRect(v1->hWnd, &Rect); 2919 GetClientRect(v1->hWnd, &Rect);
2918 Point.y = 0; 2920 Point.y = 0;
2932 a4.bottom = 480; 2934 a4.bottom = 480;
2933 a4.left = 0; 2935 a4.left = 0;
2934 a4.right = 640; 2936 a4.right = 640;
2935 BltBackToFontFast(0, 0, &a4); 2937 BltBackToFontFast(0, 0, &a4);
2936 } 2938 }
2937 } 2939 }*/
2938 } 2940 }
2939 } 2941 }
2940 2942
2941 //----- (0049FD3A) -------------------------------------------------------- 2943 //----- (0049FD3A) --------------------------------------------------------
2942 void Render::_49FD3A() 2944 void Render::_49FD3A()
2977 2979
2978 //----- (0049FE05) -------------------------------------------------------- 2980 //----- (0049FE05) --------------------------------------------------------
2979 void Render::Release() 2981 void Render::Release()
2980 { 2982 {
2981 Render *v1; // esi@1 2983 Render *v1; // esi@1
2982 RenderD3D *v2; // ecx@1 2984 //RenderD3D *v2; // ecx@1
2983 char v3; // zf@4 2985 //char v3; // zf@4
2984 void *v4; // ebx@6 2986 //void *v4; // ebx@6
2985 IDirectDraw *v5; // eax@10 2987 IDirectDraw *v5; // eax@10
2986 IDirectDrawSurface2 *v6; // eax@11 2988 IDirectDrawSurface2 *v6; // eax@11
2987 IDirectDrawSurface2 *v7; // eax@13 2989 IDirectDrawSurface2 *v7; // eax@13
2988 IDirectDrawSurface2 *v8; // eax@15 2990 IDirectDrawSurface2 *v8; // eax@15
2989 IDirectDraw2 *v9; // eax@17 2991 IDirectDraw2 *v9; // eax@17
2994 IDirectDraw4 *v14; // eax@26 2996 IDirectDraw4 *v14; // eax@26
2995 unsigned __int16 **v15; // ebx@28 2997 unsigned __int16 **v15; // ebx@28
2996 void **v16; // esi@29 2998 void **v16; // esi@29
2997 2999
2998 v1 = this; 3000 v1 = this;
2999 v2 = this->pRenderD3D; 3001 if (pRenderD3D)
3000 if ( v2 )
3001 { 3002 {
3002 if ( v1->field_40110 ) 3003 if ( v1->field_40110 )
3003 { 3004 {
3004 pRenderD3D->ClearTarget(1u, 0, 0, 1.0); 3005 pRenderD3D->ClearTarget(true, 0, false, 1.0);
3005 pRenderD3D->Present(0); 3006 pRenderD3D->Present(0);
3006 pRenderD3D->ClearTarget(1u, 0, 0, 1.0); 3007 pRenderD3D->ClearTarget(true, 0, false, 1.0);
3007 } 3008 }
3008 v1->pColorKeySurface4 = 0; 3009 v1->pColorKeySurface4 = 0;
3009 v1->pBackBuffer4 = 0; 3010 v1->pBackBuffer4 = 0;
3010 v3 = v1->pTargetSurface == 0;
3011 v1->pFrontBuffer4 = 0; 3011 v1->pFrontBuffer4 = 0;
3012 v1->pDirectDraw4 = 0; 3012 v1->pDirectDraw4 = 0;
3013 if ( !v3 ) 3013 if (v1->pTargetSurface)
3014 { 3014 {
3015 free(v1->ptr_400E8); 3015 free(v1->ptr_400E8);
3016 v1->pTargetSurface = 0; 3016 v1->pTargetSurface = 0;
3017 v1->ptr_400E8 = 0; 3017 v1->ptr_400E8 = 0;
3018 } 3018 }
3019 v4 = v1->pRenderD3D; 3019 if (pRenderD3D)
3020 if ( v4 )
3021 { 3020 {
3022 pRenderD3D->Release(); 3021 pRenderD3D->Release();
3023 free(v4); 3022 delete pRenderD3D;
3024 } 3023 }
3025 v1->pRenderD3D = 0; 3024 pRenderD3D = 0;
3026 } 3025 }
3027 else 3026 else
3028 { 3027 ;//__debugbreak(); // no sr
3028 /*{
3029 if ( bWinNT4_0 == 1 ) 3029 if ( bWinNT4_0 == 1 )
3030 { 3030 {
3031 v5 = (IDirectDraw *)v1->pDirectDraw2; 3031 v5 = (IDirectDraw *)v1->pDirectDraw2;
3032 if ( !v5 ) 3032 if ( !v5 )
3033 return; 3033 return;
3096 v16 = (void **)&v1->ptr_400E8; 3096 v16 = (void **)&v1->ptr_400E8;
3097 free(*v16); 3097 free(*v16);
3098 *v15 = 0; 3098 *v15 = 0;
3099 *v16 = 0; 3099 *v16 = 0;
3100 } 3100 }
3101 } 3101 }*/
3102 } 3102 }
3103 3103
3104 //----- (0049FFD7) -------------------------------------------------------- 3104 //----- (0049FFD7) --------------------------------------------------------
3105 void Render::CreateSomeTexture() 3105 void Render::CreateSomeTexture()
3106 { 3106 {
3107 pRenderD3D->CreateTexture(64, 64, &pSurface, &pTexture, true, false, 32); 3107 pRenderD3D->CreateTexture(64, 64, &pSurface, &pTexture, true, false, 32);
3108 } 3108 }
3109 3109
3110 //----- (0049FFFB) -------------------------------------------------------- 3110 //----- (0049FFFB) --------------------------------------------------------
3111 bool Render::InitializeFullscreen(HWND hWnd) 3111 bool Render::InitializeFullscreen()
3112 { 3112 {
3113 //Render *v2; // esi@1 3113 //Render *v2; // esi@1
3114 //HWND v3; // ebx@1 3114 //HWND v3; // ebx@1
3115 //void *v4; // eax@2 3115 //void *v4; // eax@2
3116 //RenderD3D *v5; // eax@3 3116 //RenderD3D *v5; // eax@3
3145 this->pFrontBuffer4 = 0; 3145 this->pFrontBuffer4 = 0;
3146 this->pDirectDraw4 = 0; 3146 this->pDirectDraw4 = 0;
3147 this->bColorKeySupported = 0; 3147 this->bColorKeySupported = 0;
3148 Release(); 3148 Release();
3149 //v3 = hWnd; 3149 //v3 = hWnd;
3150 this->hWnd = hWnd; 3150 this->window = window;
3151 CreateZBuffer(); 3151 CreateZBuffer();
3152 if ( bUserDirect3D ) 3152
3153 { 3153 /*if (!bUserDirect3D)
3154 {
3155 CreateDirectDraw();
3156 SetDirectDrawCooperationMode(hWnd, 1);
3157 SetDirectDrawDisplayMode(640u, 480u, 16u);
3158 CreateDirectDrawPrimarySurface();
3159 v15 = 1;
3160 }
3161 else
3162 {*/
3154 pRenderD3D = new RenderD3D; 3163 pRenderD3D = new RenderD3D;
3155 v28 = pRenderD3D; 3164 v28 = pRenderD3D;
3156 v6 = uDesiredDirect3DDevice; 3165 v6 = uDesiredDirect3DDevice;
3157 v29 = -1; 3166 v29 = -1;
3158 v7 = pRenderD3D->pAvailableDevices; 3167 v7 = pRenderD3D->pAvailableDevices;
3159 if ( v7[v6].bIsDeviceCompatible ) 3168 if ( v7[v6].bIsDeviceCompatible )
3160 { 3169 {
3161 v8 = pRenderD3D->CreateDevice(v6, 0, hWnd); 3170 v8 = pRenderD3D->CreateDevice(v6, 0, window->GetApiHandle());
3162 uAcquiredDirect3DDevice = uDesiredDirect3DDevice; 3171 uAcquiredDirect3DDevice = uDesiredDirect3DDevice;
3163 } 3172 }
3164 else 3173 else
3165 { 3174 {
3166 if ( v7[1].bIsDeviceCompatible ) 3175 if ( v7[1].bIsDeviceCompatible )
3167 { 3176 {
3168 v8 = pRenderD3D->CreateDevice(1u, 0, hWnd); 3177 v8 = pRenderD3D->CreateDevice(1u, 0, window->GetApiHandle());
3169 uAcquiredDirect3DDevice = 1; 3178 uAcquiredDirect3DDevice = 1;
3170 } 3179 }
3171 else 3180 else
3172 { 3181 {
3173 if ( !v7->bIsDeviceCompatible ) 3182 if ( !v7->bIsDeviceCompatible )
3174 Error("There aren't any D3D devices to create."); 3183 Error("There aren't any D3D devices to create.");
3175 3184
3176 v8 = pRenderD3D->CreateDevice(0, 0, hWnd); 3185 v8 = pRenderD3D->CreateDevice(0, 0, window->GetApiHandle());
3177 uAcquiredDirect3DDevice = 0; 3186 uAcquiredDirect3DDevice = 0;
3178 } 3187 }
3179 } 3188 }
3180 if ( !v8 ) 3189 if ( !v8 )
3181 Error("D3Drend->Init failed."); 3190 Error("D3Drend->Init failed.");
3259 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0)); 3268 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0));
3260 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2u)); 3269 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2u));
3261 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u)); 3270 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
3262 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0)); 3271 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0));
3263 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u)); 3272 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u));
3264 } 3273 //}
3265 else
3266 {
3267 CreateDirectDraw();
3268 SetDirectDrawCooperationMode(hWnd, 1);
3269 SetDirectDrawDisplayMode(640u, 480u, 16u);
3270 CreateDirectDrawPrimarySurface();
3271 v15 = 1;
3272 }
3273 ddpfPrimareSuface.dwSize = 32; 3274 ddpfPrimareSuface.dwSize = 32;
3274 GetTargetPixelFormat(&ddpfPrimareSuface); 3275 GetTargetPixelFormat(&ddpfPrimareSuface);
3275 ParseTargetPixelFormat(); 3276 ParseTargetPixelFormat();
3276 _49EBF1(); 3277 _49EBF1();
3277 if ( pRenderD3D ) 3278 if ( pRenderD3D )
3327 pViewport->_4C02F8(36044); 3328 pViewport->_4C02F8(36044);
3328 return v15 != 0; 3329 return v15 != 0;
3329 } 3330 }
3330 3331
3331 //----- (004A05F3) -------------------------------------------------------- 3332 //----- (004A05F3) --------------------------------------------------------
3332 bool Render::SwitchToWindow(HWND hWnd) 3333 bool Render::SwitchToWindow()
3333 { 3334 {
3334 //Render *v2; // esi@1 3335 //Render *v2; // esi@1
3335 //void *v3; // eax@2 3336 //void *v3; // eax@2
3336 //RenderD3D *v4; // eax@3 3337 //RenderD3D *v4; // eax@3
3337 //unsigned int v5; // edx@5 3338 //unsigned int v5; // edx@5
3369 pBackBuffer4 = 0; 3370 pBackBuffer4 = 0;
3370 pFrontBuffer4 = 0; 3371 pFrontBuffer4 = 0;
3371 pDirectDraw4 = 0; 3372 pDirectDraw4 = 0;
3372 bColorKeySupported = 0; 3373 bColorKeySupported = 0;
3373 CreateZBuffer(); 3374 CreateZBuffer();
3374 if ( bUserDirect3D ) 3375 /*if (!bUserDirect3D)
3375 { 3376 {
3377 CreateDirectDraw();
3378 SetDirectDrawCooperationMode(hWnd, 0);
3379 field_4004C = 1;
3380 CreateFrontBuffer();
3381 CreateClipper(hWnd);
3382 CreateBackBuffer();
3383 field_40030 = 0;
3384 field_18_locked_pitch = 0;
3385 }
3386 else
3387 {*/
3376 /*v3 = malloc(0x148u); 3388 /*v3 = malloc(0x148u);
3377 thisa = (RenderD3D *)v3; 3389 thisa = (RenderD3D *)v3;
3378 v29 = 0; 3390 v29 = 0;
3379 if ( v3 ) 3391 if ( v3 )
3380 v4 = RenderD3D::RenderD3D((RenderD3D *)v3); 3392 v4 = RenderD3D::RenderD3D((RenderD3D *)v3);
3386 v29 = -1; 3398 v29 = -1;
3387 //v6 = pRenderD3D->pAvailableDevices; 3399 //v6 = pRenderD3D->pAvailableDevices;
3388 if (pRenderD3D->pAvailableDevices[uDesiredDirect3DDevice].bIsDeviceCompatible && 3400 if (pRenderD3D->pAvailableDevices[uDesiredDirect3DDevice].bIsDeviceCompatible &&
3389 uDesiredDirect3DDevice != 1 ) 3401 uDesiredDirect3DDevice != 1 )
3390 { 3402 {
3391 v7 = pRenderD3D->CreateDevice(uDesiredDirect3DDevice, 1, hWnd); 3403 v7 = pRenderD3D->CreateDevice(uDesiredDirect3DDevice, 1, window->GetApiHandle());
3392 uAcquiredDirect3DDevice = uDesiredDirect3DDevice; 3404 uAcquiredDirect3DDevice = uDesiredDirect3DDevice;
3393 } 3405 }
3394 else 3406 else
3395 { 3407 {
3396 if ( !pRenderD3D->pAvailableDevices[0].bIsDeviceCompatible ) 3408 if ( !pRenderD3D->pAvailableDevices[0].bIsDeviceCompatible )
3397 Error("There aren't any D3D devices to init."); 3409 Error("There aren't any D3D devices to init.");
3398 3410
3399 v7 = pRenderD3D->CreateDevice(0, 1, hWnd); 3411 v7 = pRenderD3D->CreateDevice(0, 1, window->GetApiHandle());
3400 uAcquiredDirect3DDevice = 0; 3412 uAcquiredDirect3DDevice = 0;
3401 } 3413 }
3402 if ( !v7 ) 3414 if ( !v7 )
3403 Error("D3Drend->Init failed."); 3415 Error("D3Drend->Init failed.");
3404 3416
3478 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0)); 3490 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, 0));
3479 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2u)); 3491 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 2u));
3480 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u)); 3492 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, 2u));
3481 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0)); 3493 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, 0));
3482 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u)); 3494 ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, 4u));
3483 } 3495 //}
3484 else 3496
3485 {
3486 CreateDirectDraw();
3487 SetDirectDrawCooperationMode(hWnd, 0);
3488 field_4004C = 1;
3489 CreateFrontBuffer();
3490 CreateClipper(hWnd);
3491 CreateBackBuffer();
3492 field_40030 = 0;
3493 field_18_locked_pitch = 0;
3494 }
3495 ddpfPrimareSuface.dwSize = 32; 3497 ddpfPrimareSuface.dwSize = 32;
3496 GetTargetPixelFormat(&ddpfPrimareSuface); 3498 GetTargetPixelFormat(&ddpfPrimareSuface);
3497 ParseTargetPixelFormat(); 3499 ParseTargetPixelFormat();
3498 _49EBF1(); 3500 _49EBF1();
3499 if ( !pRenderD3D ) 3501 if ( !pRenderD3D )
3521 pBeforePresentFunction = Present_ColorKey; 3523 pBeforePresentFunction = Present_ColorKey;
3522 LABEL_45: 3524 LABEL_45:
3523 field_40110 = 1; 3525 field_40110 = 1;
3524 LABEL_47: 3526 LABEL_47:
3525 bWindowMode = 1; 3527 bWindowMode = 1;
3526 hWnd = hWnd; 3528 //hWnd = hWnd;
3527 return 0; 3529 return 0;
3528 } 3530 }
3529 pTargetSurface = 0; 3531 pTargetSurface = 0;
3530 ptr_400E8 = 0; 3532 ptr_400E8 = 0;
3531 v18 = (int *)new char[0x96020]; 3533 v18 = (int *)new char[0x96020];
3995 ErrD3D(DirectDrawCreate(0, &lpDD, 0)); 3997 ErrD3D(DirectDrawCreate(0, &lpDD, 0));
3996 3998
3997 pDirectDraw2 = nullptr; 3999 pDirectDraw2 = nullptr;
3998 pDirectDraw4 = nullptr; 4000 pDirectDraw4 = nullptr;
3999 4001
4000 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4002 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4003 pVersion->pVersionInfo.dwMajorVersion != 4 )
4001 ErrD3D(lpDD->QueryInterface(IID_IDirectDraw4, (void **)&pDirectDraw4)); 4004 ErrD3D(lpDD->QueryInterface(IID_IDirectDraw4, (void **)&pDirectDraw4));
4002 else 4005 else
4003 ErrD3D(lpDD->QueryInterface(IID_IDirectDraw2, (void **)&pDirectDraw2)); 4006 ErrD3D(lpDD->QueryInterface(IID_IDirectDraw2, (void **)&pDirectDraw2));
4004 4007
4005 lpDD->Release(); 4008 lpDD->Release();
4016 unsigned int v7; // [sp-4h] [bp-4h]@3 4019 unsigned int v7; // [sp-4h] [bp-4h]@3
4017 4020
4018 flags = bFullscreen ? DDSCL_NORMAL | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN : 4021 flags = bFullscreen ? DDSCL_NORMAL | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN :
4019 DDSCL_NORMAL; 4022 DDSCL_NORMAL;
4020 4023
4021 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4024 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4025 pVersion->pVersionInfo.dwMajorVersion != 4 )
4022 ErrD3D(pDirectDraw4->SetCooperativeLevel(hWnd, flags | DDSCL_MULTITHREADED)); 4026 ErrD3D(pDirectDraw4->SetCooperativeLevel(hWnd, flags | DDSCL_MULTITHREADED));
4023 else 4027 else
4024 ErrD3D(pDirectDraw2->SetCooperativeLevel(hWnd, flags)); 4028 ErrD3D(pDirectDraw2->SetCooperativeLevel(hWnd, flags));
4025 } 4029 }
4026 4030
4027 //----- (004A11C6) -------------------------------------------------------- 4031 //----- (004A11C6) --------------------------------------------------------
4028 void Render::SetDirectDrawDisplayMode(unsigned int uWidth, unsigned int uHeight, unsigned int uBPP) 4032 void Render::SetDirectDrawDisplayMode(unsigned int uWidth, unsigned int uHeight, unsigned int uBPP)
4029 { 4033 {
4030 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4034 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4035 pVersion->pVersionInfo.dwMajorVersion != 4 )
4031 ErrD3D(pDirectDraw4->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0)); 4036 ErrD3D(pDirectDraw4->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0));
4032 else 4037 else
4033 ErrD3D(pDirectDraw2->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0)); 4038 ErrD3D(pDirectDraw2->SetDisplayMode(uWidth, uHeight, uBPP, 0, 0));
4034 } 4039 }
4035 4040
4044 int v6; // [sp-8h] [bp-8Ch]@3 4049 int v6; // [sp-8h] [bp-8Ch]@3
4045 unsigned int v7; // [sp-4h] [bp-88h]@3 4050 unsigned int v7; // [sp-4h] [bp-88h]@3
4046 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3 4051 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3
4047 4052
4048 v1 = this; 4053 v1 = this;
4049 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4054 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4055 pVersion->pVersionInfo.dwMajorVersion != 4 )
4050 { 4056 {
4051 memset(&a2, 0, 0x7Cu); 4057 memset(&a2, 0, 0x7Cu);
4052 pDD = (IDirectDraw *)v1->pDirectDraw4; 4058 pDD = (IDirectDraw *)v1->pDirectDraw4;
4053 a2.dwSize = 124; 4059 a2.dwSize = 124;
4054 a2.dwFlags = 1; 4060 a2.dwFlags = 1;
4084 int v6; // [sp-8h] [bp-8Ch]@3 4090 int v6; // [sp-8h] [bp-8Ch]@3
4085 unsigned int v7; // [sp-4h] [bp-88h]@3 4091 unsigned int v7; // [sp-4h] [bp-88h]@3
4086 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3 4092 DDSURFACEDESC2 a2; // [sp+4h] [bp-80h]@3
4087 4093
4088 v1 = this; 4094 v1 = this;
4089 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4095 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4096 pVersion->pVersionInfo.dwMajorVersion != 4 )
4090 { 4097 {
4091 memset(&a2, 0, 0x7Cu); 4098 memset(&a2, 0, 0x7Cu);
4092 v2 = (IDirectDraw *)v1->pDirectDraw4; 4099 v2 = (IDirectDraw *)v1->pDirectDraw4;
4093 a2.dwSize = 124; 4100 a2.dwSize = 124;
4094 a2.dwFlags = 7; 4101 a2.dwFlags = 7;
4138 DDSURFACEDESC2 ddsd2; // [sp+Ch] [bp-94h]@3 4145 DDSURFACEDESC2 ddsd2; // [sp+Ch] [bp-94h]@3
4139 DDSCAPS2 v17; // [sp+88h] [bp-18h]@4 4146 DDSCAPS2 v17; // [sp+88h] [bp-18h]@4
4140 int a4; // [sp+98h] [bp-8h]@3 4147 int a4; // [sp+98h] [bp-8h]@3
4141 4148
4142 v1 = this; 4149 v1 = this;
4143 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4150 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4151 pVersion->pVersionInfo.dwMajorVersion != 4 )
4144 { 4152 {
4145 v2 = 0; 4153 v2 = 0;
4146 this->field_4004C = 1; 4154 this->field_4004C = 1;
4147 memset(&ddsd2, 0, 0x7Cu); 4155 memset(&ddsd2, 0, 0x7Cu);
4148 v7 = v1->pDirectDraw4; 4156 v7 = v1->pDirectDraw4;
4189 } 4197 }
4190 4198
4191 //----- (004A14F4) -------------------------------------------------------- 4199 //----- (004A14F4) --------------------------------------------------------
4192 void Render::CreateClipper(HWND a2) 4200 void Render::CreateClipper(HWND a2)
4193 { 4201 {
4194 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4202 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4203 pVersion->pVersionInfo.dwMajorVersion != 4 )
4195 { 4204 {
4196 ErrD3D(pDirectDraw4->CreateClipper(0, &pDDrawClipper, 0)); 4205 ErrD3D(pDirectDraw4->CreateClipper(0, &pDDrawClipper, 0));
4197 ErrD3D(pDDrawClipper->SetHWnd(0, a2)); 4206 ErrD3D(pDDrawClipper->SetHWnd(0, a2));
4198 ErrD3D(pFrontBuffer4->SetClipper(pDDrawClipper)); 4207 ErrD3D(pFrontBuffer4->SetClipper(pDDrawClipper));
4199 } 4208 }
4207 //----- (004A15D8) -------------------------------------------------------- 4216 //----- (004A15D8) --------------------------------------------------------
4208 void Render::GetTargetPixelFormat(DDPIXELFORMAT *pOut) 4217 void Render::GetTargetPixelFormat(DDPIXELFORMAT *pOut)
4209 { 4218 {
4210 IDirectDrawSurface *v2; // eax@3 4219 IDirectDrawSurface *v2; // eax@3
4211 4220
4212 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4221 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4222 pVersion->pVersionInfo.dwMajorVersion != 4 )
4213 v2 = (IDirectDrawSurface *)this->pFrontBuffer4; 4223 v2 = (IDirectDrawSurface *)this->pFrontBuffer4;
4214 else 4224 else
4215 v2 = (IDirectDrawSurface *)this->pFrontBuffer2; 4225 v2 = (IDirectDrawSurface *)this->pFrontBuffer2;
4216 v2->GetPixelFormat(pOut); 4226 v2->GetPixelFormat(pOut);
4217 } 4227 }
4221 { 4231 {
4222 Render *v3; // esi@1 4232 Render *v3; // esi@1
4223 signed int v4; // eax@3 4233 signed int v4; // eax@3
4224 4234
4225 v3 = this; 4235 v3 = this;
4226 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4236 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4237 pVersion->pVersionInfo.dwMajorVersion != 4 )
4227 { 4238 {
4228 DDSURFACEDESC2 pDesc; // [sp+4h] [bp-7Ch]@3 4239 DDSURFACEDESC2 pDesc; // [sp+4h] [bp-7Ch]@3
4229 memset(&pDesc, 0, 0x7Cu); 4240 memset(&pDesc, 0, 0x7Cu);
4230 pDesc.dwSize = 124; 4241 pDesc.dwSize = 124;
4231 LockSurface_DDraw4(v3->pBackBuffer4, &pDesc, DDLOCK_WAIT); 4242 LockSurface_DDraw4(v3->pBackBuffer4, &pDesc, DDLOCK_WAIT);
4242 v4 = pDesc.dwReserved; 4253 v4 = pDesc.dwReserved;
4243 } 4254 }
4244 *pOutPixelsPerRow = v4 >> 1; 4255 *pOutPixelsPerRow = v4 >> 1;
4245 } 4256 }
4246 4257
4247 //----- (004A169E) --------------------------------------------------------
4248 bool Render::UsingDirect3D()
4249 {
4250 return bUserDirect3D == 0;
4251 }
4252
4253 //----- (004A16E1) -------------------------------------------------------- 4258 //----- (004A16E1) --------------------------------------------------------
4254 void Render::UnlockBackBuffer() 4259 void Render::UnlockBackBuffer()
4255 { 4260 {
4256 if ( pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || pVersion->pVersionInfo.dwMajorVersion != 4 ) 4261 if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
4262 pVersion->pVersionInfo.dwMajorVersion != 4 )
4257 ErrD3D(pBackBuffer4->Unlock(0)); 4263 ErrD3D(pBackBuffer4->Unlock(0));
4258 else 4264 else
4259 ErrD3D(pBackBuffer2->Unlock(0)); 4265 ErrD3D(pBackBuffer2->Unlock(0));
4260 } 4266 }
4261 4267
5153 int _507D30_idx = 0; 5159 int _507D30_idx = 0;
5154 while ( 2 ) 5160 while ( 2 )
5155 { 5161 {
5156 v15 = (void *)(v72 * (v70 - (int)array_507D30[_507D30_idx].vWorldViewProjY)); 5162 v15 = (void *)(v72 * (v70 - (int)array_507D30[_507D30_idx].vWorldViewProjY));
5157 v77 = (unsigned __int64)(v62.ptr_38->field_14 * (signed __int64)(signed int)v15) >> 16; 5163 v77 = (unsigned __int64)(v62.ptr_38->field_14 * (signed __int64)(signed int)v15) >> 16;
5158 v74 = v77 + v62.ptr_38->field_C; 5164 v74 = v77 + v62.ptr_38->angle_from_north;
5159 v77 = (int)v15; 5165 v77 = (int)v15;
5160 v77 = (unsigned __int64)(v62.ptr_38->field_20 * (signed __int64)(signed int)v15) >> 16; 5166 v77 = (unsigned __int64)(v62.ptr_38->field_20 * (signed __int64)(signed int)v15) >> 16;
5161 v79 = v15; 5167 v79 = v15;
5162 v75 = (RenderVertexSoft *)(v77 + v62.ptr_38->field_18); 5168 v75 = (RenderVertexSoft *)(v77 + v62.ptr_38->angle_from_east);
5163 v79 = (void *)((unsigned __int64)(v62.v_18.z * (signed __int64)(signed int)v15) >> 16); 5169 v79 = (void *)((unsigned __int64)(v62.v_18.z * (signed __int64)(signed int)v15) >> 16);
5164 v17 = v72 * (pBLVRenderParams->uViewportCenterX - (int)array_507D30[_507D30_idx].vWorldViewProjX); 5170 v17 = v72 * (pBLVRenderParams->uViewportCenterX - (int)array_507D30[_507D30_idx].vWorldViewProjX);
5165 v18 = array_507D30[_507D30_idx].vWorldViewProjY - 1.0; 5171 v18 = array_507D30[_507D30_idx].vWorldViewProjY - 1.0;
5166 v19 = -v62.field_24; 5172 v19 = -v62.field_24;
5167 v77 = -v62.field_24; 5173 v77 = -v62.field_24;
5193 LODWORD(v23) = v77 << 16; 5199 LODWORD(v23) = v77 << 16;
5194 HIDWORD(v23) = v77 >> 16; 5200 HIDWORD(v23) = v77 >> 16;
5195 v79 = (void *)(v23 / X); 5201 v79 = (void *)(v23 / X);
5196 v77 = v17; 5202 v77 = v17;
5197 v77 = v17; 5203 v77 = v17;
5198 LODWORD(v76) = v74 + ((unsigned __int64)(v62.ptr_38->field_10 * (signed __int64)v17) >> 16); 5204 LODWORD(v76) = v74 + ((unsigned __int64)(v62.ptr_38->angle_from_west * (signed __int64)v17) >> 16);
5199 v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(v62.ptr_38->field_1C * (signed __int64)v17) >> 16)); 5205 v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(v62.ptr_38->angle_from_south * (signed __int64)v17) >> 16));
5200 v77 = (unsigned __int64)(SLODWORD(v76) * v23 / X) >> 16; 5206 v77 = (unsigned __int64)(SLODWORD(v76) * v23 / X) >> 16;
5201 LODWORD(v73) = (unsigned __int64)((signed int)v75 * v23 / X) >> 16; 5207 LODWORD(v73) = (unsigned __int64)((signed int)v75 * v23 / X) >> 16;
5202 //v14 += 48; 5208 //v14 += 48;
5203 LODWORD(v80) = v66 + ((signed int)((unsigned __int64)(SLODWORD(v76) * v23 / X) >> 16) >> 4); 5209 LODWORD(v80) = v66 + ((signed int)((unsigned __int64)(SLODWORD(v76) * v23 / X) >> 16) >> 4);
5204 v81 = (char *)v81 + 1; 5210 v81 = (char *)v81 + 1;
5269 do 5275 do
5270 { 5276 {
5271 v35 = (const void *)(v72 * (v70 - (unsigned __int64)(signed __int64)*(float *)v34)); 5277 v35 = (const void *)(v72 * (v70 - (unsigned __int64)(signed __int64)*(float *)v34));
5272 v78 = v62.ptr_38->field_14; 5278 v78 = v62.ptr_38->field_14;
5273 v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v35) >> 16); 5279 v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v35) >> 16);
5274 v36 = (int)((char *)v81 + v62.ptr_38->field_C); 5280 v36 = (int)((char *)v81 + v62.ptr_38->angle_from_north);
5275 v81 = v35; 5281 v81 = v35;
5276 v74 = v36; 5282 v74 = v36;
5277 v78 = v62.ptr_38->field_20; 5283 v78 = v62.ptr_38->field_20;
5278 v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v35) >> 16); 5284 v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v35) >> 16);
5279 v78 = (int)v35; 5285 v78 = (int)v35;
5280 v75 = (RenderVertexSoft *)((char *)v81 + v62.ptr_38->field_18); 5286 v75 = (RenderVertexSoft *)((char *)v81 + v62.ptr_38->angle_from_east);
5281 v81 = (const void *)v62.v_18.z; 5287 v81 = (const void *)v62.v_18.z;
5282 v78 = (unsigned __int64)(v62.v_18.z * (signed __int64)(signed int)v35) >> 16; 5288 v78 = (unsigned __int64)(v62.v_18.z * (signed __int64)(signed int)v35) >> 16;
5283 v37 = (const void *)(v72 5289 v37 = (const void *)(v72
5284 * (pBLVRenderParams->uViewportCenterX - (unsigned __int64)(signed __int64)*((float *)v34 - 1))); 5290 * (pBLVRenderParams->uViewportCenterX - (unsigned __int64)(signed __int64)*((float *)v34 - 1)));
5285 v38 = (signed __int64)(*(float *)v34 - 1.0); 5291 v38 = (signed __int64)(*(float *)v34 - 1.0);
5318 } 5324 }
5319 LODWORD(v42) = v77 << 16; 5325 LODWORD(v42) = v77 << 16;
5320 HIDWORD(v42) = v77 >> 16; 5326 HIDWORD(v42) = v77 >> 16;
5321 v79 = (void *)(v42 / X); 5327 v79 = (void *)(v42 / X);
5322 v81 = v37; 5328 v81 = v37;
5323 v78 = v62.ptr_38->field_10; 5329 v78 = v62.ptr_38->angle_from_west;
5324 v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16); 5330 v81 = (const void *)((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16);
5325 v43 = v74 + ((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16); 5331 v43 = v74 + ((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16);
5326 v74 = (unsigned int)v37; 5332 v74 = (unsigned int)v37;
5327 LODWORD(v76) = v43; 5333 LODWORD(v76) = v43;
5328 v78 = v62.ptr_38->field_1C; 5334 v78 = v62.ptr_38->angle_from_south;
5329 v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16)); 5335 v75 = (RenderVertexSoft *)((char *)v75 + ((unsigned __int64)(v78 * (signed __int64)(signed int)v37) >> 16));
5330 v74 = (unsigned __int64)(v43 * v42 / X) >> 16; 5336 v74 = (unsigned __int64)(v43 * v42 / X) >> 16;
5331 v81 = (const void *)((unsigned __int64)((signed int)v75 * v42 / X) >> 16); 5337 v81 = (const void *)((unsigned __int64)((signed int)v75 * v42 / X) >> 16);
5332 v34 += 48; 5338 v34 += 48;
5333 v78 = v66 + ((signed int)v74 >> 4); 5339 v78 = v66 + ((signed int)v74 >> 4);
8314 pBitmaps_LOD->ReleaseHardwareTextures(); 8320 pBitmaps_LOD->ReleaseHardwareTextures();
8315 pSprites_LOD->ReleaseAll(); 8321 pSprites_LOD->ReleaseAll();
8316 } 8322 }
8317 if ( pRenderer->bWindowMode ) 8323 if ( pRenderer->bWindowMode )
8318 { 8324 {
8319 SetMenu(hWnd, 0); 8325 //SetMenu(hWnd, 0);
8320 SetWindowLongA(hWnd, -20, 0); 8326 //SetWindowLongA(hWnd, -20, 0);
8321 SetWindowLongA(hWnd, -16, 0x10000000u); 8327 //SetWindowLongA(hWnd, -16, 0x10000000u);
8322 pRenderer->InitializeFullscreen(hWnd); 8328 window->SetFullscreenMode();
8329 pRenderer->InitializeFullscreen();
8323 v0 = (double)(signed int)uGammaPos * 0.1 + 0.6; 8330 v0 = (double)(signed int)uGammaPos * 0.1 + 0.6;
8324 pGame->pGammaController->Initialize(v0); 8331 pGame->pGammaController->Initialize(v0);
8325 } 8332 }
8326 else 8333 else
8327 { 8334 {
8328 ClipCursor(0); 8335 //ClipCursor(0);
8329 pRenderer->SwitchToWindow(hWnd); 8336 window->SetWindowedMode(window->GetWidth(), window->GetHeight());
8337 pRenderer->SwitchToWindow();
8330 } 8338 }
8331 if ( pRenderer->pRenderD3D ) 8339 if ( pRenderer->pRenderD3D )
8332 { 8340 {
8333 pBitmaps_LOD->_410423_move_textures_to_device(); 8341 pBitmaps_LOD->_410423_move_textures_to_device();
8334 pSprites_LOD->MoveSpritesToVideoMemory(); 8342 pSprites_LOD->MoveSpritesToVideoMemory();
8377 } 8385 }
8378 } 8386 }
8379 viewparams->bRedrawGameUI = 1; 8387 viewparams->bRedrawGameUI = 1;
8380 viewparams->InitGrayPalette(); 8388 viewparams->InitGrayPalette();
8381 pMouse->SetCurrentCursorBitmap(); 8389 pMouse->SetCurrentCursorBitmap();
8382 if ( pRenderer->bWindowMode ) 8390 /*if ( pRenderer->bWindowMode )
8383 { 8391 {
8384 //MoveWindow(hWnd, uWindowX, uWindowY, uWindowWidth, uWindowHeight, 0); 8392 //MoveWindow(hWnd, uWindowX, uWindowY, uWindowWidth, uWindowHeight, 0);
8385 CenterWindowAndAdjustSize(hWnd, windowed_mode_width, windowed_mode_height); 8393 CenterWindowAndAdjustSize(hWnd, windowed_mode_width, windowed_mode_height);
8386 ShowWindow(hWnd, SW_SHOWNORMAL); 8394 ShowWindow(hWnd, SW_SHOWNORMAL);
8387 } 8395 }*/
8388 pMouse->bActive = 1; 8396 pMouse->bActive = true;
8389 if ( pVideoPlayer->AnyMovieLoaded() ) 8397 if ( pVideoPlayer->AnyMovieLoaded() )
8390 pVideoPlayer->SelectMovieType(); 8398 pVideoPlayer->SelectMovieType();
8391 if (dword_6BE364_game_settings_1 & 0x0800 ) 8399 if (dword_6BE364_game_settings_1 & 0x0800 )
8392 BYTE1(dword_6BE364_game_settings_1) &= 0xF7u; 8400 BYTE1(dword_6BE364_game_settings_1) &= 0xF7u;
8393 else 8401 else