Unit CastleUtils

Description

Various basic utilities.

  • Lists, using generics derived from standard Generics.Collections. Lists of primitives, like TIntegerList and TFloatList, and a helpful class to define a list of structures TStructList.

  • Basic operations on numbers (compare, randomize).

  • Some OS-dependent things.

  • Some compatibility things, to plug the differences between various versions of FPC and Delphi.

  • Filenames operations. They do not touch actual files (operations on files are in CastleFilesUtils.)

This unit is a bag for simple and useful things. Let's not overload this unit with too many trivial utilities. When adding new utilities, first consider more specific units, like CastleFilesUtils, CastleStringUtils and CastleClassUtils. This unit does not depend on the standard Classes unit (use CastleClassUtils for utilities on top of Classes).

Initialization of this unit does some generally-useful things:

  • Makes AnsiString have UTF-8 encoding when compiled with FPC.

    See more docs about our approach to String handling in CGE, for both FPC and Delphi. Basically:

    • With FPC, we follow Lazarus convention, and String = AnsiString (8-bit) = contains UTF-8.

    • With Delphi, we follow Delphi convention, and String = UnicodeString (16-bit) = contains UTF-16.

    This way you can just use String throughout your code, and everything will just work.

    This way your applications will behave the same, whether they use Delphi, or FPC with LCL (which happens if you use TCastleControl on Lazarus form), or FPC without LCL (which happens if you use TCastleWindow with FPC).

    Some code in CGE has to assume that String is encoded like this – e.g. TCastleAbstractFont iterates over Unicode characters in a String, so it assumes that the encoding is as above, for FPC and Delphi.

Source: base/castleutils.pas (line 69).

Uses

  • BaseUnix
  • Unix
  • Dl
  • Variants
  • SysUtils
  • Math
  • Generics.Collections

Overview

Classes, Interfaces, Objects and Records

Name Description
Class EInternalError Internal error (bug) in the program.
Class ECheckFailed  
Class TNoParameterlessContructor Descend from this to hide a parameterless constructor.
Class TCastleFastList Simple fast list.
Class ELinearInterpolationImpossible TStructList
Class TStructList List of structures.
Class TMethodList List of methods (callbacks "of object").
Class EListsDifferentCount Raised by various AssignLerp implementations on lists, like TStructList.AssignLerp, when the arguments have different length.
Class TWordList List of Word (16-bit unsigned) values.
Class TUInt32List List of 32-bit unsigned values.
Class TFloatList List of Float values (defined in Math unit as float with maximum precision).
Class TSingleList List of Single (single-precision floating point) values.
Class TDoubleList List of Double (double-precision floating point) values.
Class TCardinalList List of Cardinal (unsigned) values.
Class TBooleanList List of booleans.
Class TInt32List List of 32-bit signed integer values.
Class TIntegerList List of Integer (signed) values.
Class EShortErrorMessage Descend from this to mark exceptions that should be shown in more concise way by ExceptMessage function.
Class TCodeBreaker Special class to raise an exception that is always catched.
Class EVectorInvalidOp  
Class ETransformedResultInvalid  

Functions and Procedures

