Esempio n. 1
0
int main() {


	cout << "Hello world !" << endl;



	shared_ptr<ISource> loadChannel(new SourceFile(".", false));
	shared_ptr<ISource> saveChannel(new SourceFile(".", true));

	DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();

	pom->addLoadSource(loadChannel);
	pom->addSaveSource(saveChannel);
/*
	shared_ptr<DynamicObject> Zelda = pom->load("zelda");

	shared_ptr<Integer> ageZelda = Zelda->getAttribute< Integer > ("age");
	shared_ptr<Integer> newAge(new Integer((*ageZelda)() + 1));
	Zelda->setAttribute("age2", newAge);
*/
	shared_ptr<Integer> newAge(new Integer(1));

	PJ pj("zelda32");
	pj.computeAge();
	pj.setAttribute("age2", newAge);
	pj.save();
	return 0;
}
Esempio n. 2
0
		void CInputEventsTranslator::activateKeyboardTranslation()
		{
			Messages::MessageType keyDown("KEYBOARD_KEYDOWN");
			Messages::MessageType keyUp("KEYBOARD_KEYUP");
			Messages::MessageType updateKeyboard("UPDATE_KEYBOARD");


			DynamicObjectManager *dom = DynamicObjectManager::getInstancePtr();
			shared_ptr< Gnoll::DynamicObject::DynamicObject > keyboardConfig = dom->load("keyboardConfig");

			/**
			 * How often will the keyboard module get updated (millisecond)
			 */
			unsigned long int period = 300;
			shared_ptr< Gnoll::DynamicObject::Integer > periodFromConfig = keyboardConfig->getAttribute< Gnoll::DynamicObject::Integer >("period");
			period = *periodFromConfig;

			CMessageModule* messageModule = CMessageModule::getInstancePtr();
			Messages::Messenger* messageManager = messageModule->getMessageManager();


			keyboardEventsTranslator = shared_ptr<Messages::Listener> ( new CKeyboardEventsTranslator() );
			keyboardEventsTrigger = shared_ptr<Messages::Listener> ( new CKeyboardEventsTrigger(static_pointer_cast<CKeyboardEventsTranslator>(keyboardEventsTranslator) ));
			keyboardStateTranslator = shared_ptr<Messages::Listener> ( new CKeyboardStateTranslator() );

			try
			{
				/**
				 * Continuous keyboard messages
				 */
				messageManager->addListener ( keyboardEventsTranslator, keyDown );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardEventsTranslator listener installed" );

				messageManager->addListener ( keyboardEventsTranslator, keyUp );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardEventsTranslator listener installed" );

				messageManager->addListener ( keyboardEventsTrigger, updateKeyboard );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardEventsTrigger listener installed" );

				/**
				 * State based keyboard messages
				 */
				messageManager->addListener ( keyboardStateTranslator, keyDown );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardStateTranslator listener installed" );

				messageManager->addListener ( keyboardStateTranslator, keyUp );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "KeyboardStateTranslator listener installed" );
			}
			catch(...)
			{
				throw;
			}

			CTimeModule* timeModule = CTimeModule::getInstancePtr();
			m_periodData = shared_ptr<boost::any> (new boost::any(period)) ;
			shared_ptr<CMessage>  message (new CMessage(updateKeyboard, m_periodData ));

			timeModule->addPeriodicEvent(0, message, period);
		}
		CMouseButtonEventsTranslator::CMouseButtonEventsTranslator():
			mouseButtonPressedEvent("MOUSE_PRESSED"),
			mouseButtonReleasedEvent("MOUSE_RELEASED")
		{

			DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();

			/**
			 * Loading translation map : Keycode -> Action
			 */
			this->mouseButtonEventTranslationMap = pom->load("mouseButtonEventTranslationMap");


			/**
			 * Mouse config
			 */
			this->mouseConfig = pom->load("mouseConfig");


		}
Esempio n. 4
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. 5
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);
			}
		}


	}
