annotate src/driver.cpp @ 9436:b3969ef775ba draft

(svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
author smatz <smatz@openttd.org>
date Sun, 01 Jun 2008 15:08:14 +0000
parents d48433370037
children 47924a4b2ad4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
9111
d48433370037 (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 <rubidium@openttd.org>
parents: 8844
diff changeset
3 /** @file driver.cpp Base for all driver handling. */
6125
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 6034
diff changeset
4
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
6 #include "openttd.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
7 #include "debug.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
8 #include "driver.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
9
7170
c6917d8e8c25 (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138 <peter1138@openttd.org>
parents: 7045
diff changeset
10 #include "sound/sound_driver.hpp"
c6917d8e8c25 (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138 <peter1138@openttd.org>
parents: 7045
diff changeset
11 #include "music/music_driver.hpp"
c6917d8e8c25 (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138 <peter1138@openttd.org>
parents: 7045
diff changeset
12 #include "video/video_driver.hpp"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13
8275
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
14 VideoDriver *_video_driver;
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
15 char _ini_videodriver[32];
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
16 int _num_resolutions;
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
17 uint16 _resolutions[32][2];
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
18 uint16 _cur_resolution[2];
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
19
7170
c6917d8e8c25 (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138 <peter1138@openttd.org>
parents: 7045
diff changeset
20 SoundDriver *_sound_driver;
8275
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
21 char _ini_sounddriver[32];
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
22
7170
c6917d8e8c25 (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138 <peter1138@openttd.org>
parents: 7045
diff changeset
23 MusicDriver *_music_driver;
8275
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
24 char _ini_musicdriver[32];
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
25
27c91897317f (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8214
diff changeset
26 char _ini_blitter[32];
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
27
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
28 static const char* GetDriverParam(const char* const* parm, const char* name)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
29 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
30 size_t len;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
31
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
32 if (parm == NULL) return NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
33
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34 len = strlen(name);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
35 for (; *parm != NULL; parm++) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
36 const char* p = *parm;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
37
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
38 if (strncmp(p, name, len) == 0) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
39 if (p[len] == '=') return p + len + 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
40 if (p[len] == '\0') return p + len;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
41 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
42 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
43 return NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
44 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
45
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
46 bool GetDriverParamBool(const char* const* parm, const char* name)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
47 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
48 return GetDriverParam(parm, name) != NULL;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
49 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
50
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
51 int GetDriverParamInt(const char* const* parm, const char* name, int def)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
52 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
53 const char* p = GetDriverParam(parm, name);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
54 return p != NULL ? atoi(p) : def;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
55 }
8844
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
56
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
57 /**
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
58 * Find the requested driver and return its class.
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
59 * @param name the driver to select.
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
60 * @post Sets the driver so GetCurrentDriver() returns it too.
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
61 */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
62 const Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
63 {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
64 if (GetDrivers().size() == 0) return NULL;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
65
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
66 if (*name == '\0') {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
67 /* Probe for this driver */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
68 for (int priority = 10; priority >= 0; priority--) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
69 Drivers::iterator it = GetDrivers().begin();
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
70 for (; it != GetDrivers().end(); ++it) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
71 DriverFactoryBase *d = (*it).second;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
72
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
73 /* Check driver type */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
74 if (d->type != type) continue;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
75 if (d->priority != priority) continue;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
76
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
77 Driver *newd = d->CreateInstance();
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
78 const char *err = newd->Start(NULL);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
79 if (err == NULL) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
80 DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
81 delete *GetActiveDriver(type);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
82 *GetActiveDriver(type) = newd;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
83 return newd;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
84 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
85
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
86 DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
87 delete newd;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
88 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
89 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
90 error("Couldn't find any suitable %s driver", GetDriverTypeName(type));
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
91 } else {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
92 char *parm;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
93 char buffer[256];
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
94 const char *parms[32];
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
95
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
96 /* Extract the driver name and put parameter list in parm */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
97 strecpy(buffer, name, lastof(buffer));
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
98 parm = strchr(buffer, ':');
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
99 parms[0] = NULL;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
100 if (parm != NULL) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
101 uint np = 0;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
102 /* Tokenize the parm. */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
103 do {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
104 *parm++ = '\0';
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
105 if (np < lengthof(parms) - 1) parms[np++] = parm;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
106 while (*parm != '\0' && *parm != ',') parm++;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
107 } while (*parm == ',');
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
108 parms[np] = NULL;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
109 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
110
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
111 /* Find this driver */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
112 Drivers::iterator it = GetDrivers().begin();
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
113 for (; it != GetDrivers().end(); ++it) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
114 DriverFactoryBase *d = (*it).second;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
115
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
116 /* Check driver type */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
117 if (d->type != type) continue;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
118
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
119 /* Check driver name */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
120 if (strcasecmp(buffer, d->name) != 0) continue;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
121
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
122 /* Found our driver, let's try it */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
123 Driver *newd = d->CreateInstance();
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
124
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
125 const char *err = newd->Start(parms);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
126 if (err != NULL) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
127 delete newd;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
128 error("Unable to load driver '%s'. The error was: %s", d->name, err);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
129 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
130
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
131 DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
132 delete *GetActiveDriver(type);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
133 *GetActiveDriver(type) = newd;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
134 return newd;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
135 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
136 error("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
137 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
138 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
139
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
140 /**
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
141 * Register a driver internally, based on its name.
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
142 * @param name the name of the driver.
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
143 * @note an assert() will be trigger if 2 driver with the same name try to register.
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
144 */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
145 void DriverFactoryBase::RegisterDriver(const char *name, Driver::Type type, int priority)
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
146 {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
147 /* Don't register nameless Drivers */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
148 if (name == NULL) return;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
149
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
150 this->name = strdup(name);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
151 this->type = type;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
152 this->priority = priority;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
153
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
154 /* Prefix the name with driver type to make it unique */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
155 char buf[32];
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
156 strecpy(buf, GetDriverTypeName(type), lastof(buf));
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
157 strecpy(buf + 5, name, lastof(buf));
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
158
9436
b3969ef775ba (svn r13351) -Codechange: disable warnings about unused variable for builds without asserts
smatz <smatz@openttd.org>
parents: 9111
diff changeset
159 std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(buf, this));
8844
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
160 assert(P.second);
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
161 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
162
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
163 /**
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
164 * Build a human readable list of available drivers, grouped by type.
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
165 */
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
166 char *DriverFactoryBase::GetDriversInfo(char *p, const char *last)
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
167 {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
168 for (Driver::Type type = Driver::DT_BEGIN; type != Driver::DT_END; type++) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
169 p += snprintf(p, last - p, "List of %s drivers:\n", GetDriverTypeName(type));
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
170
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
171 for (int priority = 10; priority >= 0; priority--) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
172 Drivers::iterator it = GetDrivers().begin();
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
173 for (; it != GetDrivers().end(); it++) {
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
174 DriverFactoryBase *d = (*it).second;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
175 if (d->type != type) continue;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
176 if (d->priority != priority) continue;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
177 p += snprintf(p, last - p, "%18s: %s\n", d->name, d->GetDescription());
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
178 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
179 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
180
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
181 p += snprintf(p, last - p, "\n");
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
182 }
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
183
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
184 return p;
7827dedcad92 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz <smatz@openttd.org>
parents: 8275
diff changeset
185 }