src/driver.h
author terom@frrb.lan
Fri, 19 Dec 2008 01:38:09 +0200
changeset 10439 50f056aa3024
parent 9582 3a55657869eb
permissions -rw-r--r--
industries, unmoveables... everything but the landscape
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8844
diff changeset
     3
/** @file driver.h Base for all drivers (video, sound, music, etc). */
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5475
diff changeset
     4
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     5
#ifndef DRIVER_H
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     6
#define DRIVER_H
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     7
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
     8
#include "debug.h"
8112
24b89cd40bfd (svn r11673) -Codechange: move the overflow safe type to a separate file.
rubidium
parents: 8051
diff changeset
     9
#include "core/enum_type.hpp"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8112
diff changeset
    10
#include "string_func.h"
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    11
#include <map>
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    12
7318
632cd0497770 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7254
diff changeset
    13
bool GetDriverParamBool(const char * const *parm, const char *name);
632cd0497770 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7254
diff changeset
    14
int GetDriverParamInt(const char * const *parm, const char *name, int def);
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    15
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    16
class Driver {
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    17
public:
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    18
	virtual const char *Start(const char * const *parm) = 0;
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    19
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    20
	virtual void Stop() = 0;
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    21
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    22
	virtual ~Driver() { }
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    23
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    24
	enum Type {
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    25
		DT_BEGIN = 0,
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    26
		DT_SOUND = 0,
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    27
		DT_MUSIC,
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    28
		DT_VIDEO,
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    29
		DT_END,
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    30
	};
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    31
};
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    32
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    33
DECLARE_POSTFIX_INCREMENT(Driver::Type);
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    34
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    35
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    36
class DriverFactoryBase {
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    37
private:
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    38
	Driver::Type type;
9582
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    39
	const char *name;
7193
d46cbf314baf (svn r10471) -Codechange: implement driver probing priority so that 'preferred' drivers are loaded first
peter1138
parents: 7170
diff changeset
    40
	int priority;
9582
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    41
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    42
	struct StringCompare {
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    43
		bool operator () (const char *a, const char *b) const
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    44
		{
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    45
			return strcmp(a, b) < 0;
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    46
		}
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    47
	};
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    48
3a55657869eb (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 9489
diff changeset
    49
	typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    50
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    51
	static Drivers &GetDrivers()
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    52
	{
9260
b84588111694 (svn r13126) -Fix (r13022) [FS#2009, FS#2010]: driver list should be dynamically allocated as static uninitialistion order is undetermined. The list is freed when the latest driver is removed.
glx
parents: 9159
diff changeset
    53
		static Drivers &s_drivers = *new Drivers();
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    54
		return s_drivers;
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    55
	}
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    56
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    57
	static Driver **GetActiveDriver(Driver::Type type)
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    58
	{
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    59
		static Driver *s_driver[3] = { NULL, NULL, NULL };
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    60
		return &s_driver[type];
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    61
	}
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    62
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    63
	static const char *GetDriverTypeName(Driver::Type type)
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    64
	{
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    65
		static const char *driver_type_name[] = { "sound", "music", "video" };
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    66
		return driver_type_name[type];
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    67
	}
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    68
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    69
protected:
8844
acb298434295 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8214
diff changeset
    70
	void RegisterDriver(const char *name, Driver::Type type, int priority);
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    71
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    72
public:
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    73
	DriverFactoryBase() :
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    74
		name(NULL)
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    75
	{}
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    76
9489
1a097da71d88 (svn r13462) -Codechange: move DriverFactoryBase destructor definition from header file (saves ~16kB)
smatz
parents: 9260
diff changeset
    77
	virtual ~DriverFactoryBase();
9159
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    78
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    79
	/** Shuts down all active drivers
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    80
	 */
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    81
	static void ShutdownDrivers()
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    82
	{
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    83
		for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    84
			Driver *driver = *GetActiveDriver(dt);
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    85
			if (driver != NULL) driver->Stop();
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    86
		}
e8857a691840 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 9111
diff changeset
    87
	}
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    88
8844
acb298434295 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8214
diff changeset
    89
	static const Driver *SelectDriver(const char *name, Driver::Type type);
acb298434295 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8214
diff changeset
    90
	static char *GetDriversInfo(char *p, const char *last);
7170
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    91
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    92
	/**
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    93
	 * Get a nice description of the driver-class.
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    94
	 */
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    95
	virtual const char *GetDescription() = 0;
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    96
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    97
	/**
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    98
	 * Create an instance of this driver-class.
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
    99
	 */
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
   100
	virtual Driver *CreateInstance() = 0;
923946ec324f (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6125
diff changeset
   101
};
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   102
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2186
diff changeset
   103
#endif /* DRIVER_H */