Jump to content

  • Log In with Google      Sign In   
  • Create Account

BosseBL

Member Since 13 Jun 2012
Offline Last Active Jun 21 2012 09:34 AM

Topics I've Started

Passing around void(*functions)() in light weight noob engine

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)()> 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.

PARTNERS