function Platform: TCastlePlatform;
function PlatformToStr(const T: TCastlePlatform): String;
function StrToPlatform(const S: String): TCastlePlatform;
procedure Check(TrueValue: boolean; const ErrMessage: string = 'Check failed');
function ArrayPosStr(const A: String; const Arr: array of String): Integer; overload;
function ArrayPosText(const A: String; const Arr: array of String; const IgnoreCase: boolean = true): Integer; overload;
function ArrayContainsString(const A: String; const Arr: array of String): Boolean;
function Iff(boolval: boolean; trueval, falseval: string) : string; overload;
function Iff(boolval: boolean; trueval, falseval: Integer) : Integer; overload;
function Iff(boolval: boolean; trueval, falseval: Float) : Float; overload;
function Iff(boolval: boolean; trueval, falseval: Cardinal): Cardinal; overload;
function Iff(boolval: boolean; trueval, falseval: char) : char; overload;
function SCompilerDescription: string;
function SPlatformDescription: String;
function SCastleEngineProgramHelpSuffix(const AppName, AppVersion: String; const Ignored: Boolean): String; deprecated 'use ApplicationProperties.Description';
procedure OSCheck(TrueValue: boolean); overload;
procedure OSCheck(TrueValue: boolean; const Place: string); overload;
function FormatDot(const Fmt: String; const Args: array of const): String;
function FloatToStrDot(const Value: Extended): String;
function FloatToStrFDot(const Value: Extended; const FloatFormat: TFloatFormat; const Precision: Integer; const Digits: Integer): String;
function FloatToStrDisplay(const AValue: Extended; const ADigits: Byte = DefaultFloatStrDigits): String;
function TryStrToFloatDot(const S: String; out Value: Single): Boolean; overload;
function TryStrToFloatDot(const S: String; out Value: Double): Boolean; overload;
function StrToFloatDot(const S: String): Extended;
function StrToFloatDefDot(Const S: String; const Default: Extended): Extended;
function CastleApplicationMode: TCastleApplicationMode;
function CastleDesignMode: Boolean;
function ExceptMessage(const E: TObject): string;
procedure ProgramBreak; deprecated 'Use Halt';
function CastleReadLink(const FileName: string): string;
procedure SwapValues(var a, b: Byte ); overload; inline;
procedure SwapValues(var a, b: Int64 ); overload; inline;
procedure SwapValues(var a, b: QWord ); overload; inline;
procedure SwapValues(var a, b: Int32 ); overload; inline;
procedure SwapValues(var a, b: UInt32 ); overload; inline;
procedure SwapValues(var a, b: Single ); overload; inline;
procedure SwapValues(var a, b: Double ); overload; inline;
procedure SwapValues(var a, b: char ); overload; inline;
procedure SwapValues(var a, b: Pointer ); overload; inline;
procedure OrderUp(var Smaller, Larger: Int64 ); overload; inline;
procedure OrderUp(var Smaller, Larger: Int32 ); overload; inline;
procedure OrderUp(var Smaller, Larger: UInt32 ); overload; inline;
procedure OrderUp(var Smaller, Larger: Single ); overload; inline;
procedure OrderUp(var Smaller, Larger: Double ); overload; inline;
procedure OrderUp(x, y: Int32 ; var Smaller, Larger: Int32 ); overload; inline;
procedure OrderUp(x, y: UInt32; var Smaller, Larger: UInt32 ); overload; inline;
procedure OrderUp(x, y: Single; var Smaller, Larger: Single ); overload; inline;
procedure OrderUp(x, y: Double; var Smaller, Larger: Double ); overload; inline;
procedure MinVar(var a: Word ; const b: Word ); overload; inline;
procedure MinVar(var a: Int64 ; const b: Int64 ); overload; inline;
procedure MinVar(var a: Int32 ; const b: Int32 ); overload; inline;
procedure MinVar(var a: UInt32 ; const b: UInt32 ); overload; inline;
procedure MinVar(var a: Single ; const b: Single ); overload; inline;
procedure MinVar(var a: Double ; const b: Double ); overload; inline;
procedure MaxVar(var a: Word ; const b: Word ); overload; inline;
procedure MaxVar(var a: Int64 ; const b: Int64 ); overload; inline;
procedure MaxVar(var a: Int32 ; const b: Int32 ); overload; inline;
procedure MaxVar(var a: UInt32 ; const b: UInt32 ); overload; inline;
procedure MaxVar(var a: Single ; const b: Single ); overload; inline;
procedure MaxVar(var a: Double ; const b: Double ); overload; inline;
function IndexMax(const a0, a1, a2: Double): T3DAxis; overload; inline;
function IndexMin(const a0, a1, a2: Double): T3DAxis; overload; inline;
function Between(const a, vBegin, vEnd: Int64 ): boolean; overload; inline;
function Between(const a, vBegin, vEnd: Int32 ): boolean; overload; inline;
function Between(const a, vBegin, vEnd: UInt32 ): boolean; overload; inline;
function Between(const a, vBegin, vEnd: Float ): boolean; overload; inline;
function Between(const a, vBegin, vEnd: Char ): boolean; overload; inline;
function RoundClamp255(const A: Single): Byte; inline;
function Clamped(const a, vBegin, vEnd: Int64 ): Int64 ; overload; inline;
function Clamped(const a, vBegin, vEnd: QWord ): QWord ; overload; inline;
function Clamped(const a, vBegin, vEnd: Int32 ): Int32 ; overload; inline;
function Clamped(const a, vBegin, vEnd: UInt32 ): UInt32 ; overload; inline;
function Clamped(const a, vBegin, vEnd: Single ): Single ; overload; inline;
function Clamped(const a, vBegin, vEnd: Double ): Double ; overload; inline;
procedure ClampVar(var a: Int64 ; const vBegin, vEnd: Int64 ); overload; inline;
procedure ClampVar(var a: QWord ; const vBegin, vEnd: QWord ); overload; inline;
procedure ClampVar(var a: Int32 ; const vBegin, vEnd: Int32 ); overload; inline;
procedure ClampVar(var a: UInt32 ; const vBegin, vEnd: UInt32 ); overload; inline;
procedure ClampVar(var a: Single ; const vBegin, vEnd: Single ); overload; inline;
procedure ClampVar(var a: Double ; const vBegin, vEnd: Double ); overload; inline;
procedure Clamp(var a: Int64 ; const vBegin, vEnd: Int64 ); overload; inline; deprecated 'Use ClampVar';
procedure Clamp(var a: Int32 ; const vBegin, vEnd: Int32 ); overload; inline; deprecated 'Use ClampVar';
procedure Clamp(var a: UInt32 ; const vBegin, vEnd: UInt32 ); overload; inline; deprecated 'Use ClampVar';
procedure Clamp(var a: Single ; const vBegin, vEnd: Single ); overload; inline; deprecated 'Use ClampVar';
procedure Clamp(var a: Double ; const vBegin, vEnd: Double ); overload; inline; deprecated 'Use ClampVar';
procedure RestOf3DCoords(const Coord: T3DAxis; out First, Second: T3DAxis);
procedure RestOf3DCoordsCycle(const Coord: T3DAxis; out First, Second: T3DAxis);
function ChangeIntCycle(Value, Change, MaxValue: Integer): Integer;
function Lerp(const a: Single; const l, h: Int32 ): Single; overload; inline;
function Lerp(const a: Single; const l, h: UInt32 ): Single; overload; inline;
function Lerp(const a, l, h: Single): Single; overload; inline;
function Lerp(const a: Double; const l, h: Int32 ): Double; overload; inline;
function Lerp(const a: Double; const l, h: UInt32 ): Double; overload; inline;
function Lerp(const a, l, h: Double): Double; overload; inline;
function AngleLerp(T, Angle1, Angle2: Single): Single;
function RoundUpToMultiply(value, multiplicator: Integer): Integer;
function BiggestPowerOf2(Value: Cardinal): Cardinal;
function Biggest2Exponent(Value: Cardinal): Integer;
function Smallest2Exponent(Value: Cardinal): Integer;
function Smallest2Power(Value: Cardinal): Cardinal;
function IsPowerOf2(Value: Cardinal): boolean;
function DivRoundUp(const Value, Divider: Cardinal): Cardinal; overload;
function DivRoundUp(const Value, Divider: Integer): Integer; overload;
function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Integer): Float; overload;
function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Int64 ): Float; overload;
function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: QWord ): Float; overload;
function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Float ): Float; overload;
function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Integer): Float; overload;
function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Int64 ): Float; overload;
function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: QWord ): Float; overload;
function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Float ): Float; overload;
function MapRangeTo01(const SourceVal, SourceBegin, SourceEnd: Single): Single;
function RandomFloatRange(const RangeBegin, RangeEnd: Single): Single; overload;
function RandomFloatRange(const RangeBegin, RangeEnd: Float): Float; overload;
function RandomIntRange(const RangeBegin, RangeEnd: Integer): Integer; overload;
function RandomIntRange(const RangeBegin, RangeEnd: Int64): Int64; overload;
function RandomIntRangeInclusive(const RangeBegin, RangeEnd: Integer): Integer; overload;
function RandomIntRangeInclusive(const RangeBegin, RangeEnd: Int64): Int64; overload;
function RandomBoolean: boolean;
function RandomPlusMinus: Integer;
function AngleRadPointToPoint(x1, y1, x2, y2: Single): Single;
function NatNatPower(Base, Exponent: Cardinal): Cardinal;
function ArcCot(const x: Float): Float;
function SmallFactorial(n: Integer): Int64;
procedure CastleDivMod(Dividend: Integer; Divisor: Word; out Result, Remainder: SmallInt);
procedure DivUnsignedMod(Dividend: Integer; Divisor: Word; out Result: Smallint; out Remainder: Word);
function CeilDiv(const A, B: Cardinal): Cardinal; overload;
function CeilDiv(const A, B: Int64): Int64; overload;
procedure FloatDivMod(const A, B: Double; out DivResult: Int64; out Remainder: Double);
function FloatModulo(const A, B: Double): Double;
procedure MinMax(const x0, x1, x2: Double; out min, max: Double); overload;
procedure MinMax(const x0, x1, x2: Single; out min, max: Single); overload;
function CastleCoTan(const Value: Single): Single;
function IntSqrt(const Value: Cardinal): Cardinal;
function SmoothStep(const Edge0, Edge1, X: Single): Single;
function Swap32(Value: UInt32): UInt32;
function Swap64(Value: QWord): QWord;
function SwapEndian(const Value: Single): Single; overload;
function SwapEndian(const Value: Double): Double; overload;
function NtoLE(const Value: Single): Single; overload;
function NtoLE(const Value: Double): Double; overload;
function NtoBE(const Value: Single): Single; overload;
function NtoBE(const Value: Double): Double; overload;
function LEtoN(const Value: Single): Single; overload;
function LEtoN(const Value: Double): Double; overload;
function BEtoN(const Value: Single): Single; overload;
function BEtoN(const Value: Double): Double; overload;
function Deg(const Degrees: Float): Float;
function DeleteFileExt(const FileName: string): string;
function ExtractFileDoubleExt(const FileName: string): string;
function ExtractOnlyFilename(const FileName: string): string; deprecated;
function ChangeFilePath(const FileName, NewPath: string): string; deprecated;
function InclPathDelim(const s: string): string;
function ExclPathDelim(const s: string): string;
function IsPathAbsolute(const Path: string): boolean;
function IsPathAbsoluteOnDrive(const Path: string): boolean;
function SpecialDirName(const DirectoryName: string): boolean;
function AppendToFilename(const FileName, Suffix: string): string;
function PointerAdd(p: pointer; add: integer): pointer;
function GetClearMem(Size: integer; ClearValue: byte = 0): pointer; overload;
procedure FreeMemNiling(var p: pointer);
function CheckIsMemCharFilled(const Data; Size: Integer; AChar: AnsiChar): Integer;
function IsMemCharFilled(const Data; Size: Integer; AChar: AnsiChar): boolean;
function IsMemWordFilled(const Data; Size: Integer; Value: Word): boolean;
function IsMemDWordFilled(const Data; Size: Integer; Value: DWord): boolean;
function OffsetUInt(var A, B): PtrUInt;
function Offset(var A, B): Pointer;
function CompareMethods(const AMethod1, AMethod2: TMethod): boolean; deprecated 'use SameMethods';
function SameMethods(const AMethod1, AMethod2: TMethod): boolean;
procedure ErrorWrite(const s: string); overload;
procedure WarningWrite(const s: string); overload;
procedure InfoWrite(const s: string); overload;
procedure ErrorWrite(const s: string; const args: array of const); overload;
procedure WarningWrite(const s: string; const args: array of const); overload;
procedure InfoWrite(const s: string; const args: array of const); overload;
procedure InfoWriteParts(const TitleFormat: string; const Messages: array of string); deprecated;

