Changeset - r24218:c32caa9f014d
[Not reviewed]
src/blitter/factory.hpp
Show inline comments
 
@@ -13,28 +13,28 @@
 
#include "base.hpp"
 
#include "../debug.h"
 
#include "../string_func.h"
 
#include "../core/string_compare_type.hpp"
 
#include <map>
 

	
 

	
 
/**
 
 * The base factory, keeping track of all blitters.
 
 */
 
class BlitterFactory {
 
private:
 
	const char *name;        ///< The name of the blitter factory.
 
	const char *description; ///< The description of the blitter.
 
	const std::string name;        ///< The name of the blitter factory.
 
	const std::string description; ///< The description of the blitter.
 

	
 
	typedef std::map<const char *, BlitterFactory *, StringCompare> Blitters; ///< Map of blitter factories.
 
	typedef std::map<std::string, BlitterFactory *> Blitters; ///< Map of blitter factories.
 

	
 
	/**
 
	 * Get the map with currently known blitters.
 
	 * @return The known blitters.
 
	 */
 
	static Blitters &GetBlitters()
 
	{
 
		static Blitters &s_blitters = *new Blitters();
 
		return s_blitters;
 
	}
 

	
 
	/**
 
@@ -49,88 +49,85 @@ private:
 

	
 
protected:
 
	/**
 
	 * Construct the blitter, and register it.
 
	 * @param name        The name of the blitter.
 
	 * @param description A longer description for the blitter.
 
	 * @param usable      Whether the blitter is usable (on the current computer). For example for disabling SSE blitters when the CPU can't handle them.
 
	 * @pre name != nullptr.
 
	 * @pre description != nullptr.
 
	 * @pre There is no blitter registered with this name.
 
	 */
 
	BlitterFactory(const char *name, const char *description, bool usable = true) :
 
			name(stredup(name)), description(stredup(description))
 
			name(name), description(description)
 
	{
 
		if (usable) {
 
			/*
 
			 * Only add when the blitter is usable. Do not bail out or
 
			 * do more special things since the blitters are always
 
			 * instantiated upon start anyhow and freed upon shutdown.
 
			 */
 
			std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(this->name, this));
 
			assert(P.second);
 
		} else {
 
			DEBUG(driver, 1, "Not registering blitter %s as it is not usable", name);
 
		}
 
	}
 

	
 
public:
 
	virtual ~BlitterFactory()
 
	{
 
		GetBlitters().erase(this->name);
 
		if (GetBlitters().empty()) delete &GetBlitters();
 

	
 
		free(this->name);
 
		free(this->description);
 
	}
 

	
 
	/**
 
	 * Find the requested blitter and return his class.
 
	 * @param name the blitter to select.
 
	 * @post Sets the blitter so GetCurrentBlitter() returns it too.
 
	 */
 
	static Blitter *SelectBlitter(const char *name)
 
	static Blitter *SelectBlitter(const std::string &name)
 
	{
 
		BlitterFactory *b = GetBlitterFactory(name);
 
		if (b == nullptr) return nullptr;
 

	
 
		Blitter *newb = b->CreateInstance();
 
		delete *GetActiveBlitter();
 
		*GetActiveBlitter() = newb;
 

	
 
		DEBUG(driver, 1, "Successfully %s blitter '%s'", StrEmpty(name) ? "probed" : "loaded", newb->GetName());
 
		DEBUG(driver, 1, "Successfully %s blitter '%s'", name.empty() ? "probed" : "loaded", newb->GetName());
 
		return newb;
 
	}
 

	
 
	/**
 
	 * Get the blitter factory with the given name.
 
	 * @param name the blitter factory to select.
 
	 * @return The blitter factory, or nullptr when there isn't one with the wanted name.
 
	 */
 
	static BlitterFactory *GetBlitterFactory(const char *name)
 
	static BlitterFactory *GetBlitterFactory(const std::string &name)
 
	{
 
#if defined(DEDICATED)
 
		const char *default_blitter = "null";
 
#elif defined(WITH_COCOA)
 
		const char *default_blitter = "32bpp-anim";
 
#else
 
		const char *default_blitter = "8bpp-optimized";
 
#endif
 
		if (GetBlitters().size() == 0) return nullptr;
 
		const char *bname = (StrEmpty(name)) ? default_blitter : name;
 
		const char *bname = name.empty() ? default_blitter : name.c_str();
 

	
 
		Blitters::iterator it = GetBlitters().begin();
 
		for (; it != GetBlitters().end(); it++) {
 
			BlitterFactory *b = (*it).second;
 
			if (strcasecmp(bname, b->name) == 0) {
 
			if (strcasecmp(bname, b->name.c_str()) == 0) {
 
				return b;
 
			}
 
		}
 
		return nullptr;
 
	}
 

	
 
	/**
 
	 * Get the current active blitter (always set by calling SelectBlitter).
 
	 */
 
	static Blitter *GetCurrentBlitter()
 
	{
 
		return *GetActiveBlitter();
 
@@ -139,45 +136,45 @@ public:
 
	/**
 
	 * Fill a buffer with information about the blitters.
 
	 * @param p The buffer to fill.
 
	 * @param last The last element of the buffer.
 
	 * @return p The location till where we filled the buffer.
 
	 */
 
	static char *GetBlittersInfo(char *p, const char *last)
 
	{
 
		p += seprintf(p, last, "List of blitters:\n");
 
		Blitters::iterator it = GetBlitters().begin();
 
		for (; it != GetBlitters().end(); it++) {
 
			BlitterFactory *b = (*it).second;
 
			p += seprintf(p, last, "%18s: %s\n", b->name, b->GetDescription());
 
			p += seprintf(p, last, "%18s: %s\n", b->name.c_str(), b->GetDescription().c_str());
 
		}
 
		p += seprintf(p, last, "\n");
 

	
 
		return p;
 
	}
 

	
 
	/**
 
	 * Get the long, human readable, name for the Blitter-class.
 
	 */
 
	const char *GetName() const
 
	const std::string &GetName() const
 
	{
 
		return this->name;
 
	}
 

	
 
	/**
 
	 * Get a nice description of the blitter-class.
 
	 */
 
	const char *GetDescription() const
 
	const std::string &GetDescription() const
 
	{
 
		return this->description;
 
	}
 

	
 
	/**
 
	 * Create an instance of this Blitter-class.
 
	 */
 
	virtual Blitter *CreateInstance() = 0;
 
};
 

	
 
extern char *_ini_blitter;
 
extern std::string _ini_blitter;
 
extern bool _blitter_autodetected;
 

	
 
#endif /* BLITTER_FACTORY_HPP */
src/driver.cpp
Show inline comments
 
@@ -4,187 +4,177 @@
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file driver.cpp Base for all driver handling. */
 

	
 
#include "stdafx.h"
 
#include "debug.h"
 
#include "sound/sound_driver.hpp"
 
#include "music/music_driver.hpp"
 
#include "video/video_driver.hpp"
 
#include "string_func.h"
 
#include <string>
 
#include <sstream>
 

	
 
#include "safeguards.h"
 

	
 
char *_ini_videodriver;              ///< The video driver a stored in the configuration file.
 
std::string _ini_videodriver;        ///< The video driver a stored in the configuration file.
 
std::vector<Dimension> _resolutions; ///< List of resolutions.
 
Dimension _cur_resolution;           ///< The current resolution.
 
bool _rightclick_emulate;            ///< Whether right clicking is emulated.
 

	
 
char *_ini_sounddriver;              ///< The sound driver a stored in the configuration file.
 
std::string _ini_sounddriver;        ///< The sound driver a stored in the configuration file.
 

	
 
char *_ini_musicdriver;              ///< The music driver a stored in the configuration file.
 
std::string _ini_musicdriver;        ///< The music driver a stored in the configuration file.
 

	
 
char *_ini_blitter;                  ///< The blitter as stored in the configuration file.
 
std::string _ini_blitter;            ///< The blitter as stored in the configuration file.
 
bool _blitter_autodetected;          ///< Was the blitter autodetected or specified by the user?
 

	
 
/**
 
 * Get a string parameter the list of parameters.
 
 * @param parm The parameters.
 
 * @param name The parameter name we're looking for.
 
 * @return The parameter value.
 
 */
 
const char *GetDriverParam(const char * const *parm, const char *name)
 
const char *GetDriverParam(const StringList &parm, const char *name)
 
{
 
	size_t len;
 

	
 
	if (parm == nullptr) return nullptr;
 
	if (parm.empty()) return nullptr;
 

	
 
	len = strlen(name);
 
	for (; *parm != nullptr; parm++) {
 
		const char *p = *parm;
 

	
 
		if (strncmp(p, name, len) == 0) {
 
			if (p[len] == '=')  return p + len + 1;
 
			if (p[len] == '\0') return p + len;
 
	size_t len = strlen(name);
 
	for (auto &p : parm) {
 
		if (p.compare(0, len, name) == 0) {
 
			if (p.length() == len) return "";
 
			if (p[len] == '=') return p.c_str() + len + 1;
 
		}
 
	}
 
	return nullptr;
 
}
 

	
 
/**
 
 * Get a boolean parameter the list of parameters.
 
 * @param parm The parameters.
 
 * @param name The parameter name we're looking for.
 
 * @return The parameter value.
 
 */
 
bool GetDriverParamBool(const char * const *parm, const char *name)
 
bool GetDriverParamBool(const StringList &parm, const char *name)
 
{
 
	return GetDriverParam(parm, name) != nullptr;
 
}
 

	
 
/**
 
 * Get an integer parameter the list of parameters.
 
 * @param parm The parameters.
 
 * @param name The parameter name we're looking for.
 
 * @param def  The default value if the parameter doesn't exist.
 
 * @return The parameter value.
 
 */
 
int GetDriverParamInt(const char * const *parm, const char *name, int def)
 
int GetDriverParamInt(const StringList &parm, const char *name, int def)
 
{
 
	const char *p = GetDriverParam(parm, name);
 
	return p != nullptr ? atoi(p) : def;
 
}
 

	
 
/**
 
 * Find the requested driver and return its class.
 
 * @param name the driver to select.
 
 * @param type the type of driver to select
 
 * @post Sets the driver so GetCurrentDriver() returns it too.
 
 */
 
void DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
 
void DriverFactoryBase::SelectDriver(const std::string &name, Driver::Type type)
 
{
 
	if (!DriverFactoryBase::SelectDriverImpl(name, type)) {
 
		StrEmpty(name) ?
 
		name.empty() ?
 
			usererror("Failed to autoprobe %s driver", GetDriverTypeName(type)) :
 
			usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name);
 
			usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name.c_str());
 
	}
 
}
 

	
 
/**
 
 * Find the requested driver and return its class.
 
 * @param name the driver to select.
 
 * @param type the type of driver to select
 
 * @post Sets the driver so GetCurrentDriver() returns it too.
 
 * @return True upon success, otherwise false.
 
 */
 
bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
 
bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type type)
 
