author | unc0rr |
Fri, 18 Aug 2006 21:02:11 +0000 | |
changeset 119 | 665c07365cb6 |
parent 109 | ab0340f580c2 |
child 154 | 5667e6f38704 |
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 |
* |
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
unit SDLh; |
|
35 |
interface |
|
36 |
{$IFDEF LINUX} |
|
37 |
{$DEFINE UNIX} |
|
38 |
{$ENDIF} |
|
39 |
{$IFDEF FREEBSD} |
|
40 |
{$DEFINE UNIX} |
|
41 |
{$ENDIF} |
|
42 |
||
43 |
{$IFDEF UNIX} |
|
44 |
{$linklib c} |
|
105 | 45 |
{$linklib pthread} |
4 | 46 |
{$ENDIF} |
47 |
||
48 |
{$IFDEF FPC} |
|
49 |
{$MODE Delphi} |
|
109 | 50 |
{ $PACKRECORDS 4} |
4 | 51 |
{$ENDIF} |
52 |
||
53 |
(* SDL *) |
|
54 |
const {$IFDEF WIN32} |
|
55 |
SDLLibName = 'SDL.dll'; |
|
56 |
{$ENDIF} |
|
57 |
{$IFDEF UNIX} |
|
58 |
SDLLibName = 'libSDL.so'; |
|
59 |
{$ENDIF} |
|
60 |
SDL_SWSURFACE = $00000000; |
|
61 |
SDL_HWSURFACE = $00000001; |
|
62 |
SDL_ASYNCBLIT = $00000004; |
|
63 |
SDL_ANYFORMAT = $10000000; |
|
64 |
SDL_HWPALETTE = $20000000; |
|
65 |
SDL_DOUBLEBUF = $40000000; |
|
66 |
SDL_FULLSCREEN = $80000000; |
|
67 |
SDL_NOFRAME = $00000020; |
|
68 |
SDL_HWACCEL = $00000100; |
|
69 |
SDL_SRCCOLORKEY = $00001000; |
|
70 |
SDL_RLEACCEL = $00004000; |
|
71 |
||
72 |
SDL_NOEVENT = 0; |
|
73 |
SDL_KEYDOWN = 2; |
|
74 |
SDL_KEYUP = 3; |
|
75 |
SDL_QUITEV = 12; |
|
76 |
||
77 |
SDL_INIT_VIDEO = $00000020; |
|
11 | 78 |
SDL_INIT_AUDIO = $00000010; |
79 |
||
4 | 80 |
type PSDL_Rect = ^TSDL_Rect; |
81 |
TSDL_Rect = record |
|
82 |
x, y: SmallInt; |
|
83 |
w, h: Word; |
|
84 |
end; |
|
85 |
||
86 |
TPoint = record |
|
105 | 87 |
X: LongInt; |
88 |
Y: LongInt; |
|
4 | 89 |
end; |
90 |
||
91 |
PSDL_PixelFormat = ^TSDL_PixelFormat; |
|
92 |
TSDL_PixelFormat = record |
|
93 |
palette: Pointer; |
|
94 |
BitsPerPixel : Byte; |
|
95 |
BytesPerPixel: Byte; |
|
96 |
Rloss : Byte; |
|
97 |
Gloss : Byte; |
|
98 |
Bloss : Byte; |
|
99 |
Aloss : Byte; |
|
100 |
Rshift: Byte; |
|
101 |
Gshift: Byte; |
|
102 |
Bshift: Byte; |
|
103 |
Ashift: Byte; |
|
104 |
RMask : Longword; |
|
105 |
GMask : Longword; |
|
106 |
BMask : Longword; |
|
107 |
AMask : Longword; |
|
108 |
colorkey: Longword; |
|
109 |
alpha : Byte; |
|
110 |
end; |
|
111 |
||
112 |
||
113 |
PSDL_Surface = ^TSDL_Surface; |
|
114 |
TSDL_Surface = record |
|
115 |
flags : Longword; |
|
116 |
format: PSDL_PixelFormat; |
|
106 | 117 |
w, h : integer; |
4 | 118 |
pitch : Word; |
119 |
pixels: Pointer; |
|
107 | 120 |
offset: integer; |
4 | 121 |
end; |
122 |
||
123 |
PSDL_Color = ^TSDL_Color; |
|
124 |
TSDL_Color = record |
|
125 |
r: Byte; |
|
126 |
g: Byte; |
|
127 |
b: Byte; |
|
128 |
a: Byte; |
|
129 |
end; |
|
130 |
||
131 |
PSDL_RWops = ^TSDL_RWops; |
|
105 | 132 |
TSeek = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl; |
133 |
TRead = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt; cdecl; |
|
134 |
TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl; |
|
135 |
TClose = function( context: PSDL_RWops ): LongInt; cdecl; |
|
4 | 136 |
|
137 |
TStdio = record |
|
105 | 138 |
autoclose: LongInt; |
4 | 139 |
fp: pointer; |
140 |
end; |
|
141 |
||
142 |
TMem = record |
|
143 |
base: PByte; |
|
144 |
here: PByte; |
|
145 |
stop: PByte; |
|
146 |
end; |
|
147 |
||
148 |
TUnknown = record |
|
149 |
data1: Pointer; |
|
150 |
end; |
|
151 |
||
152 |
TSDL_RWops = record |
|
153 |
seek: TSeek; |
|
154 |
read: TRead; |
|
155 |
write: TWrite; |
|
156 |
close: TClose; |
|
157 |
type_: Longword; |
|
158 |
case Byte of |
|
159 |
0: (stdio: TStdio); |
|
160 |
1: (mem: TMem); |
|
161 |
2: (unknown: TUnknown); |
|
162 |
end; |
|
163 |
||
164 |
TSDL_KeySym = record |
|
165 |
scancode: Byte; |
|
106 | 166 |
sym: Longword; |
4 | 167 |
modifier: Longword; |
168 |
unicode: Word; |
|
169 |
end; |
|
170 |
||
171 |
TSDL_KeyboardEvent = record |
|
172 |
type_: Byte; |
|
173 |
which: Byte; |
|
174 |
state: Byte; |
|
175 |
keysym: TSDL_KeySym; |
|
176 |
end; |
|
177 |
||
178 |
TSDL_QuitEvent = record |
|
179 |
type_: Byte; |
|
180 |
end; |
|
181 |
PSDL_Event = ^TSDL_Event; |
|
182 |
TSDL_Event = record |
|
183 |
case Byte of |
|
184 |
SDL_NOEVENT: (type_: byte); |
|
185 |
SDL_KEYDOWN, SDL_KEYUP: (key: TSDL_KeyboardEvent); |
|
186 |
SDL_QUITEV: (quit: TSDL_QuitEvent); |
|
187 |
end; |
|
188 |
||
189 |
PByteArray = ^TByteArray; |
|
190 |
TByteArray = array[0..32767] of Byte; |
|
191 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
192 |
PSDL_Thread = Pointer; |
95 | 193 |
PSDL_mutex = Pointer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
194 |
|
107 | 195 |
function SDL_Init(flags: Longword): integer; cdecl; external SDLLibName; |
4 | 196 |
procedure SDL_Quit; cdecl; external SDLLibName; |
197 |
||
198 |
procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; |
|
199 |
function SDL_GetTicks: Longword; cdecl; external SDLLibName; |
|
200 |
||
201 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
107 | 202 |
function SDL_LockSurface(Surface: PSDL_Surface): integer; cdecl; external SDLLibName; |
4 | 203 |
procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
204 |
||
205 |
function SDL_GetError: PChar; cdecl; external SDLLibName; |
|
206 |
||
107 | 207 |
function SDL_SetVideoMode(width, height, bpp: integer; flags: Longword): PSDL_Surface; cdecl; external SDLLibName; |
208 |
function SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
209 |
function SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
4 | 210 |
procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
105 | 211 |
function SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName; |
4 | 212 |
|
105 | 213 |
function SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName; |
214 |
function SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName; |
|
215 |
procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: Longword); cdecl; external SDLLibName; |
|
107 | 216 |
function SDL_Flip(Screen: PSDL_Surface): integer; cdecl; external SDLLibName; |
4 | 217 |
|
218 |
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName; |
|
107 | 219 |
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName; |
4 | 220 |
|
221 |
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
|
35 | 222 |
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
4 | 223 |
|
224 |
function SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName; |
|
107 | 225 |
function SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: integer): integer; cdecl; external SDLLibName; |
4 | 226 |
|
105 | 227 |
function SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName; |
107 | 228 |
function SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName; |
4 | 229 |
function SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName; |
230 |
procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName; |
|
231 |
||
107 | 232 |
function SDL_PollEvent(event: PSDL_Event): integer; cdecl; external SDLLibName; |
4 | 233 |
|
107 | 234 |
function SDL_ShowCursor(toggle: integer): integer; cdecl; external SDLLibName; |
4 | 235 |
|
236 |
procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; |
|
237 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
238 |
function SDL_CreateThread(fn: pointer; data: pointer): PSDL_Thread; cdecl; external SDLLibName; |
105 | 239 |
procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName; |
95 | 240 |
function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName; |
241 |
procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName; |
|
107 | 242 |
function SDL_LockMutex(mutex: PSDL_mutex): integer; cdecl; external SDLLibName name 'SDL_mutexP'; |
243 |
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
|
244 |
|
4 | 245 |
(* TTF *) |
246 |
||
247 |
const {$IFDEF WIN32} |
|
248 |
SDL_TTFLibName = 'SDL_ttf.dll'; |
|
249 |
{$ENDIF} |
|
250 |
{$IFDEF UNIX} |
|
251 |
SDL_TTFLibName = 'libSDL_ttf.so'; |
|
252 |
{$ENDIF} |
|
253 |
||
254 |
||
255 |
type PTTF_Font = ^TTTF_font; |
|
256 |
TTTF_Font = record |
|
257 |
end; |
|
258 |
||
105 | 259 |
function TTF_Init: LongInt; cdecl; external SDL_TTFLibName; |
4 | 260 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
261 |
||
262 |
||
107 | 263 |
function TTF_SizeUTF8(font : PTTF_Font; const text: PChar; var w, h: integer): LongInt; cdecl; external SDL_TTFLibName; |
74 | 264 |
function TTF_RenderUTF8_Solid(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
265 |
function TTF_RenderUTF8_Blended(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
107 | 266 |
function TTF_OpenFont(const filename: Pchar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName; |
4 | 267 |
|
268 |
(* SDL_mixer *) |
|
269 |
||
270 |
const {$IFDEF WIN32} |
|
271 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
272 |
{$ENDIF} |
|
273 |
{$IFDEF UNIX} |
|
274 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
|
275 |
{$ENDIF} |
|
276 |
||
277 |
type PMixChunk = ^TMixChunk; |
|
278 |
TMixChunk = record |
|
279 |
allocated: Longword; |
|
280 |
abuf : PByte; |
|
281 |
alen : Longword; |
|
282 |
volume : PByte; |
|
106 | 283 |
end; |
4 | 284 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
285 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
286 |
||
287 |
TMidiSong = record |
|
105 | 288 |
samples : LongInt; |
4 | 289 |
events : pointer; |
290 |
end; |
|
291 |
||
292 |
TMusicUnion = record |
|
293 |
case Byte of |
|
294 |
0: ( midi : TMidiSong ); |
|
295 |
1: ( ogg : pointer); |
|
296 |
end; |
|
297 |
||
298 |
PMixMusic = ^TMixMusic; |
|
299 |
TMixMusic = record |
|
300 |
end; |
|
301 |
||
105 | 302 |
function Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 303 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
304 |
||
105 | 305 |
function Mix_VolumeMusic(volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 306 |
|
105 | 307 |
function Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 308 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
309 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
310 |
||
105 | 311 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName; |
4 | 312 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
313 |
||
105 | 314 |
function Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
315 |
function Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 316 |
|
105 | 317 |
function Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
318 |
function Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
319 |
function Mix_HaltChannel(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 320 |
|
321 |
(* SDL_image *) |
|
322 |
||
323 |
const {$IFDEF WIN32} |
|
324 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
325 |
{$ENDIF} |
|
326 |
{$IFDEF UNIX} |
|
327 |
SDL_ImageLibName = 'libSDL_image.so'; |
|
328 |
{$ENDIF} |
|
329 |
||
330 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
331 |
||
332 |
(* SDL_net *) |
|
333 |
||
334 |
const {$IFDEF WIN32} |
|
335 |
SDL_NetLibName = 'SDL_net.dll'; |
|
336 |
{$ENDIF} |
|
337 |
{$IFDEF UNIX} |
|
338 |
SDL_NetLibName = 'libSDL_net.so'; |
|
339 |
{$ENDIF} |
|
340 |
||
341 |
type TIPAddress = record |
|
342 |
host: Longword; |
|
343 |
port: Word; |
|
344 |
end; |
|
345 |
||
346 |
PTCPSocket = ^TTCPSocket; |
|
347 |
TTCPSocket = record |
|
106 | 348 |
ready: LongInt; |
105 | 349 |
channel: LongInt; |
106 | 350 |
remoteAddress: TIPaddress; |
4 | 351 |
localAddress: TIPaddress; |
105 | 352 |
sflag: LongInt; |
4 | 353 |
end; |
354 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
355 |
TSDLNet_SocketSet = record |
|
356 |
numsockets, |
|
105 | 357 |
maxsockets: LongInt; |
4 | 358 |
sockets: PTCPSocket; |
359 |
end; |
|
360 |
||
105 | 361 |
function SDLNet_Init: LongInt; cdecl; external SDL_NetLibName; |
4 | 362 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
363 |
||
105 | 364 |
function SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
365 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 366 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
367 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
105 | 368 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
369 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 370 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
371 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
105 | 372 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName; |
373 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 374 |
|
375 |
||
376 |
implementation |
|
377 |
||
378 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
379 |
begin |
|
380 |
Result:= ( surface^.offset <> 0 ) |
|
381 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
|
382 |
end; |
|
383 |
||
384 |
end. |