CAST II Game Engine |
||||||||
![]() |
MAIN | FEATURES | SCREENSHOTS | FORUMS | MANUAL | DOWNLOADS | CONTACTS | |
(C) 2003-2007 George "Mirage" Bakhtadze. www.casteng.com
The source code may be used under either MPL 1.1 or LGPL 2.1 license. See included license.txt file
Unit contains basic utilities, constants and types
| Name | Description |
|---|---|
Interface IRefcountedContainer | Reference-counted container of temporary objects and memory buffers |
Class TAnsiStringStream | Non-unicode string stream class |
Class TError | Base error class |
Class TFileError | |
Class TFileStream | File stream class |
Class TInvalidArgument | |
Class TInvalidFormat | |
Class TMemoryStream | Memory stream class |
Class TRandomGenerator | |
Class TStream | Base class for streams |
Class TStreamError |
function AddColorW(const Color1, Color2: TColor; W1, W2: Single): TColor; |
function AssureFloatFormat(const s: string): string; |
function BitTest(Data: Cardinal; BitIndex: Byte): Boolean; |
function BlendColor(const Color1, Color2: TColor; K: Single): TColor; |
procedure CalcCRC32(Bytes: PByteBuffer; ByteCount: Cardinal; var CRCValue: Longword); |
function Ceil(const X: Single): Integer; |
function ClampI(V, Min, Max: Integer): Integer; |
function ClampS(V, Min, Max: Single): Single; |
function CmpMem(P1, P2: Pointer; Size: Cardinal): Boolean; |
function ColorStrToIntDef(const color: string; Default: Longword): Longword; |
function CompareDates(ADate: TDateTime; Year, Month, Day: Integer): Integer; |
function CompareValues(v1, v2: Extended): Integer; |
function CreateRefcountedContainer: IRefcountedContainer; |
function ExtractStr(s, Sig: string): string; |
function FastSqrt(x: Single): Single; |
function FastTrunc(X: Single): Integer; |
procedure FillDWord(var Dest; Count: Cardinal; Value: LongWord); |
function FloatToStrA(Value: Extended): AnsiString; |
function Floor(const X: Single): Integer; |
function ForEachFile(const PathAndMask: string; AttributeFilter: Integer; Delegate: TFileDelegate): Integer; |
function FormatA(const Format: string; const Args: array of const): AnsiString; |
function GetBitsPerPixel(PixelFormat: Cardinal): Integer; |
function GetBytesPerPixel(PixelFormat: Cardinal): Integer; |
function GetColor4SIntensity(const Color: TColor4s): Single; |
function GetColorFrom4s(const ColorS: TColor4s): TColor; |
function GetColorIntensity(const Color: TColor): Integer; |
function GetCorrectRect(ALeft, ATop, ARight, ABottom: Integer): TRect; |
function GetDefaultUVMap: TUVMap; |
function GetFileName(const FileName: string): string; |
function GetLastCharPos(c: Char; const s: string): Integer; |
function GetRectIntersect(const ARect1, ARect2: TRect): TRect; |
function GetSteppedSize(CurrentSize, Step: Integer): Integer; |
function HexStrToIntDef(const s: string; Default: Longword): Longword; |
function InterleaveBits(x, y: Smallint): Integer; |
function IntPower(Base: Single; Exponent: Integer): Single; |
function IntToHexA(Value: Int64; Digits: Integer): AnsiString; |
function IntToStrA(Value: Int64): AnsiString; |
function InvSqrt(x: Single): Single; |
function IsCharIn(C: AnsiChar; const CharSet: TSysCharSet): Boolean; |
function IsColor(const s: string): Boolean; |
function IsDecimalInteger(const s: string): Boolean; |
function IsDepthFormat(Format: Integer): Boolean; |
function IsFloat(const s: string): Boolean; |
function IsInArea(const X, Y, X1, Y1, X2, Y2: Single): Boolean; overload; |
function IsInArea(const X, Y: Single; const Area: TArea): Boolean; overload; |
function IsNan(const AValue: Single): Boolean; |
function IsReal(const s: string): Boolean; |
function isSameGUID(GUID1, GUID2: TGUID): Boolean; |
function LoadString(Stream: TStream; out s: WideString): Boolean; overload; |
function LoadString(Stream: TStream; out s: AnsiString): Boolean; overload; |
function Log2I(x: Integer): Integer; |
function MaxC(V1, V2: Cardinal): Cardinal; |
function MaxI(V1, V2: Integer): Integer; |
function MaxS(V1, V2: Single): Single; |
function MinC(V1, V2: Cardinal): Cardinal; |
function MinI(V1, V2: Integer): Integer; |
function MinS(V1, V2: Single): Single; |
procedure MoveReverse16(Src, Dest: Pointer; Count: Integer); |
procedure MoveReverse8(Src, Dest: Pointer; Count: Integer); |
function NextPowerOf2(x: Integer): Integer; |
function PixelFormatToStr(Format: Integer): AnsiString; |
function PosEx(const substr : AnsiString; const s : AnsiString; const start: Integer ) : Integer ; |
function Power(const Base, Exponent: Single): Single; |
function PtrOffs(Base: Pointer; Offset: Integer): Pointer; |
procedure QuickSortInt(N: Integer; Values: TIndArray); |
procedure QuickSortIntInd(N: Integer; Values, Inds: TIndArray; Acc: Boolean); |
procedure QuickSortS(N: Integer; Values: TSingleArray); |
procedure QuickSortSInd(N: Integer; Values: TSingleArray; Inds: TIndArray; Acc: Boolean); |
procedure QuickSortStr(N: Integer; Values: TAnsiStringArray); |
procedure QuickSortStrInd(N: Integer; Values: TAnsiStringArray; Inds: TIndArray; Acc: Boolean); |
function RealToStr(Value: Extended): string; |
procedure RectIntersect(const ARect1, ARect2: TRect; out Result: TRect); |
function SaveString(Stream: TStream; const s: WideString): Boolean; overload; |
function SaveString(Stream: TStream; const s: AnsiString): Boolean; overload; |
function ScaleColorI(const Color: TColor; S: Cardinal): TColor; |
function ScaleColorS(const Color: TColor; S: Single): TColor; |
function Sign(x: Single): Single; overload; |
function Sign(x: Integer): Integer; overload; |
procedure SinCos(a: Single; out OSin, OCos: Single); |
function Split(const Str, Delim: string; out Res: TStringArray; EmptyOK: Boolean): Integer; |
function SplitA(const Str, Delim: AnsiString; out Res: TAnsiStringArray; EmptyOK: Boolean): Integer; |
function StrFormat(const s: string; args: array of string): string; |
function StringsToEnumA(Strings: array of TShortName; EmptyOK: Boolean): Ansistring; |
function StrToFloatDefA(const S: AnsiString; const Default: Extended): Extended; |
function StrToRealDef(const s: string; Default: Extended): Extended; |
procedure Swap(var V1, V2); |
procedure SwapI(var a, b: Integer); |
function TrimSpaces(ts: string): string; |
function TrimSpacesA(ts: string): AnsiString; |
function VectorToColor(const v: TVector3s): TColor; |
function AddColorW(const Color1, Color2: TColor; W1, W2: Single): TColor; |
function AssureFloatFormat(const s: string): string; |
function BitTest(Data: Cardinal; BitIndex: Byte): Boolean; |
function BlendColor(const Color1, Color2: TColor; K: Single): TColor; |
procedure CalcCRC32(Bytes: PByteBuffer; ByteCount: Cardinal; var CRCValue: Longword); |
function Ceil(const X: Single): Integer; |
function ClampI(V, Min, Max: Integer): Integer; |
function ClampS(V, Min, Max: Single): Single; |
function CmpMem(P1, P2: Pointer; Size: Cardinal): Boolean; |
function ColorStrToIntDef(const color: string; Default: Longword): Longword; |
function CompareDates(ADate: TDateTime; Year, Month, Day: Integer): Integer; |
function CompareValues(v1, v2: Extended): Integer; |
function CreateRefcountedContainer: IRefcountedContainer; |
Create an instance of reference counted container
function ExtractStr(s, Sig: string): string; |
function FastSqrt(x: Single): Single; |
Fast (if assembler optimization are allowed) implementation of Sqrt(x) with accurasy ~0.25%
function FastTrunc(X: Single): Integer; |
Fast (if SSE optimization are allowed) implementation of Trunc(x)
procedure FillDWord(var Dest; Count: Cardinal; Value: LongWord); |
function FloatToStrA(Value: Extended): AnsiString; |
function Floor(const X: Single): Integer; |
function ForEachFile(const PathAndMask: string; AttributeFilter: Integer; Delegate: TFileDelegate): Integer; |
Calls the Delegate for each file passing the given mask and attribute filter and returns number of such files. Stops if the delegate returns False
function FormatA(const Format: string; const Args: array of const): AnsiString; |
function GetBitsPerPixel(PixelFormat: Cardinal): Integer; |
function GetBytesPerPixel(PixelFormat: Cardinal): Integer; |
function GetColor4SIntensity(const Color: TColor4s): Single; |
Returns color max component value
function GetColorFrom4s(const ColorS: TColor4s): TColor; |
function GetColorIntensity(const Color: TColor): Integer; |
Returns color max component value
function GetCorrectRect(ALeft, ATop, ARight, ABottom: Integer): TRect; |
function GetDefaultUVMap: TUVMap; |
function GetFileName(const FileName: string): string; |
function GetLastCharPos(c: Char; const s: string): Integer; |
function GetRectIntersect(const ARect1, ARect2: TRect): TRect; |
function GetSteppedSize(CurrentSize, Step: Integer): Integer; |
function HexStrToIntDef(const s: string; Default: Longword): Longword; |
function InterleaveBits(x, y: Smallint): Integer; |
function IntPower(Base: Single; Exponent: Integer): Single; |
function IntToHexA(Value: Int64; Digits: Integer): AnsiString; |
function IntToStrA(Value: Int64): AnsiString; |
function InvSqrt(x: Single): Single; |
Fast (if assembler optimization are allowed) implementation of 1/Sqrt(x)
function IsCharIn(C: AnsiChar; const CharSet: TSysCharSet): Boolean; |
Returns True if the spcefied character belongs to the specified set
function IsColor(const s: string): Boolean; |
Tests with current decimal separator
function IsDecimalInteger(const s: string): Boolean; |
function IsDepthFormat(Format: Integer): Boolean; |
function IsFloat(const s: string): Boolean; |
function IsInArea(const X, Y, X1, Y1, X2, Y2: Single): Boolean; overload; |
function IsInArea(const X, Y: Single; const Area: TArea): Boolean; overload; |
function IsNan(const AValue: Single): Boolean; |
function IsReal(const s: string): Boolean; |
function isSameGUID(GUID1, GUID2: TGUID): Boolean; |
function LoadString(Stream: TStream; out s: WideString): Boolean; overload; |
Loads a wide string from a stream. Returns True if success
function LoadString(Stream: TStream; out s: AnsiString): Boolean; overload; |
Loads a string from a stream. Returns True if success
function Log2I(x: Integer): Integer; |
function MaxC(V1, V2: Cardinal): Cardinal; |
function MaxI(V1, V2: Integer): Integer; |
function MaxS(V1, V2: Single): Single; |
function MinC(V1, V2: Cardinal): Cardinal; |
function MinI(V1, V2: Integer): Integer; |
function MinS(V1, V2: Single): Single; |
procedure MoveReverse16(Src, Dest: Pointer; Count: Integer); |
procedure MoveReverse8(Src, Dest: Pointer; Count: Integer); |
function NextPowerOf2(x: Integer): Integer; |
function PixelFormatToStr(Format: Integer): AnsiString; |
function PosEx(const substr : AnsiString; const s : AnsiString; const start: Integer ) : Integer ; |
function Power(const Base, Exponent: Single): Single; |
function PtrOffs(Base: Pointer; Offset: Integer): Pointer; |
procedure QuickSortInt(N: Integer; Values: TIndArray); |
Performs a quick sort on an array of integers
procedure QuickSortIntInd(N: Integer; Values, Inds: TIndArray; Acc: Boolean); |
Performs a quick sort on an array of integers and returns sorted indices not affecting the source array
procedure QuickSortS(N: Integer; Values: TSingleArray); |
Performs a quick sort on an array of floating point numbers
procedure QuickSortSInd(N: Integer; Values: TSingleArray; Inds: TIndArray; Acc: Boolean); |
Performs a quick sort on an array of floating point numbers and returns sorted indices not affecting the source array
procedure QuickSortStr(N: Integer; Values: TAnsiStringArray); |
Performs a quick sort on an array of strings
procedure QuickSortStrInd(N: Integer; Values: TAnsiStringArray; Inds: TIndArray; Acc: Boolean); |
Performs a quick sort on an array of strings and returns sorted indices not affecting the source array
function RealToStr(Value: Extended): string; |
procedure RectIntersect(const ARect1, ARect2: TRect; out Result: TRect); |
function SaveString(Stream: TStream; const s: WideString): Boolean; overload; |
Saves a wide string to a stream. Returns True if success
function SaveString(Stream: TStream; const s: AnsiString): Boolean; overload; |
Saves a string to a stream. Returns True if success
function ScaleColorI(const Color: TColor; S: Cardinal): TColor; |
Returns scale color. S is desired koefficient multiplied by 256
function ScaleColorS(const Color: TColor; S: Single): TColor; |
function Sign(x: Single): Single; overload; |
function Sign(x: Integer): Integer; overload; |
procedure SinCos(a: Single; out OSin, OCos: Single); |
function Split(const Str, Delim: string; out Res: TStringArray; EmptyOK: Boolean): Integer; |
Splits a string into array of strings using Delim as a delimiter If EmptyOK is True result strings can be empty. Returns number of strings in array
function SplitA(const Str, Delim: AnsiString; out Res: TAnsiStringArray; EmptyOK: Boolean): Integer; |
Splits an ansi string into array of strings using Delim as a delimiter If EmptyOK is True result strings can be empty. Returns number of strings in array
function StrFormat(const s: string; args: array of string): string; |
function StringsToEnumA(Strings: array of TShortName; EmptyOK: Boolean): Ansistring; |
Returns an enumeration string which consists of all elements of strings separated by StringDelimiter If EmptyOK is True empty elements are included in result
function StrToFloatDefA(const S: AnsiString; const Default: Extended): Extended; |
function StrToRealDef(const s: string; Default: Extended): Extended; |
Tests with general decimal separator
procedure Swap(var V1, V2); |
procedure SwapI(var a, b: Integer); |
function TrimSpaces(ts: string): string; |
function TrimSpacesA(ts: string): AnsiString; |
function VectorToColor(const v: TVector3s): TColor; |
TErrorHandler = function(const Error: TError): Boolean of object; |
TFileDelegate = function(const FileName: string): Boolean of object; |
TIDFHeader = record Signature: array[0..2] of AnsiChar; Compression, PixelFormat, MipLevels, Width, Height: Cardinal; end; |
TStringCompareDelegate = function(const s1, s2: string): Integer of object; |
TErrorHandler = function(const Error: TError): Boolean of object; |
Error handler delegate. When an error occurs a delegate of this type is called (See ErrorHandler). If it returns True the application should try to continue the operation which caused the error.
TFileDelegate = function(const FileName: string): Boolean of object; |
A delegate with file name
TIDFHeader = record Signature: array[0..2] of AnsiChar; Compression, PixelFormat, MipLevels, Width, Height: Cardinal; end; |
IDF file header (deprecated)
TStringCompareDelegate = function(const s1, s2: string): Integer of object; |
A delegate for string comparison
fuAppend = 4; |
fuDoNotOpen = 0; |
fuRead = 1; |
fuReadWrite = 2; |
fuWrite = 3; |
GeneralDecimalSeparator : Char = '.'; |
icHuffman = 3; |
icLZW = 2; |
icNone = 0; |
icRLE = 1; |
icWavelet = 4; |
IDFSignature = 'IDF'; |
MinRefCContainerLength = 8; |
OneAsInt : LongWord = $3F800000; |
OneAsInt2 : LongWord = $3F800000 shl 1; |
OneOver100 = 1/100; |
OneOver255 = 1/255; |
pfA1R5G5B5 = 6; |
pfA4L4 = 14; |
pfA4R4G4B4 = 7; |
pfA8 = 8; |
pfA8B8G8R8 = 29; |
pfA8L8 = 13; |
pfA8P8 = 10; |
pfA8R8G8B8 = 2; |
pfATIDF16 = 30; |
pfATIDF24 = 31; |
pfAuto = $FFFFFFFF; |
pfB8G8R8 = 28; |
pfD15S1 = 23; |
pfD16 = 25; |
pfD16_LOCKABLE = 21; |
pfD24S8 = 24; |
pfD24X4S4 = 27; |
pfD24X8 = 26; |
pfD32 = 22; |
pfL6V5U5 = 16; |
pfL8 = 12; |
pfP8 = 11; |
pfQ8W8V8U8 = 18; |
pfR5G6B5 = 4; |
pfR8G8B8 = 1; |
pfUndefined = 0; |
pfV16U16 = 19; |
pfV8U8 = 15; |
pfW11V11U10 = 20; |
pfX1R5G5B5 = 5; |
pfX4R4G4B4 = 9; |
pfX8L8V8U8 = 17; |
pfX8R8G8B8 = 3; |
PixelFormatsEnum = 'Undefined\&R8G8B8\&A8R8G8B8\&X8R8G8B8\&' + 'R5G6B5\&X1R5G5B5\&A1R5G5B5\&A4R4G4B4\&' + 'A8\&X4R4G4B4\&A8P8\&P8\&L8\&A8L8\&A4L4\&' + 'V8U8\&L6V5U5\&X8L8V8U8\&Q8W8V8U8\&V16U16\&W11V11U10\&' + 'D16(Lockable)\&D32\&D15S1\&D24S8\&D16\&D24X8\&D24X4S4\&' + 'B8G8R8\&A8B8G8R8\&' + 'ATI_DF16\&ATI_DF24'; |
smAllowAll = 0; |
smAllowRead = 1; |
smExclusive = 2; |
StrDelim = StringDelimiter; |
StringDelimiter = '\&'; |
TotalPixelFormats = 32; |
fuAppend = 4; |
File usage: open to append
fuDoNotOpen = 0; |
File usage: do not open
fuRead = 1; |
File usage: open to read
fuReadWrite = 2; |
File usage: open to read and write
fuWrite = 3; |
File usage: open to write
GeneralDecimalSeparator : Char = '.'; |
icHuffman = 3; |
icLZW = 2; |
icNone = 0; |
IDF file format constants
icRLE = 1; |
icWavelet = 4; |
IDFSignature = 'IDF'; |
MinRefCContainerLength = 8; |
Minimum capacity of reference counted container
OneAsInt : LongWord = $3F800000; |
1.0 in integer representation
OneAsInt2 : LongWord = $3F800000 shl 1; |
OneOver100 = 1/100; |
OneOver255 = 1/255; |
pfA1R5G5B5 = 6; |
pfA4L4 = 14; |
pfA4R4G4B4 = 7; |
pfA8 = 8; |
pfA8B8G8R8 = 29; |
pfA8L8 = 13; |
pfA8P8 = 10; |
pfA8R8G8B8 = 2; |
pfATIDF16 = 30; |
pfATIDF24 = 31; |
pfAuto = $FFFFFFFF; |
pfB8G8R8 = 28; |
pfD15S1 = 23; |
pfD16 = 25; |
pfD16_LOCKABLE = 21; |
pfD24S8 = 24; |
pfD24X4S4 = 27; |
pfD24X8 = 26; |
pfD32 = 22; |
pfL6V5U5 = 16; |
pfL8 = 12; |
pfP8 = 11; |
pfQ8W8V8U8 = 18; |
pfR5G6B5 = 4; |
pfR8G8B8 = 1; |
pfUndefined = 0; |
pfV16U16 = 19; |
pfV8U8 = 15; |
pfW11V11U10 = 20; |
pfX1R5G5B5 = 5; |
pfX4R4G4B4 = 9; |
pfX8L8V8U8 = 17; |
pfX8R8G8B8 = 3; |
smAllowAll = 0; |
File sharing mode: allow all operations
smAllowRead = 1; |
File sharing mode: allow read
smExclusive = 2; |
File sharing mode: do not allow anything (exlusive)
StrDelim = StringDelimiter; |
Short alias for StringDelimiter
StringDelimiter = '\&'; |
Delimiter which separate strings in enumerations
TotalPixelFormats = 32; |
Number of supported pixel formats
ErrorHandler: TErrorHandler; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IK_ALT: Integer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ErrorHandler: TErrorHandler; |
This handler caled when an error occurs. Default handler simply logs the error class. Application can set its own handler to handle errors, raise exceptions, continue the workflow, etc. To continue the normal workflow application's handler should call Invalidate() method of the error message.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IK_ALT: Integer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Last modified: Jan 6, 2010 |