{
 
	if (GetDrivers().size() == 0) return false;
 

	
 
	if (StrEmpty(name)) {
 
	if (name.empty()) {
 
		/* Probe for this driver, but do not fall back to dedicated/null! */
 
		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;
 
				if (d->priority != priority) continue;
 

	
 
				Driver *oldd = *GetActiveDriver(type);
 
				Driver *newd = d->CreateInstance();
 
				*GetActiveDriver(type) = newd;
 

	
 
				const char *err = newd->Start(nullptr);
 
				const char *err = newd->Start({});
 
				if (err == nullptr) {
 
					DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
 
					delete oldd;
 
					return true;
 
				}
 

	
 
				*GetActiveDriver(type) = oldd;
 
				DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
 
				delete newd;
 
			}
 
		}
 
		usererror("Couldn't find any suitable %s driver", GetDriverTypeName(type));
 
	} else {
 
		char *parm;
 
		char buffer[256];
 
		const char *parms[32];
 
		/* Extract the driver name and put parameter list in parm */
 
		std::istringstream buffer(name);
 
		std::string dname;
 
		std::getline(buffer, dname, ':');
 

	
 
		/* Extract the driver name and put parameter list in parm */
 
		strecpy(buffer, name, lastof(buffer));
 
		parm = strchr(buffer, ':');
 
		parms[0] = nullptr;
 
		if (parm != nullptr) {
 
			uint np = 0;
 
			/* Tokenize the parm. */
 
			do {
 
				*parm++ = '\0';
 
				if (np < lengthof(parms) - 1) parms[np++] = parm;
 
				while (*parm != '\0' && *parm != ',') parm++;
 
			} while (*parm == ',');
 
			parms[np] = nullptr;
 
		std::string param;
 
		std::vector<std::string> parms;
 
		while (std::getline(buffer, param, ',')) {
 
			parms.push_back(param);
 
		}
 

	
 
		/* Find this driver */
 
		Drivers::iterator it = GetDrivers().begin();
 
		for (; it != GetDrivers().end(); ++it) {
 
			DriverFactoryBase *d = (*it).second;
 

	
 
			/* Check driver type */
 
			if (d->type != type) continue;
 

	
 
			/* Check driver name */
 
			if (strcasecmp(buffer, d->name) != 0) continue;
 
			if (strcasecmp(dname.c_str(), d->name) != 0) continue;
 

	
 
			/* Found our driver, let's try it */
 
			Driver *newd = d->CreateInstance();
 

	
 
			const char *err = newd->Start(parms);
 
			if (err != nullptr) {
 
				delete newd;
 
				usererror("Unable to load driver '%s'. The error was: %s", d->name, err);
 
			}
 

	
 
			DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name);
 
			delete *GetActiveDriver(type);
 
			*GetActiveDriver(type) = newd;
 
			return true;
 
		}
 
		usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
 
		usererror("No such %s driver: %s\n", GetDriverTypeName(type), dname.c_str());
 
	}
 
}
 

	
 
/**
 
 * 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)
 
{
 
	for (Driver::Type type = Driver::DT_BEGIN; type != Driver::DT_END; type++) {
 
@@ -212,38 +202,32 @@ char *DriverFactoryBase::GetDriversInfo(
 
 * @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 = stredup(buf);
 

	
 
	std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this));
 
	std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(buf, this));
 
	assert(P.second);
 
}
 

	
 
/**
 
 * Frees memory used for this->name
 
 */
 
DriverFactoryBase::~DriverFactoryBase()
 
{
 
	/* 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);
 
	assert(it != GetDrivers().end());
 

	
 
	const char *longname = (*it).first;
 

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

	
 
	if (GetDrivers().empty()) delete &GetDrivers();
 
}
src/driver.h
Show inline comments
 
@@ -3,39 +3,40 @@
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file driver.h Base for all drivers (video, sound, music, etc). */
 

	
 
#ifndef DRIVER_H
 
#define DRIVER_H
 

	
 
#include "core/enum_type.hpp"
 
#include "core/string_compare_type.hpp"
 
#include "string_type.h"
 
#include <map>
 

	
 
const char *GetDriverParam(const char * const *parm, const char *name);
 
bool GetDriverParamBool(const char * const *parm, const char *name);
 
int GetDriverParamInt(const char * const *parm, const char *name, int def);
 
const char *GetDriverParam(const StringList &parm, const char *name);
 
bool GetDriverParamBool(const StringList &parm, const char *name);
 
int GetDriverParamInt(const StringList &parm, const char *name, int def);
 

	
 
/** A driver for communicating with the user. */
 
class Driver {
 
public:
 
	/**
 
	 * Start this driver.
 
	 * @param parm Parameters passed to the driver.
 
	 * @return nullptr if everything went okay, otherwise an error message.
 
	 */
 
	virtual const char *Start(const char * const *parm) = 0;
 
	virtual const char *Start(const StringList &parm) = 0;
 

	
 
	/**
 
	 * Stop this driver.
 
	 */
 
	virtual void Stop() = 0;
 

	
 
	virtual ~Driver() { }
 

	
 
	/** The type of driver */
 
	enum Type {
 
		DT_BEGIN = 0, ///< Helper for iteration
 
		DT_MUSIC = 0, ///< A music driver, needs to be before sound to properly shut down extmidi forked music players
 
@@ -57,25 +58,25 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type)
 
/** Base for all driver factories. */
 
class DriverFactoryBase {
 
private:
 
	friend class MusicDriver;
 
	friend class SoundDriver;
 
	friend class VideoDriver;
 

	
 
	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.
 
	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<std::string, DriverFactoryBase *> Drivers; ///< Type for a map of drivers.
 

	
 
	/**
 
	 * Get the map with drivers.
 
	 */
 
	static Drivers &GetDrivers()
 
	{
 
		static Drivers &s_drivers = *new Drivers();
 
		return s_drivers;
 
	}
 

	
 
	/**
 
	 * Get the active driver for the given type.
 
@@ -90,44 +91,44 @@ private:
 

	
 
	/**
 
	 * Get the driver type name.
 
	 * @param type The type of driver to get the name of.
 
	 * @return The name of the type.
 
	 */
 
	static const char *GetDriverTypeName(Driver::Type type)
 
	{
 
		static const char * const driver_type_name[] = { "music", "sound", "video" };
 
		return driver_type_name[type];
 
	}
 

	
 
	static bool SelectDriverImpl(const char *name, Driver::Type type);
 
	static bool SelectDriverImpl(const std::string &name, Driver::Type type);
 

	
 
protected:
 
	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++) {
 
			Driver *driver = *GetActiveDriver(dt);
 
			if (driver != nullptr) driver->Stop();
 
		}
 
	}
 

	
 
	static void SelectDriver(const char *name, Driver::Type type);
 
	static void SelectDriver(const std::string &name, Driver::Type type);
 
	static char *GetDriversInfo(char *p, const char *last);
 

	
 
	/**
 
	 * Get a nice description of the driver-class.
 
	 * @return The description.
 
	 */
 
	const char *GetDescription() const
 
	{
 
		return this->description;
 
	}
 

	
 
	/**
src/music/allegro_m.cpp
Show inline comments
 
@@ -17,25 +17,25 @@
 

	
 
#include "../safeguards.h"
 

	
 
static FMusicDriver_Allegro iFMusicDriver_Allegro;
 
static MIDI *_midi = nullptr;
 

	
 
/**
 
 * There are multiple modules that might be using Allegro and
 
 * Allegro can only be initiated once.
 
 */
 
extern int _allegro_instance_count;
 

	
 
const char *MusicDriver_Allegro::Start(const char * const *param)
 
const char *MusicDriver_Allegro::Start(const StringList &param)
 
{
 
	if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
 
		DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
 
		return "Failed to set up Allegro";
 
	}
 
	_allegro_instance_count++;
 

	
 
	/* Initialise the sound */
 
	if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, nullptr) != 0) {
 
		DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error);
 
		return "Failed to set up Allegro sound";
 
	}