Types

Float = Math.Float ;
PFloat = Math.PFloat ;
PCardinal = ˆCardinal;
PLongWord = ˆLongWord;
PShortint = ˆShortint;
PBoolean = ˆBoolean;
PByteArray = ˆTByteArray;
TByteArray = array[0..MaxInt div SizeOf(Byte)-1] of Byte;
PtrObject = ˆTObject;
TListSize = SizeInt ;
TCastlePlatform = (...);
TCastlePlatforms = set of TCastlePlatform;
TSimpleNotifyEvent = procedure of object;
TCastleApplicationMode = (...);
TBooleanSet = set of Boolean;
TUInt16List = TWordList;
TSingleArray = packed array [0..MaxInt div SizeOf(Single) - 1] of Single;
PSingleArray = ˆTSingleArray;
TInt32Array = packed array [0..MaxInt div SizeOf(Int32) - 1] of Int32;
PInt32Array = ˆTInt32Array;
EWithHiddenClassName = EShortErrorMessage deprecated 'use EShortErrorMessage';
T2DAxis = 0..1;
T3DAxis = 0..2;

Constants

AllPlatforms = [Low(TCastlePlatform)..High(TCastlePlatform)];
NL = LineEnding;
CastleEngineVersion = '7.0-alpha.3.snapshot' ;
DefaultFloatStrDigits = 5;
ENatural = 2.71828182845905;
Sqrt2 = 1.4142135623730950488016887242097;
Sqrt3 = 1.7320508075688773;
HalfPi = 1.57079632679489661923;
Pi2 = 6.28318530717958647703;
RootDir = '/' ;
ExeExtension = '' ;

Description

Functions and Procedures

function Platform: TCastlePlatform;

Current platform of this application, where we run on.

"Platform" is our term that encompasses a group of OS (operating system) and CPU (processor) combinations that behave similar in some way (for users, for developers). For example, cpDesktop is a platform that includes all desktop OSes (Linux, Windows, FreeBSD, macOS...) on all their supported CPUs.

Note There are many ways how you can make your code behave differently depending on the platform where it runs.

  • Using this function, and checking like if Platform = ... then is one approach.

  • Checking ApplicationProperties.TouchDevice is useful if you want to differentiate between devices with touch screen (and dedicated API for multi-touch) or not. See touch input for more details.

  • You can also use symbols to compile certain code only on a specific platform or specific OS or specific CPU. For example {$ifdef MSWINDOWS} WritelnLog('This is Windows'); {$endif}.

    We define some symbols by our engine build tool:

    • CASTLE_IOS

    • CASTLE_NINTENDO_SWITCH

    The compilers (Delphi or FPC) define much more symbols for this purpose. Detect OS by symbols like this:

    • LINUX

    • UNIX

    • MSWINDOWS

    • DARWIN

    • ANDROID

    • WASI (web)

    Detect CPU by symbols like this:

    • CPUX86_64

    • CPUI386

    • CPUAARCH64

    Refer to the documentation of your Pascal compiler for more details.

Source: base/castleutils_platform.inc (line 90).

function PlatformToStr(const T: TCastlePlatform): String;

This item has no description.

Source: base/castleutils_platform.inc (line 92).

function StrToPlatform(const S: String): TCastlePlatform;

Convert string to a platform name. Case (the difference between upper and lower letters) is ignored. Raises Exception on invalid platform name.

Source: base/castleutils_platform.inc (line 97).

procedure Check(TrueValue: boolean; const ErrMessage: string = 'Check failed');

Check condition.

Exceptions raised
ECheckFailed
Raised with ErrMessage if condition TrueValue if false.

Source: base/castleutils_miscella.inc (line 51).

function ArrayPosStr(const A: String; const Arr: array of String): Integer; overload;

Search the array for a given value. Returns index (zero-based) or -1 if not found.

Useful for writing case as:

case ArrayPosStr(variable, [val1, val2]) of
  0 : Something1;
  1 : Something2;
  else SomethingElse;
end;

Source: base/castleutils_miscella.inc (line 67).

function ArrayPosText(const A: String; const Arr: array of String; const IgnoreCase: boolean = true): Integer; overload;

This item has no description.

Source: base/castleutils_miscella.inc (line 68).

function ArrayContainsString(const A: String; const Arr: array of String): Boolean;

This item has no description.

Source: base/castleutils_miscella.inc (line 71).

function Iff(boolval: boolean; trueval, falseval: string) : string; overload;

Warning: this symbol is deprecated.

Simple conditional function. Returns trueval if boolval is true, falseval otherwise.

This can be used in a similar way to the ternary operator from C-like languages, e.g. like this

AvatarHeight := Iff(AvatarCrouch, 0.5, 2.0);

However, remember that this is just a regular function, so both arguments are evaluated before the result is calculated. For example, this code is incorrect:

// INCORRECT EXAMPLE, DO NOT COPY
AvatarHeight := Iff(Avatar <> nil, Avatar.Height, 0.0);

Do not use this, as equivalent functions are available in standard Pascal libraries now. Use Math.IfThen, StrUtils.IfThen instead.

Source: base/castleutils_miscella.inc (line 99).

function Iff(boolval: boolean; trueval, falseval: Integer) : Integer; overload;

This item has no description.

Source: base/castleutils_miscella.inc (line 100).

function Iff(boolval: boolean; trueval, falseval: Float) : Float; overload;

This item has no description.

Source: base/castleutils_miscella.inc (line 101).

function Iff(boolval: boolean; trueval, falseval: Cardinal): Cardinal; overload;

This item has no description.

Source: base/castleutils_miscella.inc (line 102).

function Iff(boolval: boolean; trueval, falseval: char) : char; overload;

This item has no description.

Source: base/castleutils_miscella.inc (line 103).

function SCompilerDescription: string;

Name and version of the Pascal compiler used to compile this unit.

See also
TCastleApplicationProperties.Description
Print some common information about application, for example to use in –help command-line output.
SPlatformDescription
Describe current platform, OS, CPU.

Source: base/castleutils_miscella.inc (line 116).

function SPlatformDescription: String;

Describe current platform, OS, CPU. This is all detected looking at compilation symbols defined when compiling this unit.

See also
TCastleApplicationProperties.Description
Print some common information about application, for example to use in –help command-line output.
SCompilerDescription
Name and version of the Pascal compiler used to compile this unit.

