Exemplo n.º 1
0
        static void Main(string[] args)
        {
            using var game = new GameBootstrap();
            game.GameEntity.Set(new GameName("HelloWorld"));
            // 'Inject' the configuration data that will be used for 'CreateEntityThatWillPrintSystem'
            game.Global.Context.BindExisting(new PrintConfiguration
            {
                TextsToPrint = new []
                {
                    "Hello World!",
                    "Press any key to exit the application."
                }
            });

            // Once we've added all required data, setup the game...
            game.Setup();

            while (game.Loop())
            {
                Thread.Sleep(10);

                // If the user type something, quit the game
                if (Console.Read() != 0)
                {
                    game.CancellationTokenSource.Cancel();
                }
            }
        }
Exemplo n.º 2
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.R))
     {
         m_gameBootstrap?.Dispose();
         m_gameBootstrap = new GameBootstrap();
     }
 }
Exemplo n.º 3
0
 private void Start()
 {
     m_gameFactory = Instantiate(m_gameFactory);
     m_gameFactory.BulletFactory.CorrutineHandle = FactoryCorrutine;
     m_gameFactory.PlayerFactory.CorrutineHandle = FactoryCorrutine;
     m_gameFactory.ObjectFactory.CorrutineHandle = FactoryCorrutine;
     m_gameBootstrap = new GameBootstrap();
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var runtime = DefaultApplication.Build().Bootstrap
                          (
                new GameDisplayablesServices(),
                new GameServices(),
                new CommandServices(),

                new LexiconServices(),
                new NlpServices(),
                new DeterminationServices(),
                new IteratorServices(),
                new ComDisplayablesServices()
                          );

            var commandBootstrap = new CommandBootstrap(runtime);

            var gameBootstrap = new GameBootstrap(runtime);

            commandBootstrap.Initiate();

            gameBootstrap.Initiate();

            string stringInput;

            do
            {
                Console.Write(@"> ");
                stringInput = Console.ReadLine();

                var successfulDetermination = commandBootstrap.BootstrapCommandDetermination(stringInput);

                if (successfulDetermination)
                {
                    var commandResultListener   = runtime.Container.Resolve <ResultListener>();
                    var commandResultSubscriber = runtime.Container.Resolve <ResultSubscriber>(new TypedParameter(typeof(ResultListener), commandResultListener));

                    commandResultSubscriber.Subscribe(commandBootstrap.GetCommandResultModelHandlerForGame());

                    commandBootstrap.BootstrapCommandResult();

                    commandResultSubscriber.Unsubscribe();

                    if (commandResultListener.GetObjectThatWasChanged() != null)
                    {
                        gameBootstrap.ProcessCommand(commandResultListener.GetObjectThatWasChanged(), commandResultListener.GetPropsThatWereChanged());
                    }
                    else
                    {
                        Debug.WriteLine("ERROR: Listener didn't capture any command result model that was changed.");
                    }
                }
            } while (stringInput != null && stringInput.ToLower() != "exit");
        }
Exemplo n.º 5
0
        public void CreateGame()
        {
            using (var game = new GameBootstrap())
            {
                game.GameEntity.Set(new GameName("GameTest"));
                game.CancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(0.1));
                game.Setup();
                while (game.Loop())
                {
                }
            }

            Assert.Pass();
        }
Exemplo n.º 6
0
 private void Awake()
 {
     this.Owner = this.GetComponent <GameBootstrap>();
 }
Exemplo n.º 7
0
 static void Main(string[] args)
 {
     GameBootstrap.Run();
 }
