AOS Fog of War
Loading...
Searching...
No Matches
FischlWorks_FogWar.Shadowcaster Class Reference

A non-static submodule that performs shadowcasting algorithm over a LevelData object. More...

Classes

class  FogField
 
class  LevelColumn
 

Public Member Functions

void Initialize (csFogWar fogWar)
 Initializes the shadowcaster module with properties from the dependant csFogWar object.
 
void ProcessLevelData (Vector2Int revealerPoint, int sightRange)
 Processes the level data with shadowcasting algorithm, and updates the FogField object accordingly.
 
void ResetTileVisibility ()
 Resets all tile's visibility info.
 

Properties

FogField fogField = new FogField() [get]
 

Detailed Description

A non-static submodule that performs shadowcasting algorithm over a LevelData object.

An instance of this module is instantiated for each construction of the csFogWar object.
While the LevelData class defined within csFogWar class holds the information about obstacles,
the FogField class defined within Shadowcaster class holds the information about player sight.

Member Function Documentation

◆ Initialize()

void FischlWorks_FogWar.Shadowcaster.Initialize ( csFogWar  fogWar)
inline

Initializes the shadowcaster module with properties from the dependant csFogWar object.

299 {
300 this.fogWar = fogWar;
301
302 for (int xIterator = 0; xIterator < fogWar.levelData.levelDimensionX; xIterator++)
303 {
304 // Adding a new list for column (y axis) for each unit in row (x axis)
305 fogField.AddColumn(new LevelColumn(
306 Enumerable.Repeat(LevelColumn.ETileVisibility.Hidden, fogWar.levelData.levelDimensionY)));
307 }
308
309 quadrantIterator = new QuadrantIterator(fogWar);
310 }
void AddColumn(LevelColumn levelColumn)
Definition: Shadowcaster.cs:45
FogField fogField
Definition: Shadowcaster.cs:290
int levelDimensionX
Definition: csFogWar.cs:77
int levelDimensionY
Definition: csFogWar.cs:78
LevelData levelData
Definition: csFogWar.cs:264

◆ ProcessLevelData()

void FischlWorks_FogWar.Shadowcaster.ProcessLevelData ( Vector2Int  revealerPoint,
int  sightRange 
)
inline

Processes the level data with shadowcasting algorithm, and updates the FogField object accordingly.

324 {
325 // Reveal the first tile where the revealer is at
326 RevealTile(fogWar.WorldToLevel(fogWar.GetWorldVector(revealerPoint)));
327
328 // Give the quadrant iterator the revealer's position
329 quadrantIterator.originPoint = revealerPoint;
330
331 // We deal with 90 degrees each, anti-clockwise, starting from east to west
332 foreach (int cardinal in System.Enum.GetValues(typeof(QuadrantIterator.ECardinal)))
333 {
334 quadrantIterator.cardinal = (QuadrantIterator.ECardinal)cardinal;
335
336 // Here goes the BFS algorithm, we queue a new pass during each pass if needed, then start the new one
337 Queue<ColumnIterator> columnIterators = new Queue<ColumnIterator>();
338
339 // The first pass of the given quadrant, start from slope -1 to slope 1
340 columnIterators.Enqueue(new ColumnIterator(1, sightRange, -1, 1));
341
342 while (columnIterators.Count > 0)
343 {
344 ColumnIterator columnIterator = columnIterators.Dequeue();
345
346 // Note that the given points may have negative y values instead of starting from zero
347 List<Vector2Int> quadrantPoints = columnIterator.GetTiles();
348
349 // This is to detect points where the obstacle tile and the empty tile are adjacent
350 Vector2Int lastQuadrantPoint = new Vector2Int();
351
352 // This is to skip the first pass where the lastQuadrantPoint variable is not assigned yet
353 bool firstStepFlag = true;
354
355 foreach (Vector2Int quadrantPoint in quadrantPoints)
356 {
357 if (IsTileObstacle(quadrantPoint) == true || IsTileVisible(columnIterator, quadrantPoint))
358 {
359 RevealTileIteratively(quadrantPoint, sightRange);
360 }
361
362 if (firstStepFlag == false)
363 {
364 if (IsTileObstacle(lastQuadrantPoint) == true && IsTileEmpty(quadrantPoint) == true)
365 {
366 columnIterator.startSlope = GetQuadrantSlope(quadrantPoint);
367 }
368
369 if (IsTileEmpty(lastQuadrantPoint) == true && IsTileObstacle(quadrantPoint) == true)
370 {
371 if (columnIterator.IsProceedable() == false)
372 {
373 continue;
374 }
375
376 ColumnIterator nextColumnIterator = new ColumnIterator(
377 columnIterator.depth,
378 sightRange,
379 columnIterator.startSlope,
380 GetQuadrantSlope(quadrantPoint));
381
382 nextColumnIterator.ProceedIfPossible();
383
384 columnIterators.Enqueue(nextColumnIterator);
385 }
386 }
387
388 lastQuadrantPoint = quadrantPoint;
389
390 firstStepFlag = false;
391 }
392
393 if (IsTileEmpty(lastQuadrantPoint) == true && columnIterator.IsProceedable() == true)
394 {
395 columnIterator.ProceedIfPossible();
396
397 columnIterators.Enqueue(columnIterator);
398 }
399 }
400 }
401 }
Vector3 GetWorldVector(Vector2Int worldCoordinates)
Converts level coordinates into world coordinates.
Definition: csFogWar.cs:716
Vector2Int WorldToLevel(Vector3 worldCoordinates)
Converts unit (divided by unitScale, then rounded) world coordinates to level coordinates.
Definition: csFogWar.cs:704

◆ ResetTileVisibility()

void FischlWorks_FogWar.Shadowcaster.ResetTileVisibility ( )
inline

Resets all tile's visibility info.

316 {
317 fogField.Reset();
318 }
void Reset()
Definition: Shadowcaster.cs:50

Property Documentation

◆ fogField

FogField FischlWorks_FogWar.Shadowcaster.fogField = new FogField()
get

The documentation for this class was generated from the following file: