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