Esempio n. 1
0
	void Application::init()
	{
		// The very first thing to do is to add the current directory in DynamicObjectManager's list of repositories
		// In case some modules would need to load some config files
		shared_ptr<ISource> loadChannel(new SourceFile(".", false));
		shared_ptr<ISource> saveChannel(new SourceFile(".", true));

		DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();
		SoundManager *soundManager = SoundManager::getInstancePtr();

		GNOLL_LOG() << "Adding load/save source for current path to the DynamicObjectManager\n";
		pom->addLoadSource(loadChannel);
		pom->addSaveSource(saveChannel);

		GNOLL_LOG() << "Adding load/save source for current path to the SoundManager\n";
		soundManager->addLoadSource(loadChannel);
		soundManager->addSaveSource(saveChannel);

		/**
		 * Now program options have been parsed,
		 * program is initialized
		 */

		GNOLL_LOG() << "Instanciating modules...\n";
		logModule             = CLogModule::getInstancePtr();
		graphicmanager        = CGraphicModule::getInstancePtr();
		timeModule            = CTimeModule::getInstancePtr();
		messageModule         = CMessageModule::getInstancePtr();
		soundmanager          = CSoundModule::getInstancePtr();
		inputEventsTranslator = CInputEventsTranslator::getInstancePtr();
		statsModule           = CStatsModule::getInstancePtr();
		GNOLL_LOG() << "Instanciating modules...[DONE]\n";


		try
		{
			GNOLL_LOG() << "Initializing message module\n";
			messageModule->init();
			GNOLL_LOG() << "Initializing message module [DONE]\n";

			GNOLL_LOG() << "Initializing graphic module\n";
			graphicmanager->init();
			GNOLL_LOG() << "Initializing graphic module [DONE]\n";

			GNOLL_LOG() << "Initializing input manager\n";
			inputmanager.init();
			GNOLL_LOG() << "Initializing input manager [DONE]\n";

			GNOLL_LOG() << "Initializing sound manager\n";
			soundmanager->init();
			GNOLL_LOG() << "Initializing sound manager [DONE]\n";

			GNOLL_LOG() << "Initializing time module\n";
			timeModule->init();
			GNOLL_LOG() << "Initializing time module [DONE]\n";

			GNOLL_LOG() << "Initializing input event translator\n";
			inputEventsTranslator->init();
			GNOLL_LOG() << "Initializing input event translator [DONE]\n";

			GNOLL_LOG() << "Initializing stats module\n";
			statsModule->init();
			GNOLL_LOG() << "Initializing stats module [DONE]\n";
		}
		catch (Glib::ustring str)
		{
			cout << str << endl;
		}

		/*
		 * Define the listener of the application
		 * like the message on quit
		 */
		shared_ptr<Gnoll::ApplicationListener> listenerInput = shared_ptr<Gnoll::ApplicationListener>(
															   new Gnoll::ApplicationListener());
		messageModule->getMessageManager()->addListener ( listenerInput, Messages::MessageType(Gnoll::Input::ACTION_EVENT_TYPE) );

		/**
		 * Define the listener for the button
		 */
		CEGUI::PushButton *button_quit;
		button_quit = (CEGUI::PushButton *) CEGUI::WindowManager::getSingleton().getWindow("buttonQuit");
		button_quit->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&Application::quit_OnClick, this));
	}
Esempio n. 2
0
	void Application::analyzeArguments (int argc, char* argv[])
	{

		// Declare the supported options.
		options_description desc("Allowed options");
		desc.add_options()
			("help,h", "Produce help message")
			("log,l", value<std::string>(), "Log file name")
			("load-source-directory", value< vector<string> >()->composing(), "Add a directory as a load source")
			("save-source-directory", value< vector<string> >()->composing(), "Add a directory as a save source")
		;

		variables_map vm;
		store(parse_command_line(argc, argv, desc), vm);
		notify(vm);


		/**
		 * If help is required
		 *  -> Display usage
		 *  -> Exit
		 */
		if (vm.count("help"))
		{
			cout << desc;
			::exit(1);
		}


		CLogModule *logModule = CLogModule::getInstancePtr();

		if (vm.count("log"))
		{
			std::string logFile = vm["log"].as<std::string>();

			logModule->setLogFileName(logFile);
		}

		logModule->init();



		DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();
		SoundManager *soundManager = SoundManager::getInstancePtr();
		CameraManager *cameraManager = CameraManager::getInstancePtr();

		/**
		 * If a loading source has to be added
		 */
		if (vm.count("load-source-directory"))
		{


			vector<string> lsd = vm["load-source-directory"].as< vector<string> >();
			for (vector<string>::iterator it = lsd.begin(); it != lsd.end(); it++)
			{

				GNOLL_LOG() << "Adding new load source directory : \n";
				shared_ptr<ISource> userLoadChannel(new SourceFile(*it, false, 10));
				pom->addLoadSource(userLoadChannel);
				soundManager->addLoadSource(userLoadChannel);
				cameraManager->addLoadSource(userLoadChannel);
			}
		}


		/**
		 * If a saving source has to be added
		 */
		if (vm.count("save-source-directory"))
		{

			vector<string> lsd = vm["save-source-directory"].as< vector<string> >();
			for (vector<string>::iterator it = lsd.begin(); it != lsd.end(); it++)
			{

				GNOLL_LOG() << "Adding new save source directory : \n";
				shared_ptr<ISource> userSaveChannel(new SourceFile( *it, true, 10 ));
				pom->addSaveSource(userSaveChannel);
				soundManager->addSaveSource(userSaveChannel);
				cameraManager->addLoadSource(userSaveChannel);
			}
		}


	}