Debian Codegraph @

src/scene/x3d/castlefields_internalglobals.inc

raw
1 {%MainUnit x3dfields.pas}
2 {
3 Copyright 2002-2018 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 { Helper utilities, not exposed in X3DFields interface. }
18 {$ifdef read_interface}
19
20 {$endif read_interface}
21
22 {$ifdef read_implementation}
23
24 { Parse float value.
25 This returns Float, not just Single, because it's used by
26 TSFDouble and by ParseVector(double version),
27 that want double-precision preserved. }
28 function ParseFloat(Lexer: TX3DLexer): Float;
29 begin
30 Lexer.CheckTokenIs(TokenNumbers, 'float number');
31 result := Lexer.TokenFloat;
32 Lexer.NextToken;
33 end;
34
35 procedure ParseVector(var Vector: array of Single; Lexer: TX3DLexer); overload;
36 var
37 i: integer;
38 begin
39 for i := 0 to High(Vector) do Vector[i] := ParseFloat(Lexer);
40 end;
41
42 procedure ParseVector(var Vector: array of Double; Lexer: TX3DLexer); overload;
43 var
44 i: integer;
45 begin
46 for i := 0 to High(Vector) do Vector[i] := ParseFloat(Lexer);
47 end;
48
49 function ParseUInt32(Lexer: TX3DLexer): UInt32;
50 begin
51 Lexer.CheckTokenIs(vtInteger);
52
53 if (Lexer.TokenInteger < 0) or
54 (Lexer.TokenInteger > High(UInt32)) then
55 begin
56 WritelnWarning('X3D', 'Expected unsigned 32-bit integer, but got %d', [Lexer.TokenInteger]);
57 { Forcefully convert to UInt32, without range check errors. }
58 Result := UInt32(Lexer.TokenInteger and High(UInt32));
59 end else
60 Result := Lexer.TokenInteger;
61
62 Lexer.NextToken;
63 end;
64
65 {$endif read_implementation}