-
Notifications
You must be signed in to change notification settings - Fork 0
Update from task 8f5f5615-9e0f-40cb-8b38-ecc911acf640 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: farmengine-architecture-overview-9e516
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,10 @@ | |
|
|
||
| namespace farm { | ||
|
|
||
| // Alias for FarmEngine namespace to maintain backward compatibility | ||
| namespace EngineNS = FarmEngine; | ||
|
|
||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Broken namespace alias FarmEngine/core/Engine.h introduces namespace EngineNS = FarmEngine; inside namespace farm but FarmEngine is not declared at that point, so any translation unit that includes Engine.h first will fail to compile. FarmEngine/core/Engine.cpp includes core/Engine.h as its first include, making this failure immediate for the core target. Agent Prompt
|
||
|
|
||
| // Forward declarations | ||
| class Window; | ||
| class Renderer; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,8 +56,8 @@ class ECS { | |
| private: | ||
| std::vector<Entity> entities; | ||
| std::vector<EntityID> availableIDs; | ||
| std::unordered_map<std::type_index, std::vector<std::unique_ptr<Component>>> components; | ||
| std::unordered_map<std::type_index, EntityID> componentTypeToIndex; | ||
| std::vector<std::vector<std::unique_ptr<Component>>> components; | ||
| std::unordered_map<std::type_index, uint32_t> componentTypeToIndex; | ||
|
|
||
| uint32_t nextComponentIndex = 0; | ||
|
|
||
|
|
@@ -68,18 +68,18 @@ class ECS { | |
| // Template implementations | ||
| template<typename T, typename... Args> | ||
| T& ECS::addComponent(EntityID entity, Args&&... args) { | ||
| if (entity >= entities.size() || !entities[entity].active) { | ||
| throw std::out_of_range("Invalid or inactive entity ID"); | ||
| } | ||
|
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Missing stdexcept include ECS.h now throws std::out_of_range and std::overflow_error in header-defined templates, but does not include <stdexcept>, causing compilation errors when these templates are instantiated. This is directly introduced by the new validation/overflow checks. Agent Prompt
|
||
|
|
||
| auto index = getComponentTypeIndex<T>(); | ||
|
|
||
| if (index >= components.size()) { | ||
| components.resize(index + 1); | ||
| } | ||
|
|
||
| if (!components[index]) { | ||
| components[index] = std::vector<std::unique_ptr<Component>>(); | ||
| } | ||
|
|
||
| while (components[index]->size() <= entity) { | ||
| components[index]->push_back(nullptr); | ||
| while (components[index].size() <= entity) { | ||
| components[index].push_back(nullptr); | ||
| } | ||
|
|
||
| auto component = std::make_unique<T>(std::forward<Args>(args)...); | ||
|
|
@@ -94,13 +94,17 @@ T& ECS::addComponent(EntityID entity, Args&&... args) { | |
|
|
||
| template<typename T> | ||
| T* ECS::getComponent(EntityID entity) { | ||
| if (entity >= entities.size() || !entities[entity].active) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| auto index = getComponentTypeIndex<T>(); | ||
|
|
||
| if (index >= components.size() || !components[index]) { | ||
| if (index >= components.size()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| if (entity >= components[index]->size()) { | ||
| if (entity >= components[index].size()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
|
|
@@ -109,19 +113,33 @@ T* ECS::getComponent(EntityID entity) { | |
|
|
||
| template<typename T> | ||
| void ECS::removeComponent(EntityID entity) { | ||
| if (entity >= entities.size() || !entities[entity].active) { | ||
| return; | ||
| } | ||
|
|
||
| auto index = getComponentTypeIndex<T>(); | ||
|
|
||
| if (index < components.size() && components[index] && entity < components[index]->size()) { | ||
| if (index < components.size() && entity < components[index].size()) { | ||
| components[index][entity].reset(); | ||
| entities[entity].mask.reset(index); | ||
| } | ||
| } | ||
|
|
||
| template<typename T> | ||
| uint32_t ECS::getComponentTypeIndex() { | ||
| static uint32_t index = []() { | ||
| return nextComponentIndex++; | ||
| }(); | ||
| auto key = std::type_index(typeid(T)); | ||
|
|
||
| auto it = componentTypeToIndex.find(key); | ||
| if (it != componentTypeToIndex.end()) { | ||
| return it->second; | ||
| } | ||
|
|
||
| if (nextComponentIndex >= MAX_COMPONENTS) { | ||
| throw std::overflow_error("Maximum number of component types exceeded"); | ||
| } | ||
|
|
||
| uint32_t index = nextComponentIndex++; | ||
| componentTypeToIndex[key] = index; | ||
| return index; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Terrain ubo layout mismatch
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools