Esempio n. 1
0
    Application::Application( int& argc, char** argv, GameLogic* gameLogic )
        : QApplication( argc, argv )
        , mOpenGLRenderSystem( 0 )
        , mDirect3D9RenderSystem( 0 )
        , mFrameCounter( 0 )
    {
        mGameLogic = gameLogic;
        if( mGameLogic != 0 )
        {
            mGameLogic->mApplication = this;
        }

        //Initialise the resources.
        initQtResources();

        //Load the settings file. If it doesn't exist it is created.
        mSettings = new QSettings( "settings.ini", QSettings::IniFormat );

        mOgreWidget = new EventHandlingOgreWidget( 0, 0 );

        //Logging should be initialised ASAP, and before Ogre::Root is created.
        initialiseLogging();

        //Create the root and load render system plugins. We do that here so that we know
        //what render systems are available by the time we show the settings dialog.
        //Note that the render system is not initialised until the user selects one.
        mRoot = new Ogre::Root();
        loadRenderSystemsFromPlugins();

        mSettingsDialog = new SettingsDialog( mSettings, mOgreWidget );
        mGraphicsSettingsWidget = new GraphicsSettingsWidget;
        mSettingsDialog->addSettingsWidget( "Graphics", mGraphicsSettingsWidget );
    }
Esempio n. 2
0
	Application::Application(int& argc, char** argv, GameLogic* gameLogic, IgnoredConfigWarningMode ignoredConfigWarningMode)
	:QApplication(argc, argv)
	,mFPSDialog(0)
	,mGraphicsSettingsWidget(0)
	,mOgreWidget(0)
	,mSettingsDialog(0)
	,mInternalOgreLog(0)
	,mInternalOgreLogManager(0)
	,mLogManager(0)
	,mOgreLog(0)
	,mSystemLog(0)
	,mActiveRenderSystem(0)
	,mOpenGLRenderSystem(0)
	,mDirect3D9RenderSystem(0)
	,mRoot(0)
	,mFrameCounter(0)
	,mGameLogic(gameLogic)
	,mAutoUpdateTimer(0)
	,mSettings(0)
	,mAutoUpdateEnabled(true)
	,mIsInitialised(false)
	,mIgnoredConfigWarningMode(ignoredConfigWarningMode)
	{
		if(mGameLogic != 0)
		{
			mGameLogic->mApplication = this;
		}

		//Initialise the resources.
		initQtResources();

		//Sanity check for config files
		if(mIgnoredConfigWarningMode == WarnAboutIgnoredConfigs)
		{
			QDirIterator it(".");
			while (it.hasNext())
			{
				it.next();
				if(QString::compare(it.fileInfo().suffix(), "cfg", Qt::CaseInsensitive) == 0)
				{
					if(	(QString::compare(it.fileInfo().baseName(), "plugins", Qt::CaseInsensitive) != 0) &&
						(QString::compare(it.fileInfo().baseName(), "plugins_d", Qt::CaseInsensitive) != 0) &&
						(QString::compare(it.fileInfo().baseName(), "resources", Qt::CaseInsensitive) != 0))
					{
						//We have found a file with the .cfg extension but which is not
						//'plugins.cfg' or 'resources.cfg'. Warn the user about this.
						warnAboutIgnoredConfigFile(it.fileInfo().fileName());
					}
				}
			}
		}

		mAutoUpdateTimer = new QTimer;
		QObject::connect(mAutoUpdateTimer, SIGNAL(timeout()), this, SLOT(update()));
		//On the test system, a value of one here gives a high frame rate and still allows
		//event processing to take place. A value of 0 doubles the frame rate but the mouse
		//becomes jumpy. This property is configerable via setAutoUpdateInterval().
		mAutoUpdateTimer->setInterval(1);

		//Load the settings file. If it doesn't exist it is created.
		mSettings = new QSettings("settings.ini", QSettings::IniFormat);

		mOgreWidget = new EventHandlingOgreWidget(0, 0);

		//Logging should be initialised ASAP, and before Ogre::Root is created.
		initialiseLogging();

		//Create the Ogre::Root object.
		qDebug("Creating Ogre::Root object...");
		try
		{
#ifdef QT_DEBUG
			mRoot = new Ogre::Root("plugins_d.cfg");
#else
			mRoot = new Ogre::Root("plugins.cfg");
#endif
			qDebug("Ogre::Root created successfully.");
		}
		catch(Ogre::Exception& e)
		{
			QString error
				(
				"Failed to create the Ogre::Root object. This is a fatal error and the "
				"application will now exit. There are a few known reasons why this can occur:\n\n"
				"    1) Ensure your plugins.cfg has the correct path to the plugins.\n"
				"    2) In plugins.cfg, use unix style directorary serperators. I.e '/' rather than '\\'.\n"
				"    3) If your plugins.cfg is trying to load the Direct3D plugin, make sure you have DirectX installed on your machine.\n\n"
				"The message returned by Ogre was:\n\n"
				);
			error += QString::fromStdString(e.getFullDescription().c_str());

			qCritical(error.toAscii());
			showErrorMessageBox(error);

			//Not much else we can do here...
			std::exit(1);
		}

		//Load the render system plugins. We do that here so that we know what
		//render systems are available by the time we show the settings dialog.
		//Note that the render system is not initialised until the user selects one.
		mOpenGLRenderSystem = mRoot->getRenderSystemByName("OpenGL Rendering Subsystem");
		mDirect3D9RenderSystem = mRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem");
		if(!(mOpenGLRenderSystem || mDirect3D9RenderSystem))
		{
			qCritical("No rendering subsystems found");
			showErrorMessageBox("No rendering subsystems found. Please ensure that your 'plugins.cfg' (or 'plugins_d.cfg') is correct and can be found by the executable.");
		}

		mSettingsDialog = new SettingsDialog(mSettings, mOgreWidget);
		mGraphicsSettingsWidget = new GraphicsSettingsWidget;
		mSettingsDialog->addSettingsWidget("Graphics", mGraphicsSettingsWidget);
	}