/// <summary> /// Gets the <c>DataColumn</c> from the given <paramref name="pos"/>. /// </summary> /// <param name="pos">Column position.</param> /// <returns><c>DataColumn</c> that exists at <paramref name="pos"/>.</returns> public static DataColumn GetColumn(ColumnPos pos) { DataColumn column; _columns.TryGetValue(pos, out column); return(column); }
private int[,] _surface; // Start of stone layer //private int[,] _light; // Highest opaque block /// <summary> /// Create a new <c>DataColumn</c> with a given position. /// </summary> /// <param name="pos">Column position.</param> public DataColumn(ColumnPos pos) { _pos = pos; _surface = new int[World.chunkSize, World.chunkSize]; //_light = new int[_chunkSize, _chunkSize]; for (int i = 0; i < World.chunkSize; ++i) { for (int j = 0; j < World.chunkSize; ++j) { _surface[i, j] = World.GenerateTopology(i + _pos.x * World.chunkSize, j + _pos.z * World.chunkSize); //_light[i, j] = _surface[i, j] + 3; } } }
/// <summary> /// Generates all possible chunk positions that are in view range if a chunk does not already exist at that position. /// </summary> private void GenerateChunks() { // Which direction is the player pointing in? Vector3 pov = Camera.main.transform.rotation * Vector3.forward; pov.y = 0; // Flatten it as we want it to be horizontal // Iterate through x, y, z for (int x = _playerPos.x - _viewRangeHorizontal - 1; x <= _playerPos.x + _viewRangeHorizontal + 1; ++x) { for (int z = _playerPos.z - _viewRangeHorizontal - 1; z <= _playerPos.z + _viewRangeHorizontal + 1; ++z) { ColumnPos grid = new ColumnPos(x, z); DataColumn newDataColumn; // Does column exist? if (!_columns.ContainsKey(grid)) { // Create new data column newDataColumn = new DataColumn(grid); // Store in map _columns[grid] = newDataColumn; } else { newDataColumn = _columns[grid]; } for (int y = _playerPos.y - _viewRangeVertical - 1; y <= _playerPos.y + _viewRangeVertical + 1; ++y) { ChunkPos pos = new ChunkPos(x, y, z); // Does chunk exist? if (!_chunks.ContainsKey(pos)) // && ChunkPos.Distance(pos, _playerPos) <= _viewRangeHorizontal) { // Create new chunk and get corresponding script GameObject newChunk = Instantiate(_chunkPrefab, new Vector3(x * chunkSize, y * chunkSize, z * chunkSize), Quaternion.identity); Chunk newChunkScript = newChunk.GetComponent <Chunk>(); DataChunk newDataChunk; if (_offloadChunks.ContainsKey(pos)) { // Retrieve from offload newDataChunk = _offloadChunks[pos]; // Give data chunk gameobject newDataChunk.SetChunk(newChunkScript); // Remove from offload _offloadChunks.Remove(pos); } else { // Create new data chunk newDataChunk = new DataChunk(pos, newChunkScript, newDataColumn); } // Let chunk know its corresponding data chunk and position newChunkScript.LoadData(pos, newDataChunk); // Should chunk render yet? //newChunkScript.SetRender(CubeDistance(_playerPos, pos) <= _viewRangeHorizontal); // Get angle difference between vectors Vector3 dir = pos * chunkSize - Camera.main.transform.position; float dist = dir.magnitude; float diff = Vector3.Angle(pov, dir); float final = dist + diff; if (dist < chunkSize * 2f) // Prioritize chunks immediately closest { final = dist; } // Queue chunk for generation _loadQueue.Enqueue(newChunkScript, final); // Store in map _chunks[pos] = newDataChunk; } } } } // Are there chunks that need generation? if (!_rendering && _loadQueue.Count > 0) { _rendering = true; new Thread(RenderThread).Start(); } }
/// <summary> /// Setup the sorting. /// Uses the param_sortby_readable, and adds missing columns to be calculated, but not displayed /// builds param_sortby_columns, which is a list of the column numbers /// based on these numbers the rows should be sorted, starting with the last number /// /// </summary> /// <returns>void</returns> public void SetupSorting() { StringCollection Calculations; String SortByColumnNumber; System.Int32 Counter; System.Int32 ColumnPos; if (Parameters.Exists("param_sortby_readable")) { if (MaxDisplayColumns == -1) { throw new Exception("MaxDisplayColumns is not set."); } SortByColumnNumber = ""; Calculations = StringHelper.StrSplit(Parameters.Get("param_sortby_readable").ToString(), ","); // go through all calculations, that have been selected for sorting foreach (String calculation in Calculations) { // is the calculation displayed in a column? ColumnPos = -1; for (Counter = 0; Counter <= MaxDisplayColumns - 1; Counter += 1) { String ColumnName = Parameters.Get("param_calculation", Counter).ToString(); // If the name is DataLabelColumn then we have something like office specific // data and we need to get the real name. if ((ColumnName == "DataLabelColumn") && (Parameters.Exists("param_label", Counter))) { ColumnName = Parameters.Get("param_label", Counter).ToString(); } if (ColumnName == calculation) { ColumnPos = Counter; break; } } // if the column is not displayed, add it beyond the MaxDisplayColumns if (ColumnPos == -1) { AddColumnCalculation(NewTempColumn, calculation); ColumnPos = NewTempColumn; NewTempColumn = NewTempColumn + 1; } if (SortByColumnNumber.Length != 0) { SortByColumnNumber = SortByColumnNumber + ','; } SortByColumnNumber = SortByColumnNumber + ColumnPos.ToString(); } if (SortByColumnNumber.Length != 0) { Parameters.Add("param_sortby_columns", SortByColumnNumber); } } }