public Node CreateNode(EntityInternal entity) { Node node2; Node nodeInstance = Cache.GetNodeInstance(this.nodeClass); nodeInstance.Entity = entity; try { Collections.Enumerator <Type> enumerator = Collections.GetEnumerator <Type>(this.nodeDescription.Components); while (true) { if (!enumerator.MoveNext()) { node2 = nodeInstance; break; } Type current = enumerator.Current; this.SetComponent(nodeInstance, current, entity.GetComponent(current)); } } catch (Exception exception) { throw new ConvertEntityToNodeException(this.nodeClass, entity, exception); } return(node2); }
private void CreateEntity(Engine engine) { this._entity = this.GetOrCreateEntity(); this._entity.Name = !string.IsNullOrEmpty(this.EntityName) ? string.Empty : this.GetNameFromTemplate(); SharedEntityRegistry.SetShared(this.EntityId); this.Components.ForEach <Component>(c => this._entity.AddComponentSilent(c)); }
public EntityInternal Clone(string name, EntityInternal entity, EntityBuilder entityBuilder) { entityBuilder.SetName(name); if (entity.TemplateAccessor.IsPresent()) { TemplateAccessor accessor = entity.TemplateAccessor.Get(); if (accessor != null) { TemplateDescription templateDescription = accessor.TemplateDescription; entityBuilder.SetTemplate(templateDescription.TemplateClass); if (accessor.HasConfigPath()) { entityBuilder.SetConfig(accessor.ConfigPath); } else { YamlNode yamlNode = accessor.YamlNode; if (yamlNode != null) { entityBuilder.SetTemplateYamlNode(yamlNode); } } } } EntityInternal internal2 = entityBuilder.Build(true); foreach (Type type in entity.ComponentClasses) { if (!ReferenceEquals(type, this.newEntityComponentType)) { internal2.AddComponent(entity.GetComponent(type)); } } return(internal2); }
public EntityInternal CreateEntity(long templateId, string configPath, long entityId) { EntityInternal entity = this.engineService.CreateEntityBuilder().SetId(entityId).SetName(configPath).SetConfig(configPath).SetTemplate(TemplateRegistry.GetTemplateInfo(templateId)).Build(false); this.RegisterEntity(entity, EntityState.Created); return(entity); }
public void DetachedFromEntity(Entity entity) { EntityInternal member = (EntityInternal)entity; this.OnRemoveMemberWithoutRemovingListener(member); member.RemoveEntityListener(this); }
public EntityInternal CreateEntity(long entityId, Optional <TemplateAccessor> templateAccessor) { EntityInternal entity = this.engineService.CreateEntityBuilder().SetId(entityId).SetTemplateAccessor(templateAccessor).Build(false); this.RegisterEntity(entity, EntityState.Created); return(entity); }
public EntityInternal CreateEntity(long entityId) { EntityInternal entity = this.engineService.CreateEntityBuilder().SetId(entityId).Build(false); this.RegisterEntity(entity, EntityState.Created); return(entity); }
private void RegisterEntity(EntityInternal entity, EntityState state) { if (this.registry.ContainsKey(entity.Id)) { throw new EntityAlreadyRegisteredException(entity); } this.registry.Add(entity.Id, new EntityEntry(EntityState.Created, entity)); }
private void AutoAddComponents(EntityInternal newEntity, TemplateDescription templateDescription) { foreach (Type type in templateDescription.GetAutoAddedComponentTypes()) { Component component = !typeof(GroupComponent).IsAssignableFrom(type) ? newEntity.CreateNewComponentInstance(type) : GroupRegistry.FindOrCreateGroup(type, newEntity.Id); newEntity.AddComponent(component); } }
private void OnRemoveMemberWithoutRemovingListener(EntityInternal member) { Collections.Enumerator <NodeDescription> enumerator = Collections.GetEnumerator <NodeDescription>(member.NodeDescriptionStorage.GetNodeDescriptions()); while (enumerator.MoveNext()) { this.nodeCollector.Detach(member, enumerator.Current); } this.members.Remove(member); }
private void AutoAddComponentsIfNeed(Node any) { EntityInternal entity = (EntityInternal)any.Entity; if (entity.TemplateAccessor.IsPresent()) { this.AutoAddComponents(entity, entity.TemplateAccessor.Get().TemplateDescription); } base.ScheduleEvent <ComponentsAutoAddedEvent>(entity); }
public EntityInternal GetOrCreateEntity() { if (SharedEntityRegistry.TryGetEntity(this.EntityId, out this._entity)) { this._entity.TemplateAccessor = this.EntityTemplateAccessor; } else { this._entity = SharedEntityRegistry.CreateEntity(this.EntityId, this.EntityTemplateAccessor); } return(this._entity); }
public bool TryGetEntity(long entityId, out EntityInternal entity) { EntityEntry entry; entity = null; if (!this.registry.TryGetValue(entityId, out entry)) { return(false); } entity = entry.entity; return(true); }
public void AttachedToEntity(Entity entity) { EntityInternal item = (EntityInternal)entity; this.members.Add(item); item.AddEntityListener(this); Collections.Enumerator <NodeDescription> enumerator = Collections.GetEnumerator <NodeDescription>(item.NodeDescriptionStorage.GetNodeDescriptions()); while (enumerator.MoveNext()) { this.nodeCollector.Attach(item, enumerator.Current); } }
public void DecodeToInstance(ProtocolBuffer protocolBuffer, object instance) { ComponentChangeCommand command = (ComponentChangeCommand)instance; EntityInternal internal2 = (EntityInternal)this.entityCodec.Decode(protocolBuffer); long uid = (long)this.longCodec.Decode(protocolBuffer); Type typeByUid = this.protocol.GetTypeByUid(uid); Component component = null; component = !internal2.HasComponent(typeByUid) ? ((Component)Activator.CreateInstance(typeByUid)) : internal2.GetComponent(typeByUid); this.protocol.GetCodec(typeByUid).DecodeToInstance(protocolBuffer, component); command.Entity = internal2; command.Component = component; }
protected ICollection <NodeDescription> GetRemovedNodes(EntityInternal entity, Type componentClass) { BitSet componentsBitId = entity.ComponentsBitId; List <NodeDescription> instance = flowInstances.listNodeDescription.GetInstance(); Collections.Enumerator <NodeDescription> enumerator = Collections.GetEnumerator <NodeDescription>(NodeDescriptionRegistry.GetNodeDescriptionsByNotComponent(componentClass)); while (enumerator.MoveNext()) { NodeDescription current = enumerator.Current; if (componentsBitId.Mask(current.NodeComponentBitId) && (!componentsBitId.MaskNot(current.NotNodeComponentBitId) && entity.NodeDescriptionStorage.Contains(current))) { instance.Add(current); } } return(instance); }
public bool IsAcceptable(Type componentType, EntityInternal entity) { Optional <TemplateAccessor> templateAccessor = entity.TemplateAccessor; if (!templateAccessor.IsPresent()) { return(false); } TemplateDescription templateDescription = templateAccessor.Get().TemplateDescription; if (!templateDescription.IsComponentDescriptionPresent(componentType)) { return(false); } ComponentDescription componentDescription = templateDescription.GetComponentDescription(componentType); return(this.IsAcceptable(componentDescription, entity)); }
protected int CreateEntityInternal(int pipeline, int entityIndex) { int entity; if (_reservedEntitiesCount > 0) { _reservedEntitiesCount--; entity = _reservedEntities[_reservedEntitiesCount]; var entityData = _entities[entity]; entityData.ComponentsCount = 0; entityData.PipelineContext = pipeline; entityData.EntityTypeIndex = entityIndex; } else { entity = _entitiesCount; if (_entitiesCount == _entities.Length) { Array.Resize(ref _entities, _entitiesCount << 1); } var entityData = new EntityInternal(); entityData.PipelineContext = pipeline; entityData.EntityTypeIndex = entityIndex; _entities[_entitiesCount++] = entityData; } AddDelayedUpdate(DelayedUpdate.Op.CreateEntity, entity, null, -1); #if DEBUG for (var ii = 0; ii < _debugListeners.Count; ii++) { _debugListeners[ii].OnEntityCreated(entity); } #endif #if ECP_ENABLE_WORLD_EVENTS for (var ii = 0; ii < _eventListeners.Count; ii++) { _eventListeners[ii].OnEntityCreated(entity); } #endif return(entity); }
public static string Build(bool detailInfo = false) { StringBuilder builder = new StringBuilder(); foreach (Entity entity in (EngineService == null) ? new List <Entity>() : EngineService.EntityRegistry.GetAllEntities()) { if (!EngineService.EntityStub.Equals(entity)) { builder.Append($"[Entity: Id={entity.Id}, Name={entity.Name}] "); EntityInternal internal2 = (EntityInternal)entity; foreach (Component component in !(internal2 is EntityStub) ? internal2.Components : new List <Component>()) { builder.Append("[Component: "); builder.Append(!detailInfo ? component.GetType().Name : EcsToStringUtil.ToStringWithProperties(component, ", ")); builder.Append("]\n"); } } } return(builder.ToString()); }
protected void ReserveEntity(int entity, EntityInternal entityData) { entityData.ComponentsCount = -1; if (_reservedEntitiesCount == _reservedEntities.Length) { Array.Resize(ref _reservedEntities, _reservedEntitiesCount << 1); } _reservedEntities[_reservedEntitiesCount++] = entity; #if DEBUG for (var ii = 0; ii < _debugListeners.Count; ii++) { _debugListeners[ii].OnEntityRemoved(entity); } #endif #if ECP_ENABLE_WORLD_EVENTS for (var ii = 0; ii < _eventListeners.Count; ii++) { _eventListeners[ii].OnEntityRemoved(entity); } #endif }
public static bool Update(EntityInternal entity, Component component, INamingConvention nameConvertor = null) { INamingConvention convention = ComponentInstanceDataUpdater.nameConvertor; if (!entity.TemplateAccessor.IsPresent()) { return(false); } TemplateAccessor accessor = entity.TemplateAccessor.Get(); if (!accessor.HasConfigPath()) { return(false); } if (nameConvertor != null) { convention = nameConvertor; } Type componentType = component.GetType(); if (!accessor.TemplateDescription.IsComponentDescriptionPresent(componentType)) { return(false); } ComponentDescription componentDescription = accessor.TemplateDescription.GetComponentDescription(componentType); if (!componentDescription.IsInfoPresent(typeof(ConfigComponentInfo))) { return(false); } string keyName = componentDescription.GetInfo <ConfigComponentInfo>().KeyName; if (!accessor.YamlNode.HasValue(keyName)) { return(false); } UpdateComponentData(component, accessor.YamlNode.GetChildNode(keyName), convention); return(true); }
public EntityEntry(SharedEntityRegistryImpl.EntityState state, EntityInternal entity) { this.entity = entity; this.state = state; this.unsharedTime = 0.0; }
protected override bool IsAcceptable(ComponentDescription componentDescription, EntityInternal entity) => componentDescription.IsInfoPresent(typeof(ConfigComponentInfo));
protected internal override Component GetComponentInstance(ComponentDescription componentDescription, EntityInternal entity) { Component component2; YamlNode yamlNode = entity.TemplateAccessor.Get().YamlNode; ConfigComponentInfo info = componentDescription.GetInfo <ConfigComponentInfo>(); string keyName = info.KeyName; if (info.ConfigOptional && !yamlNode.HasValue(keyName)) { return((Component)Activator.CreateInstance(componentDescription.ComponentType)); } try { component2 = (Component)yamlNode.GetChildNode(keyName).ConvertTo(componentDescription.ComponentType); } catch (Exception exception) { TemplateAccessor accessor; string str2 = !accessor.HasConfigPath() ? yamlNode.ToString() : accessor.ConfigPath; object[] objArray1 = new object[] { "Error deserializing component ", componentDescription.ComponentType, " from configs, entity=", entity, ", key=", keyName, ", pathOrNode=", str2 }; throw new Exception(string.Concat(objArray1), exception); } return(component2); }
public EntityComponentStorage(EntityInternal entity, ComponentBitIdRegistry componentBitIdRegistry) { this.entity = entity; this.componentBitIdRegistry = componentBitIdRegistry; this.bitId = new BitSet(); }
public void AttachedToEntity(Entity entity) { this.entity = (EntityInternal)entity; }
public void DetachedFromEntity(Entity entity) { this.entity = null; }
public static string ToStringWithComponents(EntityInternal entity) => !(entity is EntityStub) ? $"[{entity.Name}, {entity.Id}, {ToString(entity.ComponentClasses)}]": "[EntityStub]";
public virtual NodesToChange GetNodesToChange(EntityInternal entity, Type componentClass) => new NodesToChange { NodesToAdd = this.GetAddedNodes(entity, componentClass), NodesToRemove = this.GetRemovedNodes(entity, componentClass) };
public EntityAlreadyAttachedToSpaceException(EntityInternal entity, GroupComponent group) : base(string.Concat(objArray1)) { object[] objArray1 = new object[] { "entity=", entity, " exists in attached group=", group }; }