Compiler warnings, and don't dynamic_cast twice in Entity::GetComponent
This commit is contained in:
parent
15421ff7e0
commit
b9255b1bfb
|
@ -248,8 +248,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnCollide(std::shared_ptr<Entity> entity) {
|
void OnCollide(std::shared_ptr<Entity> entity) {
|
||||||
std::shared_ptr<SnakeFoodEntity> shared = dynamic_pointer_cast<SnakeFoodEntity>(entity);
|
if (std::shared_ptr<SnakeFoodEntity> shared = std::dynamic_pointer_cast<SnakeFoodEntity>(entity); shared) {
|
||||||
if (shared) {
|
|
||||||
shared->Relocate();
|
shared->Relocate();
|
||||||
|
|
||||||
BodyPiece piece{ sf::RectangleShape(sf::Vector2f(15, 15)), sf::Vector2i(0, 0) };
|
BodyPiece piece{ sf::RectangleShape(sf::Vector2f(15, 15)), sf::Vector2i(0, 0) };
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace simpleengine {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool HasComponent() const {
|
bool HasComponent() const {
|
||||||
for (std::shared_ptr<Component> comp : components) {
|
for (std::shared_ptr<Component> comp : components) {
|
||||||
if (dynamic_cast<T*>(comp.get())) {
|
if (std::dynamic_pointer_cast<T>(comp)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ namespace simpleengine {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::shared_ptr<T> GetComponent() const {
|
std::shared_ptr<T> GetComponent() const {
|
||||||
for (std::shared_ptr<Component> comp : components) {
|
for (std::shared_ptr<Component> comp : components) {
|
||||||
if (dynamic_cast<T*>(comp.get())) {
|
if (std::shared_ptr<T> dyn_comp = std::dynamic_pointer_cast<T>(comp); dyn_comp) {
|
||||||
return dynamic_pointer_cast<T>(comp);
|
return dyn_comp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue