⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oasisresourcemanager.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
字号:
/******************************************************************************

 * This source file is part of Bad Camel Gaming

 * Copyright (C) 2003  Zephie Greyvenstein

 * See Readme.html for acknowledgements

 *

 * 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

 *****************************************************************************/



/******************************************************************************

 * FILENAME    : oasisResourceManager.cpp

 * DESCRIPTION : The resource manager base class

 * AUTHOR      : Zephie Greyvenstein

 *****************************************************************************/



#include "oasisResourceManager.h"

#include "oasisResource.h"

#include "oasisException.h"



#include "OgreResourceManager.h"

#include "OgreSDDataChunk.h"

#include "OgreLogManager.h"



namespace Oasis {



  resourceManager::resourceManager( ) {

    // Init memory budget

    memoryBudget = std::numeric_limits< size >::max( );  

  }



  resourceManager::~resourceManager( ) {

    unloadAndDestroyAll( );

  }



  void resourceManager::setMemoryLimit( size bytes ) {

    memoryBudget = bytes;



    checkMemoryBudget( );

  }



  void resourceManager::load( resource *res, uint8 priority ) {  

    add( res );

    res->touch( );

  }



  void resourceManager::add( resource *res ) {

    if ( getByName( res->getName( ) ) ) {

      oasisError( exception::ET_DUPLICATE_ITEM,

      "A resource with this name exists : " + res->getName( ),

      "resourceManager::add( )" );

    }



    resources[ res->getName( ) ] = res;

  }

  

  void resourceManager::unload( resource *res ) {

    if ( !res ) {

      return;

    }



    /// Unload it

    res->unload( );



    /// Remove it from the map

    resources.erase( res->getName( ) );

  }



  void resourceManager::unloadAndDestroyAll( void ) {

    // Destroy them all

    for( resourceMap::iterator it = resources.begin( );

   it != resources.end( ); ++it ) {

      unload( it->second );

      it->second->destroy( );

    }



    resources.clear( );

  }



  resource *resourceManager::getByName( const string &name ) {

    resourceMap::iterator it = resources.find( name );

    

    if ( it == resources.end( ) ) {

      return NULL;

    } else {

      return it->second;

    }    

  }

   

  bool resourceManager::_findResourceData( const string &fileName,

             Ogre::DataChunk &chunk ) {

    return Ogre::ResourceManager::_findCommonResourceData( fileName, chunk );

  }



  void resourceManager::_parseAllSources( const string &extension ) {

    // Temp holding for files found

    std::set< Ogre::String > files;

   

    // search common archives

    files = Ogre::ResourceManager::_getAllCommonNamesLike( "./", extension );

       

    std::set< Ogre::String>::iterator file;

    for ( file = files.begin( ); file != files.end( ); ++file ) {     

      _parseFile( *file );

    } 

  }

  

  void resourceManager::_parseFile( const string &name ) {

    Ogre::SDDataChunk chunk;  

    Ogre::String ogreName = name;

    Ogre::ResourceManager::_findCommonResourceData( ogreName, chunk );

    

    Ogre::LogManager::getSingleton( ).

      logMessage( "Parsing script: " + name );

    _parseFile( chunk );

  }

  

  void resourceManager::_logError( const string &line, resource *file ) {

    Ogre::LogManager::getSingleton( ).logMessage( "Bad attribute line: " + 

              line + " in script " + 

              file->getName( ) );

  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -