Example #1
0
 public ClientConsole(
     ILogShipping logShipping,
     IConsoleInput consoleInput,
     IConsoleRender consoleRender)
 {
     _logShipping   = logShipping;
     _consoleInput  = consoleInput;
     _consoleRender = consoleRender;
 }
 public ConsoleLogShippingEngineHook(
     IRemoteClient remoteClient,
     ICoroutine coroutine,
     ILogShipping logShipping)
 {
     _remoteClient = remoteClient;
     _coroutine    = coroutine;
     _logShipping  = logShipping;
 }
Example #3
0
        public HostedGameRunner(
            ICoreGame game,
            ILogShipping logShipping,
            Api.Version1.Core.IConsoleHandle consoleHandle,
            ISharedRendererClientFactory sharedRendererClientFactory,
            IWantsUpdateSignal[] wantsUpdateSignals,
            IEditorClientProvider editorClientProvider)
        {
            _game          = game;
            _logShipping   = logShipping;
            _consoleHandle = consoleHandle;
            _sharedRendererClientFactory = sharedRendererClientFactory;
            _wantsUpdateSignals          = wantsUpdateSignals;
            _gameHosterClient            = editorClientProvider.GetClient <GameHosterClient>();

            State    = LoadedGameState.Loaded;
            _playing = false;
        }
Example #4
0
        public void LoadFromPath(
            IConsoleHandle consoleHandle,
            IBaseDirectory baseDirectory,
            IBackBufferDimensions backBufferDimensions,
            string gameAssembly)
        {
            // Wrap the backbuffer dimensions service in a proxy, since GraphicsDevice can not
            // cross the AppDomain boundary.
            backBufferDimensions = new BackBufferDimensionsProxy(backBufferDimensions);

            // Load the target assembly.
            consoleHandle.LogDebug("Loading game assembly from " + gameAssembly + "...");
            var assembly = Assembly.LoadFrom(gameAssembly);

            consoleHandle.LogDebug("Constructing standard kernel...");
            var kernel = new StandardKernel();

            kernel.Bind <IRawLaunchArguments>()
            .ToMethod(x => new DefaultRawLaunchArguments(new string[0]))
            .InSingletonScope();

            // Bind our extension hook first so that it runs before everything else.
            kernel.Bind <IEngineHook>().To <ExtensionEngineHook>().InSingletonScope();

            Func <System.Reflection.Assembly, Type[]> TryGetTypes = a =>
            {
                try
                {
                    return(a.GetTypes());
                }
                catch
                {
                    return(new Type[0]);
                }
            };

            consoleHandle.LogDebug("Finding configuration classes in " + gameAssembly + "...");
            var typeSource = new List <Type>();

            foreach (var attribute in assembly.GetCustomAttributes(false))
            {
                if (attribute.GetType().FullName == "Protogame.ConfigurationAttribute")
                {
                    typeSource.Add(((ConfigurationAttribute)attribute).GameConfigurationOrServerClass);
                }
            }

            if (typeSource.Count == 0)
            {
                // Scan all types to find implementors of IGameConfiguration
                typeSource.AddRange(from type in TryGetTypes(assembly)
                                    select type);
            }

            consoleHandle.LogDebug("Found {0} configuration classes in " + gameAssembly, typeSource.Count);

            consoleHandle.LogDebug("Constructing game configurations...");
            var gameConfigurations = new List <IGameConfiguration>();

            foreach (var type in typeSource)
            {
                if (typeof(IGameConfiguration).IsAssignableFrom(type) &&
                    !type.IsInterface && !type.IsAbstract)
                {
                    gameConfigurations.Add(Activator.CreateInstance(type) as IGameConfiguration);
                }
            }

            ICoreGame game = null;
            var       hasBoundNewEventEngine = false;

            consoleHandle.LogDebug("Configuring kernel and constructing game instance ({0} configurations)...", gameConfigurations.Count);
            foreach (var configuration in gameConfigurations)
            {
                consoleHandle.LogDebug("Configuring with {0}...", configuration.GetType().FullName);

                configuration.ConfigureKernel(kernel);

                // Rebind services so the game renders correctly inside the editor.
                kernel.Rebind <IBaseDirectory>().ToMethod(x => baseDirectory).InSingletonScope();
                kernel.Rebind <IBackBufferDimensions>().ToMethod(x => backBufferDimensions).InSingletonScope();
                kernel.Rebind <IDebugRenderer>().To <DefaultDebugRenderer>().InSingletonScope();
                var bindings = kernel.GetCopyOfBindings();
                var mustBindNewEventEngine = false;
                if (bindings.ContainsKey(typeof(IEngineHook)))
                {
                    if (bindings[typeof(IEngineHook)].Any(x => x.Target == typeof(EventEngineHook)))
                    {
                        mustBindNewEventEngine = !hasBoundNewEventEngine;
                        kernel.UnbindSpecific <IEngineHook>(x => x.Target == typeof(EventEngineHook));
                    }

                    if (mustBindNewEventEngine)
                    {
                        kernel.Bind <IEngineHook>().ToMethod(ctx =>
                        {
                            _editorEventEngineHook = ctx.Kernel.Get <EditorEventEngineHook>(ctx.Parent);
                            return(_editorEventEngineHook);
                        }).InSingletonScope();
                    }
                }

                if (game == null)
                {
                    game = configuration.ConstructGame(kernel);
                }
            }

            if (game != null)
            {
                consoleHandle.LogDebug("Game instance is {0}", game.GetType().FullName);
            }

            _game          = game;
            _logShipping   = kernel.Get <ILogShipping>();
            _consoleHandle = consoleHandle;

            consoleHandle.LogDebug("LoadFromPath complete");
        }
Example #5
0
 public ServerConsole(ILogShipping logShipping)
 {
     _logShipping = logShipping;
 }