diff options
author | rubidium <rubidium@openttd.org> | 2013-11-25 14:26:46 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2013-11-25 14:26:46 +0000 |
commit | 6996b441d9d104bc6d7041b64362f4426425f600 (patch) | |
tree | 074989fd03a7f672e137423688c40d1efc466a95 /src | |
parent | a399fc667ce506abcdcfd853d1ad58f0bb8dbb4f (diff) | |
download | openttd-6996b441d9d104bc6d7041b64362f4426425f600.tar.xz |
(svn r26107) -Codechange/cleanup: remove some coding bloat and simplify the driver factory instatiations
Diffstat (limited to 'src')
-rw-r--r-- | src/driver.cpp | 51 | ||||
-rw-r--r-- | src/driver.h | 18 | ||||
-rw-r--r-- | src/music/allegro_m.h | 12 | ||||
-rw-r--r-- | src/music/bemidi.h | 8 | ||||
-rw-r--r-- | src/music/cocoa_m.h | 8 | ||||
-rw-r--r-- | src/music/dmusic.h | 8 | ||||
-rw-r--r-- | src/music/extmidi.h | 8 | ||||
-rw-r--r-- | src/music/libtimidity.h | 8 | ||||
-rw-r--r-- | src/music/music_driver.hpp | 19 | ||||
-rw-r--r-- | src/music/null_m.h | 8 | ||||
-rw-r--r-- | src/music/os2_m.h | 8 | ||||
-rw-r--r-- | src/music/qtmidi.h | 8 | ||||
-rw-r--r-- | src/music/win32_m.h | 8 | ||||
-rw-r--r-- | src/openttd.cpp | 8 | ||||
-rw-r--r-- | src/sound/allegro_s.h | 8 | ||||
-rw-r--r-- | src/sound/cocoa_s.h | 8 | ||||
-rw-r--r-- | src/sound/null_s.h | 8 | ||||
-rw-r--r-- | src/sound/sdl_s.h | 8 | ||||
-rw-r--r-- | src/sound/sound_driver.hpp | 19 | ||||
-rw-r--r-- | src/sound/win32_s.h | 8 | ||||
-rw-r--r-- | src/video/allegro_v.h | 8 | ||||
-rw-r--r-- | src/video/cocoa/cocoa_v.h | 8 | ||||
-rw-r--r-- | src/video/dedicated_v.h | 11 | ||||
-rw-r--r-- | src/video/null_v.h | 8 | ||||
-rw-r--r-- | src/video/sdl_v.h | 8 | ||||
-rw-r--r-- | src/video/video_driver.hpp | 19 | ||||
-rw-r--r-- | src/video/win32_v.h | 8 |
27 files changed, 101 insertions, 208 deletions
diff --git a/src/driver.cpp b/src/driver.cpp index 6419cdd4c..dd03e5e7b 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -165,33 +165,6 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type) } /** - * Register a driver internally, based on its name. - * @param name the name of the driver. - * @param type the type of driver to register - * @param priority the priority; how badly do we want this as default? - * @note an assert() will be trigger if 2 driver with the same name try to register. - */ -void DriverFactoryBase::RegisterDriver(const char *name, Driver::Type type, int priority) -{ - /* Don't register nameless Drivers */ - if (name == NULL) return; - - this->name = strdup(name); - this->type = type; - this->priority = priority; - - /* Prefix the name with driver type to make it unique */ - char buf[32]; - strecpy(buf, GetDriverTypeName(type), lastof(buf)); - strecpy(buf + 5, name, lastof(buf)); - - const char *longname = strdup(buf); - - std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this)); - assert(P.second); -} - -/** * Build a human readable list of available drivers, grouped by type. * @param p The buffer to write to. * @param last The last element in the buffer. @@ -219,12 +192,31 @@ char *DriverFactoryBase::GetDriversInfo(char *p, const char *last) } /** + * Construct a new DriverFactory. + * @param type The type of driver. + * @param priority The priority within the driver class. + * @param name The name of the driver. + * @param description A long-ish description of the driver. + */ +DriverFactoryBase::DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description) : + type(type), priority(priority), name(name), description(description) +{ + /* Prefix the name with driver type to make it unique */ + char buf[32]; + strecpy(buf, GetDriverTypeName(type), lastof(buf)); + strecpy(buf + 5, name, lastof(buf)); + + const char *longname = strdup(buf); + + std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this)); + assert(P.second); +} + +/** * Frees memory used for this->name */ DriverFactoryBase::~DriverFactoryBase() { - if (this->name == NULL) return; - /* Prefix the name with driver type to make it unique */ char buf[32]; strecpy(buf, GetDriverTypeName(type), lastof(buf)); @@ -239,5 +231,4 @@ DriverFactoryBase::~DriverFactoryBase() free(longname); if (GetDrivers().empty()) delete &GetDrivers(); - free(this->name); } diff --git a/src/driver.h b/src/driver.h index 10a6863bc..246180270 100644 --- a/src/driver.h +++ b/src/driver.h @@ -60,8 +60,9 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type) class DriverFactoryBase { private: Driver::Type type; ///< The type of driver. + int priority; ///< The priority of this factory. const char *name; ///< The name of the drivers of this factory. - int priority; ///< The priority of this factory. + const char *description; ///< The description of this driver. typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers; ///< Type for a map of drivers. @@ -97,15 +98,11 @@ private: } protected: - void RegisterDriver(const char *name, Driver::Type type, int priority); - -public: - DriverFactoryBase() : - name(NULL) - {} + DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description); virtual ~DriverFactoryBase(); +public: /** * Shuts down all active drivers */ @@ -124,13 +121,16 @@ public: * Get a nice description of the driver-class. * @return The description. */ - virtual const char *GetDescription() = 0; + const char *GetDescription() const + { + return this->description; + } /** * Create an instance of this driver-class. * @return The instance. */ - virtual Driver *CreateInstance() = 0; + virtual Driver *CreateInstance() const = 0; }; #endif /* DRIVER_H */ diff --git a/src/music/allegro_m.h b/src/music/allegro_m.h index 2160c396e..e7cade350 100644 --- a/src/music/allegro_m.h +++ b/src/music/allegro_m.h @@ -32,20 +32,18 @@ public: }; /** Factory for allegro's music player. */ -class FMusicDriver_Allegro: public MusicDriverFactory<FMusicDriver_Allegro> { +class FMusicDriver_Allegro : public DriverFactoryBase { public: #if !defined(WITH_SDL) && defined(WITH_ALLEGRO) /* If SDL is not compiled in but Allegro is, chances are quite big * that Allegro is going to be used. Then favour this sound driver * over extmidi because with extmidi we get crashes. */ - static const int priority = 9; + static const int PRIORITY = 9; #else - static const int priority = 2; + static const int PRIORITY = 2; #endif - - /* virtual */ const char *GetName() { return "allegro"; } - /* virtual */ const char *GetDescription() { return "Allegro MIDI Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_Allegro(); } + FMusicDriver_Allegro() : DriverFactoryBase(Driver::DT_MUSIC, PRIORITY, "allegro", "Allegro MIDI Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_Allegro(); } }; #endif /* MUSIC_ALLEGRO_H */ diff --git a/src/music/bemidi.h b/src/music/bemidi.h index 1b280e667..b261ec59f 100644 --- a/src/music/bemidi.h +++ b/src/music/bemidi.h @@ -32,12 +32,10 @@ public: }; /** Factory for the BeOS midi player. */ -class FMusicDriver_BeMidi: public MusicDriverFactory<FMusicDriver_BeMidi> { +class FMusicDriver_BeMidi : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "bemidi"; } - /* virtual */ const char *GetDescription() { return "BeOS MIDI Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_BeMidi(); } + FMusicDriver_BeMidi() : DriverFactoryBase(Driver::DT_MUSIC, 10, "bemidi", "BeOS MIDI Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_BeMidi(); } }; #endif /* MUSIC_BEMIDI_H */ diff --git a/src/music/cocoa_m.h b/src/music/cocoa_m.h index f3cff9db8..00bdc6b62 100644 --- a/src/music/cocoa_m.h +++ b/src/music/cocoa_m.h @@ -30,12 +30,10 @@ public: /* virtual */ const char *GetName() const { return "cocoa"; } }; -class FMusicDriver_Cocoa: public MusicDriverFactory<FMusicDriver_Cocoa> { +class FMusicDriver_Cocoa : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "cocoa"; } - /* virtual */ const char *GetDescription() { return "Cocoa MIDI Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_Cocoa(); } + FMusicDriver_Cocoa() : DriverFactoryBase(Driver::DT_MUSIC, 10, "cocoa", "Cocoa MIDI Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_Cocoa(); } }; #endif /* MUSIC_MACOSX_COCOA_H */ diff --git a/src/music/dmusic.h b/src/music/dmusic.h index 29eee8ed0..22a758daf 100644 --- a/src/music/dmusic.h +++ b/src/music/dmusic.h @@ -34,12 +34,10 @@ public: }; /** Factory for the DirectX music player. */ -class FMusicDriver_DMusic: public MusicDriverFactory<FMusicDriver_DMusic> { +class FMusicDriver_DMusic : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "dmusic"; } - /* virtual */ const char *GetDescription() { return "DirectMusic MIDI Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_DMusic(); } + FMusicDriver_DMusic() : DriverFactoryBase(Driver::DT_MUSIC, 10, "dmusic", "DirectMusic MIDI Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_DMusic(); } }; #endif /* MUSIC_DMUSIC_H */ diff --git a/src/music/extmidi.h b/src/music/extmidi.h index 1638c78f5..8f5dd31c7 100644 --- a/src/music/extmidi.h +++ b/src/music/extmidi.h @@ -38,12 +38,10 @@ public: /* virtual */ const char *GetName() const { return "extmidi"; } }; -class FMusicDriver_ExtMidi: public MusicDriverFactory<FMusicDriver_ExtMidi> { +class FMusicDriver_ExtMidi : public DriverFactoryBase { public: - static const int priority = 3; - /* virtual */ const char *GetName() { return "extmidi"; } - /* virtual */ const char *GetDescription() { return "External MIDI Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_ExtMidi(); } + FMusicDriver_ExtMidi() : DriverFactoryBase(Driver::DT_MUSIC, 3, "extmidi", "External MIDI Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_ExtMidi(); } }; #endif /* MUSIC_EXTERNAL_H */ diff --git a/src/music/libtimidity.h b/src/music/libtimidity.h index 4f9343619..7fc667e3a 100644 --- a/src/music/libtimidity.h +++ b/src/music/libtimidity.h @@ -32,12 +32,10 @@ public: }; /** Factory for the libtimidity driver. */ -class FMusicDriver_LibTimidity: public MusicDriverFactory<FMusicDriver_LibTimidity> { +class FMusicDriver_LibTimidity : public DriverFactoryBase { public: - static const int priority = 5; - /* virtual */ const char *GetName() { return "libtimidity"; } - /* virtual */ const char *GetDescription() { return "LibTimidity MIDI Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_LibTimidity(); } + FMusicDriver_LibTimidity() : DriverFactoryBase(Driver::DT_MUSIC, 5, "libtimidity", "LibTimidity MIDI Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_LibTimidity(); } }; #endif /* MUSIC_LIBTIMIDITY_H */ diff --git a/src/music/music_driver.hpp b/src/music/music_driver.hpp index 70a1e37a5..453d05102 100644 --- a/src/music/music_driver.hpp +++ b/src/music/music_driver.hpp @@ -41,25 +41,6 @@ public: virtual void SetVolume(byte vol) = 0; }; -/** Base of the factory for the music drivers. */ -class MusicDriverFactoryBase: public DriverFactoryBase { -}; - -/** - * Factory for the music drivers. - * @tparam T The type of the music factory to register. - */ -template <class T> -class MusicDriverFactory: public MusicDriverFactoryBase { -public: - MusicDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_MUSIC, ((T *)this)->priority); } - - /** - * Get the long, human readable, name for the Driver-class. - */ - const char *GetName(); -}; - extern MusicDriver *_music_driver; extern char *_ini_musicdriver; diff --git a/src/music/null_m.h b/src/music/null_m.h index babfd3775..d7b41d53e 100644 --- a/src/music/null_m.h +++ b/src/music/null_m.h @@ -32,12 +32,10 @@ public: }; /** Factory for the null music player. */ -class FMusicDriver_Null: public MusicDriverFactory<FMusicDriver_Null> { +class FMusicDriver_Null : public DriverFactoryBase { public: - static const int priority = 1; - /* virtual */ const char *GetName() { return "null"; } - /* virtual */ const char *GetDescription() { return "Null Music Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_Null(); } + FMusicDriver_Null() : DriverFactoryBase(Driver::DT_MUSIC, 1, "null", "Null Music Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_Null(); } }; #endif /* MUSIC_NULL_H */ diff --git a/src/music/os2_m.h b/src/music/os2_m.h index 054526e59..91ccf5a00 100644 --- a/src/music/os2_m.h +++ b/src/music/os2_m.h @@ -32,12 +32,10 @@ public: }; /** Factory for OS/2's music player. */ -class FMusicDriver_OS2: public MusicDriverFactory<FMusicDriver_OS2> { +class FMusicDriver_OS2 : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "os2"; } - /* virtual */ const char *GetDescription() { return "OS/2 Music Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_OS2(); } + FMusicDriver_OS2() : DriverFactoryBase(Driver::DT_MUSIC, 10, "os2", "OS/2 Music Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_OS2(); } }; #endif /* MUSIC_OS2_H */ diff --git a/src/music/qtmidi.h b/src/music/qtmidi.h index 806a3c196..d8ecaf1fe 100644 --- a/src/music/qtmidi.h +++ b/src/music/qtmidi.h @@ -30,12 +30,10 @@ public: /* virtual */ const char *GetName() const { return "qt"; } }; -class FMusicDriver_QtMidi: public MusicDriverFactory<FMusicDriver_QtMidi> { +class FMusicDriver_QtMidi : public DriverFactoryBase { public: - static const int priority = 5; - /* virtual */ const char *GetName() { return "qt"; } - /* virtual */ const char *GetDescription() { return "QuickTime MIDI Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_QtMidi(); } + FMusicDriver_QtMidi() : DriverFactoryBase(Driver::DT_MUSIC, 5, "qt", "QuickTime MIDI Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_QtMidi(); } }; #endif /* MUSIC_MACOSX_QUICKTIME_H */ diff --git a/src/music/win32_m.h b/src/music/win32_m.h index cf46fbc15..b59298d01 100644 --- a/src/music/win32_m.h +++ b/src/music/win32_m.h @@ -32,12 +32,10 @@ public: }; /** Factory for Windows' music player. */ -class FMusicDriver_Win32: public MusicDriverFactory<FMusicDriver_Win32> { +class FMusicDriver_Win32 : public DriverFactoryBase { public: - static const int priority = 5; - /* virtual */ const char *GetName() { return "win32"; } - /* virtual */ const char *GetDescription() { return "Win32 Music Driver"; } - /* virtual */ Driver *CreateInstance() { return new MusicDriver_Win32(); } + FMusicDriver_Win32() : DriverFactoryBase(Driver::DT_MUSIC, 5, "win32", "Win32 Music Driver") {} + /* virtual */ Driver *CreateInstance() const { return new MusicDriver_Win32(); } }; #endif /* MUSIC_WIN32_H */ diff --git a/src/openttd.cpp b/src/openttd.cpp index 98c6503bb..e878d0894 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -190,7 +190,7 @@ static void ShowHelp() p = BaseMusic::GetSetsList(p, lastof(buf)); /* List the drivers */ - p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf)); + p = DriverFactoryBase::GetDriversInfo(p, lastof(buf)); /* List the blitters */ p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf)); @@ -767,7 +767,7 @@ int openttd_main(int argc, char *argv[]) free(blitter); if (videodriver == NULL && _ini_videodriver != NULL) videodriver = strdup(_ini_videodriver); - _video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO); + _video_driver = (VideoDriver*)DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO); if (_video_driver == NULL) { StrEmpty(videodriver) ? usererror("Failed to autoprobe video driver") : @@ -833,7 +833,7 @@ int openttd_main(int argc, char *argv[]) free(music_set); if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = strdup(_ini_sounddriver); - _sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND); + _sound_driver = (SoundDriver*)DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND); if (_sound_driver == NULL) { StrEmpty(sounddriver) ? usererror("Failed to autoprobe sound driver") : @@ -842,7 +842,7 @@ int openttd_main(int argc, char *argv[]) free(sounddriver); if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = strdup(_ini_musicdriver); - _music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC); + _music_driver = (MusicDriver*)DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC); if (_music_driver == NULL) { StrEmpty(musicdriver) ? usererror("Failed to autoprobe music driver") : diff --git a/src/sound/allegro_s.h b/src/sound/allegro_s.h index 315bad2a8..269a1a030 100644 --- a/src/sound/allegro_s.h +++ b/src/sound/allegro_s.h @@ -26,12 +26,10 @@ public: }; /** Factory for the allegro sound driver. */ -class FSoundDriver_Allegro: public SoundDriverFactory<FSoundDriver_Allegro> { +class FSoundDriver_Allegro : public DriverFactoryBase { public: - static const int priority = 4; - /* virtual */ const char *GetName() { return "allegro"; } - /* virtual */ const char *GetDescription() { return "Allegro Sound Driver"; } - /* virtual */ Driver *CreateInstance() { return new SoundDriver_Allegro(); } + FSoundDriver_Allegro() : DriverFactoryBase(Driver::DT_SOUND, 4, "allegro", "Allegro Sound Driver") {} + /* virtual */ Driver *CreateInstance() const { return new SoundDriver_Allegro(); } }; #endif /* SOUND_ALLEGRO_H */ diff --git a/src/sound/cocoa_s.h b/src/sound/cocoa_s.h index 7492164c5..a85748bc2 100644 --- a/src/sound/cocoa_s.h +++ b/src/sound/cocoa_s.h @@ -22,12 +22,10 @@ public: /* virtual */ const char *GetName() const { return "cocoa"; } }; -class FSoundDriver_Cocoa: public SoundDriverFactory<FSoundDriver_Cocoa> { +class FSoundDriver_Cocoa : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "cocoa"; } - /* virtual */ const char *GetDescription() { return "Cocoa Sound Driver"; } - /* virtual */ Driver *CreateInstance() { return new SoundDriver_Cocoa(); } + FSoundDriver_Cocoa() : DriverFactoryBase(Driver::DT_SOUND, 10, "cocoa", "Cocoa Sound Driver") {} + /* virtual */ Driver *CreateInstance() const { return new SoundDriver_Cocoa(); } }; #endif /* SOUND_COCOA_H */ diff --git a/src/sound/null_s.h b/src/sound/null_s.h index 5951842cb..a2714d86d 100644 --- a/src/sound/null_s.h +++ b/src/sound/null_s.h @@ -24,12 +24,10 @@ public: }; /** Factory for the null sound driver. */ -class FSoundDriver_Null: public SoundDriverFactory<FSoundDriver_Null> { +class FSoundDriver_Null : public DriverFactoryBase { public: - static const int priority = 1; - /* virtual */ const char *GetName() { return "null"; } - /* virtual */ const char *GetDescription() { return "Null Sound Driver"; } - /* virtual */ Driver *CreateInstance() { return new SoundDriver_Null(); } + FSoundDriver_Null() : DriverFactoryBase(Driver::DT_SOUND, 1, "null", "Null Sound Driver") {} + /* virtual */ Driver *CreateInstance() const { return new SoundDriver_Null(); } }; #endif /* SOUND_NULL_H */ diff --git a/src/sound/sdl_s.h b/src/sound/sdl_s.h index 6733ee6a7..60cf11838 100644 --- a/src/sound/sdl_s.h +++ b/src/sound/sdl_s.h @@ -24,12 +24,10 @@ public: }; /** Factory for the SDL sound driver. */ -class FSoundDriver_SDL: public SoundDriverFactory<FSoundDriver_SDL> { +class FSoundDriver_SDL : public DriverFactoryBase { public: - static const int priority = 5; - /* virtual */ const char *GetName() { return "sdl"; } - /* virtual */ const char *GetDescription() { return "SDL Sound Driver"; } - /* virtual */ Driver *CreateInstance() { return new SoundDriver_SDL(); } + FSoundDriver_SDL() : DriverFactoryBase(Driver::DT_SOUND, 5, "sdl", "SDL Sound Driver") {} + /* virtual */ Driver *CreateInstance() const { return new SoundDriver_SDL(); } }; #endif /* SOUND_SDL_H */ diff --git a/src/sound/sound_driver.hpp b/src/sound/sound_driver.hpp index 56664e6ad..badfabd93 100644 --- a/src/sound/sound_driver.hpp +++ b/src/sound/sound_driver.hpp @@ -21,25 +21,6 @@ public: virtual void MainLoop() {} }; -/** Base of the factory for the sound drivers. */ -class SoundDriverFactoryBase: public DriverFactoryBase { -}; - -/** - * Factory for the sound drivers. - * @tparam T The type of the sound factory to register. - */ -template <class T> -class SoundDriverFactory: public SoundDriverFactoryBase { -public: - SoundDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_SOUND, ((T *)this)->priority); } - - /** - * Get the long, human readable, name for the Driver-class. - */ - const char *GetName(); -}; - extern SoundDriver *_sound_driver; extern char *_ini_sounddriver; diff --git a/src/sound/win32_s.h b/src/sound/win32_s.h index 03af04a53..f76849b15 100644 --- a/src/sound/win32_s.h +++ b/src/sound/win32_s.h @@ -24,12 +24,10 @@ public: }; /** Factory for the sound driver for Windows. */ -class FSoundDriver_Win32: public SoundDriverFactory<FSoundDriver_Win32> { +class FSoundDriver_Win32 : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "win32"; } - /* virtual */ const char *GetDescription() { return "Win32 WaveOut Driver"; } - /* virtual */ Driver *CreateInstance() { return new SoundDriver_Win32(); } + FSoundDriver_Win32() : DriverFactoryBase(Driver::DT_SOUND, 10, "win32", "Win32 WaveOut Sound Driver") {} + /* virtual */ Driver *CreateInstance() const { return new SoundDriver_Win32(); } }; #endif /* SOUND_WIN32_H */ diff --git a/src/video/allegro_v.h b/src/video/allegro_v.h index da95269ce..d455bb515 100644 --- a/src/video/allegro_v.h +++ b/src/video/allegro_v.h @@ -37,12 +37,10 @@ public: }; /** Factory for the allegro video driver. */ -class FVideoDriver_Allegro: public VideoDriverFactory<FVideoDriver_Allegro> { +class FVideoDriver_Allegro : public DriverFactoryBase { public: - static const int priority = 4; - /* virtual */ const char *GetName() { return "allegro"; } - /* virtual */ const char *GetDescription() { return "Allegro Video Driver"; } - /* virtual */ Driver *CreateInstance() { return new VideoDriver_Allegro(); } + FVideoDriver_Allegro() : DriverFactoryBase(Driver::DT_VIDEO, 4, "allegro", "Allegro Video Driver") {} + /* virtual */ Driver *CreateInstance() const { return new VideoDriver_Allegro(); } }; #endif /* VIDEO_ALLEGRO_H */ diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h index e70a33b15..491efa94b 100644 --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -61,12 +61,10 @@ public: /* virtual */ const char *GetName() const { return "cocoa"; } }; -class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> { +class FVideoDriver_Cocoa : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "cocoa"; } - /* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; } - /* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); } + FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {} + /* virtual */ Driver *CreateInstance() const { return new VideoDriver_Cocoa(); } }; diff --git a/src/video/dedicated_v.h b/src/video/dedicated_v.h index 7d449d159..24d647fef 100644 --- a/src/video/dedicated_v.h +++ b/src/video/dedicated_v.h @@ -33,18 +33,17 @@ public: }; /** Factory for the dedicated server video driver. */ -class FVideoDriver_Dedicated: public VideoDriverFactory<FVideoDriver_Dedicated> { +class FVideoDriver_Dedicated : public DriverFactoryBase { public: #ifdef DEDICATED /* Automatically select this dedicated driver when making a dedicated * server build. */ - static const int priority = 10; + static const int PRIORITY = 10; #else - static const int priority = 0; + static const int PRIORITY = 0; #endif - /* virtual */ const char *GetName() { return "dedicated"; } - /* virtual */ const char *GetDescription() { return "Dedicated Video Driver"; } - /* virtual */ Driver *CreateInstance() { return new VideoDriver_Dedicated(); } + FVideoDriver_Dedicated() : DriverFactoryBase(Driver::DT_VIDEO, PRIORITY, "dedicated", "Dedicated Video Driver") {} + /* virtual */ Driver *CreateInstance() const { return new VideoDriver_Dedicated(); } }; #endif /* VIDEO_DEDICATED_H */ diff --git a/src/video/null_v.h b/src/video/null_v.h index 9bc26c4ef..69563f5c4 100644 --- a/src/video/null_v.h +++ b/src/video/null_v.h @@ -36,12 +36,10 @@ public: }; /** Factory the null video driver. */ -class FVideoDriver_Null: public VideoDriverFactory<FVideoDriver_Null> { +class FVideoDriver_Null : public DriverFactoryBase { public: - static const int priority = 0; - /* virtual */ const char *GetName() { return "null"; } - /* virtual */ const char *GetDescription() { return "Null Video Driver"; } - /* virtual */ Driver *CreateInstance() { return new VideoDriver_Null(); } + FVideoDriver_Null() : DriverFactoryBase(Driver::DT_VIDEO, 0, "null", "Null Video Driver") {} + /* virtual */ Driver *CreateInstance() const { return new VideoDriver_Null(); } }; #endif /* VIDEO_NULL_H */ diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h index 66f8bf856..523129309 100644 --- a/src/video/sdl_v.h +++ b/src/video/sdl_v.h @@ -41,12 +41,10 @@ private: }; /** Factory for the SDL video driver. */ -class FVideoDriver_SDL: public VideoDriverFactory<FVideoDriver_SDL> { +class FVideoDriver_SDL : public DriverFactoryBase { public: - static const int priority = 5; - /* virtual */ const char *GetName() { return "sdl"; } - /* virtual */ const char *GetDescription() { return "SDL Video Driver"; } - /* virtual */ Driver *CreateInstance() { return new VideoDriver_SDL(); } + FVideoDriver_SDL() : DriverFactoryBase(Driver::DT_VIDEO, 5, "sdl", "SDL Video Driver") {} + /* virtual */ Driver *CreateInstance() const { return new VideoDriver_SDL(); } }; #endif /* VIDEO_SDL_H */ diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index d8249b1f7..3a3b4c79e 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -80,25 +80,6 @@ public: virtual void EditBoxLostFocus() {} }; -/** Base of the factory for the video drivers. */ -class VideoDriverFactoryBase: public DriverFactoryBase { -}; - -/** - * Factory for the video drivers. - * @tparam T The type of the video factory to register. - */ -template <class T> -class VideoDriverFactory: public VideoDriverFactoryBase { -public: - VideoDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_VIDEO, ((T *)this)->priority); } - - /** - * Get the long, human readable, name for the Driver-class. - */ - const char *GetName(); -}; - extern VideoDriver *_video_driver; extern char *_ini_videodriver; extern int _num_resolutions; diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 6be60c230..f7c289009 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -41,12 +41,10 @@ public: }; /** The factory for Windows' video driver. */ -class FVideoDriver_Win32: public VideoDriverFactory<FVideoDriver_Win32> { +class FVideoDriver_Win32 : public DriverFactoryBase { public: - static const int priority = 10; - /* virtual */ const char *GetName() { return "win32"; } - /* virtual */ const char *GetDescription() { return "Win32 GDI Video Driver"; } - /* virtual */ Driver *CreateInstance() { return new VideoDriver_Win32(); } + FVideoDriver_Win32() : DriverFactoryBase(Driver::DT_VIDEO, 10, "win32", "Win32 GDI Video Driver") {} + /* virtual */ Driver *CreateInstance() const { return new VideoDriver_Win32(); } }; #endif /* VIDEO_WIN32_H */ |