]> git.jsancho.org Git - gacela.git/blob - gacela_SDL.lisp
(no commit message)
[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 (in-package :gacela)
19
20 (clines "#include <SDL/SDL.h>")
21 (clines "#include <SDL/SDL_image.h>")
22 (clines "#include <SDL/SDL_ttf.h>")
23 (clines "#include <SDL/SDL_mixer.h>")
24 (clines "#include <SDL/SDL_rotozoom.h>")
25
26 (defmacro defcconst (type name)
27   `(let ((header (concatenate 'string "(defcfun \"
28
29 ;;; SDL constants as functions
30 (defcfun "int gacela_SDL_INIT_TIMER (void)" 0 "return SDL_INIT_TIMER;")
31 (defcfun "int gacela_SDL_INIT_AUDIO (void)" 0 "return SDL_INIT_AUDIO;")
32 (defcfun "int gacela_SDL_INIT_VIDEO (void)" 0 "return SDL_INIT_VIDEO;")
33 (defcfun "int gacela_SDL_INIT_CDROM (void)" 0 "return SDL_INIT_CDROM;")
34 (defcfun "int gacela_SDL_INIT_JOYSTICK (void)" 0 "return SDL_INIT_JOYSTICK;")
35 (defcfun "int gacela_SDL_INIT_NOPARACHUTE (void)" 0 "return SDL_INIT_NOPARACHUTE;")
36 (defcfun "int gacela_SDL_INIT_EVENTTHREAD (void)" 0 "return SDL_INIT_EVENTTHREAD;")
37 (defcfun "int gacela_SDL_INIT_EVERYTHING (void)" 0 "return SDL_INIT_EVERYTHING;")
38
39 (defcfun "int gacela_SDL_SWSURFACE (void)" 0 "return SDL_SWSURFACE;")
40 (defcfun "int gacela_SDL_HWSURFACE (void)" 0 "return SDL_HWSURFACE;")
41 (defcfun "int gacela_SDL_ASYNCBLIT (void)" 0 "return SDL_ASYNCBLIT;")
42
43 (defcfun "int gacela_SDL_ANYFORMAT (void)" 0 "return SDL_ANYFORMAT;")
44 (defcfun "int gacela_SDL_HWPALETTE (void)" 0 "return SDL_HWPALETTE;")
45 (defcfun "int gacela_SDL_DOUBLEBUF (void)" 0 "return SDL_DOUBLEBUF;")
46 (defcfun "int gacela_SDL_FULLSCREEN (void)" 0 "return SDL_FULLSCREEN;")
47 (defcfun "int gacela_SDL_OPENGL (void)" 0 "return SDL_OPENGL;")
48 (defcfun "int gacela_SDL_OPENGLBLIT (void)" 0 "return SDL_OPENGLBLIT;")
49 (defcfun "int gacela_SDL_RESIZABLE (void)" 0 "return SDL_RESIZABLE;")
50 (defcfun "int gacela_SDL_NOFRAME (void)" 0 "return SDL_NOFRAME;")
51
52 (defcfun "int gacela_SDL_HWACCEL (void)" 0 "return SDL_HWACCEL;")
53 (defcfun "int gacela_SDL_SRCCOLORKEY (void)" 0 "return SDL_SRCCOLORKEY;")
54
55 (defcfun "int gacela_SDL_GL_DOUBLEBUFFER (void)" 0 "return SDL_GL_DOUBLEBUFFER;")
56
57 (defcfun "int gacela_SDL_DEFAULT_REPEAT_DELAY (void)" 0 "return DEFAULT_REPEAT_DELAY;")
58 (defcfun "int gacela_SDL_DEFAULT_REPEAT_INTERVAL (void)" 0 "return DEFAULT_REPEAT_INTERVAL;")
59
60 (defcfun "int gacela_SDL_LIL_ENDIAN (void)" 0 "return SDL_LIL_ENDIAN;")
61 (defcfun "int gacela_SDL_BIG_ENDIAN (void)" 0 "return SDL_BIG_ENDIAN;")
62
63
64 ;;; SDL Functions
65 (defcfun "int gacela_SDL_Init (int flags)" 0
66   "return SDL_Init (flags);")
67
68 (defcfun "void gacela_SDL_Quit (void)" 0
69   "SDL_Quit ();")
70
71 (defcfun "int gacela_SDL_SetVideoMode (int width, int height, int bpp, int flags)" 0
72   "return SDL_SetVideoMode (width, height, bpp, flags);")
73
74 (defcfun "void gacela_SDL_WM_SetCaption (char *title, char *icon)" 0
75   "SDL_WM_SetCaption (title, icon);")
76
77 (defcfun "int gacela_SDL_Flip (int screen)" 0
78   "return SDL_Flip (screen);")
79
80 (defcfun "void gacela_SDL_FreeSurface (int surface)" 0
81   "SDL_FreeSurface (surface);")
82
83 (defcfun "void gacela_SDL_Delay (int ms)" 0
84   "SDL_Delay (ms);")
85
86 (defcfun "int gacela_SDL_GetTicks (void)" 0
87   "return SDL_GetTicks ();")
88
89 (defcfun "int gacela_SDL_DisplayFormat (int surface)" 0
90   "return SDL_DisplayFormat (surface);")
91
92 (defcfun "int gacela_SDL_MapRGB (int format, int r, int g, int b)" 0
93   "return SDL_MapRGB (format, r, g, b);")
94
95 (defcfun "int gacela_SDL_SetColorKey (int surface, int flag, int key)" 0
96   "return SDL_SetColorKey (surface, flag, key);")
97
98 (defcfun "int gacela_SDL_LoadBMP (char *file)" 0
99   "return SDL_LoadBMP (file);")
100
101 (defcfun "int gacela_IMG_Load (char *filename)" 0
102   "return IMG_Load (filename);")
103
104 (defcfun "static object gacela_SDL_GetVideoInfo (void)" 0
105   "const SDL_VideoInfo *info;"
106   "object vi, label;"
107   "info = SDL_GetVideoInfo ();"
108   ('nil vi)
109   ((cons (int info->blit_hw) vi) vi) (':blit_hw label) ((cons label vi) vi)
110   ((cons (int info->hw_available) vi) vi) (':hw_available label) ((cons label vi) vi)
111   "return vi;")
112
113 (defcfun "int gacela_SDL_GL_SetAttribute (int attr, int value)" 0
114   "return SDL_GL_SetAttribute (attr, value);")
115
116 (defcfun "static object gacela_SDL_PollEvent (void)" 0
117   "SDL_Event sdl_event;"
118   "object event, label;"
119   ('nil event)
120   "if (SDL_PollEvent (&sdl_event)) {"
121   "  switch (sdl_event.type) {"
122   "    case SDL_KEYDOWN:"
123   "    case SDL_KEYUP:"
124   ((cons (int sdl_event.key.keysym.sym) event) event) (':key.keysym.sym label) ((cons label event) event)
125   "      break;"
126   "  }"
127   ((cons (int sdl_event.type) event) event) (':type label) ((cons label event) event)
128   "}"
129   "return event;")
130
131 (defcfun "void gacela_SDL_GL_SwapBuffers (void)" 0
132   "SDL_GL_SwapBuffers ();")
133
134 (defcfun "int gacela_SDL_EnableKeyRepeat (int delay, int interval)" 0
135   "return SDL_EnableKeyRepeat (delay, interval);")
136
137 (defcfun "int gacela_zoomSurface (int src, float zoomx, float zoomy, int smooth)" 0
138   "return zoomSurface (src, zoomx, zoomy, smooth);")
139
140 (defcfun "int gacela_SDL_ByteOrder (void)" 0
141   "return SDL_BYTEORDER;")
142
143 (defentry SDL_Init (int) (int "gacela_SDL_Init"))
144 (defentry SDL_Quit () (void "gacela_SDL_Quit"))
145 (defentry SDL_SetVideoMode (int int int int) (int "gacela_SDL_SetVideoMode"))
146 (defentry SDL_WM_SetCaption (string string) (void "gacela_SDL_WM_SetCaption"))
147 (defentry SDL_Flip (int) (int "gacela_SDL_Flip"))
148 (defentry SDL_FreeSurface (int) (void "gacela_SDL_FreeSurface"))
149 (defentry SDL_Delay (int) (void "gacela_SDL_Delay"))
150 (defentry SDL_GetTicks () (int "gacela_SDL_GetTicks"))
151 (defentry SDL_DisplayFormat (int) (int "gacela_SDL_DisplayFormat"))
152 ;(defentry SDL_SurfaceFormat (int) (int "gacela_SDL_SurfaceFormat"))
153 (defentry SDL_MapRGB (int int int int) (int "gacela_SDL_MapRGB"))
154 (defentry SDL_SetColorKey (int int int) (int "gacela_SDL_SetColorKey"))
155 ;(defentry SDL_BlitSurface (int int int int) (void "gacela_SDL_BlitSurface"))
156 ;(defentry SDL_Rect (int int int int) (int "gacela_SDL_Rect"))
157 (defentry SDL_LoadBMP (string) (int "gacela_SDL_LoadBMP"))
158 (defentry IMG_Load (string) (int "gacela_IMG_Load"))
159 (defentry SDL_GetVideoInfo () (object "gacela_SDL_GetVideoInfo"))
160 (defentry SDL_GL_SetAttribute (int int) (int "gacela_SDL_GL_SetAttribute"))
161 (defentry SDL_PollEvent () (object "gacela_SDL_PollEvent"))
162 ;(defentry TTF_Init () (int "gacela_TTF_Init"))
163 ;(defentry TTF_OpenFont (string int) (int "gacela_TTF_OpenFont"))
164 ;(defentry TTF_CloseFont (int) (void "gacela_TTF_CloseFont"))
165 ;(defentry TTF_Quit () (void "gacela_TTF_Quit"))
166 ;(defentry Mix_OpenAudio (int int int) (int "gacela_Mix_OpenAudio"))
167 ;(defentry Mix_LoadMUS (string) (int "gacela_Mix_LoadMUS"))
168 ;(defentry Mix_LoadWAV (string) (int "gacela_Mix_LoadWAV"))
169 ;(defentry Mix_PlayChannel (int int int) (int "gacela_Mix_PlayChannel"))
170 ;(defentry Mix_PlayMusic (int int) (int "gacela_Mix_PlayMusic"))
171 ;(defentry Mix_PlayingMusic () (int "gacela_Mix_PlayingMusic"))
172 ;(defentry Mix_PausedMusic () (int "gacela_Mix_PausedMusic"))
173 ;(defentry Mix_PauseMusic () (void "gacela_Mix_PauseMusic"))
174 ;(defentry Mix_ResumeMusic () (void "gacela_Mix_ResumeMusic"))
175 ;(defentry Mix_HaltMusic () (int "gacela_Mix_HaltMusic"))
176 ;(defentry Mix_FreeMusic (int) (void "gacela_Mix_FreeMusic"))
177 ;(defentry Mix_FreeChunk (int) (void "gacela_Mix_FreeChunk"))
178 ;(defentry Mix_CloseAudio () (void "gacela_Mix_CloseAudio"))
179 ;(defentry free (int) (void "gacela_free"))
180 (defentry SDL_GL_SwapBuffers () (void "gacela_SDL_GL_SwapBuffers"))
181 (defentry SDL_EnableKeyRepeat (int int) (int "gacela_SDL_EnableKeyRepeat"))
182 (defentry zoomSurface (int float float int) (int "gacela_zoomSurface"))
183 (defentry SDL_ByteOrder () (int "gacela_SDL_ByteOrder"))
184
185 ;;; C-Gacela Functions
186 (defcfun "int gacela_surface_format (int surface)" 0
187   "const SDL_Surface *s = surface;"
188   "return s->format;")
189
190 (defcfun "int gacela_surface_w (int surface)" 0
191   "const SDL_Surface *s = surface;"
192   "return s->w;")
193
194 (defcfun "int gacela_surface_h (int surface)" 0
195   "const SDL_Surface *s = surface;"
196   "return s->h;")
197
198 (defcfun "int gacela_surface_pixels (int surface)" 0
199   "const SDL_Surface *s = surface;"
200   "return s->pixels;")
201
202 (defcfun "int gacela_surface_format_BytesPerPixel (int surface)" 0
203   "const SDL_Surface *s = surface;"
204   "return s->format->BytesPerPixel;")
205
206 ;(defentry apply-surface2 (int int int int int int int int int) (void "apply_surface"))
207 ;(defentry render-text2 (int string int int int) (int "render_text"))
208 ;(defentry fill-surface (int int int int) (void "fill_surface"))
209 ;(defentry box-collision (int int int int int int) (int "box_collision"))
210 ;(defentry create-SDL_Surface (int int int int int int) (int "create_SDL_Surface"))
211 ;(defentry copy-SDL_Surface (int) (int "copy_SDL_Surface"))
212 (defentry surface-format (int) (int "gacela_surface_format"))
213 (defentry surface-w (int) (int "gacela_surface_w"))
214 (defentry surface-h (int) (int "gacela_surface_h"))
215 (defentry surface-pixels (int) (int "gacela_surface_pixels"))
216 (defentry surface-format-BytesPerPixel (int) (int "gacela_surface_format_BytesPerPixel"))