Small fixers
This commit is contained in:
parent
4a845d002e
commit
be5e5d5bc4
@ -1,11 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>
|
||||
netcoreapp2.0;
|
||||
net462;
|
||||
netstandard2.0;
|
||||
</TargetFrameworks>
|
||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||
<RootNamespace>lib</RootNamespace>
|
||||
<AssemblyVersion>0.0.1.0</AssemblyVersion>
|
||||
<FileVersion>0.0.1.0</FileVersion>
|
||||
@ -17,9 +13,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0" />
|
||||
<PackageReference Include="Optional" Version="4.0.0" />
|
||||
<PackageReference Include="Optional.Async" Version="1.3.0" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="1.6.0" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -28,6 +28,15 @@ static public class log
|
||||
Fatal = 7,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum Endpoints
|
||||
{
|
||||
Invalid = 0,
|
||||
File = 1 << 0,
|
||||
Console = 1 << 1,
|
||||
}
|
||||
|
||||
|
||||
public struct LogEvent
|
||||
{
|
||||
public DateTime Time;
|
||||
@ -83,9 +92,10 @@ static public class log
|
||||
|
||||
|
||||
|
||||
static public void create( string filename )
|
||||
|
||||
static public void create( string filename, Endpoints endpoints )
|
||||
{
|
||||
startup( filename );
|
||||
startup( filename, endpoints );
|
||||
}
|
||||
|
||||
|
||||
@ -141,16 +151,16 @@ static public class log
|
||||
logBase( msg, LogType.Warn, path, line, member, cat, obj );
|
||||
}
|
||||
|
||||
static public void high(string msg, string cat = "", object obj = null, [CallerFilePath] string path = "", [CallerLineNumber] int line = -1, [CallerMemberName] string member = "")
|
||||
{
|
||||
logBase(msg, LogType.High, path, line, member, cat, obj);
|
||||
}
|
||||
|
||||
static public void info( string msg, string cat = "", object obj = null, [CallerFilePath] string path = "", [CallerLineNumber] int line = -1, [CallerMemberName] string member = "" )
|
||||
{
|
||||
logBase( msg, LogType.Info, path, line, member, cat, obj );
|
||||
}
|
||||
|
||||
static public void high( string msg, string cat = "", object obj = null, [CallerFilePath] string path = "", [CallerLineNumber] int line = -1, [CallerMemberName] string member = "" )
|
||||
{
|
||||
logBase( msg, LogType.High, path, line, member, cat, obj );
|
||||
}
|
||||
|
||||
static public void debug( string msg, string cat = "", object obj = null, [CallerFilePath] string path = "", [CallerLineNumber] int line = -1, [CallerMemberName] string member = "" )
|
||||
{
|
||||
logBase( msg, LogType.Debug, path, line, member, cat, obj );
|
||||
@ -232,7 +242,7 @@ static public class log
|
||||
}
|
||||
|
||||
|
||||
static void startup( string filename )
|
||||
static void startup( string filename, Endpoints endpoints )
|
||||
{
|
||||
var start = new ThreadStart( run );
|
||||
|
||||
@ -261,6 +271,13 @@ static public class log
|
||||
|
||||
//s_events.Enqueue( evt );
|
||||
|
||||
if( (endpoints & Endpoints.Console) == Endpoints.Console )
|
||||
{
|
||||
addDelegate(WriteToConsole);
|
||||
}
|
||||
|
||||
|
||||
|
||||
info( $"startup" );
|
||||
|
||||
}
|
||||
@ -406,6 +423,20 @@ static public class log
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteToConsole(LogEvent evt)
|
||||
{
|
||||
char sym = getSymbol(evt.LogType);
|
||||
|
||||
var truncatedCat = evt.Cat.Substring(0, Math.Min(8, evt.Cat.Length));
|
||||
|
||||
string finalLine = string.Format("{0,-8}{1}| {2}", truncatedCat, sym, evt.Msg);
|
||||
|
||||
Console.WriteLine(finalLine);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static Stream s_stream;
|
||||
private static StreamWriter s_writer;
|
||||
|
||||
|
||||
@ -806,11 +806,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -853,11 +853,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -918,11 +918,11 @@ namespace math
|
||||
public static void Transform(Double2[] source, ref Quaternion rotation, Double2[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
double x = rotation.X + rotation.X;
|
||||
double y = rotation.Y + rotation.Y;
|
||||
@ -985,11 +985,11 @@ namespace math
|
||||
public static void Transform(Double2[] source, ref Matrix transform, Double4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1060,11 +1060,11 @@ namespace math
|
||||
public static void TransformCoordinate(Double2[] source, ref Matrix transform, Double2[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1131,11 +1131,11 @@ namespace math
|
||||
public static void TransformNormal(Double2[] source, ref Matrix transform, Double2[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
|
||||
@ -977,11 +977,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1024,11 +1024,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1096,11 +1096,11 @@ namespace math
|
||||
public static void Transform(Double3[] source, ref Quaternion rotation, Double3[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
double x = rotation.X + rotation.X;
|
||||
double y = rotation.Y + rotation.Y;
|
||||
@ -1187,11 +1187,11 @@ namespace math
|
||||
public static void Transform(Double3[] source, ref Matrix transform, Double4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1260,11 +1260,11 @@ namespace math
|
||||
public static void TransformCoordinate(Double3[] source, ref Matrix transform, Double3[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1332,11 +1332,11 @@ namespace math
|
||||
public static void TransformNormal(Double3[] source, ref Matrix transform, Double3[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
|
||||
@ -878,11 +878,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -925,11 +925,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -998,11 +998,11 @@ namespace math
|
||||
public static void Transform(Double4[] source, ref Quaternion rotation, Double4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
double x = rotation.X + rotation.X;
|
||||
double y = rotation.Y + rotation.Y;
|
||||
@ -1077,11 +1077,11 @@ namespace math
|
||||
public static void Transform(Double4[] source, ref Matrix transform, Double4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
|
||||
@ -821,11 +821,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -868,11 +868,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -933,11 +933,11 @@ namespace math
|
||||
public static void Transform(Vec2[] source, ref Quaternion rotation, Vec2[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
float x = rotation.X + rotation.X;
|
||||
float y = rotation.Y + rotation.Y;
|
||||
@ -1000,11 +1000,11 @@ namespace math
|
||||
public static void Transform(Vec2[] source, ref Matrix transform, Vec4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1075,11 +1075,11 @@ namespace math
|
||||
public static void TransformCoordinate(Vec2[] source, ref Matrix transform, Vec2[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1146,11 +1146,11 @@ namespace math
|
||||
public static void TransformNormal(Vec2[] source, ref Matrix transform, Vec2[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
|
||||
@ -992,11 +992,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1039,11 +1039,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1111,11 +1111,11 @@ namespace math
|
||||
public static void Transform(Vec3[] source, ref Quaternion rotation, Vec3[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
float x = rotation.X + rotation.X;
|
||||
float y = rotation.Y + rotation.Y;
|
||||
@ -1202,11 +1202,11 @@ namespace math
|
||||
public static void Transform(Vec3[] source, ref Matrix transform, Vec4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1275,11 +1275,11 @@ namespace math
|
||||
public static void TransformCoordinate(Vec3[] source, ref Matrix transform, Vec3[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1347,11 +1347,11 @@ namespace math
|
||||
public static void TransformNormal(Vec3[] source, ref Matrix transform, Vec3[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
|
||||
@ -892,11 +892,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -939,11 +939,11 @@ namespace math
|
||||
//q5 = ...
|
||||
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
@ -1012,11 +1012,11 @@ namespace math
|
||||
public static void Transform(Vec4[] source, ref Quaternion rotation, Vec4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
float x = rotation.X + rotation.X;
|
||||
float y = rotation.Y + rotation.Y;
|
||||
@ -1091,11 +1091,11 @@ namespace math
|
||||
public static void Transform(Vec4[] source, ref Matrix transform, Vec4[] destination)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
throw new ArgumentNullException("_source");
|
||||
if (destination == null)
|
||||
throw new ArgumentNullException("destination");
|
||||
if (destination.Length < source.Length)
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the source array.");
|
||||
throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array.");
|
||||
|
||||
for (int i = 0; i < source.Length; ++i)
|
||||
{
|
||||
|
||||
305
scr/Script.cs
Normal file
305
scr/Script.cs
Normal file
@ -0,0 +1,305 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Emit;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
public class MemoryRefResolver : SourceReferenceResolver
|
||||
{
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override string NormalizePath(string path, string baseFilePath)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public override Stream OpenRead(string resolvedPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override SourceText ReadText(string resolvedPath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string ResolveReference(string path, string baseFilePath)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class scr
|
||||
{
|
||||
|
||||
|
||||
public static bool firstErrorSourceLogged = false;
|
||||
|
||||
private static class ReferencesCache
|
||||
{
|
||||
// create the list of references on first use, but if two threads both *start* making the list thats fine since we'll just use whichever wins.
|
||||
private static readonly Lazy<ImmutableArray<MetadataReference>> lazyReferences = new Lazy<ImmutableArray<MetadataReference>>(GetReferences, LazyThreadSafetyMode.PublicationOnly);
|
||||
|
||||
public static IReadOnlyList<MetadataReference> References => lazyReferences.Value;
|
||||
|
||||
private static ImmutableArray<MetadataReference> GetReferences()
|
||||
{
|
||||
var builder = ImmutableArray.CreateBuilder<MetadataReference>();
|
||||
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
foreach (var ass in assemblies)
|
||||
{
|
||||
if (ass != null && !ass.IsDynamic && ass.Location != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
builder.Add(MetadataReference.CreateFromFile(ass.Location));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
}
|
||||
|
||||
public static string CleanString(string dirty)
|
||||
{
|
||||
// TODO @@ Get a clean string implementation in
|
||||
return dirty; //return Newtonsoft.Json.JsonConvert.ToString(dirty);
|
||||
}
|
||||
|
||||
public static string PrettyName(Type type)
|
||||
{
|
||||
if (type.GetGenericArguments().Length == 0)
|
||||
{
|
||||
return type.FullName.Replace('+', '.');
|
||||
}
|
||||
var genericArguments = type.GetGenericArguments();
|
||||
var typeDef = type.FullName;
|
||||
|
||||
var indexOfTick = typeDef.IndexOf("`");
|
||||
|
||||
var unmangledOuterName = typeDef.Substring(0, typeDef.IndexOf('`')).Replace('+', '.');
|
||||
|
||||
var innerName = "";
|
||||
|
||||
//Check for inner class
|
||||
if (typeDef.ElementAt(indexOfTick + 2) != '[')
|
||||
{
|
||||
var indexOfOpenBracket = typeDef.IndexOf('[', indexOfTick);
|
||||
|
||||
innerName = typeDef.Substring(indexOfTick + 2, indexOfOpenBracket - (indexOfTick + 2)).Replace('+', '.');
|
||||
}
|
||||
|
||||
return unmangledOuterName + "<" + String.Join(",", genericArguments.Select(PrettyName)) + ">" + innerName;
|
||||
}
|
||||
|
||||
public static FieldInfo GetFieldInfo(Type t, string name)
|
||||
{
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
var fi = t.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
|
||||
if (fi != null)
|
||||
return fi;
|
||||
|
||||
if (t.BaseType != null)
|
||||
return GetFieldInfo(t.BaseType, name);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// From stack overflow
|
||||
static Lazy<ISet<Type>> typeSetLazy =
|
||||
new Lazy<ISet<Type>>(() => {
|
||||
var types = AppDomain
|
||||
.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.SelectMany(a => a.GetTypes()
|
||||
.Where(t => t.IsClass));
|
||||
var typesAndBaseTypes = types
|
||||
.Select(t => new { Type = t, t.BaseType })
|
||||
.ToList();
|
||||
var typesWithSubclasses = typesAndBaseTypes
|
||||
.Join(
|
||||
typesAndBaseTypes,
|
||||
t => t.Type,
|
||||
t => t.BaseType,
|
||||
(t1, t2) => t2.BaseType);
|
||||
var typesHs = new HashSet<Type>(types);
|
||||
typesHs.ExceptWith(typesWithSubclasses);
|
||||
return typesHs;
|
||||
});
|
||||
|
||||
static bool IsLeafType(this Type type)
|
||||
{
|
||||
return typeSetLazy.Value.Contains(type);
|
||||
}
|
||||
|
||||
static public string TypeToIdentifier(string typename)
|
||||
{
|
||||
return typename.Replace('<', '_').Replace('>', '_').Replace(',', '_').Replace(' ', '_').Replace('.', '_').Replace('+', '_').Replace('[', '_').Replace(']', '_').Replace('$', '_').Replace(':', '_');
|
||||
}
|
||||
|
||||
public static void LogDiagnosticErrorsAndWarnings(ImmutableArray<Diagnostic> diagnostics, string sourceFile)
|
||||
{
|
||||
foreach (Diagnostic diagnostic in diagnostics)
|
||||
{
|
||||
//if (diagnostic.Severity != DiagnosticSeverity.Hidden)
|
||||
{
|
||||
switch (diagnostic.Severity)
|
||||
{
|
||||
case DiagnosticSeverity.Error:
|
||||
{
|
||||
var msg = $"{sourceFile}({diagnostic.Location.GetLineSpan().StartLinePosition.Line + 1}): {diagnostic.GetMessage()}";
|
||||
System.Diagnostics.Debug.WriteLine(msg);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case DiagnosticSeverity.Warning:
|
||||
case DiagnosticSeverity.Info:
|
||||
{
|
||||
var msg = $"{sourceFile}({diagnostic.Location.GetLineSpan().StartLinePosition.Line + 1}): {diagnostic.GetMessage()}";
|
||||
System.Diagnostics.Debug.WriteLine(msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Compile(string dynamicScript, string uniquePath, Action<Assembly> onSuccess, Action<ImmutableArray<Diagnostic>> onFailure, Platform platform = Platform.X86)
|
||||
{
|
||||
string assemblyName = Path.GetRandomFileName();
|
||||
|
||||
var parseOptions = new CSharpParseOptions(documentationMode: DocumentationMode.Diagnose, kind: SourceCodeKind.Regular);
|
||||
|
||||
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(dynamicScript, parseOptions, uniquePath, encoding: System.Text.Encoding.UTF8);
|
||||
|
||||
var memRef = new MemoryRefResolver();
|
||||
|
||||
/*
|
||||
CSharpCompilation compilation = CSharpCompilation.Create(
|
||||
assemblyName,
|
||||
syntaxTrees: new[] { syntaxTree },
|
||||
references: ReferencesCache.References,
|
||||
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary,
|
||||
sourceReferenceResolver: memRef,
|
||||
optimizationLevel: OptimizationLevel.Debug,
|
||||
platform: platform));
|
||||
*/
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
using (var pdb = new MemoryStream())
|
||||
{
|
||||
var result = CompileAndEmit(assemblyName, new[] { syntaxTree }, ms, pdb, platform);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
if (onFailure == null)
|
||||
{
|
||||
LogDiagnosticErrorsAndWarnings(result.Diagnostics, "unknown");
|
||||
}
|
||||
else
|
||||
{
|
||||
onFailure(result.Diagnostics);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
foreach (Diagnostic diagnostic in result.Diagnostics)
|
||||
{
|
||||
//if (diagnostic.Severity != DiagnosticSeverity.Hidden)
|
||||
{
|
||||
if (diagnostic.Id == "CS1591") continue;
|
||||
|
||||
switch (diagnostic.Severity)
|
||||
{
|
||||
case DiagnosticSeverity.Error:
|
||||
{
|
||||
var msg = $"{source.file}({diagnostic.Location.GetLineSpan().StartLinePosition.Line + 1}): {diagnostic.GetMessage()}";
|
||||
log.Error(msg);
|
||||
System.Diagnostics.Debug.WriteLine(msg);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case DiagnosticSeverity.Warning:
|
||||
case DiagnosticSeverity.Info:
|
||||
{
|
||||
var msg = $"{source.file}({diagnostic.Location.GetLineSpan().StartLinePosition.Line + 1}): {diagnostic.GetMessage()}";
|
||||
log.Warn(msg);
|
||||
System.Diagnostics.Debug.WriteLine(msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
var assembly = Assembly.Load(ms.ToArray(), pdb.ToArray());
|
||||
|
||||
onSuccess(assembly);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static EmitResult CompileAndEmit(string assemblyName, SyntaxTree[] syntaxTrees, MemoryStream ms, MemoryStream pdb, Platform platform)
|
||||
{
|
||||
var memRef = new MemoryRefResolver();
|
||||
|
||||
CSharpCompilation compilation = CSharpCompilation.Create(
|
||||
assemblyName,
|
||||
syntaxTrees: syntaxTrees,
|
||||
references: ReferencesCache.References,
|
||||
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary,
|
||||
sourceReferenceResolver: memRef,
|
||||
optimizationLevel: OptimizationLevel.Debug,
|
||||
platform: platform,
|
||||
specificDiagnosticOptions: new Dictionary<string, ReportDiagnostic>
|
||||
{
|
||||
{ "CS1701", ReportDiagnostic.Suppress }
|
||||
}));
|
||||
|
||||
return compilation.Emit(ms, pdb);
|
||||
}
|
||||
|
||||
private static void AddIfFirst<TKey, TValue>(IDictionary<TKey, TValue> dict, TKey key, TValue value)
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
dict.Add(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,6 +91,14 @@ namespace lib
|
||||
//lib.log.info( "Deserialize END ( Stream stream ) {0} {1}", m_rndVal, m_alreadySerialized.Count );
|
||||
}
|
||||
|
||||
|
||||
public T Deserialize<T>(Stream stream)
|
||||
{
|
||||
//lib.log.info( "Deserialize( Stream stream ) {0} {1}", m_rndVal, m_alreadySerialized.Count );
|
||||
return (T)DeserializeKnownType(stream, typeof(T));
|
||||
//lib.log.info( "Deserialize END ( Stream stream ) {0} {1}", m_rndVal, m_alreadySerialized.Count );
|
||||
}
|
||||
|
||||
public object DeserializeKnownType( Stream stream, Type t )
|
||||
{
|
||||
//lib.log.info( "DeserializeKnownType( Stream stream, Type t ) {0} {1}", m_rndVal, m_alreadySerialized.Count );
|
||||
|
||||
Loading…
Reference in New Issue
Block a user