-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConstantsUnit.pas
128 lines (108 loc) · 2.67 KB
/
ConstantsUnit.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
unit ConstantsUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Windows;
const
ViewTexSize=128;
type
TObjectMethod=procedure of object;
var
path:String;
OpenSaveFilePath:String;
OpenPicturePath:String;
RenderTextureWidth:Integer;
RenderTextureHeight:Integer;
IsDocSaved:boolean;
ss_seed:Cardinal = 131322131;
function irandom(var seed:Cardinal;const max:Integer):Integer;
function frandom(var seed:Cardinal):Single;
function GetWord(var s:String):String;
function RndColor:Cardinal;
procedure SSMsg(s:String);
function ReadTagInt(var s:String;var n:Integer):boolean;
function IsDirectoryWriteable(const AName: string): Boolean;
implementation
procedure SSMsg(s:String);
begin
//MessageBox(0,PChar(s),PChar('Space Sim Message'),0);
end;
function IsDirectoryWriteable(const AName: string): Boolean;
var
FileName: String;
H: THandle;
begin
FileName := IncludeTrailingPathDelimiter(AName) + 'chk.tmp';
H := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE, 0, nil,
CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY or FILE_FLAG_DELETE_ON_CLOSE, 0);
Result := H <> INVALID_HANDLE_VALUE;
if Result then CloseHandle(H);
end;
function GetWord(var s:String):String;
var
i,j:Integer;
ss:String;
begin
s:=trim(s)+' ';
j:=pos('/',s);
i:=pos(' ',s);
if (i<j) or (j<=0) then begin
result:=copy(s,1,i-1);
delete(s,1,i);
end else begin
result:=copy(s,1,j-1);
delete(s,1,j);
end;
end;
function RndColor:Cardinal;
begin
result:=random($ffffff);
end;
function frandom(var seed:Cardinal):Single; // -1..1
var
r:Single;
begin
{$R-} // Îòêëþ÷àåì ïðîâåðêó íà ïåðåïîëíåíèå
{$Q-}
seed:=((seed shr 11) * seed * 15731 + 7789221) * seed + 8376312589;
PCardinal(@r)^:=(seed and $007fffff) or $40000000;
result:=r-3.0;
{$Q+}
{$R+} // Îòêëþ÷àåì ïðîâåðêó íà ïåðåïîëíåíèå
end;
function irandom(var seed:Cardinal;const max:Integer):Integer; // 0..max-1
var
r:Single;
sd:Cardinal;
begin
{$R-} // Îòêëþ÷àåì ïðîâåðêó íà ïåðåïîëíåíèå
{$Q-} // Îòêëþ÷àåì ïðîâåðêó íà ïåðåïîëíåíèå
seed:=seed * 543234 + 7874234234;
seed:=round($FFFFFFFF * sin(seed xor $AAAAAAAA)+56872342);
seed:=seed * 456455 + 9978234232;
result:=seed mod max;
{$R+} // Îòêëþ÷àåì ïðîâåðêó íà ïåðåïîëíåíèå
{$Q+} // Îòêëþ÷àåì ïðîâåðêó íà ïåðåïîëíåíèå
end;
function ReadTagInt(var s:String;var n:Integer):boolean;
var
si:String;
i:Integer;
begin
result:=false;
if length(s)<=0 then exit;
i:=1;
while not (s[i] in ['0'..'9']) do begin
if i>length(s) then exit;
inc(i);
end;
si:='';
while (s[i] in ['0'..'9']) do begin
si:=si+s[i];
inc(i);
end;
n:=StrToIntDef(si,0);
delete(s,1,i);
result:=true;
end;
end.