src/music/allegro_m.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file allegro_m.h Base support for playing music via allegro. */
 

	
 
#ifndef MUSIC_ALLEGRO_H
 
#define MUSIC_ALLEGRO_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** Allegro's music player. */
 
class MusicDriver_Allegro : public MusicDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "allegro"; }
 
};
src/music/bemidi.cpp
Show inline comments
 
@@ -15,25 +15,25 @@
 

	
 
/* BeOS System Includes */
 
#include <MidiSynthFile.h>
 

	
 
#include "../safeguards.h"
 

	
 
/** The file we're playing. */
 
static BMidiSynthFile midiSynthFile;
 

	
 
/** Factory for BeOS' midi player. */
 
static FMusicDriver_BeMidi iFMusicDriver_BeMidi;
 

	
 
const char *MusicDriver_BeMidi::Start(const char * const *parm)
 
const char *MusicDriver_BeMidi::Start(const StringList &parm)
 
{
 
	return nullptr;
 
}
 

	
 
void MusicDriver_BeMidi::Stop()
 
{
 
	midiSynthFile.UnloadFile();
 
}
 

	
 
void MusicDriver_BeMidi::PlaySong(const MusicSongInfo &song)
 
{
 
	std::string filename = MidiFile::GetSMFFile(song);
src/music/bemidi.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file bemidi.h Base of BeOS Midi support. */
 

	
 
#ifndef MUSIC_BEMIDI_H
 
#define MUSIC_BEMIDI_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** The midi player for BeOS. */
 
class MusicDriver_BeMidi : public MusicDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "bemidi"; }
 
};
src/music/cocoa_m.cpp
Show inline comments
 
@@ -70,25 +70,25 @@ static void DoSetVolume()
 
		DEBUG(driver, 1, "cocoa_m: Failed to get output node to set volume");
 
		return;
 
	}
 

	
 
	Float32 vol = _volume / 127.0f;  // 0 - +127 -> 0.0 - 1.0
 
	AudioUnitSetParameter(output_unit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, vol, 0);
 
}
 

	
 

	
 
/**
 
 * Initialized the MIDI player, including QuickTime initialization.
 
 */
 
const char *MusicDriver_Cocoa::Start(const char * const *parm)
 
const char *MusicDriver_Cocoa::Start(const StringList &parm)
 
{
 
	if (NewMusicPlayer(&_player) != noErr) return "failed to create music player";
 

	
 
	return nullptr;
 
}
 

	
 

	
 
/**
 
 * Checks whether the player is active.
 
 */
 
bool MusicDriver_Cocoa::IsSongPlaying()
 
{
src/music/cocoa_m.h
Show inline comments
 
@@ -5,25 +5,25 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file cocoa_m.h Base of music playback via CoreAudio. */
 

	
 
#ifndef MUSIC_MACOSX_COCOA_H
 
#define MUSIC_MACOSX_COCOA_H
 

	
 
#include "music_driver.hpp"
 

	
 
class MusicDriver_Cocoa : public MusicDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "cocoa"; }
 
};
src/music/dmusic.cpp
Show inline comments
 
@@ -1062,25 +1062,25 @@ static const char *LoadDefaultDLSFile(co
 
				download_port->Release();
 
				return "Downloading DLS instrument failed";
 
			}
 
		}
 

	
 
		download_port->Release();
 
	}
 

	
 
	return nullptr;
 
}
 

	
 

	
 
const char *MusicDriver_DMusic::Start(const char * const *parm)
 
const char *MusicDriver_DMusic::Start(const StringList &parm)
 
{
 
	/* Initialize COM */
 
	if (FAILED(CoInitializeEx(nullptr, COINITBASE_MULTITHREADED))) return "COM initialization failed";
 

	
 
	/* Create the DirectMusic object */
 
	if (FAILED(CoCreateInstance(
 
				CLSID_DirectMusic,
 
				nullptr,
 
				CLSCTX_INPROC,
 
				IID_IDirectMusic,
 
				(LPVOID*)&_music
 
			))) {
src/music/dmusic.h
Show inline comments
 
@@ -8,25 +8,25 @@
 
/** @file dmusic.h Base of playing music via DirectMusic. */
 

	
 
#ifndef MUSIC_DMUSIC_H
 
#define MUSIC_DMUSIC_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** Music player making use of DirectX. */
 
class MusicDriver_DMusic : public MusicDriver {
 
public:
 
	virtual ~MusicDriver_DMusic();
 

	
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "dmusic"; }
 
};
src/music/extmidi.cpp
Show inline comments
 
@@ -27,25 +27,25 @@
 
#include <errno.h>
 

	
 
#include "../safeguards.h"
 

	
 
#ifndef EXTERNAL_PLAYER
 
/** The default external midi player. */
 
#define EXTERNAL_PLAYER "timidity"
 
#endif
 

	
 
/** Factory for the midi player that uses external players. */
 
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
 

	
 
const char *MusicDriver_ExtMidi::Start(const char * const * parm)
 
const char *MusicDriver_ExtMidi::Start(const StringList &parm)
 
{
 
	if (strcmp(VideoDriver::GetInstance()->GetName(), "allegro") == 0 ||
 
			strcmp(SoundDriver::GetInstance()->GetName(), "allegro") == 0) {
 
		return "the extmidi driver does not work when Allegro is loaded.";
 
	}
 

	
 
	const char *command = GetDriverParam(parm, "cmd");
 
#ifndef MIDI_ARG
 
	if (StrEmpty(command)) command = EXTERNAL_PLAYER;
 
#else
 
	if (StrEmpty(command)) command = EXTERNAL_PLAYER " " MIDI_ARG;
 
#endif
src/music/extmidi.h
Show inline comments
 
@@ -13,25 +13,25 @@
 
#include "music_driver.hpp"
 

	
 
class MusicDriver_ExtMidi : public MusicDriver {
 
private:
 
	char **params;
 
	char song[MAX_PATH];
 
	pid_t pid;
 

	
 
	void DoPlay();
 
	void DoStop();
 

	
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "extmidi"; }
 
};
src/music/fluidsynth.cpp
Show inline comments
 
@@ -41,25 +41,25 @@ static const char *default_sf[] = {
 

	
 
	nullptr
 
};
 

	
 
static void RenderMusicStream(int16 *buffer, size_t samples)
 
{
 
	std::unique_lock<std::mutex> lock{ _midi.synth_mutex, std::try_to_lock };
 

	
 
	if (!lock.owns_lock() || !_midi.synth || !_midi.player) return;
 
	fluid_synth_write_s16(_midi.synth, samples, buffer, 0, 2, buffer, 1, 2);
 
}
 

	
 
const char *MusicDriver_FluidSynth::Start(const char * const *param)
 
const char *MusicDriver_FluidSynth::Start(const StringList &param)
 
{
 
	std::lock_guard<std::mutex> lock{ _midi.synth_mutex };
 

	
 
	const char *sfont_name = GetDriverParam(param, "soundfont");
 
	int sfont_id;
 

	
 
	DEBUG(driver, 1, "Fluidsynth: sf %s", sfont_name);
 

	
 
	/* Create the settings. */
 
	_midi.settings = new_fluid_settings();
 
	if (!_midi.settings) return "Could not create midi settings";
 
	/* Don't try to lock sample data in memory, OTTD usually does not run with privileges allowing that */
src/music/fluidsynth.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file fluidsynth.h Base for FluidSynth music playback. */
 

	
 
#ifndef MUSIC_FLUIDSYNTH_H
 
#define MUSIC_FLUIDSYNTH_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** Music driver making use of FluidSynth. */
 
class MusicDriver_FluidSynth : public MusicDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "fluidsynth"; }
 
};
src/music/music_driver.hpp
Show inline comments
 
