File: opendingux.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (217 lines) | stat: -rw-r--r-- 7,787 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program 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, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#define FORBIDDEN_SYMBOL_EXCEPTION_system

#include "common/scummsys.h"
#include "common/config-manager.h"
#include "common/translation.h"

#include "backends/graphics/opendingux/opendingux-graphics.h"
#include "backends/platform/sdl/opendingux/opendingux.h"

#include "backends/fs/posix/posix-fs-factory.h"
#include "backends/fs/posix/posix-fs.h"
#include "backends/saves/default/default-saves.h"

#include "backends/keymapper/action.h"
#include "backends/keymapper/keymapper-defaults.h"
#include "backends/keymapper/hardware-input.h"
#include "backends/keymapper/keymap.h"
#include "backends/keymapper/keymapper.h"

#define SCUMM_DIR	"~/.scummvm"
#define CONFIG_FILE	"~/.scummvmrc"
#define SAVE_PATH	"~/.scummvm/saves"
#define LOG_FILE	"~/.scummvm/scummvm.log"
#define JOYSTICK_DIR	"/sys/devices/platform/joystick"

static const Common::KeyTableEntry odKeyboardButtons[] = {
	// I18N: Hardware key
	{ "JOY_A",		Common::KEYCODE_LCTRL,		_s("A")			},
	// I18N: Hardware key
	{ "JOY_B",		Common::KEYCODE_LALT,		_s("B")			},
	// I18N: Hardware key
	{ "JOY_X",		Common::KEYCODE_SPACE,		_s("X")			},
	// I18N: Hardware key
	{ "JOY_Y",		Common::KEYCODE_LSHIFT,		_s("Y")			},
	// I18N: Hardware key
	{ "JOY_BACK",		Common::KEYCODE_ESCAPE,		_s("Select")		},
	// I18N: Hardware key
	{ "JOY_START",		Common::KEYCODE_RETURN,		_s("Start")		},
	// I18N: Hardware key
	{ "JOY_LEFT_SHOULDER",	Common::KEYCODE_TAB,		_s("L")			},
	// I18N: Hardware key
	{ "JOY_RIGHT_SHOULDER", Common::KEYCODE_BACKSPACE,	_s("R")			},
	{ "JOY_UP",		Common::KEYCODE_UP,		_s("D-pad Up")	},
	{ "JOY_DOWN",		Common::KEYCODE_DOWN,		_s("D-pad Down")	},
	{ "JOY_LEFT",		Common::KEYCODE_LEFT,		_s("D-pad Left")	},
	{ "JOY_RIGHT",		Common::KEYCODE_RIGHT,		_s("D-pad Right")	},
	{nullptr,			Common::KEYCODE_INVALID,	nullptr			}
};

static const Common::HardwareInputTableEntry odJoystickButtons[] = {
	// I18N: Hardware key
	{ "JOY_LEFT_TRIGGER",	Common::JOYSTICK_BUTTON_LEFT_STICK,	_s("L3")	 },
	{ nullptr,		0,					nullptr		 }
};

static const Common::AxisTableEntry odJoystickAxes[] = {
	{ "JOY_LEFT_STICK_X",  Common::JOYSTICK_AXIS_LEFT_STICK_X,  Common::kAxisTypeFull, _s("Left Stick X")  },
	{ "JOY_LEFT_STICK_Y",  Common::JOYSTICK_AXIS_LEFT_STICK_Y,  Common::kAxisTypeFull, _s("Left Stick Y")  },
	{ nullptr,	       0,				    Common::kAxisTypeFull, nullptr	       }
};

Common::KeymapperDefaultBindings *OSystem_SDL_Opendingux::getKeymapperDefaultBindings() {
	Common::KeymapperDefaultBindings *keymapperDefaultBindings = new Common::KeymapperDefaultBindings();

	if (!Posix::assureDirectoryExists(JOYSTICK_DIR)) {
		keymapperDefaultBindings->setDefaultBinding(Common::kGlobalKeymapName, "VMOUSEUP", "JOY_UP");
		keymapperDefaultBindings->setDefaultBinding(Common::kGlobalKeymapName, "VMOUSEDOWN", "JOY_DOWN");
		keymapperDefaultBindings->setDefaultBinding(Common::kGlobalKeymapName, "VMOUSELEFT", "JOY_LEFT");
		keymapperDefaultBindings->setDefaultBinding(Common::kGlobalKeymapName, "VMOUSERIGHT", "JOY_RIGHT");
		keymapperDefaultBindings->setDefaultBinding(Common::kGuiKeymapName, "UP", "");
		keymapperDefaultBindings->setDefaultBinding(Common::kGuiKeymapName, "DOWN", "");
		keymapperDefaultBindings->setDefaultBinding(Common::kGuiKeymapName, "LEFT", "");
		keymapperDefaultBindings->setDefaultBinding(Common::kGuiKeymapName, "RIGHT", "");
		keymapperDefaultBindings->setDefaultBinding("engine-default", "UP", "");
		keymapperDefaultBindings->setDefaultBinding("engine-default", "DOWN", "");
		keymapperDefaultBindings->setDefaultBinding("engine-default", "LEFT", "");
		keymapperDefaultBindings->setDefaultBinding("engine-default", "RIGHT", "");
	}

	return keymapperDefaultBindings;
}