Source: base/castleutils_miscella.inc (line 123).

function SCastleEngineProgramHelpSuffix(const AppName, AppVersion: String; const Ignored: Boolean): String; deprecated 'use ApplicationProperties.Description';

Warning: this symbol is deprecated: use ApplicationProperties.Description

This item has no description.

Source: base/castleutils_miscella.inc (line 125).

procedure OSCheck(TrueValue: boolean); overload;

If not TrueValue then RaiseLastOSError.

Source: base/castleutils_miscella.inc (line 129).

procedure OSCheck(TrueValue: boolean; const Place: string); overload;

This item has no description.

Source: base/castleutils_miscella.inc (line 130).

function FormatDot(const Fmt: String; const Args: array of const): String;

Like standard Format, but always uses dot (.) as a decimal separator for the floating point numbers, regardless of the user's locale settings.

In general this ignores locale, so also ThousandSeparator doesn't matter (conversion is done like it is #0).

Source: base/castleutils_miscella.inc (line 161).

function FloatToStrDot(const Value: Extended): String;

Like standard FloatToStr, but always uses dot (.) as a decimal separator for the floating point numbers, regardless of the user's locale settings.

In general this ignores locale, so also ThousandSeparator doesn't matter (conversion is done like it is #0).

Source: base/castleutils_miscella.inc (line 168).

function FloatToStrFDot(const Value: Extended; const FloatFormat: TFloatFormat; const Precision: Integer; const Digits: Integer): String;

Like standard FloatToStr, but always uses dot (.) as a decimal separator for the floating point numbers, regardless of the user's locale settings.

In general this ignores locale, so also ThousandSeparator doesn't matter (conversion is done like it is #0).

Source: base/castleutils_miscella.inc (line 175).

function FloatToStrDisplay(const AValue: Extended; const ADigits: Byte = DefaultFloatStrDigits): String;

Display float as nice concise number to read (but not necessarily with absolute precision). This means:

  • always decimal,

  • no digits after dot if not necessary,

  • show some digits but not too many (because too many digits are usually not useful, being the result of rounding errors and not anything meaningful).

Like the ...Dot routines, this always uses dot (.) as a decimal separator, regardless of the user's locale settings.

Source: base/castleutils_miscella.inc (line 199).

function TryStrToFloatDot(const S: String; out Value: Single): Boolean; overload;

Like standard TryStrToFloat, but always uses dot (.) as a decimal separator for the floating point numbers, regardless of the user's locale settings.

Also it doesn't Trim the argument (so whitespace around number is not tolerated), and in general ignores locale (standard StrToFloat looks at ThousandSeparator).

Source: base/castleutils_miscella.inc (line 207).

function TryStrToFloatDot(const S: String; out Value: Double): Boolean; overload;

This item has no description.

Source: base/castleutils_miscella.inc (line 208).

function StrToFloatDot(const S: String): Extended;

Like standard StrToFloat, but always uses dot (.) as a decimal separator for the floating point numbers, regardless of the user's locale settings.

Also it doesn't Trim the argument (so whitespace around number is not tolerated), and in general ignores locale (standard StrToFloat looks at ThousandSeparator).

Source: base/castleutils_miscella.inc (line 218).

function StrToFloatDefDot(Const S: String; const Default: Extended): Extended;

Like standard StrToFloatDef, but always uses dot (.) as a decimal separator for the floating point numbers, regardless of the user's locale settings.

Also it doesn't Trim the argument (so whitespace around number is not tolerated), and in general ignores locale (standard StrToFloat looks at ThousandSeparator).

Source: base/castleutils_miscella.inc (line 225).

function CastleApplicationMode: TCastleApplicationMode;

Current application mode, see TCastleApplicationMode for various possible values.

Source: base/castleutils_miscella.inc (line 248).

function CastleDesignMode: Boolean;

Are we in design-time now. Shortcut for CastleApplicationMode <> appRunning.

Source: base/castleutils_miscella.inc (line 251).

function ExceptMessage(const E: TObject): string;

Nice exception description. Contains the ClassName (unless it descends from EShortErrorMessage), and the exception Message (if it descends from Exception).

Source: base/castleutils_program_exit.inc (line 40).

procedure ProgramBreak; deprecated 'Use Halt';

Warning: this symbol is deprecated: Use Halt

This item has no description.

Source: base/castleutils_program_exit.inc (line 42).

function CastleReadLink(const FileName: string): string;

Return the symlink target path. Like Libc.ReadLink or FpReadLink, but more comfortable, it returns a normal Pascal string.

Exceptions raised
EOSError
In case of any failure (non-existing FileName etc.)

Source: base/unix/castleutils_os_specific_unix.inc (line 24).

procedure SwapValues(var a, b: Byte ); overload; inline;

Swap variables values.

Source: base/castleutils_math.inc (line 23).

procedure SwapValues(var a, b: Int64 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 24).

procedure SwapValues(var a, b: QWord ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 25).

procedure SwapValues(var a, b: Int32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 26).

procedure SwapValues(var a, b: UInt32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 27).

procedure SwapValues(var a, b: Single ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 28).

procedure SwapValues(var a, b: Double ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 29).

procedure SwapValues(var a, b: char ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 33).

procedure SwapValues(var a, b: Pointer ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 34).

procedure OrderUp(var Smaller, Larger: Int64 ); overload; inline;

Make sure the Smaller value is <= than the Larger value, by eventually swapping them.

Source: base/castleutils_math.inc (line 40).

procedure OrderUp(var Smaller, Larger: Int32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 41).

procedure OrderUp(var Smaller, Larger: UInt32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 42).

procedure OrderUp(var Smaller, Larger: Single ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 43).

procedure OrderUp(var Smaller, Larger: Double ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 44).

procedure OrderUp(x, y: Int32 ; var Smaller, Larger: Int32 ); overload; inline;

Assign the smaller value from X, Y to Smaller variable, the other one to Larger variable.

Source: base/castleutils_math.inc (line 53).

procedure OrderUp(x, y: UInt32; var Smaller, Larger: UInt32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 54).

procedure OrderUp(x, y: Single; var Smaller, Larger: Single ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 55).

procedure OrderUp(x, y: Double; var Smaller, Larger: Double ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 56).

procedure MinVar(var a: Word ; const b: Word ); overload; inline;

Update value of A to be a minimum of A, B. Works like A := Min(A, B), but is marginally faster, since you don't have to do anything when A is already smaller.

Source: base/castleutils_math.inc (line 66).

procedure MinVar(var a: Int64 ; const b: Int64 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 67).

procedure MinVar(var a: Int32 ; const b: Int32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 68).

procedure MinVar(var a: UInt32 ; const b: UInt32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 69).

procedure MinVar(var a: Single ; const b: Single ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 70).

procedure MinVar(var a: Double ; const b: Double ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 71).

procedure MaxVar(var a: Word ; const b: Word ); overload; inline;

Update value of A to be a maximum of A, B. Works like A := Max(A, B), but is marginally faster, since you don't have to do anything when A is already larger.

Source: base/castleutils_math.inc (line 81).

procedure MaxVar(var a: Int64 ; const b: Int64 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 82).

procedure MaxVar(var a: Int32 ; const b: Int32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 83).

procedure MaxVar(var a: UInt32 ; const b: UInt32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 84).

procedure MaxVar(var a: Single ; const b: Single ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 85).

