Dilemma with SDL screen surface
Posted: Sat May 08, 2010 11:07 am
Hey Everyone,
So lately I've been running into a design problem that I can't seem to figure out a solution for. In all the games I create with SDL/C++ I'm never able determine the best way to implement my 'screen' into the code so that it makes for a well-organized and easily accessible setup. In my very first game I had a set of header and source files called 'globals' and ended up instantiating an SDL_Surface* screen within that and including it in every source file that needed it. UGLY!!! My solution the 2nd was to instantiate the screen within the main() and simply pass a reference to it into any function that needed to draw to the buffer. At first this was ok because I had like one or two functions calling all the drawing, but over time I kept needing more and more access to the screen until eventually I had a shitload of screen arguments getting tossed around like a salad. Once again, UGGGGLLYY!!!!
So here I am...stuck. I was hoping someone might be able to point me in the general direction of what might be a better (not necessarily the best) design pattern to follow here. I remember a couple months ago there was a thread about creating the screen as a singleton but that seemed to get shot down as another bad design. Thanks in advance for any help.
-hurst
So lately I've been running into a design problem that I can't seem to figure out a solution for. In all the games I create with SDL/C++ I'm never able determine the best way to implement my 'screen' into the code so that it makes for a well-organized and easily accessible setup. In my very first game I had a set of header and source files called 'globals' and ended up instantiating an SDL_Surface* screen within that and including it in every source file that needed it. UGLY!!! My solution the 2nd was to instantiate the screen within the main() and simply pass a reference to it into any function that needed to draw to the buffer. At first this was ok because I had like one or two functions calling all the drawing, but over time I kept needing more and more access to the screen until eventually I had a shitload of screen arguments getting tossed around like a salad. Once again, UGGGGLLYY!!!!
So here I am...stuck. I was hoping someone might be able to point me in the general direction of what might be a better (not necessarily the best) design pattern to follow here. I remember a couple months ago there was a thread about creating the screen as a singleton but that seemed to get shot down as another bad design. Thanks in advance for any help.
-hurst