author | unc0rr |
Wed, 25 Oct 2006 18:03:41 +0000 | |
changeset 203 | 0ee86f9d9ba6 |
parent 202 | 8603c0420461 |
child 206 | 32fa6282efe2 |
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; |
|
202 | 113 |
unused: Byte; |
4 | 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 |
||
107 | 177 |
function SDL_Init(flags: Longword): integer; cdecl; external SDLLibName; |
4 | 178 |
procedure SDL_Quit; cdecl; external SDLLibName; |
192 | 179 |
function SDL_VideoDriverName(var namebuf; maxlen: integer): PChar; cdecl; external SDLLibName; |
4 | 180 |
|
181 |
procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; |
|
182 |
function SDL_GetTicks: Longword; cdecl; external SDLLibName; |
|
183 |
||
184 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
107 | 185 |
function SDL_LockSurface(Surface: PSDL_Surface): integer; cdecl; external SDLLibName; |
4 | 186 |
procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
187 |
||
188 |
function SDL_GetError: PChar; cdecl; external SDLLibName; |
|
189 |
||
107 | 190 |
function SDL_SetVideoMode(width, height, bpp: integer; flags: Longword): PSDL_Surface; cdecl; external SDLLibName; |
191 |
function SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
192 |
function SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: integer; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
4 | 193 |
procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
105 | 194 |
function SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName; |
4 | 195 |
|
105 | 196 |
function SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName; |
197 |
function SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName; |
|
198 |
procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: Longword); cdecl; external SDLLibName; |
|
107 | 199 |
function SDL_Flip(Screen: PSDL_Surface): integer; cdecl; external SDLLibName; |
4 | 200 |
|
201 |
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName; |
|
107 | 202 |
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName; |
4 | 203 |
|
204 |
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
|
35 | 205 |
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
4 | 206 |
|
207 |
function SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName; |
|
107 | 208 |
function SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: integer): integer; cdecl; external SDLLibName; |
4 | 209 |
|
105 | 210 |
function SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName; |
107 | 211 |
function SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName; |
4 | 212 |
function SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName; |
213 |
procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName; |
|
214 |
||
107 | 215 |
function SDL_PollEvent(event: PSDL_Event): integer; cdecl; external SDLLibName; |
4 | 216 |
|
107 | 217 |
function SDL_ShowCursor(toggle: integer): integer; cdecl; external SDLLibName; |
4 | 218 |
|
219 |
procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; |
|
220 |
||
221 |
(* TTF *) |
|
222 |
||
223 |
const {$IFDEF WIN32} |
|
224 |
SDL_TTFLibName = 'SDL_ttf.dll'; |
|
225 |
{$ENDIF} |
|
226 |
{$IFDEF UNIX} |
|
227 |
SDL_TTFLibName = 'libSDL_ttf.so'; |
|
228 |
{$ENDIF} |
|
202 | 229 |
TTF_STYLE_NORMAL = 0; |
230 |
TTF_STYLE_BOLD = 1; |
|
231 |
TTF_STYLE_ITALIC = 2; |
|
4 | 232 |
|
233 |
type PTTF_Font = ^TTTF_font; |
|
234 |
TTTF_Font = record |
|
235 |
end; |
|
236 |
||
200 | 237 |
function TTF_Init: integer; cdecl; external SDL_TTFLibName; |
4 | 238 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
239 |
||
240 |
||
200 | 241 |
function TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: integer): integer; cdecl; external SDL_TTFLibName; |
198 | 242 |
function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
243 |
function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
200 | 244 |
function TTF_OpenFont(const filename: PChar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName; |
202 | 245 |
procedure TTF_SetFontStyle(font: PTTF_Font; style: integer); cdecl; external SDL_TTFLibName; |
4 | 246 |
|
247 |
(* SDL_mixer *) |
|
248 |
||
249 |
const {$IFDEF WIN32} |
|
250 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
251 |
{$ENDIF} |
|
252 |
{$IFDEF UNIX} |
|
253 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
|
254 |
{$ENDIF} |
|
255 |
||
174 | 256 |
const MIX_MAX_VOLUME = 128; |
257 |
||
4 | 258 |
type PMixChunk = ^TMixChunk; |
259 |
TMixChunk = record |
|
260 |
allocated: Longword; |
|
261 |
abuf : PByte; |
|
262 |
alen : Longword; |
|
263 |
volume : PByte; |
|
106 | 264 |
end; |
4 | 265 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
266 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
267 |
||
268 |
TMidiSong = record |
|
105 | 269 |
samples : LongInt; |
4 | 270 |
events : pointer; |
271 |
end; |
|
272 |
||
273 |
TMusicUnion = record |
|
274 |
case Byte of |
|
275 |
0: ( midi : TMidiSong ); |
|
276 |
1: ( ogg : pointer); |
|
277 |
end; |
|
278 |
||
279 |
PMixMusic = ^TMixMusic; |
|
280 |
TMixMusic = record |
|
281 |
end; |
|
282 |
||
105 | 283 |
function Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 284 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
285 |
||
174 | 286 |
function Mix_Volume(channel: LongInt; volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
287 |
function Mix_SetDistance(channel: LongInt; distance: Byte): LongInt; cdecl; external SDL_MixerLibName; |
|
105 | 288 |
function Mix_VolumeMusic(volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 289 |
|
174 | 290 |
function Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 291 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
292 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
293 |
||
105 | 294 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName; |
4 | 295 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
296 |
||
105 | 297 |
function Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
298 |
function Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 299 |
|
105 | 300 |
function Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
301 |
function Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
302 |
function Mix_HaltChannel(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 303 |
|
304 |
(* SDL_image *) |
|
305 |
||
306 |
const {$IFDEF WIN32} |
|
307 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
308 |
{$ENDIF} |
|
309 |
{$IFDEF UNIX} |
|
310 |
SDL_ImageLibName = 'libSDL_image.so'; |
|
311 |
{$ENDIF} |
|
312 |
||
313 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
314 |
||
315 |
(* SDL_net *) |
|
316 |
||
317 |
const {$IFDEF WIN32} |
|
318 |
SDL_NetLibName = 'SDL_net.dll'; |
|
319 |
{$ENDIF} |
|
320 |
{$IFDEF UNIX} |
|
321 |
SDL_NetLibName = 'libSDL_net.so'; |
|
322 |
{$ENDIF} |
|
323 |
||
324 |
type TIPAddress = record |
|
325 |
host: Longword; |
|
326 |
port: Word; |
|
327 |
end; |
|
328 |
||
329 |
PTCPSocket = ^TTCPSocket; |
|
330 |
TTCPSocket = record |
|
106 | 331 |
ready: LongInt; |
105 | 332 |
channel: LongInt; |
106 | 333 |
remoteAddress: TIPaddress; |
4 | 334 |
localAddress: TIPaddress; |
105 | 335 |
sflag: LongInt; |
4 | 336 |
end; |
337 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
338 |
TSDLNet_SocketSet = record |
|
339 |
numsockets, |
|
105 | 340 |
maxsockets: LongInt; |
4 | 341 |
sockets: PTCPSocket; |
342 |
end; |
|
343 |
||
105 | 344 |
function SDLNet_Init: LongInt; cdecl; external SDL_NetLibName; |
4 | 345 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
346 |
||
105 | 347 |
function SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
348 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 349 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
350 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
105 | 351 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
352 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 353 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
354 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
105 | 355 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName; |
356 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 357 |
|
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
358 |
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
|
359 |
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
|
360 |
function SDLNet_Read16(buf: pointer): SmallInt; cdecl; external SDL_NetLibName; |
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
361 |
function SDLNet_Read32(buf: pointer): LongInt; cdecl; external SDL_NetLibName; |
4 | 362 |
|
363 |
implementation |
|
364 |
||
365 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
366 |
begin |
|
367 |
Result:= ( surface^.offset <> 0 ) |
|
368 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
|
369 |
end; |
|
370 |
||
371 |
end. |