Compiler warnings, and don't dynamic_cast twice in Entity::GetComponent

This commit is contained in:
SeanOMik 2021-03-12 17:33:10 -06:00
parent 15421ff7e0
commit b9255b1bfb
No known key found for this signature in database
GPG Key ID: CA09E5BE1F32728A
2 changed files with 4 additions and 5 deletions

View File

@ -248,8 +248,7 @@ public:
}
void OnCollide(std::shared_ptr<Entity> entity) {
std::shared_ptr<SnakeFoodEntity> shared = dynamic_pointer_cast<SnakeFoodEntity>(entity);
if (shared) {
if (std::shared_ptr<SnakeFoodEntity> shared = std::dynamic_pointer_cast<SnakeFoodEntity>(entity); shared) {
shared->Relocate();
BodyPiece piece{ sf::RectangleShape(sf::Vector2f(15, 15)), sf::Vector2i(0, 0) };

View File

@ -40,7 +40,7 @@ namespace simpleengine {
template<typename T>
bool HasComponent() const {
for (std::shared_ptr<Component> comp : components) {
if (dynamic_cast<T*>(comp.get())) {
if (std::dynamic_pointer_cast<T>(comp)) {
return true;
}
}
@ -51,8 +51,8 @@ namespace simpleengine {
template<typename T>
std::shared_ptr<T> GetComponent() const {
for (std::shared_ptr<Component> comp : components) {
if (dynamic_cast<T*>(comp.get())) {
return dynamic_pointer_cast<T>(comp);
if (std::shared_ptr<T> dyn_comp = std::dynamic_pointer_cast<T>(comp); dyn_comp) {
return dyn_comp;
}
}