/// <summary> /// Constructor. /// </summary> /// <param name="clientNetworkConnections">The sequence of network connections that could be connected to clients (but probably aren't yet). /// This defines the maximum number of clients. These clients can connect/disconnect on the fly and the server will monitor their state and update accordingly.</param> /// <param name="maxEntityHistory">The maximum number of <see cref="EntitySnapshot"/> that will be remembered for the server's history. /// One snapshot is taken each frame so this number is effectively "the last N frames" of history.</param> /// <param name="entityCapacity">The maximum number of entities the world can have.</param> /// <param name="componentsDefinition">The definition of components that are supported.</param> /// <param name="systems">The collection of server systems used to update the world's state on the server.</param> /// <param name="updateCommandingEntityID">The delegate to update a client's commanding entity ID every frame. /// The first bool is whether the client is connected. The second integer is the current commanding entity ID.</param> public GameServer(IList <INetworkConnection> clientNetworkConnections, int maxEntityHistory, int entityCapacity, ComponentsDefinition componentsDefinition, IEnumerable <IServerSystem> systems, Func <bool, int, int> updateCommandingEntityID) { this.updateCommandingEntityID = updateCommandingEntityID; this.EntityArray = new EntityArray(entityCapacity, componentsDefinition); this.SystemArray = new ServerSystemArray(systems); // Populate the entire history buffer with data that will be overwritten as needed this.entitySnapshotHistory = new Queue <EntitySnapshot>(); for (int i = 0; i < maxEntityHistory; i++) { this.entitySnapshotHistory.Enqueue(new EntitySnapshot(entityCapacity, componentsDefinition)); } // Create all the client proxies now, bound directly to the client network connections this.clients = new ClientProxy[clientNetworkConnections.Count]; for (int clientID = 0; clientID < clientNetworkConnections.Count; clientID++) { this.clients[clientID] = new ClientProxy(this, clientNetworkConnections[clientID]); } }
/// <summary> /// Constructor. /// </summary> /// <param name="capacity">The maximum number of entities that can exist.</param> /// <param name="componentsDefinition">The definition for the various component types that can be added to entities.</param> public EntityArray(int capacity, ComponentsDefinition componentsDefinition) { this.Capacity = capacity; this.entityStates = new EntityState[this.Capacity]; this.componentArrays = componentsDefinition.CreateComponentArrays(this.Capacity); }
/// <summary> /// Constructor. /// </summary> public EntitySnapshot(int entityCapacity, ComponentsDefinition componentsDefinition) { this.ServerFrameTick = -1; this.EntityArray = new EntityArray(entityCapacity, componentsDefinition); }
/// <summary> /// Constructor. /// </summary> public GameClient(INetworkConnection serverNetworkConnection, int maxEntityHistory, int entityCapacity, ComponentsDefinition componentsDefinition, IEnumerable <IClientSystem> systems) { this.serverNetworkConnection = serverNetworkConnection; this.SystemArray = new ClientSystemArray(systems); // Create the snapshots that will need to be mutated/updates, these need to be separately created to avoid accidentally mutating another snapshot reference this.InterpolationStartSnapshot = new EntitySnapshot(entityCapacity, componentsDefinition); this.InterpolationEndSnapshot = new EntitySnapshot(entityCapacity, componentsDefinition); this.RenderedSnapshot = new EntitySnapshot(entityCapacity, componentsDefinition); // Populate the entire history buffer with data that will be overwritten as needed this.entitySnapshotHistory = new EntitySnapshot[maxEntityHistory]; for (int i = 0; i < this.entitySnapshotHistory.Length; i++) { this.entitySnapshotHistory[i] = new EntitySnapshot(entityCapacity, componentsDefinition); } this.clientCommandHistory = new Queue <ClientCommand <TCommandData> >(); for (int i = 0; i < ClientCommand <TCommandData> .MaxClientCommandsPerUpdate; i++) { this.clientCommandHistory.Enqueue(new ClientCommand <TCommandData>()); } }