Exemplo n.º 1
0
  void RendererSystemComponent::DestroySceneNode(Ogre::SceneNode* sceneNode)
  {
    Ogre::Node::ChildNodeIterator children = sceneNode->getChildIterator();

    while(children.hasMoreElements())
    {
      SceneNode* childSceneNode = static_cast<SceneNode*>(children.getNext());
      this->DestroySceneNode(childSceneNode);
    }

    SceneNode::ObjectIterator objects = sceneNode->getAttachedObjectIterator();

    while(objects.hasMoreElements())
    {
      MovableObject* object = objects.getNext();

      if(object->getMovableType() == EntityFactory::FACTORY_TYPE_NAME)
      {
        Entity* entity = m_scene->GetSceneManager()->getEntity(object->getName());
        
        Ogre::Entity::ChildObjectListIterator childObjects = entity->getAttachedObjectIterator();

        while(childObjects.hasMoreElements())
        {
          m_scene->GetSceneManager()->destroyMovableObject(childObjects.getNext());
        }
      }

      m_scene->GetSceneManager()->destroyMovableObject(object);
    }

    sceneNode->removeAndDestroyAllChildren();
  }
Exemplo n.º 2
0
	void SceneNode::detachObject( MovableObject & object )
	{
		auto it = std::find_if( m_objects.begin(), m_objects.end(), [&object]( std::reference_wrapper< MovableObject > obj )
		{
			return obj.get().getName() == object.getName();
		} );

		if ( it != m_objects.end() )
		{
			m_objects.erase( it );
			object.attachTo( nullptr );
		}
	}
Exemplo n.º 3
0
/** Destructor */
SubObject::~SubObject() {

	// Destroy all attached entities and scene nodes
	unsigned short count = node_->numAttachedObjects();
	for (unsigned short i = 0; i < count; i++) {
		MovableObject* obj = node_->getAttachedObject(0U);
		node_->detachObject((unsigned short)0);
		node_->getCreator()->destroyMovableObject(obj->getName(), obj->getMovableType());
	}
	node_->getParentSceneNode()->removeAndDestroyChild(node_->getName());

	// Remove from world if the subobject was separated off
	if (body_.get()) { 
		body_->setUserPointer(0);
		game_->getWorld()->removeCollisionObject(body_.get()); 
	}
}
Exemplo n.º 4
0
  void RendererSystemComponent::LinkSkeletons(Ogre::SceneNode* sceneNode, RendererSystemComponent::SkeletonList* skeletons)
  {
    SceneNode::ObjectIterator objects = sceneNode->getAttachedObjectIterator();

    while(objects.hasMoreElements())
    {
      MovableObject* object = objects.getNext();

      if(object->getMovableType() == EntityFactory::FACTORY_TYPE_NAME)
      {
        Entity* entity = m_scene->GetSceneManager()->getEntity(object->getName());

        if (entity->hasSkeleton())
        {
          Ogre::Skeleton::BoneIterator boneIterator = entity->getSkeleton()->getBoneIterator();

          while(boneIterator.hasMoreElements())
          {
            Ogre::Bone* oBone = boneIterator.getNext();
            oBone->setManuallyControlled(true);

            /*Entity *axis = m_scene->GetSceneManager()->createEntity(oBone->getName() + "_axis", "/data/entities/meshes/axes.mesh");
            TagPoint* tagPoint = entity->attachObjectToBone(oBone->getName(), axis);
            tagPoint->setScale(0.005f, 0.005f, 0.005f);*/
          }

          skeletons->push_back(entity->getSkeleton());
        }
      }
    }

    Node::ChildNodeIterator children = sceneNode->getChildIterator();

    while(children.hasMoreElements())
    {
      SceneNode* child = static_cast<SceneNode*>(children.getNext());
      this->LinkSkeletons(child, skeletons);
    }
  }
Exemplo n.º 5
0
Object::~Object() {

	// Notify projectiles that the object is toast
	clearAllTrackers();
	//cout << "Collecting " << name_ << endl;

	// Un-track
	if (target_) target_->removeTracker(this);

	// Clean up physics
	game_->getWorld()->removeCollisionObject(body_.get());

	// Destroy all subobjects
	subObjects_.clear();

	// Destroy objects attached to the scene node
	while (node_->numAttachedObjects() > 0) {
		MovableObject* obj = node_->getAttachedObject(0U);
		node_->detachObject((unsigned short)0U);
		node_->getCreator()->destroyMovableObject(obj->getName(), obj->getMovableType());
	}

	// Destroy all attached entities and scene nodes
	SceneNode::ChildNodeIterator i = node_->getChildIterator();
	while (i.hasMoreElements()) {
		SceneNode* node = static_cast<SceneNode*>(i.getNext());
		MovableObject* obj = node->getAttachedObject(0U);
		node->detachObject((unsigned short)0U);
		node->getCreator()->destroyMovableObject(obj->getName(), obj->getMovableType());
	}
	node_->removeAndDestroyAllChildren();
	node_->getParentSceneNode()->removeAndDestroyChild(node_->getName());

	// Clean up scripting
	lua_State* env = game_->getScriptState();
	StackCheck check(env);
	lua_getref(env, table_);
	
	lua_pushnil(env);
	lua_setfield(env, -2, "__thiscpp");

	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "addEntity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setEntity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "addParticleSystem");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setParticleSystem");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "set");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "explode");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "destroy");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "target");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setPosition");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getPosition");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setVelocity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getVelocity");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setOrientation");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getOrientation");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "createMissile");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "getTarget");
	lua_pushcclosure(env, &Object::luaWarningDestroyed, 0);
	lua_setfield(env, -2, "setTarget");
	lua_unref(env, table_);
}