public void AddCommandRequest <TRequest>(TRequest receivedRequest) where TRequest : struct, IReceivedCommandRequest { var commandClass = ComponentDatabase.GetCommandMetaclassFromReceivedRequest <TRequest>(); CurrentDiff.AddCommandRequest(receivedRequest, commandClass.ComponentId, commandClass.CommandIndex); }
/// <summary> /// Removes a component snapshot from the EntityTemplate, if it exists. /// </summary> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> public void RemoveComponent <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { var id = ComponentDatabase.GetSnapshotComponentId <TSnapshot>(); entityData.Remove(id); acl.RemoveComponentWriteAccess(id); }
/// <summary> /// Attempts to get a component snapshot stored in the EntityTemplate. /// </summary> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> /// <returns>The component snapshot, if the component snapshot exists, null otherwise.</returns> public TSnapshot?GetComponent <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { if (entityData.TryGetValue(ComponentDatabase.GetSnapshotComponentId <TSnapshot>(), out var snapshot)) { return((TSnapshot)snapshot); } return(null); }
/// <summary> /// Gets the SpatialOS component snapshot if present. /// </summary> /// <returns> The component snapshot, if it exists, or null otherwise.</returns> /// <typeparam name="T">The component type.</typeparam> public T?GetComponentSnapshot <T>() where T : struct, ISpatialComponentSnapshot { var id = ComponentDatabase.GetSnapshotComponentId <T>(); if (components.TryGetValue(id, out var data)) { return((T)data); } return(null); }
/// <summary>Gets the component of the associated type.</summary> /// <param name="component"> /// When this method returns, contains the component, if the component is found; otherwise, the default value <see cref="TSnapshot"/>. This parameter is passed uninitialized. /// </param> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> /// <returns> /// True if this contains a component of type <see cref="TSnapshot"/>; otherwise, false. /// </returns> public bool TryGetComponent <TSnapshot>(out TSnapshot component) where TSnapshot : struct, ISpatialComponentSnapshot { if (entityData.TryGetValue(ComponentDatabase.GetSnapshotComponentId <TSnapshot>(), out var boxedComponent)) { component = (TSnapshot)boxedComponent; return(true); } component = default; return(false); }
public void GenerateResponse <TRequest, TResponse>(CommandRequestId id, Func <CommandRequestId, TRequest, TResponse> creator) where TRequest : ICommandRequest where TResponse : struct, IReceivedCommandResponse { if (!outgoingRequests.TryGetValue(id.Raw, out var request)) { throw new ArgumentException($"Could not find a request with request id {id}"); } var commandClass = ComponentDatabase.GetCommandMetaclassFromRequest <TRequest>(); if (typeof(TResponse) != commandClass.ReceivedResponse) { throw new ArgumentException($"Invalid response type {typeof(TResponse)}, expected {commandClass.ReceivedResponse}"); } CurrentDiff.AddCommandResponse(creator(id, (TRequest)request), commandClass.ComponentId, commandClass.CommandIndex); requestIds[typeof(TRequest)].Remove(id.Raw); outgoingRequests.Remove(id.Raw); }
public void GenerateResponses <TRequest, TResponse>(Func <CommandRequestId, TRequest, TResponse> creator) where TRequest : ICommandRequest where TResponse : struct, IReceivedCommandResponse { var ids = GetOutboundCommandRequests <TRequest>(); var commandClass = ComponentDatabase.GetCommandMetaclassFromRequest <TRequest>(); if (typeof(TResponse) != commandClass.ReceivedResponse) { throw new ArgumentException($"Invalid response type {typeof(TResponse)}, expected {commandClass.ReceivedResponse}"); } foreach (var id in ids) { var request = outgoingRequests[id.Raw]; CurrentDiff.AddCommandResponse(creator(id, (TRequest)request), commandClass.ComponentId, commandClass.CommandIndex); outgoingRequests.Remove(id.Raw); } requestIds[typeof(TRequest)].Clear(); }
// TODO: Make ref readonly when we have a dictionary type with ref indexing semantics. public T GetComponent <T>(EntityId entityId) where T : struct, ISpatialComponentSnapshot { if (!HasComponent <T>(entityId)) { throw new ArgumentException($"The view does not have entity with Entity ID: {entityId.Id} and component with ID: {ComponentDatabase.GetSnapshotComponentId<T>()}"); } var storage = (IViewComponentStorage <T>)typeToViewStorage[typeof(T)]; return(storage.GetComponent(entityId.Id)); }
/// <summary> /// Sets the write access worker attribute for a given component. /// </summary> /// <param name="writeAccess">The write access worker attribute.</param> /// <typeparam name="TSnapshot">The type of the component.</typeparam> public void SetComponentWriteAccess <TSnapshot>(string writeAccess) where TSnapshot : struct, ISpatialComponentSnapshot { SetComponentWriteAccess(ComponentDatabase.GetSnapshotComponentId <TSnapshot>(), writeAccess); }
/// <summary> /// Retrieves the write access worker attribute for a given component. /// </summary> /// <typeparam name="TSnapshot">The type of the component.</typeparam> /// <returns>The write access worker attribute, if it exists, null otherwise.</returns> public string GetComponentWriteAccess <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { return(GetComponentWriteAccess(ComponentDatabase.GetSnapshotComponentId <TSnapshot>())); }
/// <summary> /// Checks if a component snapshot is stored in the EntityTemplate. /// </summary> /// <typeparam name="TSnapshot">The type of the component snapshot.</typeparam> /// <returns>True, if the component snapshot exists, false otherwise.</returns> public bool HasComponent <TSnapshot>() where TSnapshot : struct, ISpatialComponentSnapshot { return(HasComponent(ComponentDatabase.GetSnapshotComponentId <TSnapshot>())); }