Skip to content

Conversation

@AsPJT
Copy link
Owner

@AsPJT AsPJT commented Dec 3, 2025

このプルリクエスト(#153)は、 シミュレーションのパフォーマンス向上(バイナリ対応)可視化の品質向上(移動線・色指定・バグ修正) の2つが大きな柱となっています。

具体的な改修内容を3つのポイントに整理して解説します。


1. A*アルゴリズムの改良と「棒・ループ」バグの修正

集落の移動経路を計算するAStarクラス(経路探索)と、その描画ロジックに重要な修正が入っています。

  • 「棒(Stick)」と「ループ」の防止策(setPath関数)

    • 問題: 以前は、探索失敗時やグリッド変換の誤差により、始点・終点付近で経路が予期せぬ場所(原点0,0など)へ飛んでしまう「棒(Stick)」のような描画アーティファクトや、始点付近でくるりと回ってしまう「ループ」が発生していたようです。
    • 修正:
      • 親ノードが(0,0)の場合の不正アクセスチェックを追加し、異常な経路を遮断。
      • 始点・終点と、A*のグリッド中心点が近すぎる場合(skip_dist_sq以内)、そのグリッド点を間引く処理を追加。これにより、スプライン曲線で結んだ際に端点が不自然に歪むのを防いでいます。
      • 経路が見つからない、またはフィルタリングで点が足りなくなった場合は、単純な直線(Start -> End)にフォールバックする安全装置が強化されました。
  • 集落移動の描画リッチ化(drawMovementLines関数)

    • スプライン曲線: 移動履歴を滑らかな曲線(paxg::Spline2D)で描画するように変更されました。
    • 矢印の追加: パスの最後の区間に矢印(drawArrow)が追加され、集落が「どちらの方向に移動したか」が視覚的に明確になりました。

2. バイナリ形式の地名・地物データ読み込み対応

これまでTSV(テキスト)形式のみだったデータ読み込みにおいて、より高速なバイナリ形式のサポートが拡充されました。

  • 型付きカラムのサポート:
    • 単なる文字列ではなく、latitude(緯度)、first_year/last_year(年代)、min_size/max_size(表示ズームレベル)といった数値を、バイナリデータとして適切に読み書きする機能(BinaryColumnType)が実装されました。
    • getInt32getFloat といった型指定の取得メソッドが追加され、キャストのコストを下げつつ精度を維持しています。
    • 注意点: バイナリ形式では forEachRow による行反復処理がサポートされないため、個別のセル取得メソッドを使用するよう設計が変更されています(警告ログ PAXS_WARNING が追加されています)。

3. フロー曲線と領域線の「色指定」対応

海流(FlowCurves)や文化圏(Territories)の描画色を、データファイル側から柔軟に指定できるようになりました。

  • TSVデータの変更:
    • Kuroshio.tsvShimotabaru.tsv などのデータファイルに color カラムが追加されました。
    • これまでの black 一辺倒から、#3C6491(海流の青系)や #888888(領域のグレー系)など、具体的なHEXカラーコードが指定されています。
  • カラーユーティリティの実装(ColorUtility.hpp):
    • 16進数のカラーコード(例: #fe78ba)をパースして、エンジンの色オブジェクト(paxg::Color)に変換する機能が追加されました。これで、データ側で視覚表現をコントロールしやすくなります。

まとめ

このPRによって、 「集落の移動線が綺麗になり(矢印付き・バグ解消)」「海流や文化圏を色分けして見やすく表示」 できるようになり、かつ 「大規模データの読み込み高速化(バイナリ対応)」 の準備が整ったことになります。

特に移動シミュレーションの可視化において、経路が荒ぶる現象が解消されているはずですので、確認時は集落移動の軌跡の滑らかさに注目すると良いでしょう。

@AsPJT AsPJT requested a review from guinpen98 December 3, 2025 12:24
@AsPJT AsPJT changed the title バイナリ地名・地物データの読み込み対応&A*アルゴリズムと集落移動描画の改良 バイナリ地名・地物データの読み込み対応&A*アルゴリズムと集落移動描画の改良&フロー曲線と領域線の色入力対応 Dec 3, 2025
}

// 2バイト目:データの個数のバイト数
if (!reader.safeCheck(1)) return false;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cppcheck-warning] reported by reviewdog 🐶
warning: Identical condition '!reader.safeCheck(1)', second condition is always false [identicalConditionAfterEarlyExit]

@guinpen98 guinpen98 requested review from Copilot and removed request for guinpen98 December 20, 2025 02:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements three major improvements to the simulation system: (1) Binary data format support for faster loading of place names and locale data, (2) A pathfinding bug fixes* to eliminate "stick" and "loop" visual artifacts in settlement movement rendering, and (3) Hex color string support for flow curves and territories to enable data-driven color customization.

Key Changes

  • Fixed A* pathfinding artifacts by adding parent node validation, endpoint proximity filtering, and fallback to direct lines when paths are invalid
  • Optimized agent lookup performance with O(1) hash map indexing and marriage candidate caching
  • Added binary table reader/writer infrastructure with typed columns for coordinates, dates, and sizes
  • Implemented hex color parsing (#RRGGBB format) for visual customization of map features

Reviewed changes

Copilot reviewed 31 out of 60 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Library/PAX_SAPIENTICA/Simulation/Algorithm/AStar.hpp Complete A* rewrite with priority queue, parent validation, endpoint filtering, and stick/loop prevention
Library/PAX_SAPIENTICA/Simulation/Entity/Settlement.hpp Agent indexing optimization, marriage cache, and A* integration improvements
Library/PAX_SAPIENTICA/IO/Data/BinaryTable.hpp New binary format reader with typed columns and optimized memory layout
Library/PAX_SAPIENTICA/IO/Data/UnifiedTable.hpp TSV/binary format abstraction layer with automatic format detection
Library/PAX_GRAPHICA/ColorUtility.hpp Hex color string parser (#RRGGBB/#RRGGBBAA support)
Library/PAX_MAHOROBA/Map/Content/Feature/TerritoryFeature.hpp Color parsing integration for territory rendering
Library/PAX_MAHOROBA/Map/Content/Feature/FlowCurveFeature.hpp Color parsing integration for flow curve rendering
Data/Settings/*.tsv Updated to use hex color strings instead of "black"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants