annotate GammaControl.cpp @ 2193:4842f58715ea

sub_47C3D7_get_fog_related_stuff to sub_47C3D7_get_fog_specular cleanup, IsTerrainSlopeTooHigh restoring commented out min,min/max,max implementation, some small changes in OnMapLoad, sub_4465DF_check_season attempted to pick the best readabilty/maintainability tradeoff
author Grumpy7
date Thu, 30 Jan 2014 22:09:10 +0100
parents 9bd7522cdbbb
children aff7a7b072b7
rev   line source
0
Ritor1
parents:
diff changeset
1 #include <string>
Ritor1
parents:
diff changeset
2
Ritor1
parents:
diff changeset
3 #include "GammaControl.h"
Ritor1
parents:
diff changeset
4 #include "Render.h"
Ritor1
parents:
diff changeset
5
Ritor1
parents:
diff changeset
6 #include "mm7_data.h"
Ritor1
parents:
diff changeset
7
Ritor1
parents:
diff changeset
8
Ritor1
parents:
diff changeset
9
Ritor1
parents:
diff changeset
10 //----- (0044F324) --------------------------------------------------------
Ritor1
parents:
diff changeset
11 void GammaController::GetRamp()
Ritor1
parents:
diff changeset
12 {
Ritor1
parents:
diff changeset
13 if (pGammaControl)
Ritor1
parents:
diff changeset
14 ErrD3D(pGammaControl->GetGammaRamp(0, &pDefaultRamp));
Ritor1
parents:
diff changeset
15 else
Ritor1
parents:
diff changeset
16 MessageBoxW(nullptr, L"Gamma control not active", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\GammaControl.cpp:83", 0);
Ritor1
parents:
diff changeset
17 }
Ritor1
parents:
diff changeset
18
Ritor1
parents:
diff changeset
19 //----- (0044F377) --------------------------------------------------------
Ritor1
parents:
diff changeset
20 double GammaController::_44F377(DDGAMMARAMP *a1)
Ritor1
parents:
diff changeset
21 {
Ritor1
parents:
diff changeset
22 double v2; // st7@1
Ritor1
parents:
diff changeset
23 unsigned __int16 *v3; // ecx@1
Ritor1
parents:
diff changeset
24 double v4; // st6@2
Ritor1
parents:
diff changeset
25 double result; // st7@7
Ritor1
parents:
diff changeset
26 signed int v6; // [sp+0h] [bp-8h]@1
Ritor1
parents:
diff changeset
27 signed int v7; // [sp+4h] [bp-4h]@1
Ritor1
parents:
diff changeset
28
Ritor1
parents:
diff changeset
29 v7 = 0;
Ritor1
parents:
diff changeset
30 v2 = 0.0;
Ritor1
parents:
diff changeset
31 v6 = 256;
Ritor1
parents:
diff changeset
32 v3 = a1->green;
Ritor1
parents:
diff changeset
33 do
Ritor1
parents:
diff changeset
34 {
Ritor1
parents:
diff changeset
35 v4 = ((double)*(v3 - 256) + (double)v3[256] + (double)*v3) * 0.000015259022 * 0.33333334;
Ritor1
parents:
diff changeset
36 if ( v4 == 0.0 )
Ritor1
parents:
diff changeset
37 --v6;
Ritor1
parents:
diff changeset
38 else
Ritor1
parents:
diff changeset
39 v2 = v2 + (double)v7 * 0.0039215689 / v4;
Ritor1
parents:
diff changeset
40 ++v7;
Ritor1
parents:
diff changeset
41 ++v3;
Ritor1
parents:
diff changeset
42 }
Ritor1
parents:
diff changeset
43 while ( v7 < 256 );
Ritor1
parents:
diff changeset
44 if ( v6 )
Ritor1
parents:
diff changeset
45 result = v2 / (double)v6;
Ritor1
parents:
diff changeset
46 else
Ritor1
parents:
diff changeset
47 result = 1.0;
Ritor1
parents:
diff changeset
48 return result;
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 v6 = 0;
Ritor1
parents:
diff changeset
69 v2 = pRamp->green;
Ritor1
parents:
diff changeset
70 do
Ritor1
parents:
diff changeset
71 {
Ritor1
parents:
diff changeset
72 v3 = (double)v6 * 0.0039215689 * this->fGamma;
Ritor1
parents:
diff changeset
73 if ( v3 >= 1.0 || (v4 = (signed __int64)(v3 * 65535.0), (signed int)v4 > 65535) )
1421
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
74 {
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
75 LODWORD(v4) = 65535;
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
76 }
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
77 else if ( (signed int)v4 < 0 )
0
Ritor1
parents:
diff changeset
78 {
Ritor1
parents:
diff changeset
79 LODWORD(v4) = 0;
Ritor1
parents:
diff changeset
80 }
1421
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
81 else
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
82 {
0
Ritor1
parents:
diff changeset
83 if ( (signed int)v4 > 65535 )
Ritor1
parents:
diff changeset
84 LODWORD(v4) = 65535;
1421
4fff79f04dbd more label cleaning 4
zipi
parents: 0
diff changeset
85 }
0
Ritor1
parents:
diff changeset
86 ++v6;
Ritor1
parents:
diff changeset
87 v2[256] = v4;
Ritor1
parents:
diff changeset
88 *v2 = v4;
Ritor1
parents:
diff changeset
89 *(v2 - 256) = v4;
Ritor1
parents:
diff changeset
90 ++v2;
Ritor1
parents:
diff changeset
91 }
Ritor1
parents:
diff changeset
92 while ( v6 < 256 );
Ritor1
parents:
diff changeset
93 return v4;
Ritor1
parents:
diff changeset
94 }
Ritor1
parents:
diff changeset
95
Ritor1
parents:
diff changeset
96 //----- (0044F4D9) --------------------------------------------------------
Ritor1
parents:
diff changeset
97 void GammaController::Initialize(float gamma)
Ritor1
parents:
diff changeset
98 {
Ritor1
parents:
diff changeset
99 GammaController *v2; // esi@1
Ritor1
parents:
diff changeset
100 double v3; // st7@3
Ritor1
parents:
diff changeset
101 double v4; // st6@4
Ritor1
parents:
diff changeset
102
Ritor1
parents:
diff changeset
103 v2 = this;
2152
d44b7775fc06 Removed DirectDraw2 compatibility.
Nomad
parents: 1421
diff changeset
104 //if (pVersion->pVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
d44b7775fc06 Removed DirectDraw2 compatibility.
Nomad
parents: 1421
diff changeset
105 //pVersion->pVersionInfo.dwMajorVersion != 4)
0
Ritor1
parents:
diff changeset
106 {
Ritor1
parents:
diff changeset
107 InitializeFromSurface(pRenderer->pFrontBuffer4);
Ritor1
parents:
diff changeset
108 v3 = 2.8;
Ritor1
parents:
diff changeset
109 if ( gamma <= 2.8f )
Ritor1
parents:
diff changeset
110 v4 = gamma;
Ritor1
parents:
diff changeset
111 else
Ritor1
parents:
diff changeset
112 v4 = 2.8;
Ritor1
parents:
diff changeset
113 if ( v4 >= 0.1f )
Ritor1
parents:
diff changeset
114 {
Ritor1
parents:
diff changeset
115 if ( gamma <= 2.8f )
Ritor1
parents:
diff changeset
116 v3 = gamma;
Ritor1
parents:
diff changeset
117 }
Ritor1
parents:
diff changeset
118 else
Ritor1
parents:
diff changeset
119 {
Ritor1
parents:
diff changeset
120 v3 = 0.1;
Ritor1
parents:
diff changeset
121 }
Ritor1
parents:
diff changeset
122 v2->fGamma = v3;
Ritor1
parents:
diff changeset
123 InitGammaRamp(&v2->field_60C);
Ritor1
parents:
diff changeset
124 SetGammaRamp(&v2->field_60C);
Ritor1
parents:
diff changeset
125 }
Ritor1
parents:
diff changeset
126 }
Ritor1
parents:
diff changeset
127
Ritor1
parents:
diff changeset
128
Ritor1
parents:
diff changeset
129
Ritor1
parents:
diff changeset
130
Ritor1
parents:
diff changeset
131
Ritor1
parents:
diff changeset
132 //----- (0044F215) --------------------------------------------------------
Ritor1
parents:
diff changeset
133 GammaController::GammaController()
Ritor1
parents:
diff changeset
134 {
Ritor1
parents:
diff changeset
135 static float flt_4D8670_default_gamma = 1.0f;
Ritor1
parents:
diff changeset
136
Ritor1
parents:
diff changeset
137 pGammaControl = nullptr;
Ritor1
parents:
diff changeset
138 fGamma = flt_4D8670_default_gamma;
Ritor1
parents:
diff changeset
139 }
Ritor1
parents:
diff changeset
140
Ritor1
parents:
diff changeset
141
Ritor1
parents:
diff changeset
142
Ritor1
parents:
diff changeset
143 //----- (0044F24B) --------------------------------------------------------
Ritor1
parents:
diff changeset
144 void GammaController::InitializeFromSurface(IDirectDrawSurface4 *a2)
Ritor1
parents:
diff changeset
145 {
Ritor1
parents:
diff changeset
146 GammaController *v2; // esi@1
Ritor1
parents:
diff changeset
147 IDirectDrawGammaControl **v3; // edi@1
Ritor1
parents:
diff changeset
148 IDirectDrawGammaControl *v4; // eax@1
Ritor1
parents:
diff changeset
149
Ritor1
parents:
diff changeset
150 v2 = this;
Ritor1
parents:
diff changeset
151 v3 = &this->pGammaControl;
Ritor1
parents:
diff changeset
152 this->pSurface = a2;
Ritor1
parents:
diff changeset
153 v4 = this->pGammaControl;
Ritor1
parents:
diff changeset
154 if ( v4 )
Ritor1
parents:
diff changeset
155 {
Ritor1
parents:
diff changeset
156 v4->Release();
Ritor1
parents:
diff changeset
157 *v3 = 0;
Ritor1
parents:
diff changeset
158 }
2154
9bd7522cdbbb Render decoupling.
Nomad
parents: 2152
diff changeset
159 if ( pRenderer->IsGammaSupported() )
0
Ritor1
parents:
diff changeset
160 {
Ritor1
parents:
diff changeset
161 ErrD3D(a2->QueryInterface(IID_IDirectDrawGammaControl, (LPVOID *)v3));
Ritor1
parents:
diff changeset
162 GetRamp();
Ritor1
parents:
diff changeset
163 memcpy(&v2->field_60C, &v2->pDefaultRamp, 0x600u);
Ritor1
parents:
diff changeset
164 fGamma = _44F377(&v2->field_60C);
Ritor1
parents:
diff changeset
165 }
Ritor1
parents:
diff changeset
166 }