author | koda |
Tue, 25 Dec 2012 04:45:22 +0100 | |
branch | webgl |
changeset 8330 | aaefa587e277 |
parent 8105 | d088be5ecdcb |
parent 8310 | a98c349bc06b |
child 8833 | c13ebed437cb |
permissions | -rw-r--r-- |
7959 | 1 |
unit uPhysFSLayer; |
8063 | 2 |
|
7959 | 3 |
interface |
8077 | 4 |
uses SDLh, LuaPas; |
7959 | 5 |
|
8073 | 6 |
{$IFDEF ANDROID} |
7 |
{$linklib physfs} |
|
8 |
{$ELSE} |
|
9 |
{$IFDEF DARWIN} |
|
10 |
{$LINKFRAMEWORK IOKit} |
|
11 |
{$ENDIF} |
|
12 |
{$ENDIF} |
|
13 |
||
14 |
const |
|
15 |
{$IFDEF WIN32} |
|
16 |
PhysfsLibName = 'libphysfs'; |
|
17 |
{$ELSE} |
|
18 |
PhysfsLibName = 'physfs'; |
|
19 |
{$ENDIF} |
|
20 |
||
7959 | 21 |
procedure initModule; |
22 |
procedure freeModule; |
|
23 |
||
8028 | 24 |
type PFSFile = pointer; |
25 |
||
8025 | 26 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
27 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
8022 | 28 |
|
8028 | 29 |
function pfsOpenRead(fname: shortstring): PFSFile; |
30 |
function pfsClose(f: PFSFile): boolean; |
|
31 |
||
32 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
8107 | 33 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
8031 | 34 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
35 |
function pfsEOF(f: PFSFile): boolean; |
|
36 |
||
37 |
function pfsExists(fname: shortstring): boolean; |
|
8028 | 38 |
|
8077 | 39 |
function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhysfsLibName; |
40 |
procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName; |
|
41 |
||
8105 | 42 |
{$IFNDEF PAS2C} |
43 |
//apparently pas2c doesn't render the functions below if it finds 'implementation' first |
|
7959 | 44 |
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
|
45 |
uses uUtils, uVariables, sysutils; |
8105 | 46 |
{$ENDIF} |
7959 | 47 |
|
8105 | 48 |
function PHYSFS_init(argv: PChar): LongInt; cdecl; external PhysfsLibName; |
8099
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
49 |
function PHYSFS_deinit: LongInt; cdecl; external PhysfsLibName; |
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
50 |
function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName; |
8073 | 51 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName; |
7959 | 52 |
|
8073 | 53 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName; |
54 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
55 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
56 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
57 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
58 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
|
7959 | 59 |
|
8099
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
60 |
procedure hedgewarsMountPackages; cdecl; external PhysfsLibName; |
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
61 |
|
8105 | 62 |
{$IFDEF PAS2C} |
63 |
implementation |
|
64 |
uses uUtils, uVariables; |
|
65 |
{$ENDIF} |
|
66 |
||
8099
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
67 |
(*****************************************************************) |
8052 | 68 |
|
8025 | 69 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
70 |
begin |
|
71 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname))); |
|
72 |
end; |
|
73 |
||
74 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
7959 | 75 |
begin |
8025 | 76 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname))); |
77 |
end; |
|
8022 | 78 |
|
8028 | 79 |
function pfsOpenRead(fname: shortstring): PFSFile; |
80 |
begin |
|
81 |
exit(PHYSFS_openRead(Str2PChar(fname))); |
|
82 |
end; |
|
83 |
||
84 |
function pfsEOF(f: PFSFile): boolean; |
|
85 |
begin |
|
86 |
exit(PHYSFS_eof(f)) |
|
87 |
end; |
|
88 |
||
89 |
function pfsClose(f: PFSFile): boolean; |
|
90 |
begin |
|
91 |
exit(PHYSFS_close(f)) |
|
92 |
end; |
|
93 |
||
8031 | 94 |
function pfsExists(fname: shortstring): boolean; |
95 |
begin |
|
96 |
exit(PHYSFS_exists(Str2PChar(fname))) |
|
97 |
end; |
|
98 |
||
8028 | 99 |
|
100 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
101 |
var c: char; |
|
102 |
begin |
|
103 |
s[0]:= #0; |
|
104 |
||
8034 | 105 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
8028 | 106 |
if (c <> #13) and (s[0] < #255) then |
107 |
begin |
|
108 |
inc(s[0]); |
|
109 |
s[byte(s[0])]:= c |
|
110 |
end |
|
111 |
end; |
|
112 |
||
8107 | 113 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
114 |
var c: char; |
|
115 |
b: shortstring; |
|
116 |
begin |
|
117 |
s:= ''; |
|
118 |
b[0]:= #0; |
|
119 |
||
120 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
|
121 |
if (c <> #13) then |
|
122 |
begin |
|
123 |
inc(b[0]); |
|
124 |
b[byte(b[0])]:= c; |
|
125 |
if b[0] = #255 then |
|
126 |
begin |
|
127 |
s:= s + b; |
|
128 |
b[0]:= #0 |
|
129 |
end |
|
130 |
end; |
|
8330 | 131 |
|
8107 | 132 |
s:= s + b |
133 |
end; |
|
134 |
||
8031 | 135 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
136 |
var r: Int64; |
|
137 |
begin |
|
8034 | 138 |
r:= PHYSFS_readBytes(f, buf, size); |
8031 | 139 |
|
140 |
if r <= 0 then |
|
141 |
pfsBlockRead:= 0 |
|
142 |
else |
|
143 |
pfsBlockRead:= r |
|
144 |
end; |
|
145 |
||
8025 | 146 |
procedure initModule; |
147 |
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
|
148 |
cPhysfsId: shortstring; |
8025 | 149 |
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
|
150 |
{$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
|
151 |
//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
|
152 |
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
|
153 |
{$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
|
154 |
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
|
155 |
{$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
|
156 |
|
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
|
157 |
i:= PHYSFS_init(Str2PChar(cPhysfsId)); |
8025 | 158 |
AddFileLog('[PhysFS] init: ' + inttostr(i)); |
159 |
||
160 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true); |
|
161 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
|
8031 | 162 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true); |
8046 | 163 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i)); |
8052 | 164 |
|
165 |
hedgewarsMountPackages; |
|
7959 | 166 |
end; |
167 |
||
168 |
procedure freeModule; |
|
169 |
begin |
|
170 |
PHYSFS_deinit; |
|
171 |
end; |
|
172 |
||
173 |
end. |