Commit 4346b19e authored by Pierre TESSIER's avatar Pierre TESSIER

fixed AI death bug

parent 032b9727
......@@ -54,6 +54,7 @@ void scene_model::createResources()
setupAimCursor();
buildAIHierarchyPool(m_resources);
m_resources.collisionGrid = CollisionGrid(gridResolution, gridResolution, &m_resources.terrainGeometry);
m_ecs.subscribeToEntityDestroyedEvent("removeFromCollisionGrid", [&grid = m_resources.collisionGrid](ecs::Entity entity) { grid.removeEntity(entity); });
m_resources.meshes["collision_box"] = mesh_primitive_cylinder(1.f, vec3{}, vec3{ 0.f, 0.f, 1.f });
setupCollisionRates();
}
......@@ -82,6 +83,8 @@ void scene_model::buildEntities(std::map<std::string,GLuint>& shaders)
vec3 AIPosition = m_resources.terrainGeometry.evaluate(0.4, 0.6) + vec3{ 0, 0, 5 };
builder.buildAICharacter(m_player, AIPosition, shaders);
AIPosition = m_resources.terrainGeometry.evaluate(0.2, 0.3) + vec3{ 0, 0, 5 };
builder.buildAICharacter(m_player, AIPosition, shaders);
m_aimCursor = m_ecs.createEntity();
m_ecs.add<TransformComponent>(m_aimCursor, vec3(0,0,2));
......
......@@ -87,6 +87,14 @@ void CollisionGrid::updateWith(CollisionComponent& collisionComponent)
}
}
void CollisionGrid::removeEntity(ecs::Entity entity)
{
for (auto cell = m_grid.begin(); cell != m_grid.end(); cell++)
{
cell->erase(entity);
}
}
std::size_t CollisionGrid::xIdxAt(float x) const
{
assert(m_terrain);
......@@ -116,4 +124,5 @@ std::size_t CollisionGrid::flattenIdx(std::size_t xIdx, std::size_t yIdx) const
std::pair<std::size_t, std::size_t> CollisionGrid::unflattenIdx(std::size_t idx) const
{
return { idx / m_ySize, idx % m_ySize };
}
\ No newline at end of file
}
......@@ -46,6 +46,8 @@ public:
std::size_t ySize() const { return m_ySize; }
AABB getBoundingBox(size_t const xIdx, size_t const y_Idx) const;
void removeEntity(ecs::Entity entity);
private:
std::size_t xIdxAt(float x) const;
std::size_t yIdxAt(float y) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment