diff options
author | peter1138 <peter1138@openttd.org> | 2007-07-07 20:31:23 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2007-07-07 20:31:23 +0000 |
commit | 8b81cdd2a602d63b6b7f595383cedecf54046650 (patch) | |
tree | 0bd6f98a4074b190b9e2d63d8410f76306430377 /src | |
parent | 0543657b75fe3191d4232c2ebbac80f8b860617f (diff) | |
download | openttd-8b81cdd2a602d63b6b7f595383cedecf54046650.tar.xz |
(svn r10471) -Codechange: implement driver probing priority so that 'preferred' drivers are loaded first
Diffstat (limited to 'src')
-rw-r--r-- | src/driver.h | 38 | ||||
-rw-r--r-- | src/music/bemidi.h | 3 | ||||
-rw-r--r-- | src/music/dmusic.h | 3 | ||||
-rw-r--r-- | src/music/extmidi.h | 3 | ||||
-rw-r--r-- | src/music/libtimidity.h | 3 | ||||
-rw-r--r-- | src/music/music_driver.hpp | 2 | ||||
-rw-r--r-- | src/music/null_m.h | 3 | ||||
-rw-r--r-- | src/music/os2_m.h | 3 | ||||
-rw-r--r-- | src/music/qtmidi.h | 3 | ||||
-rw-r--r-- | src/music/win32_m.h | 3 | ||||
-rw-r--r-- | src/sound/cocoa_s.h | 3 | ||||
-rw-r--r-- | src/sound/null_s.h | 3 | ||||
-rw-r--r-- | src/sound/sdl_s.h | 3 | ||||
-rw-r--r-- | src/sound/sound_driver.hpp | 2 | ||||
-rw-r--r-- | src/sound/win32_s.h | 3 | ||||
-rw-r--r-- | src/video/cocoa_v.h | 3 | ||||
-rw-r--r-- | src/video/dedicated_v.h | 3 | ||||
-rw-r--r-- | src/video/null_v.h | 3 | ||||
-rw-r--r-- | src/video/sdl_v.h | 3 | ||||
-rw-r--r-- | src/video/video_driver.hpp | 2 | ||||
-rw-r--r-- | src/video/win32_v.h | 2 |
21 files changed, 39 insertions, 55 deletions
diff --git a/src/driver.h b/src/driver.h index d10f18688..a57e62459 100644 --- a/src/driver.h +++ b/src/driver.h @@ -16,8 +16,6 @@ int GetDriverParamInt(const char* const* parm, const char* name, int def); class Driver { public: - virtual bool CanProbe() = 0; - virtual const char *Start(const char * const *parm) = 0; virtual void Stop() = 0; @@ -40,6 +38,7 @@ class DriverFactoryBase { private: Driver::Type type; char *name; + int priority; typedef std::map<std::string, DriverFactoryBase *> Drivers; static Drivers &GetDrivers() @@ -66,13 +65,14 @@ protected: * @param name the name of the driver. * @note an assert() will be trigger if 2 driver with the same name try to register. */ - void RegisterDriver(const char *name, Driver::Type type) + void 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]; @@ -101,17 +101,16 @@ public: if (*name == '\0') { /* Probe for this driver */ - Drivers::iterator it = GetDrivers().begin(); - for (; it != GetDrivers().end(); ++it) { - DriverFactoryBase *d = (*it).second; + for (int priority = 10; priority >= 0; priority--) { + Drivers::iterator it = GetDrivers().begin(); + for (; it != GetDrivers().end(); ++it) { + DriverFactoryBase *d = (*it).second; - /* Check driver type */ - if (d->type != type) continue; + /* Check driver type */ + if (d->type != type) continue; + if (d->priority != priority) continue; - Driver *newd = d->CreateInstance(); - if (!newd->CanProbe()) { - DEBUG(driver, 1, "Skipping probe of driver '%s'", d->name); - } else { + Driver *newd = d->CreateInstance(); const char *err = newd->Start(NULL); if (err == NULL) { DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name); @@ -121,9 +120,8 @@ public: } DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err); + delete newd; } - - delete newd; } error("Couldn't find any suitable %s driver", GetDriverTypeName(type)); } else { @@ -185,10 +183,14 @@ public: for (Driver::Type type = Driver::DT_BEGIN; type != Driver::DT_END; type++) { p += snprintf(p, last - p, "List of %s drivers:\n", GetDriverTypeName(type)); - Drivers::iterator it = GetDrivers().begin(); - for (; it != GetDrivers().end(); it++) { - DriverFactoryBase *d = (*it).second; - if (d->type == type) p += snprintf(p, last - p, "%18s: %s\n", d->name, d->GetDescription()); + for (int priority = 10; priority >= 0; priority--) { + Drivers::iterator it = GetDrivers().begin(); + for (; it != GetDrivers().end(); it++) { + DriverFactoryBase *d = (*it).second; + if (d->type != type) continue; + if (d->priority != priority) continue; + p += snprintf(p, last - p, "%18s: %s\n", d->name, d->GetDescription()); + } } p += snprintf(p, last - p, "\n"); diff --git a/src/music/bemidi.h b/src/music/bemidi.h index 623d6398d..096249c24 100644 --- a/src/music/bemidi.h +++ b/src/music/bemidi.h @@ -7,8 +7,6 @@ class MusicDriver_BeMidi: public MusicDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FMusicDriver_BeMidi: public MusicDriverFactory<FMusicDriver_BeMidi> { 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(); } diff --git a/src/music/dmusic.h b/src/music/dmusic.h index 9bfb1bb1c..6fed3beea 100644 --- a/src/music/dmusic.h +++ b/src/music/dmusic.h @@ -7,8 +7,6 @@ class MusicDriver_DMusic: public MusicDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FMusicDriver_DMusic: public MusicDriverFactory<FMusicDriver_DMusic> { public: + static const int priorty = 10; /* virtual */ const char *GetName() { return "dmusic"; } /* virtual */ const char *GetDescription() { return "DirectMusic MIDI Driver"; } /* virtual */ Driver *CreateInstance() { return new MusicDriver_DMusic(); } diff --git a/src/music/extmidi.h b/src/music/extmidi.h index 4f62641b4..d5fa2ba2f 100644 --- a/src/music/extmidi.h +++ b/src/music/extmidi.h @@ -14,8 +14,6 @@ private: void DoStop(); public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -31,6 +29,7 @@ public: class FMusicDriver_ExtMidi: public MusicDriverFactory<FMusicDriver_ExtMidi> { public: + static const int priority = 1; /* virtual */ const char *GetName() { return "extmidi"; } /* virtual */ const char *GetDescription() { return "External MIDI Driver"; } /* virtual */ Driver *CreateInstance() { return new MusicDriver_ExtMidi(); } diff --git a/src/music/libtimidity.h b/src/music/libtimidity.h index 2915841f7..965a19573 100644 --- a/src/music/libtimidity.h +++ b/src/music/libtimidity.h @@ -7,8 +7,6 @@ class MusicDriver_LibTimidity: public MusicDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FMusicDriver_LibTimidity: public MusicDriverFactory<FMusicDriver_LibTimidity> { 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(); } diff --git a/src/music/music_driver.hpp b/src/music/music_driver.hpp index b4486ef94..b9e0ec065 100644 --- a/src/music/music_driver.hpp +++ b/src/music/music_driver.hpp @@ -22,7 +22,7 @@ class MusicDriverFactoryBase: public DriverFactoryBase { template <class T> class MusicDriverFactory: public MusicDriverFactoryBase { public: - MusicDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_MUSIC); } + MusicDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_MUSIC, ((T *)this)->priority); } /** * Get the long, human readable, name for the Driver-class. diff --git a/src/music/null_m.h b/src/music/null_m.h index 2b7be7581..fc5c2bb09 100644 --- a/src/music/null_m.h +++ b/src/music/null_m.h @@ -7,8 +7,6 @@ class MusicDriver_Null: public MusicDriver { public: - /* virtual */ bool CanProbe() { return false; } - /* virtual */ const char *Start(const char * const *param) { return NULL; } /* virtual */ void Stop() { } @@ -24,6 +22,7 @@ public: class FMusicDriver_Null: public MusicDriverFactory<FMusicDriver_Null> { public: + static const int priority = 0; /* virtual */ const char *GetName() { return "null"; } /* virtual */ const char *GetDescription() { return "Null Music Driver"; } /* virtual */ Driver *CreateInstance() { return new MusicDriver_Null(); } diff --git a/src/music/os2_m.h b/src/music/os2_m.h index b0f4d71ce..3ba1b5de6 100644 --- a/src/music/os2_m.h +++ b/src/music/os2_m.h @@ -7,8 +7,6 @@ class MusicDriver_OS2: public MusicDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FMusicDriver_OS2: public MusicDriverFactory<FMusicDriver_OS2> { 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(); } diff --git a/src/music/qtmidi.h b/src/music/qtmidi.h index 7ffa02fe0..3aeac8b32 100644 --- a/src/music/qtmidi.h +++ b/src/music/qtmidi.h @@ -7,8 +7,6 @@ class MusicDriver_QtMidi: public MusicDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FMusicDriver_QtMidi: public MusicDriverFactory<FMusicDriver_QtMidi> { public: + static const int priorty = 10; /* virtual */ const char *GetName() { return "qt"; } /* virtual */ const char *GetDescription() { return "QuickTime MIDI Driver"; } /* virtual */ Driver *CreateInstance() { return new MusicDriver_QtMidi(); } diff --git a/src/music/win32_m.h b/src/music/win32_m.h index bef62bd66..35a79c3e7 100644 --- a/src/music/win32_m.h +++ b/src/music/win32_m.h @@ -7,8 +7,6 @@ class MusicDriver_Win32: public MusicDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FMusicDriver_Win32: public MusicDriverFactory<FMusicDriver_Win32> { public: + static const int priorty = 5; /* virtual */ const char *GetName() { return "win32"; } /* virtual */ const char *GetDescription() { return "Win32 Music Driver"; } /* virtual */ Driver *CreateInstance() { return new MusicDriver_Win32(); } diff --git a/src/sound/cocoa_s.h b/src/sound/cocoa_s.h index 96e24522f..9ec6ac5cb 100644 --- a/src/sound/cocoa_s.h +++ b/src/sound/cocoa_s.h @@ -7,8 +7,6 @@ class SoundDriver_Cocoa: public SoundDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -16,6 +14,7 @@ public: class FSoundDriver_Cocoa: public SoundDriverFactory<FSoundDriver_Cocoa> { 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(); } diff --git a/src/sound/null_s.h b/src/sound/null_s.h index 2f5c79841..27b8d8980 100644 --- a/src/sound/null_s.h +++ b/src/sound/null_s.h @@ -7,8 +7,6 @@ class SoundDriver_Null: public SoundDriver { public: - /* virtual */ bool CanProbe() { return false; } - /* virtual */ const char *Start(const char * const *param) { return NULL; } /* virtual */ void Stop() { } @@ -16,6 +14,7 @@ public: class FSoundDriver_Null: public SoundDriverFactory<FSoundDriver_Null> { public: + static const int priority = 0; /* virtual */ const char *GetName() { return "null"; } /* virtual */ const char *GetDescription() { return "Null Sound Driver"; } /* virtual */ Driver *CreateInstance() { return new SoundDriver_Null(); } diff --git a/src/sound/sdl_s.h b/src/sound/sdl_s.h index 97a9036eb..83edccc99 100644 --- a/src/sound/sdl_s.h +++ b/src/sound/sdl_s.h @@ -7,8 +7,6 @@ class SoundDriver_SDL: public SoundDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -16,6 +14,7 @@ public: class FSoundDriver_SDL: public SoundDriverFactory<FSoundDriver_SDL> { 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(); } diff --git a/src/sound/sound_driver.hpp b/src/sound/sound_driver.hpp index de1a19ac8..04c9e9224 100644 --- a/src/sound/sound_driver.hpp +++ b/src/sound/sound_driver.hpp @@ -14,7 +14,7 @@ class SoundDriverFactoryBase: public DriverFactoryBase { template <class T> class SoundDriverFactory: public SoundDriverFactoryBase { public: - SoundDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_SOUND); } + SoundDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_SOUND, ((T *)this)->priority); } /** * Get the long, human readable, name for the Driver-class. diff --git a/src/sound/win32_s.h b/src/sound/win32_s.h index 820e6c74e..8fbd8b0c1 100644 --- a/src/sound/win32_s.h +++ b/src/sound/win32_s.h @@ -7,8 +7,6 @@ class SoundDriver_Win32: public SoundDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -16,6 +14,7 @@ public: class FSoundDriver_Win32: public SoundDriverFactory<FSoundDriver_Win32> { 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(); } diff --git a/src/video/cocoa_v.h b/src/video/cocoa_v.h index a6fd41871..bb980ad91 100644 --- a/src/video/cocoa_v.h +++ b/src/video/cocoa_v.h @@ -7,8 +7,6 @@ class VideoDriver_Cocoa: public VideoDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> { 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(); } diff --git a/src/video/dedicated_v.h b/src/video/dedicated_v.h index d1dccd0c9..a2de1c275 100644 --- a/src/video/dedicated_v.h +++ b/src/video/dedicated_v.h @@ -7,8 +7,6 @@ class VideoDriver_Dedicated: public VideoDriver { public: - /* virtual */ bool CanProbe() { return false; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FVideoDriver_Dedicated: public VideoDriverFactory<FVideoDriver_Dedicated> { public: + static const int priority = 0; /* virtual */ const char *GetName() { return "dedicated"; } /* virtual */ const char *GetDescription() { return "Dedicated Video Driver"; } /* virtual */ Driver *CreateInstance() { return new VideoDriver_Dedicated(); } diff --git a/src/video/null_v.h b/src/video/null_v.h index 0e65933e8..b5b21bbbb 100644 --- a/src/video/null_v.h +++ b/src/video/null_v.h @@ -7,8 +7,6 @@ class VideoDriver_Null: public VideoDriver { public: - /* virtual */ bool CanProbe() { return false; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FVideoDriver_Null: public VideoDriverFactory<FVideoDriver_Null> { public: + static const int priority = 1; /* virtual */ const char *GetName() { return "null"; } /* virtual */ const char *GetDescription() { return "Null Video Driver"; } /* virtual */ Driver *CreateInstance() { return new VideoDriver_Null(); } diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h index ff494919d..fdfded49c 100644 --- a/src/video/sdl_v.h +++ b/src/video/sdl_v.h @@ -7,8 +7,6 @@ class VideoDriver_SDL: public VideoDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); @@ -24,6 +22,7 @@ public: class FVideoDriver_SDL: public VideoDriverFactory<FVideoDriver_SDL> { 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(); } diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index eab438491..048c233b9 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -22,7 +22,7 @@ class VideoDriverFactoryBase: public DriverFactoryBase { template <class T> class VideoDriverFactory: public VideoDriverFactoryBase { public: - VideoDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_VIDEO); } + VideoDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_VIDEO, ((T *)this)->priority); } /** * Get the long, human readable, name for the Driver-class. diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 0b05ff5db..1f412ecb0 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -7,8 +7,6 @@ class VideoDriver_Win32: public VideoDriver { public: - /* virtual */ bool CanProbe() { return true; } - /* virtual */ const char *Start(const char * const *param); /* virtual */ void Stop(); |