-
-
Notifications
You must be signed in to change notification settings - Fork 983
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
add SceneNode deletion convenience methods #2963
Conversation
adds the methods, destroyChildGraphSegment, destroyGraphSegment, destroyAllObjects.
is there a command to run the trailing whitespace check locally? I have been using |
|
OgreMain/src/OgreSceneNode.cpp
Outdated
@@ -194,6 +194,15 @@ namespace Ogre { | |||
needUpdate(); | |||
} | |||
//----------------------------------------------------------------------- | |||
void SceneNode::destroyAllObjects(void) | |||
{ | |||
while (getAttachedObjects().size() > 0) { |
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.
please use empty()
and front()
as below: https://github.com/OGRECave/ogre/pull/2963/files#diff-8b29158c3b96916d83c3b4bbc1c9ee083fee97bff80ae347e6401c6bc49dd5afR358
While GraphSegment technically makes perfect sense, it is not used anywhere else within ogre. Therefore I would rather keep to "Children" and "Objects" for now. |
OgreMain/include/OgreSceneNode.h
Outdated
* Does **not** destroy animations, textures, meshes associated with those movable objects | ||
* Does not destroy the node itself | ||
* */ | ||
void destroyGraphSegment(); |
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.
void destroyGraphSegment(); | |
void destroyAllChildrenAndObjects(); |
OgreMain/include/OgreSceneNode.h
Outdated
* | ||
* Does **not** destroy animation, textures, meshes associated with those movable objects | ||
* */ | ||
void destroyChildGraphSegment(const 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.
void destroyChildGraphSegment(const String& name); | |
void destroyChildAndObjects(const String& name); |
OgreMain/src/OgreSceneNode.cpp
Outdated
} | ||
|
||
void SceneNode::destroyChildGraphSegment(unsigned short index) { | ||
SceneNode* pChild = static_cast<SceneNode*>(getChildren()[index]); |
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.
SceneNode* pChild = static_cast<SceneNode*>(getChildren()[index]); | |
SceneNode* pChild = static_cast<SceneNode*>(removeChild(index)); |
otherwise pChild might be OOB. This is an issue in the original code as well
I believe I have made the changes you have requested |
This commit adds convenience method to delete a node and its attached objects, as I needed and people asked about here and here.
The use case is if you want to clear a
SceneNode
and put everything back from scratch (a simple if slower way of updating an object to reflect game state), or if you wish to stop rendering a node (and thus things attached to it can be garbage collected).This patch adds three new non-virtual methods to
SceneNode
that analogous to the other methods but also delete the detached objects:SceneNode::destroyGraphSegment
, analogous toSceneNode::removeAndDestroyAllChildren
, except it also destroys all MovableObjects attached tothis
and to any of the descendants. In other words, all children are destroyed and any objects attached to them and any objects attached tothis
.SceneNode::destroyChildGraphSegment
, analogous toSceneNode::removeAndDestroyChild
, except it also destroys the objects attached to the child.SceneNode::destroyAllObjects
, analogous toSceneNode::detatchAllObjects
, except it destroys the objects too. Unlike detatchAllObjects, this function is not virtual. I believe it is not required for it to be, since everything it does could be achieved using external methods. Moreover, I did not want to increase memory footprint of SceneNode. I called itdestroyAllObjects
rather thandetatchAndDestroyAllObjects
to keep the name short and because detatching is already considered part of destroying MovableObjects.The naming scheme of
GraphSegment
was chosen asremoveAndDestroyAllChildrenAndAttached
seemed too long.removeAndDestroy
in the original methods' names feel redundant to me, but best not changed as to not break the API.There are tests added to test the basic behaviour of the 3 added methods included in this pull request.
This code deletes MovableObjects only; I have never worked with skeletons or animations, so it may not delete those. I am not sure if deleting animations would even be desired behaviour, as animations might be more analogous to meshes than entities.
Please view the code with some skepticism, as I am unfamiliar with the Ogre code base and thus, it is greater risk that I broke expected behaviour or introduced undefined behaviour. And I am of course, happy to make any changes that are needed.