示例#1
0
Ogre::ResourcePtr ResourceManager::loadResource( const ResourceInfo& rResource, 
    const ResourceCallback& rCallbackSlot )
{
    Ogre::ResourcePtr resource = ResourceManager::getResource( rResource, true );

    if( !resource.isNull() && resource->isLoaded() )
    {
        CLOGD << "Resource " << rResource << " already loaded.";

        // If the resource is already loaded, callback immediately.
        rCallbackSlot( resource );
    }
    else if( !resource.isNull() && mHandleTickets.count( std::make_pair( 
        resource->getCreator()->getResourceType(), resource->getHandle() ) ) )
    {
        // If the resource is loading, add a callback.
        HandleTickets::iterator i = mHandleTickets.find(  std::make_pair( 
            resource->getCreator()->getResourceType(), resource->getHandle() ) );

        if( i != mHandleTickets.end() )
        {
            mTicketCallbacks.insert( TicketCallbacks::value_type( i->second, rCallbackSlot ) );

            CLOGD << "Resource " << rResource << " is loading, ticket callback: " << i->second;
        }
        else
        {
            DIVERSIA_EXCEPT( Exception::ERR_INTERNAL_ERROR, 
                "Could not find ticket for resource that is loading in the background.", 
	            "ResourceManager::loadResource" );
        }
    }
    else if( !resource.isNull() )
    {
        // Load the resource in the background and register the callback.
        resource = ResourceManager::getResource( rResource, true );
        Ogre::BackgroundProcessTicket ticket = 
            mRBQ.load( ResourceManager::getResourceManagerName( rResource.mType ), 
            rResource.mFile.string(), mGroup, false, 0, 0, this );
        mTicketCallbacks.insert( TicketCallbacks::value_type( ticket, rCallbackSlot ) );
        mHandleTickets.insert( std::make_pair( std::make_pair( 
            resource->getCreator()->getResourceType(), resource->getHandle() ), ticket ) );
        mTicketResources.insert( std::make_pair( ticket, resource ) );

        CLOGD << "Resource " << rResource << " will be loaded, ticket: " << ticket;
    }
    else
    {
        DIVERSIA_EXCEPT( Exception::ERR_FILE_NOT_FOUND, "Cannot load resource " + 
            rResource.mFile.string() + ", file does not exist.", 
	        "ResourceManager::loadResource" );
    }

    return resource;
}
示例#2
0
void UnloadResource(Ogre::ResourceManager* resMgr, const std::string& resourceName)
{
    Ogre::ResourcePtr rPtr = resMgr->getResourceByName(resourceName);
    if (rPtr.isNull())
    {
        StringUtil::StrStreamType msg;
        msg << "Resource no longer exists: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
        return;
    }
 
    rPtr->unload();
    if (rPtr->isLoaded())
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was not unloaded: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
    else
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was unloaded: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
 
    resMgr->remove(resourceName);
    rPtr = resMgr->getResourceByName(resourceName);
    if (rPtr.isNull())
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was removed: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
    else
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was not removed: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
 
    if (resMgr->resourceExists(resourceName))
    {
        StringUtil::StrStreamType msg;
        msg << "Resource still exists: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
    else
    {
        StringUtil::StrStreamType msg;
        msg << "Resource no longer exists: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
}
示例#3
0
void GUIManager::runCommand(const std::string &command, const std::string &args)
{
	if (command == ToggleInputMode.getCommand()) {
		getInput().toggleInputMode();
	} else if (command == ToggleGui.getCommand()) {

		S_LOG_VERBOSE("Toggle Gui Initiated -- " << getInput().getInputMode());

		if (mEnabled) {
			S_LOG_INFO("Disabling GUI");
			mEnabled = false;

			getInput().removeAdapter(mCEGUIAdapter);

		} else {
			S_LOG_INFO("Enabling GUI");
			mEnabled = true;

			getInput().addAdapter(mCEGUIAdapter);
		}
	} else if (command == ReloadGui.getCommand()) {
		Ogre::TextureManager* texMgr = Ogre::TextureManager::getSingletonPtr();
		Ogre::ResourcePtr resource = texMgr->getByName("cegui/" + getDefaultScheme() + ".png");
		if (!resource.isNull()) {
			resource->reload();
		}
	}
}
示例#4
0
Ogre::ResourcePtr
loadCorrelativeResource(const Ogre::String& resourceName, const Ogre::String& groupName,
                        const Ogre::String& baseResourceName, const Ogre::String& baseGroupName,
                        Ogre::ResourceManager& resourceManager)
{
    Ogre::ResourcePtr res;

   Ogre::String name, path;
    Ogre::StringUtil::splitFilename(resourceName, name, path);
    bool existsPath = !path.empty();

    // First, load in correlatived group and path if resource name doesn't exists path
    if (!existsPath)
    {
        Ogre::StringUtil::splitFilename(baseResourceName, name, path);
        if (!path.empty())
        {
            name = path + resourceName;
            res = tryLoadResource(resourceManager, name, baseGroupName);
            if (!res.isNull())
                return res;
        }
    }

    // Second, load in correlatived group
    res = tryLoadResource(resourceManager, resourceName, baseGroupName);
    if (!res.isNull())
        return res;

    // Three, load in user given group
    if (!groupName.empty())
    {
        res = tryLoadResource(resourceManager, resourceName, groupName);
        if (!res.isNull())
            return res;
    }

    // Four, load in global default group
    if (groupName != DEFAULT_RESOURCE_GROUP_NAME)
    {
        res = tryLoadResource(resourceManager, resourceName, groupName);
        if (!res.isNull())
            return res;
    }

    return res;
}
示例#5
0
void ManualBulletShapeLoader::load(const std::string &name,const std::string &group)
{
    // Check if the resource already exists
    Ogre::ResourcePtr ptr = BulletShapeManager::getSingleton().getByName(name, group);
    if (!ptr.isNull())
        return;
    BulletShapeManager::getSingleton().create(name,group,true,this);
}
示例#6
0
void ResourceManager::unloadResource(Ogre::ResourceManager* resMgr, const std::string& resourceName)
{
    Ogre::ResourcePtr rPtr = resMgr->getByName(resourceName);
    if (rPtr.isNull()) return

    rPtr->unload();
    if (rPtr->isLoaded())
        LOG_META(FORMAT("The resource '%1%' wasn`t unloaded!", resourceName));
    else
        LOG_META(FORMAT("The resource '%1%' was unloaded!", resourceName));

    resMgr->remove(resourceName);
    rPtr = resMgr->getByName(resourceName);
    if (!rPtr.isNull())
        LOG_META(FORMAT("The resource '%1%' wasn`t removed!", resourceName));
    else
        LOG_META(FORMAT("The resource '%1%' was removed!", resourceName));
}
示例#7
0
Ogre::ResourcePtr EntityRecipeManager::create(const Ogre::String& name, const Ogre::String& group, bool isManual, Ogre::ManualResourceLoader* loader, const Ogre::NameValuePairList* createParams)
{
	Ogre::ResourcePtr ret = getByName(name);
	if (ret.isNull()) {
		return Ogre::ResourceManager::create(name, group, isManual, loader, createParams);
	}
	S_LOG_WARNING("EntityRecipe with name " << name << " already exists.");
	return Ogre::ResourcePtr();
}
示例#8
0
Icon* IconManager::getIcon(int, EmberEntity* entity)
{

	std::string key = "entity_" + entity->getId();
	if (mIconStore.hasIcon(key)) {
		return mIconStore.getIcon(key);
	} else {
		IconActionCreator actionCreator(*entity);
		std::unique_ptr<EntityMapping::EntityMapping> modelMapping(Mapping::EmberEntityMappingManager::getSingleton().getManager().createMapping(*entity, actionCreator, &EmberOgre::getSingleton().getWorld()->getView()));
		std::string modelName;
		if (modelMapping.get()) {
			modelMapping->initialize();
			modelName = actionCreator.getModelName();
		}
		//if there's no model defined for this use the placeholder model
		if (modelName == "") {
			modelName = "placeholder";
		}
		Ogre::ResourcePtr modelDefPtr = Model::ModelDefinitionManager::getSingleton().getByName(modelName);
		if (!modelDefPtr.isNull()) {
			Model::ModelDefinition* modelDef = static_cast<Model::ModelDefinition*> (modelDefPtr.get());
			const std::string& iconPath(modelDef->getIconPath());
			if (iconPath != "") {

				Ogre::TexturePtr texPtr;
				try {
					if (Ogre::TextureManager::getSingleton().resourceExists(iconPath)) {
						texPtr = static_cast<Ogre::TexturePtr> (Ogre::TextureManager::getSingleton().getByName(iconPath));
						//try to load it to make sure that's it a working image
						texPtr->load();
					}
					if (texPtr.isNull()) {
						texPtr = Ogre::TextureManager::getSingleton().load(iconPath, "Gui");
					}
				} catch (...) {
					S_LOG_WARNING("Error when trying to load the icon " << iconPath <<". The icon will be rendered dynamically.");
					texPtr.setNull();
				}
				if (!texPtr.isNull()) {
					Icon* icon = mIconStore.createIcon(key, texPtr);
					return icon;
				}
			}
		}
		Icon* icon = mIconStore.createIcon(key);
		if (icon) {
			//update the model preview window
			// 				Model::Model* model = Model::Model::createModel(mIconRenderer.getRenderContext()->getSceneManager(), modelName);
			render(*icon, modelName);
			// 				mIconRenderer.getRenderContext()->getSceneManager()->destroyMovableObject(model);
		}
		return icon;
	}

	return 0;
}
示例#9
0
void ResourceManager::reloadResource(Ogre::ResourceManager* resMgr, const std::string& resourceName, const std::string& resourceGroup)
{
    Ogre::ResourcePtr rPtr = resMgr->load(resourceName, resourceGroup);
    if (rPtr.isNull()) LOG_META(FORMAT("The resource '%1%' no longer exists!", resourceName));

    rPtr->reload();
    if (rPtr->isLoaded())
        LOG_META(FORMAT("The resource '%1%' wasn`t unloaded!", resourceName));
    else
        LOG_META(FORMAT("The resource '%1%' was unloaded!", resourceName));
}
示例#10
0
void ResourceManager::loadResources( const ResourceList& rResources, 
    const SimpleResourceCallback& rCallbackSlot )
{
    // Convert to set to remove duplicates.
    ResourceSet resources = ResourceInfo::toResourceSet( rResources );

    if( resources.empty() )
    {
        // If there are no resources to be loaded, call the slot and return immediately.
        rCallbackSlot();
        return;
    }

    ResourceManager::ResourcesLoader* resourceLoader = 
        ResourceManager::ResourcesLoader::create( rCallbackSlot );

    unsigned short loaded = 0;
    for( ResourceSet::const_iterator i = resources.begin(); i != resources.end(); ++i )
    {
        // Add resources to resource loader.
        Ogre::ResourcePtr resource = ResourceManager::getResource( *i, true );

        if( resource.isNull() )
        {
            DIVERSIA_EXCEPT( Exception::ERR_FILE_NOT_FOUND, "Cannot load resource " + 
                (*i).mFile.string() + ", file does not exist.", 
                "ResourceManager::loadResource" );
        }

        if( resource->isLoaded() )
            loaded++;
        else
            resourceLoader->addResource( resource );
    }

    // All resources are already loaded.
    if( loaded == resources.size() )
    {
        rCallbackSlot();
        delete resourceLoader;
        return;
    }

    for( ResourceSet::const_iterator j = resources.begin(); j != resources.end(); ++j )
    {
        // Load all resources and callback to the resource loader. If all resources are loaded
        // the rCallbackSlot will be called and the resource loader will be destroyed.
        ResourceManager::loadResource( *j, sigc::mem_fun( resourceLoader, 
            &ResourceManager::ResourcesLoader::loadingComplete ) );
    }
}
Ogre::ResourcePtr ModelDefinitionManager::create(const Ogre::String& name, const Ogre::String& group,
bool isManual, Ogre::ManualResourceLoader* loader,
const Ogre::NameValuePairList* createParams)
{
	Ogre::ResourcePtr ret = getByName(name);
	if (ret.isNull())
	{
		return Ogre::ResourceManager::create(name, group, isManual, loader, createParams);
	}
	//Report this. We count on this happening a lot (user media overriding shared media for example), so we will not consider it a failure.
	S_LOG_INFO("ModelDefinition with name " << name << " already exists.");
	return Ogre::ResourcePtr();

}
    void run()
    {
        Meru::ResourceLoadingQueue *queue = &ResourceLoadingQueue::getSingleton();

        Ogre::ResourcePtr skeletonPtr = Ogre::SkeletonManager::getSingleton().getByName(mName);
        if (skeletonPtr.isNull() || !skeletonPtr->isLoaded()) {
            SILOG(resource,insane, "Skeleton Load Task run(), waiting for " << mName << " To queue");
            SILOG(resource,debug,"Queueing " << mName << " for OGRE load ");
            queue->load(Ogre::SkeletonManager::getSingleton().getResourceType(), mName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false, NULL, NULL, this);
        }
        else {
            SILOG(resource,insane, "Skeleton Load Task run() AND complete, waited for " << mName << " To queue");
            signalCompletion();
        }
    }
/*
bool MeshUnloadTask::mainThreadUnload(String name)
{
  Ogre::MeshManager::getSingleton().unload(name);
//  operationCompleted(Ogre::BackgroundProcessTicket(), Ogre::BackgroundProcessResult());
  return false;
}
*/
void MeshUnloadTask::doRun()
{
  /*I REALLY wish this were true*/
  // SequentialWorkQueue::getSingleton().queueWork(std::tr1::bind(&MeshUnloadTask::mainThreadUnload, this, mHash));

  String hash = mHash; //CDNArchive::canonicalMhashName(mHash);
  Ogre::MeshManager* meshManager = Ogre::MeshManager::getSingletonPtr();
  meshManager->remove(hash);

  Ogre::ResourcePtr meshResource = meshManager->getByName(hash);
  assert(meshResource.isNull());

  SharedResourcePtr resource = mResource.lock();
  if (resource)
    resource->unloaded(true, mEpoch);
}
示例#14
0
Ogre::ResourcePtr ResourceManager::getResource( const ResourceInfo& rResource, 
    bool create /*= false*/ ) const
{
    Ogre::ResourcePtr resource = mRGM._getResourceManager( 
        ResourceManager::getResourceManagerName( rResource.mType ) )->getByName( 
        rResource.mFile.string(), mGroup );
    if( !create ) return resource;

    if( resource.isNull() )
    {
        if( !mRGM.findResourceNames( mGroup, rResource.mFile.string() )->size() )
            return resource;

        resource = mRGM._getResourceManager( ResourceManager::getResourceManagerName( 
            rResource.mType ) )->create( rResource.mFile.string(), mGroup );
    }

    return resource;
}
示例#15
0
    Ogre::MaterialPtr
    IntersectGrid::_createIntersectGridMaterial(void)
    {
        String name = "IntersectGridMaterial";

        Ogre::ResourcePtr res = Ogre::MaterialManager::getSingleton().getByName(name);
        if (!res.isNull())
            return res;

        Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
       
        material->setLightingEnabled(false);
        material->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
        material->setDepthWriteEnabled(false);
        // Use wireframe polygon mode
        material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME);

        return material;
    }
示例#16
0
文件: SoundTrack.cpp 项目: angulo/ogf
SoundTrackPtr::SoundTrackPtr(const Ogre::ResourcePtr &resourcePtr)
{
	Log *errorLog = OGF::LogFactory::getSingletonPtr()->get(OGF::LOG_ERR);

	if (resourcePtr.isNull()) {
		return;
	}

	OGRE_LOCK_MUTEX(*resourcePtr.OGRE_AUTO_MUTEX_NAME)
	OGRE_COPY_AUTO_SHARED_MUTEX(resourcePtr.OGRE_AUTO_MUTEX_NAME)

	pRep = static_cast<SoundTrack *>(resourcePtr.getPointer());
	pUseCount = resourcePtr.useCountPointer();
	useFreeMethod = resourcePtr.freeMethod();

	// Incremento del contador de referencias.
	if (pUseCount)
		++(*pUseCount);
}
示例#17
0
Ogre::ResourcePtr SkeletonDebug::GetAxesMesh()
{
    Ogre::ResourcePtr axesMeshPtr =
        Ogre::MeshManager::getSingleton().getByName(axesMeshName);

    if (axesMeshPtr.isNull())
    {
        Ogre::ManualObject mo("tmp");
        mo.begin(GetAxesMaterial()->getName());
        /* 3 axes, each made up of 2 of these (base plane = XY)
        *   .------------|\
        *   '------------|/
        */
        mo.estimateVertexCount(7 * 2 * 3);
        mo.estimateIndexCount(3 * 2 * 3);
        Ogre::Quaternion quat[6];
        Ogre::ColourValue col[3];

        // x-axis
        quat[0] = Ogre::Quaternion::IDENTITY;
        quat[1].FromAxes(Ogre::Vector3::UNIT_X, Ogre::Vector3::NEGATIVE_UNIT_Z, Ogre::Vector3::UNIT_Y);
        col[0] = Ogre::ColourValue::Red;
        col[0].a = 0.3f;
        // y-axis
        quat[2].FromAxes(Ogre::Vector3::UNIT_Y, Ogre::Vector3::NEGATIVE_UNIT_X, Ogre::Vector3::UNIT_Z);
        quat[3].FromAxes(Ogre::Vector3::UNIT_Y, Ogre::Vector3::UNIT_Z, Ogre::Vector3::UNIT_X);
        col[1] = Ogre::ColourValue::Green;
        col[1].a = 0.3f;
        // z-axis
        quat[4].FromAxes(Ogre::Vector3::UNIT_Z, Ogre::Vector3::UNIT_Y, Ogre::Vector3::NEGATIVE_UNIT_X);
        quat[5].FromAxes(Ogre::Vector3::UNIT_Z, Ogre::Vector3::UNIT_X, Ogre::Vector3::UNIT_Y);
        col[2] = Ogre::ColourValue::Blue;
        col[2].a = 0.3f;

        Ogre::Vector3 basepos[7] =
        {
            // stalk
            Ogre::Vector3(0.0f, 0.05f, 0.0f),
            Ogre::Vector3(0.0f, -0.05f, 0.0f),
            Ogre::Vector3(0.7f, -0.05f, 0.0f),
            Ogre::Vector3(0.7f, 0.05f, 0.0f),
            // head
            Ogre::Vector3(0.7f, -0.15f, 0.0f),
            Ogre::Vector3(1.0f, 0.0f, 0.0f),
            Ogre::Vector3(0.7f, 0.15f, 0.0f)
        };

        // vertices
        // 6 arrows
        for (size_t i = 0; i < 6; ++i)
        {
            // 7 points
            for (size_t p = 0; p < 7; ++p)
            {
                Ogre::Vector3 pos = quat[i] * basepos[p];
                mo.position(pos);
                mo.colour(col[i / 2]);
            }
        }

        // indices
        // 6 arrows
        for (size_t i = 0; i < 6; ++i)
        {
            int base = static_cast<int>(i) * 7;
            mo.triangle(base + 0, base + 1, base + 2);
            mo.triangle(base + 0, base + 2, base + 3);
            mo.triangle(base + 4, base + 5, base + 6);
        }

        mo.end();

        axesMeshPtr = mo.convertToMesh(
            axesMeshName, Ogre::ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
    }

    return axesMeshPtr;
}
	void run(){
            boost::unique_lock<boost::mutex> lock(OgreFramework::getSingletonPtr()->mutex);
            	OgreFramework::getSingletonPtr()->m_pLog->logMessage("Start main loop...");
                //float fps_limit = 70.0;
                double timeSinceLastFrame = 0;
                double startTime = 0;
                
              OgreFramework::getSingletonPtr()->m_pRenderWnd->resetStatistics();
              lock.unlock();
                while(!m_bShutdown && !OgreFramework::getSingletonPtr()->isOgreToBeShutDown()) 
                {
                    boost::unique_lock<boost::mutex> lock(OgreFramework::getSingletonPtr()->mutex);
                        if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isClosed())m_bShutdown = true;

                        Ogre::WindowEventUtilities::messagePump();

                        if(OgreFramework::getSingletonPtr()->m_pRenderWnd->isActive())
                        {
                                startTime = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU();

                                OgreFramework::getSingletonPtr()->m_pKeyboard->capture();
                                OgreFramework::getSingletonPtr()->m_pMouse->capture();
                                
                                
                                OgreFramework::getSingletonPtr()->updateCaption();
                                //update mouse selection to shaders
                                Ogre::ResourcePtr r = Ogre::MaterialManager::getSingletonPtr()->getByName("MultiTextureEditor");
                                if(!r.isNull()){
                                    float mx=OgreFramework::getSingletonPtr()->cursor_x+OgreFramework::getSingletonPtr()->m_pCamera->getPosition().x;
                                    float my=OgreFramework::getSingletonPtr()->cursor_y+OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z;
                                    //float my=OgreFramework::getSingletonPtr()->cursor_y+sqrt(OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z);
                                    /*//std::cout<<((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->getSharedParameters().size()<<"\n";//->setNamedConstant("pointer", Ogre::Vector3(OgreFramework::getSingletonPtr()->cursor_x,OgreFramework::getSingletonPtr()->cursor_y,OgreFramework::getSingletonPtr()->cursor_r));
                                    float mx=(OgreFramework::getSingletonPtr()->cursor_x-OgreFramework::getSingletonPtr()->cursror_e_w/2.0)/OgreFramework::getSingletonPtr()->cursror_e_w;
                                    float my=(-OgreFramework::getSingletonPtr()->cursor_y+OgreFramework::getSingletonPtr()->cursror_e_h/2.0)/OgreFramework::getSingletonPtr()->cursror_e_h;
                                    Ogre::Ray ray=OgreFramework::getSingletonPtr()->m_pCamera->getCameraToViewportRay(mx,my);
                                    Ogre::Vector3 cam = OgreFramework::getSingletonPtr()->m_pCamera->getDirection();
                                    float factor = ray.getDirection().dotProduct(cam) / (cam.length() * ray.getDirection().length());
                                    Ogre::Vector3 point = ray.getPoint(OgreFramework::getSingletonPtr()->m_pCamera->getPosition().y*factor);
                                    */
                                    switch(OgreFramework::getSingletonPtr()->mode){
                                        case 0:
                                                ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(mx,my,OgreFramework::getSingletonPtr()->cursor_r,OgreFramework::getSingletonPtr()->cursor_rb));
                                                break;
                                        case 1:
                                            ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(mx,my,OgreFramework::getSingletonPtr()->cursor_r,0));
                                            break;
                                        case 2:
                                            ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(mx,my,2,0));
                                            break;
                                        default:
                                            ((Ogre::Material*)r.get())->getTechnique(0)->getPass(0)->getVertexProgramParameters()->setNamedConstant("pointer", Ogre::Vector4(-20,-20,0,0));
                                    }
                                        
                                }
                                else{
                                    //TODO error!
                                }
                                
                                OgreFramework::getSingletonPtr()->updateOgre(timeSinceLastFrame);
                                OgreFramework::getSingletonPtr()->m_pRoot->renderOneFrame();
                                
                                   /* while(OgreFramework::getSingletonPtr()->chunksToAdd.size()>0){//adding chunks
                                        ChunkAdding* ch = OgreFramework::getSingletonPtr()->chunksToAdd.front();
                                        OgreFramework::getSingletonPtr()->chunksToAdd.pop();
                                        Ogre::ManualObject* ogreMesh =  OgreFramework::getSingletonPtr()->m_pSceneMgr->createManualObject(std::string("Chunk")+(char)ch->x+(char)ch->y+(char)ch->z);
                                        ogreMesh->setDynamic(true);
                                        ogreMesh->setCastShadows(true);
                                        ogreMesh->begin("MultiTexture", Ogre::RenderOperation::OT_TRIANGLE_LIST);
                                        {
                                            for(int i=0;i<ch->size;++i){
                                                ogreMesh->position(ch->pos[i]);
                                                ogreMesh->normal(ch->normal[i]);
                                                ogreMesh->colour(ch->color[i]);
                                            }
                                        }
                                        ogreMesh->end();

                                        Ogre::SceneNode* ogreNode =  OgreFramework::getSingletonPtr()->m_pSceneMgr->getRootSceneNode()->createChildSceneNode(std::string("NChunk")+(char)ch->x+(char)ch->y+(char)ch->z, Ogre::Vector3(0, 0, 0));
                                        ogreNode->setVisible(true);
                                        ogreNode->attachObject(ogreMesh);
                                        ogreNode->setPosition(ch->x*CHUNK_SIZE,ch->z*(CHUNK_SIZE),ch->y*CHUNK_SIZE);
                                        delete ch;
                                    }*/
                                //update chunks
                                /*Pos* pos=NULL;
                                unsigned int chunksUpdated=0;
                                float cx=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().x,cy=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z;
                                while(chunksUpdated<8 and (pos=OgreFramework::getSingletonPtr()->map->getNextUpdatedChunk())!=NULL){
                                    int xx=pos->x*128-cx;
                                    int yy=pos->y*128-cy;
                                    if(xx*xx+yy*yy<1280){
                                    std::cout<<"Updating chunk\n";
                                    chunksUpdated++;
                                    try{
                                        OgreFramework::getSingletonPtr()->m_pSceneMgr->getSceneNode(std::string("NChunk")+(char)pos->x+(char)pos->y)->removeAndDestroyAllChildren();
                                    }
                                    catch(...){}
                                    OgreFramework::getSingletonPtr()->map->getChunk(pos->x,pos->y);
                                    delete pos;
                                    }
                                    else{
                                        OgreFramework::getSingletonPtr()->map->chunks_q.push(pos);
                                    }
                                }*/
                                float cx=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().x,cy=OgreFramework::getSingletonPtr()->m_pCamera->getPosition().z;
                                int lod = OgreFramework::getSingletonPtr()->m_pCamera->getPosition().y/OgreFramework::getSingletonPtr()->lodFactor;
                                if(lod>4)
                                    lod=4;
                                else if(lod<0)
                                    lod=0;
                                int showY = tan(OgreFramework::getSingletonPtr()->m_pCamera->getFOVy().valueRadians()) * OgreFramework::getSingletonPtr()->m_pCamera->getPosition().y/256.0+1;
                                if(showY>7)
                                    showY=7;
                                int showX=showY*4.0/3.0;
                                try{
                                for(int xx=cx/128-showX;xx<=cx/128+showX;xx++){
                                    for(int yy=cy/128-showY;yy<=cy/128+showY;yy++){
                                        if(xx>=0 and yy>=0 and xx<OgreFramework::getSingletonPtr()->map->x and yy<OgreFramework::getSingletonPtr()->map->y and !OgreFramework::getSingletonPtr()->map->fresh[lod][xx][yy]){
                                            /*try{
                                                OgreFramework::getSingletonPtr()->m_pSceneMgr->getSceneNode(std::string("NChunk")+Map::getPos(xx,yy))->removeAndDestroyAllChildren();
                                            }
                                            catch(...){
                                            //    std::cout<<"Chunk didnt exist\n";
                                            }*/
                                            OgreFramework::getSingletonPtr()->map->getChunk(xx,yy,lod);
                                            //std::cout<<"Updating chunk\n";
                                            throw (int)0;
                                            }
                                    }
                                }
                                }
                                catch(int){}//exit from loop
                                lock.unlock();
                                boost::this_thread::sleep(boost::posix_time::milliseconds(1));
                                timeSinceLastFrame = OgreFramework::getSingletonPtr()->m_pTimer->getMillisecondsCPU() - startTime; 
                        }
                        else
                        {
        #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
                    Sleep(1000);
        #else
                    sleep(1);
        #endif
                        }
                }
                OgreFramework::getSingletonPtr()->m_pLog->logMessage("Autosaving...");
                OgreFramework::getSingletonPtr()->map->save("autosave.map");
                OgreFramework::getSingletonPtr()->m_pLog->logMessage("Main loop quit");
                OgreFramework::getSingletonPtr()->m_pLog->logMessage("Shutdown OGRE...");
        }