src/driver.cpp
author peter1138
Tue, 22 Jan 2008 07:27:06 +0000
changeset 8374 7a1b6c89cb89
parent 8275 f17d0c863ee3
child 8844 acb298434295
permissions -rw-r--r--
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
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
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6034
diff changeset
     3
/** @file driver.cpp */
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6034
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
#include "stdafx.h"
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     6
#include "openttd.h"
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
     7
#include "debug.h"
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     8
#include "driver.h"
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     9
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: 7045
diff changeset
    10
#include "sound/sound_driver.hpp"
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: 7045
diff changeset
    11
#include "music/music_driver.hpp"
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: 7045
diff changeset
    12
#include "video/video_driver.hpp"
2222
ce4beae3ce18 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    13
8275
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    14
VideoDriver *_video_driver;
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    15
char _ini_videodriver[32];
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    16
int _num_resolutions;
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    17
uint16 _resolutions[32][2];
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    18
uint16 _cur_resolution[2];
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    19
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: 7045
diff changeset
    20
SoundDriver *_sound_driver;
8275
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    21
char _ini_sounddriver[32];
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    22
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: 7045
diff changeset
    23
MusicDriver *_music_driver;
8275
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    24
char _ini_musicdriver[32];
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    25
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8214
diff changeset
    26
char _ini_blitter[32];
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    27
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    28
static const char* GetDriverParam(const char* const* parm, const char* name)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    29
{
2458
dbaf5dffbb28 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2303
diff changeset
    30
	size_t len;
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    31
2224
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    32
	if (parm == NULL) return NULL;
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    33
af2f147779d3 (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    34
	len = strlen(name);
2171
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    35
	for (; *parm != NULL; parm++) {
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    36
		const char* p = *parm;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    37
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    38
		if (strncmp(p, name, len) == 0) {
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    39
			if (p[len] == '=')  return p + len + 1;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    40
			if (p[len] == '\0') return p + len;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    41
		}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    42
	}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    43
	return NULL;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    44
}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    45
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    46
bool GetDriverParamBool(const char* const* parm, const char* name)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    47
{
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    48
	return GetDriverParam(parm, name) != NULL;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    49
}
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    50
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    51
int GetDriverParamInt(const char* const* parm, const char* name, int def)
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    52
{
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    53
	const char* p = GetDriverParam(parm, name);
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    54
	return p != NULL ? atoi(p) : def;
60334c9ca477 (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    55
}