mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Remove automatic IoC discovery (#246)
* First bits removing IoCTarget. * Client works. * IoCTarget removal done on server. * IoCTarget removal in unit tests done. * Remove IIoCInterface and IoCTarget.
This commit is contained in:
committed by
GitHub
parent
860a8a8e03
commit
b9267af6c1
@@ -1,4 +1,4 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Client.GameObjects;
|
||||
using SS14.Client.Interfaces.Collision;
|
||||
@@ -18,7 +18,6 @@ namespace SS14.Client.Collision
|
||||
/// Here's what is happening here. Each collidable AABB added to this manager gets tossed into
|
||||
/// a "bucket". The buckets are subdivisions of the world space in 256-unit blocks.
|
||||
/// </summary>
|
||||
[IoCTarget]
|
||||
public class CollisionManager : ICollisionManager
|
||||
{
|
||||
private const int BucketSize = 256;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SFML.Window;
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -7,7 +7,6 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Configuration
|
||||
{
|
||||
[IoCTarget]
|
||||
public sealed class ConfigurationManager : IPlayerConfigurationManager
|
||||
{
|
||||
private string _configFile;
|
||||
|
||||
@@ -26,7 +26,6 @@ using KeyArgs = SFML.Window.KeyEventArgs;
|
||||
|
||||
namespace SS14.Client
|
||||
{
|
||||
[IoCTarget]
|
||||
public class GameController : IGameController
|
||||
{
|
||||
#region Fields
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.System;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
@@ -13,7 +13,6 @@ namespace SS14.Client.GameObjects
|
||||
/// <summary>
|
||||
/// Manager for entities -- controls things like template loading and instantiation
|
||||
/// </summary>
|
||||
[IoCTarget(Priority = 5)]
|
||||
public class ClientEntityManager : EntityManager, IClientEntityManager
|
||||
{
|
||||
public IEnumerable<IEntity> GetEntitiesInRange(Vector2f position, float Range)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using NetSerializer;
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.MessageLogging;
|
||||
@@ -13,7 +13,6 @@ using System.IO;
|
||||
|
||||
namespace SS14.Client.GameObjects
|
||||
{
|
||||
[IoCTarget]
|
||||
public class EntityNetworkManager : IEntityNetworkManager
|
||||
{
|
||||
private readonly bool _messageProfiling;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using SS14.Client.Interfaces.GameTimer;
|
||||
using SS14.Client.Interfaces.GameTimer;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.GameTimer
|
||||
{
|
||||
[IoCTarget]
|
||||
public class GameTimer : IGameTimer
|
||||
{
|
||||
public GameTimer()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.Window;
|
||||
using SFML.Window;
|
||||
using SS14.Client.Graphics;
|
||||
using SS14.Client.Interfaces.Input;
|
||||
using SS14.Shared;
|
||||
@@ -12,7 +12,6 @@ using System.Xml;
|
||||
|
||||
namespace SS14.Client.Input
|
||||
{
|
||||
[IoCTarget]
|
||||
public class KeyBindingManager : IKeyBindingManager
|
||||
{
|
||||
private Dictionary<Keyboard.Key, BoundKeyFunctions> _boundKeys;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Collision
|
||||
{
|
||||
public interface ICollisionManager : IIoCInterface
|
||||
public interface ICollisionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks to see if the specified collision rectangle collides with any of the colliders under management.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using SFML.Window;
|
||||
using SFML.Window;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Configuration
|
||||
{
|
||||
public interface IPlayerConfigurationManager : IIoCInterface
|
||||
public interface IPlayerConfigurationManager
|
||||
{
|
||||
void Initialize(string configFile);
|
||||
void SetPlayerName(string name);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using SFML.System;
|
||||
using SFML.System;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SS14.Client.Interfaces.GameObjects
|
||||
{
|
||||
public interface IClientEntityManager : IEntityManager, IIoCInterface
|
||||
public interface IClientEntityManager : IEntityManager
|
||||
{
|
||||
IEnumerable<IEntity> GetEntitiesInRange(Vector2f position, float Range);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.GameTimer
|
||||
{
|
||||
public interface IGameTimer : IIoCInterface
|
||||
public interface IGameTimer
|
||||
{
|
||||
float CurrentTime { get; }
|
||||
void UpdateTime(float delta);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces
|
||||
{
|
||||
interface IGameController : IIoCInterface
|
||||
public interface IGameController
|
||||
{
|
||||
/// <summary>
|
||||
/// Main method that does everything, starting the game loop.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using SS14.Shared;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.Interfaces.Input
|
||||
{
|
||||
public interface IKeyBindingManager : IIoCInterface
|
||||
public interface IKeyBindingManager
|
||||
{
|
||||
bool Enabled { get; set; }
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Lighting
|
||||
{
|
||||
public interface ILightManager : IIoCInterface
|
||||
public interface ILightManager
|
||||
{
|
||||
ILight CreateLight();
|
||||
void AddLight(ILight light);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,7 +8,7 @@ namespace SS14.Client.Interfaces.Map
|
||||
{
|
||||
public delegate void TileChangedEventHandler(TileRef tileRef, Tile oldTile);
|
||||
|
||||
public interface IMapManager : IIoCInterface
|
||||
public interface IMapManager
|
||||
{
|
||||
event TileChangedEventHandler TileChanged;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Map
|
||||
{
|
||||
public interface ITileDefinitionManager : IEnumerable<ITileDefinition>, IIoCInterface
|
||||
public interface ITileDefinitionManager : IEnumerable<ITileDefinition>
|
||||
{
|
||||
ushort Register(ITileDefinition tileDef);
|
||||
void RegisterServerTileMapping(NetIncomingMessage message);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using SS14.Shared;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.MessageLogging
|
||||
{
|
||||
public interface IMessageLogger : IIoCInterface
|
||||
public interface IMessageLogger
|
||||
{
|
||||
void LogOutgoingComponentNetMessage(int uid, ComponentFamily family, object[] parameters);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Network
|
||||
{
|
||||
public interface INetworkGrapher : IIoCInterface
|
||||
public interface INetworkGrapher
|
||||
{
|
||||
void Initialize();
|
||||
void Update();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.Interfaces.Network
|
||||
{
|
||||
public interface INetworkManager : IIoCInterface
|
||||
public interface INetworkManager
|
||||
{
|
||||
void Initialize();
|
||||
NetPeerStatistics CurrentStatistics { get; }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
using SS14.Shared;
|
||||
@@ -8,7 +8,7 @@ using System;
|
||||
|
||||
namespace SS14.Client.Interfaces.Placement
|
||||
{
|
||||
public interface IPlacementManager : IIoCInterface
|
||||
public interface IPlacementManager
|
||||
{
|
||||
bool IsActive { get; }
|
||||
bool Eraser { get; }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Client.Graphics.Render;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
@@ -11,7 +11,7 @@ using KeyboardKeys = SFML.Window.Keyboard.Key;
|
||||
|
||||
namespace SS14.Client.Interfaces.Player
|
||||
{
|
||||
public interface IPlayerManager : IIoCInterface
|
||||
public interface IPlayerManager
|
||||
{
|
||||
IEntity ControlledEntity { get; }
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SS14.Client.Graphics.Shader;
|
||||
using SS14.Client.Graphics.Sprite;
|
||||
using SS14.Shared.GameObjects;
|
||||
@@ -7,7 +7,7 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Resource
|
||||
{
|
||||
public interface IResourceManager : IIoCInterface
|
||||
public interface IResourceManager
|
||||
{
|
||||
Dictionary<Texture, string> TextureToKey { get; }
|
||||
void LoadResourceZip(string path = null, string pw = null);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Serialization
|
||||
{
|
||||
public interface ISS14Serializer : IIoCInterface
|
||||
public interface ISS14Serializer
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
|
||||
|
||||
using SFML.Window;
|
||||
using SFML.Window;
|
||||
using SS14.Client.Graphics.Event;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.Interfaces.State
|
||||
{
|
||||
public interface IStateManager : IIoCInterface
|
||||
public interface IStateManager
|
||||
{
|
||||
IState CurrentState { get; }
|
||||
void RequestStateChange<T>() where T : IState;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Window;
|
||||
using SS14.Client.Graphics.Event;
|
||||
using SS14.Client.Interfaces.Console;
|
||||
@@ -9,7 +9,7 @@ using System;
|
||||
|
||||
namespace SS14.Client.Interfaces.UserInterface
|
||||
{
|
||||
public interface IUserInterfaceManager : IIoCInterface
|
||||
public interface IUserInterfaceManager
|
||||
{
|
||||
void Initialize();
|
||||
IDragDropInfo DragInfo { get; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Interfaces.Utility
|
||||
{
|
||||
public interface IRand : IIoCInterface
|
||||
public interface IRand
|
||||
{
|
||||
int Next();
|
||||
int Next(int maxValue);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.Graphics;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.Lighting;
|
||||
using SS14.Shared;
|
||||
@@ -11,7 +11,6 @@ using System.Reflection;
|
||||
|
||||
namespace SS14.Client.Lighting
|
||||
{
|
||||
[IoCTarget]
|
||||
public class LightManager : ILightManager
|
||||
{
|
||||
private readonly List<Type> LightModes = new List<Type>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
@@ -11,7 +11,6 @@ using System.Linq;
|
||||
|
||||
namespace SS14.Client.Map
|
||||
{
|
||||
[IoCTarget]
|
||||
public class MapManager : IMapManager
|
||||
{
|
||||
private Dictionary<Vector2i, Chunk> chunks = new Dictionary<Vector2i, Chunk>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -6,7 +6,6 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Map
|
||||
{
|
||||
[IoCTarget]
|
||||
public sealed class TileDefinitionManager : ITileDefinitionManager
|
||||
{
|
||||
List<ITileDefinition> tileDefs = new List<ITileDefinition>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.MessageLogging;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
@@ -9,7 +9,6 @@ using System.Timers;
|
||||
|
||||
namespace SS14.Client.MessageLogging
|
||||
{
|
||||
[IoCTarget]
|
||||
public class MessageLogger : IMessageLogger
|
||||
{
|
||||
private readonly Timer _pingTimer;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.System;
|
||||
using SFML.System;
|
||||
using SS14.Client.Graphics;
|
||||
using SS14.Client.Graphics.Sprite;
|
||||
using SS14.Client.Interfaces.Network;
|
||||
@@ -10,7 +10,6 @@ using System.Collections.Generic;
|
||||
|
||||
namespace SS14.Client.Network
|
||||
{
|
||||
[IoCTarget]
|
||||
public class NetworkGrapher : INetworkGrapher
|
||||
{
|
||||
private const int MaxDataPoints = 200;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
using SS14.Client.Interfaces.Network;
|
||||
@@ -9,7 +9,6 @@ using System;
|
||||
|
||||
namespace SS14.Client.Network
|
||||
{
|
||||
[IoCTarget]
|
||||
public class NetworkManager : INetworkManager
|
||||
{
|
||||
private const string ServerName = "SS13 Server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Client.GameObjects;
|
||||
@@ -24,7 +24,6 @@ using System.Reflection;
|
||||
|
||||
namespace SS14.Client.Placement
|
||||
{
|
||||
[IoCTarget]
|
||||
public class PlacementManager : IPlacementManager
|
||||
{
|
||||
public readonly ICollisionManager CollisionManager;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Window;
|
||||
using SS14.Client.GameObjects;
|
||||
using SS14.Client.Graphics.Render;
|
||||
@@ -17,7 +17,6 @@ using System.Linq;
|
||||
|
||||
namespace SS14.Client.Player
|
||||
{
|
||||
[IoCTarget]
|
||||
public class PlayerManager : IPlayerManager
|
||||
{
|
||||
/* Here's the player controller. This will handle attaching GUIS and input to controllable things.
|
||||
|
||||
@@ -1,11 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using SS14.Client.Collision;
|
||||
using SS14.Client.Configuration;
|
||||
using SS14.Client.GameObjects;
|
||||
using SS14.Client.Input;
|
||||
using SS14.Client.Interfaces;
|
||||
using SS14.Client.Interfaces.Collision;
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.GameObjects;
|
||||
using SS14.Client.Interfaces.GameTimer;
|
||||
using SS14.Client.Interfaces.Input;
|
||||
using SS14.Client.Interfaces.Lighting;
|
||||
using SS14.Client.Interfaces.Map;
|
||||
using SS14.Client.Interfaces.MessageLogging;
|
||||
using SS14.Client.Interfaces.Network;
|
||||
using SS14.Client.Interfaces.Placement;
|
||||
using SS14.Client.Interfaces.Player;
|
||||
using SS14.Client.Interfaces.Resource;
|
||||
using SS14.Client.Interfaces.Serialization;
|
||||
using SS14.Client.Interfaces.State;
|
||||
using SS14.Client.Interfaces.UserInterface;
|
||||
using SS14.Client.Interfaces.Utility;
|
||||
using SS14.Client.Lighting;
|
||||
using SS14.Client.Map;
|
||||
using SS14.Client.MessageLogging;
|
||||
using SS14.Client.Network;
|
||||
using SS14.Client.Placement;
|
||||
using SS14.Client.Player;
|
||||
using SS14.Client.Reflection;
|
||||
using SS14.Client.Resources;
|
||||
using SS14.Client.Serialization;
|
||||
using SS14.Client.State;
|
||||
using SS14.Client.UserInterface;
|
||||
using SS14.Client.Utility;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Log;
|
||||
using SS14.Shared.Interfaces.Reflection;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Utility;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Client.Interfaces;
|
||||
using SS14.Shared.Prototypes;
|
||||
using SS14.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SS14.Client
|
||||
{
|
||||
@@ -18,6 +54,7 @@ namespace SS14.Client
|
||||
[STAThread]
|
||||
private static void Main()
|
||||
{
|
||||
RegisterIoC();
|
||||
LoadAssemblies();
|
||||
|
||||
var controller = IoCManager.Resolve<IGameController>();
|
||||
@@ -27,6 +64,43 @@ namespace SS14.Client
|
||||
IoCManager.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers all the types into the <see cref="IoCManager"/> with <see cref="IoCManager.Register{TInterface, TImplementation}"/>
|
||||
/// </summary>
|
||||
private static void RegisterIoC()
|
||||
{
|
||||
// Shared stuff.
|
||||
IoCManager.Register<IComponentManager, ComponentManager>();
|
||||
IoCManager.Register<IPrototypeManager, PrototypeManager>();
|
||||
IoCManager.Register<IEntitySystemManager, EntitySystemManager>();
|
||||
IoCManager.Register<IComponentFactory, ComponentFactory>();
|
||||
IoCManager.Register<ILogManager, LogManager>();
|
||||
|
||||
// Client stuff.
|
||||
IoCManager.Register<IRand, Rand>();
|
||||
IoCManager.Register<IStateManager, StateManager>();
|
||||
IoCManager.Register<INetworkGrapher, NetworkGrapher>();
|
||||
IoCManager.Register<IKeyBindingManager, KeyBindingManager>();
|
||||
IoCManager.Register<IUserInterfaceManager, UserInterfaceManager>();
|
||||
IoCManager.Register<IGameTimer, GameTimer.GameTimer>();
|
||||
IoCManager.Register<ITileDefinitionManager, TileDefinitionManager>();
|
||||
IoCManager.Register<IMessageLogger, MessageLogger>();
|
||||
IoCManager.Register<ICollisionManager, CollisionManager>();
|
||||
IoCManager.Register<IEntityManager, ClientEntityManager>();
|
||||
IoCManager.Register<IClientEntityManager, ClientEntityManager>();
|
||||
IoCManager.Register<INetworkManager, NetworkManager>();
|
||||
IoCManager.Register<IReflectionManager, ClientReflectionManager>();
|
||||
IoCManager.Register<IPlacementManager, PlacementManager>();
|
||||
IoCManager.Register<ILightManager, LightManager>();
|
||||
IoCManager.Register<IResourceManager, ResourceManager>();
|
||||
IoCManager.Register<ISS14Serializer, SS14Serializer>();
|
||||
IoCManager.Register<IMapManager, MapManager>();
|
||||
IoCManager.Register<IPlayerConfigurationManager, ConfigurationManager>();
|
||||
IoCManager.Register<IEntityNetworkManager, EntityNetworkManager>();
|
||||
IoCManager.Register<IPlayerManager, PlayerManager>();
|
||||
IoCManager.Register<IGameController, GameController>();
|
||||
}
|
||||
|
||||
private static void LoadAssemblies()
|
||||
{
|
||||
var assemblies = new List<Assembly>(4)
|
||||
@@ -64,7 +138,6 @@ namespace SS14.Client
|
||||
System.Console.ResetColor();
|
||||
}
|
||||
|
||||
IoCManager.AddAssemblies(assemblies);
|
||||
IoCManager.Resolve<IReflectionManager>().LoadAssemblies(assemblies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace SS14.Client.Reflection
|
||||
/// that defines <code>SS14.Client</code> and <code>SS14.Shared</code>
|
||||
/// as valid prefixes for <see cref="ReflectionManager.GetType(string)"/>
|
||||
/// </summary>
|
||||
[IoCTarget]
|
||||
public sealed class ClientReflectionManager : ReflectionManager
|
||||
{
|
||||
protected override IEnumerable<string> TypePrefixes => new[] {"", "SS14.Client.", "SS14.Shared."};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using ICSharpCode.SharpZipLib.Core;
|
||||
using ICSharpCode.SharpZipLib.Core;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
@@ -8,7 +8,6 @@ using SS14.Client.Graphics.Sprite;
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.Resource;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Utility;
|
||||
using System;
|
||||
@@ -23,7 +22,6 @@ using SS14.Client.Graphics.TexHelpers;
|
||||
|
||||
namespace SS14.Client.Resources
|
||||
{
|
||||
[IoCTarget]
|
||||
public class ResourceManager : IResourceManager
|
||||
{
|
||||
private const int zipBufferSize = 4096;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using SS14.Client.Interfaces.Serialization;
|
||||
using SS14.Client.Interfaces.Serialization;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Client.Serialization
|
||||
{
|
||||
[IoCTarget]
|
||||
public class SS14Serializer : SS14.Shared.Serialization.SS14Serializer, ISS14Serializer
|
||||
public class SS14Serializer : Shared.Serialization.SS14Serializer, ISS14Serializer
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.Window;
|
||||
using SFML.Window;
|
||||
using SS14.Client.Graphics.Event;
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SS14.Client.Interfaces.Input;
|
||||
@@ -17,7 +17,6 @@ using KeyEventArgs = SFML.Window.KeyEventArgs;
|
||||
|
||||
namespace SS14.Client.State
|
||||
{
|
||||
[IoCTarget]
|
||||
public class StateManager : IStateManager
|
||||
{
|
||||
private readonly Dictionary<Type, IState> _loadedStates;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SFML.Window;
|
||||
@@ -25,7 +25,6 @@ namespace SS14.Client.UserInterface
|
||||
/// <summary>
|
||||
/// Manages UI Components. This includes input, rendering, updates and net messages.
|
||||
/// </summary>
|
||||
[IoCTarget]
|
||||
public class UserInterfaceManager : IUserInterfaceManager
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using SS14.Client.Interfaces.Utility;
|
||||
using SS14.Client.Interfaces.Utility;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Client.Utility
|
||||
{
|
||||
[IoCTarget]
|
||||
public class Rand : IRand
|
||||
{
|
||||
private readonly Random rand;
|
||||
|
||||
@@ -20,7 +20,6 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace SS14.Server.Chat
|
||||
{
|
||||
[IoCTarget]
|
||||
public class ChatManager : IChatManager
|
||||
{
|
||||
private ISS14Server _serverMain;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.Chat;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
namespace SS14.Server.Chat.Commands
|
||||
{
|
||||
[IoCTarget]
|
||||
public class ListCommands : IChatCommand
|
||||
{
|
||||
public string Command => "list";
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.Chat;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Chat.Commands
|
||||
{
|
||||
[IoCTarget]
|
||||
public class Test : IChatCommand
|
||||
{
|
||||
public string Command => "test";
|
||||
|
||||
@@ -17,8 +17,7 @@ using System;
|
||||
|
||||
namespace SS14.Server.ClientConsoleHost
|
||||
{
|
||||
[IoCTarget]
|
||||
class ClientConsoleHost : IClientConsoleHost
|
||||
public class ClientConsoleHost : IClientConsoleHost
|
||||
{
|
||||
private Dictionary<string, IClientCommand> availableCommands = new Dictionary<string, IClientCommand>();
|
||||
public IDictionary<string, IClientCommand> AvailableCommands => availableCommands;
|
||||
@@ -41,7 +40,7 @@ namespace SS14.Server.ClientConsoleHost
|
||||
|
||||
public ClientConsoleHost(IReflectionManager reflactionManager)
|
||||
{
|
||||
foreach(Type type in reflactionManager.GetAllChildren<IClientCommand>())
|
||||
foreach (Type type in reflactionManager.GetAllChildren<IClientCommand>())
|
||||
{
|
||||
var instance = Activator.CreateInstance(type, null) as IClientCommand;
|
||||
if (AvailableCommands.ContainsKey(instance.Command))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using CommandLine;
|
||||
using CommandLine;
|
||||
using CommandLine.Text;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -6,10 +6,9 @@ using System.Reflection;
|
||||
|
||||
namespace SS14.Server
|
||||
{
|
||||
[IoCTarget]
|
||||
class CommandLineArgs : ICommandLineArgs
|
||||
public class CommandLineArgs : ICommandLineArgs
|
||||
{
|
||||
[Option("config-file", Required=false, DefaultValue="./server_config.xml", HelpText="Config file to read from.")]
|
||||
[Option("config-file", Required = false, DefaultValue = "./server_config.xml", HelpText = "Config file to read from.")]
|
||||
public string ConfigFile { get; set; }
|
||||
|
||||
[HelpOption]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.System;
|
||||
using SFML.System;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.Configuration;
|
||||
using SS14.Shared;
|
||||
@@ -10,7 +10,6 @@ using System.Xml.Serialization;
|
||||
|
||||
namespace SS14.Server.Configuration
|
||||
{
|
||||
[IoCTarget]
|
||||
public sealed class ConfigurationManager : IServerConfigurationManager
|
||||
{
|
||||
private string ConfigFile;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using NetSerializer;
|
||||
using SS14.Server.Interfaces.Configuration;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
@@ -7,7 +7,6 @@ using SS14.Server.Interfaces.Network;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -16,7 +15,6 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace SS14.Server.GameObjects
|
||||
{
|
||||
[IoCTarget]
|
||||
public class EntityNetworkManager : IEntityNetworkManager
|
||||
{
|
||||
private readonly bool _messageProfiling;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.System;
|
||||
using SFML.System;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
@@ -17,7 +17,6 @@ namespace SS14.Server.GameObjects
|
||||
/// <summary>
|
||||
/// Manager for entities -- controls things like template loading and instantiation
|
||||
/// </summary>
|
||||
[IoCTarget(Priority = 5)]
|
||||
public class ServerEntityManager : EntityManager, IServerEntityManager
|
||||
{
|
||||
#region IEntityManager Members
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Server.Interfaces.GameState;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -7,7 +7,6 @@ using System.Linq;
|
||||
|
||||
namespace SS14.Server.GameStates
|
||||
{
|
||||
[IoCTarget]
|
||||
public class GameStateManager : Dictionary<uint, SS14.Shared.GameStates.GameState>, IGameStateManager
|
||||
{
|
||||
private readonly Dictionary<long, uint> ackedStates = new Dictionary<long, uint>();
|
||||
@@ -64,7 +63,7 @@ namespace SS14.Server.GameStates
|
||||
return ackedStates[client.RemoteUniqueIdentifier];
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion IGameStateManager Members
|
||||
|
||||
public void CullAll()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -8,7 +8,7 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Chat
|
||||
{
|
||||
public interface IChatCommand : ICommand, IIoCInterface
|
||||
public interface IChatCommand : ICommand
|
||||
{
|
||||
void Execute(IChatManager manager, IClient client, params string[] args);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Shared;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Chat
|
||||
{
|
||||
public interface IChatManager : IIoCInterface
|
||||
public interface IChatManager
|
||||
{
|
||||
void SendChatMessage(ChatChannel channel, string text, string name, int? entityID);
|
||||
void SendPrivateMessage(IClient client, ChatChannel channel, string text, string name, int? entityId);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Shared.Command;
|
||||
using SS14.Shared.Command;
|
||||
using SS14.Shared.IoC;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace SS14.Server.Interfaces.ClientConsoleHost
|
||||
/// <summary>
|
||||
/// A command, executed from the debug console of a client.
|
||||
/// </summary>
|
||||
public interface IClientCommand : ICommand, IIoCInterface
|
||||
public interface IClientCommand : ICommand
|
||||
{
|
||||
void Execute(IClientConsoleHost host, IClient client, params string[] args);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.ClientConsoleHost
|
||||
{
|
||||
public interface IClientConsoleHost : IIoCInterface
|
||||
public interface IClientConsoleHost
|
||||
{
|
||||
IDictionary<string, IClientCommand> AvailableCommands { get; }
|
||||
void ProcessCommand(string text, NetConnection sender);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SFML.System;
|
||||
using SFML.System;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.Log;
|
||||
|
||||
@@ -6,7 +6,7 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Configuration
|
||||
{
|
||||
public interface IServerConfigurationManager : IIoCInterface
|
||||
public interface IServerConfigurationManager
|
||||
{
|
||||
bool MessageLogging { get; set; }
|
||||
string ServerName { get; set; }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.System;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace SS14.Server.Interfaces.GameObjects
|
||||
{
|
||||
public interface IServerEntityManager : IEntityManager, IIoCInterface
|
||||
public interface IServerEntityManager : IEntityManager
|
||||
{
|
||||
void Initialize();
|
||||
void SaveEntities();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.GameObjects
|
||||
{
|
||||
public interface IServerEntityNetworkManager : IEntityNetworkManager, IIoCInterface
|
||||
public interface IServerEntityNetworkManager : IEntityNetworkManager
|
||||
{
|
||||
void SendToAll(NetOutgoingMessage message, NetDeliveryMethod method = NetDeliveryMethod.ReliableOrdered);
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Shared;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.GameState
|
||||
{
|
||||
public interface IGameStateManager : IDictionary<uint, SS14.Shared.GameStates.GameState>, IIoCInterface
|
||||
public interface IGameStateManager : IDictionary<uint, SS14.Shared.GameStates.GameState>
|
||||
{
|
||||
uint OldestStateAcked { get; }
|
||||
void Cull();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces
|
||||
{
|
||||
public interface ICommandLineArgs : IIoCInterface
|
||||
public interface ICommandLineArgs
|
||||
{
|
||||
string ConfigFile { get; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using SS14.Server.Interfaces.Map;
|
||||
using SS14.Shared.ServerEnums;
|
||||
@@ -6,7 +6,7 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces
|
||||
{
|
||||
public interface ISS14Server : IIoCInterface
|
||||
public interface ISS14Server
|
||||
{
|
||||
RunLevel Runlevel { get; }
|
||||
void SetServerInstance(ISS14Server server);
|
||||
@@ -16,7 +16,7 @@ namespace SS14.Server.Interfaces
|
||||
void SaveEntities();
|
||||
bool Start();
|
||||
void Restart();
|
||||
void Shutdown(string reason=null);
|
||||
void Shutdown(string reason = null);
|
||||
IMapManager GetMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using SS14.Shared.Interfaces.Log;
|
||||
using SS14.Shared.Interfaces.Log;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Log
|
||||
{
|
||||
public interface IServerLogManager : ILogManager, IIoCInterface
|
||||
public interface IServerLogManager : ILogManager
|
||||
{
|
||||
/// <summary>
|
||||
/// The file path to log to.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Shared;
|
||||
@@ -9,7 +9,7 @@ namespace SS14.Server.Interfaces.Map
|
||||
{
|
||||
public delegate void TileChangedEventHandler(TileRef tileRef, Tile oldTile);
|
||||
|
||||
public interface IMapManager : IIoCInterface
|
||||
public interface IMapManager
|
||||
{
|
||||
bool LoadMap(string mapName);
|
||||
void SaveMap(string mapName);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Map
|
||||
{
|
||||
public interface ITileDefinitionManager : IEnumerable<ITileDefinition>, IIoCInterface
|
||||
public interface ITileDefinitionManager : IEnumerable<ITileDefinition>
|
||||
{
|
||||
ushort Register(ITileDefinition tileDef);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using SS14.Shared;
|
||||
using SS14.Shared;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.MessageLogging
|
||||
{
|
||||
public interface IMessageLogger : IIoCInterface
|
||||
public interface IMessageLogger
|
||||
{
|
||||
void LogOutgoingComponentNetMessage(long clientUID, int uid, ComponentFamily family, object[] parameters);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
@@ -7,7 +7,7 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Network
|
||||
{
|
||||
public interface ISS14NetServer : IIoCInterface
|
||||
public interface ISS14NetServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the NetPeerStatus of the NetPeer
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Placement
|
||||
{
|
||||
public interface IPlacementManager : IIoCInterface
|
||||
public interface IPlacementManager
|
||||
{
|
||||
void Initialize(ISS14Server server);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.System;
|
||||
using SS14.Shared.GameStates;
|
||||
using System.Collections.Generic;
|
||||
@@ -6,7 +6,7 @@ using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Player
|
||||
{
|
||||
public interface IPlayerManager : IIoCInterface
|
||||
public interface IPlayerManager
|
||||
{
|
||||
void SpawnPlayerMob(IPlayerSession player);
|
||||
IPlayerSession GetSessionByConnection(NetConnection senderConnection);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using SS14.Server.Interfaces.GameMode;
|
||||
using SS14.Server.Interfaces.GameMode;
|
||||
using SS14.Server.Interfaces.Player;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Round
|
||||
{
|
||||
public interface IRoundManager : IIoCInterface
|
||||
public interface IRoundManager
|
||||
{
|
||||
IGameMode CurrentGameMode { get; }
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.Serialization
|
||||
{
|
||||
public interface ISS14Serializer : IIoCInterface
|
||||
public interface ISS14Serializer
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Interfaces.ServerConsole
|
||||
{
|
||||
public interface IConsoleManager : IIoCInterface
|
||||
public interface IConsoleManager
|
||||
{
|
||||
IDictionary<string, IConsoleCommand> AvailableCommands { get; }
|
||||
void Update();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Server.Interfaces.Log;
|
||||
using SS14.Server.Interfaces.Log;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Log;
|
||||
using System.IO;
|
||||
@@ -7,7 +7,6 @@ using System;
|
||||
|
||||
namespace SS14.Server.Log
|
||||
{
|
||||
[IoCTarget(Priority=5)]
|
||||
public class ServerLogManager : LogManager, IServerLogManager, IDisposable
|
||||
{
|
||||
private bool disposed;
|
||||
@@ -40,7 +39,6 @@ namespace SS14.Server.Log
|
||||
{
|
||||
logStream = new StreamWriter(value, true, Encoding.UTF8);
|
||||
}
|
||||
|
||||
catch (IOException e)
|
||||
{
|
||||
Error("Unable to open log file ('{0}'): {1}", value, e);
|
||||
@@ -96,6 +94,6 @@ namespace SS14.Server.Log
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion IDisposable Members
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
using SS14.Server.Interfaces.Map;
|
||||
@@ -15,10 +15,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
namespace SS14.Server.Map
|
||||
{
|
||||
[IoCTarget]
|
||||
public class MapManager : IMapManager
|
||||
{
|
||||
private Dictionary<Vector2i, Chunk> chunks = new Dictionary<Vector2i, Chunk>();
|
||||
@@ -126,7 +124,7 @@ namespace SS14.Server.Map
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Tile Enumerators
|
||||
|
||||
#region Indexers
|
||||
|
||||
@@ -217,7 +215,7 @@ namespace SS14.Server.Map
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Indexers
|
||||
|
||||
#region Networking
|
||||
|
||||
@@ -313,7 +311,7 @@ namespace SS14.Server.Map
|
||||
IoCManager.Resolve<ISS14NetServer>().SendToAll(message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Networking
|
||||
|
||||
#region File Operations
|
||||
|
||||
@@ -334,7 +332,6 @@ namespace SS14.Server.Map
|
||||
|
||||
string fileName = Path.GetFullPath(Path.Combine(pathName, mapName));
|
||||
|
||||
|
||||
using (var fs = new FileStream(fileName, FileMode.Create))
|
||||
{
|
||||
var sw = new StreamWriter(fs);
|
||||
@@ -469,7 +466,7 @@ namespace SS14.Server.Map
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion File Operations
|
||||
|
||||
// An actual modulus implementation, because apparently % is not modulus. Srsly
|
||||
// Should probably stick this in some static class.
|
||||
@@ -478,6 +475,5 @@ namespace SS14.Server.Map
|
||||
{
|
||||
return (int)(n - (int)Math.Floor(n / d) * d);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using SS14.Server.Interfaces.Map;
|
||||
using SS14.Server.Interfaces.Map;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Map
|
||||
{
|
||||
[IoCTarget]
|
||||
public sealed class TileDefinitionManager : ITileDefinitionManager
|
||||
{
|
||||
List<ITileDefinition> tileDefs = new List<ITileDefinition>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.Configuration;
|
||||
using SS14.Server.Interfaces.MessageLogging;
|
||||
using SS14.Shared;
|
||||
@@ -10,7 +10,6 @@ using System.Timers;
|
||||
|
||||
namespace SS14.Server.MessageLogging
|
||||
{
|
||||
[IoCTarget]
|
||||
public class MessageLogger : IMessageLogger
|
||||
{
|
||||
private readonly Timer _pingTimer;
|
||||
@@ -61,11 +60,11 @@ namespace SS14.Server.MessageLogging
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
if (parameters[i] is Enum)
|
||||
parameters[i] = (int) parameters[i];
|
||||
parameters[i] = (int)parameters[i];
|
||||
}
|
||||
try
|
||||
{
|
||||
_loggerServiceClient.LogServerOutgoingNetMessage(clientUID, uid, (int) family, parameters);
|
||||
_loggerServiceClient.LogServerOutgoingNetMessage(clientUID, uid, (int)family, parameters);
|
||||
}
|
||||
catch (CommunicationException)
|
||||
{
|
||||
@@ -81,12 +80,12 @@ namespace SS14.Server.MessageLogging
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
if (parameters[i] is Enum)
|
||||
parameters[i] = (int) parameters[i];
|
||||
parameters[i] = (int)parameters[i];
|
||||
}
|
||||
try
|
||||
{
|
||||
_loggerServiceClient.LogServerIncomingNetMessage(clientUID, uid, (int) entityMessage,
|
||||
(int) componentFamily, parameters);
|
||||
_loggerServiceClient.LogServerIncomingNetMessage(clientUID, uid, (int)entityMessage,
|
||||
(int)componentFamily, parameters);
|
||||
}
|
||||
catch (CommunicationException)
|
||||
{
|
||||
@@ -101,14 +100,14 @@ namespace SS14.Server.MessageLogging
|
||||
|
||||
try
|
||||
{
|
||||
_loggerServiceClient.LogServerComponentMessage(uid, (int) senderfamily, sendertype, (int) type);
|
||||
_loggerServiceClient.LogServerComponentMessage(uid, (int)senderfamily, sendertype, (int)type);
|
||||
}
|
||||
catch (CommunicationException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion IMessageLogger Members
|
||||
|
||||
public static void CheckServer(object source, ElapsedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Server.Interfaces.Configuration;
|
||||
using SS14.Server.Interfaces.Network;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -6,7 +6,6 @@ using System.Collections.Generic;
|
||||
|
||||
namespace SS14.Server.Network
|
||||
{
|
||||
[IoCTarget]
|
||||
public class SS14NetServer : NetServer, ISS14NetServer
|
||||
{
|
||||
public SS14NetServer()
|
||||
@@ -31,7 +30,7 @@ namespace SS14.Server.Network
|
||||
SendMessage(message, recipients, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion ISS13NetServer Members
|
||||
|
||||
public static NetPeerConfiguration LoadNetPeerConfig()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.System;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
@@ -18,7 +18,6 @@ using System.Linq;
|
||||
|
||||
namespace SS14.Server.Placement
|
||||
{
|
||||
[IoCTarget]
|
||||
public class PlacementManager : IPlacementManager
|
||||
{
|
||||
//TO-DO: Expand for multiple permission per mob?
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SFML.System;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
@@ -10,13 +10,11 @@ using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Maths;
|
||||
using SS14.Shared.ServerEnums;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace SS14.Server.Player
|
||||
{
|
||||
[IoCTarget]
|
||||
public class PlayerManager : IPlayerManager
|
||||
{
|
||||
/* This class will manage connected player sessions. */
|
||||
|
||||
@@ -1,16 +1,44 @@
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.ServerEnums;
|
||||
using SS14.Shared.Interfaces.Reflection;
|
||||
using SS14.Shared.Interfaces.Log;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Utility;
|
||||
using SS14.Server.Chat;
|
||||
using SS14.Server.Configuration;
|
||||
using SS14.Server.GameObjects;
|
||||
using SS14.Server.GameStates;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.Chat;
|
||||
using SS14.Server.Interfaces.ClientConsoleHost;
|
||||
using SS14.Server.Interfaces.Configuration;
|
||||
using SS14.Server.Interfaces.GameObjects;
|
||||
using SS14.Server.Interfaces.GameState;
|
||||
using SS14.Server.Interfaces.Log;
|
||||
using SS14.Server.Interfaces.Map;
|
||||
using SS14.Server.Interfaces.MessageLogging;
|
||||
using SS14.Server.Interfaces.Network;
|
||||
using SS14.Server.Interfaces.Placement;
|
||||
using SS14.Server.Interfaces.Player;
|
||||
using SS14.Server.Interfaces.Round;
|
||||
using SS14.Server.Interfaces.Serialization;
|
||||
using SS14.Server.Interfaces.ServerConsole;
|
||||
using SS14.Server.Log;
|
||||
using SS14.Server.Map;
|
||||
using SS14.Server.MessageLogging;
|
||||
using SS14.Server.Network;
|
||||
using SS14.Server.Placement;
|
||||
using SS14.Server.Player;
|
||||
using SS14.Server.Reflection;
|
||||
using SS14.Server.Round;
|
||||
using SS14.Server.Serialization;
|
||||
using SS14.Server.ServerConsole;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.Interfaces.Log;
|
||||
using SS14.Shared.Interfaces.Reflection;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Log;
|
||||
using SS14.Shared.Prototypes;
|
||||
using SS14.Shared.Utility;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace SS14.Server
|
||||
{
|
||||
internal class EntryPoint
|
||||
@@ -19,7 +47,8 @@ namespace SS14.Server
|
||||
{
|
||||
//Register minidump dumper only if the app isn't being debugged. No use filling up hard drives with shite
|
||||
|
||||
LoadAssemblies();
|
||||
RegisterIoC();
|
||||
LoadContentAssemblies();
|
||||
|
||||
var server = IoCManager.Resolve<ISS14Server>();
|
||||
|
||||
@@ -35,23 +64,61 @@ namespace SS14.Server
|
||||
string strVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
Logger.Log("Server Version " + strVersion + " -> Ready");
|
||||
|
||||
// TODO: Move this to an interface.
|
||||
SignalHander.InstallSignals();
|
||||
|
||||
server.MainLoop();
|
||||
|
||||
Logger.Info("Goodbye.");
|
||||
|
||||
// Used to dispose of systems that want to be disposed.
|
||||
// Such as the log manager.
|
||||
IoCManager.Clear();
|
||||
}
|
||||
|
||||
private static void LoadAssemblies()
|
||||
/// <summary>
|
||||
/// Registers all the types into the <see cref="IoCManager"/> with <see cref="IoCManager.Register{TInterface, TImplementation}"/>
|
||||
/// </summary>
|
||||
private static void RegisterIoC()
|
||||
{
|
||||
// Shared stuff.
|
||||
IoCManager.Register<IComponentManager, ComponentManager>();
|
||||
IoCManager.Register<IPrototypeManager, PrototypeManager>();
|
||||
IoCManager.Register<IEntitySystemManager, EntitySystemManager>();
|
||||
IoCManager.Register<IComponentFactory, ComponentFactory>();
|
||||
|
||||
// Server stuff.
|
||||
IoCManager.Register<IEntityManager, ServerEntityManager>();
|
||||
IoCManager.Register<IServerEntityManager, ServerEntityManager>();
|
||||
IoCManager.Register<ILogManager, ServerLogManager>();
|
||||
IoCManager.Register<IServerLogManager, ServerLogManager>();
|
||||
IoCManager.Register<IMessageLogger, MessageLogger>();
|
||||
IoCManager.Register<IChatManager, ChatManager>();
|
||||
IoCManager.Register<ISS14NetServer, SS14NetServer>();
|
||||
IoCManager.Register<IMapManager, MapManager>();
|
||||
IoCManager.Register<IPlacementManager, PlacementManager>();
|
||||
IoCManager.Register<IConsoleManager, ConsoleManager>();
|
||||
IoCManager.Register<ITileDefinitionManager, TileDefinitionManager>();
|
||||
IoCManager.Register<IRoundManager, RoundManager>();
|
||||
IoCManager.Register<ISS14Server, SS14Server>();
|
||||
IoCManager.Register<ISS14Serializer, SS14Serializer>();
|
||||
IoCManager.Register<IEntityNetworkManager, EntityNetworkManager>();
|
||||
IoCManager.Register<ICommandLineArgs, CommandLineArgs>();
|
||||
IoCManager.Register<IGameStateManager, GameStateManager>();
|
||||
IoCManager.Register<IReflectionManager, ServerReflectionManager>();
|
||||
IoCManager.Register<IServerConfigurationManager, ConfigurationManager>();
|
||||
IoCManager.Register<IClientConsoleHost, ClientConsoleHost.ClientConsoleHost>();
|
||||
IoCManager.Register<IPlayerManager, PlayerManager>();
|
||||
}
|
||||
|
||||
// TODO: Move to the main server so we can have proper logging and stuff.
|
||||
private static void LoadContentAssemblies()
|
||||
{
|
||||
var assemblies = new List<Assembly>(4)
|
||||
{
|
||||
AppDomain.CurrentDomain.GetAssemblyByName("SS14.Shared"),
|
||||
Assembly.GetExecutingAssembly()
|
||||
};
|
||||
IoCManager.AddAssemblies(assemblies);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
@@ -79,7 +146,6 @@ namespace SS14.Server
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
IoCManager.AddAssemblies(assemblies);
|
||||
IoCManager.Resolve<IReflectionManager>().LoadAssemblies(assemblies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,8 @@ namespace SS14.Server.Reflection
|
||||
/// that defines <code>SS14.Server</code> and <code>SS14.Shared</code>
|
||||
/// as valid prefixes for <see cref="ReflectionManager.GetType(string)"/>
|
||||
/// </summary>
|
||||
[IoCTarget]
|
||||
public sealed class ServerReflectionManager : ReflectionManager
|
||||
{
|
||||
protected override IEnumerable<string> TypePrefixes => new[] { "", "SS14.Server.", "SS14.Shared." };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using SS14.Server.Interfaces.GameMode;
|
||||
using SS14.Server.Interfaces.GameMode;
|
||||
using SS14.Server.Interfaces.Player;
|
||||
using SS14.Server.Interfaces.Round;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Round
|
||||
{
|
||||
[IoCTarget]
|
||||
internal class RoundManager : IRoundManager
|
||||
public class RoundManager : IRoundManager
|
||||
{
|
||||
private bool _ready;
|
||||
|
||||
@@ -27,6 +26,6 @@ namespace SS14.Server.Round
|
||||
CurrentGameMode.PlayerJoined(player);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion IRoundManager Members
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Server.Interfaces;
|
||||
using SS14.Server.Interfaces.Chat;
|
||||
using SS14.Server.Interfaces.ClientConsoleHost;
|
||||
@@ -36,7 +36,6 @@ using MainLoopTimer = SS14.Server.Timing.MainLoopTimer;
|
||||
|
||||
namespace SS14.Server
|
||||
{
|
||||
[IoCTarget]
|
||||
public class SS14Server : ISS14Server
|
||||
{
|
||||
private const int GameCountdown = 15;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using SS14.Server.Interfaces.Serialization;
|
||||
using SS14.Server.Interfaces.Serialization;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Server.Serialization
|
||||
{
|
||||
[IoCTarget]
|
||||
public class SS14Serializer : SS14.Shared.Serialization.SS14Serializer, ISS14Serializer
|
||||
{
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ using Con = System.Console;
|
||||
|
||||
namespace SS14.Server.ServerConsole
|
||||
{
|
||||
[IoCTarget]
|
||||
public class ConsoleManager : IConsoleManager
|
||||
{
|
||||
private IDictionary<string, IConsoleCommand> availableCommands = new Dictionary<string, IConsoleCommand>();
|
||||
|
||||
55
SS14.Shared/Exceptions/TypeArgumentException.cs
Normal file
55
SS14.Shared/Exceptions/TypeArgumentException.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace SS14.Shared.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Thrown if a method is called with an invalid type argument.
|
||||
/// For example <see cref="IoC.IoCManager.Register{TInterface, TImplementation}(bool)"/> with an abstract <code>TImplementation</code>.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public sealed class TypeArgumentException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the type argument that had invalid data.
|
||||
/// </summary>
|
||||
public readonly string TypeArgumentName;
|
||||
|
||||
public TypeArgumentException()
|
||||
{
|
||||
}
|
||||
public TypeArgumentException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
public TypeArgumentException(string message, Exception inner) : base(message, inner)
|
||||
{
|
||||
}
|
||||
public TypeArgumentException(string message, string name) : base(message)
|
||||
{
|
||||
TypeArgumentName = name;
|
||||
}
|
||||
public TypeArgumentException(string message, string name, Exception inner) : base(message, inner)
|
||||
{
|
||||
TypeArgumentName = name;
|
||||
}
|
||||
|
||||
private TypeArgumentException(
|
||||
SerializationInfo info,
|
||||
StreamingContext context) : base(info, context)
|
||||
{
|
||||
TypeArgumentName = info.GetString("TypeArgumentName");
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
if (info == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(info));
|
||||
}
|
||||
|
||||
info.AddValue("TypeArgumentName", TypeArgumentName);
|
||||
|
||||
base.GetObjectData(info, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ using SS14.Shared.Interfaces.Reflection;
|
||||
|
||||
namespace SS14.Shared.GameObjects
|
||||
{
|
||||
[IoCTarget]
|
||||
public class ComponentFactory : IComponentFactory
|
||||
{
|
||||
private readonly IReflectionManager ReflectionManager;
|
||||
@@ -23,7 +22,7 @@ namespace SS14.Shared.GameObjects
|
||||
|
||||
ReloadComponents();
|
||||
|
||||
IoCManager.AssemblyAdded += ReloadComponents;
|
||||
reflectionManager.OnAssemblyAdded += (_, __) => ReloadComponents();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,10 +36,10 @@ namespace SS14.Shared.GameObjects
|
||||
{
|
||||
throw new ArgumentException(string.Format("{0} does not implement {1}", componentType, nameof(IComponent)), nameof(componentType));
|
||||
}
|
||||
return (IComponent) Activator.CreateInstance(componentType);
|
||||
return (IComponent)Activator.CreateInstance(componentType);
|
||||
}
|
||||
|
||||
public T GetComponent<T>() where T: IComponent
|
||||
public T GetComponent<T>() where T : IComponent
|
||||
{
|
||||
return (T)Activator.CreateInstance(typeof(T));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
@@ -7,7 +7,6 @@ using System.Linq;
|
||||
|
||||
namespace SS14.Shared.GameObjects
|
||||
{
|
||||
[IoCTarget]
|
||||
public class ComponentManager : IComponentManager
|
||||
{
|
||||
/// <summary>
|
||||
@@ -18,7 +17,7 @@ namespace SS14.Shared.GameObjects
|
||||
|
||||
public ComponentManager()
|
||||
{
|
||||
foreach (ComponentFamily family in Enum.GetValues(typeof (ComponentFamily)))
|
||||
foreach (ComponentFamily family in Enum.GetValues(typeof(ComponentFamily)))
|
||||
{
|
||||
components[family] = new List<IComponent>();
|
||||
}
|
||||
@@ -53,7 +52,7 @@ namespace SS14.Shared.GameObjects
|
||||
/// <param name="frameTime">Time since the last frame was rendered.</param>
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
foreach (ComponentFamily family in Enum.GetValues(typeof (ComponentFamily)))
|
||||
foreach (ComponentFamily family in Enum.GetValues(typeof(ComponentFamily)))
|
||||
{
|
||||
// Hack the update loop to allow us to render somewhere in the GameScreen render loop
|
||||
/*if (family == ComponentFamily.Renderable)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Prototypes;
|
||||
@@ -8,7 +8,6 @@ using System.Linq;
|
||||
|
||||
namespace SS14.Shared.GameObjects
|
||||
{
|
||||
[IoCTarget]
|
||||
public class EntityManager : IEntityManager
|
||||
{
|
||||
#region Dependencies
|
||||
|
||||
@@ -12,7 +12,6 @@ using System.Linq;
|
||||
|
||||
namespace SS14.Shared.GameObjects
|
||||
{
|
||||
[IoCTarget]
|
||||
public class EntitySystemManager : IEntitySystemManager
|
||||
{
|
||||
private readonly IReflectionManager ReflectionManager;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using SS14.Shared.Interfaces.GameObjects;
|
||||
using SS14.Shared.IoC;
|
||||
|
||||
namespace SS14.Shared.GameObjects
|
||||
{
|
||||
public interface IEntityNetworkManager : IIoCInterface
|
||||
public interface IEntityNetworkManager
|
||||
{
|
||||
NetOutgoingMessage CreateEntityMessage();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -11,7 +11,7 @@ namespace SS14.Shared.Interfaces.GameObjects
|
||||
/// Handles the spawning of components.
|
||||
/// Does IoC magic to allow accessing components by <see cref="IComponent.Name"/>.
|
||||
/// </summary>
|
||||
public interface IComponentFactory : IIoCInterface
|
||||
public interface IComponentFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a new component instantiated of the specified type.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -8,7 +8,7 @@ using SS14.Shared.GameObjects;
|
||||
|
||||
namespace SS14.Shared.Interfaces.GameObjects
|
||||
{
|
||||
public interface IComponentManager : IIoCInterface
|
||||
public interface IComponentManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IEnumerable{IComponent}"/> over every known <see cref="IComponent"/> with a specified <see cref="ComponentFamily"/>.
|
||||
@@ -16,7 +16,7 @@ namespace SS14.Shared.Interfaces.GameObjects
|
||||
/// <param name="family">The <see cref="ComponentFamily"/> to look up.</param>
|
||||
/// <returns>An <see cref="IEnumerable{IComponent}"/> over component with the specified family.</returns>
|
||||
IEnumerable<IComponent> GetComponents(ComponentFamily family);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add a component to the master component list.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Lidgren.Network;
|
||||
using Lidgren.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SS14.Shared.IoC;
|
||||
@@ -6,7 +6,7 @@ using SS14.Shared.GameObjects;
|
||||
|
||||
namespace SS14.Shared.Interfaces.GameObjects
|
||||
{
|
||||
public interface IEntityManager : IIoCInterface
|
||||
public interface IEntityManager
|
||||
{
|
||||
IList<ComponentFamily> SynchedComponentTypes { get; }
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.GameObjects;
|
||||
using SS14.Shared.Interfaces.GameObjects.System;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace SS14.Shared.Interfaces.GameObjects
|
||||
/// Periodically ticks <see cref="IEntitySystem"/> instances.
|
||||
/// </remarks>
|
||||
/// <seealso cref="IEntitySystem"/>
|
||||
public interface IEntitySystemManager : IIoCInterface
|
||||
public interface IEntitySystemManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Register an <see cref="EntitySystemMessage"/> type to be sent to the specified system.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.IoC;
|
||||
using SS14.Shared.Log;
|
||||
|
||||
namespace SS14.Shared.Interfaces.Log
|
||||
@@ -7,7 +7,7 @@ namespace SS14.Shared.Interfaces.Log
|
||||
/// Handles logging of messages on specific warning levels.
|
||||
/// Output method is dependent on implementation.
|
||||
/// </summary>
|
||||
public interface ILogManager : IIoCInterface
|
||||
public interface ILogManager
|
||||
{
|
||||
/// <summary>
|
||||
/// The minimum log level of messages to allow them through.
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace SS14.Shared.Interfaces.Reflection
|
||||
/// </remarks>
|
||||
/// <seealso cref="IoCManager"/>
|
||||
/// <seealso cref="ReflectAttribute"/>
|
||||
public interface IReflectionManager : IIoCInterface
|
||||
public interface IReflectionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all known types that are assignable to <typeparamref name="T"/>.
|
||||
@@ -34,7 +34,7 @@ namespace SS14.Shared.Interfaces.Reflection
|
||||
/// if it is a known type.
|
||||
/// </param>
|
||||
/// <returns>An enumerable over all the types. Order is in no way guaranteed.</returns>
|
||||
IEnumerable<Type> GetAllChildren<T>(bool inclusive=false);
|
||||
IEnumerable<Type> GetAllChildren<T>(bool inclusive = false);
|
||||
|
||||
/// <summary>
|
||||
/// All loaded assemblies.
|
||||
@@ -61,5 +61,20 @@ namespace SS14.Shared.Interfaces.Reflection
|
||||
/// Loads assemblies into the manager and get all the types.
|
||||
/// </summary>
|
||||
void LoadAssemblies(params Assembly[] args);
|
||||
|
||||
/// <summary>
|
||||
/// Fired whenever an assembly is added through <see cref="LoadAssemblies"/>,
|
||||
/// this means more types might be available from <see cref="GetType(string)"/> and <see cref="GetAllChildren{T}(bool)"/>
|
||||
/// </summary>
|
||||
event EventHandler<ReflectionUpdateEventArgs> OnAssemblyAdded;
|
||||
}
|
||||
|
||||
public class ReflectionUpdateEventArgs : EventArgs
|
||||
{
|
||||
public readonly IReflectionManager ReflectionManager;
|
||||
public ReflectionUpdateEventArgs(IReflectionManager reflectionManager)
|
||||
{
|
||||
ReflectionManager = reflectionManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace SS14.Shared.IoC
|
||||
{
|
||||
/// <summary>
|
||||
/// Marker type that signifies that this interface can be resolved through IoC.
|
||||
/// To use, simply inherit the interface in another interface.
|
||||
/// </summary>
|
||||
public interface IIoCInterface
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace SS14.Shared.IoC
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines priority and whether or not IoC can resolve something to this class.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public class IoCTargetAttribute : Attribute
|
||||
{
|
||||
private bool disabled = false;
|
||||
private int priority = 0;
|
||||
|
||||
public bool Disabled { get { return disabled; } set { disabled = value; } }
|
||||
public int Priority { get { return priority; } set { priority = value; } }
|
||||
}
|
||||
}
|
||||
@@ -1,63 +1,78 @@
|
||||
using SS14.Shared.IoC.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using SS14.Shared.Exceptions;
|
||||
|
||||
namespace SS14.Shared.IoC
|
||||
{
|
||||
/// <summary>
|
||||
/// The IoCManager handles Dependency Injection in the project.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Dependency Injection is a concept where instead of saying "I need the <code>EntityManager</code>",
|
||||
/// you say "I need something that implements <code>IEntityManager</code>".
|
||||
/// This decouples the various systems into swappable components that have standardized interfaces.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This is useful for a couple of things.
|
||||
/// Firstly, it allows the shared code to request the client or server code implicitly, without hacks.
|
||||
/// Secondly, it's very useful for unit tests as we can replace components to test things.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// To use the IoCManager, it first needs some types registered through <see cref="Register{TInterface, TImplementation}"/>.
|
||||
/// These implementations can then be fetched with <see cref="Resolve{T}"/>.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <seealso cref="Interfaces.Reflection.IReflectionManager"/>
|
||||
/// <seealso cref="IIoCInterface"/>
|
||||
/// <seealso cref="IoCTargetAttribute"/>
|
||||
public static class IoCManager
|
||||
{
|
||||
// Used to detect whether we have circular dependencies.
|
||||
/// <summary>
|
||||
/// Set of types that are currently being built by <see cref="BuildType(Type)"/>.
|
||||
/// Used to track whether we have circular dependencies.
|
||||
/// </summary>
|
||||
private static readonly HashSet<Type> CurrentlyBuilding = new HashSet<Type>();
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary that maps the types passed to <see cref="Resolve{T}"/> to their implementation.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<Type, object> Services = new Dictionary<Type, object>();
|
||||
private static readonly List<Type> ServiceTypes = new List<Type>();
|
||||
|
||||
/// <summary>
|
||||
/// The types interface types mapping to their registered implementations.
|
||||
/// This is pulled from to make a service if it doesn't exist yet.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<Type, Type> ResolveTypes = new Dictionary<Type, Type>();
|
||||
|
||||
public delegate void AssemblyAddedHandler();
|
||||
/// <summary>
|
||||
/// Invoked after new assemblies are loaded into IoC.
|
||||
/// Hook into this if you iterate available IoC targets for an interfaces, Like console commands.
|
||||
/// Registers an interface to an implementation, to make it accessible to <see cref="Resolve{T}"/>
|
||||
/// </summary>
|
||||
public static event AssemblyAddedHandler AssemblyAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Add extra assemblies to IoC's known types.
|
||||
/// </summary>
|
||||
public static void AddAssemblies(IEnumerable<Assembly> assemblies)
|
||||
/// <typeparam name="TInterface">The type that will be resolvable.</typeparam>
|
||||
/// <typeparam name="TImplementation">The type that will be constructed as implementation. Must not be abstract or an interface.</typeparam>
|
||||
/// <param name="overwrite">
|
||||
/// If true, do not throw an <see cref="InvalidOperationException"/> if an interface is already registered,
|
||||
/// replace the current implementation instead.
|
||||
/// </param>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown if <paramref name="overwrite"/> is false and <typeparamref name="TInterface"/> has been registered before.
|
||||
/// </exception>
|
||||
public static void Register<TInterface, TImplementation>(bool overwrite = false) where TImplementation : TInterface
|
||||
{
|
||||
foreach (var assembly in assemblies)
|
||||
if (typeof(TImplementation).IsAbstract)
|
||||
{
|
||||
try
|
||||
{
|
||||
ServiceTypes.AddRange(assembly.GetTypes());
|
||||
}
|
||||
catch (ReflectionTypeLoadException ex)
|
||||
{
|
||||
throw new AggregateException(
|
||||
string.Format("One or more exceptions occured while trying to load types from assembly {0}", assembly.FullName),
|
||||
ex.LoaderExceptions);
|
||||
}
|
||||
throw new TypeArgumentException("Must not be abstract.", nameof(TImplementation));
|
||||
}
|
||||
|
||||
SortTypes();
|
||||
|
||||
if (AssemblyAdded != null)
|
||||
var interfaceType = typeof(TInterface);
|
||||
if (!overwrite && ResolveTypes.ContainsKey(interfaceType))
|
||||
{
|
||||
AssemblyAdded.Invoke();
|
||||
throw new InvalidOperationException(
|
||||
string.Format("Attempted to register already registered interface {0}. New implementation: {1}, Old implementation: {2}",
|
||||
interfaceType, typeof(TImplementation), ResolveTypes[interfaceType]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add extra assemblies to IoC's known types.
|
||||
/// </summary>
|
||||
public static void AddAssemblies(params Assembly[] args)
|
||||
{
|
||||
AddAssemblies(args.AsEnumerable());
|
||||
ResolveTypes[interfaceType] = typeof(TImplementation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,57 +82,21 @@ namespace SS14.Shared.IoC
|
||||
/// </summary>
|
||||
public static void Clear()
|
||||
{
|
||||
AssemblyAdded = null;
|
||||
|
||||
foreach (var service in Services.Values.OfType<IDisposable>().Distinct())
|
||||
{
|
||||
service.Dispose();
|
||||
}
|
||||
Services.Clear();
|
||||
ServiceTypes.Clear();
|
||||
ResolveTypes.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort all resolvable types.
|
||||
/// Existing services do not get updated.
|
||||
/// Resolve a dependency manually.
|
||||
/// </summary>
|
||||
public static void SortTypes()
|
||||
{
|
||||
ResolveTypes.Clear();
|
||||
// Cache of interface = last resolved priority to make sorting easier.
|
||||
// Yeah I could sort with LINQ but fuck that.
|
||||
var resolvedPriorities = new Dictionary<Type, int>();
|
||||
|
||||
// TODO: handle types with multiple implemented interfaces in a special way?
|
||||
foreach (var type in ServiceTypes)
|
||||
{
|
||||
var attribute = (IoCTargetAttribute)Attribute.GetCustomAttribute(type, typeof(IoCTargetAttribute));
|
||||
if (attribute == null || attribute.Disabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (var interfaceType in type.GetInterfaces())
|
||||
{
|
||||
if (interfaceType.GetInterfaces().Any(t => t == typeof(IIoCInterface)))
|
||||
{
|
||||
if (resolvedPriorities.ContainsKey(interfaceType) && resolvedPriorities[interfaceType] >= attribute.Priority)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
resolvedPriorities[interfaceType] = attribute.Priority;
|
||||
ResolveTypes[interfaceType] = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolve a static instance of the highest priority implementation of an interface.
|
||||
/// see <see cref="NewType"/> if you want to resolve a NEW instance.
|
||||
/// </summary>
|
||||
public static T Resolve<T>() where T : IIoCInterface
|
||||
/// <exception cref="MissingImplementationException">Thrown if the interface was not registered beforehand.</exception>
|
||||
/// <exception cref="NoPublicConstructorException">Thrown if the resolved implementation does not have a public constructor.</exception>
|
||||
/// <exception cref="CircularDependencyException">Thrown if the type is already being built. This usually means a circular dependency exists.</exception>
|
||||
public static T Resolve<T>()
|
||||
{
|
||||
Type type = typeof(T);
|
||||
if (!Services.ContainsKey(type))
|
||||
@@ -129,32 +108,21 @@ namespace SS14.Shared.IoC
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves an IoC target's type, not a static instance.
|
||||
/// Build the implementation for an interface.
|
||||
/// Registers the built implementation so that it can be directly indexed.
|
||||
/// </summary>
|
||||
private static Type ResolveType<T>() where T : IIoCInterface
|
||||
/// <param name="type">The interface to build.</param>
|
||||
private static void BuildType(Type type)
|
||||
{
|
||||
return ResolveType(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves a target's type without compile time enforcement.
|
||||
/// Do not use this outside reflection!
|
||||
/// </summary>
|
||||
private static Type ResolveType(Type type)
|
||||
{
|
||||
if (!ResolveTypes.ContainsKey(type))
|
||||
if (!ResolveTypes.TryGetValue(type, out Type concreteType))
|
||||
{
|
||||
throw new MissingImplementationException(type);
|
||||
}
|
||||
return ResolveTypes[type];
|
||||
}
|
||||
|
||||
private static void BuildType(Type type)
|
||||
{
|
||||
Type concreteType = ResolveType(type);
|
||||
if (concreteType == null)
|
||||
// We're already building this, this means circular dependency!
|
||||
if (CurrentlyBuilding.Contains(concreteType))
|
||||
{
|
||||
throw new MissingImplementationException(type);
|
||||
throw new CircularDependencyException(type);
|
||||
}
|
||||
|
||||
// See if we already have an valid instance but registered as a different type.
|
||||
@@ -176,11 +144,6 @@ namespace SS14.Shared.IoC
|
||||
throw new NoPublicConstructorException(concreteType);
|
||||
}
|
||||
|
||||
if (CurrentlyBuilding.Contains(concreteType))
|
||||
{
|
||||
throw new CircularDependencyException(type);
|
||||
}
|
||||
|
||||
CurrentlyBuilding.Add(concreteType);
|
||||
|
||||
try
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using SS14.Shared.Interfaces.Log;
|
||||
using SS14.Shared.Interfaces.Log;
|
||||
using SS14.Shared.IoC;
|
||||
using System;
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace SS14.Shared.Log
|
||||
/// <summary>
|
||||
/// Generic logger. Dumps to <see cref="System.Console"/> and that's it.
|
||||
/// </summary>
|
||||
[IoCTarget]
|
||||
public class LogManager : ILogManager
|
||||
{
|
||||
#region ILogManager Members
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace SS14.Shared.Prototypes
|
||||
/// <summary>
|
||||
/// Handle storage and loading of YAML prototypes.
|
||||
/// </summary>
|
||||
public interface IPrototypeManager : IIoCInterface
|
||||
public interface IPrototypeManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain type.
|
||||
@@ -24,7 +24,7 @@ namespace SS14.Shared.Prototypes
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
IEnumerable<T> EnumeratePrototypes<T>() where T: class, IPrototype;
|
||||
IEnumerable<T> EnumeratePrototypes<T>() where T : class, IPrototype;
|
||||
/// <summary>
|
||||
/// Return an IEnumerable to iterate all prototypes of a certain type.
|
||||
/// </summary>
|
||||
@@ -38,7 +38,7 @@ namespace SS14.Shared.Prototypes
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if the type of prototype is not registered.
|
||||
/// </exception>
|
||||
T Index<T>(string id) where T: class, IIndexedPrototype;
|
||||
T Index<T>(string id) where T : class, IIndexedPrototype;
|
||||
/// <summary>
|
||||
/// Index for a <see cref="IIndexedPrototype"/> by ID.
|
||||
/// </summary>
|
||||
@@ -76,7 +76,6 @@ namespace SS14.Shared.Prototypes
|
||||
}
|
||||
}
|
||||
|
||||
[IoCTarget]
|
||||
public class PrototypeManager : IPrototypeManager
|
||||
{
|
||||
private readonly IReflectionManager ReflectionManager;
|
||||
@@ -86,7 +85,7 @@ namespace SS14.Shared.Prototypes
|
||||
private readonly Dictionary<Type, List<IPrototype>> prototypes = new Dictionary<Type, List<IPrototype>>();
|
||||
private readonly Dictionary<Type, Dictionary<string, IIndexedPrototype>> indexedPrototypes = new Dictionary<Type, Dictionary<string, IIndexedPrototype>>();
|
||||
|
||||
public IEnumerable<T> EnumeratePrototypes<T>() where T: class, IPrototype
|
||||
public IEnumerable<T> EnumeratePrototypes<T>() where T : class, IPrototype
|
||||
{
|
||||
return prototypes[typeof(T)].Select((IPrototype p) => p as T);
|
||||
}
|
||||
@@ -96,7 +95,7 @@ namespace SS14.Shared.Prototypes
|
||||
return prototypes[type];
|
||||
}
|
||||
|
||||
public T Index<T>(string id) where T: class, IIndexedPrototype
|
||||
public T Index<T>(string id) where T : class, IIndexedPrototype
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -203,7 +202,7 @@ namespace SS14.Shared.Prototypes
|
||||
public PrototypeManager(IReflectionManager reflectionManager)
|
||||
{
|
||||
ReflectionManager = reflectionManager;
|
||||
IoCManager.AssemblyAdded += ReloadPrototypeTypes;
|
||||
reflectionManager.OnAssemblyAdded += (_, __) => ReloadPrototypeTypes();
|
||||
ReloadPrototypeTypes();
|
||||
}
|
||||
|
||||
@@ -264,11 +263,19 @@ namespace SS14.Shared.Prototypes
|
||||
[Serializable]
|
||||
public class PrototypeLoadException : Exception
|
||||
{
|
||||
public PrototypeLoadException() {}
|
||||
public PrototypeLoadException(string message) : base(message) {}
|
||||
public PrototypeLoadException(string message, Exception inner) : base(message, inner) {}
|
||||
public PrototypeLoadException()
|
||||
{
|
||||
}
|
||||
public PrototypeLoadException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
public PrototypeLoadException(string message, Exception inner) : base(message, inner)
|
||||
{
|
||||
}
|
||||
|
||||
public PrototypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context) {}
|
||||
public PrototypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user