Skip to content

Commit

Permalink
Add UI Lounge Page
Browse files Browse the repository at this point in the history
  • Loading branch information
DWVoid committed Feb 20, 2019
1 parent 8741f9c commit c1cedcd
Show file tree
Hide file tree
Showing 113 changed files with 1,530 additions and 299 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.otf filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
*.dds filter=lfs diff=lfs merge=lfs -text
16 changes: 8 additions & 8 deletions Core/ApplicationControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ namespace Core
{
public static class ApplicationControl
{
public class Launch
public static void DoLaunch()
{
AssemblyReflectiveScanner.UpdateDomainAssemblies();
EventBus.Broadcast(null, new Launch());
}

public class Shutdown
public static void DoShutdown()
{
EventBus.Broadcast(null, new Shutdown());
}

public static void DoLaunch()
public class Launch
{
AssemblyReflectiveScanner.UpdateDomainAssemblies();
EventBus.Broadcast(null, new Launch());
}

public static void DoShutdown()
public class Shutdown
{
EventBus.Broadcast(null, new Shutdown());
}
}
}
}
99 changes: 85 additions & 14 deletions Core/AssemblyReflectiveScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

// IMPORTANT NOTICE: The Design and Implementation of this Functionality Assumes that there is
// and will only be ONE AppDomain Throughout the Entire Instance of The Program.
// This decision is made for the lack of functionality of the .Net Core and .Net Standard on
// isolating and safety issues. All internal interfaces and implementations ARE SUBJECTED TO CHANGE
// in the future so DO NOT rely on them for any reason outside this assembly

using System;
using System.Collections.Generic;
using System.Reflection;
Expand All @@ -25,6 +31,19 @@ namespace Core
{
public sealed class DeclareNeWorldAssemblyAttribute : Attribute
{
internal readonly AssemblyScanPolicy Policy;

public DeclareNeWorldAssemblyAttribute(AssemblyScanPolicy policy = AssemblyScanPolicy.Default)
{
Policy = policy;
}
}

public enum AssemblyScanPolicy
{
PublicOnly,
All,
Default = PublicOnly
}

public sealed class DeclareAssemblyReflectiveScannerAttribute : Attribute
Expand All @@ -49,15 +68,22 @@ internal static void UpdateDomainAssemblies()
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoadServiceRegisterAgent;
var snapshot = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in snapshot)
{
if (!CheckIfAssemblyProcessed(assembly))
{
ScanAssembly(assembly);
}
}

lock (ProcessLock)
{
_processed = null;
lock (Scanned)
{
foreach (var assembly in Scanned) ProcessAssembly(assembly);
foreach (var assembly in Scanned)
{
ProcessNewAssembly(assembly);
}
}
}
}
Expand All @@ -66,7 +92,7 @@ private static bool CheckIfAssemblyProcessed(Assembly assembly)
{
lock (ProcessLock)
{
return _processed != null && (bool) (_processed?.Contains(assembly.GetName()));
return _processed != null && (bool) _processed?.Contains(assembly.GetName());
}
}

Expand All @@ -77,12 +103,17 @@ private static void OnAssemblyLoadServiceRegisterAgent(object sender, AssemblyLo

private static void ScanForAssemblyScanners(Assembly assembly)
{
foreach (var type in assembly.GetExportedTypes())
if (CheckScannerType(type))
var allowPrivate = GetAssemblyScanPolicy(assembly) == AssemblyScanPolicy.All;
foreach (var type in assembly.DefinedTypes)
{
if ((type.IsPublic || allowPrivate) && IsScannerType(type))
{
InitializeScanner(type);
}
}
}

private static bool CheckScannerType(Type type)
private static bool IsScannerType(Type type)
{
return type.IsDefined(typeof(DeclareAssemblyReflectiveScannerAttribute), false) &&
typeof(IAssemblyReflectiveScanner).IsAssignableFrom(type);
Expand All @@ -99,15 +130,38 @@ private static void InitializeScanner(Type type)
lock (ProcessLock)
{
if (_processed != null) return;
lock (Scanned)
ProcessPastAssemblies(currentScanner);
}
}

private static void ProcessPastAssemblies(IAssemblyReflectiveScanner currentScanner)
{
lock (Scanned)
{
foreach (var assembly in Scanned)
{
foreach (var assembly in Scanned)
foreach (var target in assembly.GetExportedTypes())
currentScanner.ProcessType(target);
ProcessPastAssembly(currentScanner, assembly);
}
}
}

private static void ProcessPastAssembly(IAssemblyReflectiveScanner currentScanner, Assembly assembly)
{
var allowPrivate = GetAssemblyScanPolicy(assembly) == AssemblyScanPolicy.All;
foreach (var target in assembly.DefinedTypes)
{
if (target.IsPublic || allowPrivate)
{
currentScanner.ProcessType(target);
}
}
}

private static AssemblyScanPolicy GetAssemblyScanPolicy(Assembly assembly)
{
return assembly.GetCustomAttribute<DeclareNeWorldAssemblyAttribute>().Policy;
}

private static void ScanAssembly(Assembly assembly)
{
lock (ProcessLock)
Expand All @@ -126,17 +180,34 @@ private static void ScanAssembly(Assembly assembly)

lock (ProcessLock)
{
if (_processed == null) ProcessAssembly(assembly);
if (_processed == null)
{
ProcessNewAssembly(assembly);
}
}
}

private static void ProcessAssembly(Assembly assembly)
private static void ProcessNewAssembly(Assembly assembly)
{
foreach (var target in assembly.GetExportedTypes())
lock (Scanners)
var allowPrivate = GetAssemblyScanPolicy(assembly) == AssemblyScanPolicy.All;
foreach (var target in assembly.DefinedTypes)
{
if (target.IsPublic || allowPrivate)
{
foreach (var currentScanner in Scanners) currentScanner.ProcessType(target);
ProcessNewAssemblyType(target);
}
}
}

private static void ProcessNewAssemblyType(Type target)
{
lock (Scanners)
{
foreach (var currentScanner in Scanners)
{
currentScanner.ProcessType(target);
}
}
}
}
}
8 changes: 3 additions & 5 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MessagePack" Version="1.7.3.4" />
<PackageReference Include="Xenko.Core" Version="3.1.0.1-beta01-0430" PrivateAssets="contentfiles;analyzers" />
<PackageReference Include="Xenko.Core.Mathematics" Version="3.1.0.1-beta01-0430" />
<PackageReference Include="Xenko.Core" Version="3.1.0.1-beta01-0441" PrivateAssets="contentfiles;analyzers" />
<PackageReference Include="Xenko.Core.Mathematics" Version="3.1.0.1-beta01-0441" />
</ItemGroup>
</Project>
</Project>
20 changes: 11 additions & 9 deletions Core/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ public static void Broadcast<T>(object sender, T payload)
slot?.Invoke(sender, payload);
}

