private void CreateMap(float[] map) { var mapSize = map.Length; var mapArchetype = _entityManager.CreateArchetype(typeof(MapSettings)); var tileArchetype = _entityManager.CreateArchetype(typeof(MovementCost)); var tiles = new NativeArray <Entity>(mapSize, Allocator.Temp); _entityManager.CreateEntity(tileArchetype, tiles); var mapEntity = _entityManager.CreateEntity(mapArchetype); for (int i = 0; i < mapSize; i++) { _entityManager.SetComponentData(tiles[i], new MovementCost { Cost = map[i] }); } var blitableTiles = new BlitableArray <Entity>(); blitableTiles.Allocate(tiles, Allocator.Temp); if (TargetSystem.HasSingleton <MapSettings>() == false) { TargetSystem.EntityManager.CreateEntity(typeof(MapSettings)); TargetSystem.SetSingleton(new MapSettings { MapEdgeSize = EdgeSize(mapSize), Tiles = blitableTiles }); } }
public void Constructor_float_TempJob() { DoesNotThrow(() => { var array = new BlitableArray <float>(10, Allocator.TempJob); array.Dispose(); }); }
public void SetChunkPositions(int3[] newPositions) { chunkPositions = new BlitableArray <int3>(newPositions.Length, Allocator.Persistent); for (int i = 0; i < newPositions.Length; i++) { chunkPositions[i] = newPositions[i]; } }
public void Constructor_float_Persistent() { DoesNotThrow(() => { var array = new BlitableArray <float>(10, Allocator.Persistent); array.Dispose(); }); }
public void SetChunkIDs(int[] newIDs) { chunkIDs = new BlitableArray <int>(newIDs.Length, Allocator.Persistent); for (int i = 0; i < newIDs.Length; i++) { chunkIDs[i] = newIDs[i]; } }
public void Constructor_float_Minus() { Throws <ArgumentException>(() => { var array = new BlitableArray <float>(-1, Allocator.Temp); array.Dispose(); }); }
public void Constructor_float_Empty() { DoesNotThrow(() => { var array = new BlitableArray <float>(); array.Dispose(); }); }
public void Alocation_Count_Ten_Persistent() { DoesNotThrow(() => { var array = new BlitableArray <float>(); array.Allocate(10, Allocator.Persistent); array.Dispose(); }); }
public void Alocation_Count_Ten_TempJob() { DoesNotThrow(() => { var array = new BlitableArray <float>(); array.Allocate(10, Allocator.TempJob); array.Dispose(); }); }
public void Alocation_Count_Minus() { Throws <ArgumentException>(() => { var array = new BlitableArray <float>(); array.Allocate(-1, Allocator.Temp); array.Dispose(); }); }
public void Constructor_float_None() { LogAssert.ignoreFailingMessages = true; Throws <ArgumentException>(() => { var array = new BlitableArray <float>(10, Allocator.None); array.Dispose(); }); }
public void Alocation_Count_Ten_None() { LogAssert.ignoreFailingMessages = true; Throws <ArgumentException>(() => { var array = new BlitableArray <float>(); array.Allocate(10, Allocator.None); array.Dispose(); }); }
public void Init(int3 voxelDimensions) { Dispose(); int xyzSize = (int)(voxelDimensions.x * voxelDimensions.y * voxelDimensions.z); int maxCacheVerts = xyzSize * 4; int maxCacheTriangles = maxCacheVerts / 2; vertices = new BlitableArray <ZoxelVertex>(maxCacheVerts, Unity.Collections.Allocator.Persistent); triangles = new BlitableArray <int>(maxCacheTriangles, Unity.Collections.Allocator.Persistent); }
public void InitializeData() { int count = (int)math.floor(size.x * size.y * size.z); if (data.Length > 0) { data.Dispose(); } data = new BlitableArray <byte>(count, Allocator.Persistent); }
public void Size() { var array = new BlitableArray <float>(); Zero(array.Length); array.Dispose(); array = new BlitableArray <float>(10, Allocator.Temp); AreEqual(10, array.Length); array.Dispose(); }
public void Init(int3 voxelDimensions) { //Debug.LogError("Initiating chunksides: " + voxelDimensions); int xyzSize = (int)(voxelDimensions.x * voxelDimensions.y * voxelDimensions.z); sidesBack = new BlitableArray <byte>(xyzSize, Unity.Collections.Allocator.Persistent); sidesDown = new BlitableArray <byte>(xyzSize, Unity.Collections.Allocator.Persistent); sidesUp = new BlitableArray <byte>(xyzSize, Unity.Collections.Allocator.Persistent); sidesForward = new BlitableArray <byte>(xyzSize, Unity.Collections.Allocator.Persistent); sidesLeft = new BlitableArray <byte>(xyzSize, Unity.Collections.Allocator.Persistent); sidesRight = new BlitableArray <byte>(xyzSize, Unity.Collections.Allocator.Persistent); }
public void InitializeColors(int count) { if (colorsR.Length > 0) { colorsR.Dispose(); colorsG.Dispose(); colorsB.Dispose(); } colorsR = new BlitableArray <byte>(count, Allocator.Persistent); colorsG = new BlitableArray <byte>(count, Allocator.Persistent); colorsB = new BlitableArray <byte>(count, Allocator.Persistent); }
public void Constructor_bool() { DoesNotThrow(() => { var array = new BlitableArray <bool>(); array.Dispose(); }); Throws <ArgumentException>(() => { var array = new BlitableArray <bool>(0, Allocator.Temp); array.Dispose(); }); }
public void SetChunkRenders(bool[] newRenders) { isRender = new BlitableArray <byte>(newRenders.Length, Allocator.Persistent); for (int i = 0; i < newRenders.Length; i++) { if (newRenders[i]) { isRender[i] = 1; } else { isRender[i] = 0; } } }
public void Alocation_From_List() { var list = Enumerable.Range(0, 25).Select(x => (float)x).ToList(); var array = new BlitableArray <float>(); array.Allocate(list, Allocator.Temp); AreEqual(list.Count, array.Length); for (int i = 0; i < array.Length; i++) { AreEqual(list[i], array[i]); } array.Dispose(); }
public void To_NativeArray_Zero() { var array = new BlitableArray <float>(); NativeArray <float> nativeArray = array.ToNativeArray(Allocator.Temp); AreEqual(array.Length, nativeArray.Length); for (int i = 0; i < array.Length; i++) { AreEqual(array[i], nativeArray[i]); } nativeArray.Dispose(); array.Dispose(); }
public void Alocation_From_ManagedArray() { var managedArray = Enumerable.Range(0, 25).Select(x => (float)x).ToArray(); var array = new BlitableArray <float>(); array.Allocate(managedArray, Allocator.Temp); AreEqual(managedArray.Length, array.Length); for (int i = 0; i < array.Length; i++) { AreEqual(managedArray[i], array[i]); } array.Dispose(); }
public void To_NativeArray_Call() { var managedArray = Enumerable.Range(0, 25).Select(x => (float)x).ToArray(); var array = new BlitableArray <float>(); array.Allocate(managedArray, Allocator.Temp); NativeArray <float> nativeArray = array.ToNativeArray(Allocator.Temp); AreEqual(array.Length, nativeArray.Length); for (int i = 0; i < array.Length; i++) { AreEqual(array[i], nativeArray[i]); } nativeArray.Dispose(); array.Dispose(); }
public void SetBones(float3[] bonePositions_, quaternion[] boneRotations_) { if (bonePositions.Length != bonePositions_.Length) { bonePositions = new BlitableArray <float3>(bonePositions_.Length, Allocator.Persistent); } for (int i = 0; i < bonePositions_.Length; i++) { bonePositions[i] = bonePositions_[i]; } if (boneRotations.Length != boneRotations_.Length) { boneRotations = new BlitableArray <quaternion>(boneRotations_.Length, Allocator.Persistent); } for (int i = 0; i < boneRotations_.Length; i++) { boneRotations[i] = boneRotations_[i]; } }
private void SetMap(int edgeSize) { var mapSize = edgeSize * edgeSize; var tile = _entityManager.CreateEntity(typeof(GroundType)); _entityManager.SetComponentData(tile, new GroundType(BlobsMemory.Instance.ReferencesOf <GroundTypeBlob>()[0])); var tiles = new BlitableArray <Entity>(mapSize, Unity.Collections.Allocator.Temp); for (int i = 0; i < mapSize; i++) { tiles[i] = tile; } _entityManager.CreateEntity(typeof(MapSettings)); TargetSystem.SetSingleton(new MapSettings() { Tiles = tiles, MapEdgeSize = edgeSize }); }
public void SetMetaData(Dictionary <int, VoxelDatam> meta, List <int> voxelIDs) { // meta data for building models modelIndexes = new BlitableArray <int>(meta.Count, Unity.Collections.Allocator.Persistent); int a = 0; foreach (VoxelDatam voxel in meta.Values) { modelIndexes[a] = voxel.Value.meshIndex; a++; } uvMaps = new BlitableArray <VoxelUVMap>(voxelIDs.Count, Allocator.Persistent); for (int i = 0; i < voxelIDs.Count; i++) { int metaID = voxelIDs[i]; VoxelDatam voxels = meta[metaID]; uvMaps[i] = voxels.uvMap; } }
public void InitializeBoneWeights(int maxCacheVerts, List <BoneData> boneDatas) { //weights //hasWeights = 1; boneWeightsIndexes0 = new BlitableArray <int>(maxCacheVerts, Unity.Collections.Allocator.Persistent); boneWeights0 = new BlitableArray <float>(maxCacheVerts, Unity.Collections.Allocator.Persistent); bonePositions = new BlitableArray <float3>(boneDatas.Count, Unity.Collections.Allocator.Persistent); boneRotations = new BlitableArray <quaternion>(boneDatas.Count, Unity.Collections.Allocator.Persistent); boneInfluences = new BlitableArray <float>(boneDatas.Count, Unity.Collections.Allocator.Persistent); for (int i = 0; i < boneDatas.Count; i++) { boneWeightsIndexes0[i] = 0; boneWeights0[i] = 0; boneInfluences[i] = boneDatas[i].influence; //bones[i] = boneDatas[i].position + new float3(0.5f, 1f, 0.5f); // plus half mesh bounds //bonePositions[i] = (new float3(boneDatas[i].position.x, // boneDatas[i].position.y, boneDatas[i].position.z + 0.15f) + new float3(0.5f, 1f, 0.5f)); bonePositions[i] = boneDatas[i].position; boneRotations[i] = boneDatas[i].rotation; } }
protected override void OnUpdate() { Entities .WithStructuralChanges() .ForEach((Entity e, in MapRequest mapRequest) => { int mapEdgeSize = mapRequest.MapEdgeSize; NativeArray <Entity> tileEntities = new NativeArray <Entity>(mapEdgeSize * mapEdgeSize, Allocator.Temp, NativeArrayOptions.UninitializedMemory); EntityManager.CreateEntity(_tileArchetype, tileEntities); int index1D = 0; for (int y = 0; y < mapEdgeSize; y++) { for (int x = 0; x < mapEdgeSize; x++) { var tileEntity = tileEntities[y * mapEdgeSize + x]; var tileType = FindTileType(new float2(x, y), mapRequest); var resourceOre = CalcResourceOre(new float2(x, y), mapRequest, tileType); EntityManager.SetComponentData(tileEntity, tileType); EntityManager.SetComponentData(tileEntity, new MapIndex(index1D, new int2(x, y))); EntityManager.SetComponentData(tileEntity, resourceOre); ++index1D; } } EntityManager.DestroyEntity(e); var tiles = new BlitableArray <Entity>(); tiles.Allocate(tileEntities, Allocator.Persistent); var mapSettingsEntity = EntityManager.CreateEntity(_mapSettingsArchetype); SetSingleton(new MapSettings { MapEdgeSize = mapEdgeSize, Tiles = tiles }); tileEntities.Dispose(); Enabled = false; }).Run(); }