-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Avoid unnecessary dynamic_cast
s, LayerObject
base class, remove CollisionListener
#3110
Conversation
Unnecessary `dynamic_cast`s have been replaced with `static_cast`s, or the code requiring them has been improved. `LayerObject` is a base class for all `GameObject`s which are shown under the `EditorLayersWidget`. Used to prevent multiple casts every single frame for every single layer icon when determining z-pos.
Reverts changes done by commit fa82f91. The reason is that `CollisionListener` was not used as a base anywhere beside `MovingObject`, and made it so `CollisionObject::collide()`/`collision()` had to use `dynamic_cast` to side-cast the `other` object's listener to a `GameObject`. `CollisionObject` now contains the `MovingObject& m_parent` member, as opposed to `CollisionListener& m_listener`. Additionally, the now base `MovingObject::collision...` functions now accept `MovingObject&` in arguments, instead of `GameObject&`. This saves on a few other `dynamic_cast`s along the way.
I'm gonna test this in a few. |
This also fixes #701 |
|
I tested it, seems fine. I couldn't notice much of a benefit, only thing I might have noticed is bonus block hitting seems to be way less laggy (there used to be a slight lag before). |
Dynamic cast used in the collision code??????????????????? Good lord. This PR might bring about a substantial performance boost O_O Best it gets merge asap to prevent any future blockers in other PRs? |
src/editor/layer_object.hpp
Outdated
class LayerObject : public GameObject | ||
{ | ||
public: | ||
LayerObject(const std::string& name = ""); |
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.
std::move
me. Compiler probably wouldn't care anyway.
Nothing else to say, just decide on |
Unnecessary
dynamic_cast
s have been replaced withstatic_cast
s, or the code requiring them has been improved.Add
LayerObject
classLayerObject
is a base class for allGameObject
s which are shown under theEditorLayersWidget
. Used to prevent multiple casts every single frame for every single layer icon when determining z-pos.Closes #701.
Remove
CollisionListener
classThe changes done by commit fa82f91 have been reverted. The reason is that
CollisionListener
was not used as a base anywhere besideMovingObject
, and made it soCollisionObject::collide()
/collision()
had to usedynamic_cast
to side-cast theother
object's listener to aGameObject
.CollisionObject
now contains theMovingObject& m_parent
member, as opposed toCollisionListener& m_listener
.Additionally, the now base
MovingObject::collision...
functions now acceptMovingObject&
in arguments, instead ofGameObject&
. This saves on a few other casts along the way.