]> git.jsancho.org Git - gacela.git/blob - gacela_SDL.lisp
502c03a102dff9270436e877ad0a45e30bced6e4
[gacela.git] / gacela_SDL.lisp
1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
8 ;;;
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;; GNU General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18 (when (not (find-package 'gacela))
19   (make-package 'gacela :nicknames '(gg) :use '(lisp)))
20
21 (eval-when (eval) (in-package 'gacela :nicknames '(gg) :use '(lisp)))
22
23 (defmacro mapcconst (type c-type name)
24   (let ((c-header (concatenate 'string c-type " gacela_" name " (void)"))
25         (c-body (concatenate 'string "return " name ";"))
26         (c-name (concatenate 'string "gacela_" name))
27         (lisp-name (intern (string-upcase name))))
28     `(progn
29        (defcfun ,c-header 0 ,c-body)
30        (defentry ,lisp-name () (,type ,c-name))
31        (eval-when (load) (defconstant ,lisp-name (,lisp-name))))))
32
33 (clines "#include <SDL/SDL.h>")
34 (clines "#include <SDL/SDL_image.h>")
35 (clines "#include <SDL/SDL_mixer.h>")
36
37 ;;; SDL constants as functions
38 (mapcconst int "int" "SDL_INIT_TIMER")
39 (mapcconst int "int" "SDL_INIT_AUDIO")
40 (mapcconst int "int" "SDL_INIT_VIDEO")
41 (mapcconst int "int" "SDL_INIT_CDROM")
42 (mapcconst int "int" "SDL_INIT_JOYSTICK")
43 (mapcconst int "int" "SDL_INIT_NOPARACHUTE")
44 (mapcconst int "int" "SDL_INIT_EVENTTHREAD")
45 (mapcconst int "int" "SDL_INIT_EVERYTHING")
46
47 (mapcconst int "int" "SDL_SWSURFACE")
48 (mapcconst int "int" "SDL_HWSURFACE")
49 (mapcconst int "int" "SDL_ASYNCBLIT")
50
51 (mapcconst int "int" "SDL_ANYFORMAT")
52 (mapcconst int "int" "SDL_HWPALETTE")
53 (mapcconst int "int" "SDL_DOUBLEBUF")
54 (mapcconst int "int" "SDL_FULLSCREEN")
55 (mapcconst int "int" "SDL_OPENGL")
56 (mapcconst int "int" "SDL_OPENGLBLIT")
57 (mapcconst int "int" "SDL_RESIZABLE")
58 (mapcconst int "int" "SDL_NOFRAME")
59
60 (mapcconst int "int" "SDL_HWACCEL")
61 (mapcconst int "int" "SDL_SRCCOLORKEY")
62
63 (mapcconst int "int" "SDL_GL_DOUBLEBUFFER")
64
65 (mapcconst int "int" "SDL_DEFAULT_REPEAT_DELAY")
66 (mapcconst int "int" "SDL_DEFAULT_REPEAT_INTERVAL")
67
68 (mapcconst int "int" "SDL_LIL_ENDIAN")
69 (mapcconst int "int" "SDL_BIG_ENDIAN")
70
71 ;;; SDL Functions
72 (defcfun "int gacela_SDL_Init (int flags)" 0
73   "return SDL_Init (flags);")
74
75 (defcfun "void gacela_SDL_Quit (void)" 0
76   "SDL_Quit ();")
77
78 (defcfun "int gacela_SDL_SetVideoMode (int width, int height, int bpp, int flags)" 0
79   "return SDL_SetVideoMode (width, height, bpp, flags);")
80
81 (defcfun "void gacela_SDL_WM_SetCaption (char *title, char *icon)" 0
82   "SDL_WM_SetCaption (title, icon);")
83
84 (defcfun "int gacela_SDL_Flip (int screen)" 0
85   "return SDL_Flip (screen);")
86
87 (defcfun "void gacela_SDL_FreeSurface (int surface)" 0
88   "SDL_FreeSurface (surface);")
89
90 (defcfun "void gacela_SDL_Delay (int ms)" 0
91   "SDL_Delay (ms);")
92
93 (defcfun "int gacela_SDL_GetTicks (void)" 0
94   "return SDL_GetTicks ();")
95
96 (defcfun "int gacela_SDL_DisplayFormat (int surface)" 0
97   "return SDL_DisplayFormat (surface);")
98
99 (defcfun "int gacela_SDL_MapRGB (int format, int r, int g, int b)" 0
100   "return SDL_MapRGB (format, r, g, b);")
101
102 (defcfun "int gacela_SDL_SetColorKey (int surface, int flag, int key)" 0
103   "return SDL_SetColorKey (surface, flag, key);")
104
105 (defcfun "int gacela_SDL_LoadBMP (char *file)" 0
106   "return SDL_LoadBMP (file);")
107
108 (defcfun "int gacela_IMG_Load (char *filename)" 0
109   "return IMG_Load (filename);")
110
111 (defcfun "static object gacela_SDL_GetVideoInfo (void)" 0
112   "const SDL_VideoInfo *info;"
113   "object vi, label;"
114   "info = SDL_GetVideoInfo ();"
115   ('nil vi)
116   ((cons (int info->blit_hw) vi) vi) (':blit_hw label) ((cons label vi) vi)
117   ((cons (int info->hw_available) vi) vi) (':hw_available label) ((cons label vi) vi)
118   "return vi;")
119
120 (defcfun "int gacela_SDL_GL_SetAttribute (int attr, int value)" 0
121   "return SDL_GL_SetAttribute (attr, value);")
122
123 (defcfun "static object gacela_SDL_PollEvent (void)" 0
124   "SDL_Event sdl_event;"
125   "object event, label;"
126   ('nil event)
127   "if (SDL_PollEvent (&sdl_event)) {"
128   "  switch (sdl_event.type) {"
129   "    case SDL_KEYDOWN:"
130   "    case SDL_KEYUP:"
131   ((cons (int sdl_event.key.keysym.sym) event) event) (':key.keysym.sym label) ((cons label event) event)
132   "      break;"
133   "  }"
134   ((cons (int sdl_event.type) event) event) (':type label) ((cons label event) event)
135   "}"
136   "return event;")
137
138 (defcfun "void gacela_SDL_GL_SwapBuffers (void)" 0
139   "SDL_GL_SwapBuffers ();")
140
141 (defcfun "int gacela_SDL_EnableKeyRepeat (int delay, int interval)" 0
142   "return SDL_EnableKeyRepeat (delay, interval);")
143
144 (defcfun "int gacela_SDL_ByteOrder (void)" 0
145   "return SDL_BYTEORDER;")
146
147 (defentry SDL_Init (int) (int "gacela_SDL_Init"))
148 (defentry SDL_Quit () (void "gacela_SDL_Quit"))
149 (defentry SDL_SetVideoMode (int int int int) (int "gacela_SDL_SetVideoMode"))
150 (defentry SDL_WM_SetCaption (string string) (void "gacela_SDL_WM_SetCaption"))
151 (defentry SDL_Flip (int) (int "gacela_SDL_Flip"))
152 (defentry SDL_FreeSurface (int) (void "gacela_SDL_FreeSurface"))
153 (defentry SDL_Delay (int) (void "gacela_SDL_Delay"))
154 (defentry SDL_GetTicks () (int "gacela_SDL_GetTicks"))
155 (defentry SDL_DisplayFormat (int) (int "gacela_SDL_DisplayFormat"))
156 ;(defentry SDL_SurfaceFormat (int) (int "gacela_SDL_SurfaceFormat"))
157 (defentry SDL_MapRGB (int int int int) (int "gacela_SDL_MapRGB"))
158 (defentry SDL_SetColorKey (int int int) (int "gacela_SDL_SetColorKey"))
159 ;(defentry SDL_BlitSurface (int int int int) (void "gacela_SDL_BlitSurface"))
160 ;(defentry SDL_Rect (int int int int) (int "gacela_SDL_Rect"))
161 (defentry SDL_LoadBMP (string) (int "gacela_SDL_LoadBMP"))
162 (defentry IMG_Load (string) (int "gacela_IMG_Load"))
163 (defentry SDL_GetVideoInfo () (object "gacela_SDL_GetVideoInfo"))
164 (defentry SDL_GL_SetAttribute (int int) (int "gacela_SDL_GL_SetAttribute"))
165 (defentry SDL_PollEvent () (object "gacela_SDL_PollEvent"))
166 ;(defentry TTF_Init () (int "gacela_TTF_Init"))
167 ;(defentry TTF_OpenFont (string int) (int "gacela_TTF_OpenFont"))
168 ;(defentry TTF_CloseFont (int) (void "gacela_TTF_CloseFont"))
169 ;(defentry TTF_Quit () (void "gacela_TTF_Quit"))
170 ;(defentry Mix_OpenAudio (int int int) (int "gacela_Mix_OpenAudio"))
171 ;(defentry Mix_LoadMUS (string) (int "gacela_Mix_LoadMUS"))
172 ;(defentry Mix_LoadWAV (string) (int "gacela_Mix_LoadWAV"))
173 ;(defentry Mix_PlayChannel (int int int) (int "gacela_Mix_PlayChannel"))
174 ;(defentry Mix_PlayMusic (int int) (int "gacela_Mix_PlayMusic"))
175 ;(defentry Mix_PlayingMusic () (int "gacela_Mix_PlayingMusic"))
176 ;(defentry Mix_PausedMusic () (int "gacela_Mix_PausedMusic"))
177 ;(defentry Mix_PauseMusic () (void "gacela_Mix_PauseMusic"))
178 ;(defentry Mix_ResumeMusic () (void "gacela_Mix_ResumeMusic"))
179 ;(defentry Mix_HaltMusic () (int "gacela_Mix_HaltMusic"))
180 ;(defentry Mix_FreeMusic (int) (void "gacela_Mix_FreeMusic"))
181 ;(defentry Mix_FreeChunk (int) (void "gacela_Mix_FreeChunk"))
182 ;(defentry Mix_CloseAudio () (void "gacela_Mix_CloseAudio"))
183 ;(defentry free (int) (void "gacela_free"))
184 (defentry SDL_GL_SwapBuffers () (void "gacela_SDL_GL_SwapBuffers"))
185 (defentry SDL_EnableKeyRepeat (int int) (int "gacela_SDL_EnableKeyRepeat"))
186 (defentry SDL_ByteOrder () (int "gacela_SDL_ByteOrder"))
187
188 ;;; C-Gacela Functions
189 (defcfun "int gacela_surface_format (int surface)" 0
190   "const SDL_Surface *s = surface;"
191   "return s->format;")
192
193 (defcfun "int gacela_surface_w (int surface)" 0
194   "const SDL_Surface *s = surface;"
195   "return s->w;")
196
197 (defcfun "int gacela_surface_h (int surface)" 0
198   "const SDL_Surface *s = surface;"
199   "return s->h;")
200
201 (defcfun "int gacela_surface_pixels (int surface)" 0
202   "const SDL_Surface *s = surface;"
203   "return s->pixels;")
204
205 (defcfun "int gacela_surface_format_BytesPerPixel (int surface)" 0
206   "const SDL_Surface *s = surface;"
207   "return s->format->BytesPerPixel;")
208
209 ;(defentry apply-surface2 (int int int int int int int int int) (void "apply_surface"))
210 ;(defentry render-text2 (int string int int int) (int "render_text"))
211 ;(defentry box-collision (int int int int int int) (int "box_collision"))
212 ;(defentry create-SDL_Surface (int int int int int int) (int "create_SDL_Surface"))
213 ;(defentry copy-SDL_Surface (int) (int "copy_SDL_Surface"))
214 (defentry surface-format (int) (int "gacela_surface_format"))
215 (defentry surface-w (int) (int "gacela_surface_w"))
216 (defentry surface-h (int) (int "gacela_surface_h"))
217 (defentry surface-pixels (int) (int "gacela_surface_pixels"))
218 (defentry surface-format-BytesPerPixel (int) (int "gacela_surface_format_BytesPerPixel"))