protected override void Process(HashSet <Entity> changedChunks, NativeMultiHashMap <Entity, Entity> changedVolumesPerChunk) { var allVolumes = changedVolumesPerChunk.GetValueArray(Allocator.TempJob); foreach (var chunk in changedChunks) { var volumes = EntityManager.GetBuffer <ChunkVolumes>(chunk); var index = 0; while (index < volumes.Length) { var found = NativeArrayExtensions.IndexOf(allVolumes, volumes[index].VolumeEntity); if (found >= 0) { volumes.RemoveAt(index); } else { index++; } } } allVolumes.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (minionSystem == null) { return(inputDeps); } if (arrows.Length == 0) { return(inputDeps); } if (minions.Length == 0) { return(inputDeps); } // Update seems to be called after Play mode has been exited // ============ REALLOC =============== // todo fix nativearray NativeArrayExtensions.ResizeNativeArray(ref raycastHits, math.max(raycastHits.Length, arrows.Length)); NativeArrayExtensions.ResizeNativeArray(ref raycastCommands, math.max(raycastCommands.Length, arrows.Length)); // ============ JOB CREATION =============== var arrowJob = new ProgressArrowJob { raycastCommands = raycastCommands, arrows = arrows.data, arrowEntities = arrows.entities, dt = Time.deltaTime, allMinionTransforms = minions.transforms, buckets = minionSystem.CollisionBuckets, minionConstData = minions.constData, AttackCommands = CommandSystem.AttackCommandsConcurrent, minionEntities = minions.entities, queueForKillingEntities = lifecycleManager.queueForKillingEntities }; var stopArrowJob = new StopArrowsJob { raycastHits = raycastHits, arrows = arrows.data, arrowEntities = arrows.entities, stoppedArrowsQueue = lifecycleManager.deathQueue }; var arrowJobFence = arrowJob.Schedule(arrows.Length, SimulationState.SmallBatchSize, JobHandle.CombineDependencies(inputDeps, CommandSystem.AttackCommandsFence)); arrowJobFence.Complete(); var raycastJobFence = RaycastCommand.ScheduleBatch(raycastCommands, raycastHits, SimulationState.SmallBatchSize, arrowJobFence); var stopArrowJobFence = stopArrowJob.Schedule(arrows.Length, SimulationState.SmallBatchSize, raycastJobFence); CommandSystem.AttackCommandsConcurrentFence = JobHandle.CombineDependencies(stopArrowJobFence, CommandSystem.AttackCommandsConcurrentFence); // Complete arrow movement return(stopArrowJobFence); }
/// <summary> /// 读取图像标识符(Image Descriptor) /// 8bit -图像标识符 /// 16bit - 图像X /// 16bit - 图像Y /// 16bit - 图像Width /// 16bit - 图像Height /// 1bit Local Color Table Flag /// 1bit interlace /// 1bit sortFlag /// 2bit r保留 /// 3bit pixel /// </summary> private void ReadImage() { this.imageX = this.ReadShort(); this.imageY = this.ReadShort(); this.imageWidth = this.ReadShort(); this.imageHeight = this.ReadShort(); var packed = this.ReadByteToInt(); //1000 0000 //this.lctFlag = (packed & 0x80) != 0;//也可以直接右移7位 this.lctFlag = (packed >> 7) > 0;//如果大于0表示是true this.interlace = (packed & 0x40) != 0; //0000 0111 //packed this.lctSize = 2 << (packed & 7); if (this.lctFlag) { this.ReadColorTable(this.lctSize, out this.lct); this.act = this.lct; } else { this.act = this.gct; if (this.bgIndex == this.transIndex) { this.bgColor = 0; } } var save = 0; if (this.transparency) { save = this.act[this.transIndex]; this.act[this.transIndex] = 0;//设置为透明的颜色 } if (this.act == default(NativeArray <int>)) { Debug.LogError("解析GiF的格式出现错误"); return; } this.ReadImageData(); this.Skip(); if (this.bError) { //有错误直接跳过 return; } this.AlloctorImageData(); this.SetPixels(); this.imageData = NativeArrayExtensions.Reinterpret <int, byte>(this.imageBigData); }
static unsafe void CreateGameObjectEntity(EntityManager entityManager, GameObject gameObject, GameObjectConversionMappingSystem system) { var componentTypes = stackalloc ComponentType[128]; if (!GetComponents(gameObject, componentTypes, 128, system)) { return; } EntityArchetype archetype; try { archetype = entityManager.CreateArchetype(componentTypes, s_ComponentsCache.Count); } catch (Exception) { for (int i = 0; i < s_ComponentsCache.Count; ++i) { if (NativeArrayExtensions.IndexOf <ComponentType, ComponentType>(componentTypes, s_ComponentsCache.Count, componentTypes[i]) != i) { system.LogWarning($"GameObject '{gameObject}' has multiple {componentTypes[i]} components and cannot be converted, skipping.", null); return; } } throw; } var entity = entityManager.CreateEntity(archetype); for (var i = 0; i != s_ComponentsCache.Count; i++) { var com = s_ComponentsCache[i]; //@TODO: avoid cast var componentDataProxy = com as ComponentDataProxyBase; if (componentDataProxy != null) { componentDataProxy.UpdateComponentData(entityManager, entity); } else if (com != null) { entityManager.SetComponentObject(entity, componentTypes[i], com); } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (flyingUnits.Length == 0) { return(inputDeps); } // ============ REALLOC =============== // todo fix nativearray NativeArrayExtensions.ResizeNativeArray(ref raycastHits, math.max(raycastHits.Length, flyingUnits.Length)); NativeArrayExtensions.ResizeNativeArray(ref raycastCommands, math.max(raycastCommands.Length, flyingUnits.Length)); // ============ JOB CREATION =============== var prepareRaycastsJob = new PrepareRaycasts { transforms = flyingUnits.transforms, raycastCommands = raycastCommands }; var flightJob = new MinionFlightJob { raycastHits = raycastHits, minionData = flyingUnits.data, flyingUnits = flyingUnits.transforms, rigidbodies = flyingUnits.rigidbodies, textureAnimators = flyingUnits.animationData, dt = Time.deltaTime, }; // ==================== JOB SCHEDULING ============== var prepareRaycastFence = prepareRaycastsJob.Schedule(flyingUnits.Length, SimulationState.SmallBatchSize, inputDeps); prepareRaycastFence.Complete(); // TODO fix me var raycastJobFence = RaycastCommand.ScheduleBatch(raycastCommands, raycastHits, SimulationState.SmallBatchSize, prepareRaycastFence); var flightJobFence = flightJob.Schedule(flyingUnits.Length, SimulationState.SmallBatchSize, raycastJobFence); return(flightJobFence); }
public int IndexOf <T>(T value) where T : unmanaged, IEquatable <T> { return(NativeArrayExtensions.IndexOf <T, T>(Ptr, Length, value)); }