@@ -39,15 +39,15 @@ public:
 
	 * @param vol The new volume.
 
	 */
 
	virtual void SetVolume(byte vol) = 0;
 

	
 
	/**
 
	 * Get the currently active instance of the music driver.
 
	 */
 
	static MusicDriver *GetInstance() {
 
		return static_cast<MusicDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_MUSIC));
 
	}
 
};
 

	
 
extern char *_ini_musicdriver;
 
extern std::string _ini_musicdriver;
 

	
 
#endif /* MUSIC_MUSIC_DRIVER_HPP */
src/music/null_m.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file null_m.h Base for the silent music playback. */
 

	
 
#ifndef MUSIC_NULL_H
 
#define MUSIC_NULL_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** The music player that does nothing. */
 
class MusicDriver_Null : public MusicDriver {
 
public:
 
	const char *Start(const char * const *param) override { return nullptr; }
 
	const char *Start(const StringList &param) override { return nullptr; }
 

	
 
	void Stop() override { }
 

	
 
	void PlaySong(const MusicSongInfo &song) override { }
 

	
 
	void StopSong() override { }
 

	
 
	bool IsSongPlaying() override { return true; }
 

	
 
	void SetVolume(byte vol) override { }
 
	const char *GetName() const override { return "null"; }
 
};
src/music/os2_m.cpp
Show inline comments
 
@@ -71,21 +71,21 @@ void MusicDriver_OS2::StopSong()
 
void MusicDriver_OS2::SetVolume(byte vol)
 
{
 
	MidiSendCommand("set song audio volume %d", ((vol/127)*100));
 
}
 

	
 
bool MusicDriver_OS2::IsSongPlaying()
 
{
 
	char buf[16];
 
	mciSendString("status song mode", buf, sizeof(buf), nullptr, 0);
 
	return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
 
}
 

	
 
const char *MusicDriver_OS2::Start(const char * const *parm)
 
const char *MusicDriver_OS2::Start(const StringList &parm)
 
{
 
	return 0;
 
}
 

	
 
void MusicDriver_OS2::Stop()
 
{
 
	MidiSendCommand("close all");
 
}
src/music/os2_m.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file os2_m.h Base for OS2 music playback. */
 

	
 
#ifndef MUSIC_OS2_H
 
#define MUSIC_OS2_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** OS/2's music player. */
 
class MusicDriver_OS2 : public MusicDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "os2"; }
 
};
src/music/win32_m.cpp
Show inline comments
 
@@ -353,25 +353,25 @@ void MusicDriver_Win32::StopSong()
 

	
 
bool MusicDriver_Win32::IsSongPlaying()
 
{
 
	return _midi.playing || (_midi.do_start != 0);
 
}
 

	
 
void MusicDriver_Win32::SetVolume(byte vol)
 
{
 
	std::lock_guard<std::mutex> mutex_lock(_midi.lock);
 
	_midi.new_volume = vol;
 
}
 

	
 
const char *MusicDriver_Win32::Start(const char * const *parm)
 
const char *MusicDriver_Win32::Start(const StringList &parm)
 
