Ejemplo n.º 1
0
        /// <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 = DynamicSnapshot.GetSnapshotComponentId <TSnapshot>();

            entityData.Remove(id);
            acl.RemoveComponentWriteAccess(id);
        }
Ejemplo n.º 2
0
        /// <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(DynamicSnapshot.GetSnapshotComponentId <TSnapshot>(), out var snapshot))
            {
                return((TSnapshot)snapshot);
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Get 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 = DynamicSnapshot.GetSnapshotComponentId <T>();

            if (components.TryGetValue(id, out var data))
            {
                return((T)data);
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Creates an <see cref="Entity" /> instance from this template.
        /// </summary>
        /// <remarks>
        ///     This function allocates native memory. The <see cref="Entity" /> returned from this function should
        ///     be handed to a GDK API, which will take ownership, or otherwise must be disposed of manually.
        /// </remarks>
        /// <returns>The Entity object.</returns>
        public Entity GetEntity()
        {
            ValidateEntity();
            var handler = new EntityTemplateDynamicHandler(entityData);

            DynamicSnapshot.ForEachSnapshotComponent(handler);
            var entity = handler.Entity;

            entity.Add(acl.Build());
            return(entity);
        }
Ejemplo n.º 5
0
        internal EntityQuerySnapshot(Entity entitySnapshot)
        {
            components = new Dictionary <uint, ISpatialComponentSnapshot>();

            var componentDataHandler = new ComponentDataHandler
            {
                EntitySnapshot = entitySnapshot,
                Components     = components,
            };

            foreach (var componentId in entitySnapshot.GetComponentIds())
            {
                DynamicSnapshot.ForSnapshotComponent(componentId, componentDataHandler);
            }
        }
Ejemplo n.º 6
0
        // 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: {DynamicSnapshot.GetSnapshotComponentId<T>()}");
            }

            var storage = (IViewComponentStorage <T>)typeToViewStorage[typeof(T)];

            return(storage.GetComponent(entityId.Id));
        }
Ejemplo n.º 7
0
 /// <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(DynamicSnapshot.GetSnapshotComponentId <TSnapshot>()));
 }
Ejemplo n.º 8
0
 /// <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(DynamicSnapshot.GetSnapshotComponentId <TSnapshot>(), writeAccess);
 }
Ejemplo n.º 9
0
 /// <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(DynamicSnapshot.GetSnapshotComponentId <TSnapshot>()));
 }