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