{
 
	DEBUG(driver, 2, "Win32-MIDI: Start: initializing");
 

	
 
	int resolution = GetDriverParamInt(parm, "resolution", 5);
 
	uint port = (uint)GetDriverParamInt(parm, "port", UINT_MAX);
 
	const char *portname = GetDriverParam(parm, "portname");
 

	
 
	/* Enumerate ports either for selecting port by name, or for debug output */
 
	if (portname != nullptr || _debug_driver_level > 0) {
 
		uint numports = midiOutGetNumDevs();
 
		DEBUG(driver, 1, "Win32-MIDI: Found %d output devices:", numports);
 
		for (uint tryport = 0; tryport < numports; tryport++) {
src/music/win32_m.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file win32_m.h Base for Windows music playback. */
 

	
 
#ifndef MUSIC_WIN32_H
 
#define MUSIC_WIN32_H
 

	
 
#include "music_driver.hpp"
 

	
 
/** The Windows music player. */
 
class MusicDriver_Win32 : public MusicDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void PlaySong(const MusicSongInfo &song) override;
 

	
 
	void StopSong() override;
 

	
 
	bool IsSongPlaying() override;
 

	
 
	void SetVolume(byte vol) override;
 
	const char *GetName() const override { return "win32"; }
 
};
src/openttd.cpp
Show inline comments
 
@@ -524,28 +524,28 @@ static const OptionData _options[] = {
 
	 GETOPT_SHORT_NOVAL('h'),
 
	GETOPT_END()
 
};
 

	
 
/**
 
 * Main entry point for this lovely game.
 
 * @param argc The number of arguments passed to this game.
 
 * @param argv The values of the arguments.
 
 * @return 0 when there is no error.
 
 */
 
int openttd_main(int argc, char *argv[])
 
{
 
	char *musicdriver = nullptr;
 
	char *sounddriver = nullptr;
 
	char *videodriver = nullptr;
 
	char *blitter = nullptr;
 
	std::string musicdriver;
 
	std::string sounddriver;
 
	std::string videodriver;
 
	std::string blitter;
 
	std::string graphics_set;
 
	std::string sounds_set;
 
	std::string music_set;
 
	Dimension resolution = {0, 0};
 
	/* AfterNewGRFScan sets save_config to true after scanning completed. */
 
	bool save_config = false;
 
	AfterNewGRFScan *scanner = new AfterNewGRFScan(&save_config);
 
	bool dedicated = false;
 
	char *debuglog_conn = nullptr;
 

	
 
	extern bool _dedicated_forks;
 
	_dedicated_forks = false;
 
@@ -557,37 +557,33 @@ int openttd_main(int argc, char *argv[])
 
	_switch_mode = SM_MENU;
 
	_config_file = nullptr;
 

	
 
	GetOptData mgo(argc - 1, argv + 1, _options);
 
	int ret = 0;
 

	
 
	int i;
 
	while ((i = mgo.GetOpt()) != -1) {
 
		switch (i) {
 
		case 'I': graphics_set = mgo.opt; break;
 
		case 'S': sounds_set = mgo.opt; break;
 
		case 'M': music_set = mgo.opt; break;
 
		case 'm': free(musicdriver); musicdriver = stredup(mgo.opt); break;
 
		case 's': free(sounddriver); sounddriver = stredup(mgo.opt); break;
 
		case 'v': free(videodriver); videodriver = stredup(mgo.opt); break;
 
		case 'b': free(blitter); blitter = stredup(mgo.opt); break;
 
		case 'm': musicdriver = mgo.opt; break;
 
		case 's': sounddriver = mgo.opt; break;
 
		case 'v': videodriver = mgo.opt; break;
 
		case 'b': blitter = mgo.opt; break;
 
		case 'D':
 
			free(musicdriver);
 
			free(sounddriver);
 
			free(videodriver);
 
			free(blitter);
 
			musicdriver = stredup("null");
 
			sounddriver = stredup("null");
 
			videodriver = stredup("dedicated");
 
			blitter = stredup("null");
 
			musicdriver = "null";
 
			sounddriver = "null";
 
			videodriver = "dedicated";
 
			blitter = "null";
 
			dedicated = true;
 
			SetDebugString("net=6");
 
			if (mgo.opt != nullptr) {
 
				/* Use the existing method for parsing (openttd -n).
 
				 * However, we do ignore the #company part. */
 
				const char *temp = nullptr;
 
				const char *port = nullptr;
 
				ParseConnectionString(&temp, &port, mgo.opt);
 
				if (!StrEmpty(mgo.opt)) scanner->dedicated_host = mgo.opt;
 
				if (port != nullptr) scanner->dedicated_port = atoi(port);
 
			}
 
			break;
 
@@ -737,46 +733,44 @@ int openttd_main(int argc, char *argv[])
 
			BaseGraphics::SetSet({});
 

	
 
			ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND);
 
			msg.SetDParamStr(0, graphics_set.c_str());
 
			ScheduleErrorMessage(msg);
 
		}
 
	}
 

	
 
	/* Initialize game palette */
 
	GfxInitPalettes();
 

	
 
	DEBUG(misc, 1, "Loading blitter...");
 
	if (blitter == nullptr && _ini_blitter != nullptr) blitter = stredup(_ini_blitter);
 
	_blitter_autodetected = StrEmpty(blitter);
 
	if (blitter.empty() && !_ini_blitter.empty()) blitter = _ini_blitter;
 
	_blitter_autodetected = blitter.empty();
 
	/* Activate the initial blitter.
 
	 * This is only some initial guess, after NewGRFs have been loaded SwitchNewGRFBlitter may switch to a different one.
 
	 *  - Never guess anything, if the user specified a blitter. (_blitter_autodetected)
 
	 *  - Use 32bpp blitter if baseset or 8bpp-support settings says so.
 
	 *  - Use 8bpp blitter otherwise.
 
	 */
 
	if (!_blitter_autodetected ||
 
			(_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
 
			BlitterFactory::SelectBlitter("32bpp-anim") == nullptr) {
 
		if (BlitterFactory::SelectBlitter(blitter) == nullptr) {
 
			StrEmpty(blitter) ?
 
			blitter.empty() ?
 
				usererror("Failed to autoprobe blitter") :
 
				usererror("Failed to select requested blitter '%s'; does it exist?", blitter);
 
				usererror("Failed to select requested blitter '%s'; does it exist?", blitter.c_str());
 
		}
 
	}
 
	free(blitter);
 

	
 
	if (videodriver == nullptr && _ini_videodriver != nullptr) videodriver = stredup(_ini_videodriver);
 
	if (videodriver.empty() && !_ini_videodriver.empty()) videodriver = _ini_videodriver;
 
	DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
 
	free(videodriver);
 

	
 
	InitializeSpriteSorter();
 

	
 
	/* Initialize the zoom level of the screen to normal */
 
	_screen.zoom = ZOOM_LVL_NORMAL;
 

	
 
	NetworkStartUp(); // initialize network-core
 

	
 
	if (debuglog_conn != nullptr && _network_available) {
 
		const char *not_used = nullptr;
 
		const char *port = nullptr;
 
		uint16 rport;
 
@@ -815,31 +809,29 @@ int openttd_main(int argc, char *argv[])
 
	BaseMusic::FindSets();
 
	if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set;
 
	if (!BaseMusic::SetSet(music_set)) {
 
		if (music_set.empty() || !BaseMusic::SetSet({})) {
 
			usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md.");
 
		} else {
 
			ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND);
 
			msg.SetDParamStr(0, music_set.c_str());
 
			ScheduleErrorMessage(msg);
 
		}
 
	}
 

	
 
	if (sounddriver == nullptr && _ini_sounddriver != nullptr) sounddriver = stredup(_ini_sounddriver);
 
	if (sounddriver.empty() && !_ini_sounddriver.empty()) sounddriver = _ini_sounddriver;
 
	DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
 
	free(sounddriver);
 

	
 
	if (musicdriver == nullptr && _ini_musicdriver != nullptr) musicdriver = stredup(_ini_musicdriver);
 
	if (musicdriver.empty() && !_ini_musicdriver.empty()) musicdriver = _ini_musicdriver;
 
	DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
 
	free(musicdriver);
 

	
 
	/* Take our initial lock on whatever we might want to do! */
 
	try {
 
		modal_work_lock.lock();
 
		modal_paint_lock.lock();
 
	} catch (const std::system_error&) {
 
		/* If there is some error we assume that threads aren't usable on the system we run. */
 
		extern bool _use_threaded_modal_progress; // From progress.cpp
 
		_use_threaded_modal_progress = false;
 
	}
 

	
 
	GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
 
@@ -859,41 +851,27 @@ int openttd_main(int argc, char *argv[])
 
	WaitTillGeneratedWorld(); // Make sure any generate world threads have been joined.
 

	
 
	/* only save config if we have to */
 
	if (save_config) {
 
		SaveToConfig();
 
		SaveHotkeysToConfig();
 
		WindowDesc::SaveToConfig();
 
		SaveToHighScore();
 
	}
 

	
 
	/* Reset windowing system, stop drivers, free used memory, ... */
 
	ShutdownGame();
 
	goto exit_normal;
 

	
 
exit_noshutdown:
 
	/* These three are normally freed before bootstrap. */
 
	free(videodriver);
 
	free(blitter);
 

	
 
exit_bootstrap:
 
	/* These are normally freed before exit, but after bootstrap. */
 
	free(musicdriver);
 
	free(sounddriver);
 

	
 
exit_normal:
 
	free(_ini_musicdriver);
 
	free(_ini_sounddriver);
 
	free(_ini_videodriver);
 
	free(_ini_blitter);
 

	
 
	delete scanner;
 

	
 
	extern FILE *_log_fd;
 
	if (_log_fd != nullptr) {
 
		fclose(_log_fd);
 
	}
 

	
 
	return ret;
 
}
 

	
 
void HandleExitGameRequest()
src/sound/allegro_s.cpp
Show inline comments
 
@@ -41,25 +41,25 @@ void SoundDriver_Allegro::MainLoop()
 
	for (int i = 0; i < _buffer_size * 2; i++) snd[i] ^= 0x8000;
 

	
 
	/* Tell we've filled the stream */
 
	free_audio_stream_buffer(_stream);
 
}
 

	
 
/**
 
 * There are multiple modules that might be using Allegro and
 
 * Allegro can only be initiated once.
 
 */
 
extern int _allegro_instance_count;
 

	
 
const char *SoundDriver_Allegro::Start(const char * const *parm)
 
const char *SoundDriver_Allegro::Start(const StringList &parm)
 
{
 
	if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
 
		DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
 
		return "Failed to set up Allegro";
 
	}
 
	_allegro_instance_count++;
 

	
 
	/* Initialise the sound */
 
	if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, nullptr) != 0) {
 
		DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error);
 
		return "Failed to set up Allegro sound";
 
	}
src/sound/allegro_s.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file allegro_s.h Base for playing sound via Allegro. */
 

	
 
#ifndef SOUND_ALLEGRO_H
 
#define SOUND_ALLEGRO_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the allegro sound driver. */
 
class SoundDriver_Allegro : public SoundDriver {
 
public:
 
	const char *Start(const char * const *param);
 
	const char *Start(const StringList &param);
 

	
 
	void Stop();
 

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

	
 
/** Factory for the allegro sound driver. */
 
class FSoundDriver_Allegro : public DriverFactoryBase {
 
public:
 
	FSoundDriver_Allegro() : DriverFactoryBase(Driver::DT_SOUND, 4, "allegro", "Allegro Sound Driver") {}
 
	/* virtual */ Driver *CreateInstance() const { return new SoundDriver_Allegro(); }
src/sound/cocoa_s.cpp
Show inline comments
 
@@ -35,25 +35,25 @@ static FSoundDriver_Cocoa iFSoundDriver_
 

	
 
static AudioUnit _outputAudioUnit;
 

	
 
/* The CoreAudio callback */
 
static OSStatus audioCallback(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList * ioData)
 
{
 
	MxMixSamples(ioData->mBuffers[0].mData, ioData->mBuffers[0].mDataByteSize / 4);
 

	
 
	return noErr;
 
}
 

	
 

	
 
const char *SoundDriver_Cocoa::Start(const char * const *parm)
 
const char *SoundDriver_Cocoa::Start(const StringList &parm)
 
{
 
	struct AURenderCallbackStruct callback;
 
	AudioStreamBasicDescription requestedDesc;
 

	
 
	/* Setup a AudioStreamBasicDescription with the requested format */
 
	requestedDesc.mFormatID = kAudioFormatLinearPCM;
 
	requestedDesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
 
	requestedDesc.mChannelsPerFrame = 2;
 
	requestedDesc.mSampleRate = GetDriverParamInt(parm, "hz", 44100);
 

	
 
	requestedDesc.mBitsPerChannel = 16;
 
	requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
src/sound/cocoa_s.h
Show inline comments
 
@@ -5,25 +5,25 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file cocoa_s.h Base for Cocoa sound handling. */
 

	
 
#ifndef SOUND_COCOA_H
 
#define SOUND_COCOA_H
 

	
 
#include "sound_driver.hpp"
 

	
 
class SoundDriver_Cocoa : public SoundDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 
	const char *GetName() const override { return "cocoa"; }
 
};
 

	
 
class FSoundDriver_Cocoa : public DriverFactoryBase {
 
public:
 
	FSoundDriver_Cocoa() : DriverFactoryBase(Driver::DT_SOUND, 10, "cocoa", "Cocoa Sound Driver") {}
 
	Driver *CreateInstance() const override { return new SoundDriver_Cocoa(); }
 
};
 

	
 
#endif /* SOUND_COCOA_H */
src/sound/null_s.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file null_s.h Base for the sound of silence. */
 

	
 
#ifndef SOUND_NULL_H
 
#define SOUND_NULL_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the null sound driver. */
 
class SoundDriver_Null : public SoundDriver {
 
public:
 
