a very interesting change
This commit is contained in:
parent
f9a35ca7bb
commit
ebbb3ab2af
3 changed files with 72 additions and 102 deletions
68
Server/NativeReader.cs
Normal file
68
Server/NativeReader.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/***************************************************************************
|
||||
* NativeReader.cs
|
||||
* -------------------
|
||||
* begin : May 1, 2002
|
||||
* copyright : (C) The RunUO Software Team
|
||||
* email : info@runuo.com
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Server {
|
||||
public class NativeReader {
|
||||
|
||||
private static readonly INativeReader m_NativeReader;
|
||||
|
||||
static NativeReader() {
|
||||
if ( Core.Unix )
|
||||
m_NativeReader = new NativeReaderUnix();
|
||||
else
|
||||
m_NativeReader = new NativeReaderWin32();
|
||||
}
|
||||
|
||||
public static unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
m_NativeReader.Read( ptr, buffer, length );
|
||||
}
|
||||
}
|
||||
|
||||
public interface INativeReader {
|
||||
unsafe void Read( IntPtr ptr, void *buffer, int length );
|
||||
}
|
||||
|
||||
public sealed class NativeReaderWin32 : INativeReader {
|
||||
[DllImport( "kernel32" )]
|
||||
private unsafe static extern int _lread( IntPtr hFile, void *lpBuffer, int wBytes );
|
||||
|
||||
public NativeReaderWin32() {
|
||||
}
|
||||
|
||||
public unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
_lread( ptr, buffer, length );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class NativeReaderUnix : INativeReader {
|
||||
[DllImport( "libc" )]
|
||||
private unsafe static extern int read( IntPtr ptr, void *buffer, int length );
|
||||
|
||||
public NativeReaderUnix() {
|
||||
}
|
||||
|
||||
public unsafe void Read( IntPtr ptr, void *buffer, int length ) {
|
||||
read( ptr, buffer, length );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,11 +50,6 @@ namespace Server
|
|||
private int[][] m_StaticPatches;
|
||||
private int[][] m_LandPatches;
|
||||
|
||||
#if !MONO
|
||||
[DllImport( "Kernel32" )]
|
||||
private unsafe static extern int _lread( IntPtr hFile, void *lpBuffer, int wBytes );
|
||||
#endif
|
||||
|
||||
public Map Owner
|
||||
{
|
||||
get
|
||||
|
|
@ -376,10 +371,6 @@ namespace Server
|
|||
|
||||
private static TileList[][] m_Lists;
|
||||
|
||||
#if MONO
|
||||
private static byte[] m_Buffer;
|
||||
#endif
|
||||
|
||||
private static StaticTile[] m_TileBuffer = new StaticTile[128];
|
||||
|
||||
private unsafe Tile[][][] ReadStaticBlock( int x, int y )
|
||||
|
|
@ -408,27 +399,7 @@ namespace Server
|
|||
|
||||
fixed ( StaticTile *pTiles = staTiles )
|
||||
{
|
||||
#if !MONO
|
||||
_lread( m_Statics.SafeFileHandle.DangerousGetHandle(), pTiles, length );
|
||||
#else
|
||||
if ( m_Buffer == null || length > m_Buffer.Length )
|
||||
m_Buffer = new byte[length];
|
||||
|
||||
m_Statics.Read( m_Buffer, 0, length );
|
||||
|
||||
fixed ( byte *pbBuffer = m_Buffer )
|
||||
{
|
||||
StaticTile *pCopyBuffer = (StaticTile *)pbBuffer;
|
||||
StaticTile *pCopyEnd = pCopyBuffer + count;
|
||||
StaticTile *pCopyCur = pTiles;
|
||||
|
||||
while ( pCopyBuffer < pCopyEnd ) {
|
||||
*pCopyCur = *pCopyBuffer;
|
||||
pCopyCur = pCopyCur + 1;
|
||||
pCopyBuffer = pCopyBuffer + 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
NativeReader.Read( m_Statics.SafeFileHandle.DangerousGetHandle(), pTiles, length );
|
||||
|
||||
if ( m_Lists == null )
|
||||
{
|
||||
|
|
@ -498,27 +469,7 @@ namespace Server
|
|||
|
||||
fixed ( Tile *pTiles = tiles )
|
||||
{
|
||||
#if !MONO
|
||||
_lread( m_Map.SafeFileHandle.DangerousGetHandle(), pTiles, 192 );
|
||||
#else
|
||||
if ( m_Buffer == null || 192 > m_Buffer.Length )
|
||||
m_Buffer = new byte[192];
|
||||
|
||||
m_Map.Read( m_Buffer, 0, 192 );
|
||||
|
||||
fixed ( byte *pbBuffer = m_Buffer )
|
||||
{
|
||||
Tile *pBuffer = (Tile *)pbBuffer;
|
||||
Tile *pEnd = pBuffer + 64;
|
||||
Tile *pCur = pTiles;
|
||||
|
||||
while ( pBuffer < pEnd ) {
|
||||
*pCur = *pBuffer;
|
||||
pCur = pCur + 1;
|
||||
pBuffer = pBuffer + 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
NativeReader.Read( m_Map.SafeFileHandle.DangerousGetHandle(), pTiles, 192 );
|
||||
}
|
||||
|
||||
return tiles;
|
||||
|
|
|
|||
|
|
@ -42,11 +42,6 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
#if !MONO
|
||||
[DllImport( "Kernel32" )]
|
||||
private unsafe static extern int _lread( IntPtr hFile, void *lpBuffer, int wBytes );
|
||||
#endif
|
||||
|
||||
public int LandBlocks
|
||||
{
|
||||
get
|
||||
|
|
@ -104,27 +99,7 @@ namespace Server
|
|||
|
||||
fixed ( Tile *pTiles = tiles )
|
||||
{
|
||||
#if !MONO
|
||||
_lread( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192 );
|
||||
#else
|
||||
if ( m_Buffer == null || 192 > m_Buffer.Length )
|
||||
m_Buffer = new byte[192];
|
||||
|
||||
fsData.Read( m_Buffer, 0, 192 );
|
||||
|
||||
fixed ( byte *pbBuffer = m_Buffer )
|
||||
{
|
||||
Tile *pBuffer = (Tile *)pbBuffer;
|
||||
Tile *pEnd = pBuffer + 64;
|
||||
Tile *pCur = pTiles;
|
||||
|
||||
while ( pBuffer < pEnd ) {
|
||||
*pCur = *pBuffer;
|
||||
pCur = pCur + 1;
|
||||
pBuffer = pBuffer + 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
NativeReader.Read( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192 );
|
||||
}
|
||||
|
||||
matrix.SetLandBlock( x, y, tiles );
|
||||
|
|
@ -137,10 +112,6 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
#if MONO
|
||||
private static byte[] m_Buffer;
|
||||
#endif
|
||||
|
||||
private static StaticTile[] m_TileBuffer = new StaticTile[128];
|
||||
|
||||
private unsafe int PatchStatics( TileMatrix matrix, string dataPath, string indexPath, string lookupPath )
|
||||
|
|
@ -193,27 +164,7 @@ namespace Server
|
|||
|
||||
fixed ( StaticTile *pTiles = staTiles )
|
||||
{
|
||||
#if !MONO
|
||||
_lread( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, length );
|
||||
#else
|
||||
if ( m_Buffer == null || length > m_Buffer.Length )
|
||||
m_Buffer = new byte[length];
|
||||
|
||||
fsData.Read( m_Buffer, 0, length );
|
||||
|
||||
fixed ( byte *pbBuffer = m_Buffer )
|
||||
{
|
||||
StaticTile *pCopyBuffer = (StaticTile *)pbBuffer;
|
||||
StaticTile *pCopyEnd = pCopyBuffer + tileCount;
|
||||
StaticTile *pCopyCur = pTiles;
|
||||
|
||||
while ( pCopyBuffer < pCopyEnd ) {
|
||||
*pCopyCur = *pCopyBuffer;
|
||||
pCopyCur = pCopyCur + 1;
|
||||
pCopyBuffer = pCopyBuffer + 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
NativeReader.Read( fsData.SafeFileHandle.DangerousGetHandle(), pTiles, length );
|
||||
|
||||
StaticTile *pCur = pTiles, pEnd = pTiles + tileCount;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue