@@ -94,14 +94,14 @@ public ShroudSource(SourceType type, PPos[] projectedCells)
94
94
readonly Dictionary < object , ShroudSource > sources = new Dictionary < object , ShroudSource > ( ) ;
95
95
96
96
// Per-cell count of each source type, used to resolve the final cell type
97
- readonly CellLayer < short > passiveVisibleCount ;
98
- readonly CellLayer < short > visibleCount ;
99
- readonly CellLayer < short > generatedShroudCount ;
100
- readonly CellLayer < bool > explored ;
101
- readonly CellLayer < bool > touched ;
97
+ readonly ProjectedCellLayer < short > passiveVisibleCount ;
98
+ readonly ProjectedCellLayer < short > visibleCount ;
99
+ readonly ProjectedCellLayer < short > generatedShroudCount ;
100
+ readonly ProjectedCellLayer < bool > explored ;
101
+ readonly ProjectedCellLayer < bool > touched ;
102
102
103
103
// Per-cell cache of the resolved cell type (shroud/fog/visible)
104
- readonly CellLayer < ShroudCellType > resolvedType ;
104
+ readonly ProjectedCellLayer < ShroudCellType > resolvedType ;
105
105
106
106
[ Sync ]
107
107
bool disabled ;
@@ -137,14 +137,14 @@ public Shroud(Actor self, ShroudInfo info)
137
137
this . info = info ;
138
138
map = self . World . Map ;
139
139
140
- passiveVisibleCount = new CellLayer < short > ( map ) ;
141
- visibleCount = new CellLayer < short > ( map ) ;
142
- generatedShroudCount = new CellLayer < short > ( map ) ;
143
- explored = new CellLayer < bool > ( map ) ;
144
- touched = new CellLayer < bool > ( map ) ;
140
+ passiveVisibleCount = new ProjectedCellLayer < short > ( map ) ;
141
+ visibleCount = new ProjectedCellLayer < short > ( map ) ;
142
+ generatedShroudCount = new ProjectedCellLayer < short > ( map ) ;
143
+ explored = new ProjectedCellLayer < bool > ( map ) ;
144
+ touched = new ProjectedCellLayer < bool > ( map ) ;
145
145
146
146
// Defaults to 0 = Shroud
147
- resolvedType = new CellLayer < ShroudCellType > ( map ) ;
147
+ resolvedType = new ProjectedCellLayer < ShroudCellType > ( map ) ;
148
148
}
149
149
150
150
void INotifyCreated . Created ( Actor self )
@@ -164,27 +164,26 @@ void ITick.Tick(Actor self)
164
164
165
165
foreach ( var puv in map . ProjectedCellBounds )
166
166
{
167
- var uv = ( MPos ) puv ;
168
- if ( ! touched [ uv ] )
167
+ if ( ! touched [ puv ] )
169
168
continue ;
170
169
171
- touched [ uv ] = false ;
170
+ touched [ puv ] = false ;
172
171
173
172
var type = ShroudCellType . Shroud ;
174
173
175
- if ( explored [ uv ] && ( ! shroudGenerationEnabled || generatedShroudCount [ uv ] == 0 || visibleCount [ uv ] > 0 ) )
174
+ if ( explored [ puv ] && ( ! shroudGenerationEnabled || generatedShroudCount [ puv ] == 0 || visibleCount [ puv ] > 0 ) )
176
175
{
177
- var count = visibleCount [ uv ] ;
176
+ var count = visibleCount [ puv ] ;
178
177
if ( passiveVisibilityEnabled )
179
- count += passiveVisibleCount [ uv ] ;
178
+ count += passiveVisibleCount [ puv ] ;
180
179
181
180
type = count > 0 ? ShroudCellType . Visible : ShroudCellType . Fog ;
182
181
}
183
182
184
- var oldResolvedType = resolvedType [ uv ] ;
185
- resolvedType [ uv ] = type ;
183
+ var oldResolvedType = resolvedType [ puv ] ;
184
+ resolvedType [ puv ] = type ;
186
185
if ( type != oldResolvedType )
187
- OnShroudChanged ( ( PPos ) uv ) ;
186
+ OnShroudChanged ( puv ) ;
188
187
}
189
188
190
189
Hash = Sync . HashPlayer ( self . Owner ) + self . World . WorldTick ;
@@ -232,22 +231,21 @@ public void AddSource(object key, SourceType type, PPos[] projectedCells)
232
231
if ( ! map . Contains ( puv ) )
233
232
continue ;
234
233
235
- var uv = ( MPos ) puv ;
236
- touched [ uv ] = true ;
234
+ touched [ puv ] = true ;
237
235
switch ( type )
238
236
{
239
237
case SourceType . PassiveVisibility :
240
238
passiveVisibilityEnabled = true ;
241
- passiveVisibleCount [ uv ] ++ ;
242
- explored [ uv ] = true ;
239
+ passiveVisibleCount [ puv ] ++ ;
240
+ explored [ puv ] = true ;
243
241
break ;
244
242
case SourceType . Visibility :
245
- visibleCount [ uv ] ++ ;
246
- explored [ uv ] = true ;
243
+ visibleCount [ puv ] ++ ;
244
+ explored [ puv ] = true ;
247
245
break ;
248
246
case SourceType . Shroud :
249
247
shroudGenerationEnabled = true ;
250
- generatedShroudCount [ uv ] ++ ;
248
+ generatedShroudCount [ puv ] ++ ;
251
249
break ;
252
250
}
253
251
}
@@ -264,18 +262,17 @@ public void RemoveSource(object key)
264
262
// Cells outside the visible bounds don't increment visibleCount
265
263
if ( map . Contains ( puv ) )
266
264
{
267
- var uv = ( MPos ) puv ;
268
- touched [ uv ] = true ;
265
+ touched [ puv ] = true ;
269
266
switch ( state . Type )
270
267
{
271
268
case SourceType . PassiveVisibility :
272
- passiveVisibleCount [ uv ] -- ;
269
+ passiveVisibleCount [ puv ] -- ;
273
270
break ;
274
271
case SourceType . Visibility :
275
- visibleCount [ uv ] -- ;
272
+ visibleCount [ puv ] -- ;
276
273
break ;
277
274
case SourceType . Shroud :
278
- generatedShroudCount [ uv ] -- ;
275
+ generatedShroudCount [ puv ] -- ;
279
276
break ;
280
277
}
281
278
}
@@ -288,11 +285,10 @@ public void ExploreProjectedCells(World world, IEnumerable<PPos> cells)
288
285
{
289
286
foreach ( var puv in cells )
290
287
{
291
- var uv = ( MPos ) puv ;
292
- if ( map . Contains ( puv ) && ! explored [ uv ] )
288
+ if ( map . Contains ( puv ) && ! explored [ puv ] )
293
289
{
294
- touched [ uv ] = true ;
295
- explored [ uv ] = true ;
290
+ touched [ puv ] = true ;
291
+ explored [ puv ] = true ;
296
292
}
297
293
}
298
294
}
@@ -304,11 +300,10 @@ public void Explore(Shroud s)
304
300
305
301
foreach ( var puv in map . ProjectedCellBounds )
306
302
{
307
- var uv = ( MPos ) puv ;
308
- if ( ! explored [ uv ] && s . explored [ uv ] )
303
+ if ( ! explored [ puv ] && s . explored [ puv ] )
309
304
{
310
- touched [ uv ] = true ;
311
- explored [ uv ] = true ;
305
+ touched [ puv ] = true ;
306
+ explored [ puv ] = true ;
312
307
}
313
308
}
314
309
}
@@ -317,11 +312,10 @@ public void ExploreAll()
317
312
{
318
313
foreach ( var puv in map . ProjectedCellBounds )
319
314
{
320
- var uv = ( MPos ) puv ;
321
- if ( ! explored [ uv ] )
315
+ if ( ! explored [ puv ] )
322
316
{
323
- touched [ uv ] = true ;
324
- explored [ uv ] = true ;
317
+ touched [ puv ] = true ;
318
+ explored [ puv ] = true ;
325
319
}
326
320
}
327
321
}
@@ -330,9 +324,8 @@ public void ResetExploration()
330
324
{
331
325
foreach ( var puv in map . ProjectedCellBounds )
332
326
{
333
- var uv = ( MPos ) puv ;
334
- touched [ uv ] = true ;
335
- explored [ uv ] = ( visibleCount [ uv ] + passiveVisibleCount [ uv ] ) > 0 ;
327
+ touched [ puv ] = true ;
328
+ explored [ puv ] = ( visibleCount [ puv ] + passiveVisibleCount [ puv ] ) > 0 ;
336
329
}
337
330
}
338
331
@@ -363,8 +356,7 @@ public bool IsExplored(PPos puv)
363
356
if ( Disabled )
364
357
return map . Contains ( puv ) ;
365
358
366
- var uv = ( MPos ) puv ;
367
- return resolvedType . Contains ( uv ) && resolvedType [ uv ] > ShroudCellType . Shroud ;
359
+ return resolvedType . Contains ( puv ) && resolvedType [ puv ] > ShroudCellType . Shroud ;
368
360
}
369
361
370
362
public bool IsVisible ( WPos pos )
@@ -379,9 +371,6 @@ public bool IsVisible(CPos cell)
379
371
380
372
public bool IsVisible ( MPos uv )
381
373
{
382
- if ( ! resolvedType . Contains ( uv ) )
383
- return false ;
384
-
385
374
foreach ( var puv in map . ProjectedCellsCovering ( uv ) )
386
375
if ( IsVisible ( puv ) )
387
376
return true ;
@@ -395,15 +384,14 @@ public bool IsVisible(PPos puv)
395
384
if ( ! FogEnabled )
396
385
return map . Contains ( puv ) ;
397
386
398
- var uv = ( MPos ) puv ;
399
- return resolvedType . Contains ( uv ) && resolvedType [ uv ] == ShroudCellType . Visible ;
387
+ return resolvedType . Contains ( puv ) && resolvedType [ puv ] == ShroudCellType . Visible ;
400
388
}
401
389
402
390
public bool Contains ( PPos uv )
403
391
{
404
392
// Check that uv is inside the map area. There is nothing special
405
393
// about explored here: any of the CellLayers would have been suitable.
406
- return explored . Contains ( ( MPos ) uv ) ;
394
+ return explored . Contains ( uv ) ;
407
395
}
408
396
}
409
397
}
0 commit comments