Browse Source

Fix compilation errors in render files - update to use spawnType enum

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 month ago
parent
commit
eaf20a06c9
2 changed files with 19 additions and 19 deletions
  1. 4 4
      render/humanoid_base.cpp
  2. 15 15
      render/scene_renderer.cpp

+ 4 - 4
render/humanoid_base.cpp

@@ -67,13 +67,13 @@ FormationParams HumanoidRendererBase::resolveFormation(const DrawContext &ctx) {
 
   if (ctx.entity) {
     auto *unit = ctx.entity->getComponent<Engine::Core::UnitComponent>();
-    if (unit && !unit->unitType.empty()) {
+    if (unit) {
       params.individualsPerUnit =
           Game::Units::TroopConfig::instance().getIndividualsPerUnit(
-              unit->unitType);
+              unit->spawnType);
       params.maxPerRow = Game::Units::TroopConfig::instance().getMaxUnitsPerRow(
-          unit->unitType);
-      if (unit->unitType == "mounted_knight") {
+          unit->spawnType);
+      if (unit->spawnType == Game::Units::SpawnType::MountedKnight) {
         params.spacing = 1.35f;
       }
     }

+ 15 - 15
render/scene_renderer.cpp

@@ -1,6 +1,7 @@
 #include "scene_renderer.h"
 #include "../game/map/terrain_service.h"
 #include "../game/map/visibility_service.h"
+#include "../game/units/spawn_type.h"
 #include "../game/units/troop_config.h"
 #include "entity/registry.h"
 #include "game/core/component.h"
@@ -246,11 +247,11 @@ void Renderer::enqueueSelectionRing(Engine::Core::Entity *,
   float ringOffset = 0.05f;
   float groundOffset = 0.0f;
 
-  if (unitComp && !unitComp->unitType.empty()) {
+  if (unitComp) {
     auto &config = Game::Units::TroopConfig::instance();
-    ringSize = config.getSelectionRingSize(unitComp->unitType);
-    ringOffset += config.getSelectionRingYOffset(unitComp->unitType);
-    groundOffset = config.getSelectionRingGroundOffset(unitComp->unitType);
+    ringSize = config.getSelectionRingSize(unitComp->spawnType);
+    ringOffset += config.getSelectionRingYOffset(unitComp->spawnType);
+    groundOffset = config.getSelectionRingGroundOffset(unitComp->spawnType);
   }
 
   QVector3D pos(transform->position.x, transform->position.y,
@@ -310,15 +311,13 @@ void Renderer::renderWorld(Engine::Core::World *world) {
     if (m_camera && unitComp) {
 
       float cullRadius = 3.0f;
-      if (!unitComp->unitType.empty()) {
-
-        if (unitComp->unitType.find("mounted") != std::string::npos) {
-          cullRadius = 4.0f;
-        } else if (unitComp->unitType == "spearman" ||
-                   unitComp->unitType == "archer" ||
-                   unitComp->unitType == "knight") {
-          cullRadius = 2.5f;
-        }
+      
+      if (unitComp->spawnType == Game::Units::SpawnType::MountedKnight) {
+        cullRadius = 4.0f;
+      } else if (unitComp->spawnType == Game::Units::SpawnType::Spearman ||
+                 unitComp->spawnType == Game::Units::SpawnType::Archer ||
+                 unitComp->spawnType == Game::Units::SpawnType::Knight) {
+        cullRadius = 2.5f;
       }
 
       QVector3D unitPos(transform->position.x, transform->position.y,
@@ -350,8 +349,9 @@ void Renderer::renderWorld(Engine::Core::World *world) {
                       transform->scale.z);
 
     bool drawnByRegistry = false;
-    if (unitComp && !unitComp->unitType.empty() && m_entityRegistry) {
-      auto fn = m_entityRegistry->get(unitComp->unitType);
+    if (unitComp && m_entityRegistry) {
+      std::string unitTypeStr = Game::Units::spawnTypeToString(unitComp->spawnType);
+      auto fn = m_entityRegistry->get(unitTypeStr);
       if (fn) {
         DrawContext ctx{resources(), entity, world, modelMatrix};