Esempio n. 6
0
int main() {


	cout << "Hello world !" << endl;

	DynamicObject toto = DynamicObject("toto");

	shared_ptr<Scalar<float> > pi( new Scalar<float>("float", 3.145) );
	shared_ptr<Integer> age( new Integer(345) );
	shared_ptr<Scalar<Glib::ustring> > phrase ( new Scalar<Glib::ustring>("string", "c'etait un cafard qui vivait dans le noir") );

	toto.setAttribute( Glib::ustring("pi"), pi);
	toto.setAttribute( "phrase", phrase);
	toto.setAttribute( "age", age);

	cout << (*pi)() << endl;
	cout << (*phrase)() << endl;

	cout << "Toto has attribute 'pi' : " << toto.hasAttribute("pi") << endl;
	cout << "Toto has attribute 'phrase' : " << toto.hasAttribute("phrase") << endl;
	cout << "Toto has attribute 'tournoyant' : " << toto.hasAttribute("tournoyant") << endl;

	const Glib::ustring pi_name("pi");


	shared_ptr<Scalar<float> > pi2 = toto.getAttribute< Scalar<float> > (pi_name);
	shared_ptr<Scalar<Glib::ustring> > phrase2 = toto.getAttribute< Scalar<Glib::ustring> > ("phrase");


	cout << "Get attribute 'pi' : " << *pi2 << endl;
	cout << "Get attribute 'phrase' : " << *phrase2 << endl;

	try
	{
		shared_ptr<Scalar<Glib::ustring> > phrase3 = toto.getAttribute< Scalar<Glib::ustring> > ("aioli");
	}
	catch(Glib::ustring e)
	{
		cout << e << endl;
	}


	cout << endl << "Serializationed (I'am sure it exists :) toto : " << endl;

	shared_ptr<xmlpp::Document> output = toto.serializeXML();
	cout << output->write_to_string_formatted()  << endl;


	SourceFile sf("./");

	shared_ptr<IStream> stream = sf.loadStream("testpo.cpp");
	unsigned int bytesRead = 0;
	while (!stream->eof())
	{
		char buffer[256];
		unsigned int nbRead = stream->read(buffer, 255);
		buffer[nbRead] = 0;
//	cout << buffer;
		bytesRead += nbRead;
	}
	stream->close();

	cout << endl << "Bytes Read : " << bytesRead << endl;

	sf.setOverWrite(true);

	shared_ptr<IStream> streamW = sf.saveStream("testpo.cppW");

	unsigned int bytesWritten = streamW->write("Jesuislorsdelajusticeetdel'emeriteca\nvalier", 40);
	streamW->close();

	cout << endl << "Bytes Written : " << bytesWritten << endl;



	shared_ptr<ISource> loadChannel(new SourceFile(".", false));
	shared_ptr<ISource> saveChannel(new SourceFile(".", true));

	DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();

	pom->addLoadSource(loadChannel);
	pom->addSaveSource(saveChannel);

	shared_ptr<DynamicObject> Zelda = pom->load("zelda");

	shared_ptr<Integer> ageZelda = Zelda->getAttribute< Integer > ("age");
	shared_ptr<Integer> newAge(new Integer((*ageZelda)() + 1));
	Zelda->setAttribute("age2", newAge);


	try
	{

		shared_ptr< Float > piZelda = Zelda->getAttribute< Float > ("pi");
		cout << "Float pi**2 zelda : " << (*piZelda) * (*piZelda) << endl;



		shared_ptr< String > nut = Zelda->getAttribute< String > ("nut");
		cout << "Attribute nut = '" << *nut << "'" << endl;



		shared_ptr< Double > dpi = Zelda->getAttribute< Double > ("dpi");
		cout << "Double PI in Zelda : " << setprecision(16) << *dpi << endl;
		cout << "Squared Double PI in Zelda : " << setprecision(16) << (*dpi) * (*dpi) << endl;


		typedef list< shared_ptr<IAttribute> >::iterator ListIterator;
		shared_ptr< List > list = Zelda->getAttribute< List > ("ListPreums");
		for (ListIterator it = list->begin(); it != list->end(); it++)
		{
			if (shared_ptr<String> str = dynamic_pointer_cast<String>(*it))
			{
				cout << "String element in list : '" << (*str) << "'" << endl;
			}

			if (shared_ptr<Integer> integer = dynamic_pointer_cast<Integer>(*it))
			{
				cout << "Integer element in list : [" << (*integer) + 2 << "]" << endl;
			}

			if (shared_ptr<Double> dbl = dynamic_pointer_cast<Double>(*it))
			{
				cout << "Double element in list : [" << (*dbl) << "]" << endl;
			}

			if (shared_ptr<Float> flt = dynamic_pointer_cast<Float>(*it))
			{
				cout << "Float element in list : [" << (*flt) << "]" << endl;
			}
		}

	}
	catch(Glib::ustring e)
	{
		cout << e << endl;
	}

	pom->save(Zelda->getInstance());

	cout << endl << "Serializationed (I'am sure it exists :) Zelda : " << endl;

	shared_ptr<xmlpp::Document> outputZelda = Zelda->serializeXML();
	cout << outputZelda->write_to_string_formatted()  << endl;


	cout << endl << endl << "--------------------------------------------" << endl << endl;


	shared_ptr<DynamicObject> Zelda2 = pom->load("zelda2");

	shared_ptr<xmlpp::Document> outputZelda2 = Zelda2->serializeXML();
	cout << outputZelda2->write_to_string_formatted()  << endl;

	return 0;
}
Esempio n. 7
0
		void CInputEventsTranslator::activateMouseButtonTranslation()
		{
			Messages::MessageType mousePressed("MOUSE_PRESSED");
			Messages::MessageType mouseReleased("MOUSE_RELEASED");
			Messages::MessageType updateMouse("UPDATE_MOUSE");

			DynamicObjectManager *dom = DynamicObjectManager::getInstancePtr();
			shared_ptr< Gnoll::DynamicObject::DynamicObject > mouseConfig = dom->load("mouseConfig");

			/**
			 * How often will the mouse button module get updated (millisecond)
			 */
			unsigned long int period = 300;
			shared_ptr< Gnoll::DynamicObject::Integer > periodFromConfig = mouseConfig->getAttribute< Gnoll::DynamicObject::Integer >("period");
			period = *periodFromConfig;


			CMessageModule* messageModule = CMessageModule::getInstancePtr();
			Messages::Messenger* messageManager = messageModule->getMessageManager();


			mouseButtonEventsTranslator = shared_ptr<Messages::Listener> ( new CMouseButtonEventsTranslator() );
			mouseButtonEventsTrigger = shared_ptr<Messages::Listener> ( new CMouseButtonEventsTrigger(static_pointer_cast<CMouseButtonEventsTranslator>(mouseButtonEventsTranslator) ) );

			mouseButtonStateTranslator = shared_ptr<Messages::Listener> ( new CMouseButtonStateTranslator() );

			try
			{
				/**
				 * Continuous mouse messages
				 */
				messageManager->addListener ( mouseButtonEventsTranslator, mousePressed );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "mouseButtonEventsTranslator listener installed for MOUSE_PRESSED" );

				messageManager->addListener ( mouseButtonEventsTranslator, mouseReleased );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage( "mouseButtonEventsTranslator listener installed for MOUSE_RELEASED" );

				messageManager->addListener ( mouseButtonEventsTrigger, updateMouse );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage ( "mouseButtonEventsTrigger listener installed" );

				/**
				 * State based mouse messages
				 */
				messageManager->addListener ( mouseButtonStateTranslator, mousePressed );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage ( "mouseButtonStateTranslator listener installed for MOUSE_PRESSED" );

				messageManager->addListener ( mouseButtonStateTranslator, mouseReleased );
				Gnoll::Log::CLogModule::getInstancePtr()->logMessage ( "mouseButtonStateTranslator listener installed for MOUSE_RELEASED" );
			}
			catch(...)
			{
				throw;
			}


			CTimeModule* timeModule = CTimeModule::getInstancePtr();
			m_periodData = shared_ptr<boost::any> (new boost::any(period)) ;
			shared_ptr<CMessage>  message (new CMessage(updateMouse, m_periodData ));

			timeModule->addPeriodicEvent(0, message, period);
		}
Esempio n. 8
0
		void DynamicObjectProxy::save()
		{
			DynamicObjectManager* pom = DynamicObjectManager::getInstancePtr();
			pom->save(m_self->getInstance(), m_self);
		}
Esempio n. 9
0
		DynamicObjectProxy::DynamicObjectProxy(string instanceName)
		{
			DynamicObjectManager* pom = DynamicObjectManager::getInstancePtr();
			m_self = pom->load(instanceName);
		}