@@ -32,7 +32,8 @@ void CRender::render_lights(light_Package& LP)
3232 L->vis_update ();
3333 if (!L->vis .visible )
3434 {
35- source.erase (source.begin () + it);
35+ std::swap (source[it], source.back ());
36+ source.pop_back ();
3637 it--;
3738 }
3839 else
@@ -42,25 +43,26 @@ void CRender::render_lights(light_Package& LP)
4243 }
4344 }
4445
45- // 2. refactor - infact we could go from the backside and sort in ascending order
4646 {
4747 xr_vector<light*>& source = LP .v_shadowed ;
4848 xr_vector<light*> refactored;
4949 refactored.reserve (source.size ());
5050 const size_t total = source.size ();
5151
52+ std::sort (source.begin (), source.end (), [](light* l1, light* l2)
53+ {
54+ const u32 a0 = l1->X .S .size ;
55+ const u32 a1 = l2->X .S .size ;
56+ return a0 < a1; // ascending order
57+ });
58+
5259 for (u16 smap_ID = 0 ; refactored.size () != total; ++smap_ID)
5360 {
5461 LP_smap_pool.initialize (RImplementation.o .smapsize );
55- std::sort (source.begin (), source.end (), [](light* l1, light* l2)
56- {
57- const u32 a0 = l1->X .S .size ;
58- const u32 a1 = l2->X .S .size ;
59- return a0 > a1; // reverse -> descending
60- });
61- for (size_t test = 0 ; test < source.size (); ++test)
62+ for (auto &L : source)
6263 {
63- light* L = source[test];
64+ if (!L)
65+ continue ;
6466 SMAP_Rect R{};
6567 if (LP_smap_pool.push (R, L->X .S .size ))
6668 {
@@ -69,14 +71,12 @@ void CRender::render_lights(light_Package& LP)
6971 L->X .S .posY = R.min .y ;
7072 L->vis .smap_ID = smap_ID;
7173 refactored.push_back (L);
72- source.erase (source.begin () + test);
73- --test;
74+ L = nullptr ;
7475 }
7576 }
7677 }
7778
7879 // save (lights are popped from back)
79- std::reverse (refactored.begin (), refactored.end ());
8080 LP .v_shadowed = std::move (refactored);
8181 }
8282
@@ -129,14 +129,14 @@ void CRender::render_lights(light_Package& LP)
129129 }
130130 };
131131
132- const auto & flush_lights = [&]( )
132+ const auto & flush_lights = [] (CRender& render, xr_vector< task_data_t >& lights_queue )
133133 {
134134 for (const auto & [L, task, batch_id] : lights_queue)
135135 {
136136 VERIFY (task);
137137 TaskScheduler->Wait (*task);
138138
139- auto & dsgraph = get_context (batch_id);
139+ auto & dsgraph = render. get_context (batch_id);
140140
141141 const bool bNormal = !dsgraph.mapNormalPasses [0 ][0 ].empty () || !dsgraph.mapMatrixPasses [0 ][0 ].empty ();
142142 const bool bSpecial = !dsgraph.mapNormalPasses [1 ][0 ].empty () || !dsgraph.mapMatrixPasses [1 ][0 ].empty () ||
@@ -145,27 +145,27 @@ void CRender::render_lights(light_Package& LP)
145145 {
146146 PIX_EVENT_CTX (dsgraph.cmd_list , SHADOWED_LIGHT );
147147
148- Stats.s_merged ++;
148+ render. Stats .s_merged ++;
149149 L_spot_s.push_back (L);
150- Target->phase_smap_spot (dsgraph.cmd_list , L);
150+ render. Target ->phase_smap_spot (dsgraph.cmd_list , L);
151151 dsgraph.cmd_list .set_xform_world (Fidentity);
152152 dsgraph.cmd_list .set_xform_view (L->X .S .view );
153153 dsgraph.cmd_list .set_xform_project (L->X .S .project );
154154 dsgraph.render_graph (0 );
155155 if (ps_r2_ls_flags.test (R2FLAG_SUN_DETAILS ))
156156 {
157- if (check_grass_shadow (L, ViewBase))
157+ if (check_grass_shadow (L, render. ViewBase ))
158158 {
159- Details->fade_distance = -1 ; // Use light position to calc "fade"
160- Details->light_position .set (L->position );
161- Details->Render (dsgraph.cmd_list );
159+ render. Details ->fade_distance = -1 ; // Use light position to calc "fade"
160+ render. Details ->light_position .set (L->position );
161+ render. Details ->Render (dsgraph.cmd_list );
162162 }
163163 }
164164 L->X .S .transluent = FALSE ;
165165 if (bSpecial)
166166 {
167167 L->X .S .transluent = TRUE ;
168- Target->phase_smap_spot_tsh (dsgraph.cmd_list , L);
168+ render. Target ->phase_smap_spot_tsh (dsgraph.cmd_list , L);
169169 PIX_EVENT_CTX (dsgraph.cmd_list , SHADOWED_LIGHTS_RENDER_GRAPH );
170170 dsgraph.render_graph (1 ); // normal level, secondary priority
171171 PIX_EVENT_CTX (dsgraph.cmd_list , SHADOWED_LIGHTS_RENDER_SORTED );
@@ -174,7 +174,7 @@ void CRender::render_lights(light_Package& LP)
174174 }
175175 else
176176 {
177- Stats.s_finalclip ++;
177+ render. Stats .s_finalclip ++;
178178 }
179179
180180 L->svis [batch_id].end (); // NOTE(DX11): occqs are fetched here, this should be done on the imm context only
@@ -206,7 +206,7 @@ void CRender::render_lights(light_Package& LP)
206206 if (batch_id == R_dsgraph_structure::INVALID_CONTEXT_ID )
207207 {
208208 VERIFY (!lights_queue.empty ());
209- flush_lights ();
209+ flush_lights (* this , lights_queue );
210210 continue ;
211211 }
212212
@@ -228,7 +228,7 @@ void CRender::render_lights(light_Package& LP)
228228 }
229229 lights_queue.emplace_back (data);
230230 }
231- flush_lights (); // in case if something left
231+ flush_lights (* this , lights_queue ); // in case if something left
232232
233233 cmd_list.Invalidate ();
234234
0 commit comments