Skip to content

Commit 3b46e4a

Browse files
committed
Replace FixedMap with xr_vector. Delete FixedMAP. Small fixes.
1 parent 8e9fe15 commit 3b46e4a

File tree

7 files changed

+70
-432
lines changed

7 files changed

+70
-432
lines changed

src/Layers/xrRender/D3DXRenderBase.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ class D3DXRenderBase : public IRender, public pureFrame
138138
mapMatrixPasses[0][i].clear();
139139
mapMatrixPasses[1][i].clear();
140140
}
141-
mapSorted.destroy();
142-
mapHUD.destroy();
141+
mapSorted.clear();
142+
mapHUD.clear();
143143
mapLOD.clear();
144-
mapDistort.destroy();
144+
mapDistort.clear();
145145

146146
#if RENDER != R_R1
147-
mapWmark.destroy();
148-
mapEmissive.destroy();
147+
mapWmark.clear();
148+
mapEmissive.clear();
149149
#endif
150150
}
151151

src/Layers/xrRender/r__dsgraph_build.cpp

Lines changed: 26 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,10 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(dxRender_Visual* pVisual, Fvector&
5757
// a) Allow to optimize RT order
5858
// b) Should be rendered to special distort buffer in another pass
5959
VERIFY(pVisual->shader._get());
60-
ShaderElement* sh_d = &*pVisual->shader->E[4];
60+
ShaderElement* sh_d = &*pVisual->shader->E[4]; // 4=L_special
6161
if (RImplementation.o.distortion && sh_d && sh_d->flags.bDistort && pmask[sh_d->flags.iPriority / 2])
6262
{
63-
mapSorted_Node* N = mapDistort.insertInAnyWay(distSQ);
64-
N->val.ssa = SSA;
65-
N->val.pObject = RI.val_pObject;
66-
N->val.pVisual = pVisual;
67-
N->val.Matrix = *RI.val_pTransform;
68-
N->val.se = sh_d; // 4=L_special
63+
mapDistort.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
6964
}
7065

7166
// Select shader
@@ -75,62 +70,35 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(dxRender_Visual* pVisual, Fvector&
7570
if (!pmask[sh->flags.iPriority / 2])
7671
return;
7772

78-
// Create common node
79-
// NOTE: Invisible elements exist only in R1
80-
_MatrixItem item = {SSA, RI.val_pObject, pVisual, *RI.val_pTransform};
81-
8273
// HUD rendering
8374
if (RI.val_bHUD)
8475
{
8576
if (sh->flags.bStrictB2F)
8677
{
87-
mapSorted_Node* N = mapSorted.insertInAnyWay(distSQ);
88-
N->val.ssa = SSA;
89-
N->val.pObject = RI.val_pObject;
90-
N->val.pVisual = pVisual;
91-
N->val.Matrix = *RI.val_pTransform;
92-
N->val.se = sh;
93-
return;
78+
mapSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
9479
}
9580
else
9681
{
97-
mapHUD_Node* N = mapHUD.insertInAnyWay(distSQ);
98-
N->val.ssa = SSA;
99-
N->val.pObject = RI.val_pObject;
100-
N->val.pVisual = pVisual;
101-
N->val.Matrix = *RI.val_pTransform;
102-
N->val.se = sh;
82+
mapHUD.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
10383
#if RENDER != R_R1
10484
if (sh->flags.bEmissive)
105-
{
106-
mapSorted_Node* N2 = mapHUDEmissive.insertInAnyWay(distSQ);
107-
N2->val.ssa = SSA;
108-
N2->val.pObject = RI.val_pObject;
109-
N2->val.pVisual = pVisual;
110-
N2->val.Matrix = *RI.val_pTransform;
111-
N2->val.se = &*pVisual->shader->E[4]; // 4=L_special
112-
}
113-
#endif // RENDER!=R_R1
114-
return;
85+
mapHUDEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
86+
#endif // RENDER!=R_R1
11587
}
88+
return;
11689
}
11790

11891
// Shadows registering
11992
#if RENDER == R_R1
120-
RI.L_Shadows->add_element(item);
93+
RI.L_Shadows->add_element(_MatrixItem{ SSA, RI.val_pObject, pVisual, *RI.val_pTransform });
12194
#endif
12295
if (RI.val_bInvisible)
12396
return;
12497

12598
// strict-sorting selection
12699
if (sh->flags.bStrictB2F)
127100
{
128-
mapSorted_Node* N = mapSorted.insertInAnyWay(distSQ);
129-
N->val.ssa = SSA;
130-
N->val.pObject = RI.val_pObject;
131-
N->val.pVisual = pVisual;
132-
N->val.Matrix = *RI.val_pTransform;
133-
N->val.se = sh;
101+
mapSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
134102
return;
135103
}
136104

@@ -142,25 +110,19 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(dxRender_Visual* pVisual, Fvector&
142110
// d) Should be rendered to accumulation buffer in the second pass
143111
if (sh->flags.bEmissive)
144112
{
145-
mapSorted_Node* N = mapEmissive.insertInAnyWay(distSQ);
146-
N->val.ssa = SSA;
147-
N->val.pObject = RI.val_pObject;
148-
N->val.pVisual = pVisual;
149-
N->val.Matrix = *RI.val_pTransform;
150-
N->val.se = &*pVisual->shader->E[4]; // 4=L_special
113+
mapEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
151114
}
152115
if (sh->flags.bWmark && pmask_wmark)
153116
{
154-
mapSorted_Node* N = mapWmark.insertInAnyWay(distSQ);
155-
N->val.ssa = SSA;
156-
N->val.pObject = RI.val_pObject;
157-
N->val.pVisual = pVisual;
158-
N->val.Matrix = *RI.val_pTransform;
159-
N->val.se = sh;
117+
mapWmark.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
160118
return;
161119
}
162120
#endif
163121

122+
// Create common node
123+
// NOTE: Invisible elements exist only in R1
124+
_MatrixItem item = { SSA, RI.val_pObject, pVisual, *RI.val_pTransform };
125+
164126
for (u32 iPass = 0; iPass < sh->passes.size(); ++iPass)
165127
{
166128
auto &pass = *sh->passes[iPass];
@@ -262,15 +224,10 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
262224
// a) Allow to optimize RT order
263225
// b) Should be rendered to special distort buffer in another pass
264226
VERIFY(pVisual->shader._get());
265-
ShaderElement* sh_d = &*pVisual->shader->E[4];
227+
ShaderElement* sh_d = &*pVisual->shader->E[4]; // 4=L_special
266228
if (RImplementation.o.distortion && sh_d && sh_d->flags.bDistort && pmask[sh_d->flags.iPriority / 2])
267229
{
268-
mapSorted_Node* N = mapDistort.insertInAnyWay(distSQ);
269-
N->val.ssa = SSA;
270-
N->val.pObject = nullptr;
271-
N->val.pVisual = pVisual;
272-
N->val.Matrix = Fidentity;
273-
N->val.se = &*pVisual->shader->E[4]; // 4=L_special
230+
mapDistort.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, nullptr, pVisual, Fidentity, sh_d }))); // sh_d -> L_special
274231
}
275232

276233
// Select shader
@@ -283,11 +240,9 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
283240
// strict-sorting selection
284241
if (sh->flags.bStrictB2F)
285242
{
286-
mapSorted_Node* N = mapSorted.insertInAnyWay(distSQ);
287-
N->val.pObject = nullptr;
288-
N->val.pVisual = pVisual;
289-
N->val.Matrix = Fidentity;
290-
N->val.se = sh;
243+
// TODO: Выяснить, почему в единственном месте параметр ssa не используется
244+
// Визуально различий не замечено
245+
mapSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ /*0*/SSA, nullptr, pVisual, Fidentity, sh })));
291246
return;
292247
}
293248

@@ -299,21 +254,11 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
299254
// d) Should be rendered to accumulation buffer in the second pass
300255
if (sh->flags.bEmissive)
301256
{
302-
mapSorted_Node* N = mapEmissive.insertInAnyWay(distSQ);
303-
N->val.ssa = SSA;
304-
N->val.pObject = NULL;
305-
N->val.pVisual = pVisual;
306-
N->val.Matrix = Fidentity;
307-
N->val.se = &*pVisual->shader->E[4]; // 4=L_special
257+
mapEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, nullptr, pVisual, Fidentity, sh_d }))); // sh_d -> L_special
308258
}
309259
if (sh->flags.bWmark && pmask_wmark)
310260
{
311-
mapSorted_Node* N = mapWmark.insertInAnyWay(distSQ);
312-
N->val.ssa = SSA;
313-
N->val.pObject = NULL;
314-
N->val.pVisual = pVisual;
315-
N->val.Matrix = Fidentity;
316-
N->val.se = sh;
261+
mapWmark.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, nullptr, pVisual, Fidentity, sh })));
317262
return;
318263
}
319264
#endif
@@ -323,14 +268,14 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
323268

324269
counter_S++;
325270

326-
_NormalItem item = {SSA, pVisual};
271+
_NormalItem item = { SSA, pVisual };
327272

328273
for (u32 iPass = 0; iPass < sh->passes.size(); ++iPass)
329274
{
330275
auto &pass = *sh->passes[iPass];
331276
auto &map = mapNormalPasses[sh->flags.iPriority / 2][iPass];
332277

333-
#if defined(USE_OGL)
278+
#ifdef USE_OGL
334279
auto &Nvs = map[pass.vs->vs];
335280
auto &Ngs = Nvs[pass.gs->gs];
336281
auto &Nps = Ngs[pass.ps->ps];
@@ -351,7 +296,6 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
351296
#else
352297
auto &Ncs = Nps[pass.constants._get()];
353298
#endif
354-
//auto &Nstate = Ncs[pass.state->state];
355299
auto &Nstate = Ncs[&*pass.state];
356300
auto &Ntex = Nstate[pass.T._get()];
357301
Ntex.push_back(item);
@@ -375,7 +319,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
375319
{
376320
Nps.ssa = SSA;
377321
#endif
378-
#if defined(USE_DX10) || defined(USE_DX11)
322+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
379323
if (SSA > Ngs.ssa)
380324
{
381325
Ngs.ssa = SSA;
@@ -384,7 +328,7 @@ void D3DXRenderBase::r_dsgraph_insert_static(dxRender_Visual* pVisual)
384328
{
385329
Nvs.ssa = SSA;
386330
}
387-
#if defined(USE_DX10) || defined(USE_DX11)
331+
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
388332
}
389333
#endif
390334
}

src/Layers/xrRender/r__dsgraph_render.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ ICF float calcLOD(float ssa /*fDistSq*/, float /*R*/)
1616
}
1717

1818
// ALPHA
19-
void __fastcall sorted_L1(mapSorted_Node* N)
19+
void __fastcall sorted_L1(mapSorted_T::value_type &N)
2020
{
2121
VERIFY(N);
22-
dxRender_Visual* V = N->val.pVisual;
22+
dxRender_Visual* V = N.second.pVisual;
2323
VERIFY(V && V->shader._get());
24-
RCache.set_Element(N->val.se);
25-
RCache.set_xform_world(N->val.Matrix);
26-
RImplementation.apply_object(N->val.pObject);
24+
RCache.set_Element(N.second.se);
25+
RCache.set_xform_world(N.second.Matrix);
26+
RImplementation.apply_object(N.second.pObject);
2727
RImplementation.apply_lmaterial();
28-
V->Render(calcLOD(N->key, V->vis.sphere.R));
28+
V->Render(calcLOD(N.first, V->vis.sphere.R));
2929
}
3030

3131
template <class T> IC bool cmp_second_ssa(const T &lhs, const T &rhs) { return (lhs->second.ssa > rhs->second.ssa); }
@@ -343,6 +343,9 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
343343
BasicStats.Primitives.End();
344344
}
345345

346+
347+
template <class T> IC bool cmp_first_l(const T &lhs, const T &rhs) { return (lhs.first < rhs.first); }
348+
template <class T> IC bool cmp_first_h(const T &lhs, const T &rhs) { return (lhs.first > rhs.first); }
346349
//////////////////////////////////////////////////////////////////////////
347350
// HUD render
348351
void D3DXRenderBase::r_dsgraph_render_hud()
@@ -362,7 +365,9 @@ void D3DXRenderBase::r_dsgraph_render_hud()
362365

