File: rubysdl_main.c

package info (click to toggle)
libsdl-ruby 1.1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,320 kB
  • ctags: 1,157
  • sloc: ansic: 4,375; ruby: 1,837; makefile: 54
file content (202 lines) | stat: -rw-r--r-- 4,534 bytes parent folder | download
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
/*
  Ruby/SDL   Ruby extension library for SDL

  Copyright (C) 2001-2005 Ohbayashi Ippei
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */

#define DEF_GLOBAL
#include "rubysdl.h"
#include <signal.h>
#include <stdio.h>

/* declaration of initialize functions */
void init_video();
#ifdef HAVE_SGE
void init_sge_video();
#else
void init_pixel();
#endif
#ifdef DEF_OPENGL
void init_opengl();
#ifdef INIT_OGLMODULE_FROM_SDL
void Init_opengl();
#endif
#endif
#ifdef HAVE_SDL_IMAGE
void init_sdl_image();
#endif
void init_event();
#ifdef DEF_EVENT2
void init_event2();
#endif
void init_keyEvent();
void init_mouse();
void init_joystick();
void init_cdrom();
void init_time();
void init_wm();
void init_kanji(void);
#ifdef HAVE_SDL_TTF
void init_ttf();
void quit_ttf();
#endif
#ifdef HAVE_SDL_MIXER
void  init_mixer();
void quit_mixer();
#endif
#ifdef HAVE_SMPEG
void init_smpeg();
#endif

#ifdef HAVE_SDLSKK
void init_sdlskk();
#endif

static void sdl_quit();
static VALUE sdl_init(VALUE obj,VALUE flags)
{
  Uint32 flag;
  
  rb_secure(4);
  flag= NUM2UINT(flags);
  if( SDL_Init(flag) < 0 )
    rb_raise(eSDLError,"Couldn't initialize SDL: %s",SDL_GetError());
  return Qnil;
}

static VALUE sdl_initSubSystem(VALUE obj,VALUE flags)
{
  if( SDL_InitSubSystem(NUM2UINT(flags)) < 0 )
    rb_raise(eSDLError,"Couldn't initialize SDL subsystem: %s",SDL_GetError());
  return Qnil;
}

static VALUE sdl_wasInit(VALUE mod,VALUE flags)
{
  return UINT2NUM( SDL_WasInit(NUM2UINT(flags)) );
}

static VALUE sdl_putenv(VALUE mod,VALUE var)
{
  if( putenv(GETCSTR(var)) < 0 ){
    rb_raise(eSDLError,"Can't put environ variable: %s", GETCSTR(var));
  }
  return Qnil;
}

static VALUE sdl_getenv(VALUE mod,VALUE name)
{
  char* result = getenv(GETCSTR(name));
  if( result == NULL ){
    rb_raise(eSDLError,"Can't get environ variable: %s", GETCSTR(name));
  }
  return rb_str_new2(result);
}

static int is_quit=0;
int rubysdl_is_quit(void)
{
  return is_quit;
}
static void sdl_quit()
{
#ifdef HAVE_SDL_MIXER
  quit_mixer();
#endif
#ifdef HAVE_SDL_TTF
  quit_ttf();
#endif
  is_quit = 1;
  SDL_Quit();
  return ;
}

static VALUE sdl_rb_quit(VALUE obj)
{
  sdl_quit();
  return Qnil;
}

static void defineConst()
{
  rb_define_const(mSDL,"INIT_TIMER",UINT2NUM(SDL_INIT_TIMER));
  rb_define_const(mSDL,"INIT_AUDIO",UINT2NUM(SDL_INIT_AUDIO));
  rb_define_const(mSDL,"INIT_VIDEO",UINT2NUM(SDL_INIT_VIDEO));
  rb_define_const(mSDL,"INIT_CDROM",UINT2NUM(SDL_INIT_CDROM));
  rb_define_const(mSDL,"INIT_JOYSTICK",UINT2NUM(SDL_INIT_JOYSTICK));
  rb_define_const(mSDL,"INIT_NOPARACHUTE",UINT2NUM(SDL_INIT_NOPARACHUTE));
  rb_define_const(mSDL,"INIT_EVENTTHREAD",UINT2NUM(SDL_INIT_EVENTTHREAD));
  rb_define_const(mSDL,"INIT_EVERYTHING",UINT2NUM(SDL_INIT_EVERYTHING));
}


void Init_sdl()
{
  mSDL = rb_define_module("SDL");
  eSDLError = rb_define_class_under(mSDL,"Error",rb_eStandardError);
  rb_define_module_function(mSDL,"init",sdl_init,1);
  rb_define_module_function(mSDL,"initedSystem",sdl_wasInit,1);
  rb_define_module_function(mSDL,"initSubSystem",sdl_initSubSystem,1);
  rb_define_module_function(mSDL,"quit",sdl_rb_quit,0);
  rb_define_module_function(mSDL,"putenv",sdl_putenv,1);
  rb_define_module_function(mSDL,"getenv",sdl_getenv,1);
  
  defineConst();


  init_video();
#ifdef HAVE_SGE
  init_sge_video();
#else
  init_pixel();
#endif
#ifdef DEF_OPENGL
  init_opengl();
#ifdef INIT_OGLMODULE_FROM_SDL
  Init_opengl();
#endif
#endif
#ifdef HAVE_SDL_IMAGE
  init_sdl_image();
#endif
  init_event();
#ifdef DEF_EVENT2
  init_event2();
#endif
  init_keyEvent();
  init_mouse();
  init_joystick();
  init_cdrom();
  init_time();
  init_wm();
  init_kanji();
#ifdef HAVE_SDL_TTF
  init_ttf();
#endif
#ifdef HAVE_SDL_MIXER
  init_mixer();
#endif
#ifdef HAVE_SMPEG
  init_smpeg();
#endif
#ifdef HAVE_SDLSKK
  init_sdlskk();
#endif
  rb_set_end_proc(sdl_quit,0); 
}