RegionLoader: added utility function generateSectorMap()

this proved very useful while debugging some internal issues.
This commit is contained in:
Dylan K. Taylor 2020-06-15 13:48:17 +01:00
parent 627a7c951a
commit 63b14a083c

View File

@ -46,6 +46,7 @@ use function max;
use function ord;
use function pack;
use function str_pad;
use function str_repeat;
use function stream_set_read_buffer;
use function stream_set_write_buffer;
use function strlen;
@ -381,6 +382,28 @@ class RegionLoader{
$this->nextSector = max($this->nextSector, $entry->getLastSector() + 1);
}
public function generateSectorMap(string $usedChar, string $freeChar) : string{
$result = str_repeat($freeChar, $this->nextSector);
for($i = 0; $i < self::FIRST_SECTOR; ++$i){
$result[$i] = $usedChar;
}
foreach($this->locationTable as $locationTableEntry){
if($locationTableEntry === null){
continue;
}
foreach($locationTableEntry->getUsedSectors() as $sectorIndex){
if($sectorIndex >= strlen($result)){
throw new AssumptionFailedError("This should never happen...");
}
if($result[$sectorIndex] === $usedChar){
throw new AssumptionFailedError("Overlap detected");
}
$result[$sectorIndex] = $usedChar;
}
}
return $result;
}
public function getX() : int{
return $this->x;
}