internal void OnAddEntity(AddEntityOp op) { var entityId = new EntityId(op.EntityId); if (worker.EntityIdToEntity.ContainsKey(entityId)) { throw new InvalidSpatialEntityStateException( string.Format(Errors.EntityAlreadyExistsError, entityId.Id)); } Profiler.BeginSample("OnAddEntity"); var entity = EntityManager.CreateEntity(); EntityManager.AddComponentData(entity, new SpatialEntityId { EntityId = entityId }); EntityManager.AddComponent(entity, ComponentType.Create <NewlyAddedSpatialOSEntity>()); foreach (var AddCommandCompoent in AddAllCommandComponents) { AddCommandCompoent(entity); } WorldCommands.AddWorldCommandRequesters(World, EntityManager, entity); worker.EntityIdToEntity.Add(entityId, entity); Profiler.EndSample(); }
private void SetupDispatcherHandlers() { // Find all component specific dispatchers and create an instance. var componentDispatcherTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .Where(type => typeof(ComponentDispatcherHandler).IsAssignableFrom(type) && !type.IsAbstract && type.GetCustomAttribute(typeof(DisableAutoRegisterAttribute)) == null); WorldCommands.AddWorldCommandRequesters(World, EntityManager, worker.WorkerEntity); foreach (var componentDispatcherType in componentDispatcherTypes) { AddDispatcherHandler((ComponentDispatcherHandler) Activator.CreateInstance(componentDispatcherType, worker, World)); } Dispatcher.OnAddEntity(OnAddEntity); Dispatcher.OnRemoveEntity(OnRemoveEntity); Dispatcher.OnDisconnect(OnDisconnect); Dispatcher.OnCriticalSection(op => { inCriticalSection = op.InCriticalSection; }); Dispatcher.OnAddComponent(OnAddComponent); Dispatcher.OnRemoveComponent(OnRemoveComponent); Dispatcher.OnComponentUpdate(OnComponentUpdate); Dispatcher.OnAuthorityChange(OnAuthorityChange); Dispatcher.OnCommandRequest(OnCommandRequest); Dispatcher.OnCommandResponse(OnCommandResponse); Dispatcher.OnCreateEntityResponse(OnCreateEntityResponse); Dispatcher.OnDeleteEntityResponse(OnDeleteEntityResponse); Dispatcher.OnReserveEntityIdsResponse(OnReserveEntityIdsResponse); Dispatcher.OnEntityQueryResponse(OnEntityQueryResponse); }
private void OnAddEntity(AddEntityOp op) { var entityId = op.EntityId; if (worker.EntityMapping.ContainsKey(entityId)) { worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent(Errors.DuplicateAdditionOfEntity) .WithField(LoggingUtils.LoggerName, LoggerName) .WithField(LoggingUtils.EntityId, entityId)); return; } var entity = EntityManager.CreateEntity(); EntityManager.AddComponentData(entity, new SpatialEntityId { EntityId = entityId }); EntityManager.AddComponentData(entity, new NewlyAddedSpatialOSEntity()); foreach (var AddCommandCompoent in AddAllCommandComponents) { AddCommandCompoent(entity); } WorldCommands.AddWorldCommandRequesters(World, EntityManager, entity); worker.EntityMapping.Add(entityId, entity); }
private Entity SetupTestEntity() { var entity = entityManager.CreateEntity(); var entityId = new EntityId(TestEntityId); entityManager.AddComponentData(entity, new SpatialEntityId { EntityId = entityId }); worker.EntityIdToEntity.Add(entityId, entity); WorldCommands.AddWorldCommandRequesters(world, entityManager, entity); return(entity); }
private void SetupDispatcherHandlers() { // Find all component specific dispatchers and create an instance. var componentDispatcherTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .Where(type => typeof(ComponentDispatcherHandler).IsAssignableFrom(type) && !type.IsAbstract); WorldCommands.AddWorldCommandRequesters(World, EntityManager, worker.WorkerEntity); foreach (var componentDispatcherType in componentDispatcherTypes) { var componentDispatcher = (ComponentDispatcherHandler)Activator.CreateInstance(componentDispatcherType, worker, World); componentSpecificDispatchers.Add(componentDispatcher.ComponentId, componentDispatcher); AddAllCommandComponents.Add(componentDispatcher.AddCommandComponents); componentDispatcher.AddCommandComponents(worker.WorkerEntity); } dispatcher.OnAddEntity(OnAddEntity); dispatcher.OnRemoveEntity(OnRemoveEntity); dispatcher.OnDisconnect(OnDisconnect); dispatcher.OnCriticalSection(op => { inCriticalSection = op.InCriticalSection; }); dispatcher.OnAddComponent(OnAddComponent); dispatcher.OnRemoveComponent(OnRemoveComponent); dispatcher.OnComponentUpdate(OnComponentUpdate); dispatcher.OnAuthorityChange(OnAuthorityChange); dispatcher.OnCommandRequest(OnCommandRequest); dispatcher.OnCommandResponse(OnCommandResponse); dispatcher.OnCreateEntityResponse(OnCreateEntityResponse); dispatcher.OnDeleteEntityResponse(OnDeleteEntityResponse); dispatcher.OnReserveEntityIdsResponse(OnReserveEntityIdsResponse); dispatcher.OnEntityQueryResponse(OnEntityQueryResponse); ClientError.ExceptionCallback = HandleException; }