mirror of https://github.com/OpenTTD/OpenTTD
(svn r26107) -Codechange/cleanup: remove some coding bloat and simplify the driver factory instatiations
parent
a399fc667c
commit
6996b441d9
|
@ -164,33 +164,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.
|
* Build a human readable list of available drivers, grouped by type.
|
||||||
* @param p The buffer to write to.
|
* @param p The buffer to write to.
|
||||||
|
@ -218,13 +191,32 @@ char *DriverFactoryBase::GetDriversInfo(char *p, const char *last)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Frees memory used for this->name
|
||||||
*/
|
*/
|
||||||
DriverFactoryBase::~DriverFactoryBase()
|
DriverFactoryBase::~DriverFactoryBase()
|
||||||
{
|
{
|
||||||
if (this->name == NULL) return;
|
|
||||||
|
|
||||||
/* Prefix the name with driver type to make it unique */
|
/* Prefix the name with driver type to make it unique */
|
||||||
char buf[32];
|
char buf[32];
|
||||||
strecpy(buf, GetDriverTypeName(type), lastof(buf));
|
strecpy(buf, GetDriverTypeName(type), lastof(buf));
|
||||||
|
@ -239,5 +231,4 @@ DriverFactoryBase::~DriverFactoryBase()
|
||||||
free(longname);
|
free(longname);
|
||||||
|
|
||||||
if (GetDrivers().empty()) delete &GetDrivers();
|
if (GetDrivers().empty()) delete &GetDrivers();
|
||||||
free(this->name);
|
|
||||||
}
|
}
|
||||||
|
|
18
src/driver.h
18
src/driver.h
|
@ -60,8 +60,9 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type)
|
||||||
class DriverFactoryBase {
|
class DriverFactoryBase {
|
||||||
private:
|
private:
|
||||||
Driver::Type type; ///< The type of driver.
|
Driver::Type type; ///< The type of driver.
|
||||||
const char *name; ///< The name of the drivers of this factory.
|
|
||||||
int priority; ///< The priority of this factory.
|
int priority; ///< The priority of this factory.
|
||||||
|
const char *name; ///< The name of the drivers 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.
|
typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers; ///< Type for a map of drivers.
|
||||||
|
|
||||||
|
@ -97,15 +98,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void RegisterDriver(const char *name, Driver::Type type, int priority);
|
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description);
|
||||||
|
|
||||||
public:
|
|
||||||
DriverFactoryBase() :
|
|
||||||
name(NULL)
|
|
||||||
{}
|
|
||||||
|
|
||||||
virtual ~DriverFactoryBase();
|
virtual ~DriverFactoryBase();
|
||||||
|
|
||||||
|
public:
|
||||||
/**
|
/**
|
||||||
* Shuts down all active drivers
|
* Shuts down all active drivers
|
||||||
*/
|
*/
|
||||||
|
@ -124,13 +121,16 @@ public:
|
||||||
* Get a nice description of the driver-class.
|
* Get a nice description of the driver-class.
|
||||||
* @return The description.
|
* @return The description.
|
||||||
*/
|
*/
|
||||||
virtual const char *GetDescription() = 0;
|
const char *GetDescription() const
|
||||||
|
{
|
||||||
|
return this->description;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of this driver-class.
|
* Create an instance of this driver-class.
|
||||||
* @return The instance.
|
* @return The instance.
|
||||||
*/
|
*/
|
||||||
virtual Driver *CreateInstance() = 0;
|
virtual Driver *CreateInstance() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DRIVER_H */
|
#endif /* DRIVER_H */
|
||||||
|
|
|
@ -32,20 +32,18 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for allegro's music player. */
|
/** Factory for allegro's music player. */
|
||||||
class FMusicDriver_Allegro: public MusicDriverFactory<FMusicDriver_Allegro> {
|
class FMusicDriver_Allegro : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
#if !defined(WITH_SDL) && defined(WITH_ALLEGRO)
|
#if !defined(WITH_SDL) && defined(WITH_ALLEGRO)
|
||||||
/* If SDL is not compiled in but Allegro is, chances are quite big
|
/* 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
|
* that Allegro is going to be used. Then favour this sound driver
|
||||||
* over extmidi because with extmidi we get crashes. */
|
* over extmidi because with extmidi we get crashes. */
|
||||||
static const int priority = 9;
|
static const int PRIORITY = 9;
|
||||||
#else
|
#else
|
||||||
static const int priority = 2;
|
static const int PRIORITY = 2;
|
||||||
#endif
|
#endif
|
||||||
|
FMusicDriver_Allegro() : DriverFactoryBase(Driver::DT_MUSIC, PRIORITY, "allegro", "Allegro MIDI Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "allegro"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_Allegro(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Allegro MIDI Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_Allegro(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_ALLEGRO_H */
|
#endif /* MUSIC_ALLEGRO_H */
|
||||||
|
|
|
@ -32,12 +32,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the BeOS midi player. */
|
/** Factory for the BeOS midi player. */
|
||||||
class FMusicDriver_BeMidi: public MusicDriverFactory<FMusicDriver_BeMidi> {
|
class FMusicDriver_BeMidi : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FMusicDriver_BeMidi() : DriverFactoryBase(Driver::DT_MUSIC, 10, "bemidi", "BeOS MIDI Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "bemidi"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_BeMidi(); }
|
||||||
/* virtual */ const char *GetDescription() { return "BeOS MIDI Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_BeMidi(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_BEMIDI_H */
|
#endif /* MUSIC_BEMIDI_H */
|
||||||
|
|
|
@ -30,12 +30,10 @@ public:
|
||||||
/* virtual */ const char *GetName() const { return "cocoa"; }
|
/* virtual */ const char *GetName() const { return "cocoa"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class FMusicDriver_Cocoa: public MusicDriverFactory<FMusicDriver_Cocoa> {
|
class FMusicDriver_Cocoa : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FMusicDriver_Cocoa() : DriverFactoryBase(Driver::DT_MUSIC, 10, "cocoa", "Cocoa MIDI Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "cocoa"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_Cocoa(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Cocoa MIDI Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_Cocoa(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_MACOSX_COCOA_H */
|
#endif /* MUSIC_MACOSX_COCOA_H */
|
||||||
|
|
|
@ -34,12 +34,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the DirectX music player. */
|
/** Factory for the DirectX music player. */
|
||||||
class FMusicDriver_DMusic: public MusicDriverFactory<FMusicDriver_DMusic> {
|
class FMusicDriver_DMusic : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FMusicDriver_DMusic() : DriverFactoryBase(Driver::DT_MUSIC, 10, "dmusic", "DirectMusic MIDI Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "dmusic"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_DMusic(); }
|
||||||
/* virtual */ const char *GetDescription() { return "DirectMusic MIDI Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_DMusic(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_DMUSIC_H */
|
#endif /* MUSIC_DMUSIC_H */
|
||||||
|
|
|
@ -38,12 +38,10 @@ public:
|
||||||
/* virtual */ const char *GetName() const { return "extmidi"; }
|
/* virtual */ const char *GetName() const { return "extmidi"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class FMusicDriver_ExtMidi: public MusicDriverFactory<FMusicDriver_ExtMidi> {
|
class FMusicDriver_ExtMidi : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 3;
|
FMusicDriver_ExtMidi() : DriverFactoryBase(Driver::DT_MUSIC, 3, "extmidi", "External MIDI Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "extmidi"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_ExtMidi(); }
|
||||||
/* virtual */ const char *GetDescription() { return "External MIDI Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_ExtMidi(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_EXTERNAL_H */
|
#endif /* MUSIC_EXTERNAL_H */
|
||||||
|
|
|
@ -32,12 +32,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the libtimidity driver. */
|
/** Factory for the libtimidity driver. */
|
||||||
class FMusicDriver_LibTimidity: public MusicDriverFactory<FMusicDriver_LibTimidity> {
|
class FMusicDriver_LibTimidity : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 5;
|
FMusicDriver_LibTimidity() : DriverFactoryBase(Driver::DT_MUSIC, 5, "libtimidity", "LibTimidity MIDI Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "libtimidity"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_LibTimidity(); }
|
||||||
/* virtual */ const char *GetDescription() { return "LibTimidity MIDI Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_LibTimidity(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_LIBTIMIDITY_H */
|
#endif /* MUSIC_LIBTIMIDITY_H */
|
||||||
|
|
|
@ -41,25 +41,6 @@ public:
|
||||||
virtual void SetVolume(byte vol) = 0;
|
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 MusicDriver *_music_driver;
|
||||||
extern char *_ini_musicdriver;
|
extern char *_ini_musicdriver;
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the null music player. */
|
/** Factory for the null music player. */
|
||||||
class FMusicDriver_Null: public MusicDriverFactory<FMusicDriver_Null> {
|
class FMusicDriver_Null : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 1;
|
FMusicDriver_Null() : DriverFactoryBase(Driver::DT_MUSIC, 1, "null", "Null Music Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "null"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_Null(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Null Music Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_Null(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_NULL_H */
|
#endif /* MUSIC_NULL_H */
|
||||||
|
|
|
@ -32,12 +32,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for OS/2's music player. */
|
/** Factory for OS/2's music player. */
|
||||||
class FMusicDriver_OS2: public MusicDriverFactory<FMusicDriver_OS2> {
|
class FMusicDriver_OS2 : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FMusicDriver_OS2() : DriverFactoryBase(Driver::DT_MUSIC, 10, "os2", "OS/2 Music Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "os2"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_OS2(); }
|
||||||
/* virtual */ const char *GetDescription() { return "OS/2 Music Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_OS2(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_OS2_H */
|
#endif /* MUSIC_OS2_H */
|
||||||
|
|
|
@ -30,12 +30,10 @@ public:
|
||||||
/* virtual */ const char *GetName() const { return "qt"; }
|
/* virtual */ const char *GetName() const { return "qt"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class FMusicDriver_QtMidi: public MusicDriverFactory<FMusicDriver_QtMidi> {
|
class FMusicDriver_QtMidi : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 5;
|
FMusicDriver_QtMidi() : DriverFactoryBase(Driver::DT_MUSIC, 5, "qt", "QuickTime MIDI Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "qt"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_QtMidi(); }
|
||||||
/* virtual */ const char *GetDescription() { return "QuickTime MIDI Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_QtMidi(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_MACOSX_QUICKTIME_H */
|
#endif /* MUSIC_MACOSX_QUICKTIME_H */
|
||||||
|
|
|
@ -32,12 +32,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for Windows' music player. */
|
/** Factory for Windows' music player. */
|
||||||
class FMusicDriver_Win32: public MusicDriverFactory<FMusicDriver_Win32> {
|
class FMusicDriver_Win32 : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 5;
|
FMusicDriver_Win32() : DriverFactoryBase(Driver::DT_MUSIC, 5, "win32", "Win32 Music Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "win32"; }
|
/* virtual */ Driver *CreateInstance() const { return new MusicDriver_Win32(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Win32 Music Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new MusicDriver_Win32(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MUSIC_WIN32_H */
|
#endif /* MUSIC_WIN32_H */
|
||||||
|
|
|
@ -190,7 +190,7 @@ static void ShowHelp()
|
||||||
p = BaseMusic::GetSetsList(p, lastof(buf));
|
p = BaseMusic::GetSetsList(p, lastof(buf));
|
||||||
|
|
||||||
/* List the drivers */
|
/* List the drivers */
|
||||||
p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf));
|
p = DriverFactoryBase::GetDriversInfo(p, lastof(buf));
|
||||||
|
|
||||||
/* List the blitters */
|
/* List the blitters */
|
||||||
p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf));
|
p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf));
|
||||||
|
@ -767,7 +767,7 @@ int openttd_main(int argc, char *argv[])
|
||||||
free(blitter);
|
free(blitter);
|
||||||
|
|
||||||
if (videodriver == NULL && _ini_videodriver != NULL) videodriver = strdup(_ini_videodriver);
|
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) {
|
if (_video_driver == NULL) {
|
||||||
StrEmpty(videodriver) ?
|
StrEmpty(videodriver) ?
|
||||||
usererror("Failed to autoprobe video driver") :
|
usererror("Failed to autoprobe video driver") :
|
||||||
|
@ -833,7 +833,7 @@ int openttd_main(int argc, char *argv[])
|
||||||
free(music_set);
|
free(music_set);
|
||||||
|
|
||||||
if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = strdup(_ini_sounddriver);
|
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) {
|
if (_sound_driver == NULL) {
|
||||||
StrEmpty(sounddriver) ?
|
StrEmpty(sounddriver) ?
|
||||||
usererror("Failed to autoprobe sound driver") :
|
usererror("Failed to autoprobe sound driver") :
|
||||||
|
@ -842,7 +842,7 @@ int openttd_main(int argc, char *argv[])
|
||||||
free(sounddriver);
|
free(sounddriver);
|
||||||
|
|
||||||
if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = strdup(_ini_musicdriver);
|
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) {
|
if (_music_driver == NULL) {
|
||||||
StrEmpty(musicdriver) ?
|
StrEmpty(musicdriver) ?
|
||||||
usererror("Failed to autoprobe music driver") :
|
usererror("Failed to autoprobe music driver") :
|
||||||
|
|
|
@ -26,12 +26,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the allegro sound driver. */
|
/** Factory for the allegro sound driver. */
|
||||||
class FSoundDriver_Allegro: public SoundDriverFactory<FSoundDriver_Allegro> {
|
class FSoundDriver_Allegro : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 4;
|
FSoundDriver_Allegro() : DriverFactoryBase(Driver::DT_SOUND, 4, "allegro", "Allegro Sound Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "allegro"; }
|
/* virtual */ Driver *CreateInstance() const { return new SoundDriver_Allegro(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Allegro Sound Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new SoundDriver_Allegro(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SOUND_ALLEGRO_H */
|
#endif /* SOUND_ALLEGRO_H */
|
||||||
|
|
|
@ -22,12 +22,10 @@ public:
|
||||||
/* virtual */ const char *GetName() const { return "cocoa"; }
|
/* virtual */ const char *GetName() const { return "cocoa"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class FSoundDriver_Cocoa: public SoundDriverFactory<FSoundDriver_Cocoa> {
|
class FSoundDriver_Cocoa : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FSoundDriver_Cocoa() : DriverFactoryBase(Driver::DT_SOUND, 10, "cocoa", "Cocoa Sound Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "cocoa"; }
|
/* virtual */ Driver *CreateInstance() const { return new SoundDriver_Cocoa(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Cocoa Sound Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new SoundDriver_Cocoa(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SOUND_COCOA_H */
|
#endif /* SOUND_COCOA_H */
|
||||||
|
|
|
@ -24,12 +24,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the null sound driver. */
|
/** Factory for the null sound driver. */
|
||||||
class FSoundDriver_Null: public SoundDriverFactory<FSoundDriver_Null> {
|
class FSoundDriver_Null : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 1;
|
FSoundDriver_Null() : DriverFactoryBase(Driver::DT_SOUND, 1, "null", "Null Sound Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "null"; }
|
/* virtual */ Driver *CreateInstance() const { return new SoundDriver_Null(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Null Sound Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new SoundDriver_Null(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SOUND_NULL_H */
|
#endif /* SOUND_NULL_H */
|
||||||
|
|
|
@ -24,12 +24,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the SDL sound driver. */
|
/** Factory for the SDL sound driver. */
|
||||||
class FSoundDriver_SDL: public SoundDriverFactory<FSoundDriver_SDL> {
|
class FSoundDriver_SDL : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 5;
|
FSoundDriver_SDL() : DriverFactoryBase(Driver::DT_SOUND, 5, "sdl", "SDL Sound Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "sdl"; }
|
/* virtual */ Driver *CreateInstance() const { return new SoundDriver_SDL(); }
|
||||||
/* virtual */ const char *GetDescription() { return "SDL Sound Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new SoundDriver_SDL(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SOUND_SDL_H */
|
#endif /* SOUND_SDL_H */
|
||||||
|
|
|
@ -21,25 +21,6 @@ public:
|
||||||
virtual void MainLoop() {}
|
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 SoundDriver *_sound_driver;
|
||||||
extern char *_ini_sounddriver;
|
extern char *_ini_sounddriver;
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the sound driver for Windows. */
|
/** Factory for the sound driver for Windows. */
|
||||||
class FSoundDriver_Win32: public SoundDriverFactory<FSoundDriver_Win32> {
|
class FSoundDriver_Win32 : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FSoundDriver_Win32() : DriverFactoryBase(Driver::DT_SOUND, 10, "win32", "Win32 WaveOut Sound Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "win32"; }
|
/* virtual */ Driver *CreateInstance() const { return new SoundDriver_Win32(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Win32 WaveOut Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new SoundDriver_Win32(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SOUND_WIN32_H */
|
#endif /* SOUND_WIN32_H */
|
||||||
|
|
|
@ -37,12 +37,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the allegro video driver. */
|
/** Factory for the allegro video driver. */
|
||||||
class FVideoDriver_Allegro: public VideoDriverFactory<FVideoDriver_Allegro> {
|
class FVideoDriver_Allegro : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 4;
|
FVideoDriver_Allegro() : DriverFactoryBase(Driver::DT_VIDEO, 4, "allegro", "Allegro Video Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "allegro"; }
|
/* virtual */ Driver *CreateInstance() const { return new VideoDriver_Allegro(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Allegro Video Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Allegro(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VIDEO_ALLEGRO_H */
|
#endif /* VIDEO_ALLEGRO_H */
|
||||||
|
|
|
@ -61,12 +61,10 @@ public:
|
||||||
/* virtual */ const char *GetName() const { return "cocoa"; }
|
/* virtual */ const char *GetName() const { return "cocoa"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
|
class FVideoDriver_Cocoa : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "cocoa"; }
|
/* virtual */ Driver *CreateInstance() const { return new VideoDriver_Cocoa(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,18 +33,17 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the dedicated server video driver. */
|
/** Factory for the dedicated server video driver. */
|
||||||
class FVideoDriver_Dedicated: public VideoDriverFactory<FVideoDriver_Dedicated> {
|
class FVideoDriver_Dedicated : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
#ifdef DEDICATED
|
#ifdef DEDICATED
|
||||||
/* Automatically select this dedicated driver when making a dedicated
|
/* Automatically select this dedicated driver when making a dedicated
|
||||||
* server build. */
|
* server build. */
|
||||||
static const int priority = 10;
|
static const int PRIORITY = 10;
|
||||||
#else
|
#else
|
||||||
static const int priority = 0;
|
static const int PRIORITY = 0;
|
||||||
#endif
|
#endif
|
||||||
/* virtual */ const char *GetName() { return "dedicated"; }
|
FVideoDriver_Dedicated() : DriverFactoryBase(Driver::DT_VIDEO, PRIORITY, "dedicated", "Dedicated Video Driver") {}
|
||||||
/* virtual */ const char *GetDescription() { return "Dedicated Video Driver"; }
|
/* virtual */ Driver *CreateInstance() const { return new VideoDriver_Dedicated(); }
|
||||||
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Dedicated(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VIDEO_DEDICATED_H */
|
#endif /* VIDEO_DEDICATED_H */
|
||||||
|
|
|
@ -36,12 +36,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory the null video driver. */
|
/** Factory the null video driver. */
|
||||||
class FVideoDriver_Null: public VideoDriverFactory<FVideoDriver_Null> {
|
class FVideoDriver_Null : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 0;
|
FVideoDriver_Null() : DriverFactoryBase(Driver::DT_VIDEO, 0, "null", "Null Video Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "null"; }
|
/* virtual */ Driver *CreateInstance() const { return new VideoDriver_Null(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Null Video Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Null(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VIDEO_NULL_H */
|
#endif /* VIDEO_NULL_H */
|
||||||
|
|
|
@ -41,12 +41,10 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the SDL video driver. */
|
/** Factory for the SDL video driver. */
|
||||||
class FVideoDriver_SDL: public VideoDriverFactory<FVideoDriver_SDL> {
|
class FVideoDriver_SDL : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 5;
|
FVideoDriver_SDL() : DriverFactoryBase(Driver::DT_VIDEO, 5, "sdl", "SDL Video Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "sdl"; }
|
/* virtual */ Driver *CreateInstance() const { return new VideoDriver_SDL(); }
|
||||||
/* virtual */ const char *GetDescription() { return "SDL Video Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new VideoDriver_SDL(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VIDEO_SDL_H */
|
#endif /* VIDEO_SDL_H */
|
||||||
|
|
|
@ -80,25 +80,6 @@ public:
|
||||||
virtual void EditBoxLostFocus() {}
|
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 VideoDriver *_video_driver;
|
||||||
extern char *_ini_videodriver;
|
extern char *_ini_videodriver;
|
||||||
extern int _num_resolutions;
|
extern int _num_resolutions;
|
||||||
|
|
|
@ -41,12 +41,10 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The factory for Windows' video driver. */
|
/** The factory for Windows' video driver. */
|
||||||
class FVideoDriver_Win32: public VideoDriverFactory<FVideoDriver_Win32> {
|
class FVideoDriver_Win32 : public DriverFactoryBase {
|
||||||
public:
|
public:
|
||||||
static const int priority = 10;
|
FVideoDriver_Win32() : DriverFactoryBase(Driver::DT_VIDEO, 10, "win32", "Win32 GDI Video Driver") {}
|
||||||
/* virtual */ const char *GetName() { return "win32"; }
|
/* virtual */ Driver *CreateInstance() const { return new VideoDriver_Win32(); }
|
||||||
/* virtual */ const char *GetDescription() { return "Win32 GDI Video Driver"; }
|
|
||||||
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Win32(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VIDEO_WIN32_H */
|
#endif /* VIDEO_WIN32_H */
|
||||||
|
|
Loading…
Reference in New Issue