Exemple #1
0
        public void TestAStar()
        {
            Map map = new Map();

            map.LoadMap(Path.Combine("Resources/Maps", "small.map"));
            Simulation sim = new ClientSimulation(map);
            Unit       u   = new UnitTrooper(new ObjectID(1, 1), GlobalSettings.Wrapper.Troopers[0], new Position(0, 0), map, sim);

            map.Units[0, 1].AddFirst(u);
            map.Units[1, 1].AddFirst(u);
            map.Units[2, 1].AddFirst(u);
            map.Units[3, 0].AddFirst(u);
            map.Units[4, 1].AddFirst(u);
            map.Units[3, 2].AddFirst(u);
            map.Units[4, 2].AddFirst(u);
            map.Units[3, 3].AddFirst(u);
            MapInput mi = new MapInput(map);

            mi.IsMoveable += new MapInput.MoveCheckDelegate(IsMoveable);
            mi.Start       = new Position(0, 0);
            mi.Goal        = new Position(15, 17);
            Queue <Position> path = AStar.Search <Position>(mi);

            if (path.Count != 0)
            {
                Console.WriteLine("OK");
            }
        }
Exemple #2
0
        public void TestSimulaton()
        {
            Simulation sim;
            Map        map = new Map();

            map.LoadMap(Path.Combine("Resources/Maps", "test.map"));
            sim            = new ClientSimulation(map);
            sim.onTurnEnd += new SimulationHandler(sim_onTurnEnd);
            sim.StartSimulation();

            int msgCount = 0;

            while (msgCount < 1000)
            {
                GameMessage gm = generate();
                gm.IdTurn = sim.CurrentTurn + 1 + rnd.Next(2 * sim.Delta);
                sim.AddGameMessage(gm);

                Thread.Sleep(rnd.Next(200));

                if (rnd.Next(4) == 0)
                {
                    s.WaitOne();
                    sim.DoTurn(1);
                }

                msgCount++;
            }
        }
Exemple #3
0
 protected override void TearDownGameScene()
 {
     base.TearDownGameScene();
     if (simulation != null)
     {
         simulation = null;
     }
 }
Exemple #4
0
    private void HandleJoinAccepted(NetCommand.JoinAccepted cmd)
    {
        Debug.Log("Server join successful!");

        // Create our player object and attach client-specific components.
        Debug.Log("Local player network ID is " + cmd.YourPlayerState.NetworkObjectState.NetworkId);
        localPlayer = AddPlayerFromInitialServerState(cmd.YourPlayerState, false);
        InitializeLocalPlayer();

        // Initialize simulation.
        simulation = new ClientSimulation(
            localPlayer, playerManager, networkObjectManager, this, bestServerLatency, cmd.WorldTick);

        // Create player objects for existing clients.
        foreach (var state in cmd.ExistingPlayerStates)
        {
            AddPlayerFromInitialServerState(state, true);
        }
    }
Exemple #5
0
        public void Rollback()
        {
            const float deltaTime      = 1f / 10f; // Running 10 FPS
            const float fixedDeltaTime = 1f / 5f;  // Fixed tick at 5 FPS

            var world = new World(EcsConfig.Default);

            var inputSystem    = new PlayerInputSystem();
            var movementSystem = new MovementSystem();

            var config = SimulationConfig.Default;

            config.FixedTick = fixedDeltaTime;

            var simulation = new ClientSimulation <SingletonInputComponent>(
                config: config,
                world: world,
                update:
                new Systems(world)
                .Add(inputSystem),
                fixedUpdate:
                new Systems(world)
                .Add(movementSystem));

            simulation.Create();

            var testDriver = new SimulationManagerTestDriver <SingletonInputComponent>(
                simulation,
                fixedDeltaTime);

            // Singleton input entity
            var entityInput = world.NewEntity();
            // Singleton player entity.
            var entityPlayer = world.NewEntity();

            entityPlayer.GetComponent <SingletonPlayerComponent>();
            ref var movement = ref entityPlayer.GetComponent <MovementComponent>();
Exemple #6
0
        public GameClient(
            ILogger logger,
            IJsonSerializer jsonSerializer,
            IClientConfig config)
        {
            this._logger = logger ?? throw new ArgumentNullException(nameof(logger));

            this._jitterBuffer            = new PacketJitterBuffer(this._logger, config.Jitter.Capacity);
            this._entityServerToClientMap = new NetworkEntityMap(config.Ecs.InitialEntityPoolCapacity);

            this._world        = new World(config.Ecs);
            this._physicsWorld = new VolatilePhysicsWorld(historyLength: config.Simulation.SnapShotCount);

            this._systems      = new Systems(this._world);
            this._fixedSystems =
                new Systems(this._world)
                .Add(new ClientEntityReplicationSystem())
                .Add(new PhysicsSystem())
                .Inject(this._world)
                .Inject(this._physicsWorld)
                .Inject(this._jitterBuffer)
                .Inject(this._entityServerToClientMap);

            this._simulation = new ClientSimulation <InputComponent>(
                config.Simulation,
                this._world,
                this._systems,
                this._fixedSystems);

            this._simulation.Create();

            this._server = new GameServerClient(
                this._logger,
                jsonSerializer,
                this._jitterBuffer,
                config.NetworkTransport);
        }