procedure MaxVar(var a: Double ; const b: Double ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 86).

function IndexMax(const a0, a1, a2: Double): T3DAxis; overload; inline;

Index (0, 1 or 2) of maximum / minimum of 3 numbers.

Source: base/castleutils_math.inc (line 100).

function IndexMin(const a0, a1, a2: Double): T3DAxis; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 101).

function Between(const a, vBegin, vEnd: Int64 ): boolean; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 104).

function Between(const a, vBegin, vEnd: Int32 ): boolean; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 105).

function Between(const a, vBegin, vEnd: UInt32 ): boolean; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 106).

function Between(const a, vBegin, vEnd: Float ): boolean; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 107).

function Between(const a, vBegin, vEnd: Char ): boolean; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 108).

function RoundClamp255(const A: Single): Byte; inline;

This item has no description.

Source: base/castleutils_math.inc (line 110).

function Clamped(const a, vBegin, vEnd: Int64 ): Int64 ; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 112).

function Clamped(const a, vBegin, vEnd: QWord ): QWord ; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 113).

function Clamped(const a, vBegin, vEnd: Int32 ): Int32 ; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 114).

function Clamped(const a, vBegin, vEnd: UInt32 ): UInt32 ; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 115).

function Clamped(const a, vBegin, vEnd: Single ): Single ; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 116).

function Clamped(const a, vBegin, vEnd: Double ): Double ; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 117).

procedure ClampVar(var a: Int64 ; const vBegin, vEnd: Int64 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 122).

procedure ClampVar(var a: QWord ; const vBegin, vEnd: QWord ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 123).

procedure ClampVar(var a: Int32 ; const vBegin, vEnd: Int32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 124).

procedure ClampVar(var a: UInt32 ; const vBegin, vEnd: UInt32 ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 125).

procedure ClampVar(var a: Single ; const vBegin, vEnd: Single ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 126).

procedure ClampVar(var a: Double ; const vBegin, vEnd: Double ); overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 127).

procedure Clamp(var a: Int64 ; const vBegin, vEnd: Int64 ); overload; inline; deprecated 'Use ClampVar';

Warning: this symbol is deprecated: Use ClampVar

This item has no description.

Source: base/castleutils_math.inc (line 132).

procedure Clamp(var a: Int32 ; const vBegin, vEnd: Int32 ); overload; inline; deprecated 'Use ClampVar';

Warning: this symbol is deprecated: Use ClampVar

This item has no description.

Source: base/castleutils_math.inc (line 133).

procedure Clamp(var a: UInt32 ; const vBegin, vEnd: UInt32 ); overload; inline; deprecated 'Use ClampVar';

Warning: this symbol is deprecated: Use ClampVar

This item has no description.

Source: base/castleutils_math.inc (line 134).

procedure Clamp(var a: Single ; const vBegin, vEnd: Single ); overload; inline; deprecated 'Use ClampVar';

Warning: this symbol is deprecated: Use ClampVar

This item has no description.

Source: base/castleutils_math.inc (line 135).

procedure Clamp(var a: Double ; const vBegin, vEnd: Double ); overload; inline; deprecated 'Use ClampVar';

Warning: this symbol is deprecated: Use ClampVar

This item has no description.

Source: base/castleutils_math.inc (line 136).

procedure RestOf3DCoords(const Coord: T3DAxis; out First, Second: T3DAxis);

Remaining 3D coordinates (0, 1 or 2) except the given coordinate, in the ascending order.

E.g. Coord = 0, then it sets First = 1 and Second = 2.

The coordinates are in ascending order, so e.g. for Coord = 1 we return First = 0, Second = 2.

Source: base/castleutils_math.inc (line 147).

procedure RestOf3DCoordsCycle(const Coord: T3DAxis; out First, Second: T3DAxis);

Remaining 3D coordinates (0, 1 or 2) except the given coordinate, in order to cycle.

E.g. Coord = 0, then it sets First = 1 and Second = 2.

The coordinates are in order to cycle, so First = (Coord + 1) mod 3, Second = (Coord + 2) mod 3. E.g. for Coord = 1 we return First = 2, Second = 0.

Source: base/castleutils_math.inc (line 156).

function ChangeIntCycle(Value, Change, MaxValue: Integer): Integer;

Increase Value by Change, nicely wrapping in [0..MaxValue], accepting also negative Change. The final value is always in the [0..MaxValue] range, even when initial Value was outside.

Source: base/castleutils_math.inc (line 161).

function Lerp(const a: Single; const l, h: Int32 ): Single; overload; inline;

Linear interpolation between two values. Returns (1-A)*L + A*H.

Source: base/castleutils_math.inc (line 165).

function Lerp(const a: Single; const l, h: UInt32 ): Single; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 166).

function Lerp(const a, l, h: Single): Single; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 167).

function Lerp(const a: Double; const l, h: Int32 ): Double; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 168).

function Lerp(const a: Double; const l, h: UInt32 ): Double; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 169).

function Lerp(const a, l, h: Double): Double; overload; inline;

This item has no description.

Source: base/castleutils_math.inc (line 170).

function AngleLerp(T, Angle1, Angle2: Single): Single;

Linear interpolation between 2 angle values, in radians. Goes from one value to the other through a shortest path. Values are interpreted "modulo 2 * Pi", i.e. there's no difference between Angle1 = 0.1, Angle1 = 2 * Pi + 0.1, Angle1 = -2 * Pi + 0.1 etc.

Source: base/castleutils_math.inc (line 178).

function RoundUpToMultiply(value, multiplicator: Integer): Integer;

Smallest multiple of Multiplicator that is still >= Value.

Source: base/castleutils_math.inc (line 190).

function BiggestPowerOf2(Value: Cardinal): Cardinal;

Largest power of 2 still <= Value. When Value = 0 returns 0.

Source: base/castleutils_math.inc (line 194).

function Biggest2Exponent(Value: Cardinal): Integer;

Exponent of the largest power of 2 that it's still <= Value. Like BiggestPowerOf2, except that this returns which power of 2 it is, while BiggestPowerOf2 just returns exactly this power. Biggest2Exponent(0) = -1.

Source: base/castleutils_math.inc (line 200).

function Smallest2Exponent(Value: Cardinal): Integer;

Smallest exponent such that 2ˆthis exponent is >= Value. Smallest2Exponent(0) = -1 (this is different situation than Smallest2Exponent(1), when we return 0.

Source: base/castleutils_math.inc (line 205).

function Smallest2Power(Value: Cardinal): Cardinal;

Smallest power of 2 that is >= Value. Like Smallest2Exponent, except here we return 2ˆSmallest2Exponent(Value). Returns 0 when Value = 0.

Source: base/castleutils_math.inc (line 210).

function IsPowerOf2(Value: Cardinal): boolean;

Check is Value an exact power of 2.

Source: base/castleutils_math.inc (line 213).

function DivRoundUp(const Value, Divider: Cardinal): Cardinal; overload;

This item has no description.

Source: base/castleutils_math.inc (line 215).

function DivRoundUp(const Value, Divider: Integer): Integer; overload;

This item has no description.

Source: base/castleutils_math.inc (line 216).

function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Integer): Float; overload;

Linearly map value from a one range to another.

Consider how SourceVal is placed in the [SourceBegin .. SourceEnd] (it may be outside of this range, it all still works OK). It has some distance to range start (SourceBegin), and some distance to range end (SourceEnd).

