Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualBosseBL

Posted 13 June 2012 - 05:29 AM

So I have started working on a light weight "engine" to help me design a game easy and got an idea that I want some guidance with.
To explain my idea, let us take an input manager for example. I would like to be able to store events and functions together in the following way:

class InputManager {

private:
map<int eventID, void(*function)()> eventActions

public:
void bind(int eventID, void(*function)());
void handleEvent();  
};

so that I can write the actual game code in the form of a bunch of functions that I can bind to an event. Then all I have to do is call the handleEvent(), and it will detect events and call their corresponding function.

What I don't get is how I would go by and organize the code so that all functions I write has access to all the resources like TextureManager, SoundManager, EntityManager.

Is this possible to do?
Is it a good way of coding games?
Can I do it better differently?

thx for all the answers and sorry for a somewhat misleading title.

#2BosseBL

Posted 13 June 2012 - 05:25 AM

So I have started working on a light weight "engine" to help me design a game easy and got an idea that I want some guidance with.
To explain my idea, let us take an input manager for example. I would like to be able to store events and functions together in the following way:

class InputManager {

private:
map<int eventID, void(*function)()

public:
void bind(int eventID, void(*function)());
void handleEvent();  
};

so that I can write the actual game code in the form of a bunch of functions that I can bind to an event. Then all I have to do is call the handleEvent(), and it will detect events and call their corresponding function.

What I don't get is how I would go by and organize the code so that all functions I write has access to all the resources like TextureManager, SoundManager, EntityManager.

Is this possible to do?
Is it a good way of coding games?
Can I do it better differently?

thx for all the answers and sorry for a somewhat misleading title.

#1BosseBL

Posted 13 June 2012 - 05:24 AM

So I have started working on a light weight "engine" to help me design a game easy and got an idea that I want some guidance with.
To explain my idea, let us take an input manager for example. I would like to be able to store events and functions together in the following way:

class InputManager {

private:
map<int eventID, void(*function)()

public:
void bind(int eventID, void(*function)());
void handleEvent();  
};

so that I can write the actual game code in the form of a bunch of functions that I can bind to an event. Then all I have to do is call the handleEvent(), and it will detect events and call their corresponding function.

What I don't get is how I would go by and organize the code so that all functions I write has access to all the resources like TextureManager, SoundManager, EntityManager.

Is this possible to do?
Is it a good way of coding games?
Can I do it better differently?

thx for all the answers.

PARTNERS