#pragma once /* -*-c++-*- * dtEntity Game and Simulation Engine * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Martin Scheffler */ #include #include #include #include #include #include #include namespace dtEntityOSG { class DTENTITY_OSG_EXPORT LayerAttachPointComponent : public GroupComponent { typedef GroupComponent BaseClass; public: static const dtEntity::ComponentType TYPE; static const dtEntity::StringId NameId; LayerAttachPointComponent(); virtual ~LayerAttachPointComponent(); virtual void Finished(); void OnAddedToEntity(dtEntity::Entity& entity); void OnRemovedFromEntity(dtEntity::Entity& entity); /** * Set osg group node that will hold layer component nodes * as children. When this is set, all layer components are * traversed and their nodes are attached to this group node * if the layer name fits */ virtual void SetNode(osg::Group* node); /** * Get name SID identifying this layer attach point */ dtEntity::StringId GetName() const { return mName.Get(); } /** * Set name SID identifying this layer attach point. * When the name is changed all layer components are * traversed and their nodes are attached to this group node * if the layer name fits */ void SetName(dtEntity::StringId name); virtual dtEntity::ComponentType GetType() const { return TYPE; } private: dtEntity::EntityManager* mEntityManager; dtEntity::StringIdProperty mName; dtEntity::StringId mCurrentName; }; //////////////////////////////////////////////////////////////////////////////// class DTENTITY_OSG_EXPORT LayerAttachPointSystem : public dtEntity::DefaultEntitySystem , public dtEntity::ScriptAccessor { friend class LayerAttachPointComponent; typedef dtEntity::DefaultEntitySystem BaseClass; public: static const dtEntity::ComponentType TYPE; static const dtEntity::StringId DefaultLayerId; static const dtEntity::StringId RootId; LayerAttachPointSystem(dtEntity::EntityManager& em); virtual bool DeleteComponent(dtEntity::EntityId eid); bool GetByName(dtEntity::StringId name, LayerAttachPointComponent*& recipient); LayerAttachPointComponent* GetDefaultLayer(); LayerAttachPointComponent* GetRootLayer(); osg::Group* GetSceneGraphRoot() { return mSceneGraphRoot.get(); } void CreateSceneGraphRootEntity(osg::Group* root); dtEntity::Property* ScriptGetByName(const dtEntity::PropertyArgs& args); private: void RegisterByName(dtEntity::StringId, LayerAttachPointComponent*); typedef std::map LayerByNameMap; LayerByNameMap mLayerByNameMap; osg::ref_ptr mSceneGraphRoot; dtEntity::EntityId mBaseEntityId; }; }