/// <summary> /// パーティションを追加します。 /// </summary> /// <param name="partition">パーティション。</param> public void AddPartition(Partition partition) { lock (partitionsByPosition) { partitionsByPosition[partition.Position] = partition; } }
/// <summary> /// パーティションを追加します。 /// </summary> /// <param name="partition">パーティション。</param> public void AddPartition(Partition partition) { IntVector3 clusterPosition; CalculateClusterPosition(ref partition.Position, out clusterPosition); Cluster cluster; lock (clustersByPosition) { if (!clustersByPosition.TryGetValue(clusterPosition, out cluster)) { cluster = clusterPool.Borrow(); cluster.Initialize(clusterPosition); clustersByPosition[clusterPosition] = cluster; } } cluster.AddPartition(partition); }
/// <summary> /// パーティションが非アクティブ化された事を隣接パーティションへ通知します。 /// </summary> /// <param name="partition">非アクティブ化されたパーティション。</param> void NortifyNeighborPassivated(Partition partition) { for (int i = 0; i < Side.Items.Count; i++) { var side = Side.Items[i]; var nearbyPosition = partition.Position + side.Direction; var neighbor = clusterManager.GetPartition(nearbyPosition); if (neighbor == null) continue; var reverseSide = side.Reverse(); neighbor.OnNeighborPassivated(partition, reverseSide); } }
/// <summary> /// パーティションがアクティブ化された事を隣接パーティションへ通知します。 /// </summary> /// <param name="partition">アクティブ化されたパーティション。</param> void NotifyNeighborActivated(Partition partition) { for (int i = 0; i < Side.Items.Count; i++) { var side = Side.Items[i]; var nearbyPosition = partition.Position + side.Direction; var neighbor = clusterManager.GetPartition(nearbyPosition); if (neighbor == null) continue; // 自身へアクティブな隣接パーティションを通知。 partition.OnNeighborActivated(neighbor, side); // アクティブな隣接パーティションへ自身を通知。 var reverseSide = side.Reverse(); neighbor.OnNeighborActivated(partition, reverseSide); } }
protected virtual void OnActivated(Partition partition) { }
protected virtual void OnPassivating(Partition partition) { }
void LoadResultCallback(Partition partition) { // mark. partition.LoadState = PartitionLoadState.Loaded; int x = partition.X; int y = partition.Y; foreach (var p in partitions) { if (p.LoadState != PartitionLoadState.Loaded || p == partition) continue; bool isNeighbor = false; if (p.Y == y && (p.X == x - 1 || p.X == x + 1)) { isNeighbor = true; } if (p.X == x && (p.Y == y - 1 || p.Y == y + 1)) { isNeighbor = true; } if (isNeighbor) p.NeighborLoaded(partition); } }
/// <summary> /// このクラスの実装では、以下の処理を行います。 /// /// ・チャンクのメッシュ更新を要求。 /// ・チャンクのノードをノード グラフへ追加。 /// /// </summary> /// <param name="partition"></param> protected override void OnActivated(Partition partition) { var chunk = partition as Chunk; // ノードを追加。 BaseNode.Children.Add(chunk.Node); base.OnActivated(partition); }
public virtual void NeighborLoaded(Partition neighbor) { }
protected override void OnNeighborPassivated(Partition neighbor, Side side) { lock (neighbors) { neighbors[side] = null; } base.OnNeighborPassivated(neighbor, side); }
protected override void OnNeighborActivated(Partition neighbor, Side side) { lock (neighbors) { neighbors[side] = neighbor as Chunk; bool allNeighborsExist = true; for (int i = 0; i < neighbors.Count; i++) { if (neighbors[i] == null) { allNeighborsExist = false; break; } } if (allNeighborsExist) { // 隣接チャンクが揃ってからメッシュ構築を要求するが、 // 実際にはメッシュ構築の最中に隣接チャンクが非アクティブ化されることもある。 chunkManager.RequestUpdateMesh(this, ChunkMeshUpdatePriority.Normal); } } base.OnNeighborActivated(neighbor, side); }
public override void NeighborLoaded(Partition neighbor) { var n = neighbor as DemoPartition; if (n.Y == Y) { if (n.X == X - 1) { heightMap.MergeLeftNeighbor(n.heightMap); normalMap.MergeLeftNeighbor(n.normalMap); } else if (n.X == X + 1) { heightMap.MergeRightNeighbor(n.heightMap); normalMap.MergeRightNeighbor(n.normalMap); } else { throw new InvalidOperationException("The specified partition is not a neighbor."); } } else if (n.X == X) { if (n.Y == Y - 1) { heightMap.MergeTopNeighbor(n.heightMap); normalMap.MergeTopNeighbor(n.normalMap); } else if (n.Y == Y + 1) { heightMap.MergeBottomNeighbor(n.heightMap); normalMap.MergeBottomNeighbor(n.normalMap); } else { throw new InvalidOperationException("The specified partition is not a neighbor."); } } else { throw new InvalidOperationException("The specified partition is not a neighbor."); } base.NeighborLoaded(neighbor); }
/// <summary> /// 隣接パーティションが非アクティブになった時に呼び出されます。 /// </summary> /// <param name="neighbor">非アクティブになった隣接パーティション。</param> /// <param name="side">隣接パーティションの方向。</param> protected internal virtual void OnNeighborPassivated(Partition neighbor, Side side) { }