author | unC0Rr |
Mon, 17 Jun 2013 23:21:53 +0200 | |
branch | webgl |
changeset 9240 | 3a6608ae0a5e |
parent 9236 | ddd675825672 |
child 9260 | 64718974158f |
permissions | -rw-r--r-- |
7959 | 1 |
unit uPhysFSLayer; |
8063 | 2 |
|
7959 | 3 |
interface |
8077 | 4 |
uses SDLh, LuaPas; |
7959 | 5 |
|
9204 | 6 |
const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhwphysfs'{$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} |
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
|
12 |
{$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
|
13 |
|
7959 | 14 |
procedure initModule; |
15 |
procedure freeModule; |
|
16 |
||
8028 | 17 |
type PFSFile = pointer; |
18 |
||
8025 | 19 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
20 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
8022 | 21 |
|
8028 | 22 |
function pfsOpenRead(fname: shortstring): PFSFile; |
23 |
function pfsClose(f: PFSFile): boolean; |
|
24 |
||
25 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
8107 | 26 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
8031 | 27 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
28 |
function pfsEOF(f: PFSFile): boolean; |
|
29 |
||
30 |
function pfsExists(fname: shortstring): boolean; |
|
8028 | 31 |
|
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
|
32 |
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
|
33 |
procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName; |
8978
e6ef8fe314bd
suggestion of unc0rr's to fix issue w/ random maps in campaign. load sidecar packages in physfs for lua. should be useful also for lua that does custom layouts
nemo
parents:
8927
diff
changeset
|
34 |
procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName; |
8077 | 35 |
|
8105 | 36 |
{$IFNDEF PAS2C} |
37 |
//apparently pas2c doesn't render the functions below if it finds 'implementation' first |
|
7959 | 38 |
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
|
39 |
uses uUtils, uVariables, sysutils; |
8105 | 40 |
{$ENDIF} |
7959 | 41 |
|
8073 | 42 |
function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName; |
43 |
function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName; |
|
8839 | 44 |
function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName; |
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
|
45 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName; |
7959 | 46 |
|
8073 | 47 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName; |
48 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
49 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
50 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
51 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
52 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
|
7959 | 53 |
|
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
|
54 |
procedure hedgewarsMountPackages(); cdecl; external PhyslayerLibName; |
8052 | 55 |
|
8105 | 56 |
{$IFDEF PAS2C} |
57 |
implementation |
|
58 |
uses uUtils, uVariables; |
|
59 |
{$ENDIF} |
|
60 |
||
8099
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
61 |
(*****************************************************************) |
8052 | 62 |
|
8025 | 63 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
64 |
begin |
|
65 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname))); |
|
66 |
end; |
|
67 |
||
68 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
7959 | 69 |
begin |
8025 | 70 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname))); |
71 |
end; |
|
8022 | 72 |
|
8028 | 73 |
function pfsOpenRead(fname: shortstring): PFSFile; |
74 |
begin |
|
75 |
exit(PHYSFS_openRead(Str2PChar(fname))); |
|
76 |
end; |
|
77 |
||
78 |
function pfsEOF(f: PFSFile): boolean; |
|
79 |
begin |
|
80 |
exit(PHYSFS_eof(f)) |
|
81 |
end; |
|
82 |
||
83 |
function pfsClose(f: PFSFile): boolean; |
|
84 |
begin |
|
85 |
exit(PHYSFS_close(f)) |
|
86 |
end; |
|
87 |
||
8031 | 88 |
function pfsExists(fname: shortstring): boolean; |
89 |
begin |
|
90 |
exit(PHYSFS_exists(Str2PChar(fname))) |
|
91 |
end; |
|
92 |
||
8028 | 93 |
|
94 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
95 |
var c: char; |
|
96 |
begin |
|
97 |
s[0]:= #0; |
|
98 |
||
8034 | 99 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
8028 | 100 |
if (c <> #13) and (s[0] < #255) then |
101 |
begin |
|
102 |
inc(s[0]); |
|
103 |
s[byte(s[0])]:= c |
|
104 |
end |
|
105 |
end; |
|
106 |
||
8107 | 107 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
108 |
var c: char; |
|
109 |
b: shortstring; |
|
110 |
begin |
|
111 |
s:= ''; |
|
112 |
b[0]:= #0; |
|
113 |
||
114 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
|
115 |
if (c <> #13) then |
|
116 |
begin |
|
117 |
inc(b[0]); |
|
118 |
b[byte(b[0])]:= c; |
|
119 |
if b[0] = #255 then |
|
120 |
begin |
|
121 |
s:= s + b; |
|
122 |
b[0]:= #0 |
|
123 |
end |
|
124 |
end; |
|
8330 | 125 |
|
8107 | 126 |
s:= s + b |
127 |
end; |
|
128 |
||
8031 | 129 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
130 |
var r: Int64; |
|
131 |
begin |
|
8034 | 132 |
r:= PHYSFS_readBytes(f, buf, size); |
8031 | 133 |
|
134 |
if r <= 0 then |
|
135 |
pfsBlockRead:= 0 |
|
136 |
else |
|
137 |
pfsBlockRead:= r |
|
138 |
end; |
|
139 |
||
8025 | 140 |
procedure initModule; |
141 |
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
|
142 |
cPhysfsId: shortstring; |
8025 | 143 |
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
|
144 |
{$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
|
145 |
//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
|
146 |
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
|
147 |
{$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
|
148 |
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
|
149 |
{$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
|
150 |
|
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 |
i:= PHYSFS_init(Str2PChar(cPhysfsId)); |
8025 | 152 |
AddFileLog('[PhysFS] init: ' + inttostr(i)); |
153 |
||
8714 | 154 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, false); |
8025 | 155 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
8714 | 156 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, false); |
8046 | 157 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i)); |
8052 | 158 |
|
159 |
hedgewarsMountPackages; |
|
7959 | 160 |
end; |
161 |
||
162 |
procedure freeModule; |
|
163 |
begin |
|
164 |
PHYSFS_deinit; |
|
165 |
end; |
|
166 |
||
167 |
end. |