Exemple #1
0
/** Configures the application - returns false if the user chooses to abandon configuration. */
Ogre::Root* OgreSetup::configure() {
	delete mConfigListenerContainer;
	mConfigListenerContainer = new ConfigListenerContainer();
	mConfigListenerContainer->registerConfigListener("ogre", "loglevel", sigc::mem_fun(*this, &OgreSetup::Config_ogreLogChanged), true);

	ConfigService& configService(EmberServices::getSingleton().getConfigService());
	createOgreSystem();
#ifndef BUILD_WEBEMBER
	bool success = false;
	bool suppressConfig = false;
	if (configService.itemExists("ogre", "suppressconfigdialog")) {
		suppressConfig = static_cast<bool>(configService.getValue("ogre", "suppressconfigdialog"));
	}
	try {
		success = mRoot->restoreConfig();
		if (!success || !suppressConfig) {
			success = showConfigurationDialog();
		}

	} catch (const std::exception& ex) {
		S_LOG_WARNING("Error when showing config dialog. Will try to remove ogre.cfg file and retry." << ex);
		unlink((EmberServices::getSingleton().getConfigService().getHomeDirectory(BaseDirType_CONFIG) + "ogre.cfg").c_str());
		try {
			Ogre::ConfigDialog* dlg = OGRE_NEW Ogre::ConfigDialog();
			success = mRoot->showConfigDialog(dlg);
			OGRE_DELETE dlg;
		} catch (const std::exception& ex) {
			S_LOG_CRITICAL("Could not configure Ogre. Will shut down." << ex);
		}
	}
	if (!success) {
		return nullptr;
	}

	// we start by trying to figure out what kind of resolution the user has selected, and whether full screen should be used or not
	unsigned int height = 768, width = 1024;
	bool fullscreen = false;

	parseWindowGeometry(mRoot->getRenderSystem()->getConfigOptions(), width, height, fullscreen);

	bool handleOpenGL = false;
#ifdef __APPLE__
	handleOpenGL = true;
#endif

	std::string windowId = Input::getSingleton().createWindow(width, height, fullscreen, true, true, handleOpenGL);

	mRoot->initialise(false, "Ember");
	Ogre::NameValuePairList misc;
#ifdef __APPLE__
	misc["currentGLContext"] = Ogre::String("true");
	misc["macAPI"] = Ogre::String("cocoa");
#else
//We should use "externalWindowHandle" on Windows, and "parentWindowHandle" on Linux.
#ifdef _WIN32
	misc["externalWindowHandle"] = windowId;
#else
	misc["parentWindowHandle"] = windowId;
#endif
#endif

	mRenderWindow = mRoot->createRenderWindow("MainWindow", width, height, fullscreen, &misc);

	Input::getSingleton().EventSizeChanged.connect(sigc::mem_fun(*this, &OgreSetup::input_SizeChanged));

	registerOpenGLContextFix();

	if (mSaveShadersToCache) {
		Ogre::GpuProgramManager::getSingleton().setSaveMicrocodesToCache(true);

		std::string cacheFilePath = configService.getHomeDirectory(BaseDirType_CACHE) + "/gpu-" VERSION ".cache";
		if (std::ifstream(cacheFilePath).good()) {
			try {
				auto cacheStream = mRoot->openFileStream(cacheFilePath);
				if (cacheStream) {
					Ogre::GpuProgramManager::getSingleton().loadMicrocodeCache(cacheStream);
				}
			} catch (...) {
				S_LOG_WARNING("Error when trying to open GPU cache file.");
			}
		}
	}

#else //BUILD_WEBEMBER == true
	//In webember we will disable the config dialog.
	//Also we will use fixed resolution and windowed mode.
	try {
		mRoot->restoreConfig();
	} catch (const std::exception& ex) {
		//this isn't a problem, we will set the needed functions manually.
	}
	Ogre::RenderSystem* renderer = mRoot->getRenderSystem();
#ifdef _WIN32
	//on windows, the default renderer is directX, we will force OpenGL.
	Ogre::RenderSystem* renderer = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
	if(renderer != nullptr) {
		mRoot->setRenderSystem(renderer);
	} else {
		S_LOG_WARNING("OpenGL RenderSystem not found. Starting with default RenderSystem.");
		renderer = mRoot->getRenderSystem();
	}
#endif // _WIN32
	renderer->setConfigOption("Video Mode", "800 x 600");
	renderer->setConfigOption("Full Screen", "no");

	mRoot->initialise(false, "Ember");

	Ogre::NameValuePairList options;

	if (configService.itemExists("ogre", "windowhandle")) {
		//set the owner window
		std::string windowhandle = configService.getValue("ogre", "windowhandle");
		options["parentWindowHandle"] = windowhandle;

		//put it in the top left corner
		options["top"] = "0";
		options["left"] = "0";
	}

	mRenderWindow = mRoot->createRenderWindow("Ember",800,600,false,&options);
	mOgreWindowProvider = new OgreWindowProvider(*mRenderWindow);
	Input::getSingleton().attach(mOgreWindowProvider);

#endif // BUILD_WEBEMBER

	mRenderWindow->setActive(true);
	mRenderWindow->setAutoUpdated(true);
	mRenderWindow->setVisible(true);

	setStandardValues();


	mConfigListenerContainer->registerConfigListener("ogre", "profiler", [&](const std::string& section, const std::string& key, varconf::Variable& variable) {
		if (variable.is_bool()) {
			auto* profiler = Ogre::Profiler::getSingletonPtr();
			if (profiler) {
				if ((bool) variable) {
					auto& resourceGroupMgr = Ogre::ResourceGroupManager::getSingleton();
					if (!resourceGroupMgr.resourceGroupExists("Profiler")) {
						resourceGroupMgr.addResourceLocation(OGRE_MEDIA_DIR"/packs/profiler.zip", "Zip", "Profiler", true);
						resourceGroupMgr.addResourceLocation(OGRE_MEDIA_DIR"/packs/SdkTrays.zip", "Zip", "Profiler", true);
						resourceGroupMgr.initialiseResourceGroup("Profiler");
					}
				}

				if (profiler->getEnabled() != (bool) variable) {
					profiler->reset();
					profiler->setEnabled((bool) variable);
				}
			}
		}
	});

	// Create new scene manager factory
	//mSceneManagerFactory = new EmberPagingSceneManagerFactory();

	//// Register our factory
	//mRoot->addSceneManagerFactory(mSceneManagerFactory);

	return mRoot;
}
Exemple #2
0
/*!

*/
bool
Options::parseCmdLine( int argc,
                       char ** argv )
{
    rcsc::ParamMap system_options( "System Options" );
    rcsc::ParamMap window_options( "Window Options" );
    rcsc::ParamMap editor_options( "Editor Options" );
    rcsc::ParamMap view_options( "View Options" );

    bool help = false;
    bool version = false;

    system_options.add()
        ( "help", "h",
          rcsc::BoolSwitch( &help ),
          "print this message." )
        ( "version", "v",
          rcsc::BoolSwitch( &version ),
          "print version." )
        ;

    std::string geometry;

    window_options.add()
        ( "maximize", "",
          rcsc::BoolSwitch( &M_maximize ),
          "start with a maximized window." )
        ( "full-screen", "",
          rcsc::BoolSwitch( &M_full_screen ),
          "start with a full screen window." )
        ( "geometry", "",
          &geometry,
          "specifies the window geometry \"[WxH][+X+Y]\". e.g. --geometry=1024x768+0+0" )
        ;

    std::string conf_file;
    std::string data_file;
    std::string background_conf_file;

    editor_options.add()
        ( "conf", "c",
          &conf_file,
          "specifies a .conf file." )
        ( "data", "d",
          &data_file,
          "specifies a .dat file." )
        ( "background-conf", "C",
          &background_conf_file,
          "specifies a .conf file as a background data." )
        ( "auto-backup", "",
          &M_auto_backup,
          "make backup files automatically" )
        ;

    view_options.add()
        ( "no-antialiasing", "",
          rcsc::NegateSwitch( &M_antialiasing ),
          "disable antialiasing painting." )
        ( "no-auto-fit", "",
          rcsc::NegateSwitch( &M_auto_fit_mode ),
          "disable automatic view area fitting." )
        ;

    rcsc::CmdLineParser parser( argc, argv );

    parser.parse( system_options );
    parser.parse( window_options );
    parser.parse( editor_options );
    parser.parse( view_options );

    //
    // analyze positional options
    //

    for ( std::vector< std::string >::const_iterator it = parser.positionalOptions().begin();
          it != parser.positionalOptions().end();
          ++it )
    {
        // ".conf"
        if ( it->length() > 5
             && it->compare( it->length() - 5, 5, ".conf" ) == 0 )
        {
            if ( conf_file.empty() )
            {
                conf_file = *it;
            }
            else if ( background_conf_file.empty() )
            {
                background_conf_file = *it;
            }
            else // if ( ! conf_file.empty() && ! background_conf_file.empty() )
            {
                help = true;
                break;
            }
        }
        else
        {
            help = true;
            break;
        }
    }

    M_conf_file = QString::fromStdString( conf_file );
    M_data_file = QString::fromStdString( data_file );
    M_background_conf_file = QString::fromStdString( background_conf_file );

    //
    // help message
    //
    if ( help
         || parser.failed()
         || parser.positionalOptions().size() > 4 )
    {
        std::cout << "Usage: " << "fedit"
                  << " [options ... ] [conf file [background conf file]] [dat file]"
                  << std::endl;
        system_options.printHelp( std::cout, false ); // with_default = false
        window_options.printHelp( std::cout );
        editor_options.printHelp( std::cout );
        view_options.printHelp( std::cout );
        return false;
    }

    //
    // version message
    //
    if ( version )
    {
        std::cout << "fedit" << " Version " << VERSION
                  << std::endl;
        return false;
    }

    //
    // window size and position
    //

    parseWindowGeometry( geometry );

    return true;
}
Exemple #3
0
bool parseCmdLineArgs(int argc, char** argv, 
	std::string& name, std::string& connectionType, std::string& address, 
	WindowGeometry& geometry,
	bool& fullscreen, bool& always_on_top, bool& stereo)
{
    for(int i=1 ; i<argc ; ++i)
    {
        if(argv[i][0] == '-')
        {
			std::string applicationName(argv[0]);
			std::string geometryStr;
			int nextArgIdx;
			
            switch(argv[i][1])
            {
    		case 's':
				stereo = true;
				break;
            case 'm':
                connectionType="Multicast";
                break;
            case 'w':
                fullscreen=false;
                break;
			case 't':
				always_on_top = true;
				break;
            case 'a':
				nextArgIdx = ++i;
				if (nextArgIdx >= argc)
				{
					std::cerr << "ERROR: No address specified" << std::endl;
					usage(applicationName);
					return false;
				}
                address = argv[nextArgIdx];
				if (!validateAddress(address))
				{
					std::cerr << "ERROR: No valid IP4 address (in the form xxx.xxx.xxx.xxx) specified" << std::endl;
					usage(applicationName);
					return false;
				}
                break;
            case 'g':
				nextArgIdx = ++i;
				if (nextArgIdx >= argc)
				{
					std::cerr << "ERROR: No Window Geometry specified" << std::endl;
					usage(applicationName);
					return false;
				}
				geometryStr = argv[nextArgIdx];
				if (!parseWindowGeometry(geometryStr, geometry))
				{
					std::cerr << "ERROR: Malformed geometry: " << geometryStr << std::endl;
					usage(applicationName);
					return false;
				}
                break;
            case 'd':
				nextArgIdx = ++i;
                //display will be caught by glutInit, skip it, + its value
                /*if (strcmp(&argv[i][1], "display")==0) 
				{
                }*/
				break;
                // incorrect value falls through to bomb out...
            default:
                usage(applicationName);
                return false;
            }
        }
        else
        {
            name = argv[i];
        }
    }
	return true;
}