void OSystem_SDL_Opendingux::init() {

	_fsFactory = new POSIXFilesystemFactory();
	if (!Posix::assureDirectoryExists(SCUMM_DIR)) {
		system("mkdir " SCUMM_DIR);
	}

	// Invoke parent implementation of this method
	OSystem_SDL::init();
}

void OSystem_SDL_Opendingux::initBackend() {
#ifdef RS90
	ConfMan.registerDefault("fullscreen", false);
#else
	ConfMan.registerDefault("fullscreen", true);
#endif
	ConfMan.registerDefault("aspect_ratio", true);
	ConfMan.registerDefault("themepath", Common::Path("./themes"));
	ConfMan.registerDefault("extrapath", Common::Path("./engine-data"));
	ConfMan.registerDefault("gui_theme", "builtin");
	ConfMan.registerDefault("scale_factor", "1");

	ConfMan.setBool("fullscreen", true);
	ConfMan.setInt("joystick_num", 0);

	if (!ConfMan.hasKey("aspect_ratio")) {
		ConfMan.setBool("aspect_ratio", true);
	}
	if (!ConfMan.hasKey("themepath")) {
		ConfMan.setPath("themepath", "./themes");
	}
	if (!ConfMan.hasKey("extrapath")) {
		ConfMan.setPath("extrapath", "./engine-data");
	}
	if (!ConfMan.hasKey("savepath")) {
		ConfMan.setPath("savepath", SAVE_PATH);
	}
	if (!ConfMan.hasKey("gui_theme")) {
		ConfMan.set("gui_theme", "builtin");
	}
	if (!ConfMan.hasKey("scale_factor")) {
		ConfMan.set("scale_factor", "1");
	}
	if (!ConfMan.hasKey("opl_driver")) {
		ConfMan.set("opl_driver", "db");
	}
	if (!ConfMan.hasKey("kbdmouse_speed")) {
		ConfMan.setInt("kbdmouse_speed", 2);
	}
#ifdef LEPUS
	if (!ConfMan.hasKey("output_rate")) {
		ConfMan.set("output_rate", "22050");
	}
#elif RS90
	if (!ConfMan.hasKey("output_rate")) {
                ConfMan.set("output_rate", "11025");
        }
#endif
	// Create the savefile manager
	if (_savefileManager == nullptr) {
		_savefileManager = new DefaultSaveFileManager(SAVE_PATH);
	}

	if (!_eventSource)
		_eventSource = new SdlEventSource();
	if (!_graphicsManager)
		_graphicsManager = new OpenDinguxGraphicsManager(_eventSource, _window);

	OSystem_SDL::initBackend();
}

Common::Path OSystem_SDL_Opendingux::getDefaultConfigFileName() {
	return CONFIG_FILE;

}

Common::Path OSystem_SDL_Opendingux::getDefaultLogFileName() {
	return LOG_FILE;
}

bool OSystem_SDL_Opendingux::hasFeature(Feature f) {
	switch (f) {
	case kFeatureFullscreenMode:
	case kFeatureAspectRatioCorrection:
		return false;
	case kFeatureKbdMouseSpeed:
		return true;
	default:
		return OSystem_SDL::hasFeature(f);
	}
}

void OSystem_SDL_Opendingux::setFeatureState(Feature f, bool enable) {
	OSystem_SDL::setFeatureState(f, enable);
	}

bool OSystem_SDL_Opendingux::getFeatureState(Feature f) {
	return OSystem_SDL::getFeatureState(f);
}

Common::HardwareInputSet *OSystem_SDL_Opendingux::getHardwareInputSet() {
	using namespace Common;

	CompositeHardwareInputSet *inputSet = new CompositeHardwareInputSet();

	// Users may use USB mice - keyboards currently not possible with SDL1 as it conflicts with gpios
	inputSet->addHardwareInputSet(new MouseHardwareInputSet(defaultMouseButtons));
	//inputSet->addHardwareInputSet(new KeyboardHardwareInputSet(defaultKeys, defaultModifiers));
	inputSet->addHardwareInputSet(new KeyboardHardwareInputSet(odKeyboardButtons, defaultModifiers));
	inputSet->addHardwareInputSet(new JoystickHardwareInputSet(odJoystickButtons, odJoystickAxes));

	return inputSet;
}