-
Notifications
You must be signed in to change notification settings - Fork 5
/
ter_defs.pas
326 lines (298 loc) · 7.76 KB
/
ter_defs.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//------------------------------------------------------------------------------
//
// DD_TERRAIN: Terrain Generator
// Copyright (C) 2020-2021 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// DESCRIPTION:
// Settings(ini file)
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/DD-TERRAIN/
//------------------------------------------------------------------------------
unit ter_defs;
interface
function ter_LoadSettingFromFile(const fn: string): boolean;
procedure ter_SaveSettingsToFile(const fn: string);
const
MAXHISTORYPATH = 2048;
type
bigstring_t = array[0..MAXHISTORYPATH - 1] of char;
bigstring_p = ^bigstring_t;
var
opt_renderevniroment: Boolean = True;
opt_renderwireframe: Boolean = False;
opt_filemenuhistory0: bigstring_t;
opt_filemenuhistory1: bigstring_t;
opt_filemenuhistory2: bigstring_t;
opt_filemenuhistory3: bigstring_t;
opt_filemenuhistory4: bigstring_t;
opt_filemenuhistory5: bigstring_t;
opt_filemenuhistory6: bigstring_t;
opt_filemenuhistory7: bigstring_t;
opt_filemenuhistory8: bigstring_t;
opt_filemenuhistory9: bigstring_t;
opt_lastwadfile: bigstring_t;
opt_defaultpalette: bigstring_t;
opt_lastpk3file: bigstring_t;
opt_lastdirectory: bigstring_t;
function bigstringtostring(const bs: bigstring_p): string;
procedure stringtobigstring(const src: string; const bs: bigstring_p);
implementation
uses
SysUtils, Classes;
type
TSettingsType = (tstDevider, tstInteger, tstBoolean, tstString, tstBigString);
TSettingItem = record
desc: string;
typeof: TSettingsType;
location: pointer;
end;
const
NUMSETTINGS = 19;
var
Settings: array[0..NUMSETTINGS - 1] of TSettingItem = (
(
desc: '[OpenGL]';
typeof: tstDevider;
location: nil;
),
(
desc: 'GL_RENDERENVIROMENT';
typeof: tstBoolean;
location: @opt_renderevniroment;
),
(
desc: 'GL_RENDERWIREFRAME';
typeof: tstBoolean;
location: @opt_renderwireframe;
),
(
desc: '[File Menu History]';
typeof: tstDevider;
location: nil;
),
(
desc: 'FILEMENUHISTORY0';
typeof: tstBigString;
location: @opt_filemenuhistory0;
),
(
desc: 'FILEMENUHISTORY1';
typeof: tstBigString;
location: @opt_filemenuhistory1;
),
(
desc: 'FILEMENUHISTORY2';
typeof: tstBigString;
location: @opt_filemenuhistory2;
),
(
desc: 'FILEMENUHISTORY3';
typeof: tstBigString;
location: @opt_filemenuhistory3;
),
(
desc: 'FILEMENUHISTORY4';
typeof: tstBigString;
location: @opt_filemenuhistory4;
),
(
desc: 'FILEMENUHISTORY5';
typeof: tstBigString;
location: @opt_filemenuhistory5;
),
(
desc: 'FILEMENUHISTORY6';
typeof: tstBigString;
location: @opt_filemenuhistory6;
),
(
desc: 'FILEMENUHISTORY7';
typeof: tstBigString;
location: @opt_filemenuhistory7;
),
(
desc: 'FILEMENUHISTORY8';
typeof: tstBigString;
location: @opt_filemenuhistory8;
),
(
desc: 'FILEMENUHISTORY9';
typeof: tstBigString;
location: @opt_filemenuhistory9;
),
(
desc: '[Resources]';
typeof: tstDevider;
location: nil;
),
(
desc: 'WAD';
typeof: tstBigString;
location: @opt_lastwadfile;
),
(
desc: 'PALETTE';
typeof: tstBigString;
location: @opt_defaultpalette;
),
(
desc: 'PK3';
typeof: tstBigString;
location: @opt_lastpk3file;
),
(
desc: 'DIRECTORY';
typeof: tstBigString;
location: @opt_lastdirectory;
)
);
procedure splitstring(const inp: string; var out1, out2: string; const splitter: string = ' ');
var
p: integer;
begin
p := Pos(splitter, inp);
if p = 0 then
begin
out1 := inp;
out2 := '';
end
else
begin
out1 := Trim(Copy(inp, 1, p - 1));
out2 := Trim(Copy(inp, p + 1, Length(inp) - p));
end;
end;
function IntToBool(const x: integer): boolean;
begin
Result := x <> 0;
end;
function BoolToInt(const b: boolean): integer;
begin
if b then
Result := 1
else
Result := 0;
end;
function bigstringtostring(const bs: bigstring_p): string;
var
i: integer;
begin
Result := '';
for i := 0 to MAXHISTORYPATH - 1 do
if bs[i] = #0 then
Exit
else
Result := Result + bs[i];
end;
procedure stringtobigstring(const src: string; const bs: bigstring_p);
var
i: integer;
begin
for i := 0 to MAXHISTORYPATH - 1 do
bs[i] := #0;
for i := 1 to Length(src) do
begin
bs[i - 1] := src[i];
if i = MAXHISTORYPATH then
Exit;
end;
end;
procedure ter_SaveSettingsToFile(const fn: string);
var
s: TStringList;
i: integer;
begin
s := TStringList.Create;
try
for i := 0 to NUMSETTINGS - 1 do
begin
if Settings[i].typeof = tstInteger then
s.Add(Format('%s=%d', [Settings[i].desc, PInteger(Settings[i].location)^]))
else if Settings[i].typeof = tstBoolean then
s.Add(Format('%s=%d', [Settings[i].desc, BoolToInt(PBoolean(Settings[i].location)^)]))
else if Settings[i].typeof = tstBigString then
s.Add(Format('%s=%s', [Settings[i].desc, bigstringtostring(bigstring_p(Settings[i].location))]))
else if Settings[i].typeof = tstString then
s.Add(Format('%s=%s', [Settings[i].desc, PString(Settings[i].location)^]))
else if Settings[i].typeof = tstDevider then
begin
if s.Count > 0 then
s.Add('');
s.Add(Settings[i].desc);
end;
end;
s.SaveToFile(fn);
finally
s.Free;
end;
end;
function ter_LoadSettingFromFile(const fn: string): boolean;
var
s: TStringList;
i, j: integer;
s1, s2: string;
itmp: integer;
begin
if not FileExists(fn) then
begin
Result := False;
Exit;
end;
Result := True;
s := TStringList.Create;
try
s.LoadFromFile(fn);
begin
for i := 0 to s.Count - 1 do
begin
splitstring(s.Strings[i], s1, s2, '=');
if s2 <> '' then
begin
s1 := UpperCase(s1);
for j := 0 to NUMSETTINGS - 1 do
if UpperCase(Settings[j].desc) = s1 then
begin
if Settings[j].typeof = tstInteger then
begin
itmp := StrToIntDef(s2, PInteger(Settings[j].location)^);
PInteger(Settings[j].location)^ := itmp;
end
else if Settings[j].typeof = tstBoolean then
begin
itmp := StrToIntDef(s2, BoolToInt(PBoolean(Settings[j].location)^));
PBoolean(Settings[j].location)^ := IntToBool(itmp);
end
else if Settings[j].typeof = tstString then
begin
PString(Settings[j].location)^ := s2;
end
else if Settings[j].typeof = tstBigString then
begin
stringtobigstring(s2, bigstring_p(Settings[j].location));
end;
end;
end;
end;
end;
finally
s.Free;
end;
end;
end.