author | unc0rr |
Thu, 05 Oct 2006 16:33:18 +0000 | |
changeset 183 | 57c2ef19f719 |
parent 174 | 0b2c5b22f644 |
child 191 | a03c2d037e24 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
105 | 3 |
* Copyright (c) 2004, 2005, 2006 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 |
|
21 |
{$IFDEF LINUX} |
|
22 |
{$DEFINE UNIX} |
|
23 |
{$ENDIF} |
|
24 |
{$IFDEF FREEBSD} |
|
25 |
{$DEFINE UNIX} |
|
26 |
{$ENDIF} |
|
27 |
||
28 |
{$IFDEF UNIX} |
|
29 |
{$linklib c} |
|
105 | 30 |
{$linklib pthread} |
4 | 31 |
{$ENDIF} |
32 |
||
33 |
{$IFDEF FPC} |
|
34 |
{$MODE Delphi} |
|
109 | 35 |
{ $PACKRECORDS 4} |
4 | 36 |
{$ENDIF} |
37 |
||
38 |
(* SDL *) |
|
39 |
const {$IFDEF WIN32} |
|
40 |
SDLLibName = 'SDL.dll'; |
|
41 |
{$ENDIF} |
|
42 |
{$IFDEF UNIX} |
|
43 |
SDLLibName = 'libSDL.so'; |
|
44 |
{$ENDIF} |
|
45 |
SDL_SWSURFACE = $00000000; |
|
46 |
SDL_HWSURFACE = $00000001; |
|
47 |
SDL_ASYNCBLIT = $00000004; |
|
48 |
SDL_ANYFORMAT = $10000000; |
|
49 |
SDL_HWPALETTE = $20000000; |
|
50 |
SDL_DOUBLEBUF = $40000000; |
|
51 |
SDL_FULLSCREEN = $80000000; |
|
52 |
SDL_NOFRAME = $00000020; |
|
53 |
SDL_HWACCEL = $00000100; |
|
54 |
SDL_SRCCOLORKEY = $00001000; |
|
55 |
SDL_RLEACCEL = $00004000; |
|
56 |
||
57 |
SDL_NOEVENT = 0; |
|
58 |
SDL_KEYDOWN = 2; |
|
59 |
SDL_KEYUP = 3; |
|
60 |
SDL_QUITEV = 12; |
|
61 |
||
62 |
SDL_INIT_VIDEO = $00000020; |
|
11 | 63 |
SDL_INIT_AUDIO = $00000010; |
64 |
||
4 | 65 |
type PSDL_Rect = ^TSDL_Rect; |
66 |
TSDL_Rect = record |
|
67 |
x, y: SmallInt; |
|
68 |
w, h: Word; |
|
69 |
end; |
|
70 |
||
71 |
TPoint = record |
|
105 | 72 |
X: LongInt; |
73 |
Y: LongInt; |
|
4 | 74 |
end; |
75 |
||
76 |
PSDL_PixelFormat = ^TSDL_PixelFormat; |
|
77 |
TSDL_PixelFormat = record |
|
78 |
palette: Pointer; |
|
79 |
BitsPerPixel : Byte; |
|
80 |
BytesPerPixel: Byte; |
|
81 |
Rloss : Byte; |
|
82 |
Gloss : Byte; |
|
83 |
Bloss : Byte; |
|
84 |
Aloss : Byte; |
|
85 |
Rshift: Byte; |
|
86 |
Gshift: Byte; |
|
87 |
Bshift: Byte; |
|
88 |
Ashift: Byte; |
|
89 |
RMask : Longword; |
|
90 |
GMask : Longword; |
|
91 |
BMask : Longword; |
|
92 |
AMask : Longword; |
|
93 |
colorkey: Longword; |
|
94 |
alpha : Byte; |
|
95 |
end; |
|
96 |
||
97 |
||
98 |
PSDL_Surface = ^TSDL_Surface; |
|
99 |
TSDL_Surface = record |
|
100 |
flags : Longword; |
|
101 |
format: PSDL_PixelFormat; |
|
106 | 102 |
w, h : integer; |
4 | 103 |
pitch : Word; |
104 |
pixels: Pointer; |
|
107 | 105 |
offset: integer; |
4 | 106 |
end; |
107 |
||
108 |
PSDL_Color = ^TSDL_Color; |
|
109 |
TSDL_Color = record |
|
110 |
r: Byte; |
|
111 |
g: Byte; |
|
112 |
b: Byte; |
|
113 |
a: Byte; |
|
114 |
end; |
|
115 |
||
116 |
PSDL_RWops = ^TSDL_RWops; |
|
105 | 117 |
TSeek = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl; |
118 |
TRead = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt; cdecl; |
|
119 |
TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl; |
|
120 |
TClose = function( context: PSDL_RWops ): LongInt; cdecl; |
|
4 | 121 |
|
122 |
TStdio = record |
|
105 | 123 |
autoclose: LongInt; |
4 | 124 |
fp: pointer; |
125 |
end; |
|
126 |
||
127 |
TMem = record |
|
128 |
base: PByte; |
|
129 |
here: PByte; |
|
130 |
stop: PByte; |
|
131 |
end; |
|
132 |
||
133 |
TUnknown = record |
|
134 |
data1: Pointer; |
|
135 |
end; |
|
136 |
||
137 |
TSDL_RWops = record |
|
138 |
seek: TSeek; |
|
139 |
read: TRead; |
|
140 |
write: TWrite; |
|
141 |
close: TClose; |
|
142 |
type_: Longword; |
|
143 |
case Byte of |
|
144 |
0: (stdio: TStdio); |
|
145 |
1: (mem: TMem); |
|
146 |
2: (unknown: TUnknown); |
|
147 |
end; |
|
148 |
||
149 |
TSDL_KeySym = record |
|
150 |
scancode: Byte; |
|
106 | 151 |
sym: Longword; |
4 | 152 |
modifier: Longword; |
153 |
unicode: Word; |
|
154 |
end; |
|
155 |
||
156 |
TSDL_KeyboardEvent = record |
|
157 |
type_: Byte; |
|
158 |
which: Byte; |
|
159 |
state: Byte; |
|
160 |
keysym: TSDL_KeySym; |
|
161 |
end; |
|
162 |
||
163 |
TSDL_QuitEvent = record |
|
164 |
type_: Byte; |
|
165 |
end; |
|
166 |
PSDL_Event = ^TSDL_Event; |
|
167 |
TSDL_Event = record |
|
168 |
case Byte of |
|
169 |
SDL_NOEVENT: (type_: byte); |
|
170 |
SDL_KEYDOWN, SDL_KEYUP: (key: TSDL_KeyboardEvent); |
|
171 |
SDL_QUITEV: (quit: TSDL_QuitEvent); |
|
172 |
end; |
|
173 |
||
174 |
PByteArray = ^TByteArray; |
|
175 |
TByteArray = array[0..32767] of Byte; |
|
176 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
177 |
PSDL_Thread = Pointer; |
95 | 178 |
PSDL_mutex = Pointer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
179 |
|
107 | 180 |
function SDL_Init(flags: Longword): integer; cdecl; external SDLLibName; |
4 | 181 |
procedure SDL_Quit; cdecl; external SDLLibName; |
182 |
||
183 |
procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; |
|
184 |
function SDL_GetTicks: Longword; cdecl; external SDLLibName; |
|
185 |
||
186 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
107 | 187 |
function SDL_LockSurface(Surface: PSDL_Surface): integer; cdecl; external SDLLibName; |
4 | 188 |
procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
189 |
||
190 |
function SDL_GetError: PChar; cdecl; external SDLLibName; |
|
191 |
||
107 | 192 |
function SDL_SetVideoMode(width, height, bpp: integer; flags: Longword): PSDL_Surface; cdecl; external SDLLibName; |
193 |
function SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
194 |
function SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
4 | 195 |
procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
105 | 196 |
function SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName; |
4 | 197 |
|
105 | 198 |
function SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName; |
199 |
function SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName; |
|
200 |
procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: Longword); cdecl; external SDLLibName; |
|
107 | 201 |
function SDL_Flip(Screen: PSDL_Surface): integer; cdecl; external SDLLibName; |
4 | 202 |
|
203 |
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName; |
|
107 | 204 |
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName; |
4 | 205 |
|
206 |
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
|
35 | 207 |
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
4 | 208 |
|
209 |
function SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName; |
|
107 | 210 |
function SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: integer): integer; cdecl; external SDLLibName; |
4 | 211 |
|
105 | 212 |
function SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName; |
107 | 213 |
function SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName; |
4 | 214 |
function SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName; |
215 |
procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName; |
|
216 |
||
107 | 217 |
function SDL_PollEvent(event: PSDL_Event): integer; cdecl; external SDLLibName; |
4 | 218 |
|
107 | 219 |
function SDL_ShowCursor(toggle: integer): integer; cdecl; external SDLLibName; |
4 | 220 |
|
221 |
procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; |
|
222 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
223 |
function SDL_CreateThread(fn: pointer; data: pointer): PSDL_Thread; cdecl; external SDLLibName; |
105 | 224 |
procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName; |
95 | 225 |
function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName; |
226 |
procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName; |
|
107 | 227 |
function SDL_LockMutex(mutex: PSDL_mutex): integer; cdecl; external SDLLibName name 'SDL_mutexP'; |
228 |
function SDL_UnlockMutex(mutex: PSDL_mutex): integer; cdecl; external SDLLibName name 'SDL_mutexV'; |
|
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
229 |
|
4 | 230 |
(* TTF *) |
231 |
||
232 |
const {$IFDEF WIN32} |
|
233 |
SDL_TTFLibName = 'SDL_ttf.dll'; |
|
234 |
{$ENDIF} |
|
235 |
{$IFDEF UNIX} |
|
236 |
SDL_TTFLibName = 'libSDL_ttf.so'; |
|
237 |
{$ENDIF} |
|
238 |
||
239 |
||
240 |
type PTTF_Font = ^TTTF_font; |
|
241 |
TTTF_Font = record |
|
242 |
end; |
|
243 |
||
105 | 244 |
function TTF_Init: LongInt; cdecl; external SDL_TTFLibName; |
4 | 245 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
246 |
||
247 |
||
107 | 248 |
function TTF_SizeUTF8(font : PTTF_Font; const text: PChar; var w, h: integer): LongInt; cdecl; external SDL_TTFLibName; |
74 | 249 |
function TTF_RenderUTF8_Solid(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
250 |
function TTF_RenderUTF8_Blended(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
107 | 251 |
function TTF_OpenFont(const filename: Pchar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName; |
4 | 252 |
|
253 |
(* SDL_mixer *) |
|
254 |
||
255 |
const {$IFDEF WIN32} |
|
256 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
257 |
{$ENDIF} |
|
258 |
{$IFDEF UNIX} |
|
259 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
|
260 |
{$ENDIF} |
|
261 |
||
174 | 262 |
const MIX_MAX_VOLUME = 128; |
263 |
||
4 | 264 |
type PMixChunk = ^TMixChunk; |
265 |
TMixChunk = record |
|
266 |
allocated: Longword; |
|
267 |
abuf : PByte; |
|
268 |
alen : Longword; |
|
269 |
volume : PByte; |
|
106 | 270 |
end; |
4 | 271 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
272 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
273 |
||
274 |
TMidiSong = record |
|
105 | 275 |
samples : LongInt; |
4 | 276 |
events : pointer; |
277 |
end; |
|
278 |
||
279 |
TMusicUnion = record |
|
280 |
case Byte of |
|
281 |
0: ( midi : TMidiSong ); |
|
282 |
1: ( ogg : pointer); |
|
283 |
end; |
|
284 |
||
285 |
PMixMusic = ^TMixMusic; |
|
286 |
TMixMusic = record |
|
287 |
end; |
|
288 |
||
105 | 289 |
function Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 290 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
291 |
||
174 | 292 |
function Mix_Volume(channel: LongInt; volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
293 |
function Mix_SetDistance(channel: LongInt; distance: Byte): LongInt; cdecl; external SDL_MixerLibName; |
|
105 | 294 |
function Mix_VolumeMusic(volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 295 |
|
174 | 296 |
function Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 297 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
298 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
299 |
||
105 | 300 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName; |
4 | 301 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
302 |
||
105 | 303 |
function Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
304 |
function Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 305 |
|
105 | 306 |
function Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
307 |
function Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
308 |
function Mix_HaltChannel(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 309 |
|
310 |
(* SDL_image *) |
|
311 |
||
312 |
const {$IFDEF WIN32} |
|
313 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
314 |
{$ENDIF} |
|
315 |
{$IFDEF UNIX} |
|
316 |
SDL_ImageLibName = 'libSDL_image.so'; |
|
317 |
{$ENDIF} |
|
318 |
||
319 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
320 |
||
321 |
(* SDL_net *) |
|
322 |
||
323 |
const {$IFDEF WIN32} |
|
324 |
SDL_NetLibName = 'SDL_net.dll'; |
|
325 |
{$ENDIF} |
|
326 |
{$IFDEF UNIX} |
|
327 |
SDL_NetLibName = 'libSDL_net.so'; |
|
328 |
{$ENDIF} |
|
329 |
||
330 |
type TIPAddress = record |
|
331 |
host: Longword; |
|
332 |
port: Word; |
|
333 |
end; |
|
334 |
||
335 |
PTCPSocket = ^TTCPSocket; |
|
336 |
TTCPSocket = record |
|
106 | 337 |
ready: LongInt; |
105 | 338 |
channel: LongInt; |
106 | 339 |
remoteAddress: TIPaddress; |
4 | 340 |
localAddress: TIPaddress; |
105 | 341 |
sflag: LongInt; |
4 | 342 |
end; |
343 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
344 |
TSDLNet_SocketSet = record |
|
345 |
numsockets, |
|
105 | 346 |
maxsockets: LongInt; |
4 | 347 |
sockets: PTCPSocket; |
348 |
end; |
|
349 |
||
105 | 350 |
function SDLNet_Init: LongInt; cdecl; external SDL_NetLibName; |
4 | 351 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
352 |
||
105 | 353 |
function SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
354 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 355 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
356 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
105 | 357 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
358 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 359 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
360 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
105 | 361 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName; |
362 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 363 |
|
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
364 |
procedure SDLNet_Write16(value: SmallInt; buf: pointer); cdecl; external SDL_NetLibName; |
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
365 |
procedure SDLNet_Write32(value: LongInt; buf: pointer); cdecl; external SDL_NetLibName; |
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
366 |
function SDLNet_Read16(buf: pointer): SmallInt; cdecl; external SDL_NetLibName; |
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
367 |
function SDLNet_Read32(buf: pointer): LongInt; cdecl; external SDL_NetLibName; |
4 | 368 |
|
369 |
implementation |
|
370 |
||
371 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
372 |
begin |
|
373 |
Result:= ( surface^.offset <> 0 ) |
|
374 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
|
375 |
end; |
|
376 |
||
377 |
end. |