Exemplo n.º 1
0
 public WorldReplicationManager(
     ReplicationConfig config,
     WorldPlayers players,
     IEntityGridMap entityGridMap)
 {
     this._players                  = players ?? throw new ArgumentNullException(nameof(players));
     this._entityGridMap            = entityGridMap ?? throw new ArgumentNullException(nameof(entityGridMap));
     this._packetPriorityComponents = new ReplicationPriorityEntityComponents(config.Capacity.InitialReplicatedEntityCapacity);
     this._packetPriorityCalculator = new PacketPriorityCalculator(config.PacketPriority);
     this._entityBuffer             = new Entity[256];
 }
Exemplo n.º 2
0
        public GameWorld(
            WorldType worldType,
            WorldInstanceId id,
            ILogger logger,
            IServerConfig config,
            OutgoingServerChannel channelManager,
            IGameWorldLoader gameWorldLoader)
        {
            this.WorldType  = worldType;
            this.InstanceId = id;
            this._logger    = logger ?? throw new ArgumentNullException(nameof(logger));
            this._isStopped = false;
            this._world     = new World(config.Ecs);

            this._fixedTick = config.Simulation.FixedTick;

            this._channelManager = channelManager ?? throw new ArgumentNullException(nameof(channelManager));

            this._simulationSynchronizer = new SimulationSynchronizer(this._world);
            this._entityGridMap          = new EntityGridMap(config.Replication.GridSize);

            this._players = new WorldPlayers(
                config.Replication,
                config.PlayerInput,
                config.PlayerConnection.Capacity.InitialConnectionsCapacity);

            this._replicationManager = new WorldReplicationManager(config.Replication, this._players, this._entityGridMap);

            this._physicsWorld = new VolatilePhysicsWorld(config.Replication.PhysicsHistoryCount);

            this._systems =
                new Systems(this._world)
                .Add(new PhysicsSystem())
                .Add(new ServerEntityReplicationSystem())
                .Add(new JiggleSystem())
                .Inject(this._physicsWorld)
                .Inject(new ReplicationDataBroker(config.Replication.Capacity, this._replicationManager))
                .Inject(this._entityGridMap);

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

            this._simulation.Create();

            gameWorldLoader.LoadWorld(this.WorldType, this._world, this._physicsWorld);
        }