-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.pas
126 lines (98 loc) · 2.14 KB
/
utility.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
unit Utility;
{$mode objfpc}
{$H+}
{$modeswitch advancedrecords}
interface
uses
Classes, SysUtils;
type
tSeed = longword;
generic rNode<T> = record { TODO -cCompiler bug : Update compiler to be able to get rid of tself and advancedrecords switch }
public type
TSelf = specialize rNode<T>;
pNode = ^TSelf;
public
Value: T;
Next: pNode;
end;
//generic sNode<T> = specialize rNode<T>;
//generic pNode<T> = specialize ^rNode<T>;
{generic rNode<T> = record
data: T;
next: ^specialize rNode<T>;
end; }
const
DefaultLogName = 'ProgramLog.txt';
{$I msgstrings.inc}
procedure WriteLog(s: string; Force: boolean = false);
//procedure WriteLog(p: pchar);
function srand(Range, Seed: tSeed): longword;
function strf(v: integer): string;
function strf(v: double): string;
function Toggle(var v: boolean): boolean;
function GetBit(b: byte; n: integer): boolean;
implementation
uses
math, app;
var
ProgramLog: TFileStream;
procedure WriteLog(s: string; Force: boolean = false);
begin
s+= LineEnding;
if Force or GameApp.Options.System.KeepLog then
begin
ProgramLog.Write(s[1], length(s));
if GameApp.Options.System.PrintToConsole then
writeln(s);
end;
end;
{procedure WriteLog(p: pchar);
var
s: string;
begin
s:= string(p);
s+= LineEnding;
ProgramLog.Write(s[1], length(s));
end; }
function srand(Range, Seed: tSeed): longword;
begin
RandSeed:= Seed;
srand:= random(Range);
end;
function strf(v: integer): string;
begin
str(v, Result);
end;
function strf(v: double): string;
begin
str(v, Result);
end;
function Toggle(var v: boolean): boolean;
begin
v:= not v;
Result:= v;
end;
function GetBit(b: byte; n: integer): boolean;
var
mask: byte;
begin //intpower maybe
case n of
1: mask:= %00000001;
2: mask:= %00000010;
3: mask:= %00000100;
4: mask:= %00001000;
5: mask:= %00010000;
6: mask:= %00100000;
7: mask:= %01000000;
8: mask:= %10000000;
end;
if b and mask > 0 then
Result:= true
else
Result:= false;
end;
initialization
ProgramLog:= TFileStream.Create(DefaultLogName, fmCreate);
finalization
ProgramLog.Free;
end.