-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrudl.c
More file actions
338 lines (303 loc) · 8.05 KB
/
Copy pathrudl.c
File metadata and controls
338 lines (303 loc) · 8.05 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/* RUDL - a C library wrapping SDL for use in Ruby. Copyright (C) 2001 Danny van Bruggen */
#include "rudl.h"
#include "rudl_audio.h"
#include "rudl_cdrom.h"
#include "rudl_events.h"
#include "rudl_joystick.h"
#include "rudl_keyboard.h"
#include "rudl_mouse.h"
#include "rudl_sfont.h"
#include "rudl_timer.h"
#include "rudl_ttf.h"
#include "rudl_video.h"
#include "rudl_flxplay.h"
#include "rudl_net.h"
// For getting versions:
#ifdef HAVE_SDL_MIXER_H
#include "SDL_mixer.h"
#ifndef MIX_MAJOR_VERSION
#define MIX_MAJOR_VERSION 0
#define MIX_MINOR_VERSION 0
#endif
#endif
#ifdef HAVE_SMPEG_SMPEG_H
#include "smpeg/smpeg.h"
#endif
#ifdef HAVE_SDL_GFXPRIMITIVES_H
#include "SDL_gfxPrimitives.h"
#endif
#ifdef HAVE_SDL_FRAMERATE_H
#include "SDL_framerate.h"
#endif
#ifdef HAVE_SDL_IMAGEFILTER_H
#include "SDL_imageFilter.h"
#endif
#ifdef HAVE_SDL_ROTOZOOM_H
#include "SDL_rotozoom.h"
#endif
#ifdef HAVE_SDL_NET_H
#include "SDL_net.h"
#endif
//
bool sDLInitWasCalled=false;
VALUE id_new;
VALUE id_clone;
ID id_begin; // For ranges
ID id_end;
VALUE moduleRUDL;
VALUE classPit;
VALUE classSDLError;
VALUE moduleConstant;
#if defined(macintosh)
#if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON
QDGlobals qd;
#endif
#endif
///////////////////////////////// "CORE"
void initSDL()
{
if(!sDLInitWasCalled){
#ifdef MS_WIN32
SDL_RegisterApp("RUDL window", 0, GetModuleHandle(NULL));
#endif
#if defined(macintosh)
#if !TARGET_API_MAC_CARBON
SDL_InitQuickDraw(&qd);
#endif
#endif
rb_eval_string("Kernel.at_exit {RUDL.at_exit}");
sDLInitWasCalled=true;
}
}
static VALUE RUDL_at_exit(VALUE obj)
{
DEBUG_S("Reached RUDL_at_exit");
#ifdef HAVE_SDL_NET_H
quitNet();
#endif
quitJoystick();
#ifdef HAVE_SDL_MIXER_H
quitAudio();
#endif
quitVideo();
quitTTF();
DEBUG_S("Quitting the rest of it");
SDL_Quit();
return Qnil;
}
__inline__ Uint32 PARAMETER2FLAGS(VALUE flagsArg)
{
Uint32 flags=0;
int i;
VALUE tmp;
if(rb_obj_is_kind_of(flagsArg, rb_cArray)){
for(i=0; i<RARRAY(flagsArg)->len; i++){
tmp=rb_ary_entry(flagsArg, i);
flags|=NUM2UINT(tmp);
}
}else{
flags=NUM2UINT(flagsArg);
}
return flags;
}
__inline__ VALUE rb_range_first(VALUE obj)
{
return rb_ivar_get(obj, id_begin);
}
__inline__ VALUE rb_range_last(VALUE obj)
{
return rb_ivar_get(obj, id_end);
}
VALUE RUDL_init(VALUE obj, VALUE flags)
{
initSDL();
return UINT2NUM(SDL_Init(PARAMETER2FLAGS(flags)));
}
VALUE RUDL_quit(VALUE obj, VALUE flags)
{
SDL_QuitSubSystem(PARAMETER2FLAGS(flags));
return obj;
}
VALUE RUDL_is_init(VALUE obj, VALUE flags)
{
initSDL();
return UINT2NUM(SDL_WasInit(PARAMETER2FLAGS(flags)));
}
/**
@file RUDL
@module RUDL
Module @RUDL contains all @RUDL classes as inner classes.
It has some class methods of its own too.
*/
/**@section Class Methods
@method versions
Returns a hash of library names with their versions that are supported by @RUDL.
This list was determined when @RUDL was compiled for a certain system,
and might change when other libraries have been installed or removed
and @RUDL is recompiled.
Versions are @RUDL::Version objects.
This includes "RUDL" itself.
*/
static VALUE RUDL_versions(VALUE self)
{
char versions[8192]; // Ugh
sprintf(versions, "{"
"'RUDL'=>RUDL::Version.new(%i,%i,%i),\n"
"'SDL'=>RUDL::Version.new(%i,%i,%i),\n"
"'BitMask'=>RUDL::Version.new,\n"
#ifdef HAVE_SDL_IMAGE_H
"'SDL_image'=>RUDL::Version.new,\n"
#endif
#ifdef HAVE_SDL_MIXER_H
"'SDL_mixer'=>RUDL::Version.new(%i, %i),\n"
#endif
#ifdef HAVE_SDL_TTF_H
"'SDL_ttf'=>RUDL::Version.new,\n"
#endif
#ifdef HAVE_SDL_GFXPRIMITIVES_H
"'SDL_gfxPrimitives'=>RUDL::Version.new(%i, %i),\n"
#endif
#ifdef HAVE_SDL_FRAMERATE_H
// not used "'SDL_framerate'=>RUDL::Version.new,\n"
#endif
#ifdef HAVE_SDL_IMAGEFILTER_H
// "'SDL_imagefilter'=>RUDL::Version.new,\n"
#endif
#ifdef HAVE_SDL_ROTOZOOM_H
"'SDL_rotozoom'=>RUDL::Version.new,\n"
#endif
#ifdef HAVE_SMPEG_SMPEG_H
"'smpeg'=>RUDL::Version.new(%i, %i, %i),\n"
#endif
#ifdef HAVE_SDL_NET_H
"'net'=>RUDL::Version.new,\n"
#endif
"}"
,RUDLVERSION_MAJOR, RUDLVERSION_MINOR, RUDLVERSION_PATCH
,SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL
// no version info (BitMask)
#ifdef HAVE_SDL_IMAGE_H
// no version info
#endif
#ifdef HAVE_SDL_MIXER_H
,MIX_MAJOR_VERSION ,MIX_MINOR_VERSION
#endif
#ifdef HAVE_SDL_TTF_H
// no version info
#endif
#ifdef HAVE_SDL_GFXPRIMITIVES_H
,SDL_GFXPRIMITIVES_MAJOR, SDL_GFXPRIMITIVES_MINOR
#endif
#ifdef HAVE_SDL_FRAMERATE_H
// no version info
#endif
#ifdef HAVE_SDL_IMAGEFILTER_H
// no version info
#endif
#ifdef HAVE_SDL_ROTOZOOM_H
// no version info
#endif
#ifdef HAVE_SMPEG_SMPEG_H
,SMPEG_MAJOR_VERSION, SMPEG_MINOR_VERSION, SMPEG_PATCHLEVEL
#endif
#ifdef HAVE_SDL_NET_H
// no version info
#endif
);
return rb_eval_string(versions);
}
//////////////////////////////////
DECKLSPECKL void Init_RUDL()
{
DEBUG_S("Init_RUDL()");
moduleRUDL=rb_define_module("RUDL");
rb_define_singleton_method(moduleRUDL, "at_exit", RUDL_at_exit, 0);
rb_define_singleton_method(moduleRUDL, "init_subsystem", RUDL_init, 1);
rb_define_singleton_method(moduleRUDL, "quit_subsystem", RUDL_quit, 1);
rb_define_singleton_method(moduleRUDL, "is_subsystem_init", RUDL_is_init, 1);
rb_define_singleton_method(moduleRUDL, "versions", RUDL_versions, 0);
/**
@class RUDL::SDLError
SDLError is the class that is thrown when SDL or RUDL find an SDL-specific
problem.
*/
classSDLError=rb_define_class("SDLError", rb_eStandardError);
/**
@class RUDL::Pit
The @Pit is where the things end up that don't fit anywhere else.
The methods are documented where they fit best.
*/
classPit=rb_define_class_under(moduleRUDL, "Pit", rb_cObject);
/**
@class RUDL::Version
@Version is the class used for version comparisons.
It defines four version levels: major, minor, patch and deepest.
*/
/**
@method initialize( major=0, minor=0, patch=0, deepest=0 )
Initializes a new Version object.
*/
/**
@method <( v )
Compares this version number with the one in @v.
Returns <code>true</code> if older.
*/
/**
@method to_s
Returns the version as a string: "major.minor.patch.deepest"
*/
rb_eval_string(
"module RUDL\n"
" class Version\n"
" attr_accessor :major, :minor, :patch, :deepest\n"
" def <(v)\n"
" (@major<v.major) or\n"
" (@major==v.major and @minor<v.minor) or\n"
" (@major==v.major and @minor==v.minor and @patch<v.patch) or\n"
" (@major==v.major and @minor==v.minor and @patch==v.patch and @deepest<v.deepest)\n"
" end\n"
" def initialize(major=0, minor=0, patch=0, deepest=0)\n"
" @major=major\n"
" @minor=minor\n"
" @patch=patch\n"
" @deepest=deepest\n"
" end\n"
" def to_s\n"
" \"#{major}.#{minor}.#{patch}.#{deepest}\"\n"
" end\n"
" end\n"
"end\n"
);
id_begin=rb_intern("begin");
id_end=rb_intern("end");
id_new=rb_intern("new");
id_clone=rb_intern("clone");
/**
@class RUDL::Constants
All for the hacked @init_subsystem and @quit_subsystem,
which should officially never be needed:
<code>INIT_TIMER, INIT_AUDIO, INIT_VIDEO, INIT_CDROM, INIT_JOYSTICK, INIT_NOPARACHUTE, INIT_EVERYTHING</code>
*/
moduleConstant=rb_define_module_under(moduleRUDL, "Constant");
DEC_CONST(INIT_TIMER);
DEC_CONST(INIT_AUDIO);
DEC_CONST(INIT_VIDEO);
DEC_CONST(INIT_CDROM);
DEC_CONST(INIT_JOYSTICK);
DEC_CONST(INIT_NOPARACHUTE);
DEC_CONST(INIT_EVERYTHING);
initAudioClasses();
initCDClasses();
initEventsClasses();
initTrueTypeFontClasses();
initJoystickClasses();
initKeyClasses();
initMouseClasses();
initTimerClasses();
initVideoClasses();
initSFontClasses();
initFLXClasses();
initNetClasses();
initSDL();
}