From: Ingo Ruhnke Date: Sun, 6 Dec 2009 09:11:12 +0000 (+0000) Subject: Turned functions in video_systems.?pp into class VideoSystem X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=d78fbc721f773f410a373ca1f060dfe223cf45d2;p=supertux.git Turned functions in video_systems.?pp into class VideoSystem SVN-Revision: 6183 --- diff --git a/src/supertux/gameconfig.cpp b/src/supertux/gameconfig.cpp index d90ccc00d..59a2c0a7f 100644 --- a/src/supertux/gameconfig.cpp +++ b/src/supertux/gameconfig.cpp @@ -32,7 +32,7 @@ Config::Config() : aspect_size(0, 0), // auto detect magnification(1.0f), use_fullscreen(false), - video(AUTO_VIDEO), + video(VideoSystem::AUTO_VIDEO), try_vsync(true), show_fps(false), sound_enabled(true), @@ -70,7 +70,7 @@ Config::load() config_video_lisp->get("fullscreen", use_fullscreen); std::string video_string; config_video_lisp->get("video", video_string); - video = get_video_system(video_string); + video = VideoSystem::get_video_system(video_string); config_video_lisp->get("vsync", try_vsync); config_video_lisp->get("fullscreen_width", fullscreen_size.width); @@ -113,7 +113,7 @@ Config::save() writer.start_list("video"); writer.write("fullscreen", use_fullscreen); - writer.write("video", get_video_string(video)); + writer.write("video", VideoSystem::get_video_string(video)); writer.write("vsync", try_vsync); writer.write("fullscreen_width", fullscreen_size.width); diff --git a/src/supertux/gameconfig.hpp b/src/supertux/gameconfig.hpp index 2d708c4b7..527241fd2 100644 --- a/src/supertux/gameconfig.hpp +++ b/src/supertux/gameconfig.hpp @@ -43,7 +43,7 @@ public: float magnification; bool use_fullscreen; - VideoSystem video; + VideoSystem::Enum video; bool try_vsync; bool show_fps; bool sound_enabled; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 31d8f435c..0d88d3102 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -333,7 +333,7 @@ Main::parse_commandline(int argc, char** argv) } else { - g_config->video = get_video_system(argv[i]); + g_config->video = VideoSystem::get_video_system(argv[i]); } } else if(arg == "--show-fps") { g_config->show_fps = true; diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index d5a5be12b..e831fe063 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -73,8 +73,8 @@ DrawingContext::init_renderer() delete renderer; delete lightmap; - renderer = new_renderer(); - lightmap = new_lightmap(); + renderer = VideoSystem::new_renderer(); + lightmap = VideoSystem::new_lightmap(); } void diff --git a/src/video/surface.cpp b/src/video/surface.cpp index 926342e7e..c996e51bd 100644 --- a/src/video/surface.cpp +++ b/src/video/surface.cpp @@ -44,7 +44,7 @@ Surface::Surface(const std::string& file) : flipx(false) { texture->ref(); - surface_data = new_surface_data(*this); + surface_data = VideoSystem::new_surface_data(*this); } Surface::Surface(const std::string& file, const Rect& rect_) : @@ -54,7 +54,7 @@ Surface::Surface(const std::string& file, const Rect& rect_) : flipx(false) { texture->ref(); - surface_data = new_surface_data(*this); + surface_data = VideoSystem::new_surface_data(*this); } Surface::Surface(const Surface& rhs) : @@ -64,7 +64,7 @@ Surface::Surface(const Surface& rhs) : flipx(false) { texture->ref(); - surface_data = new_surface_data(*this); + surface_data = VideoSystem::new_surface_data(*this); } const Surface& @@ -79,7 +79,7 @@ Surface::operator=(const Surface& rhs) Surface::~Surface() { - free_surface_data(surface_data); + VideoSystem::free_surface_data(surface_data); texture->unref(); } diff --git a/src/video/texture_manager.cpp b/src/video/texture_manager.cpp index ca311ed31..5cb962be5 100644 --- a/src/video/texture_manager.cpp +++ b/src/video/texture_manager.cpp @@ -98,7 +98,7 @@ TextureManager::create_image_texture(const std::string& filename) Texture* result = 0; try { - result = new_texture(image); + result = VideoSystem::new_texture(image); result->set_filename(filename); } catch(...) { delete result; @@ -132,7 +132,7 @@ TextureManager::create_image_texture(const std::string& filename) Texture* result = 0; try { - result = new_texture(image); + result = VideoSystem::new_texture(image); result->set_filename("-dummy-texture-.png"); } catch(...) { delete result; diff --git a/src/video/video_systems.cpp b/src/video/video_systems.cpp index ab2dc8a47..c148990ae 100644 --- a/src/video/video_systems.cpp +++ b/src/video/video_systems.cpp @@ -30,7 +30,8 @@ #include "video/texture.hpp" #include "video/video_systems.hpp" -Renderer *new_renderer() +Renderer* +VideoSystem::new_renderer() { switch(g_config->video) { @@ -62,7 +63,8 @@ Renderer *new_renderer() } } -Lightmap *new_lightmap() +Lightmap* +VideoSystem::new_lightmap() { switch(g_config->video) { @@ -88,7 +90,8 @@ Lightmap *new_lightmap() } } -Texture *new_texture(SDL_Surface *image) +Texture* +VideoSystem::new_texture(SDL_Surface *image) { switch(g_config->video) { @@ -114,7 +117,8 @@ Texture *new_texture(SDL_Surface *image) } } -void *new_surface_data(const Surface &surface) +void* +VideoSystem::new_surface_data(const Surface &surface) { switch(g_config->video) { @@ -140,12 +144,15 @@ void *new_surface_data(const Surface &surface) } } -void free_surface_data(void *surface_data) +void +VideoSystem::free_surface_data(void *surface_data) { + // FIXME: this won't call any destructors delete reinterpret_cast(surface_data); } -VideoSystem get_video_system(const std::string &video) +VideoSystem::Enum +VideoSystem::get_video_system(const std::string &video) { if(video == "auto") { @@ -167,7 +174,8 @@ VideoSystem get_video_system(const std::string &video) } } -std::string get_video_string(VideoSystem video) +std::string +VideoSystem::get_video_string(VideoSystem::Enum video) { switch(video) { diff --git a/src/video/video_systems.hpp b/src/video/video_systems.hpp index c4e79b181..d15d06710 100644 --- a/src/video/video_systems.hpp +++ b/src/video/video_systems.hpp @@ -27,21 +27,32 @@ class Lightmap; class Texture; class Surface; -enum VideoSystem { - AUTO_VIDEO, - OPENGL, - PURE_SDL, - NUM_SYSTEMS +class VideoSystem +{ +public: + enum Enum { + AUTO_VIDEO, + OPENGL, + PURE_SDL, + NUM_SYSTEMS + }; + +public: + static Renderer* new_renderer(); + static Lightmap* new_lightmap(); + static Texture* new_texture(SDL_Surface *image); + static void* new_surface_data(const Surface &surface); + static void free_surface_data(void *surface_data); + + static Enum get_video_system(const std::string &video); + static std::string get_video_string(Enum video); + +private: + VideoSystem(); + VideoSystem(const VideoSystem&); + VideoSystem& operator=(const VideoSystem&); }; -Renderer* new_renderer(); -Lightmap* new_lightmap(); -Texture* new_texture(SDL_Surface *image); -void* new_surface_data(const Surface &surface); -void free_surface_data(void *surface_data); -VideoSystem get_video_system(const std::string &video); -std::string get_video_string(VideoSystem video); - #endif /* EOF */