author | unc0rr |
Tue, 20 Jun 2006 21:20:06 +0000 | |
changeset 67 | 3101306251e5 |
parent 66 | 9643d75baf1e |
child 70 | 82d93eeecebe |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
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} |
|
45 |
{$linklib pthread} // кажется, это только для FreeBSD, не уверен |
|
46 |
{$ENDIF} |
|
47 |
||
48 |
{$IFDEF FPC} |
|
49 |
{$MODE Delphi} |
|
50 |
{$PACKRECORDS 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 |
|
87 |
x: Integer; |
|
88 |
y: Integer; |
|
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; |
|
117 |
w, h : Integer; |
|
118 |
pitch : Word; |
|
119 |
pixels: Pointer; |
|
120 |
offset: Integer; |
|
121 |
hwdata: Pointer; |
|
122 |
clip_rect: TSDL_Rect; |
|
123 |
unused1, |
|
124 |
locked : Longword; |
|
125 |
Blitmap : Pointer; |
|
126 |
format_version: Longword; |
|
127 |
refcount : Integer; |
|
128 |
end; |
|
129 |
||
130 |
PSDL_Color = ^TSDL_Color; |
|
131 |
TSDL_Color = record |
|
132 |
r: Byte; |
|
133 |
g: Byte; |
|
134 |
b: Byte; |
|
135 |
a: Byte; |
|
136 |
end; |
|
137 |
||
138 |
PSDL_RWops = ^TSDL_RWops; |
|
139 |
TSeek = function( context: PSDL_RWops; offset: Integer; whence: Integer ): Integer; cdecl; |
|
140 |
TRead = function( context: PSDL_RWops; Ptr: Pointer; size: Integer; maxnum : Integer ): Integer; cdecl; |
|
141 |
TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: Integer; num: Integer ): Integer; cdecl; |
|
142 |
TClose = function( context: PSDL_RWops ): Integer; cdecl; |
|
143 |
||
144 |
TStdio = record |
|
145 |
autoclose: Integer; |
|
146 |
fp: pointer; |
|
147 |
end; |
|
148 |
||
149 |
TMem = record |
|
150 |
base: PByte; |
|
151 |
here: PByte; |
|
152 |
stop: PByte; |
|
153 |
end; |
|
154 |
||
155 |
TUnknown = record |
|
156 |
data1: Pointer; |
|
157 |
end; |
|
158 |
||
159 |
TSDL_RWops = record |
|
160 |
seek: TSeek; |
|
161 |
read: TRead; |
|
162 |
write: TWrite; |
|
163 |
close: TClose; |
|
164 |
type_: Longword; |
|
165 |
case Byte of |
|
166 |
0: (stdio: TStdio); |
|
167 |
1: (mem: TMem); |
|
168 |
2: (unknown: TUnknown); |
|
169 |
end; |
|
170 |
||
171 |
TSDL_KeySym = record |
|
172 |
scancode: Byte; |
|
173 |
sym, |
|
174 |
modifier: Longword; |
|
175 |
unicode: Word; |
|
176 |
end; |
|
177 |
||
178 |
TSDL_KeyboardEvent = record |
|
179 |
type_: Byte; |
|
180 |
which: Byte; |
|
181 |
state: Byte; |
|
182 |
keysym: TSDL_KeySym; |
|
183 |
end; |
|
184 |
||
185 |
TSDL_QuitEvent = record |
|
186 |
type_: Byte; |
|
187 |
end; |
|
188 |
PSDL_Event = ^TSDL_Event; |
|
189 |
TSDL_Event = record |
|
190 |
case Byte of |
|
191 |
SDL_NOEVENT: (type_: byte); |
|
192 |
SDL_KEYDOWN, SDL_KEYUP: (key: TSDL_KeyboardEvent); |
|
193 |
SDL_QUITEV: (quit: TSDL_QuitEvent); |
|
194 |
end; |
|
195 |
||
196 |
PByteArray = ^TByteArray; |
|
197 |
TByteArray = array[0..32767] of Byte; |
|
198 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
199 |
PSDL_Thread = Pointer; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
200 |
|
4 | 201 |
function SDL_Init(flags: Longword): Integer; cdecl; external SDLLibName; |
202 |
procedure SDL_Quit; cdecl; external SDLLibName; |
|
203 |
||
204 |
procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; |
|
205 |
function SDL_GetTicks: Longword; cdecl; external SDLLibName; |
|
206 |
||
207 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
208 |
function SDL_LockSurface(Surface: PSDL_Surface): Integer; cdecl; external SDLLibName; |
|
209 |
procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
|
210 |
||
211 |
function SDL_GetError: PChar; cdecl; external SDLLibName; |
|
212 |
||
213 |
function SDL_SetVideoMode(width, height, bpp: Integer; flags: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
214 |
function SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: Integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
215 |
function SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: Integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
216 |
procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
|
217 |
function SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): Integer; cdecl; external SDLLibName; |
|
218 |
||
219 |
function SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): Integer; cdecl; external SDLLibName; |
|
220 |
function SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): Integer; cdecl; external SDLLibName; |
|
221 |
procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: Integer; w, h: Longword); cdecl; external SDLLibName; |
|
222 |
function SDL_Flip(Screen: PSDL_Surface): Integer; cdecl; external SDLLibName; |
|
223 |
||
224 |
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName; |
|
225 |
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Integer; cdecl; external SDLLibName; |
|
226 |
||
227 |
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
|
35 | 228 |
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
4 | 229 |
|
230 |
function SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName; |
|
231 |
function SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: Integer): Integer; cdecl; external SDLLibName; |
|
232 |
||
233 |
function SDL_GetKeyState(numkeys: PInteger): PByteArray; cdecl; external SDLLibName; |
|
234 |
function SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName; |
|
235 |
function SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName; |
|
236 |
procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName; |
|
237 |
||
238 |
function SDL_PollEvent(event: PSDL_Event): Integer; cdecl; external SDLLibName; |
|
239 |
||
240 |
function SDL_ShowCursor(toggle: Integer): Integer; cdecl; external SDLLibName; |
|
241 |
||
242 |
procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; |
|
243 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
244 |
function SDL_CreateThread(fn: pointer; data: pointer): PSDL_Thread; cdecl; external SDLLibName; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
245 |
procedure SDL_WaitThread(thread: PSDL_Thread; status: PInteger); cdecl; external SDLLibName; |
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
246 |
|
4 | 247 |
(* TTF *) |
248 |
||
249 |
const {$IFDEF WIN32} |
|
250 |
SDL_TTFLibName = 'SDL_ttf.dll'; |
|
251 |
{$ENDIF} |
|
252 |
{$IFDEF UNIX} |
|
253 |
SDL_TTFLibName = 'libSDL_ttf.so'; |
|
254 |
{$ENDIF} |
|
255 |
||
256 |
||
257 |
type PTTF_Font = ^TTTF_font; |
|
258 |
TTTF_Font = record |
|
259 |
end; |
|
260 |
||
261 |
function TTF_Init: integer; cdecl; external SDL_TTFLibName; |
|
262 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
|
263 |
||
264 |
||
265 |
function TTF_SizeText(font : PTTF_Font; const text: PChar; var w, h: integer): Integer; cdecl; external SDL_TTFLibName; |
|
266 |
function TTF_RenderText_Solid(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
267 |
function TTF_RenderText_Blended(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
268 |
function TTF_OpenFont(const filename: Pchar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName; |
|
269 |
||
270 |
(* SDL_mixer *) |
|
271 |
||
272 |
const {$IFDEF WIN32} |
|
273 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
274 |
{$ENDIF} |
|
275 |
{$IFDEF UNIX} |
|
276 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
|
277 |
{$ENDIF} |
|
278 |
||
279 |
type PMixChunk = ^TMixChunk; |
|
280 |
TMixChunk = record |
|
281 |
allocated: Longword; |
|
282 |
abuf : PByte; |
|
283 |
alen : Longword; |
|
284 |
volume : PByte; |
|
285 |
end; |
|
286 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
|
287 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
288 |
||
289 |
TMidiSong = record |
|
290 |
samples : Integer; |
|
291 |
events : pointer; |
|
292 |
end; |
|
293 |
||
294 |
TMusicUnion = record |
|
295 |
case Byte of |
|
296 |
0: ( midi : TMidiSong ); |
|
297 |
1: ( ogg : pointer); |
|
298 |
end; |
|
299 |
||
300 |
PMixMusic = ^TMixMusic; |
|
301 |
TMixMusic = record |
|
302 |
type_ : TMusic; |
|
303 |
data : TMusicUnion; |
|
304 |
fading : TMix_Fading; |
|
305 |
fade_volume, |
|
306 |
fade_step, |
|
307 |
fade_steps, |
|
308 |
error : integer; |
|
309 |
end; |
|
310 |
||
311 |
function Mix_OpenAudio(frequency: integer; format: Word; channels: integer; chunksize: integer): integer; cdecl; external SDL_MixerLibName; |
|
312 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
|
313 |
||
314 |
function Mix_VolumeMusic(volume: integer): integer; cdecl; external SDL_MixerLibName; |
|
315 |
||
11 | 316 |
function Mix_AllocateChannels(numchans: integer): integer; cdecl; external SDL_MixerLibName; |
4 | 317 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
318 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
319 |
||
320 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: integer): PMixChunk; cdecl; external SDL_MixerLibName; |
|
321 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
|
322 |
||
323 |
function Mix_Playing(channel: integer): integer; cdecl; external SDL_MixerLibName; |
|
324 |
function Mix_PlayingMusic: integer; cdecl; external SDL_MixerLibName; |
|
325 |
||
326 |
function Mix_PlayChannelTimed(channel: integer; chunk: PMixChunk; loops: integer; ticks: integer): integer; cdecl; external SDL_MixerLibName; |
|
327 |
function Mix_PlayMusic(music: PMixMusic; loops: integer): integer; cdecl; external SDL_MixerLibName; |
|
328 |
function Mix_HaltChannel(channel: integer): integer; cdecl; external SDL_MixerLibName; |
|
329 |
||
330 |
(* SDL_image *) |
|
331 |
||
332 |
const {$IFDEF WIN32} |
|
333 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
334 |
{$ENDIF} |
|
335 |
{$IFDEF UNIX} |
|
336 |
SDL_ImageLibName = 'libSDL_image.so'; |
|
337 |
{$ENDIF} |
|
338 |
||
339 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
340 |
||
341 |
(* SDL_net *) |
|
342 |
||
343 |
const {$IFDEF WIN32} |
|
344 |
SDL_NetLibName = 'SDL_net.dll'; |
|
345 |
{$ENDIF} |
|
346 |
{$IFDEF UNIX} |
|
347 |
SDL_NetLibName = 'libSDL_net.so'; |
|
348 |
{$ENDIF} |
|
349 |
||
350 |
type TIPAddress = record |
|
351 |
host: Longword; |
|
352 |
port: Word; |
|
353 |
end; |
|
354 |
||
355 |
PTCPSocket = ^TTCPSocket; |
|
356 |
TTCPSocket = record |
|
357 |
ready, |
|
358 |
channel: integer; |
|
359 |
remoteAddress, |
|
360 |
localAddress: TIPaddress; |
|
361 |
sflag: integer; |
|
362 |
end; |
|
363 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
364 |
TSDLNet_SocketSet = record |
|
365 |
numsockets, |
|
366 |
maxsockets: integer; |
|
367 |
sockets: PTCPSocket; |
|
368 |
end; |
|
369 |
||
370 |
function SDLNet_Init: integer; cdecl; external SDL_NetLibName; |
|
371 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
|
372 |
||
373 |
function SDLNet_AllocSocketSet(maxsockets: integer): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
|
374 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): integer; cdecl; external SDL_NetLibName; |
|
375 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
|
376 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
377 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: integer): integer; cdecl; external SDL_NetLibName; |
|
378 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: integer): integer; cdecl; external SDL_NetLibName; |
|
379 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
|
380 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
381 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): integer; cdecl; external SDL_NetLibName; |
|
382 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: integer): integer; cdecl; external SDL_NetLibName; |
|
383 |
||
384 |
||
385 |
implementation |
|
386 |
||
387 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
388 |
begin |
|
389 |
Result:= ( surface^.offset <> 0 ) |
|
390 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
|
391 |
end; |
|
392 |
||
393 |
end. |