public void Execute(Entity entity, int index, [ReadOnly] ref NetworkIdComponent netId) { commandBuffer.AddComponent(entity, new LevelRequestedTag()); rpcQueue.Schedule(rpcBuffer[entity], new RpcLoadLevel { width = level[0].width, height = level[0].height }); }
public void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent state) { if (state.targetEntity == Entity.Null) { if (shoot != 0) { rpcQueue.Schedule(rpcBuffer[entity], new RpcSpawn()); } } else { // If ship, store commands in network command buffer // FIXME: when destroying the ship is in a command buffer this no longer works if (shipState.Exists(state.targetEntity)) // There might be a pending set to null { shipState[state.targetEntity] = new ShipStateComponentData(thrust, true); } if (inputFromEntity.Exists(state.targetEntity)) { var input = inputFromEntity[state.targetEntity]; input.AddCommandData(new ShipCommandData { tick = inputTargetTick, left = left, right = right, thrust = thrust, shoot = shoot }); } } }
public void Execute(Entity entity, int index, ref PlayerReadyComponent state) { GameDebug.Assert(ConnectionEntity.Length == 1, "Only one connection per client supported"); var connectionEntity = ConnectionEntity[0]; RpcQueue.Schedule(RpcBuffer[connectionEntity], new RpcPlayerReady()); CommandBuffer.DestroyEntity(entity); CommandBuffer.AddComponent <NetworkStreamInGame>(ConnectionEntity[0]); }
public void SendMessage(string message) { var connectionEntity = GetSingletonEntity <NetworkIdComponent>(); m_RpcChatQueue.Schedule(EntityManager.GetBuffer <OutgoingRpcDataStreamBufferComponent>(connectionEntity), new RpcChatMessage { Message = new NativeString512(message) }); }
public void Execute(Entity entity, int index, ref RemoteCommandComponent state) { GameDebug.Assert(ConnectionEntity.Length == 1, "Only one connection per client supported"); var connectionEntity = ConnectionEntity[0]; RpcQueue.Schedule(RpcBuffer[connectionEntity], new RpcRemoteCommand { Command = state.Command }); CommandBuffer.DestroyEntity(entity); }
public void Execute(Entity entity, int index, ref PlayerSettingsComponent state) { GameDebug.Assert(ConnectionEntity.Length == 1, "Only one connection per client supported"); var connectionEntity = ConnectionEntity[0]; RpcQueue.Schedule(RpcBuffer[connectionEntity], new RpcPlayerSetup { TeamId = state.TeamId, CharacterType = state.CharacterType, PlayerName = state.PlayerName }); CommandBuffer.DestroyEntity(entity); }
public void Execute(Entity entity, int index, [ReadOnly] ref LevelLoadRequest request) { commandBuffer.DestroyEntity(index, entity); // Check for disconnects if (!rpcFromEntity.Exists(request.connection)) { return; } // set the level size - fake loading of level levelFromEntity[levelSingleton] = new LevelComponent { width = request.width, height = request.height }; commandBuffer.AddComponent(index, request.connection, new PlayerStateComponentData()); rpcQueue.Schedule(rpcFromEntity[request.connection], new RpcLevelLoaded()); }
public void Execute(Entity entity, int index, [ReadOnly] ref LevelLoadRequest request, [ReadOnly] ref ReceiveRpcCommandRequestComponent requestSource) { commandBuffer.DestroyEntity(index, entity); // Check for disconnects if (!rpcFromEntity.Exists(requestSource.SourceConnection)) { return; } // set the level size - fake loading of level levelFromEntity[levelSingleton] = new LevelComponent { width = request.width, height = request.height, playerForce = request.playerForce, bulletVelocity = request.bulletVelocity }; commandBuffer.AddComponent(index, requestSource.SourceConnection, new PlayerStateComponentData()); commandBuffer.AddComponent(index, requestSource.SourceConnection, default(NetworkStreamInGame)); rpcQueue.Schedule(rpcFromEntity[requestSource.SourceConnection], new RpcLevelLoaded()); }
public unsafe void Execute(Entity entity, int index, [ReadOnly] ref PlayerStateComponentData state) { // FIXME: ack and sending command stream should be handled by a different system DataStreamWriter writer = new DataStreamWriter(128, Allocator.Temp); var buffer = cmdBuffer[entity]; var ack = ackSnapshot[entity]; writer.Write((byte)NetworkStreamProtocol.Command); writer.Write(ack.LastReceivedSnapshotByLocal); writer.Write(ack.ReceivedSnapshotByLocalMask); writer.Write(localTime); writer.Write(ack.LastReceivedRemoteTime - (localTime - ack.LastReceiveTimestamp)); if (state.PlayerShip == Entity.Null) { if (shoot != 0) { rpcQueue.Schedule(rpcBuffer[entity], new RpcSpawn()); } } else { writer.Write(inputTargetTick); writer.Write(left); writer.Write(right); writer.Write(thrust); writer.Write(shoot); // If ship, store commands in network command buffer /*input = new PlayerInputComponentData(left, right, thrust, shoot);*/ // FIXME: when destroying the ship is in a command buffer this no longer works if (shipState.Exists(state.PlayerShip)) // There might be a pending set to null { shipState[state.PlayerShip] = new ShipStateComponentData(thrust, true); } } buffer.ResizeUninitialized(writer.Length); byte *ptr = (byte *)buffer.GetUnsafePtr(); UnsafeUtility.MemCpy(buffer.GetUnsafePtr(), writer.GetUnsafeReadOnlyPtr(), writer.Length); }
public void Execute(Entity entity, int index, [ReadOnly] ref NetworkStreamConnection connection) { if (!connection.Value.IsCreated) { return; } // Send RPC - assign network id int nid; if (!freeNetworkIds.TryDequeue(out nid)) { // Avoid using 0 nid = numNetworkId[0] + 1; numNetworkId[0] = nid; } commandBuffer.AddComponent(entity, new NetworkIdComponent { Value = nid }); rpcQueue.Schedule(rpcBuffer[entity], new RpcSetNetworkId { nid = nid }); }