Exemplo n.º 8
0
        public void Start()
        {
            using (var game = new GameBootstrap())
            {
                game.GameEntity.Set(new GameName("GameTest"));
                game.Global.World.CreateEntity()
                .Set <IFeature>(new ReceiveGameHostClientFeature(0));
                game.Setup();

                var rpcSystem = game.Global.Collection.GetOrCreate(wc => new RpcSystem(wc));
                rpcSystem.RegisterPacket <TestNotification>("Tests.TestNotification");
                rpcSystem.RegisterPacketWithResponse <TestRequestAdd, TestRequestAdd.Response>("Tests.TestRequestAdd");

                NetManager client = null;
                var        evL    = new RpcListener(game.Global.Collection.GetOrCreate(wc => new RpcLowLevelSystem(wc)));

                var clientState = new ClientState();
                evL.PeerConnected += args =>
                {
                    clientState.State        = ClientState.EState.Connect;
                    clientState.ClientEntity = args.clientEntity;
                };

                var serverState = new ServerState();

                for (var i = 0; i != 128; i++)
                {
                    game.Loop();

                    if (client == null && game.Global.Collection.TryGet(out StartGameHostListener listener) &&
                        listener.DependencyResolver.Dependencies.Count == 0)
                    {
                        client = new NetManager(evL);
                        client.Start();
                        client.Connect("127.0.0.1", listener.Server.Value.LocalPort, string.Empty);
                    }

                    if (clientState.State == ClientState.EState.Connect)
                    {
                        clientState.State = ClientState.EState.Connected;
                        rpcSystem.CreateNotification(new TestNotification {
                            Value = 42
                        }, clientState.ClientEntity);

                        clientState.Request = rpcSystem.CreateCall <TestRequestAdd, TestRequestAdd.Response>(new TestRequestAdd {
                            Left = 8, Right = 4
                        }, clientState.ClientEntity);
                        clientState.Subscribed = rpcSystem.CreateCall <TestRequestAdd, TestRequestAdd.Response>(new TestRequestAdd {
                            Left = 2, Right = 5
                        }, clientState.ClientEntity);

                        Console.WriteLine($"Request: {clientState.Request.Entity}, Subscribed: {clientState.Subscribed.Entity} (client: {clientState.ClientEntity})");

                        clientState.Subscribed.OnReply += packet =>
                        {
                            Assert.IsTrue(clientState.Request.Entity.Has <RpcSystem.DestroyOnProcessedTag>());

                            Assert.AreEqual(7, packet.Value.Result);
                            clientState.State = ClientState.EState.HasReply;

                            clientState.SuccessfulResponse++;
                        };
                    }

                    client?.PollEvents();
                    Thread.Sleep(1);

                    // If we read the response (and nobody subscribed to the entity) the entity shouldn't be alive after we read it.
                    if (clientState.Request.HasResponse)
                    {
                        Assert.IsTrue(clientState.Request.Entity.Has <RpcSystem.DestroyOnProcessedTag>());

                        // Doing that will remove the entity
                        Assert.AreEqual(12, clientState.Request.Response.Result);
                        Assert.IsFalse(clientState.Request.Entity.IsAlive);

                        clientState.SuccessfulResponse++;
                    }

                    // If we had a reply, and that we subscribed on it, the entity shouldn't be alive after the event has been triggered.
                    if (clientState.State == ClientState.EState.HasReply)
                    {
                        Assert.IsFalse(clientState.Subscribed.Entity.IsAlive);
                    }

                    using (var set = game.Global.World.GetEntities()
                                     .With <TestRequestAdd>()
                                     .With <RpcSystem.ClientRequestTag>()
                                     .AsSet())
                    {
                        foreach (var entity in set.GetEntities())
                        {
                            var prepareRpc = rpcSystem.PrepareReply <TestRequestAdd, TestRequestAdd.Response>(entity);
                            prepareRpc.ReplyWith(new TestRequestAdd.Response
                            {
                                Result = prepareRpc.Request.Left + prepareRpc.Request.Right
                            });
                        }
                    }

                    using (var set = game.Global.World.GetEntities()
                                     .With <TestNotification>()
                                     .Without <EntityRpcMultiHandler>()
                                     .AsSet())
                    {
                        if (set.Count == 1)
                        {
                            serverState.Notification = set.GetEntities()[0].Get <TestNotification>();
                        }
                    }
                }

                client?.Stop();

                if (game.Global.Collection.TryGet(out StartGameHostListener startGameHostListener))
                {
                    Assert.IsEmpty(startGameHostListener.DependencyResolver.Dependencies);

                    Assert.IsNotNull(startGameHostListener.Server.Value);
                    Assert.IsTrue(startGameHostListener.Server.Value.IsRunning);
                }
                else
                {
                    Assert.Fail();
                }

                Assert.IsFalse(serverState.Notification is null);
                Assert.AreEqual(42, serverState.Notification.Value.Value);                 // since it's a nullable, we should do Value.Value!
                Assert.AreEqual(2, clientState.SuccessfulResponse);

                game.CancellationTokenSource.Cancel();
            }

            Assert.Pass();
        }
Exemplo n.º 9
0
 public void Awake()
 {
     Owner = this.GetComponent <GameBootstrap>();
 }