[Orxonox-commit 528] r3077 - trunk/src/orxonox/objects/worldentities
landauf at orxonox.net
landauf at orxonox.net
Mon May 25 23:16:27 CEST 2009
Author: landauf
Date: 2009-05-25 23:16:27 +0200 (Mon, 25 May 2009)
New Revision: 3077
Added:
trunk/src/orxonox/objects/worldentities/Attacher.cc
trunk/src/orxonox/objects/worldentities/Attacher.h
Modified:
trunk/src/orxonox/objects/worldentities/CMakeLists.txt
trunk/src/orxonox/objects/worldentities/WorldEntity.cc
trunk/src/orxonox/objects/worldentities/WorldEntity.h
Log:
Added Attacher - a class which attaches itself to an object with a given name
Added: trunk/src/orxonox/objects/worldentities/Attacher.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/Attacher.cc (rev 0)
+++ trunk/src/orxonox/objects/worldentities/Attacher.cc 2009-05-25 21:16:27 UTC (rev 3077)
@@ -0,0 +1,121 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "Attacher.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+ CreateFactory(Attacher);
+
+ Attacher::Attacher(BaseObject* creator) : StaticEntity(creator)
+ {
+ RegisterObject(Attacher);
+
+ this->target_ = 0;
+ }
+
+ void Attacher::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(Attacher, XMLPort, xmlelement, mode);
+
+ XMLPortParam(Attacher, "target", setTarget, getTarget, xmlelement, mode);
+ XMLPortObject(Attacher, WorldEntity, "", addObject, getObject, xmlelement, mode);
+ }
+
+ void Attacher::processEvent(Event& event)
+ {
+ for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
+ (*it)->fireEvent(event);
+ }
+
+ void Attacher::changedActivity()
+ {
+ SUPER(Attacher, changedActivity);
+
+ for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
+ (*it)->setActive(this->isActive());
+ }
+
+ void Attacher::changedVisibility()
+ {
+ SUPER(Attacher, changedVisibility);
+
+ for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
+ (*it)->setVisible(this->isVisible());
+ }
+
+ void Attacher::addObject(WorldEntity* object)
+ {
+ this->objects_.push_back(object);
+
+ this->attach(object);
+ }
+
+ WorldEntity* Attacher::getObject(unsigned int index) const
+ {
+ unsigned int i = 0;
+ for (std::list<WorldEntity*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
+ {
+ if (i == index)
+ return (*it);
+
+ ++i;
+ }
+ return 0;
+ }
+
+ void Attacher::setTarget(const std::string& target)
+ {
+ this->targetname_ = target;
+ this->target_ = 0;
+
+ if (this->targetname_ == "")
+ return;
+
+ for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it)
+ if (it->getName() == this->targetname_)
+ this->attachToParent(*it);
+ }
+
+ void Attacher::loadedNewXMLName(BaseObject* object)
+ {
+ if (this->target_ || this->targetname_ == "")
+ return;
+
+ WorldEntity* entity = dynamic_cast<WorldEntity*>(object);
+ if (entity && entity->getName() == this->targetname_)
+ {
+ this->target_ = entity;
+ this->attachToParent(entity);
+ }
+ }
+}
Added: trunk/src/orxonox/objects/worldentities/Attacher.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/Attacher.h (rev 0)
+++ trunk/src/orxonox/objects/worldentities/Attacher.h 2009-05-25 21:16:27 UTC (rev 3077)
@@ -0,0 +1,69 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _Attacher_H__
+#define _Attacher_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <list>
+
+#include "objects/worldentities/StaticEntity.h"
+#include "core/XMLNameListener.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport Attacher : public StaticEntity, public XMLNameListener
+ {
+ public:
+ Attacher(BaseObject* creator);
+ virtual ~Attacher() {}
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+ virtual void processEvent(Event& event);
+ virtual void changedActivity();
+ virtual void changedVisibility();
+
+ void addObject(WorldEntity* object);
+ WorldEntity* getObject(unsigned int index) const;
+
+ void setTarget(const std::string& target);
+ inline const std::string& getTarget() const
+ { return this->targetname_; }
+
+ void loadedNewXMLName(BaseObject* object);
+
+ private:
+ WorldEntity* target_;
+ std::string targetname_;
+ std::list<WorldEntity*> objects_;
+ };
+}
+
+#endif /* _Attacher_H__ */
Modified: trunk/src/orxonox/objects/worldentities/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/objects/worldentities/CMakeLists.txt 2009-05-25 20:25:28 UTC (rev 3076)
+++ trunk/src/orxonox/objects/worldentities/CMakeLists.txt 2009-05-25 21:16:27 UTC (rev 3077)
@@ -5,6 +5,7 @@
MobileEntity.cc
ControllableEntity.cc
+ Attacher.cc
Backlight.cc
Billboard.cc
BlinkingBillboard.cc
Modified: trunk/src/orxonox/objects/worldentities/WorldEntity.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/WorldEntity.cc 2009-05-25 20:25:28 UTC (rev 3076)
+++ trunk/src/orxonox/objects/worldentities/WorldEntity.cc 2009-05-25 21:16:27 UTC (rev 3077)
@@ -68,6 +68,7 @@
this->parent_ = 0;
this->parentID_ = OBJECTID_UNKNOWN;
+ this->bDeleteWithParent_ = true;
this->node_->setPosition(Vector3::ZERO);
this->node_->setOrientation(Quaternion::IDENTITY);
@@ -107,7 +108,16 @@
this->detachFromParent();
for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); )
- delete (*(it++));
+ {
+ if ((*it)->getDeleteWithParent())
+ delete (*(it++));
+ else
+ {
+ this->detach(*it);
+ (*it)->setPosition(this->getWorldPosition());
+ ++it;
+ }
+ }
if (this->physicalBody_)
{
@@ -137,6 +147,7 @@
XMLPortParamLoadOnly(WorldEntity, "yaw", yaw_xmlport, xmlelement, mode);
XMLPortParamLoadOnly(WorldEntity, "pitch", pitch_xmlport, xmlelement, mode);
XMLPortParamLoadOnly(WorldEntity, "roll", roll_xmlport, xmlelement, mode);
+ XMLPortParam (WorldEntity, "deletewithparent", setDeleteWithParent, getDeleteWithParent, xmlelement, mode);
// Physics
XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode);
Modified: trunk/src/orxonox/objects/worldentities/WorldEntity.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/WorldEntity.h 2009-05-25 20:25:28 UTC (rev 3076)
+++ trunk/src/orxonox/objects/worldentities/WorldEntity.h 2009-05-25 21:16:27 UTC (rev 3077)
@@ -172,6 +172,11 @@
void attachToNode(Ogre::SceneNode* node);
void detachFromNode(Ogre::SceneNode* node);
+ inline void setDeleteWithParent(bool value)
+ { this->bDeleteWithParent_ = value; }
+ inline bool getDeleteWithParent() const
+ { return this->bDeleteWithParent_; }
+
void notifyChildPropsChanged();
protected:
@@ -199,6 +204,7 @@
WorldEntity* parent_;
unsigned int parentID_;
std::set<WorldEntity*> children_;
+ bool bDeleteWithParent_;
/////////////
More information about the Orxonox-commit
mailing list