	const char *Start(const char * const *param) override { return nullptr; }
 
	const char *Start(const StringList &param) override { return nullptr; }
 

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

	
 
/** Factory for the null sound driver. */
 
class FSoundDriver_Null : public DriverFactoryBase {
 
public:
 
	FSoundDriver_Null() : DriverFactoryBase(Driver::DT_SOUND, 1, "null", "Null Sound Driver") {}
 
	Driver *CreateInstance() const override { return new SoundDriver_Null(); }
 
};
 

	
src/sound/sdl2_s.cpp
Show inline comments
 
@@ -22,25 +22,25 @@ static FSoundDriver_SDL iFSoundDriver_SD
 

	
 
/**
 
 * Callback that fills the sound buffer.
 
 * @param userdata Ignored.
 
 * @param stream   The stream to put data into.
 
 * @param len      The length of the stream in bytes.
 
 */
 
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
 
{
 
	MxMixSamples(stream, len / 4);
 
}
 

	
 
const char *SoundDriver_SDL::Start(const char * const *parm)
 
const char *SoundDriver_SDL::Start(const StringList &parm)
 
{
 
	SDL_AudioSpec spec;
 
	SDL_AudioSpec spec_actual;
 

	
 
	/* Only initialise SDL if the video driver hasn't done it already */
 
	int ret_code = 0;
 
	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
 
		ret_code = SDL_Init(SDL_INIT_AUDIO);
 
	} else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
 
		ret_code = SDL_InitSubSystem(SDL_INIT_AUDIO);
 
	}
 
	if (ret_code == -1) return SDL_GetError();
src/sound/sdl_s.cpp
Show inline comments
 
@@ -22,25 +22,25 @@ static FSoundDriver_SDL iFSoundDriver_SD
 

	
 
/**
 
 * Callback that fills the sound buffer.
 
 * @param userdata Ignored.
 
 * @param stream   The stream to put data into.
 
 * @param len      The length of the stream in bytes.
 
 */
 
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
 
{
 
	MxMixSamples(stream, len / 4);
 
}
 

	
 
const char *SoundDriver_SDL::Start(const char * const *parm)
 
const char *SoundDriver_SDL::Start(const StringList &parm)
 
{
 
	SDL_AudioSpec spec;
 

	
 
	/* Only initialise SDL if the video driver hasn't done it already */
 
	int ret_code = 0;
 
	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
 
		ret_code = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
 
	} else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
 
		ret_code = SDL_InitSubSystem(SDL_INIT_AUDIO);
 
	}
 
	if (ret_code == -1) return SDL_GetError();
 

	
src/sound/sdl_s.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file sdl_s.h Base for playing sound via SDL. */
 

	
 
#ifndef SOUND_SDL_H
 
#define SOUND_SDL_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the SDL sound driver. */
 
class SoundDriver_SDL : public SoundDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

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

	
 
/** Factory for the SDL sound driver. */
 
class FSoundDriver_SDL : public DriverFactoryBase {
 
public:
 
	FSoundDriver_SDL() : DriverFactoryBase(Driver::DT_SOUND, 5, "sdl", "SDL Sound Driver") {}
 
	Driver *CreateInstance() const override { return new SoundDriver_SDL(); }
 
};
 

	
src/sound/sound_driver.hpp
Show inline comments
 
@@ -17,15 +17,15 @@ class SoundDriver : public Driver {
 
public:
 
	/** Called once every tick */
 
	virtual void MainLoop() {}
 

	
 
	/**
 
	 * Get the currently active instance of the sound driver.
 
	 */
 
	static SoundDriver *GetInstance() {
 
		return static_cast<SoundDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_SOUND));
 
	}
 
};
 

	
 
extern char *_ini_sounddriver;
 
extern std::string _ini_sounddriver;
 

	
 
#endif /* SOUND_SOUND_DRIVER_HPP */
src/sound/win32_s.cpp
Show inline comments
 
@@ -49,25 +49,25 @@ static DWORD WINAPI SoundThread(LPVOID a
 
			MxMixSamples(hdr->lpData, hdr->dwBufferLength / 4);
 
			if (waveOutWrite(_waveout, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
 
				MessageBox(nullptr, _T("Sounds are disabled until restart."), _T("waveOutWrite failed"), MB_ICONINFORMATION);
 
				return 0;
 
			}
 
		}
 
		WaitForSingleObject(_event, INFINITE);
 
	} while (_waveout != nullptr);
 

	
 
	return 0;
 
}
 

	
 
const char *SoundDriver_Win32::Start(const char * const *parm)
 
const char *SoundDriver_Win32::Start(const StringList &parm)
 
{
 
	WAVEFORMATEX wfex;
 
	wfex.wFormatTag = WAVE_FORMAT_PCM;
 
	wfex.nChannels = 2;
 
	wfex.wBitsPerSample = 16;
 
	wfex.nSamplesPerSec = GetDriverParamInt(parm, "hz", 44100);
 
	wfex.nBlockAlign = (wfex.nChannels * wfex.wBitsPerSample) / 8;
 
	wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign;
 

	
 
	/* Limit buffer size to prevent overflows. */
 
	_bufsize = GetDriverParamInt(parm, "bufsize", (GB(GetVersion(), 0, 8) > 5) ? 8192 : 4096);
 
	_bufsize = min(_bufsize, UINT16_MAX);
src/sound/win32_s.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file win32_s.h Base for Windows sound handling. */
 

	
 
#ifndef SOUND_WIN32_H
 
#define SOUND_WIN32_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the sound driver for Windows. */
 
class SoundDriver_Win32 : public SoundDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

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

	
 
/** Factory for the sound driver for Windows. */
 
class FSoundDriver_Win32 : public DriverFactoryBase {
 
public:
 
	FSoundDriver_Win32() : DriverFactoryBase(Driver::DT_SOUND, 9, "win32", "Win32 WaveOut Sound Driver") {}
 
	Driver *CreateInstance() const override { return new SoundDriver_Win32(); }
 
};
 

	
src/sound/xaudio2_s.cpp
Show inline comments
 
@@ -117,25 +117,25 @@ static HMODULE _xaudio_dll_handle;
 
static IXAudio2SourceVoice* _source_voice = nullptr;
 
static IXAudio2MasteringVoice* _mastering_voice = nullptr;
 
static ComPtr<IXAudio2> _xaudio2;
 
static StreamingVoiceContext* _voice_context = nullptr;
 

	
 
/**
 
* Initialises the XAudio2 driver.
 
*
 
* @param parm Driver parameters.
 
* @return An error message if unsuccessful, or nullptr otherwise.
 
*
 
*/
 
const char *SoundDriver_XAudio2::Start(const char * const *parm)
 
const char *SoundDriver_XAudio2::Start(const StringList &parm)
 
{
 
	HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
 

	
 
	if (FAILED(hr))
 
	{
 
		DEBUG(driver, 0, "xaudio2_s: CoInitializeEx failed (%08x)", hr);
 
		return "Failed to initialise COM";
 
	}
 

	
 
	_xaudio_dll_handle = LoadLibraryA(XAUDIO2_DLL_A);
 

	
 
	if (_xaudio_dll_handle == nullptr)
src/sound/xaudio2_s.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file xaudio2_s.h Base for XAudio2 sound handling. */
 

	
 
#ifndef SOUND_XAUDIO2_H
 
#define SOUND_XAUDIO2_H
 

	
 
#include "sound_driver.hpp"
 

	
 
/** Implementation of the XAudio2 sound driver. */
 
class SoundDriver_XAudio2 : public SoundDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 
	const char *GetName() const override { return "xaudio2"; }
 
};
 

	
 
/** Factory for the XAudio2 sound driver. */
 
class FSoundDriver_XAudio2 : public DriverFactoryBase {
 
public:
 
	FSoundDriver_XAudio2() : DriverFactoryBase(Driver::DT_SOUND, 10, "xaudio2", "XAudio2 Sound Driver") {}
 
	Driver *CreateInstance() const override { return new SoundDriver_XAudio2(); }
 
};
 

	
src/table/misc_settings.ini
Show inline comments
 
@@ -71,46 +71,46 @@ name     = ""soundsset""
 
type     = SLE_STRQ
 
var      = BaseSounds::ini_set
 
def      = nullptr
 
cat      = SC_BASIC
 

	
 
[SDTG_SSTR]
 
name     = ""musicset""
 
type     = SLE_STRQ
 
var      = BaseMusic::ini_set
 
def      = nullptr
 
cat      = SC_BASIC
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""videodriver""
 
type     = SLE_STRQ
 
var      = _ini_videodriver
 
def      = nullptr
 
cat      = SC_EXPERT
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""musicdriver""
 
type     = SLE_STRQ
 
var      = _ini_musicdriver
 
def      = nullptr
 
cat      = SC_EXPERT
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""sounddriver""
 
type     = SLE_STRQ
 
var      = _ini_sounddriver
 
def      = nullptr
 
cat      = SC_EXPERT
 

	
 
[SDTG_STR]
 
[SDTG_SSTR]
 
name     = ""blitter""
 
type     = SLE_STRQ
 
var      = _ini_blitter
 
def      = nullptr
 

	
 
[SDTG_STR]
 
name     = ""language""
 
type     = SLE_STRB
 
var      = _config_language_file
 
def      = nullptr
 
cat      = SC_BASIC
 

	
src/video/allegro_v.cpp
Show inline comments
 
@@ -401,25 +401,25 @@ static void PollEvent()
 
		WChar character;
 
		uint keycode = ConvertAllegroKeyIntoMy(&character);
 
		HandleKeypress(keycode, character);
 
	}
 
}
 

	
 
