tilematrix thread-safety
main waithandle timeout removed basecreature typo
This commit is contained in:
parent
b3831721d9
commit
855b6463ca
5 changed files with 83 additions and 53 deletions
|
|
@ -5648,7 +5648,7 @@ namespace Server.Mobiles
|
||||||
return base.CanBeDamaged();
|
return base.CanBeDamaged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool PlayerRangeSensitive{ get{ return (this.CurrentWayPoint != null); } } //If they are following a waypoint, they'll continue to follow it even if players aren't around
|
public virtual bool PlayerRangeSensitive{ get{ return (this.CurrentWayPoint == null); } } //If they are following a waypoint, they'll continue to follow it even if players aren't around
|
||||||
|
|
||||||
/* until we are sure about who should be getting deleted, move them instead */
|
/* until we are sure about who should be getting deleted, move them instead */
|
||||||
/* On OSI, they despawn */
|
/* On OSI, they despawn */
|
||||||
|
|
|
||||||
|
|
@ -575,13 +575,12 @@ namespace Server
|
||||||
|
|
||||||
const int sampleInterval = 100;
|
const int sampleInterval = 100;
|
||||||
const float ticksPerSecond = (float)(1000 * sampleInterval);
|
const float ticksPerSecond = (float)(1000 * sampleInterval);
|
||||||
TimeSpan _oneMS = TimeSpan.FromMilliseconds( 1 );
|
|
||||||
|
|
||||||
long sample = 0;
|
long sample = 0;
|
||||||
|
|
||||||
while( !m_Closing )
|
while( !m_Closing )
|
||||||
{
|
{
|
||||||
m_Signal.WaitOne( _oneMS );
|
m_Signal.WaitOne();
|
||||||
|
|
||||||
Mobile.ProcessDeltaQueue();
|
Mobile.ProcessDeltaQueue();
|
||||||
Item.ProcessDeltaQueue();
|
Item.ProcessDeltaQueue();
|
||||||
|
|
|
||||||
|
|
@ -933,12 +933,15 @@ namespace Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object tileLock = new object();
|
||||||
|
|
||||||
public TileMatrix Tiles
|
public TileMatrix Tiles
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ( m_Tiles == null )
|
lock (tileLock)
|
||||||
m_Tiles = new TileMatrix( this, m_FileIndex, m_MapID, m_Width, m_Height );
|
if ( m_Tiles == null )
|
||||||
|
m_Tiles = new TileMatrix( this, m_FileIndex, m_MapID, m_Width, m_Height );
|
||||||
|
|
||||||
return m_Tiles;
|
return m_Tiles;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Server
|
namespace Server
|
||||||
{
|
{
|
||||||
|
|
@ -51,13 +52,13 @@ namespace Server
|
||||||
private int[][] m_StaticPatches;
|
private int[][] m_StaticPatches;
|
||||||
private int[][] m_LandPatches;
|
private int[][] m_LandPatches;
|
||||||
|
|
||||||
public Map Owner
|
/*public Map Owner
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return m_Owner;
|
return m_Owner;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public TileMatrixPatch Patch
|
public TileMatrixPatch Patch
|
||||||
{
|
{
|
||||||
|
|
@ -83,7 +84,7 @@ namespace Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Width
|
/*public int Width
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -97,7 +98,7 @@ namespace Server
|
||||||
{
|
{
|
||||||
return m_Height;
|
return m_Height;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public FileStream MapStream
|
public FileStream MapStream
|
||||||
{
|
{
|
||||||
|
|
@ -105,10 +106,10 @@ namespace Server
|
||||||
set{ m_Map = value; }
|
set{ m_Map = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MapUOPPacked
|
/*public bool MapUOPPacked
|
||||||
{
|
{
|
||||||
get{ return ( m_MapIndex != null ); }
|
get{ return ( m_MapIndex != null ); }
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public FileStream IndexStream
|
public FileStream IndexStream
|
||||||
{
|
{
|
||||||
|
|
@ -138,18 +139,25 @@ namespace Server
|
||||||
|
|
||||||
public TileMatrix( Map owner, int fileIndex, int mapID, int width, int height )
|
public TileMatrix( Map owner, int fileIndex, int mapID, int width, int height )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < m_Instances.Count; ++i )
|
lock (m_Instances) {
|
||||||
{
|
for ( int i = 0; i < m_Instances.Count; ++i )
|
||||||
TileMatrix tm = m_Instances[i];
|
|
||||||
|
|
||||||
if ( tm.m_FileIndex == fileIndex )
|
|
||||||
{
|
{
|
||||||
tm.m_FileShare.Add( this );
|
TileMatrix tm = m_Instances[i];
|
||||||
m_FileShare.Add( tm );
|
|
||||||
|
if ( tm.m_FileIndex == fileIndex )
|
||||||
|
{
|
||||||
|
lock (m_FileShare) {
|
||||||
|
lock (tm.m_FileShare) {
|
||||||
|
tm.m_FileShare.Add( this );
|
||||||
|
m_FileShare.Add( tm );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_Instances.Add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Instances.Add( this );
|
|
||||||
m_FileIndex = fileIndex;
|
m_FileIndex = fileIndex;
|
||||||
m_Width = width;
|
m_Width = width;
|
||||||
m_Height = height;
|
m_Height = height;
|
||||||
|
|
@ -219,6 +227,7 @@ namespace Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
public void SetStaticBlock( int x, int y, StaticTile[][][] value )
|
public void SetStaticBlock( int x, int y, StaticTile[][][] value )
|
||||||
{
|
{
|
||||||
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight )
|
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight )
|
||||||
|
|
@ -235,6 +244,7 @@ namespace Server
|
||||||
m_StaticPatches[x][y >> 5] |= 1 << (y & 0x1F);
|
m_StaticPatches[x][y >> 5] |= 1 << (y & 0x1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
public StaticTile[][][] GetStaticBlock( int x, int y )
|
public StaticTile[][][] GetStaticBlock( int x, int y )
|
||||||
{
|
{
|
||||||
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Statics == null || m_Index == null )
|
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Statics == null || m_Index == null )
|
||||||
|
|
@ -247,23 +257,27 @@ namespace Server
|
||||||
|
|
||||||
if ( tiles == null )
|
if ( tiles == null )
|
||||||
{
|
{
|
||||||
for ( int i = 0; tiles == null && i < m_FileShare.Count; ++i )
|
lock (m_FileShare) {
|
||||||
{
|
for ( int i = 0; tiles == null && i < m_FileShare.Count; ++i )
|
||||||
TileMatrix shared = m_FileShare[i];
|
|
||||||
|
|
||||||
if ( x >= 0 && x < shared.m_BlockWidth && y >= 0 && y < shared.m_BlockHeight )
|
|
||||||
{
|
{
|
||||||
StaticTile[][][][] theirTiles = shared.m_StaticTiles[x];
|
TileMatrix shared = m_FileShare[i];
|
||||||
|
|
||||||
if ( theirTiles != null )
|
lock (shared) {
|
||||||
tiles = theirTiles[y];
|
if ( x >= 0 && x < shared.m_BlockWidth && y >= 0 && y < shared.m_BlockHeight )
|
||||||
|
{
|
||||||
|
StaticTile[][][][] theirTiles = shared.m_StaticTiles[x];
|
||||||
|
|
||||||
if ( tiles != null )
|
if ( theirTiles != null )
|
||||||
{
|
tiles = theirTiles[y];
|
||||||
int[] theirBits = shared.m_StaticPatches[x];
|
|
||||||
|
|
||||||
if ( theirBits != null && (theirBits[y >> 5] & (1 << (y & 0x1F))) != 0 )
|
if ( tiles != null )
|
||||||
tiles = null;
|
{
|
||||||
|
int[] theirBits = shared.m_StaticPatches[x];
|
||||||
|
|
||||||
|
if ( theirBits != null && (theirBits[y >> 5] & (1 << (y & 0x1F))) != 0 )
|
||||||
|
tiles = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -284,8 +298,9 @@ namespace Server
|
||||||
return tiles[x & 0x7][y & 0x7];
|
return tiles[x & 0x7][y & 0x7];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TileList m_TilesList = new TileList();
|
private TileList m_TilesList = new TileList();
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
public StaticTile[] GetStaticTiles( int x, int y, bool multis )
|
public StaticTile[] GetStaticTiles( int x, int y, bool multis )
|
||||||
{
|
{
|
||||||
StaticTile[][][] tiles = GetStaticBlock( x >> 3, y >> 3 );
|
StaticTile[][][] tiles = GetStaticBlock( x >> 3, y >> 3 );
|
||||||
|
|
@ -322,6 +337,7 @@ namespace Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
public void SetLandBlock( int x, int y, LandTile[] value )
|
public void SetLandBlock( int x, int y, LandTile[] value )
|
||||||
{
|
{
|
||||||
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight )
|
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight )
|
||||||
|
|
@ -338,6 +354,7 @@ namespace Server
|
||||||
m_LandPatches[x][y >> 5] |= 1 << (y & 0x1F);
|
m_LandPatches[x][y >> 5] |= 1 << (y & 0x1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
public LandTile[] GetLandBlock( int x, int y )
|
public LandTile[] GetLandBlock( int x, int y )
|
||||||
{
|
{
|
||||||
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Map == null )
|
if ( x < 0 || y < 0 || x >= m_BlockWidth || y >= m_BlockHeight || m_Map == null )
|
||||||
|
|
@ -350,23 +367,27 @@ namespace Server
|
||||||
|
|
||||||
if ( tiles == null )
|
if ( tiles == null )
|
||||||
{
|
{
|
||||||
for ( int i = 0; tiles == null && i < m_FileShare.Count; ++i )
|
lock (m_FileShare) {
|
||||||
{
|
for ( int i = 0; tiles == null && i < m_FileShare.Count; ++i )
|
||||||
TileMatrix shared = m_FileShare[i];
|
|
||||||
|
|
||||||
if ( x >= 0 && x < shared.m_BlockWidth && y >= 0 && y < shared.m_BlockHeight )
|
|
||||||
{
|
{
|
||||||
LandTile[][] theirTiles = shared.m_LandTiles[x];
|
TileMatrix shared = m_FileShare[i];
|
||||||
|
|
||||||
if ( theirTiles != null )
|
lock (shared) {
|
||||||
tiles = theirTiles[y];
|
if ( x >= 0 && x < shared.m_BlockWidth && y >= 0 && y < shared.m_BlockHeight )
|
||||||
|
{
|
||||||
|
LandTile[][] theirTiles = shared.m_LandTiles[x];
|
||||||
|
|
||||||
if ( tiles != null )
|
if ( theirTiles != null )
|
||||||
{
|
tiles = theirTiles[y];
|
||||||
int[] theirBits = shared.m_LandPatches[x];
|
|
||||||
|
|
||||||
if ( theirBits != null && (theirBits[y >> 5] & (1 << (y & 0x1F))) != 0 )
|
if ( tiles != null )
|
||||||
tiles = null;
|
{
|
||||||
|
int[] theirBits = shared.m_LandPatches[x];
|
||||||
|
|
||||||
|
if ( theirBits != null && (theirBits[y >> 5] & (1 << (y & 0x1F))) != 0 )
|
||||||
|
tiles = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -387,10 +408,11 @@ namespace Server
|
||||||
return tiles[((y & 0x7) << 3) + (x & 0x7)];
|
return tiles[((y & 0x7) << 3) + (x & 0x7)];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TileList[][] m_Lists;
|
private TileList[][] m_Lists;
|
||||||
|
|
||||||
private static StaticTile[] m_TileBuffer = new StaticTile[128];
|
private StaticTile[] m_TileBuffer = new StaticTile[128];
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
private unsafe StaticTile[][][] ReadStaticBlock( int x, int y )
|
private unsafe StaticTile[][][] ReadStaticBlock( int x, int y )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -480,6 +502,7 @@ namespace Server
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
private unsafe LandTile[] ReadLandBlock( int x, int y )
|
private unsafe LandTile[] ReadLandBlock( int x, int y )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -531,7 +554,7 @@ namespace Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Runtime.InteropServices.StructLayout( System.Runtime.InteropServices.LayoutKind.Sequential, Pack=1 )]
|
[StructLayout(LayoutKind.Sequential, Pack=1)]
|
||||||
public struct LandTile
|
public struct LandTile
|
||||||
{
|
{
|
||||||
internal short m_ID;
|
internal short m_ID;
|
||||||
|
|
@ -572,7 +595,7 @@ namespace Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Runtime.InteropServices.StructLayout( System.Runtime.InteropServices.LayoutKind.Sequential, Pack=1 )]
|
[StructLayout(LayoutKind.Sequential, Pack=1)]
|
||||||
public struct StaticTile
|
public struct StaticTile
|
||||||
{
|
{
|
||||||
internal ushort m_ID;
|
internal ushort m_ID;
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Server
|
namespace Server
|
||||||
{
|
{
|
||||||
|
|
@ -46,7 +47,8 @@ namespace Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return m_LandBlocks;
|
lock (this)
|
||||||
|
return m_LandBlocks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,7 +56,8 @@ namespace Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return m_StaticBlocks;
|
lock (this)
|
||||||
|
return m_StaticBlocks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,6 +80,7 @@ namespace Server
|
||||||
m_StaticBlocks = PatchStatics( matrix, staDataPath, staIndexPath, staLookupPath );
|
m_StaticBlocks = PatchStatics( matrix, staDataPath, staIndexPath, staLookupPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
private unsafe int PatchLand( TileMatrix matrix, string dataPath, string indexPath )
|
private unsafe int PatchLand( TileMatrix matrix, string dataPath, string indexPath )
|
||||||
{
|
{
|
||||||
using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
||||||
|
|
@ -116,8 +120,9 @@ namespace Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StaticTile[] m_TileBuffer = new StaticTile[128];
|
private StaticTile[] m_TileBuffer = new StaticTile[128];
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||||
private unsafe int PatchStatics( TileMatrix matrix, string dataPath, string indexPath, string lookupPath )
|
private unsafe int PatchStatics( TileMatrix matrix, string dataPath, string indexPath, string lookupPath )
|
||||||
{
|
{
|
||||||
using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
using ( FileStream fsData = new FileStream( dataPath, FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue