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 OpenWindowsCount: integer; |
|
function ProcessMessage(WaitForMessage, WaitToLimitFPS: boolean): boolean; |
|
function ProcessAllMessages: boolean; |
|
procedure Terminate; override; |
|
procedure Run; |
|
function BackendName: String; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
procedure HandleException(Sender: TObject); override; |
|
procedure ParseStandardParameters; |
|
function ParseStandardParametersHelp: String; |
|
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 MainWindow: TCastleWindow read FMainWindow write SetMainWindow; |
|
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; |
|
This item has no description. |
VideoResizeHeight: Integer; |
|
This item has no description. |
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; |
|
This item has no description. |
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 See example code Simple example usage: unit GameChangeVideoResolution; interface var // TODO: Allow user to configure it somehow UserWantsToChangeScreenResolution: Boolean = true; { Change screen resolution, if desired by UserWantsToChangeScreenResolution. } procedure ChangeResolution; implementation uses CastleWindow, CastleLog, CastleConfig; procedure ChangeResolution; begin if UserWantsToChangeScreenResolution then begin Application.VideoResize := true; // TODO: Allow user to choose the desired resolution Application.VideoResizeWidth := 1024; Application.VideoResizeHeight := 768; if not Application.TryVideoChange then WritelnWarning('Cannot change screen resolution, continuing with current settings'); end; end; initialization UserWantsToChangeScreenResolution := UserConfig.GetValue('video/change_resolution', false); ChangeResolution; finalization Application.VideoReset; end.
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; |
|
This item has no description. |
function ScreenWidth: integer; |
|
This item has no description. |
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 methods of TCastleUserInterface instances (including TCastleView) are called. For simple programs calling the Run method is usually the best solution, Run just calls while not SomethingHappened do Application.ProcessMessage(...);
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 Terminate; override; |
|
This item has no description. |
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.Terminate) 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; |
|
This item has no description. |
constructor Create(AOwner: TComponent); override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
procedure HandleException(Sender: TObject); override; |
|
This item has no description. |
procedure ParseStandardParameters; |
|
Parse some command-line options and remove them from Parameters list. These are standard command-line parameters of Castle Game Engine programs. See TCastleWindow.ParseParameters for more options specific to each window.
Moreover this also handles parameters from TCastleWindow.ParseParameters, if MainWindow is set already. But note that our templates do not set MainWindow so early. We recommend to explicitly set window size / Window.FullScreen from code and call TCastleWindow.ParseParameters right after, to allow user to override. Moreover this also handles parameters from TSoundEngine.ParseParameters. |
function ParseStandardParametersHelp: String; |
|
This item has no description. |
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; |
|
This item has no description. |
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 TCastleUserInterface.GLContextOpen on all UIs). 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; |
|
This item has no description. |
property MainWindow: TCastleWindow read FMainWindow write SetMainWindow; |
|
Used on platforms that can only show a single window (TCastleWindow) at a time, like mobile or web applications. In other exceptional situations when we need a single window (e.g. to display CGE uncaught exception) we may also use this window, if set (otherwise we may use the 1st currently open window). |
Generated by PasDoc 0.16.0-snapshot.