fix: Fixes file reading. (#958)

.NET 6 introduced a breaking change where lseek and sys-calls are not used for reading and file streams. This effectively broke out native reader. Since the file reading is fairly optimized, and honestly we don't need it to be "fast" in this case, I have removed the native reader.

https://devblogs.microsoft.com/dotnet/file-io-improvements-in-dotnet-6/
This commit is contained in:
Kamron Batman 2022-03-11 01:45:03 -08:00 committed by GitHub
parent bdee7bc671
commit 16c4268b54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 81 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Server
{
@ -63,10 +64,9 @@ namespace Server
fsData.Seek(4, SeekOrigin.Current);
var tiles = new LandTile[64];
fixed (LandTile* pTiles = tiles)
{
NativeReader.Read(fsData, pTiles, 192);
fsData.Read(new Span<byte>(pTiles, 192));
}
matrix.SetLandBlock(x, y, tiles);
@ -81,8 +81,8 @@ namespace Server
using var fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
using var fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
using var fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read);
var indexReader = new BinaryReader(fsIndex);
var lookupReader = new BinaryReader(fsLookup);
using var indexReader = new BinaryReader(fsIndex);
using var lookupReader = new BinaryReader(fsLookup);
var count = (int)(indexReader.BaseStream.Length / 4);
@ -127,7 +127,7 @@ namespace Server
fixed (StaticTile* pTiles = staTiles)
{
NativeReader.Read(fsData, pTiles, length);
fsData.Read(new Span<byte>(pTiles, length));
StaticTile* pCur = pTiles, pEnd = pTiles + tileCount;
@ -153,9 +153,6 @@ namespace Server
}
}
indexReader.Close();
lookupReader.Close();
return count;
}
}