author | unc0rr |
Thu, 02 Apr 2009 20:37:03 +0000 | |
changeset 1932 | f586d75c8b6a |
parent 1916 | 9c3d0e3df6bb |
child 1947 | 9b8bdee5db6c |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 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. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit SDLh; |
|
20 |
interface |
|
753 | 21 |
|
4 | 22 |
{$IFDEF LINUX} |
23 |
{$DEFINE UNIX} |
|
24 |
{$ENDIF} |
|
25 |
{$IFDEF FREEBSD} |
|
26 |
{$DEFINE UNIX} |
|
27 |
{$ENDIF} |
|
28 |
||
29 |
{$IFDEF UNIX} |
|
1903 | 30 |
{$IFNDEF DARWIN} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
31 |
{$linklib c} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
32 |
{$ENDIF} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
33 |
{$linklib pthread} |
4 | 34 |
{$ENDIF} |
35 |
||
432 | 36 |
{$PACKRECORDS C} |
4 | 37 |
|
1819 | 38 |
{$IFDEF DARWIN} |
1916 | 39 |
{$IFNDEF IPHONE} |
1819 | 40 |
{$linklib libpng} |
41 |
{$linklib libz} |
|
42 |
{$linklib libjpeg} |
|
43 |
{$linklib libtiff} |
|
44 |
{$linklib libfreetype} |
|
45 |
{$linklib libsmpeg} |
|
46 |
{$linklib libvorbis} |
|
47 |
{$linklib libvorbisfile} |
|
48 |
{$linklib libogg} |
|
49 |
||
50 |
{$linkframework Carbon} |
|
51 |
{$linkframework OpenGL} |
|
52 |
{$linkframework AudioUnit} |
|
53 |
{$linkframework Quicktime} |
|
54 |
{$linkframework IOKit} |
|
1906 | 55 |
{add ForceFeedback and CoreAudio frameworks when you use SDL-1.3} |
1819 | 56 |
{$ENDIF} |
1916 | 57 |
{$ENDIF} |
1819 | 58 |
|
4 | 59 |
(* SDL *) |
60 |
const {$IFDEF WIN32} |
|
61 |
SDLLibName = 'SDL.dll'; |
|
62 |
{$ENDIF} |
|
63 |
{$IFDEF UNIX} |
|
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
64 |
{$IFDEF DARWIN} |
1819 | 65 |
SDLLibName = 'libSDL.a'; |
1916 | 66 |
{$IFNDEF IPHONE} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
67 |
{$linklib libSDL} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
68 |
{$linklib SDLmain} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
69 |
{$linkframework Cocoa} |
1916 | 70 |
{$ENDIF} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
71 |
{$PASCALMAINNAME SDL_main} |
1916 | 72 |
{$IFNDEF IPHONE} |
1903 | 73 |
{$linklib gcc} |
1916 | 74 |
{$ENDIF} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
75 |
{$ELSE} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
76 |
SDLLibName = 'libSDL.so'; |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
77 |
{$ENDIF} |
4 | 78 |
{$ENDIF} |
79 |
SDL_SWSURFACE = $00000000; |
|
80 |
SDL_HWSURFACE = $00000001; |
|
81 |
SDL_ASYNCBLIT = $00000004; |
|
82 |
SDL_ANYFORMAT = $10000000; |
|
83 |
SDL_HWPALETTE = $20000000; |
|
358 | 84 |
SDL_DOUBLEBUF = $40000000; |
4 | 85 |
SDL_FULLSCREEN = $80000000; |
86 |
SDL_NOFRAME = $00000020; |
|
87 |
SDL_HWACCEL = $00000100; |
|
88 |
SDL_SRCCOLORKEY = $00001000; |
|
89 |
SDL_RLEACCEL = $00004000; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
883
diff
changeset
|
90 |
|
4 | 91 |
SDL_NOEVENT = 0; |
308 | 92 |
SDL_ACTIVEEVENT = 1; |
4 | 93 |
SDL_KEYDOWN = 2; |
94 |
SDL_KEYUP = 3; |
|
95 |
SDL_QUITEV = 12; |
|
1120 | 96 |
SDL_VIDEORESIZE = 16; |
4 | 97 |
|
308 | 98 |
SDL_APPINPUTFOCUS = 2; |
99 |
||
4 | 100 |
SDL_INIT_VIDEO = $00000020; |
11 | 101 |
SDL_INIT_AUDIO = $00000010; |
753 | 102 |
|
103 |
SDL_GL_DOUBLEBUFFER = 5; |
|
104 |
SDL_OPENGL = 2; |
|
1120 | 105 |
SDL_RESIZABLE = $00000010; |
754 | 106 |
|
107 |
RMask = $FF; |
|
108 |
GMask = $FF00; |
|
109 |
BMask = $FF0000; |
|
110 |
AMask = $FF000000; |
|
111 |
||
4 | 112 |
type PSDL_Rect = ^TSDL_Rect; |
113 |
TSDL_Rect = record |
|
114 |
x, y: SmallInt; |
|
115 |
w, h: Word; |
|
116 |
end; |
|
117 |
||
118 |
TPoint = record |
|
105 | 119 |
X: LongInt; |
120 |
Y: LongInt; |
|
4 | 121 |
end; |
122 |
||
123 |
PSDL_PixelFormat = ^TSDL_PixelFormat; |
|
124 |
TSDL_PixelFormat = record |
|
125 |
palette: Pointer; |
|
126 |
BitsPerPixel : Byte; |
|
127 |
BytesPerPixel: Byte; |
|
128 |
Rloss : Byte; |
|
129 |
Gloss : Byte; |
|
130 |
Bloss : Byte; |
|
131 |
Aloss : Byte; |
|
132 |
Rshift: Byte; |
|
133 |
Gshift: Byte; |
|
134 |
Bshift: Byte; |
|
135 |
Ashift: Byte; |
|
136 |
RMask : Longword; |
|
137 |
GMask : Longword; |
|
138 |
BMask : Longword; |
|
139 |
AMask : Longword; |
|
140 |
colorkey: Longword; |
|
141 |
alpha : Byte; |
|
142 |
end; |
|
143 |
||
144 |
||
145 |
PSDL_Surface = ^TSDL_Surface; |
|
146 |
TSDL_Surface = record |
|
147 |
flags : Longword; |
|
148 |
format: PSDL_PixelFormat; |
|
432 | 149 |
w, h : LongInt; |
4 | 150 |
pitch : Word; |
151 |
pixels: Pointer; |
|
432 | 152 |
offset: LongInt; |
4 | 153 |
end; |
154 |
||
155 |
PSDL_Color = ^TSDL_Color; |
|
156 |
TSDL_Color = record |
|
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
157 |
case byte of |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
158 |
0: (r: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
159 |
g: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
160 |
b: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
161 |
unused: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
162 |
); |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
163 |
1: (value: Longword); |
4 | 164 |
end; |
165 |
||
166 |
PSDL_RWops = ^TSDL_RWops; |
|
105 | 167 |
TSeek = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl; |
168 |
TRead = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt; cdecl; |
|
169 |
TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl; |
|
170 |
TClose = function( context: PSDL_RWops ): LongInt; cdecl; |
|
4 | 171 |
|
172 |
TStdio = record |
|
105 | 173 |
autoclose: LongInt; |
4 | 174 |
fp: pointer; |
175 |
end; |
|
176 |
||
177 |
TMem = record |
|
178 |
base: PByte; |
|
179 |
here: PByte; |
|
180 |
stop: PByte; |
|
181 |
end; |
|
182 |
||
183 |
TUnknown = record |
|
184 |
data1: Pointer; |
|
185 |
end; |
|
186 |
||
187 |
TSDL_RWops = record |
|
188 |
seek: TSeek; |
|
189 |
read: TRead; |
|
190 |
write: TWrite; |
|
191 |
close: TClose; |
|
192 |
type_: Longword; |
|
193 |
case Byte of |
|
194 |
0: (stdio: TStdio); |
|
195 |
1: (mem: TMem); |
|
196 |
2: (unknown: TUnknown); |
|
197 |
end; |
|
198 |
||
199 |
TSDL_KeySym = record |
|
200 |
scancode: Byte; |
|
106 | 201 |
sym: Longword; |
4 | 202 |
modifier: Longword; |
203 |
unicode: Word; |
|
204 |
end; |
|
205 |
||
308 | 206 |
TSDL_ActiveEvent = record |
207 |
type_: byte; |
|
1120 | 208 |
gain: byte; |
209 |
state: byte; |
|
210 |
end; |
|
308 | 211 |
|
4 | 212 |
TSDL_KeyboardEvent = record |
213 |
type_: Byte; |
|
214 |
which: Byte; |
|
215 |
state: Byte; |
|
216 |
keysym: TSDL_KeySym; |
|
217 |
end; |
|
218 |
||
219 |
TSDL_QuitEvent = record |
|
220 |
type_: Byte; |
|
221 |
end; |
|
1120 | 222 |
TSDL_ResizeEvent = record |
223 |
type_: Byte; |
|
224 |
w, h: LongInt; |
|
225 |
end; |
|
226 |
||
4 | 227 |
PSDL_Event = ^TSDL_Event; |
228 |
TSDL_Event = record |
|
229 |
case Byte of |
|
230 |
SDL_NOEVENT: (type_: byte); |
|
308 | 231 |
SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent); |
4 | 232 |
SDL_KEYDOWN, SDL_KEYUP: (key: TSDL_KeyboardEvent); |
233 |
SDL_QUITEV: (quit: TSDL_QuitEvent); |
|
1120 | 234 |
SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent); |
4 | 235 |
end; |
236 |
||
237 |
PByteArray = ^TByteArray; |
|
316 | 238 |
TByteArray = array[0..65535] of Byte; |
239 |
PLongWordArray = ^TLongWordArray; |
|
240 |
TLongWordArray = array[0..16383] of LongWord; |
|
4 | 241 |
|
433 | 242 |
PSDL_Thread = Pointer; |
243 |
PSDL_mutex = Pointer; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
883
diff
changeset
|
244 |
|
432 | 245 |
function SDL_Init(flags: Longword): LongInt; cdecl; external SDLLibName; |
4 | 246 |
procedure SDL_Quit; cdecl; external SDLLibName; |
432 | 247 |
function SDL_VideoDriverName(var namebuf; maxlen: LongInt): PChar; cdecl; external SDLLibName; |
248 |
procedure SDL_EnableUNICODE(enable: LongInt); cdecl; external SDLLibName; |
|
4 | 249 |
|
250 |
procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; |
|
251 |
function SDL_GetTicks: Longword; cdecl; external SDLLibName; |
|
252 |
||
253 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
432 | 254 |
function SDL_LockSurface(Surface: PSDL_Surface): LongInt; cdecl; external SDLLibName; |
4 | 255 |
procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
256 |
||
257 |
function SDL_GetError: PChar; cdecl; external SDLLibName; |
|
258 |
||
432 | 259 |
function SDL_SetVideoMode(width, height, bpp: LongInt; flags: Longword): PSDL_Surface; cdecl; external SDLLibName; |
260 |
function SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: LongInt; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
261 |
function SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: LongInt; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
4 | 262 |
procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
105 | 263 |
function SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName; |
4 | 264 |
|
105 | 265 |
function SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName; |
266 |
function SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName; |
|
267 |
procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: Longword); cdecl; external SDLLibName; |
|
432 | 268 |
function SDL_Flip(Screen: PSDL_Surface): LongInt; cdecl; external SDLLibName; |
4 | 269 |
|
270 |
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName; |
|
107 | 271 |
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName; |
4 | 272 |
|
273 |
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
|
35 | 274 |
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
4 | 275 |
|
276 |
function SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName; |
|
432 | 277 |
function SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName; |
4 | 278 |
|
105 | 279 |
function SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName; |
107 | 280 |
function SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName; |
4 | 281 |
function SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName; |
282 |
procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName; |
|
283 |
||
432 | 284 |
function SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName; |
4 | 285 |
|
432 | 286 |
function SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName; |
4 | 287 |
|
288 |
procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; |
|
289 |
||
433 | 290 |
function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName; |
291 |
procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName; |
|
292 |
function SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexP'; |
|
293 |
function SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexV'; |
|
294 |
||
753 | 295 |
function SDL_GL_SetAttribute(attr: byte; value: LongInt): LongInt; cdecl; external SDLLibName; |
296 |
procedure SDL_GL_SwapBuffers(); cdecl; external SDLLibName; |
|
297 |
||
4 | 298 |
(* TTF *) |
299 |
||
300 |
const {$IFDEF WIN32} |
|
301 |
SDL_TTFLibName = 'SDL_ttf.dll'; |
|
302 |
{$ENDIF} |
|
303 |
{$IFDEF UNIX} |
|
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
304 |
{$IFDEF DARWIN} |
1819 | 305 |
SDL_TTFLibName = 'libSDL_ttf.a'; |
1916 | 306 |
{$IFNDEF IPHONE} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
307 |
{$linklib libSDL_ttf} |
1916 | 308 |
{$ENDIF} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
309 |
{$ELSE} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
310 |
SDL_TTFLibName = 'libSDL_ttf.so'; |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
311 |
{$ENDIF} |
4 | 312 |
{$ENDIF} |
202 | 313 |
TTF_STYLE_NORMAL = 0; |
314 |
TTF_STYLE_BOLD = 1; |
|
315 |
TTF_STYLE_ITALIC = 2; |
|
4 | 316 |
|
317 |
type PTTF_Font = ^TTTF_font; |
|
318 |
TTTF_Font = record |
|
319 |
end; |
|
320 |
||
432 | 321 |
function TTF_Init: LongInt; cdecl; external SDL_TTFLibName; |
4 | 322 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
323 |
||
324 |
||
432 | 325 |
function TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: LongInt): LongInt; cdecl; external SDL_TTFLibName; |
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
326 |
(* TSDL_Color -> Longword conversion is workaround over freepascal bug. |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
327 |
See http://www.freepascal.org/mantis/view.php?id=7613 for details *) |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
328 |
function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
329 |
function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName; |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
883
diff
changeset
|
330 |
function TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName; |
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
331 |
|
432 | 332 |
function TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName; |
333 |
procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName; |
|
4 | 334 |
|
335 |
(* SDL_mixer *) |
|
336 |
||
337 |
const {$IFDEF WIN32} |
|
338 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
339 |
{$ENDIF} |
|
340 |
{$IFDEF UNIX} |
|
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
341 |
{$IFDEF DARWIN} |
1819 | 342 |
SDL_MixerLibName = 'libSDL_mixer.a'; |
1916 | 343 |
{$IFNDEF IPHONE} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
344 |
{$linklib libSDL_mixer} |
1916 | 345 |
{$ENDIF} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
346 |
{$ELSE} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
347 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
348 |
{$ENDIF} |
4 | 349 |
{$ENDIF} |
350 |
||
174 | 351 |
const MIX_MAX_VOLUME = 128; |
352 |
||
4 | 353 |
type PMixChunk = ^TMixChunk; |
354 |
TMixChunk = record |
|
355 |
allocated: Longword; |
|
356 |
abuf : PByte; |
|
357 |
alen : Longword; |
|
358 |
volume : PByte; |
|
106 | 359 |
end; |
4 | 360 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
361 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
362 |
||
363 |
TMidiSong = record |
|
105 | 364 |
samples : LongInt; |
4 | 365 |
events : pointer; |
366 |
end; |
|
367 |
||
368 |
TMusicUnion = record |
|
369 |
case Byte of |
|
370 |
0: ( midi : TMidiSong ); |
|
371 |
1: ( ogg : pointer); |
|
372 |
end; |
|
373 |
||
374 |
PMixMusic = ^TMixMusic; |
|
375 |
TMixMusic = record |
|
376 |
end; |
|
377 |
||
105 | 378 |
function Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 379 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
380 |
||
174 | 381 |
function Mix_Volume(channel: LongInt; volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
382 |
function Mix_SetDistance(channel: LongInt; distance: Byte): LongInt; cdecl; external SDL_MixerLibName; |
|
105 | 383 |
function Mix_VolumeMusic(volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 384 |
|
174 | 385 |
function Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 386 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
387 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
388 |
||
105 | 389 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName; |
4 | 390 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
391 |
||
105 | 392 |
function Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
393 |
function Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName; |
|
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1120
diff
changeset
|
394 |
function Mix_FadeInMusic(music: PMixMusic; loops: LongInt; ms: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 395 |
|
105 | 396 |
function Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
397 |
function Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
1712 | 398 |
function Mix_PausedMusic(music: PMixMusic): LongInt; cdecl; external SDL_MixerLibName; |
399 |
function Mix_PauseMusic(music: PMixMusic): LongInt; cdecl; external SDL_MixerLibName; |
|
400 |
function Mix_ResumeMusic(music: PMixMusic): LongInt; cdecl; external SDL_MixerLibName; |
|
105 | 401 |
function Mix_HaltChannel(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 402 |
|
403 |
(* SDL_image *) |
|
404 |
||
405 |
const {$IFDEF WIN32} |
|
406 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
407 |
{$ENDIF} |
|
408 |
{$IFDEF UNIX} |
|
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
409 |
{$IFDEF DARWIN} |
1819 | 410 |
SDL_ImageLibName = 'libSDL_image.a'; |
1916 | 411 |
{$IFNDEF IPHONE} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
412 |
{$linklib libSDL_image} |
1916 | 413 |
{$ENDIF} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
414 |
{$ELSE} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
415 |
SDL_ImageLibName = 'libSDL_image.so'; |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
416 |
{$ENDIF} |
4 | 417 |
{$ENDIF} |
418 |
||
419 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
420 |
||
421 |
(* SDL_net *) |
|
422 |
||
423 |
const {$IFDEF WIN32} |
|
424 |
SDL_NetLibName = 'SDL_net.dll'; |
|
425 |
{$ENDIF} |
|
426 |
{$IFDEF UNIX} |
|
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
427 |
{$IFDEF DARWIN} |
1819 | 428 |
SDL_NetLibName = 'libSDL_net.a'; |
1916 | 429 |
{$IFNDEF IPHONE} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
430 |
{$linklib libSDL_net} |
1916 | 431 |
{$ENDIF} |
1556
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
432 |
{$ELSE} |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
433 |
SDL_NetLibName = 'libSDL_net.so'; |
3369f016b79d
Patch for engine to successfully build on Mac OS X by Michael Schindler
unc0rr
parents:
1225
diff
changeset
|
434 |
{$ENDIF} |
4 | 435 |
{$ENDIF} |
436 |
||
437 |
type TIPAddress = record |
|
438 |
host: Longword; |
|
439 |
port: Word; |
|
440 |
end; |
|
441 |
||
442 |
PTCPSocket = ^TTCPSocket; |
|
443 |
TTCPSocket = record |
|
106 | 444 |
ready: LongInt; |
105 | 445 |
channel: LongInt; |
106 | 446 |
remoteAddress: TIPaddress; |
4 | 447 |
localAddress: TIPaddress; |
105 | 448 |
sflag: LongInt; |
4 | 449 |
end; |
450 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
451 |
TSDLNet_SocketSet = record |
|
452 |
numsockets, |
|
105 | 453 |
maxsockets: LongInt; |
4 | 454 |
sockets: PTCPSocket; |
455 |
end; |
|
456 |
||
105 | 457 |
function SDLNet_Init: LongInt; cdecl; external SDL_NetLibName; |
4 | 458 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
459 |
||
105 | 460 |
function SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
461 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 462 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
463 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
105 | 464 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
465 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 466 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
467 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
105 | 468 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName; |
469 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 470 |
|
459
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
471 |
procedure SDLNet_Write16(value: Word; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
472 |
procedure SDLNet_Write32(value: LongWord; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
473 |
function SDLNet_Read16(buf: pointer): Word; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
474 |
function SDLNet_Read32(buf: pointer): LongWord; |
4 | 475 |
|
476 |
implementation |
|
477 |
||
478 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
479 |
begin |
|
432 | 480 |
SDL_MustLock:= ( surface^.offset <> 0 ) |
4 | 481 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
482 |
end; |
|
483 |
||
459
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
484 |
procedure SDLNet_Write16(value: Word; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
485 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
486 |
PByteArray(buf)^[1]:= value; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
487 |
PByteArray(buf)^[0]:= value shr 8 |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
488 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
489 |
|
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
490 |
procedure SDLNet_Write32(value: LongWord; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
491 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
492 |
PByteArray(buf)^[3]:= value; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
493 |
PByteArray(buf)^[2]:= value shr 8; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
494 |
PByteArray(buf)^[1]:= value shr 16; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
495 |
PByteArray(buf)^[0]:= value shr 24 |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
496 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
497 |
|
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
498 |
function SDLNet_Read16(buf: pointer): Word; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
499 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
500 |
SDLNet_Read16:= PByteArray(buf)^[1] or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
501 |
(PByteArray(buf)^[0] shl 8) |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
502 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
503 |
|
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
504 |
function SDLNet_Read32(buf: pointer): LongWord; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
505 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
506 |
SDLNet_Read32:= PByteArray(buf)^[3] or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
507 |
(PByteArray(buf)^[2] shl 8) or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
508 |
(PByteArray(buf)^[1] shl 16) or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
509 |
(PByteArray(buf)^[0] shl 24) |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
510 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
511 |
|
4 | 512 |
end. |