We want to find another number, that is identically placed in another range [DestBegin .. DestEnd].

  1. Such that Distance(SourceVal, SourceBegin) / Distance(SourceVal, SourceEnd) = Distance(Result, DestBegin) / Distance(Result, DestEnd).

  2. And such that it's on the same side of the range. So if SourceVal is beyond SourceEnd (that is, SourceBegin < SourceEnd < SourceVal or SourceBegin > SourceEnd > SourceVal) then the result must be similarly beyond DestEnd.

    As you can see, this works regardless if one, or both, of the ranges increase (range end is larger than range begin).

MapRangeClamped additionally at the end clamps the result to be within [DestBegin, DestEnd] range (or [DestEnd, DestBegin] range, in case DestEnd < DestBegin).

Source: base/castleutils_math.inc (line 248).

function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Int64 ): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 249).

function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: QWord ): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 250).

function MapRange(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Float ): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 251).

function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Integer): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 252).

function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Int64 ): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 253).

function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: QWord ): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 254).

function MapRangeClamped(const SourceVal, SourceBegin, SourceEnd, DestBegin, DestEnd: Float ): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 255).

function MapRangeTo01(const SourceVal, SourceBegin, SourceEnd: Single): Single;

This item has no description.

Source: base/castleutils_math.inc (line 258).

function RandomFloatRange(const RangeBegin, RangeEnd: Single): Single; overload;

Random Float value in the given range, result is between RangeBegin and RangeEnd. Always pass arguments such that RangeBegin < RangeEnd.

Source: base/castleutils_math.inc (line 263).

function RandomFloatRange(const RangeBegin, RangeEnd: Float): Float; overload;

This item has no description.

Source: base/castleutils_math.inc (line 264).

function RandomIntRange(const RangeBegin, RangeEnd: Integer): Integer; overload;

Random integer value in the given range, result is always >= RangeBegin and < RangeEnd. So result is never equal to RangeEnd, this is often convenient, and makes RandomIntRange(0, N) consistent with Random(N). Always pass arguments such that RangeBegin < RangeEnd.

Source: base/castleutils_math.inc (line 271).

function RandomIntRange(const RangeBegin, RangeEnd: Int64): Int64; overload;

This item has no description.

Source: base/castleutils_math.inc (line 272).

function RandomIntRangeInclusive(const RangeBegin, RangeEnd: Integer): Integer; overload;

Random int value in the given range, result is always >= RangeBegin and <= RangeEnd. Always pass arguments such that RangeBegin <= RangeEnd.

Source: base/castleutils_math.inc (line 277).

function RandomIntRangeInclusive(const RangeBegin, RangeEnd: Int64): Int64; overload;

This item has no description.

Source: base/castleutils_math.inc (line 278).

function RandomBoolean: boolean;

This item has no description.

Source: base/castleutils_math.inc (line 280).

function RandomPlusMinus: Integer;

Random -1 or +1.

Source: base/castleutils_math.inc (line 283).

function AngleRadPointToPoint(x1, y1, x2, y2: Single): Single;

Angle between a 2D line segments and OX axis. Angle 0 means that Y1 = Y2 and X2 > X1, then the angle increases as you rotate CCW. In radians.

Source: base/castleutils_math.inc (line 287).

function NatNatPower(Base, Exponent: Cardinal): Cardinal;

Calculate power Base to Exponent, knowing both arguments (and so, also the result) are >= 0.

Source: base/castleutils_math.inc (line 291).

function ArcCot(const x: Float): Float;

Calculate arc cotangent (inverse cotangent) of x, in radians. Defined only for FPC, as Delphi features it in Math unit.

Source: base/castleutils_math.inc (line 296).

function SmallFactorial(n: Integer): Int64;

Trivial factorial with Int64 result. Beware, the results very quickly stop to fit inside Int64 range.

Source: base/castleutils_math.inc (line 301).

procedure CastleDivMod(Dividend: Integer; Divisor: Word; out Result, Remainder: SmallInt);

Better DivMod version, in case Dividend may be < 0.

