| 1 |
{ |
| 2 |
Copyright 2019-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Game initialization and logic. } |
| 17 |
unit GameInitialize; |
| 18 |
|
| 19 |
interface |
| 20 |
|
| 21 |
implementation |
| 22 |
|
| 23 |
uses SysUtils, |
| 24 |
CastleWindow, CastleControls, CastleLog, CastleSoundEngine, |
| 25 |
CastleFilesUtils, CastleKeysMouse, CastleColors, CastleTimeUtils, |
| 26 |
CastleUIControls, CastleApplicationProperties |
| 27 |
{$region 'Castle Initialization Uses'} |
| 28 |
// The content here may be automatically updated by CGE editor. |
| 29 |
, GameViewMain |
| 30 |
{$endregion 'Castle Initialization Uses'}; |
| 31 |
|
| 32 |
var |
| 33 |
Window: TCastleWindow; |
| 34 |
|
| 35 |
{ One-time initialization of resources. } |
| 36 |
procedure ApplicationInitialize; |
| 37 |
begin |
| 38 |
{ Adjust container settings for a scalable UI (adjusts to any window size in a smart way). } |
| 39 |
Window.Container.LoadSettings('castle-data:/CastleSettings.xml'); |
| 40 |
|
| 41 |
{ Configure sound stuff } |
| 42 |
// Default is 16, but 8 is easier to display and test. |
| 43 |
SoundEngine.MaxAllocatedSources := 8; |
| 44 |
// Get infotmation in log when each sound is loaded. |
| 45 |
SoundEngine.LogSoundLoading := true; |
| 46 |
|
| 47 |
{ Create views (see https://castle-engine.io/views ). } |
| 48 |
{$region 'Castle View Creation'} |
| 49 |
// The content here may be automatically updated by CGE editor. |
| 50 |
ViewMain := TViewMain.Create(Application); |
| 51 |
{$endregion 'Castle View Creation'} |
| 52 |
|
| 53 |
Window.Container.View := ViewMain; |
| 54 |
end; |
| 55 |
|
| 56 |
initialization |
| 57 |
{ This initialization section configures: |
| 58 |
- Application.OnInitialize |
| 59 |
- Application.MainWindow |
| 60 |
- determines initial window size |
| 61 |
|
| 62 |
You should not need to do anything more in this initialization section. |
| 63 |
Most of your actual application initialization (in particular, any file reading) |
| 64 |
should happen inside ApplicationInitialize. } |
| 65 |
|
| 66 |
Application.OnInitialize := @ApplicationInitialize; |
| 67 |
|
| 68 |
Window := TCastleWindow.Create(Application); |
| 69 |
Application.MainWindow := Window; |
| 70 |
|
| 71 |
{ Optionally, adjust window fullscreen state and size at this point. |
| 72 |
Examples: |
| 73 |
|
| 74 |
Run fullscreen: |
| 75 |
|
| 76 |
Window.FullScreen := true; |
| 77 |
|
| 78 |
Run in a 600x400 window: |
| 79 |
|
| 80 |
Window.FullScreen := false; // default |
| 81 |
Window.Width := 600; |
| 82 |
Window.Height := 400; |
| 83 |
|
| 84 |
Run in a window taking 2/3 of screen (width and height): |
| 85 |
|
| 86 |
Window.FullScreen := false; // default |
| 87 |
Window.Width := Application.ScreenWidth * 2 div 3; |
| 88 |
Window.Height := Application.ScreenHeight * 2 div 3; |
| 89 |
|
| 90 |
Note that some platforms (like mobile) ignore these window sizes. |
| 91 |
} |
| 92 |
|
| 93 |
{ Handle command-line parameters like --fullscreen and --window. |
| 94 |
By doing this last, you let user to override your fullscreen / mode setup. } |
| 95 |
Window.ParseParameters; |
| 96 |
|
| 97 |
// Measure sound loading time. |
| 98 |
// The profile is automatically output to log at the end of ApplicationInitialize |
| 99 |
// (you could also output it explicitly by "WritelnLog(Profiler.Summary);", |
| 100 |
// and you can measure time explicitly by "Profiler" or "Timer" or "ProcessTimer". |
| 101 |
Profiler.Enabled := true; |
| 102 |
end. |