internal IGrid CreateForEditor(CellMatrixData data) { var cellMatrix = CellMatrix.CreateForEditor(this, data); var subSections = CreateSubSections(cellMatrix.start); return(Grid.Create(cellMatrix, subSections)); }
private IEnumerator Populate(CellMatrixData data) { var accessor = data.GetAccessor(); //Get the height lookup _heightLookup = CreateHeightLookup(accessor.heightEntries); for (int x = 0; x < _heightMapSizeX; x++) { for (int z = 0; z < _heightMapSizeZ; z++) { var idx = (x * _heightMapSizeZ) + z; var height = accessor.GetHeight(idx); _heightLookup.Add(x, z, height); yield return(null); } } _heightLookup.Cleanup(); //Init the cells var heightSampler = GetHeightSampler(); var cellFactory = GameServices.cellConstruction.cellFactory; var maxHeight = _origin.y + _upperBoundary; var minHeight = _origin.y - _lowerBoundary; for (int x = 0; x < this.columns; x++) { for (int z = 0; z < this.rows; z++) { var idx = (z * this.columns) + x; var position = new Vector3(_start.x + (x * _cellSize) + (_cellSize / 2.0f), _origin.y, _start.z + (z * _cellSize) + (_cellSize / 2.0f)); position.y = Mathf.Clamp(heightSampler.SampleHeight(position, this), minHeight, maxHeight); var blocked = accessor.IsPermaBlocked(idx); var cell = cellFactory.Create(this, position, x, z, blocked); accessor.InjectData(cell, idx); this.rawMatrix[x, z] = cell; yield return(null); } } //For now we don't bake clearance data var cellConstruct = GameServices.cellConstruction; if (cellConstruct.clearanceProvider != null) { var iter = cellConstruct.clearanceProvider.SetClearance(this); while (iter.MoveNext()) { yield return(null); } } }
internal void Create(CellMatrixData data, int maxMillisecondsUsedPerFrame, Action <IGrid> callback) { Ensure.ArgumentNotNull(data, "data"); LoadBalancer.defaultBalancer.Add( new LongRunningAction(() => CreateIncrementally(data, callback), maxMillisecondsUsedPerFrame), 0.01f, true); }
/// <summary> /// Creates a grid configuration based on the prebaked data /// </summary> /// <param name="data">The data.</param> /// <returns>The grid.</returns> public IGrid Create(CellMatrixData data) { Ensure.ArgumentNotNull(data, "data"); var cellMatrix = CellMatrix.Create(this, data); var subSections = CreateSubSections(cellMatrix.start); return(Grid.Create(cellMatrix, subSections)); }
/// <summary> /// Creates a cell matrix based on the given configuration and stored data. /// </summary> /// <param name="cfg">The configuration.</param> /// <param name="data">The data.</param> /// <returns>The matrix</returns> public static CellMatrix Create(ICellMatrixConfiguration cfg, CellMatrixData data) { var matrix = new CellMatrix(cfg); var iter = matrix.Populate(data); while (iter.MoveNext()) { /* NOOP, we just iterate over all */ } return(matrix); }
internal static CellMatrix CreateForEditor(ICellMatrixConfiguration cfg, CellMatrixData data) { var matrix = new CellMatrix(cfg); if (data == null) { matrix._heightLookup = matrix.CreateHeightLookup(0); } else { matrix.InitHeightMapForEditor(data); } return(matrix); }
private IEnumerator CreateIncrementally(CellMatrixData data, Action <IGrid> callback) { var cellMatrixInitializer = CellMatrix.CreateIncrementally(this, data); while (cellMatrixInitializer.isInitializing) { yield return(null); } var cellMatrix = cellMatrixInitializer.matrix; var subSections = CreateSubSections(cellMatrix.start); yield return(null); var grid = Grid.Create(cellMatrix, subSections); callback(grid); }
private void InitHeightMapForEditor(CellMatrixData data) { var accessor = data.GetAccessor(); //Get the height map _heightLookup = CreateHeightLookup(accessor.heightEntries); for (int x = 0; x < _heightMapSizeX; x++) { for (int z = 0; z < _heightMapSizeZ; z++) { var idx = (x * _heightMapSizeZ) + z; var height = accessor.GetHeight(idx); _heightLookup.Add(x, z, height); } } _heightLookup.Cleanup(); }
internal void EnsureGrid() { if (this.grid == null) { var builder = GetBuilder(); if (this.bakedData != null) { this.grid = builder.Create(this.bakedData); if (!this.storeBakedDataAsAsset) { //No need to hang on to this anymore. this.bakedData = null; } } else { this.grid = builder.Create(); } } }
internal MatrixIncrementalInitializer(ICellMatrixConfiguration cfg, CellMatrixData data) { _matrix = new CellMatrix(cfg); _iter = _matrix.Populate(data); }
internal DataAccessor(CellMatrixData data) { _data = data; _blockedLookup = new HashSet <int>(_data._blockedIndexes); }
internal static MatrixIncrementalInitializer CreateIncrementally(ICellMatrixConfiguration cfg, CellMatrixData data) { return(new MatrixIncrementalInitializer(cfg, data)); }
private IEnumerator CreateIncrementally(CellMatrixData data, Action<IGrid> callback) { var cellMatrixInitializer = CellMatrix.CreateIncrementally(this, data); while (cellMatrixInitializer.isInitializing) { yield return null; } var cellMatrix = cellMatrixInitializer.matrix; var subSections = CreateSubSections(cellMatrix.start); yield return null; var grid = Grid.Create(cellMatrix, subSections); callback(grid); }
internal void Create(CellMatrixData data, int maxMillisecondsUsedPerFrame, Action<IGrid> callback) { Ensure.ArgumentNotNull(data, "data"); LoadBalancer.defaultBalancer.Add( new LongRunningAction(() => CreateIncrementally(data, callback), maxMillisecondsUsedPerFrame), 0.01f, true); }
internal IGrid CreateForEditor(CellMatrixData data) { var cellMatrix = CellMatrix.CreateForEditor(this, data); var subSections = CreateSubSections(cellMatrix.start); return Grid.Create(cellMatrix, subSections); }
/// <summary> /// Creates a grid configuration based on the prebaked data /// </summary> /// <param name="data">The data.</param> /// <returns>The grid.</returns> public IGrid Create(CellMatrixData data) { Ensure.ArgumentNotNull(data, "data"); var cellMatrix = CellMatrix.Create(this, data); var subSections = CreateSubSections(cellMatrix.start); return Grid.Create(cellMatrix, subSections); }
internal DataAccessor(CellMatrixData data) { _data = data; _blockedLookup = new HashSet<int>(_data._blockedIndexes); }
internal void UpdateForEditor(Bounds extent, CellMatrixData data) { var bounds = GetMatrixBounds(extent.center, extent.extents.x + (_cellSize * 2), extent.extents.z + (_cellSize * 2), 0.0f, true); if (data == null) { var blockThreshold = Mathf.Max(_obstacleSensitivityRange, 0.01f); for (int x = bounds.minColumn; x <= bounds.maxColumn; x++) { for (int z = bounds.minRow; z <= bounds.maxRow; z++) { var cell = this.rawMatrix[x, z]; if (cell == null) { var position = new Vector3(_start.x + (x * _cellSize) + (_cellSize / 2.0f), _origin.y, _start.z + (z * _cellSize) + (_cellSize / 2.0f)); var blocked = IsBlocked(position, blockThreshold); this.rawMatrix[x, z] = _cellFactory.Create(this, position, x, z, blocked); } else { var cellPos = cell.position; var blocked = IsBlocked(cellPos, blockThreshold); cell.UpdateState(cellPos.y, blocked); } } } } else { var accessor = data.GetAccessor(); var heightSampler = GetHeightSampler(); var maxHeight = _origin.y + _upperBoundary; var minHeight = _origin.y - _lowerBoundary; //Init the cells for (int x = bounds.minColumn; x <= bounds.maxColumn; x++) { for (int z = bounds.minRow; z <= bounds.maxRow; z++) { var cell = this.rawMatrix[x, z]; if (cell == null) { var idx = (z * this.columns) + x; var position = new Vector3(_start.x + (x * _cellSize) + (_cellSize / 2.0f), _origin.y, _start.z + (z * _cellSize) + (_cellSize / 2.0f)); position.y = Mathf.Clamp(heightSampler.SampleHeight(position, this), minHeight, maxHeight); var blocked = accessor.IsPermaBlocked(idx); cell = _cellFactory.Create(this, position, x, z, blocked); accessor.InjectData(cell, idx); this.rawMatrix[x, z] = cell; cell.EnsureDataForEditor(); } } } } }