This fixes lack of DivMod with negative Remainder (for FPC at least older than 2.2.4, see fpc-devel thread "Math.DivMod results should be signed" on 2006-03-21, http://www.mail-archive.com/fpc-devel@lists.freepascal.org/msg04565.html).

And workarounds faulty DivMod behavior with FPC 2.4.0, see http://bugs.freepascal.org/view.php?id=15453

Source: base/castleutils_math.inc (line 311).

procedure DivUnsignedMod(Dividend: Integer; Divisor: Word; out Result: Smallint; out Remainder: Word);

Like DivMod (return result of Integer division and a remainder), but always return Remainder >= 0.

This is useful in case when Dividend < 0. Standard DivMod (and Pascal div and mod operators) return then Result rounded toward zero, and Remainder may be < 0. This procedure will return Result rounded toward negative infinity, and Remainder will always be >= 0.

Source: base/castleutils_math.inc (line 322).

function CeilDiv(const A, B: Cardinal): Cardinal; overload;

Returns Ceil(A / B), but calculated faster and more precisely (without floating-point help).

Source: base/castleutils_math.inc (line 327).

function CeilDiv(const A, B: Int64): Int64; overload;

This item has no description.

Source: base/castleutils_math.inc (line 328).

procedure FloatDivMod(const A, B: Double; out DivResult: Int64; out Remainder: Double);

Calculate Integer division and modulo on two Float arguments. Requires that A >= 0 and B > 0, and the Result is always >= 0.

Tries to secure against floating point imprecision. It's always guaranteed that Remainder >= 0 and <= B (and usually should be < B, but this cannot be guaranteed).

Source: base/castleutils_math.inc (line 336).

function FloatModulo(const A, B: Double): Double;

Calculate Float modulo of division on two Float arguments. Works for any A (lesser than zero too). Assumes that B > 0.

Tries to secure against floating point imprecision. It's always guaranteed that Remainder >= 0 and <= B (and usually should be < B, but this cannot be guaranteed).

Source: base/castleutils_math.inc (line 345).

procedure MinMax(const x0, x1, x2: Double; out min, max: Double); overload;

This item has no description.

Source: base/castleutils_math.inc (line 347).

procedure MinMax(const x0, x1, x2: Single; out min, max: Single); overload;

This item has no description.

Source: base/castleutils_math.inc (line 348).

function CastleCoTan(const Value: Single): Single;

Our version of CoTan, to workaround old FPC bug.

Source: base/castleutils_math.inc (line 351).

function IntSqrt(const Value: Cardinal): Cardinal;

Floor from Sqrt(Value).

Source: base/castleutils_math.inc (line 354).

function SmoothStep(const Edge0, Edge1, X: Single): Single;

Hermite interpolation between two values. For X changing from Edge0 to Edge1, the resulting value changes from 0 to 1, smoothly (not with a linear speed). This is useful to make nicer transition from one value to another, it often looks better than using directly Lerp or MapRange.

Just like GLSL smoothstep: http://www.khronos.org/opengles/sdk/docs/manglsl/xhtml/smoothstep.xml

Source: base/castleutils_math.inc (line 364).

function Swap32(Value: UInt32): UInt32;

Utility functions to control the endianess. Note: Floating-point versions support Single and Double, but not Extended (which means different things on different platforms/compilers, see https://castle-engine.io/coding_conventions#no_extended , and in practice binary files don't contain numbers >= Double).

Source: base/castleutils_math.inc (line 373).

function Swap64(Value: QWord): QWord;

This item has no description.

Source: base/castleutils_math.inc (line 374).

function SwapEndian(const Value: Single): Single; overload;

This item has no description.

Source: base/castleutils_math.inc (line 375).

function SwapEndian(const Value: Double): Double; overload;

This item has no description.

Source: base/castleutils_math.inc (line 376).

function NtoLE(const Value: Single): Single; overload;

This item has no description.

Source: base/castleutils_math.inc (line 385).

function NtoLE(const Value: Double): Double; overload;

This item has no description.

Source: base/castleutils_math.inc (line 386).

function NtoBE(const Value: Single): Single; overload;

This item has no description.

Source: base/castleutils_math.inc (line 395).

function NtoBE(const Value: Double): Double; overload;

This item has no description.

Source: base/castleutils_math.inc (line 396).

function LEtoN(const Value: Single): Single; overload;

This item has no description.

Source: base/castleutils_math.inc (line 405).

function LEtoN(const Value: Double): Double; overload;

This item has no description.

Source: base/castleutils_math.inc (line 406).

function BEtoN(const Value: Single): Single; overload;

This item has no description.

Source: base/castleutils_math.inc (line 414).

function BEtoN(const Value: Double): Double; overload;

This item has no description.

Source: base/castleutils_math.inc (line 415).

function Deg(const Degrees: Float): Float;

Convert degrees to radians, consistent with CastleScript deg() function and display of rotations in CGE editor. In CGE, all functions take rotations in radians.

Source: base/castleutils_math.inc (line 421).

function DeleteFileExt(const FileName: string): string;

Remove from the FileName the last extension (including the dot). Note that if the FileName had a couple of extensions (e.g. blah.x3d.gz) this will remove only the last one. Will remove nothing if filename has no extension.

It is not adviced to use this function, better to operate on URLs and MIME types instead of filenames and extensions, see CastleUriUtils.

Source: base/castleutils_filenames.inc (line 43).

function ExtractFileDoubleExt(const FileName: string): string;

Extracts two last extensions from the filename, if it has two extensions. If the filename has only one extension, returns that one extension, if the filename has no extension — returns empty string, similar to ExtractFileExt.

This is useful to detect file types from filenames like model.x3d.gz, where ExtractFileExt returns only .gz. This function will return .x3d.gz.

It is not adviced to use this function, better to operate on URLs and MIME types instead of filenames and extensions, see CastleUriUtils.

Source: base/castleutils_filenames.inc (line 57).

function ExtractOnlyFilename(const FileName: string): string; deprecated;

Warning: this symbol is deprecated.

Extracts from FileName the name of file, without directory, without last extension and without any Windows drive letter.

Deprecated, since we use URLs everywhere and also because this has very low usage. Use DeleteURIExt(ExtractURIName(URL)) if you really need to.

Source: base/castleutils_filenames.inc (line 65).

function ChangeFilePath(const FileName, NewPath: string): string; deprecated;

Warning: this symbol is deprecated.

Returns FileName with directory (path) part replaced with given NewPath. NewPath must contain trailing PathDelim.

Deprecated, since we use URLs everywhere and also because this has very low usage.

Source: base/castleutils_filenames.inc (line 72).

function InclPathDelim(const s: string): string;

Include / exclude the last path delimiter, if necessary. These are just comfortable shorter names for IncludeTrailingPathDelimiter and ExcludeTrailingPathDelimiter.

For Delphi, we also fix treatment of slash on Windows: it should be treated as a path delimiter, as Windows accepts both slashes and backslashes.

Source: base/castleutils_filenames.inc (line 83).

function ExclPathDelim(const s: string): string;

This item has no description.

Source: base/castleutils_filenames.inc (line 84).

function IsPathAbsolute(const Path: string): boolean;

Check is the given Path absolute.

Path may point to directory or normal file, it doesn't matter. Also it doesn't matter whether Path ends with PathDelim or not.

Note for Windows: while it's obvious that 'c:\autoexec.bat' is an absolute path, and 'autoexec.bat' is not, there's a question whether path like '\autoexec.bat' is absolute? It doesn't specify drive letter, but it does specify full directory hierarchy on some drive. This function treats this as not absolute, on the reasoning that "not all information is contained in Path".

See also
IsPathAbsoluteOnDrive
Just like IsPathAbsolute, but on Windows accepts also paths that specify full directory tree without drive letter.

Source: base/castleutils_filenames.inc (line 100).

function IsPathAbsoluteOnDrive(const Path: string): boolean;

Just like IsPathAbsolute, but on Windows accepts also paths that specify full directory tree without drive letter.

See also
IsPathAbsolute
Check is the given Path absolute.

Source: base/castleutils_filenames.inc (line 106).

function SpecialDirName(const DirectoryName: string): boolean;

Checks is the directory name special, like "." or "..".

The precise definition of "special" is that you cannot ever create or even have any filenames / directories named like this.

Source: base/castleutils_filenames.inc (line 112).

function AppendToFilename(const FileName, Suffix: string): string;

Add Suffix to the filename, right before extension. Returns DeleteFileExt(FileName) + Suffix + ExtractFileExt(FileName).

Source: base/castleutils_filenames.inc (line 116).

function PointerAdd(p: pointer; add: integer): pointer;

Pointer arithmetic. Will wrap over if you add too much. Add may be negative. This is just a shortcut for PtrInt(Result) := PtrInt(P)+Add, without any range / overflow checks.

Source: base/castleutils_pointers.inc (line 25).

function GetClearMem(Size: integer; ClearValue: byte = 0): pointer; overload;

This item has no description.

Source: base/castleutils_pointers.inc (line 27).

procedure FreeMemNiling(var p: pointer);

Safer version of FreeMem, checks is parameter Nil, and sets it to Nil afterwards.

Source: base/castleutils_pointers.inc (line 31).

function CheckIsMemCharFilled(const Data; Size: Integer; AChar: AnsiChar): Integer;

Check is memory filled with the given character. Returns -1 is True, or the number (between 0 .. Size - 1) or the first character different than AChar.

Source: base/castleutils_pointers.inc (line 36).

function IsMemCharFilled(const Data; Size: Integer; AChar: AnsiChar): boolean;

Check is memory filled with the given character. Returns simple boolean, use CheckIsMemCharFilled to get more informative result.

Source: base/castleutils_pointers.inc (line 41).

function IsMemWordFilled(const Data; Size: Integer; Value: Word): boolean;

Check is memory filled with the Word (2 byte sequence). Size if the number of words (not bytes), this is consequent with Size parameter from FillWord from FPC's RTL.

Source: base/castleutils_pointers.inc (line 46).

function IsMemDWordFilled(const Data; Size: Integer; Value: DWord): boolean;

Check is memory filled with the DWord (4 byte sequence). Size if the number of dwords (not bytes), this is consequent with Size parameter from FillDWord from FPC's RTL.

Source: base/castleutils_pointers.inc (line 51).

function OffsetUInt(var A, B): PtrUInt;

Calculate shift between A and B addresses (in bytes). Useful to pass as offsets to methods like TGLSLAttribute.EnableArray that wrap OpenGL vertex-array API. This is simply Result := A - B, except we do some typecasting.

Source: base/castleutils_pointers.inc (line 57).

function Offset(var A, B): Pointer;

This item has no description.

Source: base/castleutils_pointers.inc (line 58).

function CompareMethods(const AMethod1, AMethod2: TMethod): boolean; deprecated 'use SameMethods';

Warning: this symbol is deprecated: use SameMethods

Compare two methods.

Source: base/castleutils_pointers.inc (line 61).

function SameMethods(const AMethod1, AMethod2: TMethod): boolean;

This item has no description.

Source: base/castleutils_pointers.inc (line 62).

procedure ErrorWrite(const s: string); overload;

Write using a dialog box or console.

If we are a Windows GUI program (not IsConsole) then we use native Windows dialog boxes. Otherwise (a console is available, which is always true on non-Windows) we output the message using simple Writeln (to standard output for InfoWrite, or ErrOutput for ErrorWrite and WarningWrite).

Source: base/castleutils_read_write.inc (line 28).

procedure WarningWrite(const s: string); overload;

This item has no description.

Source: base/castleutils_read_write.inc (line 29).

procedure InfoWrite(const s: string); overload;

This item has no description.

Source: base/castleutils_read_write.inc (line 30).

procedure ErrorWrite(const s: string; const args: array of const); overload;

This item has no description.

Source: base/castleutils_read_write.inc (line 32).

procedure WarningWrite(const s: string; const args: array of const); overload;

This item has no description.

Source: base/castleutils_read_write.inc (line 33).

procedure InfoWrite(const s: string; const args: array of const); overload;

This item has no description.

Source: base/castleutils_read_write.inc (line 34).

procedure InfoWriteParts(const TitleFormat: string; const Messages: array of string); deprecated;

Warning: this symbol is deprecated.

Output messages, using console or dialog box.

If we're not on Windows or IsConsole, then we simply output Messages using Writeln.

If we're on Windows and not IsConsole, then every Messages is displayed in a separate dialog box. Dialog box uses our InfoBox routine, with Messages[I] being message content and title being Format(TitleFormat, [I + 1, Messages.Count]).

This is good for outputting a lot of information.

Deprecated. This just looks ugly in GUI version. It's better to present long information using only a console (just use Writeln), or only a full-featured GUI (like Lazarus LCL or our CastleUIControls).

Source: base/castleutils_read_write.inc (line 52).

Types

Float = Math.Float ;

Floating-point type with best precision.

Source: base/castleutils_types.inc (line 23).

PFloat = Math.PFloat ;

This item has no description.

Source: base/castleutils_types.inc (line 24).

PCardinal = ˆCardinal;

This item has no description.

Source: base/castleutils_types.inc (line 26).

PLongWord = ˆLongWord;

This item has no description.

Source: base/castleutils_types.inc (line 27).

PShortint = ˆShortint;

This item has no description.

Source: base/castleutils_types.inc (line 28).

PBoolean = ˆBoolean;

Pointer to a boolean. Defined as ˆByte in some Delphi Windows unit, for FPC 1.0.x PBoolean is not available at all.

Source: base/castleutils_types.inc (line 34).

PByteArray = ˆTByteArray;

Infinite array of bytes.

Source: base/castleutils_types.inc (line 38).

TByteArray = array[0..MaxInt div SizeOf(Byte)-1] of Byte;

This item has no description.

Source: base/castleutils_types.inc (line 39).

PtrObject = ˆTObject;

Pointer to TObject. Don't call this PObject or PTObject to avoid possible name clashes with other units (pointers are often used in situations that prevent good type-checking, so better to avoid name clashes to avoid some nasty errors).

Source: base/castleutils_types.inc (line 46).

TListSize = SizeInt ;

Size (signed) used for various list types Count, Capacity, index variables.

Delphi uses Integer for this. FPC uses SizeInt for this (which may have larger size than Integer, FPC docs say it is matching pointer size, so 64-bit on 64-bit platforms).

Source: base/castleutils_types.inc (line 53).

TCastlePlatform = (...);

Possible platforms supported by CGE. See Platform.

Values
  • cpDesktop
  • cpAndroid
  • cpIOS
  • cpNintendoSwitch
  • cpWeb

Source: base/castleutils_platform.inc (line 23).

TCastlePlatforms = set of TCastlePlatform;

This item has no description.

Source: base/castleutils_platform.inc (line 30).

TSimpleNotifyEvent = procedure of object;

Simple notify event with no Sender

TCastleApplicationMode = (...);

Application mode.

Values
  • appRunning: Application is running. We are not inside any editor (CGE editor, LCL/Delphi designer).
  • appDesign: We are designing the application in CGE editor (or LCL/Delphi designer). Simulation is not started.
  • appSimulation: We are designing the application and simulation has been started by user. The main feature of simulation right now is to test the physics at design-time. More features may be unlocked in particular components.
  • appSimulationPaused: We are designing the application and simulation has been started and paused by the user.

Source: base/castleutils_miscella.inc (line 229).

TBooleanSet = set of Boolean;

This item has no description.

Source: base/castleutils_miscella.inc (line 268).

TUInt16List = TWordList;

This item has no description.

Source: base/castleutils_primitive_lists.inc (line 41).

TSingleArray = packed array [0..MaxInt div SizeOf(Single) - 1] of Single;

This item has no description.

Source: base/castleutils_primitive_lists.inc (line 76).

PSingleArray = ˆTSingleArray;

This item has no description.

Source: base/castleutils_primitive_lists.inc (line 77).

TInt32Array = packed array [0..MaxInt div SizeOf(Int32) - 1] of Int32;

This item has no description.

Source: base/castleutils_primitive_lists.inc (line 158).

PInt32Array = ˆTInt32Array;

This item has no description.

Source: base/castleutils_primitive_lists.inc (line 159).

EWithHiddenClassName = EShortErrorMessage deprecated 'use EShortErrorMessage';

Warning: this symbol is deprecated: use EShortErrorMessage

This item has no description.

Source: base/castleutils_program_exit.inc (line 31).

T2DAxis = 0..1;

Index of axis in 2D.

Source: base/castleutils_math.inc (line 94).

T3DAxis = 0..2;

Index of axis in 3D.

Source: base/castleutils_math.inc (line 96).

Constants

AllPlatforms = [Low(TCastlePlatform)..High(TCastlePlatform)];

This item has no description.

Source: base/castleutils_platform.inc (line 33).

NL = LineEnding;

New line sequence, suitable for current OS. Short name for LineEnding.

Source: base/castleutils_miscella.inc (line 25).

CastleEngineVersion = '7.0-alpha.3.snapshot' ;

Castle Game Engine version.

Source: base/castleutils_miscella.inc (line 110).

DefaultFloatStrDigits = 5;

Number of digits after the decimal point we show using FloatToStrDisplay by default. This affects the display of floats and vectors in CGE editor's object inspector.

Source: base/castleutils_miscella.inc (line 184).

ENatural = 2.71828182845905;

This item has no description.

Source: base/castleutils_math.inc (line 181).

Sqrt2 = 1.4142135623730950488016887242097;

This item has no description.

Source: base/castleutils_math.inc (line 182).

Sqrt3 = 1.7320508075688773;

This item has no description.

Source: base/castleutils_math.inc (line 183).

HalfPi = 1.57079632679489661923;

Pi / 2.

Source: base/castleutils_math.inc (line 185).

Pi2 = 6.28318530717958647703;

Pi * 2.

Source: base/castleutils_math.inc (line 187).

RootDir = '/' ;

Root dir name. Empty if not applicable to this OS.

Source: base/castleutils_filenames.inc (line 23).

ExeExtension = '' ;

TODO: web: filesystem not yet implemented

Source: base/castleutils_filenames.inc (line 28).


Generated by PasDoc 0.17.0.snapshot.