author | Periklis Ntanasis <pntanasis@gmail.com> |
Sat, 14 Sep 2013 00:39:59 +0300 | |
branch | spacecampaign |
changeset 9622 | db9f6b7955ba |
parent 9378 | 2be457289e60 |
child 9407 | 860f959f92c9 |
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 |
|
7959 | 36 |
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
|
37 |
uses uUtils, uVariables, sysutils; |
7959 | 38 |
|
8073 | 39 |
function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName; |
40 |
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
|
41 |
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
|
42 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName; |
7959 | 43 |
|
8073 | 44 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName; |
45 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
46 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
47 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
48 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
49 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
|
7959 | 50 |
|
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
|
51 |
procedure hedgewarsMountPackages(); cdecl; external PhyslayerLibName; |
8052 | 52 |
|
8025 | 53 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
54 |
begin |
|
55 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname))); |
|
56 |
end; |
|
57 |
||
58 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
7959 | 59 |
begin |
8025 | 60 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname))); |
61 |
end; |
|
8022 | 62 |
|
8028 | 63 |
function pfsOpenRead(fname: shortstring): PFSFile; |
64 |
begin |
|
65 |
exit(PHYSFS_openRead(Str2PChar(fname))); |
|
66 |
end; |
|
67 |
||
68 |
function pfsEOF(f: PFSFile): boolean; |
|
69 |
begin |
|
70 |
exit(PHYSFS_eof(f)) |
|
71 |
end; |
|
72 |
||
73 |
function pfsClose(f: PFSFile): boolean; |
|
74 |
begin |
|
75 |
exit(PHYSFS_close(f)) |
|
76 |
end; |
|
77 |
||
8031 | 78 |
function pfsExists(fname: shortstring): boolean; |
79 |
begin |
|
80 |
exit(PHYSFS_exists(Str2PChar(fname))) |
|
81 |
end; |
|
82 |
||
8028 | 83 |
|
84 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
85 |
var c: char; |
|
86 |
begin |
|
87 |
s[0]:= #0; |
|
88 |
||
8034 | 89 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
8028 | 90 |
if (c <> #13) and (s[0] < #255) then |
91 |
begin |
|
92 |
inc(s[0]); |
|
93 |
s[byte(s[0])]:= c |
|
94 |
end |
|
95 |
end; |
|
96 |
||
8107 | 97 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
98 |
var c: char; |
|
99 |
b: shortstring; |
|
100 |
begin |
|
101 |
s:= ''; |
|
102 |
b[0]:= #0; |
|
103 |
||
104 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
|
105 |
if (c <> #13) then |
|
106 |
begin |
|
107 |
inc(b[0]); |
|
108 |
b[byte(b[0])]:= c; |
|
109 |
if b[0] = #255 then |
|
110 |
begin |
|
111 |
s:= s + b; |
|
112 |
b[0]:= #0 |
|
113 |
end |
|
114 |
end; |
|
115 |
||
116 |
s:= s + b |
|
117 |
end; |
|
118 |
||
8031 | 119 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
120 |
var r: Int64; |
|
121 |
begin |
|
8034 | 122 |
r:= PHYSFS_readBytes(f, buf, size); |
8031 | 123 |
|
124 |
if r <= 0 then |
|
125 |
pfsBlockRead:= 0 |
|
126 |
else |
|
127 |
pfsBlockRead:= r |
|
128 |
end; |
|
129 |
||
8025 | 130 |
procedure initModule; |
131 |
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
|
132 |
cPhysfsId: shortstring; |
8025 | 133 |
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
|
134 |
{$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
|
135 |
//TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html |
9378
2be457289e60
update physlayer and sdl bindings to the new rwops interface
koda
parents:
9224
diff
changeset
|
136 |
cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}{$IFNDEF IPHONEOS}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF}{$ENDIF} ' hedgewars'; |
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
|
137 |
{$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
|
138 |
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
|
139 |
{$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
|
140 |
|
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
|
141 |
i:= PHYSFS_init(Str2PChar(cPhysfsId)); |
8025 | 142 |
AddFileLog('[PhysFS] init: ' + inttostr(i)); |
143 |
||
8714 | 144 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, false); |
8025 | 145 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
8714 | 146 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, false); |
8046 | 147 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i)); |
8052 | 148 |
|
149 |
hedgewarsMountPackages; |
|
7959 | 150 |
end; |
151 |
||
152 |
procedure freeModule; |
|
153 |
begin |
|
154 |
PHYSFS_deinit; |
|
155 |
end; |
|
156 |
||
157 |
end. |