浏览代码

Address code review feedback: improve modularity and add clarifying comments

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 周之前
父节点
当前提交
ea5dddd25a
共有 3 个文件被更改,包括 20 次插入14 次删除
  1. 1 13
      app/core/ambient_state_manager.h
  2. 14 0
      app/core/game_engine.h
  3. 5 1
      app/core/minimap_manager.cpp

+ 1 - 13
app/core/ambient_state_manager.h

@@ -6,19 +6,7 @@ namespace Engine::Core {
 class World;
 }
 
-struct EntityCache {
-  int player_troop_count = 0;
-  bool player_barracks_alive = false;
-  bool enemy_barracks_alive = false;
-  int enemy_barracks_count = 0;
-
-  void reset() {
-    player_troop_count = 0;
-    player_barracks_alive = false;
-    enemy_barracks_alive = false;
-    enemy_barracks_count = 0;
-  }
-};
+struct EntityCache;
 
 class AmbientStateManager {
 public:

+ 14 - 0
app/core/game_engine.h

@@ -83,6 +83,20 @@ class AudioSystemProxy;
 
 class QQuickWindow;
 
+struct EntityCache {
+  int player_troop_count = 0;
+  bool player_barracks_alive = false;
+  bool enemy_barracks_alive = false;
+  int enemy_barracks_count = 0;
+
+  void reset() {
+    player_troop_count = 0;
+    player_barracks_alive = false;
+    enemy_barracks_alive = false;
+    enemy_barracks_count = 0;
+  }
+};
+
 class GameEngine : public QObject {
   Q_OBJECT
 public:

+ 5 - 1
app/core/minimap_manager.cpp

@@ -84,6 +84,8 @@ void MinimapManager::update_fog(float dt, int local_owner_id) {
   const int img_width = m_minimap_image.width();
   const int img_height = m_minimap_image.height();
 
+  // Rotation constants for -45 degree isometric projection
+  // k_inv_cos = -cos(45°), k_inv_sin = sin(45°)
   constexpr float k_inv_cos = -0.70710678118F;
   constexpr float k_inv_sin = 0.70710678118F;
 
@@ -180,7 +182,9 @@ void MinimapManager::update_units(
   }
 
   std::vector<Game::Map::Minimap::UnitMarker> markers;
-  markers.reserve(128);
+  // Reserve space for typical unit count to avoid reallocations
+  constexpr size_t EXPECTED_MAX_UNITS = 128;
+  markers.reserve(EXPECTED_MAX_UNITS);
 
   std::unordered_set<Engine::Core::EntityID> selected_ids;
   if (selection_system) {