/**
 
 * There are multiple modules that might be using Allegro and
 
 * Allegro can only be initiated once.
 
 */
 
int _allegro_instance_count = 0;
 

	
 
const char *VideoDriver_Allegro::Start(const char * const *parm)
 
const char *VideoDriver_Allegro::Start(const StringList &parm)
 
{
 
	if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
 
		DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
 
		return "Failed to set up Allegro";
 
	}
 
	_allegro_instance_count++;
 

	
 
	install_timer();
 
	install_mouse();
 
	install_keyboard();
 

	
 
#if defined _DEBUG
src/video/allegro_v.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file allegro_v.h Base of the Allegro video driver. */
 

	
 
#ifndef VIDEO_ALLEGRO_H
 
#define VIDEO_ALLEGRO_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The allegro video driver. */
 
class VideoDriver_Allegro : public VideoDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
 
	void MainLoop() override;
 

	
 
	bool ChangeResolution(int w, int h) override;
 

	
 
	bool ToggleFullscreen(bool fullscreen) override;
 

	
 
	bool AfterBlitterChange() override;
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -5,25 +5,25 @@
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file cocoa_v.h The Cocoa video driver. */
 

	
 
#ifndef VIDEO_COCOA_H
 
#define VIDEO_COCOA_H
 

	
 
#include "../video_driver.hpp"
 

	
 
class VideoDriver_Cocoa : public VideoDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	/** Stop the video driver */
 
	void Stop() override;
 

	
 
	/** Mark dirty a screen region
 
	 * @param left x-coordinate of left border
 
	 * @param top  y-coordinate of top border
 
	 * @param width width or dirty rectangle
 
	 * @param height height of dirty rectangle
 
	 */
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
src/video/cocoa/cocoa_v.mm
Show inline comments
 
@@ -387,25 +387,25 @@ void VideoDriver_Cocoa::Stop()
 

	
 
	delete _cocoa_subdriver;
 
	_cocoa_subdriver = NULL;
 

	
 
	[ _ottd_main release ];
 

	
 
	_cocoa_video_started = false;
 
}
 

	
 
/**
 
 * Initialize a cocoa video subdriver.
 
 */
 
const char *VideoDriver_Cocoa::Start(const char * const *parm)
 
const char *VideoDriver_Cocoa::Start(const StringList &parm)
 
{
 
	if (!MacOSVersionIsAtLeast(10, 6, 0)) return "The Cocoa video driver requires Mac OS X 10.6 or later.";
 

	
 
	if (_cocoa_video_started) return "Already started";
 
	_cocoa_video_started = true;
 

	
 
	setupApplication();
 

	
 
	/* Don't create a window or enter fullscreen if we're just going to show a dialog. */
 
	if (_cocoa_video_dialog) return NULL;
 

	
 
	int width  = _cur_resolution.width;
 
@@ -511,25 +511,25 @@ void VideoDriver_Cocoa::EditBoxLostFocus
 
 * @param message Message text.
 
 * @param buttonLabel Button text.
 
 *
 
 * @note This is needed since sometimes assert is called before the videodriver is initialized .
 
 */
 
void CocoaDialog(const char *title, const char *message, const char *buttonLabel)
 
{
 
	_cocoa_video_dialog = true;
 

	
 
	bool wasstarted = _cocoa_video_started;
 
	if (VideoDriver::GetInstance() == NULL) {
 
		setupApplication(); // Setup application before showing dialog
 
	} else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start(NULL) != NULL) {
 
	} else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start(StringList()) != NULL) {
 
		fprintf(stderr, "%s: %s\n", title, message);
 
		return;
 
	}
 

	
 
	NSAlert *alert = [ [ NSAlert alloc ] init ];
 
	[ alert setAlertStyle: NSCriticalAlertStyle ];
 
	[ alert setMessageText:[ NSString stringWithUTF8String:title ] ];
 
	[ alert setInformativeText:[ NSString stringWithUTF8String:message ] ];
 
	[ alert addButtonWithTitle: [ NSString stringWithUTF8String:buttonLabel ] ];
 
	[ alert runModal ];
 
	[ alert release ];
 

	
src/video/dedicated_v.cpp
Show inline comments
 
@@ -124,25 +124,25 @@ static void CloseWindowsConsoleThread()
 

	
 

	
 
static void *_dedicated_video_mem;
 

	
 
/* Whether a fork has been done. */
 
bool _dedicated_forks;
 

	
 
extern bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
 

	
 
static FVideoDriver_Dedicated iFVideoDriver_Dedicated;
 

	
 

	
 
const char *VideoDriver_Dedicated::Start(const char * const *parm)
 
const char *VideoDriver_Dedicated::Start(const StringList &parm)
 
{
 
	int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
 
	_dedicated_video_mem = (bpp == 0) ? nullptr : MallocT<byte>(_cur_resolution.width * _cur_resolution.height * (bpp / 8));
 

	
 
	_screen.width  = _screen.pitch = _cur_resolution.width;
 
	_screen.height = _cur_resolution.height;
 
	_screen.dst_ptr = _dedicated_video_mem;
 
	ScreenSizeChanged();
 
	BlitterFactory::GetCurrentBlitter()->PostResize();
 

	
 
#if defined(_WIN32)
 
	/* For win32 we need to allocate a console (debug mode does the same) */
src/video/dedicated_v.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file dedicated_v.h Base for the dedicated video driver. */
 

	
 
#ifndef VIDEO_DEDICATED_H
 
#define VIDEO_DEDICATED_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The dedicated server video driver. */
 
class VideoDriver_Dedicated : public VideoDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
 
	void MainLoop() override;
 

	
 
	bool ChangeResolution(int w, int h) override;
 

	
 
	bool ToggleFullscreen(bool fullscreen) override;
 
	const char *GetName() const override { return "dedicated"; }
 
	bool HasGUI() const override { return false; }
src/video/null_v.cpp
Show inline comments
 
@@ -8,25 +8,25 @@
 
/** @file null_v.cpp The videio driver that doesn't blit. */
 

	
 
#include "../stdafx.h"
 
#include "../gfx_func.h"
 
#include "../blitter/factory.hpp"
 
#include "null_v.h"
 

	
 
#include "../safeguards.h"
 

	
 
/** Factory for the null video driver. */
 
static FVideoDriver_Null iFVideoDriver_Null;
 

	
 
const char *VideoDriver_Null::Start(const char * const *parm)
 
const char *VideoDriver_Null::Start(const StringList &parm)
 
{
 
#ifdef _MSC_VER
 
	/* Disable the MSVC assertion message box. */
 
	_set_error_mode(_OUT_TO_STDERR);
 
#endif
 

	
 
	this->ticks = GetDriverParamInt(parm, "ticks", 1000);
 
	_screen.width  = _screen.pitch = _cur_resolution.width;
 
	_screen.height = _cur_resolution.height;
 
	_screen.dst_ptr = nullptr;
 
	ScreenSizeChanged();
 

	
src/video/null_v.h
Show inline comments
 
@@ -9,25 +9,25 @@
 

	
 
#ifndef VIDEO_NULL_H
 
#define VIDEO_NULL_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The null video driver. */
 
class VideoDriver_Null : public VideoDriver {
 
private:
 
	uint ticks; ///< Amount of ticks to run.
 

	
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
 
	void MainLoop() override;
 

	
 
	bool ChangeResolution(int w, int h) override;
 

	
 
	bool ToggleFullscreen(bool fullscreen) override;
 
	const char *GetName() const override { return "null"; }
 
	bool HasGUI() const override { return false; }
src/video/sdl2_v.cpp
Show inline comments
 
@@ -617,25 +617,25 @@ int VideoDriver_SDL::PollEvent()
 
				_cursor.in_window = true;
 
			} else if (ev.window.event == SDL_WINDOWEVENT_LEAVE) {
 
				// mouse left the window, undraw cursor
 
				UndrawMouseCursor();
 
				_cursor.in_window = false;
 
			}
 
			break;
 
		}
 
	}
 
	return -1;
 
}
 

	
 
const char *VideoDriver_SDL::Start(const char * const *parm)
 
const char *VideoDriver_SDL::Start(const StringList &parm)
 
{
 
	/* Explicitly disable hardware acceleration. Enabling this causes
 
	 * UpdateWindowSurface() to update the window's texture instead of
 
	 * its surface. */
 
	SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION , "0");
 

	
 
	/* Just on the offchance the audio subsystem started before the video system,
 
	 * check whether any part of SDL has been initialised before getting here.
 
	 * Slightly duplicated with sound/sdl_s.cpp */
 
	int ret_code = 0;
 
	if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
 
		ret_code = SDL_InitSubSystem(SDL_INIT_VIDEO);
 
@@ -643,25 +643,25 @@ const char *VideoDriver_SDL::Start(const
 
	if (ret_code < 0) return SDL_GetError();
 

	
 
	GetVideoModes();
 
	if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height, false)) {
 
		return SDL_GetError();
 
	}
 

	
 
	const char *dname = SDL_GetCurrentVideoDriver();
 
	DEBUG(driver, 1, "SDL2: using driver '%s'", dname);
 

	
 
	MarkWholeScreenDirty();
 

	
 
	_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr;
 
	_draw_threaded = !GetDriverParamBool(parm, "no_threads") && !GetDriverParamBool(parm, "no_thread");
 

	
 
	SDL_StopTextInput();
 
	this->edit_box_focused = false;
 

	
 
	return nullptr;
 
}
 

	
 
void VideoDriver_SDL::Stop()
 
{
 
	SDL_QuitSubSystem(SDL_INIT_VIDEO);
 
	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
 
		SDL_Quit(); // If there's nothing left, quit SDL
src/video/sdl2_v.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file sdl2_v.h Base of the SDL2 video driver. */
 

	
 
#ifndef VIDEO_SDL_H
 
#define VIDEO_SDL_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The SDL video driver. */
 
class VideoDriver_SDL : public VideoDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
 
	void MainLoop() override;
 

	
 
	bool ChangeResolution(int w, int h) override;
 

	
 
	bool ToggleFullscreen(bool fullscreen) override;
 

	
 
	bool AfterBlitterChange() override;
src/video/sdl_v.cpp
Show inline comments
 
@@ -587,25 +587,25 @@ int VideoDriver_SDL::PollEvent()
 
		}
 
		case SDL_VIDEOEXPOSE: {
 
			/* Force a redraw of the entire screen. Note
 
			 * that SDL 1.2 seems to do this automatically
 
			 * in most cases, but 1.3 / 2.0 does not. */
 
		        _num_dirty_rects = MAX_DIRTY_RECTS + 1;
 
			break;
 
		}
 
	}
 
	return -1;
 
}
 

	
 
const char *VideoDriver_SDL::Start(const char * const *parm)
 
const char *VideoDriver_SDL::Start(const StringList &parm)
 
{
 
	char buf[30];
 
	_use_hwpalette = GetDriverParamInt(parm, "hw_palette", 2);
 

	
 
	/* Just on the offchance the audio subsystem started before the video system,
 
	 * check whether any part of SDL has been initialised before getting here.
 
	 * Slightly duplicated with sound/sdl_s.cpp */
 
	int ret_code = 0;
 
	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
 
		ret_code = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
 
	} else if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
 
		ret_code = SDL_InitSubSystem(SDL_INIT_VIDEO);
 
@@ -614,25 +614,25 @@ const char *VideoDriver_SDL::Start(const
 

	
 
	GetVideoModes();
 
	if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) {
 
		return SDL_GetError();
 
	}
 

	
 
	SDL_VideoDriverName(buf, sizeof buf);
 
	DEBUG(driver, 1, "SDL: using driver '%s'", buf);
 

	
 
	MarkWholeScreenDirty();
 
	SetupKeyboard();
 

	
 
	_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr;
 
	_draw_threaded = !GetDriverParamBool(parm, "no_threads") && !GetDriverParamBool(parm, "no_thread");
 

	
 
	return nullptr;
 
}
 

	
 
void VideoDriver_SDL::SetupKeyboard()
 
{
 
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
 
	SDL_EnableUNICODE(1);
 
}
 

	
 
void VideoDriver_SDL::Stop()
 
{
src/video/sdl_v.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file sdl_v.h Base of the SDL video driver. */
 

	
 
#ifndef VIDEO_SDL_H
 
#define VIDEO_SDL_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The SDL video driver. */
 
class VideoDriver_SDL : public VideoDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
 
	void MainLoop() override;
 

	
 
	bool ChangeResolution(int w, int h) override;
 

	
 
	bool ToggleFullscreen(bool fullscreen) override;
 

	
 
	bool AfterBlitterChange() override;
src/video/video_driver.hpp
Show inline comments
 
@@ -95,18 +95,18 @@ public:
 
	 * An edit box gained the input focus
 
	 */
 
	virtual void EditBoxGainedFocus() {}
 

	
 
	/**
 
	 * Get the currently active instance of the video driver.
 
	 */
 
	static VideoDriver *GetInstance() {
 
		return static_cast<VideoDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO));
 
	}
 
};
 

	
 
extern char *_ini_videodriver;
 
extern std::string _ini_videodriver;
 
extern std::vector<Dimension> _resolutions;
 
extern Dimension _cur_resolution;
 
extern bool _rightclick_emulate;
 

	
 
#endif /* VIDEO_VIDEO_DRIVER_HPP */
src/video/win32_v.cpp
Show inline comments
 
@@ -1102,46 +1102,46 @@ static void FindResolutions()
 
	}
 

	
 
	/* We have found no resolutions, show the default list */
 
	if (_resolutions.empty()) {
 
		_resolutions.assign(std::begin(default_resolutions), std::end(default_resolutions));
 
	}
 

	
 
	SortResolutions();
 
}
 

	
 
static FVideoDriver_Win32 iFVideoDriver_Win32;
 

	
 
const char *VideoDriver_Win32::Start(const char * const *parm)
 
const char *VideoDriver_Win32::Start(const StringList &parm)
 
{
 
	memset(&_wnd, 0, sizeof(_wnd));
 

	
 
	RegisterWndClass();
 

	
 
	MakePalette();
 

	
 
	FindResolutions();
 

	
 
	DEBUG(driver, 2, "Resolution for display: %ux%u", _cur_resolution.width, _cur_resolution.height);
 

	
 
	/* fullscreen uses those */
 
	_wnd.width_org  = _cur_resolution.width;
 
	_wnd.height_org = _cur_resolution.height;
 

	
 
	AllocateDibSection(_cur_resolution.width, _cur_resolution.height);
 
	this->MakeWindow(_fullscreen);
 

	
 
	MarkWholeScreenDirty();
 

	
 
	_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr && std::thread::hardware_concurrency() > 1;
 
	_draw_threaded = !GetDriverParamBool(parm, "no_threads") && !GetDriverParamBool(parm, "no_thread") && std::thread::hardware_concurrency() > 1;
 

	
 
	return nullptr;
 
}
 

	
 
void VideoDriver_Win32::Stop()
 
{
 
	DeleteObject(_wnd.gdi_palette);
 
	DeleteObject(_wnd.dib_sect);
 
	DestroyWindow(_wnd.main_wnd);
 

	
 
	if (_wnd.fullscreen) ChangeDisplaySettings(nullptr, 0);
 
	MyShowCursor(true);
src/video/win32_v.h
Show inline comments
 
@@ -6,25 +6,25 @@
 
 */
 

	
 
/** @file win32_v.h Base of the Windows video driver. */
 

	
 
#ifndef VIDEO_WIN32_H
 
#define VIDEO_WIN32_H
 

	
 
#include "video_driver.hpp"
 

	
 
/** The video driver for windows. */
 
class VideoDriver_Win32 : public VideoDriver {
 
public:
 
	const char *Start(const char * const *param) override;
 
	const char *Start(const StringList &param) override;
 

	
 
	void Stop() override;
 

	
 
	void MakeDirty(int left, int top, int width, int height) override;
 

	
 
	void MainLoop() override;
 

	
 
	bool ChangeResolution(int w, int h) override;
 

	
 
	bool ToggleFullscreen(bool fullscreen) override;
 

	
 
	bool AfterBlitterChange() override;
0 comments (0 inline, 0 general)