Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Amr0

Member Since 19 Mar 2007
Offline Last Active Yesterday, 02:27 AM

Posts I've Made

In Topic: (In)efficiency of Event Handlers in a flexible game

04 May 2015 - 04:01 AM

Instead of a centralized event object, you can do something like this:

class Application
{
	Run()
	{
		InitializeSomeStuff();
		CreateWindow();
		
		TriggerEvent( this->onStartup );
		
		StartTheLoop();
	}
	
	// public variables (events)
	
	Event< bool, void> onStartup;
	Event< bool, int reason > onQuit;
	// ... etc
};


class SoundEngine
{
	void PlaySound( string sname );
	void PlayMusic( string sname );
	
	Event< void, Sound& > onStartPlaying;
	Event< void, Sound& > onFinishedPlaying;
	// ... etc
};

This way, an event is a variable, and you don't have to use enumerators or strings to identify events, and the different modules remain completely independent from one another.  You can add callbacks to an event (free functions or member variables). But as you mentioned in your previous thread, you have to be careful not to go overboard with this by making an event variable for every possible event that you can imagine another module may be interested in. Also, for callbacks that are object methods, you have to make sure that the object "overlasts" the event, or properly remove the callback when the object dies.

 

You can find such an implementation here: http://code-section.com/entry/2/c-a-simple-event-system

 

The performance of this will probably not be an issue since the callbacks are typically stored in a list, and triggering an event is a matter of iterating over the list elements.


In Topic: Free Web Hosting Area

12 April 2015 - 02:47 AM

Not meaning to sound harsh, but what do you mean by having "absolutely no budget"? Surely you can spare like $20 a year if you take your work and effort seriously? You can use a single site for multiple projects. Not having a method of payment (like a credit card or paypal account) is a different real issue in many countries (mine included).


In Topic: What Are You Working On

20 March 2015 - 06:53 AM

* learning how to use Maya so I can rig a simple character model for a game I'm building in my spare time


PM me for a free copy of MayaFPS if you'd like :) (see my signature)

In Topic: What Are You Working On

20 March 2015 - 06:10 AM

My latest. More coming soon.
 
e1145oiu3067skqzg.jpg


Could you at least provide basic information about your project? Share your enthusiasm!

In Topic: What Are You Working On

19 March 2015 - 02:32 PM

pac_ghost1.jpg

It's scaring me more than it's supposed to for some reason :(

PARTNERS