-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpsv_script_functions.pas
533 lines (419 loc) · 12.2 KB
/
psv_script_functions.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
//------------------------------------------------------------------------------
//
// DD_VOXEL: DelphiDoom Voxel Editor
// Copyright (C) 2013-2018 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:
// Script functions library
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/delphidoom-voxel-editor/
// https://sourceforge.net/projects/delphidoom/files/DDVoxels/
//------------------------------------------------------------------------------
unit psv_script_functions;
interface
// --------------------------- general -----------------------------------------
type
TDynamicIntegerArray = array of Integer;
TDynamicInt64Array = array of Int64;
TDynamicLongWordArray = array of LongWord;
TDynamicSingleArray = array of single;
TDynamicDoubleArray = array of double;
TDynamicExtendedArray = array of extended;
procedure VDLS_Write(const parm: string);
procedure VDLS_WriteFmt(const Fmt: string; const args: array of const);
procedure VDLS_Writeln(const parm: string);
procedure VDLS_WritelnFmt(const Fmt: string; const args: array of const);
procedure VDLS_BreakPoint(const msg: string);
function VDLS_Tan(const parm: Extended): Extended;
function VDLS_Sin360(const parm: Extended): Extended;
function VDLS_Cos360(const parm: Extended): Extended;
function VDLS_Tan360(const parm: Extended): Extended;
function VDLS_Format(const Fmt: string; const args: array of const): string;
function VDLS_IFI(const condition: boolean; const iftrue, iffalse: Int64): Int64;
function VDLS_IFF(const condition: boolean; const iftrue, iffalse: Extended): Extended;
function VDLS_IFS(const condition: boolean; const iftrue, iffalse: string): string;
function VDLS_Odd(const x: integer): boolean;
function VDLS_Even(const x: integer): boolean;
function VDLS_MergeIntegerArrays(const A1, A2: TDynamicIntegerArray): TDynamicIntegerArray;
function VDLS_MergeInt64Arrays(const A1, A2: TDynamicInt64Array): TDynamicInt64Array;
function VDLS_MergeLongWordArrays(const A1, A2: TDynamicLongWordArray): TDynamicLongWordArray;
function VDLS_MergeSingleArrays(const A1, A2: TDynamicSingleArray): TDynamicSingleArray;
function VDLS_MergeDoubleArrays(const A1, A2: TDynamicDoubleArray): TDynamicDoubleArray;
function VDLS_MergeExtendedArrays(const A1, A2: TDynamicExtendedArray): TDynamicExtendedArray;
function VDLS_IsPrime(const N: Int64): Boolean;
function VDLS_IsIntegerInRange(const test, f1, f2: integer): boolean;
function VDLS_IsLongWordInRange(const test, f1, f2: LongWord): boolean;
function VDLS_IsFloatInRange(const test, f1, f2: single): boolean;
function VDLS_IsDoubleInRange(const test, f1, f2: double): boolean;
function VDLS_IsExtendedInRange(const test, f1, f2: Extended): boolean;
function VDLS_Sqr(const x: Extended): Extended;
function VDLS_Sqrt(const x: Extended): Extended;
function VDLS_Cube(const x: Extended): Extended;
function VDLS_ArcCos(const X: Extended): Extended;
function VDLS_ArcSin(const X: Extended): Extended;
function VDLS_ArcTan2(const Y, X: Extended): Extended;
procedure VDLS_SinCosE(const Theta: Extended; var S, C: Extended);
procedure VDLS_SinCosD(const Theta: Extended; var S, C: Double);
procedure VDLS_SinCosF(const Theta: Extended; var S, C: Single);
function VDLS_Cosh(const X: Extended): Extended;
function VDLS_Sinh(const X: Extended): Extended;
function VDLS_Tanh(const X: Extended): Extended;
function VDLS_ArcCosh(const X: Extended): Extended;
function VDLS_ArcSinh(const X: Extended): Extended;
function VDLS_ArcTanh(const X: Extended): Extended;
function VDLS_Log10(const X: Extended): Extended;
function VDLS_Log2(const X: Extended): Extended;
function VDLS_Ln(const X: Extended): Extended;
function VDLS_LogN(const Base, X: Extended): Extended;
function VDLS_IntPower(const Base: Extended; const Exponent: Integer): Extended;
function VDLS_Power(const Base, Exponent: Extended): Extended;
function VDLS_Ceil(const X: Extended):Integer;
function VDLS_Floor(const X: Extended): Integer;
type
outproc_t = procedure(const s: string);
var
outproc: outproc_t;
procedure printf(const s: string);
// ---------------------------- opengl -----------------------------------------
implementation
uses
SysUtils,
Math;
procedure printf(const s: string);
begin
if Assigned(outproc) then
outproc(s);
end;
procedure VDLS_Write(const parm: string);
begin
printf(parm);
end;
procedure VDLS_WriteFmt(const Fmt: string; const args: array of const);
begin
VDLS_Write(VDLS_Format(Fmt, args));
end;
procedure VDLS_Writeln(const parm: string);
begin
printf(parm + #13#10);
end;
procedure VDLS_WritelnFmt(const Fmt: string; const args: array of const);
begin
VDLS_Writeln(VDLS_Format(Fmt, args));
end;
var
bpmsg: string = '';
// Actually for debuging the engine, not script
procedure VDLS_BreakPoint(const msg: string);
begin
bpmsg := msg;
end;
function VDLS_Tan(const parm: Extended): Extended;
begin
Result := tan(parm);
end;
function VDLS_Sin360(const parm: Extended): Extended;
begin
Result := sin(parm / 360 * 2 * pi);
end;
function VDLS_Cos360(const parm: Extended): Extended;
begin
Result := cos(parm / 360 * 2 * pi);
end;
function VDLS_Tan360(const parm: Extended): Extended;
begin
Result := tan(parm / 360 * 2 * pi);
end;
function VDLS_Format(const Fmt: string; const args: array of const): string;
begin
try
Result := Format(Fmt, Args);
except
Result := Fmt;
end;
end;
function VDLS_IFI(const condition: boolean; const iftrue, iffalse: Int64): Int64;
begin
if condition then
Result := iftrue
else
Result := iffalse;
end;
function VDLS_IFF(const condition: boolean; const iftrue, iffalse: Extended): Extended;
begin
if condition then
Result := iftrue
else
Result := iffalse;
end;
function VDLS_IFS(const condition: boolean; const iftrue, iffalse: string): string;
begin
if condition then
Result := iftrue
else
Result := iffalse;
end;
function VDLS_Odd(const x: integer): boolean;
begin
Result := Odd(x);
end;
function VDLS_Even(const x: integer): boolean;
begin
Result := not Odd(x);
end;
function VDLS_MergeIntegerArrays(const A1, A2: TDynamicIntegerArray): TDynamicIntegerArray;
var
l1, l2: integer;
i: integer;
begin
l1 := Length(A1);
l2 := Length(A2);
SetLength(Result, l1 + l2);
for i := 0 to l1 - 1 do
Result[i] := A1[i];
for i := 0 to l2 - 1 do
Result[l1 + i] := A2[i];
end;
function VDLS_MergeInt64Arrays(const A1, A2: TDynamicInt64Array): TDynamicInt64Array;
var
l1, l2: integer;
i: integer;
begin
l1 := Length(A1);
l2 := Length(A2);
SetLength(Result, l1 + l2);
for i := 0 to l1 - 1 do
Result[i] := A1[i];
for i := 0 to l2 - 1 do
Result[l1 + i] := A2[i];
end;
function VDLS_MergeLongWordArrays(const A1, A2: TDynamicLongWordArray): TDynamicLongWordArray;
var
l1, l2: integer;
i: integer;
begin
l1 := Length(A1);
l2 := Length(A2);
SetLength(Result, l1 + l2);
for i := 0 to l1 - 1 do
Result[i] := A1[i];
for i := 0 to l2 - 1 do
Result[l1 + i] := A2[i];
end;
function VDLS_MergeSingleArrays(const A1, A2: TDynamicSingleArray): TDynamicSingleArray;
var
l1, l2: integer;
i: integer;
begin
l1 := Length(A1);
l2 := Length(A2);
SetLength(Result, l1 + l2);
for i := 0 to l1 - 1 do
Result[i] := A1[i];
for i := 0 to l2 - 1 do
Result[l1 + i] := A2[i];
end;
function VDLS_MergeDoubleArrays(const A1, A2: TDynamicDoubleArray): TDynamicDoubleArray;
var
l1, l2: integer;
i: integer;
begin
l1 := Length(A1);
l2 := Length(A2);
SetLength(Result, l1 + l2);
for i := 0 to l1 - 1 do
Result[i] := A1[i];
for i := 0 to l2 - 1 do
Result[l1 + i] := A2[i];
end;
function VDLS_MergeExtendedArrays(const A1, A2: TDynamicExtendedArray): TDynamicExtendedArray;
var
l1, l2: integer;
i: integer;
begin
l1 := Length(A1);
l2 := Length(A2);
SetLength(Result, l1 + l2);
for i := 0 to l1 - 1 do
Result[i] := A1[i];
for i := 0 to l2 - 1 do
Result[l1 + i] := A2[i];
end;
function VDLS_IsPrime(const N: Int64): Boolean;
var
Test, k: Int64;
ee: Extended;
begin
if N <= 3 then
Result := N > 1
else if ((N mod 2) = 0) or ((N mod 3) = 0) then
Result := False
else
begin
Result := True;
ee := N;
k := Trunc(Sqrt(ee));
Test := 5;
while Test <= k do
begin
if ((N mod Test) = 0) or ((N mod (Test + 2)) = 0) then
begin
Result := False;
break; // jump out of the for loop
end;
Test := Test + 6;
end;
end;
end;
function VDLS_IsIntegerInRange(const test, f1, f2: integer): boolean;
begin
if f1 < f2 then
result := (test >= f1) and (test <= f2)
else
result := (test >= f2) and (test <= f1)
end;
function VDLS_IsLongWordInRange(const test, f1, f2: LongWord): boolean;
begin
if f1 < f2 then
result := (test >= f1) and (test <= f2)
else
result := (test >= f2) and (test <= f1)
end;
function VDLS_IsFloatInRange(const test, f1, f2: single): boolean;
begin
if f1 < f2 then
result := (test >= f1) and (test <= f2)
else
result := (test >= f2) and (test <= f1)
end;
function VDLS_IsDoubleInRange(const test, f1, f2: double): boolean;
begin
if f1 < f2 then
result := (test >= f1) and (test <= f2)
else
result := (test >= f2) and (test <= f1)
end;
function VDLS_IsExtendedInRange(const test, f1, f2: Extended): boolean;
begin
if f1 < f2 then
result := (test >= f1) and (test <= f2)
else
result := (test >= f2) and (test <= f1)
end;
function VDLS_Sqr(const x: Extended): Extended;
begin
Result := x * x;
end;
function VDLS_Sqrt(const x: Extended): Extended;
begin
Result := Sqrt(x);
end;
function VDLS_Cube(const x: Extended): Extended;
begin
Result := x * x * x;
end;
function VDLS_ArcCos(const X: Extended): Extended;
begin
Result := ArcCos(X);
end;
function VDLS_ArcSin(const X: Extended): Extended;
begin
Result := ArcSin(X);
end;
function VDLS_ArcTan2(const Y, X: Extended): Extended;
begin
Result := ArcTan2(Y, X);
end;
procedure VDLS_SinCosE(const Theta: Extended; var S, C: Extended);
begin
SinCos(Theta, S, C);
end;
procedure VDLS_SinCosD(const Theta: Extended; var S, C: Double);
var
S1, C1: Extended;
begin
SinCos(Theta, S1, C1);
S := S1;
C := C1;
end;
procedure VDLS_SinCosF(const Theta: Extended; var S, C: Single);
var
S1, C1: Extended;
begin
SinCos(Theta, S1, C1);
S := S1;
C := C1;
end;
function VDLS_Cosh(const X: Extended): Extended;
begin
Result := Cosh(X);
end;
function VDLS_Sinh(const X: Extended): Extended;
begin
Result := Sinh(X);
end;
function VDLS_Tanh(const X: Extended): Extended;
begin
Result := Tanh(X);
end;
function VDLS_ArcCosh(const X: Extended): Extended;
begin
Result := ArcCosh(X);
end;
function VDLS_ArcSinh(const X: Extended): Extended;
begin
Result := ArcSinh(X);
end;
function VDLS_ArcTanh(const X: Extended): Extended;
begin
Result := ArcTanh(X);
end;
function VDLS_Log10(const X: Extended): Extended;
begin
Result := Log10(X);
end;
function VDLS_Log2(const X: Extended): Extended;
begin
Result := Log2(X);
end;
function VDLS_Ln(const X: Extended): Extended;
begin
Result := Ln(X);
end;
function VDLS_LogN(const Base, X: Extended): Extended;
begin
Result := LogN(Base, X);
end;
function VDLS_IntPower(const Base: Extended; const Exponent: Integer): Extended;
begin
Result := IntPower(Base, Exponent);
end;
function VDLS_Power(const Base, Exponent: Extended): Extended;
begin
Result := Power(Base, Exponent);
end;
function VDLS_Ceil(const X: Extended): Integer;
begin
Result := Ceil(X);
end;
function VDLS_Floor(const X: Extended): Integer;
begin
Result := Floor(X);
end;
end.