diff --git a/src/driver.cpp b/src/driver.cpp --- a/src/driver.cpp +++ b/src/driver.cpp @@ -165,33 +165,6 @@ Driver *DriverFactoryBase::SelectDriver( } /** - * 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 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( } /** + * 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 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 --- 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 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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 { +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 --- 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 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 --- 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 { +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 */