author | unc0rr |
Sat, 05 Aug 2006 20:57:36 +0000 | |
changeset 95 | 1ef5e2c41115 |
parent 74 | 42257fee61ae |
child 105 | e7cb9bb4a9de |
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 |
|
70 | 87 |
X: Integer; |
88 |
Y: Integer; |
|
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; |
|
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; |
95 | 200 |
PSDL_mutex = Pointer; |
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
201 |
|
4 | 202 |
function SDL_Init(flags: Longword): Integer; cdecl; external SDLLibName; |
203 |
procedure SDL_Quit; cdecl; external SDLLibName; |
|
204 |
||
205 |
procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; |
|
206 |
function SDL_GetTicks: Longword; cdecl; external SDLLibName; |
|
207 |
||
208 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
209 |
function SDL_LockSurface(Surface: PSDL_Surface): Integer; cdecl; external SDLLibName; |
|
210 |
procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
|
211 |
||
212 |
function SDL_GetError: PChar; cdecl; external SDLLibName; |
|
213 |
||
214 |
function SDL_SetVideoMode(width, height, bpp: Integer; flags: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
215 |
function SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: Integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
216 |
function SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: Integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
217 |
procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
|
218 |
function SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): Integer; cdecl; external SDLLibName; |
|
219 |
||
220 |
function SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): Integer; cdecl; external SDLLibName; |
|
221 |
function SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): Integer; cdecl; external SDLLibName; |
|
222 |
procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: Integer; w, h: Longword); cdecl; external SDLLibName; |
|
223 |
function SDL_Flip(Screen: PSDL_Surface): Integer; cdecl; external SDLLibName; |
|
224 |
||
225 |
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName; |
|
226 |
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Integer; cdecl; external SDLLibName; |
|
227 |
||
228 |
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
|
35 | 229 |
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
4 | 230 |
|
231 |
function SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName; |
|
232 |
function SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: Integer): Integer; cdecl; external SDLLibName; |
|
233 |
||
234 |
function SDL_GetKeyState(numkeys: PInteger): PByteArray; cdecl; external SDLLibName; |
|
235 |
function SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName; |
|
236 |
function SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName; |
|
237 |
procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName; |
|
238 |
||
239 |
function SDL_PollEvent(event: PSDL_Event): Integer; cdecl; external SDLLibName; |
|
240 |
||
241 |
function SDL_ShowCursor(toggle: Integer): Integer; cdecl; external SDLLibName; |
|
242 |
||
243 |
procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; |
|
244 |
||
66
9643d75baf1e
Many AI improvements, bots do think in separate thread
unc0rr
parents:
35
diff
changeset
|
245 |
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
|
246 |
procedure SDL_WaitThread(thread: PSDL_Thread; status: PInteger); cdecl; external SDLLibName; |
95 | 247 |
function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName; |
248 |
procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName; |
|
249 |
function SDL_LockMutex(mutex: PSDL_mutex): integer; cdecl; external SDLLibName name 'SDL_mutexP'; |
|
250 |
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
|
251 |
|
4 | 252 |
(* TTF *) |
253 |
||
254 |
const {$IFDEF WIN32} |
|
255 |
SDL_TTFLibName = 'SDL_ttf.dll'; |
|
256 |
{$ENDIF} |
|
257 |
{$IFDEF UNIX} |
|
258 |
SDL_TTFLibName = 'libSDL_ttf.so'; |
|
259 |
{$ENDIF} |
|
260 |
||
261 |
||
262 |
type PTTF_Font = ^TTTF_font; |
|
263 |
TTTF_Font = record |
|
264 |
end; |
|
265 |
||
266 |
function TTF_Init: integer; cdecl; external SDL_TTFLibName; |
|
267 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
|
268 |
||
269 |
||
74 | 270 |
function TTF_SizeUTF8(font : PTTF_Font; const text: PChar; var w, h: integer): Integer; cdecl; external SDL_TTFLibName; |
271 |
function TTF_RenderUTF8_Solid(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
272 |
function TTF_RenderUTF8_Blended(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
4 | 273 |
function TTF_OpenFont(const filename: Pchar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName; |
274 |
||
275 |
(* SDL_mixer *) |
|
276 |
||
277 |
const {$IFDEF WIN32} |
|
278 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
279 |
{$ENDIF} |
|
280 |
{$IFDEF UNIX} |
|
281 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
|
282 |
{$ENDIF} |
|
283 |
||
284 |
type PMixChunk = ^TMixChunk; |
|
285 |
TMixChunk = record |
|
286 |
allocated: Longword; |
|
287 |
abuf : PByte; |
|
288 |
alen : Longword; |
|
289 |
volume : PByte; |
|
290 |
end; |
|
291 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
|
292 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
293 |
||
294 |
TMidiSong = record |
|
295 |
samples : Integer; |
|
296 |
events : pointer; |
|
297 |
end; |
|
298 |
||
299 |
TMusicUnion = record |
|
300 |
case Byte of |
|
301 |
0: ( midi : TMidiSong ); |
|
302 |
1: ( ogg : pointer); |
|
303 |
end; |
|
304 |
||
305 |
PMixMusic = ^TMixMusic; |
|
306 |
TMixMusic = record |
|
307 |
type_ : TMusic; |
|
308 |
data : TMusicUnion; |
|
309 |
fading : TMix_Fading; |
|
310 |
fade_volume, |
|
311 |
fade_step, |
|
312 |
fade_steps, |
|
313 |
error : integer; |
|
314 |
end; |
|
315 |
||
316 |
function Mix_OpenAudio(frequency: integer; format: Word; channels: integer; chunksize: integer): integer; cdecl; external SDL_MixerLibName; |
|
317 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
|
318 |
||
319 |
function Mix_VolumeMusic(volume: integer): integer; cdecl; external SDL_MixerLibName; |
|
320 |
||
11 | 321 |
function Mix_AllocateChannels(numchans: integer): integer; cdecl; external SDL_MixerLibName; |
4 | 322 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
323 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
324 |
||
325 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: integer): PMixChunk; cdecl; external SDL_MixerLibName; |
|
326 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
|
327 |
||
328 |
function Mix_Playing(channel: integer): integer; cdecl; external SDL_MixerLibName; |
|
329 |
function Mix_PlayingMusic: integer; cdecl; external SDL_MixerLibName; |
|
330 |
||
331 |
function Mix_PlayChannelTimed(channel: integer; chunk: PMixChunk; loops: integer; ticks: integer): integer; cdecl; external SDL_MixerLibName; |
|
332 |
function Mix_PlayMusic(music: PMixMusic; loops: integer): integer; cdecl; external SDL_MixerLibName; |
|
333 |
function Mix_HaltChannel(channel: integer): integer; cdecl; external SDL_MixerLibName; |
|
334 |
||
335 |
(* SDL_image *) |
|
336 |
||
337 |
const {$IFDEF WIN32} |
|
338 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
339 |
{$ENDIF} |
|
340 |
{$IFDEF UNIX} |
|
341 |
SDL_ImageLibName = 'libSDL_image.so'; |
|
342 |
{$ENDIF} |
|
343 |
||
344 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
345 |
||
346 |
(* SDL_net *) |
|
347 |
||
348 |
const {$IFDEF WIN32} |
|
349 |
SDL_NetLibName = 'SDL_net.dll'; |
|
350 |
{$ENDIF} |
|
351 |
{$IFDEF UNIX} |
|
352 |
SDL_NetLibName = 'libSDL_net.so'; |
|
353 |
{$ENDIF} |
|
354 |
||
355 |
type TIPAddress = record |
|
356 |
host: Longword; |
|
357 |
port: Word; |
|
358 |
end; |
|
359 |
||
360 |
PTCPSocket = ^TTCPSocket; |
|
361 |
TTCPSocket = record |
|
362 |
ready, |
|
363 |
channel: integer; |
|
364 |
remoteAddress, |
|
365 |
localAddress: TIPaddress; |
|
366 |
sflag: integer; |
|
367 |
end; |
|
368 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
369 |
TSDLNet_SocketSet = record |
|
370 |
numsockets, |
|
371 |
maxsockets: integer; |
|
372 |
sockets: PTCPSocket; |
|
373 |
end; |
|
374 |
||
375 |
function SDLNet_Init: integer; cdecl; external SDL_NetLibName; |
|
376 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
|
377 |
||
378 |
function SDLNet_AllocSocketSet(maxsockets: integer): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
|
379 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): integer; cdecl; external SDL_NetLibName; |
|
380 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
|
381 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
382 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: integer): integer; cdecl; external SDL_NetLibName; |
|
383 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: integer): integer; cdecl; external SDL_NetLibName; |
|
384 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
|
385 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
386 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): integer; cdecl; external SDL_NetLibName; |
|
387 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: integer): integer; cdecl; external SDL_NetLibName; |
|
388 |
||
389 |
||
390 |
implementation |
|
391 |
||
392 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
393 |
begin |
|
394 |
Result:= ( surface^.offset <> 0 ) |
|
395 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
|
396 |
end; |
|
397 |
||
398 |
end. |