bool CanDropHere(BlockGroup group, BoxCell cell){ foreach (var position in group.positions) { BoxCell boxCell = ( grid.GetCell (cell.coord + position) as BoxCell ); if (boxCell == null || boxCell.HasColor) return false; } return true; }
bool HasPlace(BlockGroup group){ for (int x = 0; x < grid.GetMap ().size.x; x++) { for (int y = 0; y < grid.GetMap ().size.y; y++) { if(CanDropHere(group, (BoxCell) grid.GetCell(new Coord(x,y)))) return true; } } return false; }
// Refactor public void DropHere(BlockGroup group, DropZone dropenOn, bool WithAnimation = false){ BoxCell cellDropenOn = dropenOn.GetComponent<BoxCell>(); foreach (var position in group.positions) { (grid.GetCell (cellDropenOn.coord + position) as BoxCell).SetColor (group.color); } if (OnSuccessfulDrop != null) OnSuccessfulDrop (group, dropenOn); blocksContainer.blocks.Remove (group); Destroy (group.gameObject); grid.ClearSolvedRowsAndColumns (); }
public void BasicTest() { Assert.Throws<InvalidOperationException>(() => new BlockGroup(new Address(0), BlockGroup.ReservedBlocks)); var group = new BlockGroup(new Address(4096), 1000); Assert.IsNotNull(group.Descriptor); Assert.AreEqual(4096, group.Descriptor.BitmapsAddress.Value); Assert.AreEqual(1000 - BlockGroup.ReservedBlocks, group.Descriptor.NumFreeBlocksInGroup); Assert.AreEqual(Constants.NodesPerGroup, group.Descriptor.NumFreeNodesInGroup); var node1 = group.AllocateNewNode(); var node2 = group.AllocateNewNode(); Assert.AreEqual(Constants.NodesPerGroup - 2, group.Descriptor.NumFreeNodesInGroup); group.FreeNode(node1); group.FreeNode(node2); Assert.AreEqual(Constants.NodesPerGroup, group.Descriptor.NumFreeNodesInGroup); var block1 = group.AllocateNewBlock(); var block2 = group.AllocateNewBlock(); Assert.AreEqual(1000 - BlockGroup.ReservedBlocks - 2, group.Descriptor.NumFreeBlocksInGroup); group.FreeBlock(block1); group.FreeBlock(block2); Assert.AreEqual(1000 - BlockGroup.ReservedBlocks, group.Descriptor.NumFreeBlocksInGroup); while (group.AllocateNewBlock() != null) { } while (group.AllocateNewNode() != null) { } Assert.IsNull(group.AllocateNewBlock()); Assert.IsNull(group.AllocateNewNode()); }
internal override void parseArg(string arg) { base.parseArg(arg); if (arg.Contains(SWITCH_ID)) { int newSwitchID = int.Parse(arg.Split(':')[1]); SwitchManager.instance.removeSwitch(switchID); switchID = newSwitchID; SwitchManager.instance.switchMap.Add(switchID, this); //registers this switch return; } if (arg.Contains(Block.CHUNK_ID)) { //this switch triggers a chunk string chunkID = arg.Split(':')[1]; BlockGroup chunk = BlockGroup.groupMap[chunkID]; SwitchManager.instance.registerSwitchTarget(switchID, chunk); StartCoroutine(deactivateChunk()); //must wait for all blocks to be added to chunk first } }
public void UnloadDistantChunks(int chunkX, int chunkY, int chunkZ, int radius) { #if UNITY_EDITOR if (!Application.isPlaying) { return; } #endif for (int i = 0; i < blockGroups.Count; i++) { BlockGroup g = blockGroups[i] as BlockGroup; g.UnloadDistantChunks(chunkX, chunkY, chunkZ, radius); if (g.IsEmpty()) { blockGroups.RemoveAt(i--); } } }
// 上に4ブロック分のスペースがあるか public bool IsEnterable(BlockGroup blockGroup) { if (this.enterable == false) { return(false); } if (this.shape.panelVertices == null) { return(false); } for (int i = 1; i <= 4; i++) { var block = blockGroup.GetBlock(this.position + new Vector3(0, 0.5f * i, 0)); if (block != null) { return(false); } } return(true); }
public override void Init(BlockGroup group, Chunk chunk) { this.chunk = chunk; // Duplicate the material // chunkMat = new Material(chunkMat); matProp = new MaterialPropertyBlock(); // Draw it by invoking the CS indBuffer = new ComputeBuffer(5, sizeof(uint), ComputeBufferType.IndirectArguments); inputBuffer = new ComputeBuffer(this.chunk.blockData.Length, System.Runtime.InteropServices.Marshal.SizeOf(typeof(Block))); // Update my initial position position = chunk.centerPos; renderPosition = chunk.positionOffset; //GenerateMesh(chunk); }
public void Awake() { instantiator = GetComponent <BlockInstantiator>(); groups = new List <BlockGroup>(); core = new CoreGroupBuilder(new Position(0, 0), GetComponent <Axis>(), groups) .ForEachBlock(block => { BlockBehaviour behaviour = instantiator.InstantiateBlock(block); if (block.Position.Equals(new Position(0, 0))) { config.follower.Follow(behaviour.gameObject); } }) .Build(); groups.Add(new SquareBuilder(new Position(0, -7), core) .ForEachBlock(block => instantiator.InstantiateBlock(block)) .Build()); heartbeat = new Heartbeat(config.heartbeat); }
public override void Render(BlockGroup group) { if (task != null) { if (task.IsCompleted) { Afterwards(task.Result); task = null; } else { return; } } if (IsReadyForPresent()) { base.Render(group); } }
public void BlockColorChange() { //블럭텍스트 / 스코어를 7등분해서 색을 칠함 for (int i = 0; i < BlockGroup.childCount; i++) { if (BlockGroup.GetChild(i).CompareTag("Block")) { float per = int.Parse(BlockGroup.GetChild(i).GetChild(0).GetComponentInChildren <Text>().text) / (float)score; Color curColor; if (per <= 0.1428f) { curColor = blockColor[6]; } else if (per <= 0.2856f) { curColor = blockColor[5]; } else if (per <= 0.4284f) { curColor = blockColor[4]; } else if (per <= 0.5172f) { curColor = blockColor[3]; } else if (per <= 0.714f) { curColor = blockColor[2]; } else if (per <= 0.8568f) { curColor = blockColor[1]; } else { curColor = blockColor[0]; } BlockGroup.GetChild(i).GetComponent <SpriteRenderer>().color = curColor; } } }
public BlockGroup CreateNewBlockGroup() { Block[] blocks = BlockGroupTypes.GetRandom().Copy(); for (int i = 0; i < blocks.Length; i++) { IntVector3 coordinate = GetSpawnCoordinate() + blocks[i].Coordinate; Vector3 worldCoordinate = new Vector3(coordinate.x + cubeSize.x / 2f, coordinate.y + cubeSize.y / 2f, coordinate.z + cubeSize.z / 2f); Block block = new Block(coordinate); block.SetGameObject(Instantiate(blockPrefab)); block.gObj.name = coordinate.ToString(); block.gObj.GetComponent <MeshRenderer>().enabled = false; block.gObj.transform.localScale = new Vector3(cubeSize.x, cubeSize.y, cubeSize.z); block.Coordinate = coordinate; block.gObj.transform.localPosition = worldCoordinate; blocks[i] = block; } BlockGroup group = new BlockGroup(blocks); return(group); }
// ルート用メッシュを出力 public void WriteToRouteMesh(BlockGroup blockGroup, BlockMeshMerger mesh) { if (!this.IsEnterable(blockGroup)) { return; } int offset = mesh.vertexPos.Count; for (int j = 0; j < 4; j++) { int index = EditUtil.ReversePanelVertexIndex(j, this.direction); Vector3 vertex = EditUtil.panelVertices[j]; vertex.y = this.shape.panelVertices[index] * 0.5f - 0.25f; vertex = EditManager.Instance.ToWorldCoordinate(vertex); mesh.vertexPos.Add(this.position + vertex); } if (this.direction == BlockDirection.Xplus || this.direction == BlockDirection.Xminus ) { mesh.triangles.Add(offset + 0); mesh.triangles.Add(offset + 2); mesh.triangles.Add(offset + 1); mesh.triangles.Add(offset + 1); mesh.triangles.Add(offset + 2); mesh.triangles.Add(offset + 3); } else { mesh.triangles.Add(offset + 0); mesh.triangles.Add(offset + 3); mesh.triangles.Add(offset + 1); mesh.triangles.Add(offset + 0); mesh.triangles.Add(offset + 2); mesh.triangles.Add(offset + 3); } }
public override void Continue() { blockGroup = new BlockGroup() { index = 0, unlock = 0 }; blockGroup.blockIndex = new List <int>(); blockGroup.blockHp = new List <int>(); for (int i = 0; i < disposedBlocks.Count; i++) { if (disposedBlocks[i].isBreaked == false) { blockGroup.blockIndex.Add(disposedBlocks[i].index); blockGroup.blockHp.Add(disposedBlocks[i].hp); } } StartCoroutine(ResetShot()); }
public static BlockGroup Load(BlockGroupSaveData data, Chunk chunk) { if (current_id <= data.Id) { current_id = data.Id + 1; } BlockGroup group = new BlockGroup(data.Name, (GroupType)data.Type); group.Id = data.Id; foreach (long id in data.Blocks) { Block block = chunk.Blocks.FirstOrDefault(x => x.Id == id); if (block == null) { CustomLogger.Instance.Error(string.Format("Block not found: #{0}", id)); continue; } group.Blocks.Add(block); block.Groups.Add(group); } return(group); }
private void CreateBoundaryButton_Click_1(object sender, EventArgs e) { if (Db == null) { MessageBox.Show("Database not connected. \n Connect a database in the Options menu under Tools."); } else { newBlockGroup = new BlockGroup(w.d.GetSelectedLines()); if (newBlockGroup.isBoundary()) { createBoundaryForm = new CreateBoundary(ref Db); createBoundaryForm.FormClosed += CreateBoundaryFormClosed; //So, this is like the most amazing thing ever!!! Basically i'm adding an event handler on this form to an event on that form!!! I know Right? It's like some kind of inception shit or something. I can't express how amazing this is!!! createBoundaryForm.addEventHandler(CreateBoundaryDirectionClick); createBoundaryForm.Show(); } else { MessageBox.Show("Block group not created"); } } }
// 6方向ブロックメッシュ public void WriteToMeshNormal(BlockGroup blockGroup, BlockMeshMerger meshMerger) { BlockShape shape = this.shape; for (int i = 0; i < shape.meshes.Length; i++) { int index = this.ToLocalDirection(i); var mesh = shape.meshes[index]; if (mesh == null) { continue; } // 隣のブロックに完全に覆われていたら省略する if (i < 6 && this.CheckOcculusion(blockGroup, (BlockDirection)i)) { continue; } meshMerger.Merge(mesh, this.position, this.direction, this.textureChips[index], i); } }
public override void Init(BlockGroup group, Chunk chunk) { base.Init(group, chunk); blockExtraPointers_buffer = new ComputeBuffer(this.chunk.blockData.Length, sizeof(uint)); fsBufSize = 0; // TODO: count FS's only if (chunk.blockExtrasDict.Count > 0) { // TODO: variable fsBufSize = chunk.blockExtrasDict.Count; int maxFSs = 4096; if (fsBufSize > maxFSs) { Debug.LogError($"Too many FS's !! ({fsBufSize} in Chunk {chunk.positionOffset / 32})"); fsBufSize = maxFSs; } CreateFSTex3D(out fineStructure16_tex3D, out tex3D_tmpBuf, fsBufSize, fsBufRowlen, 16); blkEx_tmpBuf = new uint[this.chunk.blockData.Length]; } }
public abstract void GenerateGeometry(BlockGroup group, Chunk chunk);
public abstract void Render(BlockGroup group);
// 自動配置ブロックの処理 public void WriteToMeshAutoPlacement(BlockGroup blockGroup, BlockMeshMerger meshMerger) { BlockShape shape = this.shape; // 隣接ブロックを取得 var list = new Vector3[] { new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(1, 0, 1), new Vector3(1, 0, -1), new Vector3(-1, 0, -1), new Vector3(-1, 0, 1), new Vector3(0, 0.5f, 0), new Vector3(0, 0.5f, 1), new Vector3(1, 0.5f, 0), new Vector3(0, 0.5f, -1), new Vector3(-1, 0.5f, 0), }; int pattern = 0; for (int i = 0; i < list.Length; i++) { var block = blockGroup.GetBlock(position + EditManager.Instance.ToWorldCoordinate(list[i])); if (block != null) { pattern |= (1 << i); } } for (int i = 0; i < 4; i++) { bool s1 = (pattern & (1 << (i))) != 0; // 隣接1 bool s2 = (pattern & (1 << ((i + 1) % 4))) != 0; // 隣接2 bool s3 = (pattern & (1 << (i + 4))) != 0; // 斜め隣接 bool s4 = (pattern & (1 << 8)) != 0; // 上隣接 bool s5 = (pattern & (1 << (9 + i))) != 0; // 上横隣接1 bool s6 = (pattern & (1 << (9 + (i + 1) % 4))) != 0; // 上横隣接2 int meshOffset; if (s3) { if (s1 && s2) { meshOffset = (s4 && (s5 || s6)) ? -1 : 0; } else if (s1) { meshOffset = (s4) ? (s5) ? 24 : 32 : 8; } else if (s2) { meshOffset = (s4) ? (s6) ? 28 : 36 : 12; } else { meshOffset = (s4) ? 20 : 4; } } else { if (s1 && s2) { meshOffset = 16; } else if (s1) { meshOffset = (s4) ? (s5) ? 24 : 32 : 8; } else if (s2) { meshOffset = (s4) ? (s6) ? 28 : 36 : 12; } else { meshOffset = (s4) ? 20 : 4; } } if (meshOffset < 0) { continue; } var mesh = shape.meshes[6 + meshOffset + i]; if (mesh == null) { continue; } meshMerger.Merge(mesh, this.position, this.direction, Vector3.one, shape.divideChipVert, this.textureChips[6], 0); } }
private void tryBreakIntoPieces() { if (bList.Count == 0) { return; } int[] unionFind = new int[bList.Count]; for (int i = 0; i < unionFind.Length; i++) { unionFind[i] = i; } for (int i = 0; i < bList.Count; i++) { for (int j = i + 1; j < bList.Count; j++) { if (bList[i].gridPosition[0] == bList[j].gridPosition[0]) { if (bList[i].gridPosition[1] + 1 == bList[j].gridPosition[1] || bList[i].gridPosition[1] - 1 == bList[j].gridPosition[1]) { int rootI = i; while (rootI != unionFind[rootI]) { rootI = unionFind[rootI]; } int rootJ = j; while (rootJ != unionFind[rootJ]) { rootJ = unionFind[rootJ]; } if (rootI != rootJ) { unionFind[rootJ] = rootI; } } } else if (bList[i].gridPosition[1] == bList[j].gridPosition[1]) { if (bList[i].gridPosition[0] + 1 == bList[j].gridPosition[0] || bList[i].gridPosition[0] - 1 == bList[j].gridPosition[0]) { int rootI = i; while (rootI != unionFind[rootI]) { rootI = unionFind[rootI]; } int rootJ = j; while (rootJ != unionFind[rootJ]) { rootJ = unionFind[rootJ]; } if (rootI != rootJ) { unionFind[rootJ] = rootI; } } } } } for (int i = 0; i < unionFind.Length; i++) { while (unionFind[i] != unionFind[unionFind[i]]) { unionFind[i] = unionFind[unionFind[i]]; } } Dictionary <int, List <Block> > dic = new Dictionary <int, List <Block> >(); for (int i = 0; i < unionFind.Length; i++) { if (!dic.ContainsKey(unionFind[i])) { dic.Add(unionFind[i], new List <Block>()); } dic[unionFind[i]].Add(bList[i]); } if (dic.Count == 1) { return; } foreach (List <Block> lb in dic.Values) { BlockGroup newBlockGroup = GameObjectPoolManager.Instance.Pool_BlockGroupPool.AllocateGameObject <BlockGroup>(transform.parent); newBlockGroup.transform.rotation = transform.parent.rotation; newBlockGroup.transform.position = transform.position; foreach (Block b in lb) { b.transform.parent = newBlockGroup.transform; } newBlockGroup.Initialize(lb); newBlockGroup.isPiece = true; BlocksManager.Instance.currentBlockGroupPieces.Add(newBlockGroup); } bList.Clear(); isBroken = true; if (isPiece) { BlocksManager.Instance.currentBlockGroupPieces.Remove(this); } PoolRecycle(); BlocksManager.Instance.resetKeyPressTime(); BlocksManager.Instance.resetKeyPressBeginTime(); }
void BlockGenerator() { ScoreText.text = "현재점수 : " + (++score).ToString(); if (PlayerPrefs.GetInt("BestScore", 0) < score) { PlayerPrefs.SetInt("BestScore", score); BestScoreText.text = "최고기록 : " + PlayerPrefs.GetInt("BestScore").ToString(); BestScoreText.color = greenColor; isNewRecord = true; } int count; int randBlock = Random.Range(0, 24); if (score <= 10) { count = randBlock < 16 ? 1 : 2; } else if (score <= 20) { count = randBlock < 8 ? 1 : (randBlock < 16 ? 2 : 3); } else if (score <= 40) { count = randBlock < 9 ? 2 : (randBlock < 18 ? 3 : 4); } else { count = randBlock < 8 ? 2 : (randBlock < 16 ? 3 : (randBlock < 20 ? 4 : 5)); } List <Vector3> SpawnList = new List <Vector3>(); for (int i = 0; i < 6; i++) { SpawnList.Add(new Vector3(-46.7f + i * 18.68f, 51.2f, 0)); } for (int i = 0; i < count; i++) { int rand = Random.Range(0, SpawnList.Count); Transform TR = Instantiate(P_Block, SpawnList[rand], QI).transform; TR.SetParent(BlockGroup); TR.GetChild(0).GetComponentInChildren <Text>().text = score.ToString(); SpawnList.RemoveAt(rand); } Instantiate(P_GreenOrb, SpawnList[Random.Range(0, SpawnList.Count)], QI).transform.SetParent(BlockGroup); isBlockMoving = true; for (int i = 0; i < BlockGroup.childCount; i++) { StartCoroutine(BlockMoveDown(BlockGroup.GetChild(i))); } }
public override void Render(BlockGroup group) { RenderAt(group.transform); }
bool CanDropHere(BlockGroup group, DropZone dropenOn){ BoxCell cellDropenOn = dropenOn.GetComponent<BoxCell>(); return CanDropHere (group, cellDropenOn); }
private MediaTypes EnqueueFrameData(Cluster cluster, Block block, ref long timecode) { MediaTypes currBlockType = MediaTypes.None; Block currBlock = null; BlockGroup blockGroup = null; Queue <FrameBufferData> frameQueue = null; //블록 자식 레벨 엘리먼트 로드 currBlock = block.GetBlock(out blockGroup); //큐 선택 if (currBlock.TrackNumber == VideoTrackID) { currBlockType = MediaTypes.Video; frameQueue = VideoFrameQueue; } else if (currBlock.TrackNumber == AudioTrackID) { currBlockType = MediaTypes.Audio; frameQueue = AudioFrameQueue; } else if (currBlock.TrackNumber == SubtitleTrackID) { currBlockType = MediaTypes.Subtitle; frameQueue = SubtitleFrameQueue; } else { return(MediaTypes.None); } var codec = UsableCodecs.FirstOrDefault(x => x.TrackNumber == currBlock.TrackNumber); var track = codec.TrackEntry; byte[] CompressHeader = codec.CompressHeader; timecode = ((long)cluster.Timecode + currBlock.Timecode) * Element.TIC_MILLISECONDS; long timecodeOffset = 0, duration = (long)(track.DefaultDuration / 100); //100나노 초가 1틱이므로 100으로 나눈다. if (blockGroup != null && blockGroup.BlockDuration > 0) { duration = (long)blockGroup.BlockDuration * Element.TIC_MILLISECONDS; } var dts = currBlock.GetBlockData(CompressHeader); foreach (var item in dts) { try { var frame = codec.GetFrameBufferData( item, (long)timecodeOffset + (long)timecode, duration, currBlock.IsKeyFrame, currBlock.Discardable, currBlock.Invisible); frameQueue.Enqueue(frame); timecodeOffset += duration; } catch (Exception) { throw; } } //리턴값 (마지막 시간) timecode += timecodeOffset; //블록 타입 return(currBlockType); }
public void SetGroup(BlockGroup _group){ group = _group; spR.color = _group.color; }
public override void GenerateGeometry(BlockGroup group, Chunk chunk) { if (waiting) { return; } waiting = true; UnityEngine.Profiling.Profiler.BeginSample("CRender_GSRayM: GenerateGeometry"); inputBuffer.SetData(this.chunk.blockData); if (buffer == null) { UnityEngine.Profiling.Profiler.BeginSample("CRender_GSRayM: Dispatch Kernel1"); _ind = new uint[] { 0, 1, 0, 0, 0 }; indBuffer.SetData(_ind); // Set buffers for I/O cs_chunkMeshPopulator.SetBuffer(1, "indirectBuffer", indBuffer); cs_chunkMeshPopulator.SetBuffer(1, "chunkData", inputBuffer); // Get chunk vert count cs_chunkMeshPopulator.Dispatch(1, 32 / 8, 32 / 8, 32 / 8); UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample("CRender_GSRayM: Readback #vert"); indBuffer.GetData(_ind); UnityEngine.Profiling.Profiler.EndSample(); int allocSize = 65536; if (_ind[0] == 0) { chunk.dirty = false; populated = true; waiting = false; UnityEngine.Profiling.Profiler.EndSample(); return; } else { buffer = new ComputeBuffer(allocSize, System.Runtime.InteropServices.Marshal.SizeOf(typeof(Vertex_GR))); vCount = (uint)allocSize; } } // Set Flatten Factor cs_chunkMeshPopulator.SetInts("flatFactor", this.chunk.flatFactor.x, this.chunk.flatFactor.y, this.chunk.flatFactor.z); #region Overrided // Before readback, fill compute buffer for block ex pointers & tex3D if (fsBufSize > 0) // Do only if we need render fs's { UnityEngine.Profiling.Profiler.BeginSample($"FS16: Fill HostBuffer ({fsBufSize})"); System.Array.Clear(blkEx_tmpBuf, 0, blkEx_tmpBuf.Length); uint bexCount = 0; foreach (var bexPair in chunk.blockExtrasDict) { Vector3Int pos = bexPair.Key; int flatten_ix = pos.x * Chunk.SideLength * Chunk.SideLength + pos.y * Chunk.SideLength + pos.z; blkEx_tmpBuf[flatten_ix] = bexCount | 0x80000000; FillHostBuffer(ref tex3D_tmpBuf, (bexPair.Value as Voxelis.BlockExtras.FineStructure_16).blockData, (int)bexCount); bexCount += 1; if (bexCount >= fsBufSize) { break; } } UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample($"FS16: SetPixelData ({totalMipSize / 512} KiB)"); for (int m = 0; m < mipCount; m++) { fineStructure16_tex3D.SetPixelData(tex3D_tmpBuf, m, mipOffset[m]); } UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.BeginSample($"FS16: Upload ({totalMipSize / 512} KiB)"); fineStructure16_tex3D.Apply(false, true); Globals.voxelisMain.Instance.lastFSTex3D = fineStructure16_tex3D; blockExtraPointers_buffer.SetData(blkEx_tmpBuf); // Assign to material matProp.SetTexture("_FSTex", fineStructure16_tex3D); matProp.SetFloat("blockSize", chunk.blockSize); matProp.SetVector("FStexGridSize", new Vector3(1.0f / (fsBufSize / fsBufRowlen), 1.0f / fsBufRowlen, 1.0f)); UnityEngine.Profiling.Profiler.EndSample(); } #endregion UnityEngine.Profiling.Profiler.BeginSample("CRender_GSRayM: Dispatch Kernel0"); _ind[0] = 0; indBuffer.SetData(_ind); buffer.SetCounterValue(0); cs_chunkMeshPopulator.SetBuffer(0, "vertexBuffer", buffer); cs_chunkMeshPopulator.SetBuffer(0, "indirectBuffer", indBuffer); cs_chunkMeshPopulator.SetBuffer(0, "chunkData", inputBuffer); cs_chunkMeshPopulator.SetBuffer(0, "fsPointerBuffer", blockExtraPointers_buffer); cs_chunkMeshPopulator.SetInt("fsBufLenX", fsBufSize / fsBufRowlen); cs_chunkMeshPopulator.SetInt("fsBufLenY", fsBufRowlen); // Invoke it cs_chunkMeshPopulator.Dispatch(0, 32 / 8, 32 / 8, 32 / 8); // Set an sync fence GPUDispatchManager.Singleton.AppendTask(this); // Update my position position = chunk.centerPos; renderPosition = chunk.positionOffset; bound = new Bounds(chunk.centerPos, Vector3.one * 32.0f); //ExportMesh(buffer, vCount, $"ExportedMeshes/Chunk_{chunk.positionOffset.x / 32}_{chunk.positionOffset.y / 32}_{chunk.positionOffset.z / 32}.obj"); chunk.dirty = false; UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.EndSample(); }
public String AsHtml(IList<Block> blocks, DocumentLinkResolver linkResolver, HtmlSerializer htmlSerializer) { IList<BlockGroup> blockGroups = new List<BlockGroup>(); foreach(Block block in blocks) { BlockGroup lastOne = blockGroups.Count == 0 ? null : blockGroups[blockGroups.Count - 1]; if(lastOne != null && "ul" == lastOne.tag && block is ListItem && !((ListItem)block).IsOrdered) { lastOne.blocks.Add(block); } else if(lastOne != null && "ol" == lastOne.tag && block is ListItem && ((ListItem)block).IsOrdered) { lastOne.blocks.Add(block); } else if(block is ListItem && !((ListItem)block).IsOrdered) { BlockGroup newBlockGroup = new BlockGroup("ul", new List<Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } else if(block is ListItem && ((ListItem)block).IsOrdered) { BlockGroup newBlockGroup = new BlockGroup("ol", new List<Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } else { BlockGroup newBlockGroup = new BlockGroup(null, new List<Block>()); newBlockGroup.blocks.Add(block); blockGroups.Add(newBlockGroup); } } var html = ""; foreach(BlockGroup blockGroup in blockGroups) { if(blockGroup.tag != null) { html += ("<" + blockGroup.tag + ">"); foreach(Block block in blockGroup.blocks) { html += (asHtml(block, linkResolver, htmlSerializer)); } html += ("</" + blockGroup.tag + ">"); } else { foreach(Block block in blockGroup.blocks) { html += (asHtml(block, linkResolver, htmlSerializer)); } } } return html; }
public override void GenerateGeometry(BlockGroup group, Chunk chunk) { GenerateGeometryNeighborAware(group, chunk, null, null, null, null, null, null); }
/// <summary> /// Loads the master record. /// </summary> /// <exception cref="InvalidOperationException">Only volumes aligned on block size are supported.</exception> public void Load() { ulong offset = 0; VolumeSize = _diskAccess.ReadULong(ref offset); _freeSpaceBlocks = _diskAccess.ReadULong(ref offset); if (VolumeSize % Constants.BlockSizeBytes != 0) { throw new InvalidOperationException("Only volumes aligned on block size are supported."); } var rootNodeAddress = new Address(_diskAccess.ReadULong(ref offset)); var groupCount = _diskAccess.ReadULong(ref offset); _groupsReserved = new BlockGroup[groupCount]; for (uint i = 0; i < groupCount; ++i) { var descriptor = new BlockGroupDescriptor(); offset = descriptor.Load(offset, _diskAccess); _groupsReserved[i] = new BlockGroup(descriptor); // block group not initialized at this point. } foreach (var group in _groupsReserved) { var desc = group.Descriptor; group.Load(desc.BitmapsAddress.Value, _diskAccess); } RootNode = GetDirectoryNode(rootNodeAddress); }
// 从真实磁盘读入文件系统 public bool readFileSystemFromRealDisk() { try { FileStream fsTest = new FileStream("disk.img", System.IO.FileMode.Open, FileAccess.Read); fsTest.Close(); } catch (FileNotFoundException) // 未找到文件 { MessageBox.Show("未找到磁盘映像!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } FileStream fs = new FileStream("disk.img", System.IO.FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); String volumnStr = sr.ReadLine(); // 读入卷大小 blockGroup = new BlockGroup(int.Parse(volumnStr), INODENUM); // 建立文件系统 blockGroup.volume = int.Parse(volumnStr); String superBlockStr = sr.ReadLine(); // 读入超级块 blockGroup.superBlock.inodeNum = int.Parse(superBlockStr.Split(' ')[0]); blockGroup.superBlock.freeInodeNum = int.Parse(superBlockStr.Split(' ')[1]); String blockBitMapStr = sr.ReadLine(); // 读入数据块位图 foreach (var index in blockBitMapStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { blockGroup.groupDescriptorList[0].blockBitmap[int.Parse(index)] = false; } String inodeBitMapStr = sr.ReadLine(); // 读入inode位图 foreach (var index in inodeBitMapStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { blockGroup.groupDescriptorList[0].inodeBitmap[int.Parse(index)] = false; } // 逐个读入数据块 foreach (var i in blockBitMapStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { int index = int.Parse(i); DataBlock dataBlock = new DataBlock(); dataBlock.data = new char[BLOCKSIZE / 2]; sr.ReadBlock(dataBlock.data, 0, BLOCKSIZE / 2); blockGroup.dataBlockList[index] = dataBlock; } sr.ReadLine(); // 逐个读入inode foreach (var i in inodeBitMapStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { int index = int.Parse(i); Inode inode = new Inode(); String inodeStr = sr.ReadLine(); var strList = inodeStr.Split(' '); // 读入文件类型 if (strList[0] == FileMode.directory.ToString()) { inode.fileMode = FileMode.directory; } else if (strList[0] == FileMode.common.ToString()) { inode.fileMode = FileMode.common; } else { inode.fileMode = FileMode.unknown; } // 读入文件大小 inode.fileSize = int.Parse(strList[1]); // 读入文件名称 inode.fileName = strList[2]; // 读入创建时间 inode.createdTime = DateTime.Parse(strList[3] + ' ' + strList[4]); // 读入更新时间 inode.updatedTime = DateTime.Parse(strList[5] + ' ' + strList[6]); // 读入占块数 inode.blockSize = int.Parse(strList[7]); // 读入占用的数据块的索引 inode.dataBlockList = new List <int>(); foreach (var j in strList[8].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)) { inode.dataBlockList.Add(int.Parse(j)); } // 读入子文件的inode索引 inode.childInodeIndex = new List <int>(); foreach (var j in strList[9].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)) { inode.childInodeIndex.Add(int.Parse(j)); } // 读入子文件数量 inode.childrenNum = int.Parse(strList[10]); // 读入父目录编号 inode.fatherIndex = int.Parse(strList[11]); // 写入inode blockGroup.inodeList[index] = inode; } sr.Close(); fs.Close(); return(true); }
public abstract void Init(BlockGroup group, Chunk chunk);
public static void blk_drawGhost(BlockGroup blkG, int col, int row) { blkG.AddBlock(GraphicDefs.ght_draw(blkG.GetField()).Move(blkG.GetLocation().x + col + ((blkG.GetLocation().y - row) * blkG.GetField().GetDimentions().width))); }
public override void GenerateGeometry(BlockGroup group, Chunk chunk) { if (waiting) { return; } waiting = true; _ind = new uint[] { 0, 1, 0, 0, 0 }; indBuffer.SetData(_ind); inputBuffer.SetData(this.chunk.blockData); // Set buffers for I/O cs_chunkMeshPopulator.SetBuffer(1, "indirectBuffer", indBuffer); cs_chunkMeshPopulator.SetBuffer(1, "chunkData", inputBuffer); // Get chunk vert count cs_chunkMeshPopulator.Dispatch(1, 32 / 8, 32 / 8, 32 / 8); indBuffer.GetData(_ind); int allocSize = (int)(_ind[0] * 1.25) + 1024; //int allocSize = 65536; //_ind[0] = 65536; // Need to extend buffer size if (vCount < _ind[0]) { // Realloc if (buffer != null) { buffer_bak = buffer; matProp.SetBuffer("cs_vbuffer", buffer_bak); } // 1.0 - scale factor for potentially more blocks buffer = new ComputeBuffer(allocSize, System.Runtime.InteropServices.Marshal.SizeOf(typeof(Vertex))); } else if (_ind[0] == 0) { chunk.dirty = false; populated = true; waiting = false; return; } vCount = (uint)allocSize; _ind[0] = 0; indBuffer.SetData(_ind); buffer.SetCounterValue(0); cs_chunkMeshPopulator.SetBuffer(0, "vertexBuffer", buffer); cs_chunkMeshPopulator.SetBuffer(0, "indirectBuffer", indBuffer); cs_chunkMeshPopulator.SetBuffer(0, "chunkData", inputBuffer); // Invoke it cs_chunkMeshPopulator.Dispatch(0, 32 / 8, 32 / 8, 32 / 8); // Set an sync fence GPUDispatchManager.Singleton.AppendTask(this); //Vertex[] output = new Vertex[262144]; //buffer.GetData(output); //indBuffer.GetData(_ind); //Debug.Log("CS finished with " + _ind[0] + " vertices"); //Debug.Log(_ind); // Update my position position = chunk.centerPos; renderPosition = chunk.positionOffset; bound = new Bounds(chunk.centerPos, Vector3.one * 32.0f); chunk.dirty = false; }
void DropBlocksOnDropZone(BlockGroup g, DropZone d){ int gNumber = gamePlayMaster.blocksContainer.GetBlockGroupID(g); Coord cellCoord = gamePlayMaster.CoordForDropZone(d); photonView.RPC ("DropBlocksOnDropZone_RPC", PhotonTargets.All, gNumber, cellCoord.x, cellCoord.y); }
private static void WriteMetaFile(string path, Vector3 offset, bool toRightHanded) { BlockGroup blockGroup = EditManager.Instance.Layers[0].GetBlockGroup(); ModelGroup modelGroup = EditManager.Instance.Layers[0].GetModelGroup(); Mesh mesh = blockGroup.GetRouteMesh(); Block[] blocks = blockGroup.GetEnterableBlocks(); // モデルを見て移動可能かどうかをチェックする blocks = blocks.Where(block => { var model = modelGroup.GetModel(block.position); return(model == null || model.shape.enterable); }).ToArray(); var fieldPanels = new FieldPanelGroup(mesh, blocks, offset); fieldPanels.ApplyRoutePath(blockGroup, EditManager.Instance.RoutePath); // バウンディングボックス Vector3 minpos = mesh.bounds.min + offset; Vector3 maxpos = mesh.bounds.max + offset; // 座標系反転処理 if (toRightHanded) { fieldPanels.ApplyRightHanded(); minpos = FileUtil.ApplyRightHanded(minpos); maxpos = FileUtil.ApplyRightHanded(maxpos); float z = minpos.z; minpos.z = maxpos.z; maxpos.z = z; } var mem = new MemoryStream(); var writer = new BinaryWriter(mem); writer.Write("E3MT".ToArray()); // Identifier writer.Write(2); // Version // バウンディングボックス writer.Write(minpos); writer.Write(maxpos); // 移動パネル fieldPanels.Write(writer); // 当たり判定ブロック Block[] colliderBlocks = blockGroup.GetAllBlocks(); writer.Write(colliderBlocks.Length); Vector3 colliderOffset = new Vector3(0.5f, 0.25f, 0.5f); foreach (var block in colliderBlocks) { Vector3 position = block.position; if (toRightHanded) { position = FileUtil.ApplyRightHanded(position); } position += colliderOffset; writer.Write(position); } // 3Dモデル配置 Model[] models = modelGroup.GetAllModels(); writer.Write(models.Length); foreach (var model in models) { Vector3 position = model.position; if (toRightHanded) { position = FileUtil.ApplyRightHanded(position); } writer.Write(model.shape.id); writer.Write(position); writer.Write(model.offset); writer.Write((float)model.rotation); writer.Write(model.shape.scale * model.scale); } File.WriteAllBytes(path, mem.ToArray()); }
public int GetBlockGroupID(BlockGroup g){ return blocks.IndexOf (g); }
public static MasterRecord CreateNewVolume([NotNull] IDirectDiskAccess access, ulong size) { Validate.ArgumentNotNull(access, "access"); if (size % Constants.BlockSizeBytes != 0) { throw new ArgumentOutOfRangeException("Volume size should be on block size boundary."); } if (size <= BlockGroup.ReservedBlocks * Constants.BlockSizeBytes) { throw new ArgumentOutOfRangeException(string.Format("Min volume size is {0}", Constants.BlockSizeBytes * (BlockGroup.ReservedBlocks + 1))); } var totalBlocks = (uint)(size / Constants.BlockSizeBytes); uint numberOfFullGroups = totalBlocks / Constants.BlocksPerGroup; uint remainingBlocks = totalBlocks % Constants.BlocksPerGroup; if (remainingBlocks > BlockGroup.ReservedBlocks) { numberOfFullGroups++; } var rec = new MasterRecord(access); rec._groupsReserved = new BlockGroup[numberOfFullGroups]; var offset = new Address(32 + (BlockGroupDescriptor.RawSizeBytes * numberOfFullGroups)); offset = offset.AlignOnBlockBoundary; uint totalFreeBlocks = 0; for (uint i = 0; i < numberOfFullGroups; ++i) { bool last = (i == numberOfFullGroups - 1 && remainingBlocks > 0); var groupSize = last ? remainingBlocks : Constants.BlocksPerGroup; var newGroup = new BlockGroup(offset, groupSize); offset = offset.AddBlocks(groupSize); totalFreeBlocks += newGroup.Descriptor.NumFreeBlocksInGroup; rec._groupsReserved[i] = newGroup; } rec._freeSpaceBlocks = totalFreeBlocks; rec.VolumeSize = offset.Value; rec.RootNode = rec.CreateDirectoryNode("\\", null); return rec; }
// 6方向ブロックメッシュ public void WriteToMeshStandard(BlockGroup blockGroup, BlockMeshMerger meshMerger) { BlockShape shape = this.shape; for (int i = 0; i < shape.meshes.Length; i++) { int index = this.ToLocalDirection(i); var mesh = shape.meshes[index]; if (mesh == null) { continue; } // 隣のブロックに完全に覆われていたら省略する if (i < 6 && this.IsOcculuded(blockGroup, (BlockDirection)i)) { continue; } // 一番下の底面は省略する if ((BlockDirection)i == BlockDirection.Yminus && this.position.y == 0.0f) { continue; } Vector3 position = this.position; Vector3 scale = Vector3.one; // 側面パネルの場合は分割する bool divideChipVert = shape.divideChipVert && i < 6 && (BlockDirection)i != BlockDirection.Yplus && (BlockDirection)i != BlockDirection.Yminus; if (divideChipVert && this.IsCombinable((BlockDirection)i)) { BlockDirection direction = (BlockDirection)i; // 上下に2個続いているブロックをまとめる if (this.position.y - Math.Floor(this.position.y) >= 0.5f) { Block neighborBlock = blockGroup.GetBlock(this.position - new Vector3(0, 0.5f, 0)); if (neighborBlock != null && neighborBlock.IsCombinable(direction) && this.GetTextureChip(direction) == neighborBlock.GetTextureChip(direction)) { divideChipVert = false; position.y -= 0.25f; scale.y = 2.0f; } } else { Block neighborBlock = blockGroup.GetBlock(this.position + new Vector3(0, 0.5f, 0)); if (neighborBlock != null && neighborBlock.IsCombinable(direction) && this.GetTextureChip(direction) == neighborBlock.GetTextureChip(direction)) { if (!neighborBlock.IsOcculuded(blockGroup, direction)) { continue; } } } } meshMerger.Merge(mesh, position, this.direction, scale, divideChipVert, this.textureChips[index], i); } }
public VM() { allscripts = new BlockGroup<Script>(this); }
public static int DestroyBlocksRadius(Vec2 pPosition, float pRadius, Thing culprit, bool pExplode = false, bool destroyWindows = true, bool destroyPhyObjs = true, bool explodeMakeFire = false) { if (destroyWindows) { foreach (Window w in Level.CheckCircleAll <Window>(pPosition, pRadius - 20f)) { Thing.Fondle(w, DuckNetwork.localConnection); if (Level.CheckLine <Block>(pPosition, w.position, w) == null) { w.Destroy(new DTImpact(culprit)); } } } if (destroyPhyObjs) { foreach (PhysicsObject p in Level.CheckCircleAll <PhysicsObject>(pPosition, pRadius + 30f)) { if (p == culprit) { continue; } if (culprit.isLocal && culprit.owner == null) { Thing.Fondle(p, DuckNetwork.localConnection); } if ((p.position - pPosition).length < 30f) { p.Destroy(new DTImpact(culprit)); } p.sleeping = false; p.vSpeed = -2f; } } int idd = 0; HashSet <ushort> idx = new HashSet <ushort>(); foreach (BlockGroup block2 in Level.CheckCircleAll <BlockGroup>(pPosition, pRadius)) { if (block2 == null) { continue; } BlockGroup group = block2; foreach (Block bl in group.blocks) { if (!Collision.Circle(pPosition, pRadius - 22f, bl.rectangle)) { continue; } bl.shouldWreck = true; if (bl is AutoBlock { indestructable: false } block) { idx.Add(block.blockIndex); if (pExplode && idd % 10 == 0) { Level.Add(new ExplosionPart(block.x, block.y)); if (explodeMakeFire) { Level.Add(SmallFire.New(block.x, block.y, Rando.Float(-2f, 2f), Rando.Float(-2f, 2f))); } } idd++; } } group.Wreck(); } foreach (Block block in Level.CheckCircleAll <Block>(pPosition, pRadius - 22f)) { if (block is AutoBlock { indestructable: false } autoBlock) { autoBlock.skipWreck = true; autoBlock.shouldWreck = true; idx.Add(autoBlock.blockIndex); if (pExplode) { if (idd % 10 == 0 && explodeMakeFire) { Level.Add(new ExplosionPart(autoBlock.x, autoBlock.y)); Level.Add(SmallFire.New(autoBlock.x, autoBlock.y, Rando.Float(-2f, 2f), Rando.Float(-2f, 2f))); } idd++; } }