[DeclareAssemblyReflectiveScanner]
private sealed class GlobalHandlerClassDetector : IAssemblyReflectiveScanner
{
public void ProcessType(Type type)
{
if (type.IsDefined(typeof(DeclareGlobalBusEventHandlerClassAttribute), false))
AddCollection(Activator.CreateInstance(type));
}
}

private interface ISlot
{
void Add(Delegate handler);
Expand Down Expand Up @@ -179,15 +189,7 @@ public void Invoke(object sender, T payload)
}
}

public sealed class DeclareGlobalBusEventHandlerClassAttribute : Attribute {}

[DeclareAssemblyReflectiveScanner]
public sealed class GlobalBusEventHandlerClassDetector : IAssemblyReflectiveScanner
public sealed class DeclareGlobalBusEventHandlerClassAttribute : Attribute
{
public void ProcessType(Type type)
{
if (type.IsDefined(typeof(DeclareGlobalBusEventHandlerClassAttribute), false))
EventBus.AddCollection(Activator.CreateInstance(type));
}
}
}
1 change: 1 addition & 0 deletions Core/Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

namespace Core
{
public static class Generic
Expand Down
1 change: 1 addition & 0 deletions Core/LogPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using Xenko.Core.Diagnostics;

Expand Down
3 changes: 2 additions & 1 deletion Core/Math/Mat4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using Xenko.Core.Mathematics;

namespace Core.Math
{
public struct Mat4D
{
private const double Pi = 3.1415926535897932f;
private const double Pi = System.Math.PI;

public double[] Data;

Expand Down
43 changes: 22 additions & 21 deletions Core/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,6 @@ public sealed class Modules : IAssemblyReflectiveScanner
private static readonly Dictionary<string, IModule> Loaded = new Dictionary<string, IModule>();

private static string _basePath = AppContext.BaseDirectory;

public static void SetBasePath(string path)
{
_basePath = path;
}

public static void Load(string moduleFile)
{
Assembly.Load(moduleFile);
}

[DeclareBusEventHandler]
public static void UnloadAll(object sender, ApplicationControl.Shutdown type)
{
lock (Loaded)
{
foreach (var module in Loaded)
module.Value.CoFinalize();
Loaded.Clear();
}
}

public void ProcessType(Type type)
{
Expand All @@ -74,12 +53,34 @@ public void ProcessType(Type type)
{
Loaded.Add(type.FullName ?? "", module);
}

LogPort.Debug($"Loaded Module : {type}");
}
catch (Exception e)
{
LogPort.Debug($"Module {type} Load Failure : {e}");
}
}

public static void SetBasePath(string path)
{
_basePath = path;
}

public static void Load(string moduleFile)
{
Assembly.Load(moduleFile);
}

[DeclareBusEventHandler]
public static void UnloadAll(object sender, ApplicationControl.Shutdown type)
{
lock (Loaded)
{
foreach (var module in Loaded)
module.Value.CoFinalize();
Loaded.Clear();
}
}
}
}
1 change: 1 addition & 0 deletions Core/Network/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;
using System.Net.Sockets;
Expand Down
1 change: 1 addition & 0 deletions Core/Network/ConnectionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down
1 change: 1 addition & 0 deletions Core/Network/Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

namespace Core.Network
{
public abstract class Protocol
Expand Down
1 change: 1 addition & 0 deletions Core/Network/Protocols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down
1 change: 1 addition & 0 deletions Core/Network/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with NEWorld. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
Expand Down
Loading

0 comments on commit c1cedcd

Please sign in to comment.