void* SoundManager::loadAudioGroup(std::string audioGroup)
{
	void * audioGroupHandle = nullptr;
#ifdef FMOD_ACTIVE
	FMOD::Studio::Bank * bank = nullptr;
	#if (CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
		FileUtilsAndroid * androidUtils = static_cast<FileUtilsAndroid *>(FileUtils::getInstance());
		Data bankData = androidUtils->getDataFromFile("Media/" + audioGroup);

		const char * buffer = (const char *)bankData.getBytes();
		int size = (int)bankData.getSize();

		ERRCHECK(_system->loadBankMemory(buffer, size, FMOD_STUDIO_LOAD_MEMORY, FMOD_STUDIO_LOAD_BANK_NORMAL, &bank));
	#else
		ERRCHECK(_system->loadBankFile(getMediaPath(audioGroup.c_str()), FMOD_STUDIO_LOAD_BANK_NORMAL, &bank));
	#endif
	if (bank)
	{
		audioGroupHandle = (void*)bank;
	}
#endif
	return audioGroupHandle;
}
예제 #2
0
bool Application::initialize( int argc, char **argv )
{
    // this is used when hunting for memory leaks
#ifdef YAF3D_ENABLE_HEAPCHECK
    // trigger debugger
    //__asm int 3;
#endif

    std::string arg_levelname;
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments( &argc,argv );
    osg::ArgumentParser::Parameter levelparam( arg_levelname );
    arguments.read( "-level", arg_levelname ); // read the level file if one given

    int   argpos;
    // set proper game mode
    GameState::get()->setMode( GameState::Standalone );
    if ( ( argpos = arguments.find( "-server" ) ) != 0 )
    {
        GameState::get()->setMode( GameState::Server );
        arguments.remove( argpos );
    }
    else if ( ( argpos = arguments.find( "-client" ) ) != 0 )
    {
        GameState::get()->setMode( GameState::Client );
        arguments.remove( argpos );
    }

    // note: before beginning to initialize the framework modules the media path must be set, 
    //  other modules need it for loading resources etc.
    //-------------------
    std::vector< std::string > path;
    std::string dir;
    {
        char* p_env = getenv( YAF3D_ENV_MEDIA_DIR );
        if ( p_env )
        {
            _mediaPath = p_env;
        }
        else
        {
            dir = getCurrentWorkingDirectory();
            dir = cleanPath( dir );
            dir += "/";
            path.clear();
            explode( dir, "/", &path );
#ifdef LINUX
            dir = "/";
#endif
#ifdef WIN32
            dir = "";
#endif
            for ( size_t cnt = 0; cnt < path.size() - 2; ++cnt )
                dir += path[ cnt ] + "/";

            dir.erase( dir.size() -1 );
            _mediaPath = dir;
            _mediaPath += YAF3D_MEDIA_PATH;
        }
    }

    //-------------------
    // set the ful binary path of application
    _fulBinaryPath = arguments.getApplicationName();
    _fulBinaryPath = cleanPath( _fulBinaryPath );
    _fulBinaryPath = _fulBinaryPath.substr( 0, _fulBinaryPath.rfind( '/' ) );
    //-------------------

    // load the standard configuration before changing to 'Initializing' state
    Configuration::get()->load();

    // set game state
    _p_gameState->setState( GameState::Initializing );

    // setup log system
    {
        std::string loglevel;
        bool        invalidloglevel = false;
        Log::Level  level           = Log::L_ERROR;

        // get the log level from configuration
        Configuration::get()->getSettingValue( YAF3D_GS_LOG_LEVEL, loglevel );

        if ( loglevel == "error" )
            level = Log::L_ERROR;
        else if ( loglevel == "warning" )
            level = Log::L_WARNING;
        else if ( loglevel == "debug" )
            level = Log::L_DEBUG;
        else if ( loglevel == "info" )
            level = Log::L_INFO;
        else 
            invalidloglevel = true;

        // create log sinks with configured log level
        if ( GameState::get()->getMode() != GameState::Server )
            log.addSink( "file", getMediaPath() + std::string( LOG_FILE_NAME ), level );
        else
            log.addSink( "file", getMediaPath() + std::string( LOG_FILE_NAME_SERVER ), level );

        // only the server needs an console stdout
#ifdef YAF3D_HAS_CONSOLE
        log.addSink( "stdout", std::cout, level );
#endif

        // check if we have to report an invalid log level in configuration
        if ( invalidloglevel )
            log_warning << "Application: configuration contains an invalid log level, possible values are: error, warning, debug, info. set to error." << std::endl;
    }

    log.enableSeverityLevelPrinting( false );
    log_info << std::endl;
    log << " *******************************************"    << std::endl;
    log << " * yaf3d -- Yet another Framework 3D       *"    << std::endl;
    log << " * version: " << std::string( YAF3D_VERSION ) << "                          *"  << std::endl;
    log << " * project: Yag2002                        *"    << std::endl;
    log << " * site:    http://yag2002.sourceforge.net *"    << std::endl;
    log << " * contact: [email protected]               *"    << std::endl;
    log << " *******************************************"    << std::endl;
    log << "" << std::endl;
    log.enableSeverityLevelPrinting( true );

    log << "Application: time " << yaf3d::getTimeStamp();

    // print cpu info
    {
        std::stringstream cpuinfo;
        cpuinfo << "Application: CPU supports ";
        if ( SDL_HasRDTSC() ) 
            cpuinfo << "RDTSC ";
        if ( SDL_HasMMX() ) 
            cpuinfo << "MMX ";
        if ( SDL_HasMMXExt() ) 
            cpuinfo << "MMXExt ";
        if ( SDL_Has3DNow() ) 
            cpuinfo << "3DNow ";
        if ( SDL_Has3DNowExt() ) 
            cpuinfo << "3DNowExt ";
        if ( SDL_HasSSE() ) 
            cpuinfo << "SSE ";
        if ( SDL_HasSSE2() ) 
            cpuinfo << "SSE2 ";
        if ( SDL_HasAltiVec() ) 
            cpuinfo << "AltiVec ";

        log << cpuinfo.str() << std::endl;
    }

    log << "Application: initializing viewer" << std::endl;
    log << "Application: using media path: " << _mediaPath << std::endl;

    // setup the viewer
    //----------
    
    // load the display settings
    Configuration::get()->getSettingValue( YAF3D_GS_SCREENWIDTH,  _screenWidth  );
    Configuration::get()->getSettingValue( YAF3D_GS_SCREENHEIGHT, _screenHeight );
    Configuration::get()->getSettingValue( YAF3D_GS_FULLSCREEN,   _fullScreen   );
    unsigned int colorBits = 24;
    Configuration::get()->getSettingValue( YAF3D_GS_COLORBITS, colorBits );

    // init SDL
    SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE );
    // set the icon and caption title
    SDL_WM_SetCaption( YAF3D_APP_TITLE, NULL );
    SDL_Surface* p_bmpsurface = SDL_LoadBMP( YAF3D_APP_ICON );
    if ( p_bmpsurface )
    {
        Uint32 col = SDL_MapRGB( p_bmpsurface->format, 255, 255, 255 );
        SDL_SetColorKey( p_bmpsurface, SDL_SRCCOLORKEY, col );
        SDL_WM_SetIcon( p_bmpsurface, NULL );
    }
    // enable unicode translation
    SDL_EnableUNICODE( 1 ); 
    SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); // enable key repeating

    _p_viewer = new osgSDL::Viewer;
    _rootSceneNode = new osg::Group;
    _rootSceneNode->setName( "_topSceneGroup_" );
	osgSDL::Viewport*   p_viewport = new osgSDL::Viewport( _rootSceneNode.get() );
	osgUtil::SceneView* p_sceneView = p_viewport->getSceneView();
    p_sceneView->setDefaults( osgUtil::SceneView::COMPILE_GLOBJECTS_AT_INIT );
	_p_viewer->addViewport( p_viewport );
    _p_viewer->requestContinuousUpdate( true ); // force event generation for FRAMEs, we need this for animations, etc.
    int flags = SDL_HWSURFACE;
    if ( _fullScreen )
        flags |= SDL_FULLSCREEN;
    if ( GameState::get()->getMode() == GameState::Server )
    {
        SDL_WM_SetCaption( YAF3D_APP_TITLE "-server", NULL );
    }
  	_p_viewer->setDisplayMode( _screenWidth, _screenHeight, colorBits, flags );
    _p_viewer->setCursorEnabled( false );    
    //------------

    // setup keyboard map
    std::string keybType;
    Configuration::get()->getSettingValue( YAF3D_GS_KEYBOARD, keybType );
    log_info << "Application: setup keyboard map to: " << keybType << std::endl;
    if ( keybType == YAF3D_GS_KEYBOARD_ENGLISH )
        KeyMap::get()->setup( KeyMap::English );
    else
        KeyMap::get()->setup( KeyMap::German );

    // get the instance of gui manager
    _p_guiManager = GuiManager::get();
    // setup networking
    _p_networkDevice = NetworkDevice::get();
    // avoid creating of remote clients so long we are initializing the system
    _p_networkDevice->lockObjects();
    if ( GameState::get()->getMode() == GameState::Server )
    {
        log_info << "Application: loading level file '" << arg_levelname << "'" << std::endl;
        // load the level and setup things
        osg::ref_ptr< osg::Group > sceneroot = LevelManager::get()->loadLevel( YAF3D_LEVEL_SERVER_DIR + arg_levelname );
        if ( !sceneroot.valid() )
            return false;

        // start networking before setting up entities
        std::string servername;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_NAME, servername );
        NodeInfo nodeinfo( arg_levelname, servername );
        unsigned int channel;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_PORT, channel );

        // try to setup server
        try
        {
            _p_networkDevice->setupServer( channel, nodeinfo );
        }
        catch ( const NetworkExpection& e )
        {
            log_error << "Application: error starting server, reason: " << e.what() << std::endl;
            return false;
        }

        // complete level loading
        LevelManager::get()->finalizeLoading();

        // the server needs no drawing
        _p_viewer->setUpdateAllViewports( false );
    }
    else if ( GameState::get()->getMode() == GameState::Client )
    {
        std::string url;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_IP, url );
        std::string clientname( "vrc-client" );
        NodeInfo nodeinfo( "", clientname );
        unsigned int channel;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_PORT, channel );

        // try to setup client networking
        try
        {
            _p_networkDevice->setupClient( url, channel, nodeinfo );
        }
        catch ( const NetworkExpection& e )
        {
            log_error << "Application: error setting up client networking, reason: " << e.what() << std::endl;
            return false;
        }

        // now load level
        std::string levelname = YAF3D_LEVEL_CLIENT_DIR + _p_networkDevice->getNodeInfo()->getLevelName();
        log_info << "Application: loading level file '" << levelname << "'" << std::endl;
        // load the level and setup things
        osg::ref_ptr< osg::Group > sceneroot = LevelManager::get()->loadLevel( levelname );
        if ( !sceneroot.valid() )
            return false;
        // complete level loading
        LevelManager::get()->finalizeLoading();

        // if we directly start a client with cmd line option then we must send a leave-menu notification to entities
        //  as many entities do special steps when leaving the menu
        EntityNotification notification( YAF3D_NOTIFY_MENU_LEAVE );
        EntityManager::get()->sendNotification( notification );
    }
    else // check for any level file name, so we try to start in Standalone mode
    {
        std::string defaultlevel = arg_levelname.length() ? ( std::string( YAF3D_LEVEL_SALONE_DIR ) + arg_levelname ) : std::string( YAF3D_DEFAULT_LEVEL );
        log_info << "Application: loading level file '" << defaultlevel << "'" << std::endl;
        // set game mode
        GameState::get()->setMode( GameState::Standalone );
        // load the level and setup things
        osg::ref_ptr< osg::Group > sceneroot = LevelManager::get()->loadLevel( defaultlevel );
        if ( !sceneroot.valid() )
            return false;
        // complete level loading
        LevelManager::get()->finalizeLoading();

        // if we directly start a client with cmd line option then we must send a leave-menu notification to entities
        //  as many entities do special steps when leaving the menu
        EntityNotification notification( YAF3D_NOTIFY_MENU_LEAVE );
        EntityManager::get()->sendNotification( notification );
    }

    return true;
}
예제 #3
0
bool Application::initialize( int argc, char **argv )
{
    // this is used when hunting for memory leaks
#ifdef YAF3D_ENABLE_HEAPCHECK
    // trigger debugger
    //__asm int 3;
#endif

    //! NOTE: on multi-core systems running win32, sometimes a noticable performance drop has been observed
    //        when the application uses more than one cpu for its threads. here we assign only one cpu to the entire app.
#ifdef WIN32
    SYSTEM_INFO sysInfo;
    GetSystemInfo( &sysInfo );
    if ( sysInfo.dwNumberOfProcessors > 1 )
    {
        // take the first cpu for our application
        DWORD_PTR  processAffinityMask = 0x1;
        SetProcessAffinityMask( GetCurrentProcess(), processAffinityMask );
    }
#endif

    // seed the standard pseudo random generator
    time_t t = time( NULL );
    srand( static_cast< unsigned int >( t ) );

    std::string arg_levelname;
    bool        arg_nodefaultlvl = false;
    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments( &argc,argv );
    osg::ArgumentParser::Parameter levelparam( arg_levelname );
    arguments.read( "-level", arg_levelname ); // read the level file if one given

    int   argpos;
    // set proper game mode
    GameState::get()->setMode( GameState::Standalone );
    if ( ( argpos = arguments.find( "-server" ) ) > 0 )
    {
        GameState::get()->setMode( GameState::Server );
        arguments.remove( argpos );
    }
    else if ( ( argpos = arguments.find( "-client" ) ) > 0 )
    {
        GameState::get()->setMode( GameState::Client );
        arguments.remove( argpos );
    }
    if ( ( argpos = arguments.find( "-nodefaultlevel" ) ) > 0 )
    {
        arg_nodefaultlvl = true;
        arguments.remove( argpos );
    }

    // note: before beginning to initialize the framework modules the media path must be set,
    //  other modules need it for loading resources etc.
    //-------------------
    std::vector< std::string > path;
    std::string dir;
    {
        char* p_env = getenv( YAF3D_ENV_MEDIA_DIR );
        if ( p_env )
        {
            _mediaPath = p_env;
        }
        else
        {
            dir = getCurrentWorkingDirectory();
            dir = cleanPath( dir );
            dir += "/";
            path.clear();
            explode( dir, "/", &path );
#ifdef LINUX
            dir = "/";
#endif
#ifdef WIN32
            dir = "";
#endif
            for ( size_t cnt = 0; cnt < path.size() - 2; ++cnt )
                dir += path[ cnt ] + "/";

            dir.erase( dir.size() -1 );
            _mediaPath = dir;
            _mediaPath += YAF3D_MEDIA_PATH;
        }
    }

    //-------------------
    // set the ful binary path of application
    _fulBinaryPath = arguments.getApplicationName();
    _fulBinaryPath = cleanPath( _fulBinaryPath );
    _fulBinaryPath = _fulBinaryPath.substr( 0, _fulBinaryPath.rfind( '/' ) );
    //-------------------

    // load the standard configuration before changing to 'Initializing' state
    Configuration::get()->load();

    // set game state
    _p_gameState->setState( GameState::Initializing );

    // setup log system
    {
        std::string loglevel;
        Log::Level  level = Log::L_ERROR;

        // get the log level from configuration
        Configuration::get()->getSettingValue( YAF3D_GS_LOG_LEVEL, loglevel );

        // check if we have to report an invalid log level in configuration
        if ( loglevel == "error" )
            level = Log::L_ERROR;
        else if ( loglevel == "warning" )
            level = Log::L_WARNING;
        else if ( loglevel == "debug" )
            level = Log::L_DEBUG;
        else if ( loglevel == "info" )
            level = Log::L_INFO;
        else if ( loglevel == "verbose" )
            level = Log::L_VERBOSE;
        else
            log_warning << "Application: configuration contains an invalid log level, possible values are: error, warning, debug, info, verbose. set to error." << std::endl;

        // create log sinks with configured log level
        if ( GameState::get()->getMode() != GameState::Server )
            log_out.addSink( "file", getMediaPath() + std::string( LOG_FILE_NAME ), level );
        else
            log_out.addSink( "file", getMediaPath() + std::string( LOG_FILE_NAME_SERVER ), level );

        // only the server needs an console stdout
#ifdef YAF3D_HAS_CONSOLE
        log_out.addSink( "stdout", std::cout, level );
#endif

    }

    log_out.enableSeverityLevelPrinting( false );
    log_info << std::endl;
    log_out << " *******************************************"    << std::endl;
    log_out << " * yaf3d -- Yet another Framework 3D       *"    << std::endl;
    log_out << " * version: " << std::string( YAF3D_VERSION ) << "                          *"  << std::endl;
    log_out << " * project: Yag2002                        *"    << std::endl;
    log_out << " * site:    http://yag2002.sourceforge.net *"    << std::endl;
    log_out << " * contact: [email protected] *"    << std::endl;
    log_out << " *******************************************"    << std::endl;
    log_out << "" << std::endl;
    log_out.enableSeverityLevelPrinting( true );

    log_out << "Application: time " << yaf3d::getTimeStamp();

    // print cpu info
    {
        std::stringstream cpuinfo;
        cpuinfo << "Application: CPU supports ";
        if ( SDL_HasRDTSC() )
            cpuinfo << "RDTSC ";
        if ( SDL_HasMMX() )
            cpuinfo << "MMX ";
        if ( SDL_HasMMXExt() )
            cpuinfo << "MMXExt ";
        if ( SDL_Has3DNow() )
            cpuinfo << "3DNow ";
        if ( SDL_Has3DNowExt() )
            cpuinfo << "3DNowExt ";
        if ( SDL_HasSSE() )
            cpuinfo << "SSE ";
        if ( SDL_HasSSE2() )
            cpuinfo << "SSE2 ";
        if ( SDL_HasAltiVec() )
            cpuinfo << "AltiVec ";

        log_out << cpuinfo.str() << std::endl;
    }

    // implement the signal handler
    implementSignalHandler();

    log_out << "Application: using media path: " << _mediaPath << std::endl;
    log_out << "Application: setup virtual file system" << std::endl;

    try
    {
        FileSystem::get()->initialize( argv );
        FileSystem::get()->mountResource( _mediaPath, "/" );
        if ( fileExists( _mediaPath + YAF3D_MEDIA_PACK ) )
        {
            FileSystem::get()->mountResource( _mediaPath + YAF3D_MEDIA_PACK, "/" );
        }
    }
    catch ( const FileSystemException& e )
    {
        log_error << "Application: problem occured while setting up the virtual file system!" << std::endl;
        log_error << " reason:" << e.what() << std::endl;
        return false;
    }

    // setup the viewer
    //----------

    // load the display settings
    log_out << "Application: initializing viewer" << std::endl;
    Configuration::get()->getSettingValue( YAF3D_GS_SCREENWIDTH,  _screenWidth  );
    Configuration::get()->getSettingValue( YAF3D_GS_SCREENHEIGHT, _screenHeight );
    Configuration::get()->getSettingValue( YAF3D_GS_FULLSCREEN,   _fullScreen   );
    unsigned int colorBits = 24;
    Configuration::get()->getSettingValue( YAF3D_GS_COLORBITS, colorBits );

    // set the icon and caption title only for non-servers
    if ( GameState::get()->getMode() != GameState::Server )
    {
       // init SDL with video
        SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE );

        // set application window's title
        _appWindowTitle = YAF3D_APP_TITLE " " YAF3D_VERSION;
        setWindowTitle( _appWindowTitle );

        SDL_Surface* p_bmpsurface = SDL_LoadBMP( YAF3D_APP_ICON );
        if ( p_bmpsurface )
        {
            Uint32 col = SDL_MapRGB( p_bmpsurface->format, 255, 255, 255 );
            SDL_SetColorKey( p_bmpsurface, SDL_SRCCOLORKEY, col );
            SDL_WM_SetIcon( p_bmpsurface, NULL );
        }
    }
    else
    {
        // init SDl witout video for server
        SDL_Init( SDL_INIT_NOPARACHUTE );
    }
    // enable unicode translation
    SDL_EnableUNICODE( 1 );
    SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); // enable key repeating

    _p_viewer = new osgSDL::Viewer;
    _rootSceneNode = new osg::Group;
    _rootSceneNode->setName( "_topSceneGroup_" );
    osgSDL::Viewport*   p_viewport = new osgSDL::Viewport( _rootSceneNode.get() );
    osgUtil::SceneView* p_sceneView = p_viewport->getSceneView();
    p_sceneView->setDefaults( osgUtil::SceneView::COMPILE_GLOBJECTS_AT_INIT );
    _p_viewer->addViewport( p_viewport );
    _p_viewer->requestContinuousUpdate( true ); // force event generation for FRAMEs, we need this for animations, etc.

    int flags = SDL_HWSURFACE;
    if ( _fullScreen )
        flags |= SDL_FULLSCREEN;

    _p_viewer->setDisplayMode( _screenWidth, _screenHeight, colorBits, flags );
    _p_viewer->setCursorEnabled( false );
    //------------

    // setup keyboard map
    std::string keybType;
    Configuration::get()->getSettingValue( YAF3D_GS_KEYBOARD, keybType );
    log_info << "Application: setup keyboard map to: " << keybType << std::endl;
    if ( keybType == YAF3D_GS_KEYBOARD_ENGLISH )
        KeyMap::get()->setup( KeyMap::English );
    else
        KeyMap::get()->setup( KeyMap::German );

    // get the instance of gui manager
    _p_guiManager = GuiManager::get();

    // setup networking
    _p_networkDevice = NetworkDevice::get();
    if ( GameState::get()->getMode() == GameState::Server )
    {
        log_info << "Application: loading level file '" << arg_levelname << "'" << std::endl;
        // load the level and setup things
        osg::ref_ptr< osg::Group > sceneroot = LevelManager::get()->loadLevel( YAF3D_LEVEL_SERVER_DIR + arg_levelname );
        if ( !sceneroot.valid() )
        {
            log_error << "Application: could not load level '" << YAF3D_LEVEL_SERVER_DIR + arg_levelname << "'" << std::endl;
            return false;
        }

        // append the level node to scene root node
        _rootSceneNode->addChild( sceneroot.get() );

        // start networking before setting up entities
        std::string servername;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_NAME, servername );
        NodeInfo nodeinfo( arg_levelname, servername );
        unsigned int channel = 0;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_PORT, channel );
        bool needsAuth = false;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_AUTH, needsAuth );
        nodeinfo.setNeedAuthentification( needsAuth );

        // try to setup server
        try
        {
            _p_networkDevice->setupServer( channel, nodeinfo );
        }
        catch ( const NetworkException& e )
        {
            log_error << "Application: error starting server, reason: " << e.what() << std::endl;
            return false;
        }

        // complete level loading
        LevelManager::get()->finalizeLoading();

        // the server needs no drawing
        _p_viewer->setUpdateAllViewports( false );
    }
    else if ( GameState::get()->getMode() == GameState::Client )
    {
        std::string url;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_IP, url );
        std::string clientname( "vrc-client" );
        NodeInfo nodeinfo( "", clientname );
        unsigned int channel = 0;
        Configuration::get()->getSettingValue( YAF3D_GS_SERVER_PORT, channel );

        // try to setup client networking
        try
        {
            _p_networkDevice->setupClient( url, channel, nodeinfo );
        }
        catch ( const NetworkException& e )
        {
            log_error << "Application: error setting up client networking, reason: " << e.what() << std::endl;
            return false;
        }

        // now load level
        std::string levelname = YAF3D_LEVEL_CLIENT_DIR + nodeinfo.getLevelName();
        log_info << "Application: loading level file '" << levelname << "'" << std::endl;
        // load the level and setup things
        osg::ref_ptr< osg::Group > sceneroot = LevelManager::get()->loadLevel( levelname );
        if ( !sceneroot.valid() )
        {
            log_error << "Application: could not load level '" << levelname << "'" << std::endl;
            return false;
        }

        // append the level node to scene root node
        _rootSceneNode->addChild( sceneroot.get() );

        // complete level loading
        LevelManager::get()->finalizeLoading();

        // if we directly start a client with cmd line option then we must send a leave-menu notification to entities
        //  as many entities do special steps when leaving the menu
        EntityNotification notification( YAF3D_NOTIFY_MENU_LEAVE );
        EntityManager::get()->sendNotification( notification );
    }
    else if ( !arg_nodefaultlvl ) // check for any level file name, so we try to start in Standalone mode if not no-default-level option is given
    {
        std::string defaultlevel = arg_levelname.length() ? ( std::string( YAF3D_LEVEL_SALONE_DIR ) + arg_levelname ) : std::string( YAF3D_DEFAULT_LEVEL );
        log_info << "Application: loading level file '" << defaultlevel << "'" << std::endl;
        // set game mode
        GameState::get()->setMode( GameState::Standalone );
        // load the level and setup things
        osg::ref_ptr< osg::Group > sceneroot = LevelManager::get()->loadLevel( defaultlevel );
        if ( !sceneroot.valid() )
        {
            log_error << "Application: could not load level '" << defaultlevel << "'" << std::endl;
            return false;
        }

        // append the level node to scene root node
        _rootSceneNode->addChild( sceneroot.get() );

        // complete level loading
        LevelManager::get()->finalizeLoading();

        // if we directly start a level with cmd line option then we must send a leave-menu notification to entities
        //  as many entities do special steps when leaving the menu
        if ( arg_levelname.length() )
        {
            EntityNotification notification( YAF3D_NOTIFY_MENU_LEAVE );
            EntityManager::get()->sendNotification( notification );
        }
    }

    if ( arg_nodefaultlvl )
    {
        // set game mode to standalone
        GameState::get()->setMode( GameState::Standalone );

        // setup the level manager
        LevelManager::get()->finalizeLoading();
        // setup the root node
        _rootSceneNode->addChild( LevelManager::get()->getTopNodeGroup().get() );
    }

    // setup the shadow mananger now
    if ( GameState::get()->getMode() != GameState::Server )
    {
        bool shadow = true;
        // if glsl is not available then disable dynamic shadow flag in configuration
        if ( !yaf3d::isGlslAvailable() )
        {
            log_info << "Dynamic shadows disabled as GLSL is not available!" << std::endl;
            shadow = false;
            yaf3d::Configuration::get()->setSettingValue( YAF3D_GS_SHADOW_ENABLE, shadow );
            yaf3d::Configuration::get()->store();
        }

        bool shadowEnable = false;
        Configuration::get()->getSettingValue( YAF3D_GS_SHADOW_ENABLE, shadowEnable );

        if ( shadow && shadowEnable )
        {
            unsigned int shadowTexSizeX = 0, shadowTexSizeY = 0, shadowTexChannel = 0;
            yaf3d::Configuration::get()->getSettingValue( YAF3D_GS_SHADOW_TEXSIZEX, shadowTexSizeX );
            yaf3d::Configuration::get()->getSettingValue( YAF3D_GS_SHADOW_TEXSIZEY, shadowTexSizeY );
            yaf3d::Configuration::get()->getSettingValue( YAF3D_GS_SHADOW_TEXCHANNEL, shadowTexChannel );
            ShadowManager::get()->setup( shadowTexSizeX, shadowTexSizeY, shadowTexChannel );
        }
    }

    // store sound manager reference for faster access in loop
    _p_soundManager = SoundManager::get();

    // from now on game state can handle application window state changes
    _p_gameState->initAppWindowStateHandler();

    // setup local app window state handler
    _p_appWindowStateHandler = new AppWindowStateHandler( this );

    return true;
}
SoundManager::SoundManager()
: _systemVolumeMusic(1.0f)
, _systemVolumeFX(1.0f)
, _userVolumeMusic(1.0f)
, _userVolumeFX(1.0f)
, _expectedSystemVolumeFX(1.0f)
, _expectedSystemVolumeMusic(1.0f)
, _expectedUserVolumeFX(1.0f)
, _expectedUserVolumeMusic(1.0f)
{
    // Sound Init
#ifdef FMOD_ACTIVE
    //    void *extraDriverData = NULL;
    //    utilityInit(&extraDriverData);
    
    _system = NULL;
    ERRCHECK(FMOD::Studio::System::create(&_system) );
    
#if CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID

    FMOD::System * lowLevelSystem = nullptr;
    ERRCHECK(_system->getLowLevelSystem(&lowLevelSystem));
    ERRCHECK(lowLevelSystem->setOutput(FMOD_OUTPUTTYPE_AUDIOTRACK));

    unsigned int bufferLength;
    int numBuffers;

    ERRCHECK(lowLevelSystem->getDSPBufferSize(&bufferLength, &numBuffers));

    CCLOG("SoundManager - Default Buffer Length %u", bufferLength);
    CCLOG("SoundManager - Default Number of Buffer %d", numBuffers);

    bufferLength = 256; // 512; // 1024;
    numBuffers = 2; // 2; // 8;

    ERRCHECK(lowLevelSystem->setDSPBufferSize(bufferLength, numBuffers));

    ERRCHECK(lowLevelSystem->getDSPBufferSize(&bufferLength, &numBuffers));

    CCLOG("SoundManager - New Buffer Length %u", bufferLength);
    CCLOG("SoundManager - New Number of Buffer %d", numBuffers);

    int sampleRate;
    FMOD_SPEAKERMODE speakerMode;
    int numRawSpeakers;

    ERRCHECK(lowLevelSystem->getSoftwareFormat(&sampleRate , &speakerMode, &numRawSpeakers));

    CCLOG("SoundManager - Default Sample Rate %d", sampleRate);
    CCLOG("SoundManager - Default Speaker mode %d", (int)speakerMode);
    CCLOG("SoundManager - Default Number of Raw Speakers %d", numRawSpeakers);

    sampleRate = 24000;

    ERRCHECK(lowLevelSystem->setSoftwareFormat(sampleRate, speakerMode, numRawSpeakers));

    ERRCHECK(lowLevelSystem->getSoftwareFormat(&sampleRate , &speakerMode, &numRawSpeakers));

    CCLOG("SoundManager - New Sample Rate %d", sampleRate);
    CCLOG("SoundManager - New Speaker mode %d", (int)speakerMode);
    CCLOG("SoundManager - New Number of Raw Speakers %d", numRawSpeakers);

#endif

    ERRCHECK(_system->initialize(64, FMOD_STUDIO_INIT_LIVEUPDATE, FMOD_INIT_NORMAL, 0) );
//    ERRCHECK(_system->initialize(64, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, 0) );
    //    ERRCHECK(_system->initialize(32, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, 0) );
    ERRCHECK(FMOD_Debug_Initialize(FMOD_DEBUG_LEVEL_WARNING, FMOD_DEBUG_MODE_TTY, 0, nullptr));
    //    ERRCHECK(_system->initialize(32, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, extraDriverData) );

//    _masterBank = NULL;
//    ERRCHECK(_system->loadBankFile(getMediaPath(FILE_BANK_MASTER_DATA_NAME), FMOD_STUDIO_LOAD_BANK_NORMAL, &_masterBank));
    
    //_stringsBank = static_cast<FMOD::Studio::Bank*>(this->loadAudioGroup(FILE_BANK_MASTER_META_NAME));
    _stringsBank = NULL;
    ERRCHECK(_system->loadBankFile(getMediaPath(FILE_BANK_MASTER_META_NAME), FMOD_STUDIO_LOAD_BANK_NORMAL, &_stringsBank));
    
    Director::getInstance()->getScheduler()->schedule(schedule_selector(SoundManager::updateSounds), this, 0.05, false);
#endif
}
예제 #5
0
파일: backup.c 프로젝트: linhuafu/hwapu
void BackUp_Init(char *source, char*dest)
{
	/* Init TTS */
	memset(&bk_nano, 0x00, sizeof(struct backup_nano));
	bk_nano.thiz = (struct CopyInfo *)malloc(sizeof(struct CopyInfo));
	if(!bk_nano.thiz){
		bk_nano.err_exit = 1;
		return;
	}
	memset(bk_nano.thiz, 0x00, sizeof(struct CopyInfo));
	backup_reg_ttsSingal();
	plextalk_update_tts(g_config->setting.lang.lang);
	/* Init language */
	plextalk_update_lang(g_config->setting.lang.lang, "backup");
	backup_tts_init();
	
	bk_nano.source = source;
	bk_nano.dest = dest;

	if(StringStartWith(source, DISK_INNER)){
		bk_nano.media = 0;
	}else if(StringStartWith(source, DISK_SDCRD)){
		bk_nano.media = 1;
	}else{
		bk_nano.media = 2;
	}

	//只读判断
	if(isMediaReadOnly(bk_nano.dest))
	{
		backup_tts(TTS_MEDIA_LOCKED, 0);
		bk_nano.err_exit = 1;
		return;
	}

	if(StringStartWith(source, DISK_CDDA))
	{
		bk_nano.iscdda = 1;
		bk_nano.ret_pathsize = 1;
	}
	else{		
		struct statfs diskinfo;
		getMediaPath(bk_nano.dest, bk_nano.dirpath, sizeof(bk_nano.dirpath));
		DBGMSG("bk_nano.dirpath = %s\n", bk_nano.dirpath);
		statfs (bk_nano.dirpath, &diskinfo);
		bk_nano.freedir = (long long)diskinfo.f_bfree * (long long)diskinfo.f_bsize;
		DBGMSG("bk_nano.freedir  = %lld\n", bk_nano.freedir);
		bk_nano.getting_size = 1;

		bk_nano.bmusic = g_mode;
		//计算得到目标文件路径总大小		
		char cmd[1024];
		if(bk_nano.bmusic)
		{
			DBGMSG("copy only mp3 wave\n");
			sprintf(cmd, "find \"%s\" -name *.mp3 -exec cp {} \"%s\" \;", bk_nano.source, MUSIC_TMP_PATH);
			system(cmd);
			sprintf(cmd, "find \"%s\" -name *.wav -exec cp {} \"%s\" \;", bk_nano.source, MUSIC_TMP_PATH);
			system(cmd);
			bk_nano.source = MUSIC_TMP_PATH;
		}

		snprintf(cmd, 1024, "du -ck  \"%s\"", bk_nano.source);
		DBGMSG("cmd:%s\n", cmd);
		bk_nano.path_fp = popen(cmd, "r");
		bk_nano.path_fd = fileno(bk_nano.path_fp);
		bk_nano.path_report = 1;

		NeuxAppFDSourceRegister(bk_nano.path_fd , NULL, backup_pathsize_read, NULL);
		NeuxAppFDSourceActivate(bk_nano.path_fd , 1, 0);
	}
예제 #6
0
bool Renderer::init()
{
    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK) != 0) { 
        std::cerr << "Failed to initialise video subsytem"
                  << std::endl << std::flush;
        return false;
    }

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 1);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    int sticks = SDL_NumJoysticks();
    if (sticks > 0) {
        SDL_Joystick * stick = SDL_JoystickOpen(0);
        int axes = SDL_JoystickNumAxes(stick); // Returns the number of joysitck axes
        int buttons = SDL_JoystickNumButtons(stick); // Returns the number of joysitck buttons
        int balls = SDL_JoystickNumBalls(stick); // Returns the number of joysitck balls
        int hats = SDL_JoystickNumHats(stick); // Returns the number of joysitck hats
        std::cout << "Querying the first of " << sticks << " joysticks";
        std::cout << "It has " << axes << " axes, " << buttons << " buttons, "
                  << balls << " balls and " << hats << " hats"
                  << std::endl << std::flush;

    }

    videoModes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);

    /* Check is there are any modes available */
    if(videoModes == 0){
        printf("No modes available!\n");
    } else if (videoModes == (SDL_Rect **)-1) {
        printf("All resolutions available.\n");
    } else{
        /* Print valid modes */
        printf("Available Modes\n");
        for(int i=0; videoModes[i]; ++i) {
            printf("  %d x %d\n", videoModes[i]->w, videoModes[i]->h);
        }
    }
    fflush(stdout);
    // These should be turned on when running in production mode, but they
    // make using a debugger really hard and are only required in the perspective
    // client
    // SDL_WM_GrabInput(SDL_GRAB_ON);
    // SDL_ShowCursor(0);

    shapeView();

    Texture::getDefault();

    std::string extensions((const char *)glGetString(GL_EXTENSIONS));

    std::cout << "EXTENSIONS: " << extensions << std::endl << std::flush;

    sage_init();

    if (sage_ext[GL_ARB_VERTEX_BUFFER_OBJECT]) {
        std::cout << "GL_ARB_VERTEX_BUFFER_OBJECT supported" << std::endl << std::flush;
    } else {
        std::cout << "GL_ARB_VERTEX_BUFFER_OBJECT NOT supported" << std::endl << std::flush;
    }

    int textureUnits = -23;
    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &textureUnits);
    std::cout << "TEXTURE UNITS AVAILABLE: " << textureUnits
              << std::endl << std::flush;
    int depthbits = -1;
    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depthbits);
    std::cout << "DEPTH BITS AVAILABLE: " << depthbits
              << std::endl << std::flush;

    model = new Cal3dModel();
    if (!model->onInit(getMediaPath() + "/media/media_new/3d_skeletons/paladin/paladin.cfg")) {
        std::cerr << "Loading paladin model failed" << std::endl << std::flush;
    }
    model->setLodLevel(1.0f);

    return true;
}