-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClayTypes.pas
326 lines (279 loc) · 6.76 KB
/
ClayTypes.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
unit ClayTypes;
{$mode ObjFPC}{$H+}
{$i clay.inc}
interface
type
{unsigned 8-bit integer}
UInt8 = Byte;
PUInt8 = ^UInt8;
PPUInt8 = ^PUInt8;
{signed 8-bit integer}
SInt8 = ShortInt;
PSInt8 = ^SInt8;
PPSInt8 = ^PSInt8;
{unsigned 16-bit integer}
UInt16 = Word;
PUInt16 = ^UInt16;
PPUInt16 = ^PUInt16;
{signed 16-bit integer}
SInt16 = SmallInt;
PSInt16 = ^SInt16;
PPSInt16 = ^PSInt16;
{unsigned 32-bit integer}
UInt32 = LongWord;
PUInt32 = ^UInt32;
PPUInt32 = ^PUInt32;
{signed 32-bit integer}
SInt32 = LongInt;
PSInt32 = ^SInt32;
PPSInt32 = ^PSInt32;
{unsigned 64-bit integer}
{'UInt64' already defined in FPC}
PUInt64 = ^UInt64;
PPUInt64 = ^PUInt64;
{signed 64-bit integer}
SInt64 = Int64;
PSInt64 = ^SInt64;
PPSInt64 = ^PSInt64;
{32-bit float}
Float32 = Single;
PFloat32 = ^Float32;
PPFloat32 = ^PFloat32;
{64-bit float}
Float64 = Double;
PFloat64 = ^Float64;
PPFloat64 = ^PFloat64;
{16-bit Helper}
T16 = packed record
case UInt8 of
0 : (Bytes : array[0..1] of UInt8);
1 : (Chars : array[0..1] of Char);
{$IFDEF ENDIAN_LITTLE}
2 : (Low, High : UInt8);
{$ENDIF}
{$IFDEF ENDIAN_BIG}
2 : (High, Low : UInt8);
{$ENDIF}
4 : (U16 : UInt16);
5 : (S16 : SInt16);
6 : (Bits : bitpacked array [0..15] of 0..1);
end;
P16 = ^T16;
PP16 = ^P16;
{32-bit Helper}
T32 = packed record
case UInt8 of
0 : (Bytes : array[0..3] of UInt8);
1 : (Chars : array[0..3] of Char);
{$IFDEF ENDIAN_LITTLE}
2 : (Low, High : UInt16);
{$ENDIF}
{$IFDEF ENDIAN_BIG}
2 : (High, Low : UInt16);
{$ENDIF}
4 : (U32 : UInt32);
5 : (S32 : SInt32);
6 : (Bits : bitpacked array [0..31] of 0..1);
end;
P32 = ^T32;
PP32 = ^P32;
{3 Channel 8-bit}
TColour3 = packed record
case UInt8 of
1:(R,G,B: UInt8);
2:(RGB : packed array [0..2] of UInt8);
end;
PColour3 = ^TColour3;
PPColour3 = ^PColour3;
{4 Channel 8-bit}
TColour4 = packed record
case UInt8 of
1:(RGB: TColour3);
2:(R,G,B,A: UInt8);
3:(RGBA: packed array [0..3] of UInt8);
4:(RGBA32 : UInt32);
end;
PColour4 = ^TColour4;
PPColour4 = ^PColour4;
{-----Old Types------}
const
stringsize=20;
type
stdstring=string[stringsize];
stringptr=^string;
realptr=^real;
integerptr=^integer;
wordptr=^word;
byteptr=^byte;
Stringarray=^Stringarray_;
Stringarray_=array[0..0] of stdstring;
bytearray=^bytearray_;
bytearray_=array[0..0] of byte;
CharArray=^CharArray_;
CharArray_=array[0..0] of Char;
ShortArray=^ShortArray_;
ShortArray_=array[0..0] of ShortInt;
Integerarray=^Integerarray_;
Integerarray_=array[0..0] of Integer;
Wordarray=^Wordarray_;
Wordarray_=array[0..0] of word;
Longintarray=^Longintarray_;
Longintarray_=array[0..0] of longint;
realarray=^realarray_;
realarray_=array[0..0] of real;
PointerArray=^PointerArray_;
PointerArray_=array[0..0] of pointer;
BytePointerArray=^BytePointerArray_;
BytePointerArray_=array[0..0] of BytePtr;
BElemPtr=^BElem;
BElem=object
{Prev,}Next:Pointer;
end;
LinkedList=Object
Count,size:word;
first,Last:pointer;
Function Prev(Elem:BElemPtr):Pointer;
Procedure Add(Elem:BelemPtr);
Procedure Insert(By,Elem:BElemPtr);
Procedure Delete(Elem:BelemPtr);
function GetByIndex(index:word):Pointer;
Constructor Create(Size_:word);
Destructor Done;virtual;
end;
linkedlistptr=^linkedlist;
wordlistelem=object(belem)
data:word;
end;
wordlistelemptr=^wordlistelem;
integerlistelem=object(belem)
data:integer;
end;
integerlistelemptr=^integerlistelem;
longintlistelem=object(belem)
data:longint;
end;
longintlistelemptr=^longintlistelem;
reallistelem=object(belem)
data:real;
end;
reallistelemptr=^reallistelem;
Function CountFrom(elem:belemptr;count:word):Pointer;
function createwordelem(data:word):belemptr;
function createintegerelem(data:integer):belemptr;
{Type Constructors}
function Colour3(Red, Green, Blue : UInt8) : TColour3; inline;
function Colour4(Red, Green, Blue, Alpha : UInt8) : TColour4; inline;
implementation
function Colour3(Red, Green, Blue : UInt8) : TColour3; inline;
begin
Result.R := Red;
Result.G := Green;
Result.B := Blue;
end;
function Colour4(Red, Green, Blue, Alpha : UInt8) : TColour4; inline;
begin
Result.R := Red;
Result.G := Green;
Result.B := Blue;
Result.A := Alpha;
end;
function createwordelem(data:word):belemptr;
var new:belemptr;
begin
getmem(new,sizeof(wordlistelem));
wordlistelemptr(new)^.data:=data;
createwordelem:=new;
end;
function createintegerelem(data:integer):belemptr;
var new:belemptr;
begin
getmem(new,sizeof(integerlistelem));
integerlistelemptr(new)^.data:=data;
createintegerelem:=new;
end;
Function CountFrom(elem:belemptr;count:word):Pointer;
var lop:word;
begin
For lop:=1 to count-1 do
elem:=elem^.next;
CountFrom:=elem;
end;
Function LinkedList.Prev(Elem:BelemPtr):Pointer;
var E:BelemPtr;
begin
E:=First;
While (E<>nil)and(E^.next<>Elem) do
E:=E^.next;
Prev:=E;
end;
Constructor LinkedList.Create(Size_:word);
begin
Count:=0;
first:=nil;
Last:=nil;
Size:=Size_;
end;
Destructor LinkedList.Done;
var next:BelemPtr;
begin
while first<>nil do begin
next:=BelemPtr(first)^.next;
Freemem(BelemPtr(first),size);
first:=next;
end;
Count:=0;
last:=nil;
first:=nil;
end;
{assumes Elem^.next = nil}
Procedure LinkedList.add(Elem:BelemPtr);
begin
BelemPtr(Elem)^.next:=nil;
if First=nil then
First:=Elem
else
BelemPtr(last)^.next:=Elem;
last:=Elem;
inc(count);
end;
Procedure LinkedList.delete(Elem:BelemPtr);
var Previous:BelemPtr;
begin
if Elem=first then begin
first:=Elem^.next;
Previous:=nil;
end else begin
Previous:=Prev(elem);
Previous^.next:=Elem^.next;
end;
if elem=last then last:=Previous;
Freemem(Elem,Size);
dec(count);
end;
Procedure LinkedList.insert(by,elem:BelemPtr);
var previous:BelemPtr;
begin
if by=first then begin
elem^.next:=by;
first:=elem;
end else begin
Previous:=Prev(by);
Elem^.next:=Previous^.next;
Previous^.next:=Elem;
end;
inc(count);
end;
function LinkedList.GetByIndex(index:word):Pointer;
var lop:word;
CurrElem:BelemPtr;
begin
if index>count then
GetByIndex:=Last
else begin
Currelem:=First;
for lop:=1 to index do
Currelem:=Currelem^.next;
GetByIndex:=CurrElem;
end;
end;
end.