forked from gunslingermod/gunslinger_wpnpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector.pas
32 lines (24 loc) · 996 Bytes
/
Vector.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
unit Vector;
interface
type xr_vector = packed record
start:pointer;
last:pointer;
memory_end:pointer;
end;
pxr_vector = ^xr_vector;
function items_count_in_vector(v:pxr_vector; itemsz:cardinal):integer; stdcall;
function get_item_from_vector(v:pxr_vector; index:integer; itemsz:cardinal):pointer; stdcall;
implementation
uses BaseGameData;
function items_count_in_vector(v:pxr_vector; itemsz:cardinal):integer; stdcall;
begin
R_ASSERT(v<>nil, 'Cannot get items count - vector is nil', 'items_count_in_vector');
result:=(cardinal(v^.last) - cardinal(v^.start)) div itemsz;
end;
function get_item_from_vector(v:pxr_vector; index:integer; itemsz:cardinal):pointer; stdcall;
begin
R_ASSERT(v<>nil, 'Cannot get item - vector is nil', 'get_item_from_vector');
R_ASSERT((index>=0) and (index < items_count_in_vector(v, itemsz)), 'Cannot get item from vector - invalid index', 'get_item_from_vector');
result:= pointer(cardinal(v^.start)+itemsz * cardinal(index));
end;
end.