Rogue is a dungeon crawling video game first developed by Michael Toy and Glenn Wichman around 1980. It is generally credited with being the first "graphical" adventure game, and was a favorite on college Unix systems in the early to mid-1980s, in part due to the procedural generation of game content.

-- http://en.wikipedia.org/wiki/Rogue_(computer_game)

Thursday, May 6, 2010

Fighting Elegance

So instead of doing lesson 29 on top of what I have already done, I decided to clean up what I have already done to make things more uniform. My realization is that sprite sheets, animation sheets, and tile sheets (not to mention font sheets) all share a lot of similar properties. You take an image file and show only a section of it depending on external factors. So it is time to combine as many of the common attributes and methods in to a single class.

In the process I am looking at my wrapper functions and wondering how I can make them more generic. Right now I have the following functions:


SDL_Surface* load_image(std::string filename);
TTF_Font* load_font(std::string filename, int fontsize);
Mix_Music* load_music(std::string filename);
Mix_Chunk* load_chunk(std::string filename);


Each of these takes regular SDL load function for each data type, traps any errors in the process and then returns the pointer. Also each one adds the pointer type specific object array so that I can close all objects with one generic close_all_objects() function.

Here is my dilemma. What I have works, but it lacks a sort of elegance, that I think could be achieved. For example, I would like have a load_object() function that would determine the type of object and do the correct loads. One option is just to do a set of overloading functions like:


void load_object(SDL_Surface *surface_ptr,std::string filename);
void load_object(Mix_Music *music_ptr,std::string filename);


But this leaves me sort of where I was before. I just have this feeling that I can make the code more "elegant" and "concise" by generalizing even the common structure. I suspect I am falling in to the fairly common trap of "over-elegance." I am not adding any more functionality. Not mention I now spending more time anguishing over this little task, other than making actual progress on fundamental components for the games.

0 comments:

Post a Comment