Sign in to follow this  
ekrax

strange design problem

Recommended Posts

hey i have run into a wierd design problem, just to start i know how to solve this problem but i can't seem to solve it with "good code". ok in my design i have my main program file which includes all the windows and opengl code, withen this i create an instance of my engine class which is declared at the top of my main program file. then withen my main loop withen my main program file the instance of the engine class calls "run" which in turn calls everything else. the problem is that i'm trying to get rid of as many global variables as possible, so first of all instead of having all my texture images defined globably i store them withen the classes which display them. in this case textures used for my map are stored withen my map class, however i want to use a constructor to initialize my map class but to initialize my map class i need to give it a vector of textures (i pass a vector of textures from a function withen my main program). however i need to declare my map instance withen my engine class, so im forced to overload the map constructor so i can declare a map instance without passing any parameters to it, so now withen my engine init i have to call a map init function to set the variables, but it seems so eniffiecnt this way to have a blank constructor and then an init function. so does anyone have any suggestions on how to go about this? im trying not to have any global variables but i also dont want to have "bad code" in which constructors dont construct. i hope this sorta made sense. thanks

Share this post


Link to post
Share on other sites
A quick suggestion would be to have a singleton resource manager (which would allow for all sorts of features). Your map class would then take a resource id in the constructor, and request the matching texture from the manager when needed. The manager would either preload the texture during initialization, or at the first request.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this