@kmamal/sdl 0.9.5 → 0.9.6-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -103
- package/binding.gyp +25 -5
- package/package.json +7 -4
- package/src/javascript/audio/audio-instance.js +9 -6
- package/src/javascript/cleanup.js +1 -1
- package/src/javascript/clipboard/index.js +2 -1
- package/src/javascript/controller/controller-instance.js +7 -4
- package/src/javascript/enums.js +1 -9
- package/src/javascript/events/index.js +293 -305
- package/src/javascript/index.js +1 -1
- package/src/javascript/joystick/device.js +0 -3
- package/src/javascript/joystick/joystick-instance.js +8 -6
- package/src/javascript/keyboard/index.js +3 -3
- package/src/javascript/keyboard/key-mapping.js +14 -6
- package/src/javascript/mouse/index.js +14 -13
- package/src/javascript/power/index.js +1 -8
- package/src/javascript/sensor/sensor-instance.js +1 -5
- package/src/javascript/video/index.js +0 -5
- package/src/javascript/video/window.js +17 -16
- package/src/native/audio.cpp +178 -0
- package/src/native/audio.h +21 -0
- package/src/native/clipboard.cpp +45 -0
- package/src/native/clipboard.h +13 -0
- package/src/native/cocoa-global.h +8 -0
- package/src/native/cocoa-global.mm +8 -0
- package/src/native/cocoa-window.h +9 -4
- package/src/native/cocoa-window.mm +6 -9
- package/src/native/controller.cpp +160 -0
- package/src/native/controller.h +22 -0
- package/src/native/enums.cpp +339 -0
- package/src/native/enums.h +12 -0
- package/src/native/events.cpp +391 -0
- package/src/native/events.h +70 -0
- package/src/native/global.cpp +361 -0
- package/src/native/global.h +15 -0
- package/src/native/joystick.cpp +394 -0
- package/src/native/joystick.h +29 -0
- package/src/native/keyboard.cpp +51 -0
- package/src/native/keyboard.h +18 -0
- package/src/native/module.cpp +98 -0
- package/src/native/mouse.cpp +186 -0
- package/src/native/mouse.h +21 -0
- package/src/native/power.cpp +23 -0
- package/src/native/power.h +17 -0
- package/src/native/sensor.cpp +124 -0
- package/src/native/sensor.h +21 -0
- package/src/native/video.cpp +95 -0
- package/src/native/video.h +16 -0
- package/src/native/window.cpp +755 -0
- package/src/native/window.h +29 -0
- package/src/types/index.d.ts +91 -49
- package/scripts/test.mjs +0 -12
- package/src/native/asprintf.c +0 -47
- package/src/native/asprintf.h +0 -37
- package/src/native/binding.cpp +0 -1680
- package/src/native/sdl-helpers.cpp +0 -2617
- package/src/native/sdl-helpers.h +0 -182
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
#include "global.h"
|
|
2
|
+
#include "events.h"
|
|
3
|
+
#include "keyboard.h"
|
|
4
|
+
#include "video.h"
|
|
5
|
+
#include "joystick.h"
|
|
6
|
+
#include "controller.h"
|
|
7
|
+
#include "sensor.h"
|
|
8
|
+
#include "power.h"
|
|
9
|
+
#include <SDL.h>
|
|
10
|
+
#include <string>
|
|
11
|
+
#include <sstream>
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
#if defined(__MACOSX__)
|
|
15
|
+
#include "cocoa-global.h"
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
SDL_threadID mainThreadId;
|
|
20
|
+
|
|
21
|
+
int filterEvents(void*, SDL_Event *event) {
|
|
22
|
+
if (SDL_ThreadID() != mainThreadId) { return 1; }
|
|
23
|
+
|
|
24
|
+
if (event->type != SDL_WINDOWEVENT) { return 1; }
|
|
25
|
+
|
|
26
|
+
int window_event_type = event->window.event;
|
|
27
|
+
if (true
|
|
28
|
+
&& window_event_type != SDL_WINDOWEVENT_MOVED
|
|
29
|
+
&& window_event_type != SDL_WINDOWEVENT_SIZE_CHANGED
|
|
30
|
+
) { return 1; }
|
|
31
|
+
|
|
32
|
+
events::dispatchEvent(*event);
|
|
33
|
+
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const char *global::no_error = nullptr;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
Napi::Value
|
|
42
|
+
global::initialize(const Napi::CallbackInfo &info)
|
|
43
|
+
{
|
|
44
|
+
Napi::Env env = info.Env();
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
events::families::DISPLAY = "display";
|
|
48
|
+
events::families::WINDOW = "window";
|
|
49
|
+
events::families::DROP = "drop";
|
|
50
|
+
events::families::KEYBOARD = "keyboard";
|
|
51
|
+
events::families::TEXT = "text";
|
|
52
|
+
events::families::MOUSE = "mouse";
|
|
53
|
+
events::families::JOYSTICK_DEVICE = "joystickDevice";
|
|
54
|
+
events::families::JOYSTICK = "joystick";
|
|
55
|
+
events::families::CONTROLLER = "controller";
|
|
56
|
+
events::families::SENSOR = "sensor";
|
|
57
|
+
events::families::AUDIO_DEVICE = "audioDevice";
|
|
58
|
+
events::families::CLIPBOARD = "clipboard";
|
|
59
|
+
|
|
60
|
+
events::types::DISPLAY_ADD = "displayAdd";
|
|
61
|
+
events::types::DISPLAY_REMOVE = "displayRemove";
|
|
62
|
+
events::types::DISPLAY_ORIENT = "displayOrient";
|
|
63
|
+
events::types::SHOW = "show";
|
|
64
|
+
events::types::HIDE = "hide";
|
|
65
|
+
events::types::EXPOSE = "expose";
|
|
66
|
+
events::types::MOVE = "move";
|
|
67
|
+
events::types::RESIZE = "resize";
|
|
68
|
+
events::types::MINIMIZE = "minimize";
|
|
69
|
+
events::types::MAXIMIZE = "maximize";
|
|
70
|
+
events::types::RESTORE = "restore";
|
|
71
|
+
events::types::FOCUS = "focus";
|
|
72
|
+
events::types::BLUR = "blur";
|
|
73
|
+
events::types::HOVER = "hover";
|
|
74
|
+
events::types::LEAVE = "leave";
|
|
75
|
+
events::types::KEY_DOWN = "keyDown";
|
|
76
|
+
events::types::KEY_UP = "keyUp";
|
|
77
|
+
events::types::TEXT_INPUT = "textInput";
|
|
78
|
+
events::types::MOUSE_MOVE = "mouseMove";
|
|
79
|
+
events::types::MOUSE_BUTTON_DOWN = "mouseButtonDown";
|
|
80
|
+
events::types::MOUSE_BUTTON_UP = "mouseButtonUp";
|
|
81
|
+
events::types::MOUSE_WHEEL = "mouseWheel";
|
|
82
|
+
events::types::DROP_BEGIN = "dropBegin";
|
|
83
|
+
events::types::DROP_COMPLETE = "dropComplete";
|
|
84
|
+
events::types::DROP_FILE = "dropFile";
|
|
85
|
+
events::types::DROP_TEXT = "dropText";
|
|
86
|
+
events::types::CLOSE = "close";
|
|
87
|
+
events::types::DEVICE_ADD = "deviceAdd";
|
|
88
|
+
events::types::DEVICE_REMOVE = "deviceRemove";
|
|
89
|
+
events::types::AXIS_MOTION = "axisMotion";
|
|
90
|
+
events::types::BUTTON_DOWN = "buttonDown";
|
|
91
|
+
events::types::BUTTON_UP = "buttonUp";
|
|
92
|
+
events::types::BALL_MOTION = "ballMotion";
|
|
93
|
+
events::types::HAT_MOTION = "hatMotion";
|
|
94
|
+
events::types::REMAP = "remap";
|
|
95
|
+
events::types::UPDATE = "update";
|
|
96
|
+
|
|
97
|
+
video::formats[SDL_PIXELFORMAT_RGB332] = "rgb332";
|
|
98
|
+
video::formats[SDL_PIXELFORMAT_RGB444] = "rgb444";
|
|
99
|
+
video::formats[SDL_PIXELFORMAT_RGB555] = "rgb555";
|
|
100
|
+
video::formats[SDL_PIXELFORMAT_BGR555] = "bgr555";
|
|
101
|
+
video::formats[SDL_PIXELFORMAT_ARGB4444] = "argb4444";
|
|
102
|
+
video::formats[SDL_PIXELFORMAT_RGBA4444] = "rgba4444";
|
|
103
|
+
video::formats[SDL_PIXELFORMAT_ABGR4444] = "abgr4444";
|
|
104
|
+
video::formats[SDL_PIXELFORMAT_BGRA4444] = "bgra4444";
|
|
105
|
+
video::formats[SDL_PIXELFORMAT_ARGB1555] = "argb1555";
|
|
106
|
+
video::formats[SDL_PIXELFORMAT_RGBA5551] = "rgba5551";
|
|
107
|
+
video::formats[SDL_PIXELFORMAT_ABGR1555] = "abgr1555";
|
|
108
|
+
video::formats[SDL_PIXELFORMAT_BGRA5551] = "bgra5551";
|
|
109
|
+
video::formats[SDL_PIXELFORMAT_RGB565] = "rgb565";
|
|
110
|
+
video::formats[SDL_PIXELFORMAT_BGR565] = "bgr565";
|
|
111
|
+
video::formats[SDL_PIXELFORMAT_RGB24] = "rgb24";
|
|
112
|
+
video::formats[SDL_PIXELFORMAT_BGR24] = "bgr24";
|
|
113
|
+
video::formats[SDL_PIXELFORMAT_RGB888] = "rgb888";
|
|
114
|
+
video::formats[SDL_PIXELFORMAT_RGBX8888] = "rgbx8888";
|
|
115
|
+
video::formats[SDL_PIXELFORMAT_BGR888] = "bgr888";
|
|
116
|
+
video::formats[SDL_PIXELFORMAT_BGRX8888] = "bgrx8888";
|
|
117
|
+
video::formats[SDL_PIXELFORMAT_ARGB8888] = "argb8888";
|
|
118
|
+
video::formats[SDL_PIXELFORMAT_RGBA8888] = "rgba8888";
|
|
119
|
+
video::formats[SDL_PIXELFORMAT_ABGR8888] = "abgr8888";
|
|
120
|
+
video::formats[SDL_PIXELFORMAT_BGRA8888] = "bgra8888";
|
|
121
|
+
video::formats[SDL_PIXELFORMAT_ARGB2101010] = "argb2101010";
|
|
122
|
+
video::formats[SDL_PIXELFORMAT_RGBA32] = "rgba32";
|
|
123
|
+
video::formats[SDL_PIXELFORMAT_ARGB32] = "argb32";
|
|
124
|
+
video::formats[SDL_PIXELFORMAT_BGRA32] = "bgra32";
|
|
125
|
+
video::formats[SDL_PIXELFORMAT_ABGR32] = "abgr32";
|
|
126
|
+
video::formats[SDL_PIXELFORMAT_YV12] = "yv12";
|
|
127
|
+
video::formats[SDL_PIXELFORMAT_IYUV] = "iyuv";
|
|
128
|
+
video::formats[SDL_PIXELFORMAT_YUY2] = "yuy2";
|
|
129
|
+
video::formats[SDL_PIXELFORMAT_UYVY] = "uyvy";
|
|
130
|
+
video::formats[SDL_PIXELFORMAT_YVYU] = "yvyu";
|
|
131
|
+
video::formats[SDL_PIXELFORMAT_NV12] = "nv12";
|
|
132
|
+
video::formats[SDL_PIXELFORMAT_NV21] = "nv21";
|
|
133
|
+
|
|
134
|
+
// joystick::power_levels[SDL_JOYSTICK_POWER_UNKNOWN] = nullptr;
|
|
135
|
+
joystick::power_levels[SDL_JOYSTICK_POWER_EMPTY] = "empty";
|
|
136
|
+
joystick::power_levels[SDL_JOYSTICK_POWER_LOW] = "low";
|
|
137
|
+
joystick::power_levels[SDL_JOYSTICK_POWER_MEDIUM] = "medium";
|
|
138
|
+
joystick::power_levels[SDL_JOYSTICK_POWER_FULL] = "full";
|
|
139
|
+
joystick::power_levels[SDL_JOYSTICK_POWER_WIRED] = "wired";
|
|
140
|
+
joystick::power_levels[SDL_JOYSTICK_POWER_MAX] = "max";
|
|
141
|
+
|
|
142
|
+
// joystick::joystick_types[SDL_JOYSTICK_TYPE_UNKNOWN] = nullptr; // Only possible on error
|
|
143
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_GAMECONTROLLER] = "gamecontroller";
|
|
144
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_WHEEL] = "wheel";
|
|
145
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_ARCADE_STICK] = "arcadestick";
|
|
146
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_FLIGHT_STICK] = "flightstick";
|
|
147
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_DANCE_PAD] = "dancepad";
|
|
148
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_GUITAR] = "guitar";
|
|
149
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_DRUM_KIT] = "drumkit";
|
|
150
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_ARCADE_PAD] = "arcadepad";
|
|
151
|
+
joystick::joystick_types[SDL_JOYSTICK_TYPE_THROTTLE] = "throttle";
|
|
152
|
+
|
|
153
|
+
joystick::hat_positions[SDL_HAT_CENTERED] = "centered";
|
|
154
|
+
joystick::hat_positions[SDL_HAT_UP] = "up";
|
|
155
|
+
joystick::hat_positions[SDL_HAT_RIGHT] = "right";
|
|
156
|
+
joystick::hat_positions[SDL_HAT_DOWN] = "down";
|
|
157
|
+
joystick::hat_positions[SDL_HAT_LEFT] = "left";
|
|
158
|
+
joystick::hat_positions[SDL_HAT_RIGHTUP] = "rightup";
|
|
159
|
+
joystick::hat_positions[SDL_HAT_RIGHTDOWN] = "rightdown";
|
|
160
|
+
joystick::hat_positions[SDL_HAT_LEFTUP] = "leftup";
|
|
161
|
+
joystick::hat_positions[SDL_HAT_LEFTDOWN] = "leftdown";
|
|
162
|
+
|
|
163
|
+
controller::axes[SDL_CONTROLLER_AXIS_LEFTX] = "leftStickX";
|
|
164
|
+
controller::axes[SDL_CONTROLLER_AXIS_LEFTY] = "leftStickY";
|
|
165
|
+
controller::axes[SDL_CONTROLLER_AXIS_RIGHTX] = "rightStickX";
|
|
166
|
+
controller::axes[SDL_CONTROLLER_AXIS_RIGHTY] = "rightStickY";
|
|
167
|
+
controller::axes[SDL_CONTROLLER_AXIS_TRIGGERLEFT] = "leftTrigger";
|
|
168
|
+
controller::axes[SDL_CONTROLLER_AXIS_TRIGGERRIGHT] = "rightTrigger";
|
|
169
|
+
|
|
170
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_DPAD_LEFT] = "dpadLeft";
|
|
171
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_DPAD_RIGHT] = "dpadRight";
|
|
172
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_DPAD_UP] = "dpadUp";
|
|
173
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_DPAD_DOWN] = "dpadDown";
|
|
174
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_A] = "a";
|
|
175
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_B] = "b";
|
|
176
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_X] = "x";
|
|
177
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_Y] = "y";
|
|
178
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_GUIDE] = "guide";
|
|
179
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_BACK] = "back";
|
|
180
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_START] = "start";
|
|
181
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_LEFTSTICK] = "leftStick";
|
|
182
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_RIGHTSTICK] = "rightStick";
|
|
183
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_LEFTSHOULDER] = "leftShoulder";
|
|
184
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_RIGHTSHOULDER] = "rightShoulder";
|
|
185
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_PADDLE1] = "paddle1";
|
|
186
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_PADDLE2] = "paddle2";
|
|
187
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_PADDLE3] = "paddle3";
|
|
188
|
+
controller::buttons[SDL_CONTROLLER_BUTTON_PADDLE4] = "paddle4";
|
|
189
|
+
|
|
190
|
+
// sensor::types[SDL_SENSOR_UNKNOWN] = nullptr;
|
|
191
|
+
sensor::types[SDL_SENSOR_ACCEL] = "accelerometer";
|
|
192
|
+
sensor::types[SDL_SENSOR_GYRO] = "gyroscope";
|
|
193
|
+
sensor::types[SDL_SENSOR_ACCEL_L] = "accelerometer";
|
|
194
|
+
sensor::types[SDL_SENSOR_GYRO_L] = "gyroscope";
|
|
195
|
+
sensor::types[SDL_SENSOR_ACCEL_R] = "accelerometer";
|
|
196
|
+
sensor::types[SDL_SENSOR_GYRO_R] = "gyroscope";
|
|
197
|
+
|
|
198
|
+
// sensor::sides[SDL_SENSOR_UNKNOWN] = nullptr;
|
|
199
|
+
// sensor::sides[SDL_SENSOR_ACCEL] = nullptr;
|
|
200
|
+
// sensor::sides[SDL_SENSOR_GYRO] = nullptr;
|
|
201
|
+
sensor::sides[SDL_SENSOR_ACCEL_L] = "left";
|
|
202
|
+
sensor::sides[SDL_SENSOR_GYRO_L] = "left";
|
|
203
|
+
sensor::sides[SDL_SENSOR_ACCEL_R] = "right";
|
|
204
|
+
sensor::sides[SDL_SENSOR_GYRO_R] = "right";
|
|
205
|
+
|
|
206
|
+
// power::states[SDL_POWERSTATE_UNKNOWN] = nullptr;
|
|
207
|
+
power::states[SDL_POWERSTATE_NO_BATTERY] = "noBattery";
|
|
208
|
+
power::states[SDL_POWERSTATE_ON_BATTERY] = "battery";
|
|
209
|
+
power::states[SDL_POWERSTATE_CHARGING] = "charging";
|
|
210
|
+
power::states[SDL_POWERSTATE_CHARGED] = "charged";
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0");
|
|
214
|
+
|
|
215
|
+
if (SDL_Init(0
|
|
216
|
+
| SDL_INIT_EVENTS
|
|
217
|
+
| SDL_INIT_JOYSTICK
|
|
218
|
+
| SDL_INIT_GAMECONTROLLER
|
|
219
|
+
| SDL_INIT_HAPTIC
|
|
220
|
+
| SDL_INIT_SENSOR
|
|
221
|
+
) < 0) {
|
|
222
|
+
std::ostringstream message;
|
|
223
|
+
message << "SDL_Init() error: " << SDL_GetError();
|
|
224
|
+
SDL_ClearError();
|
|
225
|
+
throw Napi::Error::New(env, message.str());
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
SDL_version sdl_compile_version;
|
|
229
|
+
SDL_VERSION(&sdl_compile_version);
|
|
230
|
+
|
|
231
|
+
Napi::Object compile_version = Napi::Object::New(env);
|
|
232
|
+
compile_version.Set("major", Napi::Number::New(env, sdl_compile_version.major));
|
|
233
|
+
compile_version.Set("minor", Napi::Number::New(env, sdl_compile_version.minor));
|
|
234
|
+
compile_version.Set("patch", Napi::Number::New(env, sdl_compile_version.patch));
|
|
235
|
+
|
|
236
|
+
SDL_version sdl_runtime_version;
|
|
237
|
+
SDL_GetVersion(&sdl_runtime_version);
|
|
238
|
+
|
|
239
|
+
Napi::Object runtime_version = Napi::Object::New(env);
|
|
240
|
+
runtime_version.Set("major", Napi::Number::New(env, sdl_runtime_version.major));
|
|
241
|
+
runtime_version.Set("minor", Napi::Number::New(env, sdl_runtime_version.minor));
|
|
242
|
+
runtime_version.Set("patch", Napi::Number::New(env, sdl_runtime_version.patch));
|
|
243
|
+
|
|
244
|
+
Napi::Object versions = Napi::Object::New(env);
|
|
245
|
+
versions.Set("compile", compile_version);
|
|
246
|
+
versions.Set("runtime", runtime_version);
|
|
247
|
+
|
|
248
|
+
const char *platform_name = SDL_GetPlatform();
|
|
249
|
+
|
|
250
|
+
Napi::Array all_video_drivers = Napi::Array::New(env);
|
|
251
|
+
|
|
252
|
+
int num_video_drivers = SDL_GetNumVideoDrivers();
|
|
253
|
+
if (num_video_drivers < 0) {
|
|
254
|
+
std::ostringstream message;
|
|
255
|
+
message << "SDL_GetNumVideoDrivers() error: " << SDL_GetError();
|
|
256
|
+
SDL_ClearError();
|
|
257
|
+
throw Napi::Error::New(env, message.str());
|
|
258
|
+
}
|
|
259
|
+
for (int i = 0; i < num_video_drivers; i ++) {
|
|
260
|
+
const char *name = SDL_GetVideoDriver(i);
|
|
261
|
+
if(name == nullptr) {
|
|
262
|
+
std::ostringstream message;
|
|
263
|
+
message << "SDL_GetVideoDriver(" << i << ") error: " << SDL_GetError();
|
|
264
|
+
SDL_ClearError();
|
|
265
|
+
throw Napi::Error::New(env, message.str());
|
|
266
|
+
}
|
|
267
|
+
all_video_drivers.Set(all_video_drivers.Length(), Napi::String::New(env, name));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
Napi::Value current_video_driver;
|
|
271
|
+
if (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) {
|
|
272
|
+
const char *name = SDL_GetCurrentVideoDriver();
|
|
273
|
+
if(name == nullptr) {
|
|
274
|
+
std::ostringstream message;
|
|
275
|
+
message << "SDL_GetCurrentVideoDriver() error: " << SDL_GetError();
|
|
276
|
+
SDL_ClearError();
|
|
277
|
+
throw Napi::Error::New(env, message.str());
|
|
278
|
+
}
|
|
279
|
+
current_video_driver = Napi::String::New(env, name);
|
|
280
|
+
} else {
|
|
281
|
+
current_video_driver = env.Null();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
Napi::Object video_drivers = Napi::Object::New(env);
|
|
285
|
+
video_drivers.Set("all", all_video_drivers);
|
|
286
|
+
video_drivers.Set("current", current_video_driver);
|
|
287
|
+
|
|
288
|
+
Napi::Array all_audio_drivers = Napi::Array::New(env);
|
|
289
|
+
|
|
290
|
+
int num_audio_drivers = SDL_GetNumAudioDrivers();
|
|
291
|
+
if (num_audio_drivers < 0) {
|
|
292
|
+
std::ostringstream message;
|
|
293
|
+
message << "SDL_GetNumAudioDrivers() error: " << SDL_GetError();
|
|
294
|
+
SDL_ClearError();
|
|
295
|
+
throw Napi::Error::New(env, message.str());
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
for (int i = 0; i < num_audio_drivers; i ++) {
|
|
299
|
+
const char *name = SDL_GetAudioDriver(i);
|
|
300
|
+
if(name == nullptr) {
|
|
301
|
+
std::ostringstream message;
|
|
302
|
+
message << "SDL_GetAudioDriver(" << i << ") error: " << SDL_GetError();
|
|
303
|
+
SDL_ClearError();
|
|
304
|
+
throw Napi::Error::New(env, message.str());
|
|
305
|
+
}
|
|
306
|
+
all_audio_drivers.Set(all_audio_drivers.Length(), Napi::String::New(env, name));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
Napi::Value current_audio_driver;
|
|
310
|
+
if (SDL_InitSubSystem(SDL_INIT_AUDIO) == 0) {
|
|
311
|
+
const char *name = SDL_GetCurrentAudioDriver();
|
|
312
|
+
if(name == nullptr) {
|
|
313
|
+
std::ostringstream message;
|
|
314
|
+
message << "SDL_GetCurrentAudioDriver() error: " << SDL_GetError();
|
|
315
|
+
SDL_ClearError();
|
|
316
|
+
throw Napi::Error::New(env, message.str());
|
|
317
|
+
}
|
|
318
|
+
current_audio_driver = Napi::String::New(env, name);
|
|
319
|
+
} else {
|
|
320
|
+
current_audio_driver = env.Null();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
Napi::Object audio_drivers = Napi::Object::New(env);
|
|
324
|
+
audio_drivers.Set("all", all_audio_drivers);
|
|
325
|
+
audio_drivers.Set("current", current_audio_driver);
|
|
326
|
+
|
|
327
|
+
Napi::Object drivers = Napi::Object::New(env);
|
|
328
|
+
drivers.Set("video", video_drivers);
|
|
329
|
+
drivers.Set("audio", audio_drivers);
|
|
330
|
+
|
|
331
|
+
SDL_ClearError();
|
|
332
|
+
global::no_error = SDL_GetError();
|
|
333
|
+
|
|
334
|
+
mainThreadId = SDL_ThreadID();
|
|
335
|
+
SDL_SetEventFilter(filterEvents, nullptr);
|
|
336
|
+
|
|
337
|
+
keyboard::keys = SDL_GetKeyboardState(&keyboard::num_keys);
|
|
338
|
+
SDL_StartTextInput(); // TODO
|
|
339
|
+
|
|
340
|
+
#if defined(__MACOSX__)
|
|
341
|
+
reenableInertialScrolling();
|
|
342
|
+
#endif
|
|
343
|
+
|
|
344
|
+
Napi::Object result = Napi::Object::New(env);
|
|
345
|
+
result.Set("version", versions);
|
|
346
|
+
result.Set("platform", Napi::String::New(env, platform_name));
|
|
347
|
+
result.Set("drivers", drivers);
|
|
348
|
+
|
|
349
|
+
return result;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
Napi::Value
|
|
354
|
+
global::cleanup(const Napi::CallbackInfo &info)
|
|
355
|
+
{
|
|
356
|
+
Napi::Env env = info.Env();
|
|
357
|
+
|
|
358
|
+
SDL_Quit();
|
|
359
|
+
|
|
360
|
+
return env.Undefined();
|
|
361
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#ifndef _GLOBAL_H_
|
|
2
|
+
#define _GLOBAL_H_
|
|
3
|
+
|
|
4
|
+
#include <napi.h>
|
|
5
|
+
|
|
6
|
+
namespace global {
|
|
7
|
+
|
|
8
|
+
extern const char *no_error;
|
|
9
|
+
|
|
10
|
+
Napi::Value initialize(const Napi::CallbackInfo &info);
|
|
11
|
+
Napi::Value cleanup(const Napi::CallbackInfo &info);
|
|
12
|
+
|
|
13
|
+
}; // namespace global
|
|
14
|
+
|
|
15
|
+
#endif // _GLOBAL_H_
|