Skip to content

Commit 19a2176

Browse files
ADD: Support for dynamic linking first version that can be compiled under Windows and Linux
1 parent 0db34c2 commit 19a2176

48 files changed

Lines changed: 25180 additions & 19517 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

units/ctypes.inc

Lines changed: 203 additions & 203 deletions
Large diffs are not rendered by default.

units/jedi.inc

Lines changed: 516 additions & 516 deletions
Large diffs are not rendered by default.

units/sdl.inc

Lines changed: 114 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,114 @@
1-
// based on "sdl.h"
2-
3-
type
4-
PPSDL_Init = ^PSDL_Init;
5-
PSDL_Init = ^TSDL_Init;
6-
TSDL_Init = type cuint32;
7-
8-
const
9-
SDL_INIT_TIMER = TSDL_Init($00000001);
10-
{$EXTERNALSYM SDL_INIT_TIMER}
11-
SDL_INIT_AUDIO = TSDL_Init($00000010);
12-
{$EXTERNALSYM SDL_INIT_AUDIO}
13-
SDL_INIT_VIDEO = TSDL_Init($00000020); // SDL_INIT_VIDEO implies SDL_INIT_EVENTS
14-
{$EXTERNALSYM SDL_INIT_VIDEO}
15-
SDL_INIT_JOYSTICK = TSDL_Init($00000200); // SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS
16-
{$EXTERNALSYM SDL_INIT_JOYSTICK}
17-
SDL_INIT_HAPTIC = TSDL_Init($00001000);
18-
{$EXTERNALSYM SDL_INIT_HAPTIC}
19-
SDL_INIT_GAMECONTROLLER = TSDL_Init($00002000); //turn on game controller also implicitly does JOYSTICK
20-
{$EXTERNALSYM SDL_INIT_GAMECONTROLLER} // SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK
21-
SDL_INIT_EVENTS = TSDL_Init($00004000);
22-
{$EXTERNALSYM SDL_INIT_EVENTS}
23-
SDL_INIT_SENSOR = TSDL_Init($00008000);
24-
{$EXTERNALSYM SDL_INIT_SENSOR}
25-
SDL_INIT_NOPARACHUTE = TSDL_Init($00100000); //Don't catch fatal signals
26-
{$EXTERNALSYM SDL_INIT_NOPARACHUTE} // compatibility; this flag is ignored.
27-
SDL_INIT_EVERYTHING = TSDL_Init(
28-
SDL_INIT_TIMER or
29-
SDL_INIT_AUDIO or
30-
SDL_INIT_VIDEO or
31-
SDL_INIT_EVENTS or
32-
SDL_INIT_JOYSTICK or
33-
SDL_INIT_HAPTIC or
34-
SDL_INIT_GAMECONTROLLER or
35-
SDL_INIT_SENSOR
36-
);
37-
{$EXTERNALSYM SDL_INIT_EVERYTHING}
38-
39-
{**
40-
* This function initializes the subsystems specified by flags
41-
* Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup
42-
* signal handlers for some commonly ignored fatal signals (like SIGSEGV).
43-
*}
44-
function SDL_Init(flags: TSDL_Init): cint; cdecl;
45-
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Init' {$ENDIF} {$ENDIF};
46-
47-
{**
48-
* This function initializes specific SDL subsystems
49-
*}
50-
function SDL_InitSubSystem(flags: TSDL_Init): cint; cdecl;
51-
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_InitSubSystem' {$ENDIF} {$ENDIF};
52-
53-
{**
54-
* This function cleans up specific SDL subsystems
55-
*}
56-
procedure SDL_QuitSubSystem(flags: TSDL_Init); cdecl;
57-
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_QuitSubSystem' {$ENDIF} {$ENDIF};
58-
59-
{**
60-
* This function returns a mask of the specified subsystems which have
61-
* previously been initialized.
62-
*
63-
* If flags is 0, it returns a mask of all initialized subsystems.
64-
*}
65-
function SDL_WasInit(flags: TSDL_Init): cuint32; cdecl;
66-
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WasInit' {$ENDIF} {$ENDIF};
67-
68-
{**
69-
* This function cleans up all initialized subsystems. You should
70-
* call it upon all exit conditions.
71-
*}
72-
procedure SDL_Quit(); cdecl;
73-
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Quit' {$ENDIF} {$ENDIF};
74-
1+
// based on "sdl.h"
2+
3+
type
4+
PPSDL_Init = ^PSDL_Init;
5+
PSDL_Init = ^TSDL_Init;
6+
TSDL_Init = type cuint32;
7+
8+
const
9+
SDL_INIT_TIMER = TSDL_Init($00000001);
10+
{$EXTERNALSYM SDL_INIT_TIMER}
11+
SDL_INIT_AUDIO = TSDL_Init($00000010);
12+
{$EXTERNALSYM SDL_INIT_AUDIO}
13+
SDL_INIT_VIDEO = TSDL_Init($00000020); // SDL_INIT_VIDEO implies SDL_INIT_EVENTS
14+
{$EXTERNALSYM SDL_INIT_VIDEO}
15+
SDL_INIT_JOYSTICK = TSDL_Init($00000200); // SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS
16+
{$EXTERNALSYM SDL_INIT_JOYSTICK}
17+
SDL_INIT_HAPTIC = TSDL_Init($00001000);
18+
{$EXTERNALSYM SDL_INIT_HAPTIC}
19+
SDL_INIT_GAMECONTROLLER = TSDL_Init($00002000); //turn on game controller also implicitly does JOYSTICK
20+
{$EXTERNALSYM SDL_INIT_GAMECONTROLLER} // SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK
21+
SDL_INIT_EVENTS = TSDL_Init($00004000);
22+
{$EXTERNALSYM SDL_INIT_EVENTS}
23+
SDL_INIT_SENSOR = TSDL_Init($00008000);
24+
{$EXTERNALSYM SDL_INIT_SENSOR}
25+
SDL_INIT_NOPARACHUTE = TSDL_Init($00100000); //Don't catch fatal signals
26+
{$EXTERNALSYM SDL_INIT_NOPARACHUTE} // compatibility; this flag is ignored.
27+
SDL_INIT_EVERYTHING = TSDL_Init(
28+
SDL_INIT_TIMER or
29+
SDL_INIT_AUDIO or
30+
SDL_INIT_VIDEO or
31+
SDL_INIT_EVENTS or
32+
SDL_INIT_JOYSTICK or
33+
SDL_INIT_HAPTIC or
34+
SDL_INIT_GAMECONTROLLER or
35+
SDL_INIT_SENSOR
36+
);
37+
{$EXTERNALSYM SDL_INIT_EVERYTHING}
38+
39+
{**
40+
* This function initializes the subsystems specified by flags
41+
* Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup
42+
* signal handlers for some commonly ignored fatal signals (like SIGSEGV).
43+
*}
44+
{$ifdef SDL_DYNAMIC_LINKING}
45+
Type
46+
TSDL_Init_fun = function(flags: TSDL_Init): cint; cdecl;
47+
Var
48+
SDL_Init : TSDL_Init_fun = Nil;
49+
{$else}
50+
51+
function SDL_Init(flags: TSDL_Init): cint; cdecl;
52+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Init' {$ENDIF} {$ENDIF};
53+
{$endif}
54+
55+
{**
56+
* This function initializes specific SDL subsystems
57+
*}
58+
{$ifdef SDL_DYNAMIC_LINKING}
59+
Type
60+
TSDL_InitSubSystem_fun = function(flags: TSDL_Init): cint; cdecl;
61+
Var
62+
SDL_InitSubSystem : TSDL_InitSubSystem_fun = Nil;
63+
{$else}
64+
65+
function SDL_InitSubSystem(flags: TSDL_Init): cint; cdecl;
66+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_InitSubSystem' {$ENDIF} {$ENDIF};
67+
{$endif}
68+
69+
{**
70+
* This function cleans up specific SDL subsystems
71+
*}
72+
{$ifdef SDL_DYNAMIC_LINKING}
73+
Type
74+
TSDL_QuitSubSystem_proc = procedure(flags: TSDL_Init); cdecl;
75+
Var
76+
SDL_QuitSubSystem : TSDL_QuitSubSystem_proc = Nil;
77+
{$else}
78+
79+
procedure SDL_QuitSubSystem(flags: TSDL_Init); cdecl;
80+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_QuitSubSystem' {$ENDIF} {$ENDIF};
81+
{$endif}
82+
83+
{**
84+
* This function returns a mask of the specified subsystems which have
85+
* previously been initialized.
86+
*
87+
* If flags is 0, it returns a mask of all initialized subsystems.
88+
*}
89+
{$ifdef SDL_DYNAMIC_LINKING}
90+
Type
91+
TSDL_WasInit_fun = function(flags: TSDL_Init): cuint32; cdecl;
92+
Var
93+
SDL_WasInit : TSDL_WasInit_fun = Nil;
94+
{$else}
95+
96+
function SDL_WasInit(flags: TSDL_Init): cuint32; cdecl;
97+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WasInit' {$ENDIF} {$ENDIF};
98+
{$endif}
99+
100+
{**
101+
* This function cleans up all initialized subsystems. You should
102+
* call it upon all exit conditions.
103+
*}
104+
{$ifdef SDL_DYNAMIC_LINKING}
105+
Type
106+
TSDL_Quit_proc = procedure(); cdecl;
107+
Var
108+
SDL_Quit : TSDL_Quit_proc = Nil;
109+
{$else}
110+
111+
procedure SDL_Quit(); cdecl;
112+
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Quit' {$ENDIF} {$ENDIF};
113+
{$endif}
114+

