-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
DeveMazeGeneratorCore/InnerMaps/BitArreintjeFastChunkedInnerMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using DeveMazeGeneratorCore.InnerMaps.InnerStuff; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace DeveMazeGeneratorCore.InnerMaps | ||
{ | ||
public class BitArreintjeFastChunkedInnerMap : InnerMap | ||
{ | ||
private BitArreintjeFastInnerMapArray[] _innerData; | ||
|
||
public const int ChunkSize = 8; | ||
private int _chunksPerRow; | ||
|
||
public BitArreintjeFastChunkedInnerMap(int width, int height) | ||
: base(width, height) | ||
{ | ||
_chunksPerRow = width / ChunkSize; | ||
var chunkCount = _chunksPerRow * (height / ChunkSize); | ||
|
||
_innerData = new BitArreintjeFastInnerMapArray[chunkCount]; | ||
for (int i = 0; i < chunkCount; i++) | ||
{ | ||
_innerData[i] = new BitArreintjeFastInnerMapArray(ChunkSize * ChunkSize); | ||
} | ||
} | ||
|
||
public override void FillMap(bool state) | ||
{ | ||
for (int i = 0; i < _innerData.Length; i++) | ||
{ | ||
_innerData[i].FillMap(state); | ||
} | ||
} | ||
|
||
public override InnerMap Clone() | ||
{ | ||
var innerMapTarget = new BitArreintjeFastChunkedInnerMap(Width, Height); | ||
for (int i = 0; i < _innerData.Length; i++) | ||
{ | ||
innerMapTarget._innerData[i] = _innerData[i].Clone(); | ||
} | ||
return innerMapTarget; | ||
} | ||
|
||
public override bool this[int x, int y] | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
get | ||
{ | ||
int chunkX = x / ChunkSize; | ||
int chunkY = y / ChunkSize; | ||
|
||
var chunkNumber = chunkY * _chunksPerRow + chunkX; | ||
|
||
int localX = x % ChunkSize; | ||
int localY = y % ChunkSize; | ||
|
||
var positionInChunk = localY * ChunkSize + localX; | ||
|
||
|
||
return _innerData[chunkNumber][positionInChunk]; | ||
} | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
set | ||
{ | ||
int chunkX = x / ChunkSize; | ||
int chunkY = y / ChunkSize; | ||
|
||
var chunkNumber = chunkY * _chunksPerRow + chunkX; | ||
|
||
int localX = x % ChunkSize; | ||
int localY = y % ChunkSize; | ||
|
||
var positionInChunk = localY * ChunkSize + localX; | ||
|
||
_innerData[chunkNumber][positionInChunk] = value; | ||
} | ||
} | ||
} | ||
} |