annotate GammaControl.cpp @ 2483:b3f96acf6bab

Fixing arrows not being drawn for 2nd player char
author Grumpy7
date Sat, 06 Sep 2014 20:52:46 +0200
parents f4af3b203f65
children
rev   line source
2415
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2268
diff changeset
1 #define _CRTDBG_MAP_ALLOC
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2268
diff changeset
2 #include <stdlib.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2268
diff changeset
3 #include <crtdbg.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2268
diff changeset
4
2253
aff7a7b072b7 adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents: 2154
diff changeset
5 #define _CRT_SECURE_NO_WARNINGS
0
Ritor1
parents:
diff changeset
6 #include <string>
Ritor1
parents:
diff changeset
7
Ritor1
parents:
diff changeset
8 #include "GammaControl.h"
Ritor1
parents:
diff changeset
9 #include "Render.h"
Ritor1
parents:
diff changeset
10
Ritor1
parents:
diff changeset
11 #include "mm7_data.h"
Ritor1
parents:
diff changeset
12
Ritor1
parents:
diff changeset
13
Ritor1
parents:
diff changeset
14
Ritor1
parents:
diff changeset
15 //----- (0044F324) --------------------------------------------------------
Ritor1
parents:
diff changeset
16 void GammaController::GetRamp()
Ritor1
parents:
diff changeset
17 {
Ritor1
parents:
diff changeset
18 if (pGammaControl)
Ritor1
parents:
diff changeset
19 ErrD3D(pGammaControl->GetGammaRamp(0, &pDefaultRamp));
Ritor1
parents:
diff changeset
20 else
Ritor1
parents:
diff changeset
21 MessageBoxW(nullptr, L"Gamma control not active", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\GammaControl.cpp:83", 0);
Ritor1
parents:
diff changeset
22 }
Ritor1
parents:
diff changeset
23
Ritor1
parents:
diff changeset
24 //----- (0044F377) --------------------------------------------------------
Ritor1
parents:
diff changeset
25 double GammaController::_44F377(DDGAMMARAMP *a1)
Ritor1
parents:
diff changeset
26 {
Ritor1
parents:
diff changeset
27 double v2; // st7@1
Ritor1
parents:
diff changeset
28 unsigned __int16 *v3; // ecx@1
Ritor1
parents:
diff changeset
29 double v4; // st6@2
Ritor1
parents:
diff changeset
30 signed int v6; // [sp+0h] [bp-8h]@1
Ritor1
parents:
diff changeset
31 signed int v7; // [sp+4h] [bp-4h]@1
Ritor1
parents:
diff changeset
32
Ritor1
parents:
diff changeset
33 v2 = 0.0;
Ritor1
parents:
diff changeset
34 v6 = 256;
Ritor1
parents:
diff changeset
35 v3 = a1->green;
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
36 for ( v7 = 0; v7 < 256; ++v7 )
0
Ritor1
parents:
diff changeset
37 {
Ritor1
parents:
diff changeset
38 v4 = ((double)*(v3 - 256) + (double)v3[256] + (double)*v3) * 0.000015259022 * 0.33333334;
Ritor1
parents:
diff changeset
39 if ( v4 == 0.0 )
Ritor1
parents:
diff changeset
40 --v6;
Ritor1
parents:
diff changeset
41 else
Ritor1
parents:
diff changeset
42 v2 = v2 + (double)v7 * 0.0039215689 / v4;
Ritor1
parents:
diff changeset
43 ++v3;
Ritor1
parents:
diff changeset
44 }
Ritor1
parents:
diff changeset
45 if ( v6 )
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
46 return v2 / (double)v6;
0
Ritor1
parents:
diff changeset
47 else
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
48 return 1.0;
0
Ritor1
parents:
diff changeset
49 }
Ritor1
parents:
diff changeset
50
Ritor1
parents:
diff changeset
51 //----- (0044F408) --------------------------------------------------------
Ritor1
parents:
diff changeset
52 void GammaController::SetGammaRamp(DDGAMMARAMP *pRamp)
Ritor1
parents:
diff changeset
53 {
Ritor1
parents:
diff changeset
54 if (pGammaControl)
Ritor1
parents:
diff changeset
55 ErrD3D(pGammaControl->SetGammaRamp(0, pRamp));
Ritor1
parents:
diff changeset
56 else
Ritor1
parents:
diff changeset
57 MessageBoxW(nullptr, L"Gamma control not active", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\GammaControl.cpp:120", 0);
Ritor1
parents:
diff changeset
58 }
Ritor1
parents:
diff changeset
59
Ritor1
parents:
diff changeset
60 //----- (0044F45B) --------------------------------------------------------
Ritor1
parents:
diff changeset
61 int GammaController::InitGammaRamp(DDGAMMARAMP *pRamp)
Ritor1
parents:
diff changeset
62 {
Ritor1
parents:
diff changeset
63 unsigned __int16 *v2; // esi@1
Ritor1
parents:
diff changeset
64 double v3; // st7@2
Ritor1
parents:
diff changeset
65 signed __int64 v4; // qax@3
Ritor1
parents:
diff changeset
66 signed int v6; // [sp+Ch] [bp-4h]@1
Ritor1
parents:
diff changeset
67
Ritor1
parents:
diff changeset
68 v2 = pRamp->green;
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
69 for ( v6 = 0; v6 < 256; ++v6 )
0
Ritor1
parents:
diff changeset
70 {
Ritor1
parents:
diff changeset
71 v3 = (double)v6 * 0.0039215689 * this->fGamma;
Ritor1
parents:
diff changeset
72 if ( v3 >= 1.0 || (v4 = (signed __int64)(v3 * 65535.0), (signed int)v4 > 65535) )
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
73 LODWORD(v4) = 65535;
1421
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
74 else if ( (signed int)v4 < 0 )
0
Ritor1
parents:
diff changeset
75 LODWORD(v4) = 0;
1421
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
76 else
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
77 {
0
Ritor1
parents:
diff changeset
78 if ( (signed int)v4 > 65535 )
Ritor1
parents:
diff changeset
79 LODWORD(v4) = 65535;
1421
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
80 }
0
Ritor1
parents:
diff changeset
81 v2[256] = v4;
Ritor1
parents:
diff changeset
82 *v2 = v4;
Ritor1
parents:
diff changeset
83 *(v2 - 256) = v4;
Ritor1
parents:
diff changeset
84 ++v2;
Ritor1
parents:
diff changeset
85 }
Ritor1
parents:
diff changeset
86 return v4;
Ritor1
parents:
diff changeset
87 }
Ritor1
parents:
diff changeset
88
Ritor1
parents:
diff changeset
89 //----- (0044F4D9) --------------------------------------------------------
Ritor1
parents:
diff changeset
90 void GammaController::Initialize(float gamma)
Ritor1
parents:
diff changeset
91 {
Ritor1
parents:
diff changeset
92 double v3; // st7@3
Ritor1
parents:
diff changeset
93 double v4; // st6@4
Ritor1
parents:
diff changeset
94
2152
d44b7775fc06 Removed DirectDraw2 compatibility.
Nomad
parents: 1421
diff changeset
95 //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
d44b7775fc06 Removed DirectDraw2 compatibility.
Nomad
parents: 1421
diff changeset
96 //pVersion->pVersionInfo.dwMajorVersion != 4)
0
Ritor1
parents:
diff changeset
97 {
Ritor1
parents:
diff changeset
98 InitializeFromSurface(pRenderer->pFrontBuffer4);
Ritor1
parents:
diff changeset
99 v3 = 2.8;
Ritor1
parents:
diff changeset
100 if ( gamma <= 2.8f )
Ritor1
parents:
diff changeset
101 v4 = gamma;
Ritor1
parents:
diff changeset
102 else
Ritor1
parents:
diff changeset
103 v4 = 2.8;
Ritor1
parents:
diff changeset
104 if ( v4 >= 0.1f )
Ritor1
parents:
diff changeset
105 {
Ritor1
parents:
diff changeset
106 if ( gamma <= 2.8f )
Ritor1
parents:
diff changeset
107 v3 = gamma;
Ritor1
parents:
diff changeset
108 }
Ritor1
parents:
diff changeset
109 else
Ritor1
parents:
diff changeset
110 v3 = 0.1;
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
111 this->fGamma = v3;
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
112 InitGammaRamp(&this->field_60C);
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
113 SetGammaRamp(&this->field_60C);
0
Ritor1
parents:
diff changeset
114 }
Ritor1
parents:
diff changeset
115 }
Ritor1
parents:
diff changeset
116
Ritor1
parents:
diff changeset
117 //----- (0044F215) --------------------------------------------------------
Ritor1
parents:
diff changeset
118 GammaController::GammaController()
Ritor1
parents:
diff changeset
119 {
Ritor1
parents:
diff changeset
120 static float flt_4D8670_default_gamma = 1.0f;
Ritor1
parents:
diff changeset
121
Ritor1
parents:
diff changeset
122 pGammaControl = nullptr;
Ritor1
parents:
diff changeset
123 fGamma = flt_4D8670_default_gamma;
Ritor1
parents:
diff changeset
124 }
Ritor1
parents:
diff changeset
125
Ritor1
parents:
diff changeset
126 //----- (0044F24B) --------------------------------------------------------
Ritor1
parents:
diff changeset
127 void GammaController::InitializeFromSurface(IDirectDrawSurface4 *a2)
Ritor1
parents:
diff changeset
128 {
Ritor1
parents:
diff changeset
129 this->pSurface = a2;
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
130 if ( this->pGammaControl )
0
Ritor1
parents:
diff changeset
131 {
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
132 this->pGammaControl->Release();
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
133 this->pGammaControl = 0;
0
Ritor1
parents:
diff changeset
134 }
2154
9bd7522cdbbb Render decoupling.
Nomad
parents: 2152
diff changeset
135 if ( pRenderer->IsGammaSupported() )
0
Ritor1
parents:
diff changeset
136 {
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
137 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)&this->pGammaControl));
0
Ritor1
parents:
diff changeset
138 GetRamp();
2268
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
139 memcpy(&this->field_60C, &this->pDefaultRamp, 0x600u);
fd788d2e9585 EventProcessor cleaned and ODM_NearClip fix
Ritor1
parents: 2253
diff changeset
140 fGamma = _44F377(&this->field_60C);
0
Ritor1
parents:
diff changeset
141 }
Ritor1
parents:
diff changeset
142 }