units/sdl2.pas

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@
6161

6262
{$I jedi.inc}
6363

64+
(*
65+
* If you get a compiler error with missing file
66+
* just create a file namend "sdl2_cfg.inc" in your project folder and
67+
* insert the following content:
68+
*
69+
* ---------- Content of file ----------
70+
71+
{*
72+
* set this define if you want to use dynamic linking instead of static linking
73+
* ! Attention !
74+
* Not all functions are "ported" yet, so use is on own risk
75+
* port missing functions.
76+
*}
77+
{.$DEFINE SDL_DYNAMIC_LINKING}
78+
79+
* ---------- End content of file ----------
80+
*
81+
* ! Attention !
82+
* If you use the dynamic link feature, don't forget to call the SDL_LoadLib
83+
* function.
84+
*)
85+
86+
{$I sdl2_cfg.inc}
87+
6488
interface
6589

6690
{$IFDEF WINDOWS}
@@ -169,6 +193,11 @@ interface
169193
{$I sdlsystem.inc} // 2.24.0
170194
{$I sdl.inc} // 2.0.14
171195

196+
{$ifdef SDL_DYNAMIC_LINKING}
197+
Function SDL_LoadLib(LibFilename: String): Boolean;
198+
Procedure SDL_UnLoadLib();
199+
{$endif}
200+
172201
implementation
173202

174203
(*
@@ -183,7 +212,12 @@ implementation
183212
{$ELSE}
184213
AnsiStrings
185214
{$ENDIF}
186-
;
215+
{$ifdef SDL_DYNAMIC_LINKING}
216+
, dynlibs
217+
{$endif}
218+
;
219+
220+
{$I sdl_dnymic_linking.inc}
187221

188222
// Macros from "sdl_version.h"
189223
procedure SDL_VERSION(out x: TSDL_Version);
@@ -219,13 +253,13 @@ function SDL_Button(X: cint): cint;
219253
{$IFDEF WINDOWS}
220254
//from "sdl_thread.h"
221255

222-
function SDL_CreateThread(fn: TSDL_ThreadFunction; name: PAnsiChar;
256+
function SDL_CreateThread2(fn: TSDL_ThreadFunction; name: PAnsiChar;
223257
data: Pointer): PSDL_Thread; overload;
224258
begin
225259
Result := SDL_CreateThread(fn,name,data,nil,nil);
226260
end;
227261

228-
function SDL_CreateThreadWithStackSize(fn: TSDL_ThreadFunction;
262+
function SDL_CreateThreadWithStackSize2(fn: TSDL_ThreadFunction;
229263
name: PAnsiChar; const stacksize: csize_t; data: Pointer
230264
): PSDL_Thread; overload;
231265
begin
@@ -480,4 +514,11 @@ function SDL_GameControllerAddMappingsFromFile(const FilePath: PAnsiChar
480514
Result := SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(FilePath, 'rb'), 1)
481515
end;
482516

517+
518+
{$IFDEF SDL_DYNAMIC_LINKING}
519+
520+
Finalization
521+
SDL_UnLoadLib();
522+
{$ENDIF}
523+
483524
end.

0 commit comments

Comments
 (0)