+ Make sure #Map_NewEnumerables is defined by default, multiple sources have verified stability.
+ Core housekeeping, converted some for-loops to foreach-loops. + Reimplementation of Core.TickCount using only native .NET Stopwatch. * Stopwatch actually wraps the QueryPerformanceCounter method to get its result and can also be used to determine whether HRT is supported. - Removed SafeNativeMethods DLLImport for QueryPerformanceCounter. + Added Core.GlobalUpdateRange to define a constant standard range used in many calculations throughout RunUO. * The value '18' in a range context is hard-coded in many places, this new property will eventually be used to replace those usages.
This commit is contained in:
parent
75c9c79a48
commit
d093acfb2e
2 changed files with 209 additions and 229 deletions
438
Server/Main.cs
438
Server/Main.cs
|
|
@ -22,16 +22,12 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Server;
|
|
||||||
using Server.Accounting;
|
|
||||||
using Server.Gumps;
|
|
||||||
using Server.Network;
|
using Server.Network;
|
||||||
using System.Runtime;
|
using System.Runtime;
|
||||||
|
|
||||||
|
|
@ -45,7 +41,9 @@ namespace Server
|
||||||
private static Thread timerThread;
|
private static Thread timerThread;
|
||||||
private static string m_BaseDirectory;
|
private static string m_BaseDirectory;
|
||||||
private static string m_ExePath;
|
private static string m_ExePath;
|
||||||
private static List<string> m_DataDirectories = new List<string>();
|
|
||||||
|
private static readonly List<string> m_DataDirectories = new List<string>();
|
||||||
|
|
||||||
private static Assembly m_Assembly;
|
private static Assembly m_Assembly;
|
||||||
private static Process m_Process;
|
private static Process m_Process;
|
||||||
private static Thread m_Thread;
|
private static Thread m_Thread;
|
||||||
|
|
@ -127,35 +125,26 @@ namespace Server
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static readonly bool _HighRes = Stopwatch.IsHighResolution;
|
private static readonly bool _HighRes = Stopwatch.IsHighResolution;
|
||||||
private static readonly double _Frequency = 1000.0 / Stopwatch.Frequency;
|
|
||||||
|
private static readonly double _HighFrequency = 1000.0 / Stopwatch.Frequency;
|
||||||
|
private static readonly double _LowFrequency = 1000.0 / TimeSpan.TicksPerSecond;
|
||||||
|
|
||||||
private static bool _UseHRT;
|
private static bool _UseHRT;
|
||||||
|
|
||||||
public static bool UsingHighResolutionTiming { get { return _UseHRT && _HighRes && !m_Unix; } }
|
public static bool UsingHighResolutionTiming { get { return _UseHRT && _HighRes && !Unix; } }
|
||||||
|
|
||||||
public static long TickCount {
|
public static long TickCount { get { return (long)Ticks; } }
|
||||||
get {
|
|
||||||
#if !MONO
|
public static double Ticks
|
||||||
if (_UseHRT && _HighRes)
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_UseHRT && _HighRes && !Unix)
|
||||||
{
|
{
|
||||||
long t = 0;
|
return Stopwatch.GetTimestamp() * _HighFrequency;
|
||||||
SafeNativeMethods.QueryPerformanceCounter(out t);
|
|
||||||
return (long)((double)t * _Frequency);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
|
||||||
return (long)((double)DateTime.UtcNow.Ticks * 0.0001);
|
|
||||||
|
|
||||||
/* We don't really need this, but it may be useful in the future.
|
return DateTime.UtcNow.Ticks * _LowFrequency;
|
||||||
uint t = (uint)Environment.TickCount;
|
|
||||||
|
|
||||||
if (_LastTickCount.Value > t) // Wrapped
|
|
||||||
_HighOrder.Value += 0x100000000;
|
|
||||||
|
|
||||||
_LastTickCount.Value = t;
|
|
||||||
|
|
||||||
return _HighOrder.Value | _LastTickCount.Value;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,9 +167,9 @@ namespace Server
|
||||||
|
|
||||||
string fullPath = null;
|
string fullPath = null;
|
||||||
|
|
||||||
for( int i = 0; i < m_DataDirectories.Count; ++i )
|
foreach (string p in m_DataDirectories)
|
||||||
{
|
{
|
||||||
fullPath = Path.Combine( m_DataDirectories[i], path );
|
fullPath = Path.Combine( p, path );
|
||||||
|
|
||||||
if( File.Exists( fullPath ) )
|
if( File.Exists( fullPath ) )
|
||||||
break;
|
break;
|
||||||
|
|
@ -254,16 +243,7 @@ namespace Server
|
||||||
|
|
||||||
public static string ExePath
|
public static string ExePath
|
||||||
{
|
{
|
||||||
get
|
get { return m_ExePath ?? (m_ExePath = Assembly.Location); }
|
||||||
{
|
|
||||||
if( m_ExePath == null )
|
|
||||||
{
|
|
||||||
m_ExePath = Assembly.Location;
|
|
||||||
//m_ExePath = Process.GetCurrentProcess().MainModule.FileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_ExePath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string BaseDirectory
|
public static string BaseDirectory
|
||||||
|
|
@ -316,9 +296,9 @@ namespace Server
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for( int i = 0; i < m_MessagePump.Listeners.Length; i++ )
|
foreach (Listener l in m_MessagePump.Listeners)
|
||||||
{
|
{
|
||||||
m_MessagePump.Listeners[i].Dispose();
|
l.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
@ -345,11 +325,6 @@ namespace Server
|
||||||
internal delegate bool ConsoleEventHandler( ConsoleEventType type );
|
internal delegate bool ConsoleEventHandler( ConsoleEventType type );
|
||||||
internal static ConsoleEventHandler m_ConsoleEventHandler;
|
internal static ConsoleEventHandler m_ConsoleEventHandler;
|
||||||
|
|
||||||
internal class SafeNativeMethods {
|
|
||||||
[DllImport("kernel32")]
|
|
||||||
internal static extern bool QueryPerformanceCounter(out long value);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class UnsafeNativeMethods {
|
internal class UnsafeNativeMethods {
|
||||||
[DllImport("Kernel32")]
|
[DllImport("Kernel32")]
|
||||||
internal static extern bool SetConsoleCtrlHandler(ConsoleEventHandler callback, bool add);
|
internal static extern bool SetConsoleCtrlHandler(ConsoleEventHandler callback, bool add);
|
||||||
|
|
@ -373,30 +348,12 @@ namespace Server
|
||||||
private static bool m_Closing;
|
private static bool m_Closing;
|
||||||
public static bool Closing { get { return m_Closing; } }
|
public static bool Closing { get { return m_Closing; } }
|
||||||
|
|
||||||
private static long m_CycleIndex = 1;
|
private static int m_CycleIndex = 1;
|
||||||
private static float[] m_CyclesPerSecond = new float[100];
|
private static readonly float[] m_CyclesPerSecond = new float[100];
|
||||||
|
|
||||||
public static float CyclesPerSecond
|
public static float CyclesPerSecond { get { return m_CyclesPerSecond[(m_CycleIndex - 1) % m_CyclesPerSecond.Length]; } }
|
||||||
{
|
|
||||||
get { return m_CyclesPerSecond[(m_CycleIndex - 1) % m_CyclesPerSecond.Length]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float AverageCPS
|
public static float AverageCPS { get { return m_CyclesPerSecond.Take(m_CycleIndex).Average(); } }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
float t = 0.0f;
|
|
||||||
int c = 0;
|
|
||||||
|
|
||||||
for( int i = 0; i < m_CycleIndex && i < m_CyclesPerSecond.Length; ++i )
|
|
||||||
{
|
|
||||||
t += m_CyclesPerSecond[i];
|
|
||||||
++c;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (t / Math.Max( c, 1 ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Kill()
|
public static void Kill()
|
||||||
{
|
{
|
||||||
|
|
@ -432,29 +389,30 @@ namespace Server
|
||||||
Console.WriteLine( "done" );
|
Console.WriteLine( "done" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AutoResetEvent m_Signal = new AutoResetEvent( true );
|
private static readonly AutoResetEvent m_Signal = new AutoResetEvent( true );
|
||||||
|
|
||||||
public static void Set() { m_Signal.Set(); }
|
public static void Set() { m_Signal.Set(); }
|
||||||
|
|
||||||
public static void Main( string[] args )
|
public static void Main( string[] args )
|
||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( CurrentDomain_UnhandledException );
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||||
AppDomain.CurrentDomain.ProcessExit += new EventHandler( CurrentDomain_ProcessExit );
|
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
|
||||||
|
|
||||||
for( int i = 0; i < args.Length; ++i )
|
foreach (string a in args)
|
||||||
{
|
{
|
||||||
if ( Insensitive.Equals( args[i], "-debug" ) )
|
if ( Insensitive.Equals( a, "-debug" ) )
|
||||||
m_Debug = true;
|
m_Debug = true;
|
||||||
else if ( Insensitive.Equals( args[i], "-service" ) )
|
else if ( Insensitive.Equals( a, "-service" ) )
|
||||||
m_Service = true;
|
m_Service = true;
|
||||||
else if ( Insensitive.Equals( args[i], "-profile" ) )
|
else if ( Insensitive.Equals( a, "-profile" ) )
|
||||||
Profiling = true;
|
Profiling = true;
|
||||||
else if ( Insensitive.Equals( args[i], "-nocache" ) )
|
else if ( Insensitive.Equals( a, "-nocache" ) )
|
||||||
m_Cache = false;
|
m_Cache = false;
|
||||||
else if ( Insensitive.Equals( args[i], "-haltonwarning" ) )
|
else if ( Insensitive.Equals( a, "-haltonwarning" ) )
|
||||||
m_HaltOnWarning = true;
|
m_HaltOnWarning = true;
|
||||||
else if ( Insensitive.Equals( args[i], "-vb" ) )
|
else if ( Insensitive.Equals( a, "-vb" ) )
|
||||||
m_VBdotNET = true;
|
m_VBdotNET = true;
|
||||||
else if (Insensitive.Equals(args[i], "-usehrt"))
|
else if ( Insensitive.Equals( a, "-usehrt" ) )
|
||||||
_UseHRT = true;
|
_UseHRT = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -487,8 +445,10 @@ namespace Server
|
||||||
Directory.SetCurrentDirectory( BaseDirectory );
|
Directory.SetCurrentDirectory( BaseDirectory );
|
||||||
|
|
||||||
Timer.TimerThread ttObj = new Timer.TimerThread();
|
Timer.TimerThread ttObj = new Timer.TimerThread();
|
||||||
timerThread = new Thread( new ThreadStart( ttObj.TimerMain ) );
|
timerThread = new Thread(ttObj.TimerMain)
|
||||||
timerThread.Name = "Timer Thread";
|
{
|
||||||
|
Name = "Timer Thread"
|
||||||
|
};
|
||||||
|
|
||||||
Version ver = m_Assembly.GetName().Version;
|
Version ver = m_Assembly.GetName().Version;
|
||||||
|
|
||||||
|
|
@ -515,7 +475,7 @@ namespace Server
|
||||||
Console.WriteLine( "Core: Unix environment detected" );
|
Console.WriteLine( "Core: Unix environment detected" );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_ConsoleEventHandler = new ConsoleEventHandler( OnConsoleEvent );
|
m_ConsoleEventHandler = OnConsoleEvent;
|
||||||
UnsafeNativeMethods.SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
|
UnsafeNativeMethods.SetConsoleCtrlHandler( m_ConsoleEventHandler, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -551,8 +511,8 @@ namespace Server
|
||||||
|
|
||||||
timerThread.Start();
|
timerThread.Start();
|
||||||
|
|
||||||
for( int i = 0; i < Map.AllMaps.Count; ++i )
|
foreach (Map m in Map.AllMaps)
|
||||||
Map.AllMaps[i].Tiles.Force();
|
m.Tiles.Force();
|
||||||
|
|
||||||
NetState.Initialize();
|
NetState.Initialize();
|
||||||
|
|
||||||
|
|
@ -563,7 +523,7 @@ namespace Server
|
||||||
long now, last = TickCount;
|
long now, last = TickCount;
|
||||||
|
|
||||||
const int sampleInterval = 100;
|
const int sampleInterval = 100;
|
||||||
const float ticksPerSecond = (float)(1000 * sampleInterval);
|
const float ticksPerSecond = 1000.0f * sampleInterval;
|
||||||
|
|
||||||
long sample = 0;
|
long sample = 0;
|
||||||
|
|
||||||
|
|
@ -583,13 +543,14 @@ namespace Server
|
||||||
if( Slice != null )
|
if( Slice != null )
|
||||||
Slice();
|
Slice();
|
||||||
|
|
||||||
if( (++sample % sampleInterval) == 0 )
|
if (sample++ % sampleInterval != 0)
|
||||||
{
|
{
|
||||||
now = TickCount;
|
continue;
|
||||||
m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] =
|
|
||||||
ticksPerSecond / (now - last);
|
|
||||||
last = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now = TickCount;
|
||||||
|
m_CyclesPerSecond[m_CycleIndex++ % m_CyclesPerSecond.Length] = ticksPerSecond / (now - last);
|
||||||
|
last = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
|
|
@ -604,13 +565,13 @@ namespace Server
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
if( Core.Debug )
|
if( m_Debug )
|
||||||
Utility.Separate( sb, "-debug", " " );
|
Utility.Separate( sb, "-debug", " " );
|
||||||
|
|
||||||
if( Core.Service )
|
if( m_Service )
|
||||||
Utility.Separate( sb, "-service", " " );
|
Utility.Separate( sb, "-service", " " );
|
||||||
|
|
||||||
if( Core.Profiling )
|
if( m_Profiling )
|
||||||
Utility.Separate( sb, "-profile", " " );
|
Utility.Separate( sb, "-profile", " " );
|
||||||
|
|
||||||
if( !m_Cache )
|
if( !m_Cache )
|
||||||
|
|
@ -622,10 +583,21 @@ namespace Server
|
||||||
if ( m_VBdotNET )
|
if ( m_VBdotNET )
|
||||||
Utility.Separate( sb, "-vb", " " );
|
Utility.Separate( sb, "-vb", " " );
|
||||||
|
|
||||||
|
if ( _UseHRT )
|
||||||
|
Utility.Separate( sb, "-usehrt", " " );
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int m_GlobalUpdateRange = 18;
|
||||||
|
|
||||||
|
public static int GlobalUpdateRange
|
||||||
|
{
|
||||||
|
get { return m_GlobalUpdateRange; }
|
||||||
|
set { m_GlobalUpdateRange = value; }
|
||||||
|
}
|
||||||
|
|
||||||
private static int m_GlobalMaxUpdateRange = 24;
|
private static int m_GlobalMaxUpdateRange = 24;
|
||||||
|
|
||||||
public static int GlobalMaxUpdateRange
|
public static int GlobalMaxUpdateRange
|
||||||
|
|
@ -644,205 +616,213 @@ namespace Server
|
||||||
m_ItemCount = 0;
|
m_ItemCount = 0;
|
||||||
m_MobileCount = 0;
|
m_MobileCount = 0;
|
||||||
|
|
||||||
VerifySerialization( Assembly.GetCallingAssembly() );
|
var ca = Assembly.GetCallingAssembly();
|
||||||
|
|
||||||
for( int a = 0; a < ScriptCompiler.Assemblies.Length; ++a )
|
VerifySerialization(ca);
|
||||||
VerifySerialization( ScriptCompiler.Assemblies[a] );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly Type[] m_SerialTypeArray = new Type[1] { typeof(Serial) };
|
foreach (var a in ScriptCompiler.Assemblies.Where(a => a != ca))
|
||||||
|
|
||||||
private static void VerifyType( Type t )
|
|
||||||
{
|
|
||||||
bool isItem = t.IsSubclassOf(typeof(Item));
|
|
||||||
|
|
||||||
if (isItem || t.IsSubclassOf(typeof(Mobile)))
|
|
||||||
{
|
{
|
||||||
if (isItem)
|
VerifySerialization(a);
|
||||||
{
|
|
||||||
//++m_ItemCount;
|
|
||||||
Interlocked.Increment(ref m_ItemCount);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//++m_MobileCount;
|
|
||||||
Interlocked.Increment(ref m_MobileCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder warningSb = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
if( isItem && t.IsPublic && !t.IsAbstract )
|
|
||||||
{
|
|
||||||
ConstructorInfo cInfo = t.GetConstructor( Type.EmptyTypes );
|
|
||||||
|
|
||||||
if( cInfo == null )
|
|
||||||
{
|
|
||||||
if (warningSb == null)
|
|
||||||
warningSb = new StringBuilder();
|
|
||||||
|
|
||||||
warningSb.AppendLine(" - No zero paramater constructor");
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (t.GetConstructor(m_SerialTypeArray) == null)
|
|
||||||
{
|
|
||||||
if (warningSb == null)
|
|
||||||
warningSb = new StringBuilder();
|
|
||||||
|
|
||||||
warningSb.AppendLine(" - No serialization constructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.GetMethod("Serialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null)
|
|
||||||
{
|
|
||||||
if (warningSb == null)
|
|
||||||
warningSb = new StringBuilder();
|
|
||||||
|
|
||||||
warningSb.AppendLine(" - No Serialize() method");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t.GetMethod("Deserialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null)
|
|
||||||
{
|
|
||||||
if (warningSb == null)
|
|
||||||
warningSb = new StringBuilder();
|
|
||||||
|
|
||||||
warningSb.AppendLine(" - No Deserialize() method");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warningSb != null && warningSb.Length > 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Warning: {0}\n{1}", t, warningSb.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
Console.WriteLine("Warning: Exception in serialization verification of type {0}", t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void VerifySerialization( Assembly a )
|
private static readonly Type[] m_SerialTypeArray = { typeof(Serial) };
|
||||||
{
|
|
||||||
if( a == null )
|
|
||||||
return;
|
|
||||||
|
|
||||||
Parallel.ForEach(a.GetTypes(), t =>
|
private static void VerifyType(Type t)
|
||||||
|
{
|
||||||
|
var isItem = t.IsSubclassOf(typeof(Item));
|
||||||
|
|
||||||
|
if (!isItem && !t.IsSubclassOf(typeof(Mobile)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isItem)
|
||||||
|
{
|
||||||
|
//++_ItemCount;
|
||||||
|
Interlocked.Increment(ref m_ItemCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//++_MobileCount;
|
||||||
|
Interlocked.Increment(ref m_MobileCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder warningSb = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (t.GetConstructor(m_SerialTypeArray) == null)
|
||||||
{
|
{
|
||||||
VerifyType(t);
|
warningSb = new StringBuilder();
|
||||||
});
|
|
||||||
|
warningSb.AppendLine(" - No serialization constructor");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
t.GetMethod(
|
||||||
|
"Serialize",
|
||||||
|
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null)
|
||||||
|
{
|
||||||
|
if (warningSb == null)
|
||||||
|
{
|
||||||
|
warningSb = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
warningSb.AppendLine(" - No Serialize() method");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
t.GetMethod(
|
||||||
|
"Deserialize",
|
||||||
|
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null)
|
||||||
|
{
|
||||||
|
if (warningSb == null)
|
||||||
|
{
|
||||||
|
warningSb = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
warningSb.AppendLine(" - No Deserialize() method");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warningSb != null && warningSb.Length > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Warning: {0}\n{1}", t, warningSb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Console.WriteLine("Warning: Exception in serialization verification of type {0}", t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void VerifySerialization(Assembly a)
|
||||||
|
{
|
||||||
|
if (a != null)
|
||||||
|
{
|
||||||
|
Parallel.ForEach(a.GetTypes(), VerifyType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FileLogger : TextWriter
|
public class FileLogger : TextWriter
|
||||||
{
|
{
|
||||||
private string m_FileName;
|
|
||||||
private bool m_NewLine;
|
|
||||||
public const string DateFormat = "[MMMM dd hh:mm:ss.f tt]: ";
|
public const string DateFormat = "[MMMM dd hh:mm:ss.f tt]: ";
|
||||||
|
|
||||||
public string FileName { get { return m_FileName; } }
|
private bool _NewLine;
|
||||||
|
|
||||||
public FileLogger( string file )
|
public string FileName { get; private set; }
|
||||||
: this( file, false )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileLogger( string file, bool append )
|
public FileLogger(string file)
|
||||||
|
: this(file, false)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public FileLogger(string file, bool append)
|
||||||
{
|
{
|
||||||
m_FileName = file;
|
FileName = file;
|
||||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read ) ) )
|
|
||||||
|
using (
|
||||||
|
var writer =
|
||||||
|
new StreamWriter(
|
||||||
|
new FileStream(FileName, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read)))
|
||||||
{
|
{
|
||||||
writer.WriteLine( ">>>Logging started on {0}.", DateTime.UtcNow.ToString( "f" ) ); //f = Tuesday, April 10, 2001 3:51 PM
|
writer.WriteLine(">>>Logging started on {0}.", DateTime.UtcNow.ToString("f"));
|
||||||
|
//f = Tuesday, April 10, 2001 3:51 PM
|
||||||
}
|
}
|
||||||
m_NewLine = true;
|
|
||||||
|
_NewLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Write( char ch )
|
public override void Write(char ch)
|
||||||
{
|
{
|
||||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
using (var writer = new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read)))
|
||||||
{
|
{
|
||||||
if( m_NewLine )
|
if (_NewLine)
|
||||||
{
|
{
|
||||||
writer.Write( DateTime.UtcNow.ToString( DateFormat ) );
|
writer.Write(DateTime.UtcNow.ToString(DateFormat));
|
||||||
m_NewLine = false;
|
_NewLine = false;
|
||||||
}
|
}
|
||||||
writer.Write( ch );
|
|
||||||
|
writer.Write(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Write( string str )
|
public override void Write(string str)
|
||||||
{
|
{
|
||||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
using (var writer = new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read)))
|
||||||
{
|
{
|
||||||
if( m_NewLine )
|
if (_NewLine)
|
||||||
{
|
{
|
||||||
writer.Write( DateTime.UtcNow.ToString( DateFormat ) );
|
writer.Write(DateTime.UtcNow.ToString(DateFormat));
|
||||||
m_NewLine = false;
|
_NewLine = false;
|
||||||
}
|
}
|
||||||
writer.Write( str );
|
|
||||||
|
writer.Write(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteLine( string line )
|
public override void WriteLine(string line)
|
||||||
{
|
{
|
||||||
using( StreamWriter writer = new StreamWriter( new FileStream( m_FileName, FileMode.Append, FileAccess.Write, FileShare.Read ) ) )
|
using (var writer = new StreamWriter(new FileStream(FileName, FileMode.Append, FileAccess.Write, FileShare.Read)))
|
||||||
{
|
{
|
||||||
if( m_NewLine )
|
if (_NewLine)
|
||||||
writer.Write( DateTime.UtcNow.ToString( DateFormat ) );
|
{
|
||||||
writer.WriteLine( line );
|
writer.Write(DateTime.UtcNow.ToString(DateFormat));
|
||||||
m_NewLine = true;
|
}
|
||||||
|
|
||||||
|
writer.WriteLine(line);
|
||||||
|
_NewLine = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override System.Text.Encoding Encoding
|
public override Encoding Encoding { get { return Encoding.Default; } }
|
||||||
{
|
|
||||||
get { return System.Text.Encoding.Default; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MultiTextWriter : TextWriter
|
public class MultiTextWriter : TextWriter
|
||||||
{
|
{
|
||||||
private List<TextWriter> m_Streams;
|
private readonly List<TextWriter> _Streams;
|
||||||
|
|
||||||
public MultiTextWriter( params TextWriter[] streams )
|
public MultiTextWriter(params TextWriter[] streams)
|
||||||
{
|
{
|
||||||
m_Streams = new List<TextWriter>( streams );
|
_Streams = new List<TextWriter>(streams);
|
||||||
|
|
||||||
if( m_Streams.Count < 0 )
|
if (_Streams.Count < 0)
|
||||||
throw new ArgumentException( "You must specify at least one stream." );
|
{
|
||||||
|
throw new ArgumentException("You must specify at least one stream.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add( TextWriter tw )
|
public void Add(TextWriter tw)
|
||||||
{
|
{
|
||||||
m_Streams.Add( tw );
|
_Streams.Add(tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove( TextWriter tw )
|
public void Remove(TextWriter tw)
|
||||||
{
|
{
|
||||||
m_Streams.Remove( tw );
|
_Streams.Remove(tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Write( char ch )
|
public override void Write(char ch)
|
||||||
{
|
{
|
||||||
for( int i = 0; i < m_Streams.Count; i++ )
|
foreach (var t in _Streams)
|
||||||
m_Streams[i].Write( ch );
|
{
|
||||||
|
t.Write(ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteLine( string line )
|
public override void WriteLine(string line)
|
||||||
{
|
{
|
||||||
for( int i = 0; i < m_Streams.Count; i++ )
|
foreach (var t in _Streams)
|
||||||
m_Streams[i].WriteLine( line );
|
{
|
||||||
|
t.WriteLine(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteLine( string line, params object[] args )
|
public override void WriteLine(string line, params object[] args)
|
||||||
{
|
{
|
||||||
WriteLine( String.Format( line, args ) );
|
WriteLine(String.Format(line, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Encoding Encoding
|
public override Encoding Encoding { get { return Encoding.Default; } }
|
||||||
{
|
|
||||||
get { return Encoding.Default; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +61,7 @@
|
||||||
* This update generally increases performance and reduces overall player
|
* This update generally increases performance and reduces overall player
|
||||||
* connection latency.
|
* connection latency.
|
||||||
*/
|
*/
|
||||||
//#define Map_NewEnumerables
|
#define Map_NewEnumerables
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* UseMaxRange
|
* UseMaxRange
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue