Changeset - r21027:e87e97e6befd
[Not reviewed]
master
0 27 0
rubidium - 11 years ago 2013-11-25 14:26:46
rubidium@openttd.org
(svn r26107) -Codechange/cleanup: remove some coding bloat and simplify the driver factory instatiations
27 files changed with 101 insertions and 208 deletions:
0 comments (0 inline, 0 general)
src/driver.cpp
Show inline comments
 
@@ -162,39 +162,12 @@ Driver *DriverFactoryBase::SelectDriver(
 
		}
 
		usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
 
	}
 
}
 

	
 
/**
 
 * 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.
 
 * @return The end of the written buffer.
 
 */
 
char *DriverFactoryBase::GetDriversInfo(char *p, const char *last)
 
@@ -216,18 +189,37 @@ char *DriverFactoryBase::GetDriversInfo(
 
	}
 

	
 
	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
 
 */
 
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));
 
	strecpy(buf + 5, this->name, lastof(buf));
 

	
 
	Drivers::iterator it = GetDrivers().find(buf);
 
@@ -236,8 +228,7 @@ DriverFactoryBase::~DriverFactoryBase()
 
	const char *longname = (*it).first;
 

	
 
	GetDrivers().erase(it);
 
	free(longname);
 

	
 
	if (GetDrivers().empty()) delete &GetDrivers();
 
	free(this->name);
 
}
src/driver.h
Show inline comments
 
@@ -57,14 +57,15 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type)
 

	
 

	
 
/** Base for all driver factories. */
 
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.
 

	
 
	/**
 
	 * Get the map with drivers.
 
	 */
 
@@ -94,21 +95,17 @@ private:
 
	{
 
		static const char * const driver_type_name[] = { "music", "sound", "video" };
 
		return driver_type_name[type];
 
	}
 

	
 
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
 
	 */
 
	static void ShutdownDrivers()
 
	{
 
		for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
 
@@ -121,16 +118,19 @@ public:
 
	static char *GetDriversInfo(char *p, const char *last);
 

	
 
	/**
 
	 * 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 */
src/music/allegro_m.h
Show inline comments
 
@@ -29,23 +29,21 @@ public:
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "allegro"; }
 
};
 

	
 
/** 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 */
src/music/bemidi.h
Show inline comments
 
@@ -29,15 +29,13 @@ public:
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "bemidi"; }
 
};
 

	
 
/** 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 */
src/music/cocoa_m.h
Show inline comments
 
@@ -27,15 +27,13 @@ public:
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* 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 */
src/music/dmusic.h
Show inline comments
 
@@ -31,15 +31,13 @@ public:
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "dmusic"; }
 
};
 

	
 
/** 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 */
src/music/extmidi.h
Show inline comments
 
@@ -35,15 +35,13 @@ public:
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* 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 */
src/music/libtimidity.h
Show inline comments
 
@@ -29,15 +29,13 @@ public:
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "libtimidity"; }
 
};
 

	
 
/** 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 */
src/music/music_driver.hpp
Show inline comments
 
@@ -38,29 +38,10 @@ public:
 
	 * Set the volume, if possible.
 
	 * @param vol The new volume.
 
	 */
 
	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;
 

	
 
#endif /* MUSIC_MUSIC_DRIVER_HPP */
src/music/null_m.h
Show inline comments
 
@@ -29,15 +29,13 @@ public:
 

	
 
	/* virtual */ void SetVolume(byte vol) { }
 
	/* virtual */ const char *GetName() const { return "null"; }
 
};
 

	
 
/** 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 */
src/music/os2_m.h
Show inline comments
 
@@ -29,15 +29,13 @@ public:
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "os2"; }
 
};
 

	
 
/** 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 */
src/music/qtmidi.h
Show inline comments
 
@@ -27,15 +27,13 @@ public:
 
	/* virtual */ bool IsSongPlaying();
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* 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 */
src/music/win32_m.h
Show inline comments
 
@@ -29,15 +29,13 @@ public:
 

	
 
	/* virtual */ void SetVolume(byte vol);
 
	/* virtual */ const char *GetName() const { return "win32"; }
 
};
 

	
 
/** 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 */
src/openttd.cpp
Show inline comments
 
@@ -187,13 +187,13 @@ static void ShowHelp()
 
	p = BaseSounds::GetSetsList(p, lastof(buf));
 

	
 
	/* List the music packs */
 
	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));
 

	
 
	/* List the debug facilities. */
 
	p = DumpDebugFacilityNames(p, lastof(buf));
 
@@ -764,13 +764,13 @@ int openttd_main(int argc, char *argv[])
 
				usererror("Failed to select requested blitter '%s'; does it exist?", blitter);
 
		}
 
	}
 
	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") :
 
			usererror("Failed to select requested video driver '%s'", videodriver);
 
	}
 
	free(videodriver);
 
@@ -830,22 +830,22 @@ int openttd_main(int argc, char *argv[])
 
			ScheduleErrorMessage(msg);
 
		}
 
	}
 
	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") :
 
			usererror("Failed to select requested sound driver '%s'", sounddriver);
 
	}
 
	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") :
 
			usererror("Failed to select requested music driver '%s'", musicdriver);
 
	}
 
	free(musicdriver);
src/sound/allegro_s.h
Show inline comments
 
@@ -23,15 +23,13 @@ public:
 

	
 
	/* virtual */ void MainLoop();
 
	/* virtual */ const char *GetName() const { return "allegro"; }
 
};
 

	
 
/** 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 */
src/sound/cocoa_s.h
Show inline comments
 
@@ -19,15 +19,13 @@ public:
 
	/* virtual */ const char *Start(const char * const *param);
 

	
 
	/* virtual */ void Stop();
 
	/* 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 */
src/sound/null_s.h
Show inline comments
 
@@ -21,15 +21,13 @@ public:
 

	
 
	/* virtual */ void Stop() { }
 
	/* virtual */ const char *GetName() const { return "null"; }
 
};
 

	
 
/** 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 */
src/sound/sdl_s.h
Show inline comments
 
@@ -21,15 +21,13 @@ public:
 

	
 
	/* virtual */ void Stop();
 
	/* virtual */ const char *GetName() const { return "sdl"; }
 
};
 

	
 
/** 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 */
src/sound/sound_driver.hpp
Show inline comments
 
@@ -18,29 +18,10 @@
 
class SoundDriver: public Driver {
 
public:
 
	/** Called once every tick */
 
	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;
 

	
 
#endif /* SOUND_SOUND_DRIVER_HPP */
src/sound/win32_s.h
Show inline comments
 
@@ -21,15 +21,13 @@ public:
 

	
 
	/* virtual */ void Stop();
 
	/* virtual */ const char *GetName() const { return "win32"; }
 
};
 

	
 
/** 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 */
src/video/allegro_v.h
Show inline comments
 
@@ -34,15 +34,13 @@ public:
 
	/* virtual */ bool ClaimMousePointer();
 

	
 
	/* virtual */ const char *GetName() const { return "allegro"; }
 
};
 

	
 
/** 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 */
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -58,18 +58,16 @@ public:
 
	/** Return driver name
 
	 * @return driver name
 
	 */
 
	/* 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(); }
 
};
 

	
 

	
 
/**
 
 * Generic display driver for cocoa
 
 * On grounds to not duplicate some code, it contains a few variables
src/video/dedicated_v.h
Show inline comments
 
@@ -30,21 +30,20 @@ public:
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
	/* virtual */ const char *GetName() const { return "dedicated"; }
 
	/* virtual */ bool HasGUI() const { return false; }
 
};
 

	
 
/** 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 */
src/video/null_v.h
Show inline comments
 
@@ -33,15 +33,13 @@ public:
 
	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 
	/* virtual */ const char *GetName() const { return "null"; }
 
	/* virtual */ bool HasGUI() const { return false; }
 
};
 

	
 
/** 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 */
src/video/sdl_v.h
Show inline comments
 
@@ -38,15 +38,13 @@ private:
 
	int PollEvent();
 
	bool CreateMainSurface(uint w, uint h);
 
	void SetupKeyboard();
 
};
 

	
 
/** 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 */
src/video/video_driver.hpp
Show inline comments
 
@@ -77,31 +77,12 @@ public:
 
	/**
 
	 * An edit box lost the input focus. Abort character compositing if necessary.
 
	 */
 
	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;
 
extern Dimension _resolutions[32];
 
extern Dimension _cur_resolution;
 
extern bool _rightclick_emulate;
src/video/win32_v.h
Show inline comments
 
@@ -38,15 +38,13 @@ public:
 
	/* virtual */ const char *GetName() const { return "win32"; }
 

	
 
	bool MakeWindow(bool full_screen);
 
};
 

	
 
/** 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 */
0 comments (0 inline, 0 general)