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) {
|
||||
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) };
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue