author | koda |
Tue, 26 Mar 2013 01:18:04 +0100 | |
branch | 0.9.19 |
changeset 8926 | 8fde68cfeb71 |
parent 8714 | ab201a62d115 |
child 8927 | 3da5182d8682 |
permissions | -rw-r--r-- |
7959 | 1 |
unit uPhysFSLayer; |
8063 | 2 |
|
7959 | 3 |
interface |
8077 | 4 |
uses SDLh, LuaPas; |
7959 | 5 |
|
8558 | 6 |
const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhw_physfs'{$ELSE}'libphysfs'{$ENDIF}; |
8540
cf808329bb6f
this should hijack the linker name and always pick the bundled physfs when another version is already prsent
koda
parents:
8533
diff
changeset
|
7 |
const PhyslayerLibName = 'libphyslayer'; |
8073 | 8 |
|
8540
cf808329bb6f
this should hijack the linker name and always pick the bundled physfs when another version is already prsent
koda
parents:
8533
diff
changeset
|
9 |
{$IFNDEF WIN32} |
cf808329bb6f
this should hijack the linker name and always pick the bundled physfs when another version is already prsent
koda
parents:
8533
diff
changeset
|
10 |
{$linklib physfs} |
cf808329bb6f
this should hijack the linker name and always pick the bundled physfs when another version is already prsent
koda
parents:
8533
diff
changeset
|
11 |
{$linklib physlayer} |
8926
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
12 |
|
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
13 |
{statically linking physfs brings IOKit dependency on OSX and |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
14 |
stdc++ under linux 32 bit because divdi3 is not defined} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
15 |
{$IFDEF PHYSFS_INTERNAL} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
16 |
{$IFDEF DARWIN} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
17 |
{$linkframework IOKit} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
18 |
{$ELSE} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
19 |
{$IFDEF CPU32} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
20 |
{$linklib stdc++} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
21 |
{$ENDIF} |
8fde68cfeb71
link stdc++ (for physfs on linux) only when targetting 32bit
koda
parents:
8714
diff
changeset
|
22 |
{$ENDIF} |
8540
cf808329bb6f
this should hijack the linker name and always pick the bundled physfs when another version is already prsent
koda
parents:
8533
diff
changeset
|
23 |
{$ENDIF} |
8533
2d7703d6bc22
this should make physfs happy to link on windows too, forcing every function in its proper dll and skipping linklib
koda
parents:
8528
diff
changeset
|
24 |
{$ENDIF} |
2d7703d6bc22
this should make physfs happy to link on windows too, forcing every function in its proper dll and skipping linklib
koda
parents:
8528
diff
changeset
|
25 |
|
7959 | 26 |
procedure initModule; |
27 |
procedure freeModule; |
|
28 |
||
8028 | 29 |
type PFSFile = pointer; |
30 |
||
8025 | 31 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
32 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
8022 | 33 |
|
8028 | 34 |
function pfsOpenRead(fname: shortstring): PFSFile; |
35 |
function pfsClose(f: PFSFile): boolean; |
|
36 |
||
37 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
8107 | 38 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
8031 | 39 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
40 |
function pfsEOF(f: PFSFile): boolean; |
|
41 |
||
42 |
function pfsExists(fname: shortstring): boolean; |
|
8028 | 43 |
|
8533
2d7703d6bc22
this should make physfs happy to link on windows too, forcing every function in its proper dll and skipping linklib
koda
parents:
8528
diff
changeset
|
44 |
function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName; |
2d7703d6bc22
this should make physfs happy to link on windows too, forcing every function in its proper dll and skipping linklib
koda
parents:
8528
diff
changeset
|
45 |
procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName; |
8077 | 46 |
|
7959 | 47 |
implementation |
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
48 |
uses uUtils, uVariables, sysutils; |
7959 | 49 |
|
8073 | 50 |
function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName; |
51 |
function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName; |
|
8533
2d7703d6bc22
this should make physfs happy to link on windows too, forcing every function in its proper dll and skipping linklib
koda
parents:
8528
diff
changeset
|
52 |
function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhyslayerLibName; |
2d7703d6bc22
this should make physfs happy to link on windows too, forcing every function in its proper dll and skipping linklib
koda
parents:
8528
diff
changeset
|
53 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName; |
7959 | 54 |
|
8073 | 55 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName; |
56 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
57 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
58 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
59 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
60 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
|
7959 | 61 |
|
8533
2d7703d6bc22
this should make physfs happy to link on windows too, forcing every function in its proper dll and skipping linklib
koda
parents:
8528
diff
changeset
|
62 |
procedure hedgewarsMountPackages(); cdecl; external PhyslayerLibName; |
8052 | 63 |
|
8025 | 64 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
65 |
begin |
|
66 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname))); |
|
67 |
end; |
|
68 |
||
69 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
7959 | 70 |
begin |
8025 | 71 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname))); |
72 |
end; |
|
8022 | 73 |
|
8028 | 74 |
function pfsOpenRead(fname: shortstring): PFSFile; |
75 |
begin |
|
76 |
exit(PHYSFS_openRead(Str2PChar(fname))); |
|
77 |
end; |
|
78 |
||
79 |
function pfsEOF(f: PFSFile): boolean; |
|
80 |
begin |
|
81 |
exit(PHYSFS_eof(f)) |
|
82 |
end; |
|
83 |
||
84 |
function pfsClose(f: PFSFile): boolean; |
|
85 |
begin |
|
86 |
exit(PHYSFS_close(f)) |
|
87 |
end; |
|
88 |
||
8031 | 89 |
function pfsExists(fname: shortstring): boolean; |
90 |
begin |
|
91 |
exit(PHYSFS_exists(Str2PChar(fname))) |
|
92 |
end; |
|
93 |
||
8028 | 94 |
|
95 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
96 |
var c: char; |
|
97 |
begin |
|
98 |
s[0]:= #0; |
|
99 |
||
8034 | 100 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
8028 | 101 |
if (c <> #13) and (s[0] < #255) then |
102 |
begin |
|
103 |
inc(s[0]); |
|
104 |
s[byte(s[0])]:= c |
|
105 |
end |
|
106 |
end; |
|
107 |
||
8107 | 108 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
109 |
var c: char; |
|
110 |
b: shortstring; |
|
111 |
begin |
|
112 |
s:= ''; |
|
113 |
b[0]:= #0; |
|
114 |
||
115 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
|
116 |
if (c <> #13) then |
|
117 |
begin |
|
118 |
inc(b[0]); |
|
119 |
b[byte(b[0])]:= c; |
|
120 |
if b[0] = #255 then |
|
121 |
begin |
|
122 |
s:= s + b; |
|
123 |
b[0]:= #0 |
|
124 |
end |
|
125 |
end; |
|
126 |
||
127 |
s:= s + b |
|
128 |
end; |
|
129 |
||
8031 | 130 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
131 |
var r: Int64; |
|
132 |
begin |
|
8034 | 133 |
r:= PHYSFS_readBytes(f, buf, size); |
8031 | 134 |
|
135 |
if r <= 0 then |
|
136 |
pfsBlockRead:= 0 |
|
137 |
else |
|
138 |
pfsBlockRead:= r |
|
139 |
end; |
|
140 |
||
8025 | 141 |
procedure initModule; |
142 |
var i: LongInt; |
|
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
143 |
cPhysfsId: shortstring; |
8025 | 144 |
begin |
8310
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
145 |
{$IFDEF HWLIBRARY} |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
146 |
//TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
147 |
cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF} ' hedgewars'; |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
148 |
{$ELSE} |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
149 |
cPhysfsId:= ParamStr(0); |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
150 |
{$ENDIF} |
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
151 |
|
a98c349bc06b
minor adjustments to libengine, moc is correctly created as definitions are set before calling it, params are better numbered and we don't subclass qthread but rather use moveToThread()
koda
parents:
8283
diff
changeset
|
152 |
i:= PHYSFS_init(Str2PChar(cPhysfsId)); |
8025 | 153 |
AddFileLog('[PhysFS] init: ' + inttostr(i)); |
154 |
||
8714 | 155 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, false); |
8025 | 156 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
8714 | 157 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, false); |
8046 | 158 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i)); |
8052 | 159 |
|
160 |
hedgewarsMountPackages; |
|
7959 | 161 |
end; |
162 |
||
163 |
procedure freeModule; |
|
164 |
begin |
|
165 |
PHYSFS_deinit; |
|
166 |
end; |
|
167 |
||
168 |
end. |