author | unc0rr |
Thu, 12 Oct 2006 18:52:00 +0000 | |
changeset 196 | 993cf173218b |
parent 192 | b644f61e803f |
child 198 | 6f00e0f4cb88 |
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; |
|
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
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} |
|
229 |
||
230 |
||
231 |
type PTTF_Font = ^TTTF_font; |
|
232 |
TTTF_Font = record |
|
233 |
end; |
|
234 |
||
105 | 235 |
function TTF_Init: LongInt; cdecl; external SDL_TTFLibName; |
4 | 236 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
237 |
||
238 |
||
107 | 239 |
function TTF_SizeUTF8(font : PTTF_Font; const text: PChar; var w, h: integer): LongInt; cdecl; external SDL_TTFLibName; |
74 | 240 |
function TTF_RenderUTF8_Solid(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
241 |
function TTF_RenderUTF8_Blended(font : PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName; |
|
107 | 242 |
function TTF_OpenFont(const filename: Pchar; size: integer): PTTF_Font; cdecl; external SDL_TTFLibName; |
4 | 243 |
|
244 |
(* SDL_mixer *) |
|
245 |
||
246 |
const {$IFDEF WIN32} |
|
247 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
248 |
{$ENDIF} |
|
249 |
{$IFDEF UNIX} |
|
250 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
|
251 |
{$ENDIF} |
|
252 |
||
174 | 253 |
const MIX_MAX_VOLUME = 128; |
254 |
||
4 | 255 |
type PMixChunk = ^TMixChunk; |
256 |
TMixChunk = record |
|
257 |
allocated: Longword; |
|
258 |
abuf : PByte; |
|
259 |
alen : Longword; |
|
260 |
volume : PByte; |
|
106 | 261 |
end; |
4 | 262 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
263 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
264 |
||
265 |
TMidiSong = record |
|
105 | 266 |
samples : LongInt; |
4 | 267 |
events : pointer; |
268 |
end; |
|
269 |
||
270 |
TMusicUnion = record |
|
271 |
case Byte of |
|
272 |
0: ( midi : TMidiSong ); |
|
273 |
1: ( ogg : pointer); |
|
274 |
end; |
|
275 |
||
276 |
PMixMusic = ^TMixMusic; |
|
277 |
TMixMusic = record |
|
278 |
end; |
|
279 |
||
105 | 280 |
function Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 281 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
282 |
||
174 | 283 |
function Mix_Volume(channel: LongInt; volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
284 |
function Mix_SetDistance(channel: LongInt; distance: Byte): LongInt; cdecl; external SDL_MixerLibName; |
|
105 | 285 |
function Mix_VolumeMusic(volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 286 |
|
174 | 287 |
function Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 288 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
289 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
290 |
||
105 | 291 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName; |
4 | 292 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
293 |
||
105 | 294 |
function Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
295 |
function Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 296 |
|
105 | 297 |
function Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
298 |
function Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
299 |
function Mix_HaltChannel(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 300 |
|
301 |
(* SDL_image *) |
|
302 |
||
303 |
const {$IFDEF WIN32} |
|
304 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
305 |
{$ENDIF} |
|
306 |
{$IFDEF UNIX} |
|
307 |
SDL_ImageLibName = 'libSDL_image.so'; |
|
308 |
{$ENDIF} |
|
309 |
||
310 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
311 |
||
312 |
(* SDL_net *) |
|
313 |
||
314 |
const {$IFDEF WIN32} |
|
315 |
SDL_NetLibName = 'SDL_net.dll'; |
|
316 |
{$ENDIF} |
|
317 |
{$IFDEF UNIX} |
|
318 |
SDL_NetLibName = 'libSDL_net.so'; |
|
319 |
{$ENDIF} |
|
320 |
||
321 |
type TIPAddress = record |
|
322 |
host: Longword; |
|
323 |
port: Word; |
|
324 |
end; |
|
325 |
||
326 |
PTCPSocket = ^TTCPSocket; |
|
327 |
TTCPSocket = record |
|
106 | 328 |
ready: LongInt; |
105 | 329 |
channel: LongInt; |
106 | 330 |
remoteAddress: TIPaddress; |
4 | 331 |
localAddress: TIPaddress; |
105 | 332 |
sflag: LongInt; |
4 | 333 |
end; |
334 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
335 |
TSDLNet_SocketSet = record |
|
336 |
numsockets, |
|
105 | 337 |
maxsockets: LongInt; |
4 | 338 |
sockets: PTCPSocket; |
339 |
end; |
|
340 |
||
105 | 341 |
function SDLNet_Init: LongInt; cdecl; external SDL_NetLibName; |
4 | 342 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
343 |
||
105 | 344 |
function SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
345 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 346 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
347 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
105 | 348 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
349 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 350 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
351 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
105 | 352 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName; |
353 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 354 |
|
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
function SDLNet_Read16(buf: pointer): SmallInt; cdecl; external SDL_NetLibName; |
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
109
diff
changeset
|
358 |
function SDLNet_Read32(buf: pointer): LongInt; cdecl; external SDL_NetLibName; |
4 | 359 |
|
360 |
implementation |
|
361 |
||
362 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
363 |
begin |
|
364 |
Result:= ( surface^.offset <> 0 ) |
|
365 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
|
366 |
end; |
|
367 |
||
368 |
end. |