Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
.idea/
*/bin
*/obj
.vs/
packages/
/bin/Debug
/Modules/Main/obj/Debug
*.user
*.lock
*.lock.json
.vs/
_ReSharper*
*.suo
*.VC.db
*.vshost.exe
*.manifest
*.sdf
[Bb]in/
obj/
*/[Bb]in/
*/[Oo]bj/
Cache/
43 changes: 43 additions & 0 deletions Core/ApplicationControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// NEWorld/Core: ApplicationControl.cs
// NEWorld: A Free Game with Similar Rules to Minecraft.
// Copyright (C) 2015-2019 NEWorld Team
//
// NEWorld is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// NEWorld is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
// Public License for more details.
//
// 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 ApplicationControl
{
public class Launch
{
}

public class Shutdown
{
}

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

public static void DoShutdown()
{
EventBus.Broadcast(null, new Shutdown());
}
}
}
142 changes: 142 additions & 0 deletions Core/AssemblyReflectiveScanner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// NEWorld/Core: AssemblyReflectiveScanner.cs
// NEWorld: A Free Game with Similar Rules to Minecraft.
// Copyright (C) 2015-2019 NEWorld Team
//
// NEWorld is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// NEWorld is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
// Public License for more details.
//
// 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.Reflection;

namespace Core
{
public sealed class DeclareNeWorldAssemblyAttribute : Attribute
{
}

public sealed class DeclareAssemblyReflectiveScannerAttribute : Attribute
{
}

public interface IAssemblyReflectiveScanner
{
void ProcessType(Type type);
}

internal static class AssemblyReflectiveScanner
{
// Only for conflict resolve for multi-thread load
private static HashSet<AssemblyName> _processed = new HashSet<AssemblyName>();
private static readonly object ProcessLock = new object();
private static readonly List<IAssemblyReflectiveScanner> Scanners = new List<IAssemblyReflectiveScanner>();
private static readonly List<Assembly> Scanned = new List<Assembly>();

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);
}
}
}

private static bool CheckIfAssemblyProcessed(Assembly assembly)
{
lock (ProcessLock)
{
return _processed != null && (bool) (_processed?.Contains(assembly.GetName()));
}
}

private static void OnAssemblyLoadServiceRegisterAgent(object sender, AssemblyLoadEventArgs args)
{
ScanAssembly(args.LoadedAssembly);
}

private static void ScanForAssemblyScanners(Assembly assembly)
{
foreach (var type in assembly.GetExportedTypes())
if (CheckScannerType(type))
InitializeScanner(type);
}

private static bool CheckScannerType(Type type)
{
return type.IsDefined(typeof(DeclareAssemblyReflectiveScannerAttribute), false) &&
typeof(IAssemblyReflectiveScanner).IsAssignableFrom(type);
}

private static void InitializeScanner(Type type)
{
var currentScanner = (IAssemblyReflectiveScanner) Activator.CreateInstance(type);
lock (Scanners)
{
Scanners.Add(currentScanner);
}

lock (ProcessLock)
{
if (_processed != null) return;
lock (Scanned)
{
foreach (var assembly in Scanned)
foreach (var target in assembly.GetExportedTypes())
currentScanner.ProcessType(target);
}
}
}

private static void ScanAssembly(Assembly assembly)
{
lock (ProcessLock)
{
_processed?.Add(assembly.GetName(true));
}

if (!assembly.IsDefined(typeof(DeclareNeWorldAssemblyAttribute), false)) return;

ScanForAssemblyScanners(assembly);

lock (Scanned)
{
Scanned.Add(assembly);
}

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

private static void ProcessAssembly(Assembly assembly)
{
foreach (var target in assembly.GetExportedTypes())
lock (Scanners)
{
foreach (var currentScanner in Scanners) currentScanner.ProcessType(target);
}
}
}
}
79 changes: 8 additions & 71 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -1,75 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{ECB0E309-625F-4A24-926D-D1D23C1B7693}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Core</RootNamespace>
<AssemblyName>Core</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>7.2</LangVersion>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="MsgPack, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a2625990d5dc0167">
<HintPath>..\packages\MsgPack.Cli.1.0.0\lib\net46\MsgPack.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Generic.cs" />
<Compile Include="Math\Mat4.cs" />
<Compile Include="Math\Vector.cs" />
<Compile Include="Module\Module.cs" />
<Compile Include="Network\Client.cs" />
<Compile Include="Network\ConnectionHost.cs" />
<Compile Include="Network\Protocol.cs" />
<Compile Include="Network\Protocols.cs" />
<Compile Include="Network\Server.cs" />
<Compile Include="Path.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Rect.cs" />
<Compile Include="Services.cs" />
<Compile Include="Utilities\EndianCheck.cs" />
<Compile Include="Utilities\RateController.cs" />
<Compile Include="Utilities\Singleton.cs" />
<Compile Include="Utilities\StrictDispose.cs" />
</ItemGroup>

<ItemGroup>
<None Include="packages.config" />
<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" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
17 changes: 17 additions & 0 deletions Core/Core.xkpkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
!Package
SerializedVersion: {Assets: 3.1.0.0}
Meta:
Name: Core
Version: 1.0.0
Authors: []
Owners: []
Dependencies: null
AssetFolders:
- Path: !dir Assets
ResourceFolders:
- !dir Resources
OutputGroupDirectories: {}
ExplicitFolders: []
Bundles: []
TemplateFolders: []
RootAssets: []
Loading