Add interface into Process (maybe?)
Ref updates
This commit is contained in:
parent
c9cbacb1c9
commit
bdf392cb36
13
imm/Imm.cs
13
imm/Imm.cs
@ -74,6 +74,19 @@ public interface Imm
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
);
|
||||
|
||||
public Imm Process( Imm next,
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0,
|
||||
[CallerArgumentExpression("next")]
|
||||
string dbgExp = default
|
||||
)
|
||||
{
|
||||
return next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
145
res/Resource.cs
145
res/Resource.cs
@ -9,6 +9,7 @@ using System.Collections.Immutable;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
|
||||
namespace res;
|
||||
@ -28,20 +29,31 @@ public class Ref : lib.I_Serialize
|
||||
|
||||
public string Filename =>path;
|
||||
|
||||
//For construction
|
||||
public Ref()
|
||||
{
|
||||
path = "{set_from_ref_default_cons}";
|
||||
if( s_verboseLogging ) log.info( $"Ref: {GetType().Name} {path}" );
|
||||
}
|
||||
|
||||
public Ref( string filename )
|
||||
public Ref( string filename = "{empty_filename}",
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
)
|
||||
{
|
||||
path = filename;
|
||||
if( s_verboseLogging ) log.info( $"Ref: {GetType().Name} {path}" );
|
||||
|
||||
_reason = reason;
|
||||
_dbgName = dbgName;
|
||||
_dbgPath = dbgPath;
|
||||
_dbgLine = dbgLine;
|
||||
}
|
||||
|
||||
virtual public object lookup() => default;
|
||||
virtual public object lookup(
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
|
||||
) => default;
|
||||
|
||||
|
||||
virtual public void OnChange()
|
||||
{
|
||||
@ -53,6 +65,14 @@ public class Ref : lib.I_Serialize
|
||||
}
|
||||
|
||||
private string path = "{set_from_inline_cons}";
|
||||
|
||||
protected string _reason = "";
|
||||
protected string _dbgName = "";
|
||||
protected string _dbgPath = "";
|
||||
protected int _dbgLine = 0;
|
||||
protected string _dbgExp = "";
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@ -61,32 +81,55 @@ public class Ref<T> : Ref where T : class
|
||||
{
|
||||
public T? res => m_res != null ? m_res : lookup();
|
||||
|
||||
|
||||
/*
|
||||
override public T? lookup()
|
||||
{
|
||||
m_res = Mgr.load<T>( Filename );
|
||||
if( s_verboseLogging ) log.info( $"Ref.lookup {GetType().Name} {GetType().GenericTypeArguments[0]} path {Filename}" );
|
||||
return m_res;
|
||||
}
|
||||
*/
|
||||
|
||||
override public T? lookup(
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
|
||||
)
|
||||
{
|
||||
m_res = Mgr.load<T>( Filename, $"Ref lookup", dbgName, dbgPath, dbgLine );
|
||||
if( s_verboseLogging ) log.info( $"Ref.lookup {GetType().Name} {GetType().GenericTypeArguments[0]} path {Filename}" );
|
||||
return m_res;
|
||||
}
|
||||
|
||||
//For serialization
|
||||
/*
|
||||
public Ref()
|
||||
:
|
||||
base( "{set_from_ref<>_default_cons}" )
|
||||
{
|
||||
if( s_verboseLogging ) log.info( $"Ref {GetType().Name} {GetType().GenericTypeArguments[0]} path {Filename}" );
|
||||
}
|
||||
*/
|
||||
|
||||
public Ref( string filename )
|
||||
|
||||
public Ref( string filename = "",
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
)
|
||||
:
|
||||
base( filename )
|
||||
base( !string.IsNullOrWhiteSpace(filename) ? filename : $"{{{dbgName}_{log.whatFile(dbgPath)}}}" , reason, dbgName, dbgPath, dbgLine )
|
||||
{
|
||||
if( s_verboseLogging ) log.info( $"Ref {GetType().Name} {GetType().GenericTypeArguments[0]} path {Filename}" );
|
||||
}
|
||||
|
||||
|
||||
override internal void load()
|
||||
{
|
||||
m_res = Mgr.load<T>( Filename );
|
||||
m_res = Mgr.load<T>( Filename, _reason, _dbgName, _dbgPath, _dbgLine, _dbgExp );
|
||||
if( s_verboseLogging ) log.info( $"Ref.load {GetType().Name} {GetType().GenericTypeArguments[0]} path {Filename}" );
|
||||
}
|
||||
|
||||
@ -95,7 +138,12 @@ public class Ref<T> : Ref where T : class
|
||||
return enclosing;
|
||||
}
|
||||
|
||||
static public Ref<T> createAsset( T v, string path )
|
||||
static public Ref<T> createAsset( T v, string path,
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
)
|
||||
{
|
||||
if( File.Exists( path ) )
|
||||
{
|
||||
@ -108,7 +156,14 @@ public class Ref<T> : Ref where T : class
|
||||
log.warn( $"For {typeof(T).Name}, renamed to {newPath}" );
|
||||
}
|
||||
|
||||
var newRef = new Ref<T>( path );
|
||||
var createReason = $"Type {v.GetType().Name}";
|
||||
|
||||
if( v is imm.Imm imm )
|
||||
{
|
||||
createReason = $"{imm?.Meta}";
|
||||
}
|
||||
|
||||
var newRef = new Ref<T>( path, $"createAsset {createReason} bcs {reason}", dbgName, dbgPath, dbgLine );
|
||||
|
||||
return newRef;
|
||||
}
|
||||
@ -116,11 +171,15 @@ public class Ref<T> : Ref where T : class
|
||||
[NonSerialized]
|
||||
protected T m_res;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public class RefMemory<T> : Ref<T> where T : class
|
||||
{
|
||||
|
||||
//For serialization
|
||||
public RefMemory( T res )
|
||||
:
|
||||
@ -132,9 +191,8 @@ public class RefMemory<T> : Ref<T> where T : class
|
||||
override internal void load()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@ -251,14 +309,26 @@ public class Mgr
|
||||
}
|
||||
|
||||
|
||||
static public Ref<T> lookup<T>( string filename ) where T : class
|
||||
static public Ref<T> lookup<T>( string filename,
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
) where T : class
|
||||
{
|
||||
return new Ref<T>( filename );
|
||||
return new Ref<T>( filename, reason, dbgName, dbgPath, dbgLine );
|
||||
}
|
||||
|
||||
static public Ref lookup( string filename, Type t )
|
||||
/*
|
||||
|
||||
static public Ref lookup( string filename, Type t,
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0
|
||||
)
|
||||
{
|
||||
return new Ref( filename );
|
||||
return new Ref( filename, reason, dbgName, dbgPath, dbgLine );
|
||||
}
|
||||
|
||||
// @@@ TODO Pass information through here
|
||||
@ -281,6 +351,39 @@ public class Mgr
|
||||
|
||||
return newV;
|
||||
}
|
||||
*/
|
||||
|
||||
static public T? load<T>( string filename,
|
||||
string reason = "",
|
||||
[CallerMemberName] string dbgName = "",
|
||||
[CallerFilePath] string dbgPath = "",
|
||||
[CallerLineNumber] int dbgLine = 0,
|
||||
[CallerArgumentExpression("fn")]
|
||||
string dbgExp = default
|
||||
) where T : class
|
||||
{
|
||||
if( ResCache<T>.s_cache.TryGetValue( filename, out var holder ) )
|
||||
{
|
||||
|
||||
if( holder.weak.TryGetTarget( out var v ) )
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
log.info( $"{filename} was in cache, but its been dropped, reloading." );
|
||||
}
|
||||
|
||||
log.warn( $"Block Loading {filename}." );
|
||||
|
||||
var newV = actualLoad<T>( filename );
|
||||
|
||||
if( newV is imm.Imm imm )
|
||||
{
|
||||
newV = (T)imm.Record( $"Loading because {reason}", dbgName, dbgPath, dbgLine );
|
||||
}
|
||||
|
||||
return newV;
|
||||
}
|
||||
|
||||
static public T actualLoad<T>( string filename ) where T : class
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user