Class TCastleApplication
Unit
Declaration
type TCastleApplication = class(TCustomApplication)
Description
Application, managing all open TCastleWindow (OpenGL windows). This tracks all open instances of TCastleWindow and implements message loop. It also handles some global tasks like managing the screen (changing current screen resolution and/or bit depth etc.)
The only instance of this class should be in Application variable. Don't create any other instances of class TCastleApplication
, there's no point in doing that.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCustomApplication
- TCastleApplication
Overview
Fields
VideoResize: boolean; |
|
VideoResizeWidth: integer; |
|
VideoResizeheight: integer; |
Methods
procedure DoLog(EventType: TEventType; const Msg: String); override; |
|
procedure DoRun; override; |
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override; |
|
function VideoSettingsDescribe: string; |
|
function TryVideoChange: boolean; |
|
procedure VideoChange(OnErrorWarnUserAndContinue: boolean); |
|
procedure VideoReset; |
|
function ScreenHeight: integer; |
|
function ScreenWidth: integer; |
|
function ScreenStatusBarScaledHeight: Cardinal; |
|
function OpenWindowsCount: integer; |
|
function ProcessMessage(WaitForMessage, WaitToLimitFPS: boolean): boolean; |
|
function ProcessAllMessages: boolean; |
|
procedure Quit; deprecated 'Use Terminate'; |
|
procedure Terminate; override; |
|
procedure Run; |
|
function BackendName: string; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
procedure HandleException(Sender: TObject); override; |
|
procedure ParseStandardParameters; |
|
function OpenGLES: Boolean; |
Properties
property XDisplayName: string read FXDisplayName write FXDisplayName; |
|
property VideoColorBits: integer read FVideoColorBits write FVideoColorBits default 0; |
|
property VideoFrequency: Cardinal read FVideoFrequency write FVideoFrequency default 0; |
|
property OpenWindows[Index:integer]: TCastleWindow read GetOpenWindows; |
|
property OnInitialize: TProcedure read FOnInitialize write FOnInitialize; |
|
property OnInitializeEvent: TNotifyEvent read FOnInitializeEvent write FOnInitializeEvent; |
|
property OnUpdate: TUpdateFunc read FOnUpdate write FOnUpdate; |
|
property OnIdle: TUpdateFunc read FOnUpdate write FOnUpdate; deprecated; |
|
property OnTimer: TProcedure read FOnTimer write FOnTimer; deprecated 'use TCastleTimer to perform periodic operations, or track time delay in OnUpdate'; |
|
property TimerMilisec: Cardinal read FTimerMilisec write FTimerMilisec default 1000; deprecated 'use TCastleTimer to perform periodic operations, or track time delay in OnUpdate'; |
|
property MainWindow: TCastleWindow read FMainWindow write SetMainWindow; |
|
property UserAgent: string read FUserAgent; |
|
property LimitFPS: Single read GetLimitFPS write SetLimitFPS; deprecated 'use ApplicationProperties.LimitFps'; |
|
property Version: string read GetVersion write SetVersion; deprecated 'use ApplicationProperties.Version'; |
|
property TouchDevice: boolean read GetTouchDevice write SetTouchDevice; deprecated 'use ApplicationProperties.TouchDevice'; |
Description
Fields
VideoResize: boolean; |
|
If |
VideoResizeWidth: integer; |
|
VideoResizeheight: integer; |
|
Methods
procedure DoLog(EventType: TEventType; const Msg: String); override; |
|
Override TCustomApplication to pass TCustomApplication.Log to CastleLog logger. |
procedure DoRun; override; |
|
Every backend must override this. TCustomApplication will automatically catch exceptions occuring inside |
procedure Notification(AComponent: TComponent; Operation: TOperation); override; |
|
function VideoSettingsDescribe: string; |
|
Describe the changes recorded in variables VideoXxx, used by VideoChange and TryVideoChange. This is a multiline string, each line is indented by 2 spaces, always ends with CastleUtils.NL. |
function TryVideoChange: boolean; |
|
Change the screen size, color bits and such, following the directions you set in VideoColorBits, VideoResize, VideoResizeWidth / VideoResizeHeight, and VideoFrequency variables. Returns TODO: Expose methods like EnumeratePossibleVideoConfigurations to predict what video settings are possible. TODO: Prefix "Video" for the family of these functions is not clear. Something like "Screen" would be better. |
procedure VideoChange(OnErrorWarnUserAndContinue: boolean); |
|
Change the screen size, color bits and such, following the directions you set in VideoColorBits, VideoResize, VideoResizeWidth / VideoResizeHeight, and VideoFrequency variables. This actually just calls TryVideoChange and checks the result. If not success: if OnErrorWarnUserAndContinue then we'll display a warning and continue. If not OnErrorWarnUserAndContinue then we'll raise an Exception. Exceptions raised
|
procedure VideoReset; |
|
Return default screen video mode. If you never called TryVideoChange (with success), then this does nothing. This is automatically called in Application.Destroy, so at finalization of this unit. This way your game nicely restores screen resolution for user. |
function ScreenHeight: integer; |
|
function ScreenWidth: integer; |
|
function ScreenStatusBarScaledHeight: Cardinal; |
|
function OpenWindowsCount: integer; |
|
List of all open windows. |
function ProcessMessage(WaitForMessage, WaitToLimitFPS: boolean): boolean; |
|
Process messages from the window system. You have to call this repeatedly to process key presses, mouse events, redraws and everything else. Messages are processed and appropriate window callbacks are called, like TCastleWindow.OnRender, TCastleWindow.OnUpdate, TCastleWindow.OnKeyPress and many others. For simple programs calling the Run method is usually the best solution, Run just calls while not SomethingHappened do Application.ProcessMessages(...);
This can used to implement routines that wait until a modal dialog box returns, like MessageOK or MessageYesNo. For comfort, returns while not SomethingHappened do if not Application.ProcessMessage(...) then Break;
Do not assume too much about message processing internals. For example, not all
Parameters
|
function ProcessAllMessages: boolean; |
|
Processes all pending messages. Do not wait for anything. Contrast this with ProcessMessage method, that processes only a single event. Or no event at all (when no events were pending and AllowSuspend =
So |
procedure Quit; deprecated 'Use Terminate'; |
|
Warning: this symbol is deprecated: Use Terminate |
procedure Terminate; override; |
|
procedure Run; |
|
Run the program using TCastleWindow, by doing the event loop. Think of it as just a shortcut for "while ProcessMessage do ;". Note that this does nothing if OpenWindowsCount = 0, that is there are no open windows. Besides the obvious reason (you didn't call TCastleWindow.Open on any window...) this may also happen if you called Close (or Application.Quit) from your window OnOpen / OnResize callback. In such case no event would probably reach our program, and user would have no chance to quit, so Run just refuses to work and exits immediately without any error. |
function BackendName: string; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
procedure HandleException(Sender: TObject); override; |
|
procedure ParseStandardParameters; |
|
Handle standard command-line parameters of Castle Game Engine programs. Handles:
|
function OpenGLES: Boolean; |
|
Are we using |
Properties
property XDisplayName: string read FXDisplayName write FXDisplayName; |
|
Set XDisplay name, this will be used for all TCastleWindow that will be subsequently initialized by TCastleWindow.Open. Note that this is exposed by GTK even for non-XWindows platforms, but I don't know what it does there. |
property VideoColorBits: integer read FVideoColorBits write FVideoColorBits default 0; |
|
Color bits per pixel that will be set by next VideoChange call, and that are tried to be used at TCastleWindow.Open. Zero means that system default is used. |
property VideoFrequency: Cardinal read FVideoFrequency write FVideoFrequency default 0; |
|
Video frequency to set in next VideoChange call. Leave as 0 to use system default. |
property OpenWindows[Index:integer]: TCastleWindow read GetOpenWindows; |
|
property OnInitialize: TProcedure read FOnInitialize write FOnInitialize; |
|
The application and CastleWindow backend is initialized. Called only once, at the very beginning of the game, when we're ready to load everything and the first OpenGL context is initialized (right before calling TCastleWindow.OnOpen). For targets like Android or iOS, you should not do anything (even reading files) before this callback occurs. Only when this occurs, we know that external process told us "Ok, you're ready". So you should put all the game initialization in an Application.OnInitialize callback. It will be automatically called by CastleWindow backend when we're really ready (actually, a little later — when OpenGL context is active, to allow you to display progress bars etc. when loading). |
property OnInitializeEvent: TNotifyEvent read FOnInitializeEvent write FOnInitializeEvent; |
|
property OnUpdate: TUpdateFunc read FOnUpdate write FOnUpdate; |
|
Continuously occuring event. See also
|
property OnIdle: TUpdateFunc read FOnUpdate write FOnUpdate; deprecated; |
|
Warning: this symbol is deprecated. Deprecated name for OnUpdate. |
property OnTimer: TProcedure read FOnTimer write FOnTimer; deprecated 'use TCastleTimer to perform periodic operations, or track time delay in OnUpdate'; |
|
Warning: this symbol is deprecated: use TCastleTimer to perform periodic operations, or track time delay in OnUpdate Event called approximately after each TimerMilisec miliseconds. The actual delay may be larger than TimerMilisec miliseconds, depending on how the program (and OS) is busy. You can of course change TimerMilisec (and |
property MainWindow: TCastleWindow read FMainWindow write SetMainWindow; |
|
Main window used for various purposes. On targets when only one TCastleWindow instance makes sense (like Android or iOS or web), set this to the reference of that window. It is also used by TWindowProgressInterface to display progress bar. |
property UserAgent: string read FUserAgent; |
|
User agent string, when running inside a browser. Right now never set (was used by NPAPI plugin, may be useful to new web target). |
property LimitFPS: Single read GetLimitFPS write SetLimitFPS; deprecated 'use ApplicationProperties.LimitFps'; |
|
Warning: this symbol is deprecated: use ApplicationProperties.LimitFps |
property Version: string read GetVersion write SetVersion; deprecated 'use ApplicationProperties.Version'; |
|
Warning: this symbol is deprecated: use ApplicationProperties.Version |
property TouchDevice: boolean read GetTouchDevice write SetTouchDevice; deprecated 'use ApplicationProperties.TouchDevice'; |
|
Warning: this symbol is deprecated: use ApplicationProperties.TouchDevice |
Generated by PasDoc 0.16.0.