From 98db61a4a56c42c2129799cc213f4c5a85b35f86 Mon Sep 17 00:00:00 2001 From: Marc Hernandez Date: Thu, 4 Jul 2019 06:17:37 -0700 Subject: [PATCH] Resource Manager Major resource manager changes. Things now properly lazy load. There code for deferred loading, but its not currently active --- Config.cs | 37 +--- Conn.cs | 2 +- Imm.cs | 15 ++ Log.cs | 32 +++- SharpLib.csproj | 7 + packages.config | 4 + res/Resource.cs | 450 +++++++++++++++++++++++++++++++++--------------- 7 files changed, 374 insertions(+), 173 deletions(-) create mode 100644 Imm.cs create mode 100644 packages.config diff --git a/Config.cs b/Config.cs index 2a30b64..b23997c 100644 --- a/Config.cs +++ b/Config.cs @@ -17,29 +17,6 @@ public class DescAttribute : Attribute } - -[Serializable] -public class ResRefConfig : res.Ref where T: Config -{ - public ResRefConfig() - { - } - - public ResRefConfig( string filename, T cfg ) - : base( filename, cfg ) - { - } - - override public void OnDeserialize( object enclosing ) - { - base.OnDeserialize( enclosing ); - - var cfg = Config.load( filename ); - - res = cfg; - } -} - [Serializable] public class Config { @@ -52,20 +29,22 @@ public class Config static public void startup() { - res.Mgr.register( res_load ); - res.Mgr.registerSub( res_load ); + res.Mgr.register( load ); + res.Mgr.registerSub(typeof(Config)); } #region SaveLoad - static public ResRefConfig res_load( string filename ) + /* + static public res.Ref res_load( string filename ) { - return new ResRefConfig( filename, load( filename ) ); + return new res.Ref( filename, load( filename ) ); } + */ - static public ResRefConfig res_load( string filename ) where T : Config + static public T res_load( string filename ) where T : Config { - return new ResRefConfig( filename, load( filename ) ); + return load( filename ); } /* diff --git a/Conn.cs b/Conn.cs index 8c2ac3e..fafdc85 100644 --- a/Conn.cs +++ b/Conn.cs @@ -20,7 +20,7 @@ public interface IProcess - public class Conn +public class Conn { public Socket Sock { get { return m_socket; } } public Stream Stream { get { return m_streamNet; } } diff --git a/Imm.cs b/Imm.cs new file mode 100644 index 0000000..fe30cef --- /dev/null +++ b/Imm.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +// A spot for immutable helpers + +public static class imm +{ + + +} diff --git a/Log.cs b/Log.cs index d915707..fbce754 100644 --- a/Log.cs +++ b/Log.cs @@ -90,7 +90,7 @@ namespace lib s_log = null; } - static private Log s_log; + static public Log s_log; /* static public Log log @@ -103,37 +103,37 @@ namespace lib */ // Forwards. - static public void fatal( string msg, string cat = "unknown", object obj = null ) + static public void fatal( string msg, string cat = "unk", object obj = null ) { log(msg, LogType.Fatal, cat, obj); } - static public void error( string msg, string cat = "unknown", object obj = null ) + static public void error( string msg, string cat = "unk", object obj = null ) { log(msg, LogType.Error, cat, obj); } - static public void warn( string msg, string cat = "unknown", object obj = null ) + static public void warn( string msg, string cat = "unk", object obj = null ) { log( msg, LogType.Warn, cat, obj ); } - static public void info( string msg, string cat = "unknown", object obj = null ) + static public void info( string msg, string cat = "unk", object obj = null ) { log(msg, LogType.Info, cat, obj); } - static public void debug( string msg, string cat = "unknown", object obj = null ) + static public void debug( string msg, string cat = "unk", object obj = null ) { log(msg, LogType.Debug, cat, obj); } - static public void trace( string msg, string cat = "unknown", object obj = null ) + static public void trace( string msg, string cat = "unk", object obj = null ) { log(msg, LogType.Trace, cat, obj); } - static public void log( string msg, LogType type = LogType.Debug, string cat = "unknown", object obj = null ) + static public void log( string msg, LogType type = LogType.Debug, string cat = "unk", object obj = null ) { lock(s_log) { @@ -143,6 +143,22 @@ namespace lib } } + //This might seem a little odd, but the intent is that usually you wont need to set notExpectedValue. + static public void expected( T value, string falseString, string trueString = "", T notExpectedValue = default(T) ) + { + + var name = nameof(value); + + if( !value.Equals( notExpectedValue ) ) + { + lib.Log.info( $"Properly got {value}{trueString}" ); + } + else + { + lib.Log.warn( $"Got {notExpectedValue} instead of {value}{falseString}" ); + } + } + private Log( string filename ) { diff --git a/SharpLib.csproj b/SharpLib.csproj index 5911018..0de9e0c 100644 --- a/SharpLib.csproj +++ b/SharpLib.csproj @@ -44,6 +44,9 @@ + + ..\..\packages\System.Collections.Immutable.1.6.0-preview3.19128.7\lib\netstandard2.0\System.Collections.Immutable.dll + 3.5 @@ -67,6 +70,7 @@ + @@ -131,6 +135,9 @@ + + +