363366
// Rendering
364367
rmNear();
365-
mapHUD.traverseLR(sorted_L1);
368+
std::sort(mapHUD.begin(), mapHUD.end(), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
369+
for (auto &i : mapHUD)
370+
sorted_L1(i);
366371
mapHUD.clear();
367372

368373
#if RENDER == R_R1
@@ -468,8 +473,9 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
468473
// strict-sorted render
469474
void D3DXRenderBase::r_dsgraph_render_sorted()
470475
{
471-
// Sorted (back to front)
472-
mapSorted.traverseRL(sorted_L1);
476+
std::sort(mapSorted.begin(), mapSorted.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
477+
for (auto &i : mapSorted)
478+
sorted_L1(i);
473479
mapSorted.clear();
474480
}
475481

@@ -478,8 +484,9 @@ void D3DXRenderBase::r_dsgraph_render_sorted()
478484
void D3DXRenderBase::r_dsgraph_render_emissive()
479485
{
480486
#if RENDER != R_R1
481-
// Sorted (back to front)
482-
mapEmissive.traverseLR(sorted_L1);
487+
std::sort(mapEmissive.begin(), mapEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
488+
for (auto &i : mapEmissive)
489+
sorted_L1(i);
483490
mapEmissive.clear();
484491

485492
// HACK: Calculate this only once
@@ -497,8 +504,9 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
497504

498505
// Rendering
499506
rmNear();
500-
// Sorted (back to front)
501-
mapHUDEmissive.traverseLR(sorted_L1);
507+
std::sort(mapHUDEmissive.begin(), mapHUDEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
508+
for (auto &i : mapHUDEmissive)
509+
sorted_L1(i);
502510
mapHUDEmissive.clear();
503511

504512
rmNormal();
@@ -515,8 +523,9 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
515523
void D3DXRenderBase::r_dsgraph_render_wmarks()
516524
{
517525
#if RENDER != R_R1
518-
// Sorted (back to front)
519-
mapWmark.traverseLR(sorted_L1);
526+
std::sort(mapWmark.begin(), mapWmark.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
527+
for (auto &i : mapWmark)
528+
sorted_L1(i);
520529
mapWmark.clear();
521530
#endif
522531
}
@@ -525,8 +534,9 @@ void D3DXRenderBase::r_dsgraph_render_wmarks()
525534
// strict-sorted render
526535
void D3DXRenderBase::r_dsgraph_render_distort()
527536
{
528-
// Sorted (back to front)
529-
mapDistort.traverseRL(sorted_L1);
537+
std::sort(mapDistort.begin(), mapDistort.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
538+
for (auto &i : mapDistort)
539+
sorted_L1(i);
530540
mapDistort.clear();
531541
}
532542

src/Layers/xrRender/r__dsgraph_types.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include "xrCore/FixedMap.h"
4-
53
class dxRender_Visual;
64

75
namespace R_dsgraph
@@ -21,8 +19,16 @@ struct _MatrixItem
2119
Fmatrix Matrix; // matrix (copy)
2220
};
2321

24-
struct _MatrixItemS : public _MatrixItem
22+
struct _MatrixItemS
2523
{
24+
// Хак для использования списков инициализации
25+
// Не используем наследование
26+
// _MatrixItem begin
27+
float ssa;
28+
IRenderable* pObject;
29+
dxRender_Visual* pVisual;
30+
Fmatrix Matrix; // matrix (copy)
31+
// _MatrixItem end
2632
ShaderElement* se;
2733
};
2834

@@ -164,11 +170,7 @@ using mapMatrix_T = mapMatrixVS;
164170
using mapMatrixPasses_T = mapMatrix_T[SHADER_PASSES_MAX];
165171

166172
// Top level
167-
using mapSorted_T = FixedMAP<float, _MatrixItemS>;
168-
using mapSorted_Node = mapSorted_T::TNode;
169-
170-
using mapHUD_T = FixedMAP<float, _MatrixItemS>;
171-
using mapHUD_Node = mapHUD_T::TNode;
172-
173-
using mapLOD_T = xr_vector<std::pair<float, _LodItem>>;
173+
using mapSorted_T = xr_vector<std::pair<float, _MatrixItemS>>;
174+
using mapHUD_T = xr_vector<std::pair<float, _MatrixItemS>>;
175+
using mapLOD_T = xr_vector<std::pair<float, _LodItem>>;
174176
}

0 commit comments

Comments
 (0)