首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

WPF/Silverlight 遊戲開發教程(三十九之二):Silverlight 引擎 A* 優化與地圖切片最佳化

     編輯:關於C語言

3) A* 移動優化

預留介面,依參數啟動不同效率/路徑長度/精度的 A*。推薦兩方案:預設最精確但耗效能;另一最高效但路徑非最短:

PathFinderFast pathFinderFast = new PathFinderFast(varyObstruction)
{
    HeavyDiagonals = false,
    HeuristicEstimate = 100,
};

封裝的 A* DLL 基於第七節改編,可作調試器調試參數組合。模擬測試得 0.0071 秒,滿意則記錄配置:Diagonals=true, HeavyDiagonals=true, Heuristic=5, Formula=Max(DX,DY), TIEBreaker=false, SearchLimit=40000。Silverlight 引擎中啟動:

PathFinderFast pathFinderFast = new PathFinderFast(varyObstruction)
{
    Diagonals = true, HeavyDiagonals = true, HeuristicEstimate = 5,
    Formula = HeuristicFormula.MaxDXDY, TIEBreaker = false, SearchLimit = 40000,
};

二、主要優化

1) 地圖切片最優載入法

無需額外判斷、無需 Clear 容器,按 0-8 順序重新賦值 9 片 Source,效能極優:

private void ChangeMapSection()
{
    countSection = 0;
    for (int x = startSectionX; x <= endSectionX; x++)
        for (int y = startSectionY; y <= endSectionY; y++)
        {
            mapSection[countSection].Source = Super.GetImage(string.Format("/Image/Map/{0}/Surface/{1}_{2}.jpg", mapCode, x, y));
            Canvas.SetLeft(mapSection[countSection], x * mapSectionWidth);
            Canvas.SetTop(mapSection[countSection], y * mapSectionHeight);
            countSection++;
        }
}

A* 使用竟可如此簡單。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved