-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_cMossBackground.cpp
405 lines (327 loc) · 14.6 KB
/
07_cMossBackground.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
///////////////////////////////////////////////////////
//*-------------------------------------------------*//
//| Part of Project One (https://www.maus-games.at) |//
//*-------------------------------------------------*//
//| Copyright (c) 2010 Martin Mauersics |//
//| Released under the zlib License |//
//*-------------------------------------------------*//
///////////////////////////////////////////////////////
#include "main.h"
// ****************************************************************
// constructor
cMossBackground::cMossBackground()noexcept
: cBackground (false)
, m_vRainMove (coreVector2(-0.5f,-1.2f))
, m_fLightningDelay (Core::Rand->Float(15.0f, 30.0f))
, m_fLightningFlash (0.0f)
, m_LightningTicker (coreTimer(1.0f, 1.0f, 1u))
, m_fThunderDelay (0.0f)
, m_iThunderIndex (Core::Rand->Uint(ARRAY_SIZE(m_apThunder) - 1u))
, m_bEnableLightning (true)
{
coreBatchList* pList1;
coreBatchList* pList2;
coreBatchList* pList3;
//
this->__InitOwn();
// create outdoor-surface object
m_pOutdoor = new cOutdoor("moss", "blood", OUTDOOR_ALGORITHM_MOSS, 4.5f, false);
//
pList1 = new coreBatchList(MOSS_TREE_1_RESERVE);
pList1->DefineProgram("object_ground_inst_program");
pList2 = new coreBatchList(MOSS_TREE_2_RESERVE);
pList2->DefineProgram("object_ground_inst_program");
pList3 = new coreBatchList(MOSS_TREE_3_RESERVE);
pList3->DefineProgram("object_ground_inst_program");
{
// load object resources
coreObject3D oBase;
oBase.DefineProgram("object_ground_program");
for(coreUintW i = 0u; i < MOSS_TREE_NUM; ++i)
{
// calculate position and height
const coreVector2 vPosition = __BACKGROUND_SCANLINE(Core::Rand->Float(-0.45f, 0.45f), i, MOSS_TREE_NUM);
const coreFloat fHeight = m_pOutdoor->RetrieveBackHeight(vPosition);
// test for valid values
if((fHeight > -20.0f) && (fHeight < -18.0f))
{
if(!cBackground::_CheckIntersectionQuick(pList1, vPosition, POW2(10.0f)) &&
!cBackground::_CheckIntersectionQuick(pList2, vPosition, POW2(10.0f)) &&
!cBackground::_CheckIntersectionQuick(pList3, vPosition, POW2(15.0f)))
{
// determine object type
const coreUint8 iType = Core::Rand->Bool() ? 0u : (Core::Rand->Bool(0.75f) ? 1u : 2u);
//
const coreVector3 vNormal = (m_pOutdoor->RetrieveBackNormal(vPosition) * coreVector3(1.0f,1.0f,2.0f)).Normalized();
// create object
coreObject3D* pObject = POOLED_NEW(s_MemoryPool, coreObject3D, oBase);
pObject->DefineModel ( (iType == 0u) ? "environment_tree_01.md3" : ((iType == 1u) ? "environment_tree_02.md3" : "environment_tree_03.md3"));
pObject->DefineTexture(0u, (iType == 0u) ? "environment_tree_01_diff.png" : ((iType == 1u) ? "environment_tree_02_diff.png" : "environment_tree_03_diff.png"));
pObject->DefineTexture(1u, (iType == 0u) ? "environment_tree_01_norm.png" : ((iType == 1u) ? "environment_tree_02_norm.png" : "environment_tree_03_norm.png"));
// set object properties
pObject->SetPosition (coreVector3(vPosition, 0.0f) - vNormal * 5.0f);
pObject->SetSize (coreVector3(1.0f,1.0f,1.0f) * Core::Rand->Float(3.5f, 4.2f) * 1.3f);
pObject->SetDirection (coreVector3(coreVector2::Rand(), 0.0f));
pObject->SetColor3 (coreVector3(1.0f,1.0f,1.0f) * Core::Rand->Float(0.85f, 1.0f));
// add object to the list
if(iType == 0u) cBackground::_BindSorted(pList1, pObject);
else if(iType == 1u) cBackground::_BindSorted(pList2, pObject);
else cBackground::_BindSorted(pList3, pObject);
}
}
}
//
this->_StoreHeight(pList1, 0.0f);
this->_StoreHeight(pList2, 0.0f);
this->_StoreHeight(pList3, 1.0f);
// post-process list and add to the ground
cBackground::_FillInfinite(pList1, MOSS_TREE_1_RESERVE);
m_apGroundObjectList.push_back(pList1);
cBackground::_FillInfinite(pList2, MOSS_TREE_2_RESERVE);
m_apGroundObjectList.push_back(pList2);
cBackground::_FillInfinite(pList3, MOSS_TREE_3_RESERVE);
m_apGroundObjectList.push_back(pList3);
//
m_pOutdoor->GetShadowMap()->BindList(pList1);
m_pOutdoor->GetShadowMap()->BindList(pList2);
m_pOutdoor->GetShadowMap()->BindList(pList3);
}
//
pList1 = new coreBatchList(MOSS_GRAVE_RESERVE);
pList1->DefineProgram("object_ground_inst_program");
{
// load object resources
coreObject3D oBase;
oBase.DefineModel ("environment_grave.md3");
oBase.DefineTexture(0u, "environment_grave_diff.png");
oBase.DefineTexture(1u, "environment_grave_norm.png");
oBase.DefineProgram("object_ground_program");
for(coreUintW i = 0u; i < MOSS_GRAVE_NUM; ++i)
{
// calculate position and height
const coreVector2 vPosition = __BACKGROUND_SCANLINE(Core::Rand->Float(-0.45f, 0.45f), i, MOSS_GRAVE_NUM);
const coreFloat fHeight = m_pOutdoor->RetrieveBackHeight(vPosition);
// test for valid values
if((fHeight > -26.0f) && (fHeight < -21.0f) && (F_TO_SI(vPosition.y+160.0f) % 80 < 40))
{
if(!cBackground::_CheckIntersectionQuick(pList1, vPosition, POW2(5.0f)))
{
// create object
coreObject3D* pObject = POOLED_NEW(s_MemoryPool, coreObject3D, oBase);
// set object properties
pObject->SetPosition (coreVector3(vPosition, 0.0f));
pObject->SetSize (coreVector3(1.0f,1.0f,2.0f) * (Core::Rand->Bool() ? 3.0f : 5.0f) * 1.2f * 1.3f);
pObject->SetDirection (coreVector3(AlongCrossNormal(coreVector2::Rand()), 0.0f));
pObject->SetOrientation(coreVector3(0.0f, 0.0f, Core::Rand->Bool() ? 1.0f : -1.0f));
pObject->SetColor3 (coreVector3(1.0f,1.0f,1.0f) * Core::Rand->Float(0.85f, 1.0f));
// add object to the list
pList1->BindObject(pObject);
}
}
}
//
this->_StoreHeight(pList1, 5.0f);
// post-process list and add to the ground
cBackground::_FillInfinite(pList1, MOSS_GRAVE_RESERVE);
m_apGroundObjectList.push_back(pList1);
//
m_pOutdoor->GetShadowMap()->BindList(pList1);
//
m_apWaterRefList.push_back(pList1);
}
// allocate cloud list
pList1 = new coreBatchList(MOSS_CLOUD_RESERVE);
pList1->DefineProgram("environment_clouds_inst_program");
{
// load object resources
coreObject3D oBase;
oBase.DefineModel (Core::Manager::Object->GetLowQuad());
oBase.DefineTexture(0u, "environment_clouds_mid.png");
oBase.DefineProgram("environment_clouds_program");
for(coreUintW i = 0u; i < MOSS_CLOUD_NUM; ++i)
{
// calculate position and height
const coreVector2 vPosition = __BACKGROUND_SCANLINE(Core::Rand->Float(0.05f, 0.25f) * ((i % 2u) ? 1.0f : -1.0f), i, MOSS_CLOUD_NUM);
const coreFloat fHeight = Core::Rand->Float(20.0f, 60.0f);
// create object
coreObject3D* pObject = POOLED_NEW(s_MemoryPool, coreObject3D, oBase);
// set object properties
pObject->SetPosition (coreVector3(vPosition, fHeight));
pObject->SetSize (coreVector3(coreVector2(2.4f,2.4f) * Core::Rand->Float(15.0f, 21.0f), 1.0f));
pObject->SetDirection(coreVector3(coreVector2::Rand(), 0.0f));
pObject->SetColor3 (coreVector3(1.0f,1.0f,1.0f) * (0.5f + 0.2f * fHeight/60.0f));
pObject->SetAlpha (0.85f);
pObject->SetTexOffset(coreVector2::Rand(0.0f,4.0f, 0.0f,4.0f));
// add object to the list
pList1->BindObject(pObject);
}
// post-process list and add to the air
cBackground::_FillInfinite (pList1, MOSS_CLOUD_RESERVE);
cBackground::_SortBackToFront(pList1);
m_apAirObjectList.push_back(pList1);
ASSERT(pList1->GetCapacity() == MOSS_CLOUD_RESERVE)
}
//
m_Rain.DefineTexture(0u, "effect_rain.png");
m_Rain.DefineProgram("effect_weather_rain_moss_program");
m_Rain.SetPosition (coreVector2(0.0f,0.0f));
m_Rain.SetAlpha (0.55f);
//
m_Lightning.DefineProgram("menu_color_program");
m_Lightning.SetPosition (coreVector2(0.0f,0.0f));
m_Lightning.SetSize (coreVector2(1.0f,1.0f));
m_Lightning.SetAlpha (0.0f);
m_Lightning.SetEnabled (CORE_OBJECT_ENABLE_NOTHING);
//
m_apThunder[0] = Core::Manager::Resource->Get<coreSound>("environment_thunder_01.wav");
m_apThunder[1] = Core::Manager::Resource->Get<coreSound>("environment_thunder_02.wav");
m_apThunder[2] = Core::Manager::Resource->Get<coreSound>("environment_thunder_03.wav");
//
m_Headlight.SetAlpha(0.0f);
}
// ****************************************************************
// destructor
cMossBackground::~cMossBackground()
{
//
this->__ExitOwn();
}
// ****************************************************************
//
void cMossBackground::__InitOwn()
{
//
m_pWater = new cRainWater("environment_clouds_grey.png");
// load base sound-effect
m_pBaseSound = Core::Manager::Resource->Get<coreSound>("environment_moss.wav");
m_pBaseSound.OnUsableOnce([this, pResource = m_pBaseSound]()
{
pResource->PlayRelative(this, 0.0f, 1.0f, true, SOUND_AMBIENT);
});
}
// ****************************************************************
//
void cMossBackground::__ExitOwn()
{
//
SAFE_DELETE(m_pWater)
// stop base sound-effect
m_pBaseSound.OnUsableOnce([this, pResource = m_pBaseSound]()
{
if(pResource->EnableRef(this))
pResource->Stop();
});
}
// ****************************************************************
//
void cMossBackground::__RenderOwnAfter()
{
// enable the shader-program
if(!m_Rain.GetProgram().IsUsable()) return;
if(!m_Rain.GetProgram()->Enable()) return;
//
coreProgram* pLocal = m_Rain.GetProgram().GetResource();
for(coreUintW i = 0u; i < MOSS_RAIN_NUM; ++i)
{
const coreVector2 vNewTexOffset = m_Rain.GetTexOffset() + coreVector2(0.56f,0.36f) * I_TO_F(POW2(i));
const coreFloat fNewScale = 1.0f - 0.15f * I_TO_F(i);
pLocal->SendUniform(s_asOverlayTransform[i], coreVector3(vNewTexOffset.Processed(FRACT), fNewScale));
}
glDisable(GL_DEPTH_TEST);
{
// (# render first)
m_Rain.Render();
//
m_Lightning.Render();
//
if(m_Headlight.GetAlpha()) m_Headlight.Render();
}
glEnable(GL_DEPTH_TEST);
}
// ****************************************************************
// move the moss background
void cMossBackground::__MoveOwn()
{
//
const coreVector2 vEnvMove = coreVector2(0.3f,1.0f) * (-0.35f * MAX0(g_pEnvironment->GetSpeed()));
const coreVector2 vTexSize = coreVector2(1.0f,1.0f) * 5.5f;
const coreVector2 vTexOffset = m_Rain.GetTexOffset() + (coreVector2(0.0f, -m_vRainMove.Length()) + vEnvMove) * (1.0f * TIME);
//
m_Rain.SetSize (coreVector2(1.0f,1.0f) * SQRT2 * ENVIRONMENT_SCALE_FACTOR);
m_Rain.SetDirection(MapToAxisInv(-m_vRainMove.InvertedX().Normalized(), g_pEnvironment->GetDirection()));
m_Rain.SetTexSize (vTexSize);
m_Rain.SetTexOffset(vTexOffset.Processed(FRACT));
m_Rain.Move();
if(m_bEnableLightning && g_CurConfig.Graphics.iFlash)
{
//
m_fLightningDelay.Update(-1.0f);
if(m_fLightningDelay <= 0.0f)
{
//
m_fLightningDelay = Core::Rand->Float(15.0f, 30.0f);
//
m_LightningTicker.SetSpeed (Core::Rand->Float(8.0f, 11.0f));
m_LightningTicker.SetMaxLoops(Core::Rand->Bool(0.67f) ? 3u : 2u);
m_LightningTicker.Play (CORE_TIMER_PLAY_RESET);
//
m_fThunderDelay = -1.0f;
}
}
//
const coreFloat fPrevDelay = m_fThunderDelay;
//
m_LightningTicker.Update(1.0f);
m_fThunderDelay .Update(1.0f);
//
m_fLightningFlash.UpdateMax(-1.0f, 0.0f);
//
this->__UpdateLightning();
//
if((fPrevDelay < 0.0f) && (m_fThunderDelay >= 0.0f))
{
m_iThunderIndex = (m_iThunderIndex + Core::Rand->Uint(1u, ARRAY_SIZE(m_apThunder) - 1u)) % ARRAY_SIZE(m_apThunder);
m_apThunder[m_iThunderIndex]->PlayRelative(this, 0.0f, 1.0f, false, SOUND_AMBIENT);
}
//
for(coreUintW i = 0u; i < ARRAY_SIZE(m_apThunder); ++i)
{
if(m_apThunder[i]->EnableRef(this))
{
m_apThunder[i]->SetVolume(g_pEnvironment->RetrieveTransitionBlend(this));
}
}
// adjust volume of the base sound-effect
if(m_pBaseSound.IsUsable() && m_pBaseSound->EnableRef(this))
{
m_pBaseSound->SetVolume(g_pEnvironment->RetrieveTransitionBlend(this));
}
const coreFloat fCloudMove = 0.0018f * (1.0f + ABS(g_pEnvironment->GetSpeed())) * TIME;
coreBatchList* pList = m_apAirObjectList[0];
for(coreUintW i = 0u, ie = LOOP_NONZERO(pList->GetSize()); i < ie; ++i)
{
coreObject3D* pCloud = (*pList->List())[i];
pCloud->SetTexOffset((pCloud->GetTexOffset() + MapToAxis(coreVector2(fCloudMove * ((pCloud->GetDirection().x < 0.0f) ? -1.0f : 1.0f), 0.0f), pCloud->GetDirection().xy())).Processed(FRACT));
}
pList->MoveNormal();
//
if(m_Headlight.GetAlpha()) m_Headlight.Move();
}
// ****************************************************************
//
void cMossBackground::__UpdateOwn()
{
//
if(m_Headlight.GetAlpha()) m_Headlight.UpdateDefault(0u);
}
// ****************************************************************
//
void cMossBackground::__UpdateLightning()
{
const coreFloat fValue = MAX(MIN1(m_fLightningFlash), m_LightningTicker.GetStatus() ? m_LightningTicker.GetValue(CORE_TIMER_GET_REVERSED) : 0.0f);
//
m_Lightning.SetColor3 (g_CurConfig.Graphics.iFlash ? coreVector3(1.0f,1.0f,1.0f) : COLOR_MENU_BLACK);
m_Lightning.SetAlpha (BLENDH3(fValue) * 0.7f);
m_Lightning.SetEnabled(fValue ? CORE_OBJECT_ENABLE_ALL : CORE_OBJECT_ENABLE_NOTHING);
m_Lightning.Move();
}