📄 hge.pas
字号:
unit HGE;
(*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** Delphi conversion by Erik van Bilsen
*)
interface
uses
Classes, Windows, DirectXGraphics, Bass, OpenJpeg, Graphics, D3DX81mo;
(****************************************************************************
* HGE.h
****************************************************************************)
const
HGE_VERSION = $160;
IRad = 1 / 360;
TwoPI = 2 * 3.14159265358;
(*
** HGE Handle types
*)
type
ITexture = Interface
['{9D5C8783-956C-42E1-9307-CAD03DEC1E7A}']
function GetHandle: IDirect3DTexture8;
function GetName: string;
procedure SetName(Value: string);
function GetPatternWidth: Integer;
procedure SetPatternWidth(Value: Integer);
function GetPatternHeight: Integer;
procedure SetPatternHeight(Value: Integer);
function GetPatternCount: Integer;
procedure SetHandle(const Value: IDirect3DTexture8);
function GetWidth(const Original: Boolean = False): Integer;
function GetHeight(const Original: Boolean = False): Integer;
function Lock(const ReadOnly: Boolean = True; const Left: Integer = 0;
const Top: Integer = 0; const Width: Integer = 0;
const Height: Integer = 0): PLongword;
procedure Unlock;
property Name: string read GetName write SetName;
property PatternWidth: Integer read GetPatternWidth write SetPatternWidth;
property PatternHeight: Integer read GetPatternHeight write SetPatternHeight;
property PatternCount: Integer read GetPatternCount;
property Handle: IDirect3DTexture8 read GetHandle write SetHandle;
end;
type
IChannel = interface
['{32549D16-44B1-4912-A7FE-025BCFFFB950}']
function GetHandle: HChannel;
procedure SetPanning(const Pan: Integer);
procedure SetVolume(const Volume: Integer);
procedure SetPitch(const Pitch: Single);
procedure Pause;
procedure Resume;
procedure Stop;
function IsPlaying: Boolean;
function IsSliding: Boolean;
function GetLength: Single;
function GetPos: Single;
procedure SetPos(const Seconds: Single);
procedure SlideTo(const Time: Single; const Volume: Integer;
const Pan: Integer = -101; const Pitch: Single = -1);
property Handle: HChannel read GetHandle;
end;
type
IEffect = interface
['{526AD139-7C58-4692-AF7E-84206531CEC2}']
function GetHandle: HSample;
function Play: IChannel;
function PlayEx(const Volume: Integer = 100; const Pan: Integer = 0;
const Pitch: Single = 1.0; const Loop: Boolean = False): IChannel;
property Handle: HSample read GetHandle;
end;
type
IMusic = interface
['{15A0ADA4-DF3D-4821-B06E-5F72208709EA}']
function GetHandle: HMusic;
function Play(const Loop: Boolean; const Volume: Integer = 100;
const Order: Integer = -1; const Row: Integer = -1): IChannel;
function GetAmplification: Integer;
function GetLength: Integer;
procedure SetPos(const Order, Row: Integer);
function GetPos(out Order, Row: Integer): Boolean;
procedure SetInstrVolume(const Instr, Volume: Integer);
function GetInstrVolume(const Instr: Integer): Integer;
procedure SetChannelVolume(const Channel, Volume: Integer);
function GetChannelVolume(const Channel: Integer): Integer;
property Handle: HMusic read GetHandle;
end;
type
ITarget = interface
['{16FB54D6-6682-4496-82F0-4B4617FDF2D0}']
function GetWidth: Integer;
function GetHeight: Integer;
function GetTex: ITexture;
function GetTexture: ITexture;
property Width: Integer read GetWidth;
property Height: Integer read GetHeight;
property Tex: ITexture read GetTex;
end;
type
IStream = interface
['{589A2704-27A7-4E18-B0EA-8F00E1E3A349}']
function GetHandle: HStream;
function Play(const Loop: Boolean; const Volume: Integer = 100): IChannel;
property Handle: HStream read GetHandle;
end;
type
IResource = interface
['{BAA2A47B-87B1-4D26-A8EF-AE49E3B2BC6F}']
function GetHandle: Pointer;
function GetSize: Longword;
property Handle: Pointer read GetHandle;
property Size: Longword read GetSize;
end;
(*
** Common math constants
*)
const
M_PI = 3.14159265358979323846;
M_PI_2 = 1.57079632679489661923;
M_PI_4 = 0.785398163397448309616;
M_1_PI = 0.318309886183790671538;
M_2_PI = 0.636619772367581343076;
(*
** Hardware color macros
*)
function ARGB(const A, R, G, B: Byte): Longword; inline;
function GetA(const Color: Longword): Byte; inline;
function GetR(const Color: Longword): Byte; inline;
function GetG(const Color: Longword): Byte; inline;
function GetB(const Color: Longword): Byte; inline;
function SetA(const Color: Longword; const A: Byte): Longword; inline;
function SetR(const Color: Longword; const A: Byte): Longword; inline;
function SetG(const Color: Longword; const A: Byte): Longword; inline;
function SetB(const Color: Longword; const A: Byte): Longword; inline;
(*
** HGE Blending constants
*)
const
BLEND_COLORADD = 1;
BLEND_COLORMUL = 0;
BLEND_ALPHABLEND = 2;
BLEND_ALPHAADD = 0;
BLEND_ZWRITE = 4;
BLEND_NOZWRITE = 0;
BLEND_DEFAULT = BLEND_COLORMUL or BLEND_ALPHABLEND or BLEND_NOZWRITE;
BLEND_DEFAULT_Z = BLEND_COLORMUL or BLEND_ALPHABLEND or BLEND_ZWRITE;
Blend_Add = 100;
Blend_SrcAlpha = 101;
Blend_SrcAlphaAdd = 102;
Blend_SrcColor = 103;
BLEND_SrcColorAdd = 104;
Blend_Invert = 105;
Blend_SrcBright = 106;
Blend_Multiply = 107;
Blend_InvMultiply = 108;
Blend_MultiplyAlpha = 109;
Blend_InvMultiplyAlpha = 110;
Blend_DestBright = 111;
Blend_InvSrcBright = 112;
Blend_InvDestBright = 113;
Blend_Bright = 114;
Blend_BrightAdd = 115;
Blend_GrayScale = 116;
Blend_Light = 117;
Blend_LightAdd = 118;
Blend_Add2X = 119;
Blend_OneColor = 120;
Blend_XOR = 121;
{*
** HGE System state constants
*}
type
THGEBoolState = (
HGE_WINDOWED = 12, // bool run in window? (default: false)
HGE_ZBUFFER = 13, // bool use z-buffer? (default: false)
HGE_TEXTUREFILTER = 28, // bool texture filtering? (default: true)
HGE_USESOUND = 18, // bool use BASS for sound? (default: true)
HGE_DONTSUSPEND = 24, // bool focus lost:suspend? (default: false)
HGE_HIDEMOUSE = 25, // bool hide system cursor? (default: true)
HGE_SHOWSPLASH = 27, // bool hide system cursor? (default: true)
HGEBOOLSTATE_FORCE_DWORD = $7FFFFFFF
);
type
THGEFuncState = (
HGE_FRAMEFUNC = 1, // bool*() frame function (default: NULL) (you MUST set this)
HGE_RENDERFUNC = 2, // bool*() render function (default: NULL)
HGE_FOCUSLOSTFUNC = 3, // bool*() focus lost function (default: NULL)
HGE_FOCUSGAINFUNC = 4, // bool*() focus gain function (default: NULL)
HGE_GFXRESTOREFUNC = 5, // bool*() exit function (default: NULL)
HGE_EXITFUNC = 6, // bool*() exit function (default: NULL)
HGEFUNCSTATE_FORCE_DWORD = $7FFFFFFF
);
type
THGEHWndState = (
HGE_HWND = 26, // int window handle: read only
HGE_HWNDPARENT = 27, // int parent win handle (default: 0)
HGEHWNDSTATE_FORCE_DWORD = $7FFFFFFF
);
type
THGEIntState = (
HGE_SCREENWIDTH = 9, // int screen width (default: 800)
HGE_SCREENHEIGHT = 10, // int screen height (default: 600)
HGE_SCREENBPP = 11, // int screen bitdepth (default: 32) (desktop bpp in windowed mode)
HGE_SAMPLERATE = 19, // int sample rate (default: 44100)
HGE_FXVOLUME = 20, // int global fx volume (default: 100)
HGE_MUSVOLUME = 21, // int global music volume (default: 100)
HGE_FPS = 23, // int fixed fps (default: HGEFPS_UNLIMITED)
HGEINTSTATE_FORCE_DWORD = $7FFFFFF
);
type
THGEStringState = (
HGE_ICON = 7, // char* icon resource (default: NULL)
HGE_TITLE = 8, // char* window title (default: "HGE")
HGE_INIFILE = 15, // char* ini file (default: NULL) (meaning no file)
HGE_LOGFILE = 16, // char* log file (default: NULL) (meaning no file)
HGESTRINGSTATE_FORCE_DWORD = $7FFFFFFF
);
(*
** Callback protoype used by HGE
*)
type
THGECallback = function: Boolean;
(*
** HGE_FPS system state special constants
*)
const
HGEFPS_UNLIMITED = 0;
HGEFPS_VSYNC = -1;
(*
** HGE Primitive type constants
*)
const
HGEPRIM_LINES = 2;
HGEPRIM_TRIPLES = 3;
HGEPRIM_QUADS = 4;
(*
** HGE Vertex structure
*)
type
THGEVertex = record
X, Y: Single; // screen position
Z: Single; // Z-buffer depth 0..1
Col: Longword; // color
TX, TY: Single; // texture coordinates
end;
PHGEVertex = ^THGEVertex;
THGEVertexArray = array [0..MaxInt div 32 - 1] of THGEVertex;
PHGEVertexArray = ^THGEVertexArray;
(*
** HGE Triple structure
*)
type
THGETriple = record
V: array [0..2] of THGEVertex;
Tex: ITexture;
Blend: Integer;
end;
PHGETriple = ^THGETriple;
(*
** HGE Quad structure
*)
type
THGEQuad = record
V: array [0..3] of THGEVertex;
Tex: ITexture;
Blend: Integer;
end;
PHGEQuad = ^THGEQuad;
(*
** HGE Input Event structure
*)
type
THGEInputEvent = record
EventType: Integer; // event type
Key: Integer; // key code
Flags: Integer; // event flags
Chr: Integer; // character code
Wheel: Integer; // wheel shift
X: Single; // mouse cursor x-coordinate
Y: Single; // mouse cursor y-coordinate
end;
(*
** HGE Input Event type constants
*)
const
INPUT_KEYDOWN = 1;
INPUT_KEYUP = 2;
INPUT_MBUTTONDOWN = 3;
INPUT_MBUTTONUP = 4;
INPUT_MOUSEMOVE = 5;
INPUT_MOUSEWHEEL = 6;
(*
** HGE Input Event flags
*)
const
HGEINP_SHIFT = 1;
HGEINP_CTRL = 2;
HGEINP_ALT = 4;
HGEINP_CAPSLOCK = 8;
HGEINP_SCROLLLOCK = 16;
HGEINP_NUMLOCK = 32;
HGEINP_REPEAT = 64;
type
IHGE = interface
['{14AD0876-19A5-4B13-B2D8-46ECE1E336BA}']
function System_Initiate: Boolean;
procedure System_Shutdown;
function System_Start: Boolean;
function System_GetErrorMessage: String;
procedure System_Log(const S: String); overload;
procedure System_Log(const Format: String; const Args: array of Const); overload;
function System_Launch(const Url: String): Boolean;
procedure System_Snapshot(const Filename: String);
procedure System_SetState(const State: THGEBoolState; const Value: Boolean); overload;
procedure System_SetState(const State: THGEFuncState; const Value: THGECallback); overload;
procedure System_SetState(const State: THGEHWndState; const Value: HWnd); overload;
procedure System_SetState(const State: THGEIntState; const Value: Integer); overload;
procedure System_SetState(const State: THGEStringState; const Value: String); overload;
function System_GetState(const State: THGEBoolState): Boolean; overload;
function System_GetState(const State: THGEFuncState): THGECallback; overload;
function System_GetState(const State: THGEHWndState): HWnd; overload;
function System_GetState(const State: THGEIntState): Integer; overload;
function System_GetState(const State: THGEStringState): String; overload;
function Resource_Load(const Filename: String; const Size: PLongword = nil): IResource;
{ NOTE: ZIP passwords are not supported in Delphi version }
function Resource_AttachPack(const Filename: String): Boolean;
procedure Resource_RemovePack(const Filename: String);
procedure Resource_RemoveAllPacks;
function Resource_MakePath(const Filename: String = ''): String;
function Resource_EnumFiles(const Wildcard: String = ''): String;
function Resource_EnumFolders(const Wildcard: String = ''): String;
procedure Ini_SetInt(const Section, Name: String; const Value: Integer);
function Ini_GetInt(const Section, Name: String; const DefVal: Integer = 0): Integer;
procedure Ini_SetFloat(const Section, Name: String; const Value: Single);
function Ini_GetFloat(const Section, Name: String; const DefVal: Single): Single;
procedure Ini_SetString(const Section, Name, Value: String);
function Ini_GetString(const Section, Name, DefVal: String): String;
procedure Random_Seed(const Seed: Integer = 0);
function Random_Int(const Min, Max: Integer): Integer;
function Random_Float(const Min, Max: Single): Single;
function Timer_GetTime: Single;
function Timer_GetDelta: Single;
function Timer_GetFPS: Integer;
function Effect_Load(const Data: Pointer; const Size: Longword): IEffect; overload;
function Effect_Load(const Filename: String): IEffect; overload;
function Effect_Play(const Eff: IEffect): IChannel;
function Effect_PlayEx(const Eff: IEffect; const Volume: Integer = 100;
const Pan: Integer = 0; const Pitch: Single = 1.0; const Loop: Boolean = False): IChannel;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -