| 1 |
{ |
| 2 |
Copyright 2023-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. |
| 17 |
This unit is cross-platform. |
| 18 |
It will be used by the platform-specific program or library file. } |
| 19 |
unit GameInitialize; |
| 20 |
|
| 21 |
interface |
| 22 |
|
| 23 |
uses CastleWindow; |
| 24 |
|
| 25 |
var |
| 26 |
Window1, Window2: TCastleWindow; |
| 27 |
|
| 28 |
implementation |
| 29 |
|
| 30 |
uses SysUtils, |
| 31 |
CastleLog, CastleUIControls, CastleViewport |
| 32 |
{$region 'Castle Initialization Uses'} |
| 33 |
// The content here may be automatically updated by CGE editor. |
| 34 |
, GameViewMain |
| 35 |
{$endregion 'Castle Initialization Uses'}; |
| 36 |
|
| 37 |
{ One-time initialization of resources. } |
| 38 |
procedure ApplicationInitialize; |
| 39 |
|
| 40 |
{ Adjust ViewportToChange.Items, changing also camera parent. |
| 41 |
See https://castle-engine.io/multiple_viewports_to_display_one_world } |
| 42 |
procedure ShareWorld(const TargetViewport, ViewportToChange: TCastleViewport); |
| 43 |
begin |
| 44 |
ViewportToChange.Items.Remove(ViewportToChange.Camera); |
| 45 |
ViewportToChange.Items := TargetViewport.Items; |
| 46 |
ViewportToChange.Items.Add(ViewportToChange.Camera); |
| 47 |
end; |
| 48 |
|
| 49 |
begin |
| 50 |
{ Adjust container settings for a scalable UI (adjusts to any window size in a smart way). } |
| 51 |
Window1.Container.LoadSettings('castle-data:/CastleSettings.xml'); |
| 52 |
Window2.Container.LoadSettings('castle-data:/CastleSettings.xml'); |
| 53 |
|
| 54 |
{ Create views (see https://castle-engine.io/views ). } |
| 55 |
ViewMainInWindow1 := TViewMain.Create(Application); |
| 56 |
ViewMainInWindow2 := TViewMain.Create(Application); |
| 57 |
|
| 58 |
Window1.Container.View := ViewMainInWindow1; |
| 59 |
Window2.Container.View := ViewMainInWindow2; |
| 60 |
|
| 61 |
{ Make all 4 viewports refer to one world, |
| 62 |
from ViewMainInWindow1.ViewportTop.Items } |
| 63 |
ShareWorld(ViewMainInWindow1.ViewportTop, ViewMainInWindow1.ViewportBottom); |
| 64 |
ShareWorld(ViewMainInWindow1.ViewportTop, ViewMainInWindow2.ViewportTop); |
| 65 |
ShareWorld(ViewMainInWindow1.ViewportTop, ViewMainInWindow2.ViewportBottom); |
| 66 |
end; |
| 67 |
|
| 68 |
initialization |
| 69 |
{ This initialization section configures: |
| 70 |
- Application.OnInitialize |
| 71 |
- Application.MainWindow |
| 72 |
- determines initial window size |
| 73 |
|
| 74 |
You should not need to do anything more in this initialization section. |
| 75 |
Most of your actual application initialization (in particular, any file reading) |
| 76 |
should happen inside ApplicationInitialize. } |
| 77 |
|
| 78 |
Application.OnInitialize := @ApplicationInitialize; |
| 79 |
|
| 80 |
Window1 := TCastleWindow.Create(Application); |
| 81 |
Window2 := TCastleWindow.Create(Application); |
| 82 |
Application.MainWindow := Window1; |
| 83 |
|
| 84 |
Window1.Left := Application.ScreenWidth div 9; |
| 85 |
Window1.Width := Application.ScreenWidth div 3; |
| 86 |
|
| 87 |
Window2.Left := Application.ScreenWidth - Application.ScreenWidth div 9 - Application.ScreenWidth div 3; |
| 88 |
Window2.Width := Application.ScreenWidth div 3; |
| 89 |
|
| 90 |
{ Open Window2 now. Window1 will be open by main application file. |
| 91 |
This way of opening many windows is nice to keep auto-generated |
| 92 |
main application file (DPR). |
| 93 |
You can also easily ifdef-out the creation of Window2 |
| 94 |
on systems that don't support multiple windows, |
| 95 |
so on Android or iOS will have only Window1. |
| 96 |
|
| 97 |
Alternative approach would be to modify DPR to open all windows |
| 98 |
in a desired order, like |
| 99 |
|
| 100 |
Window1.Open; |
| 101 |
Window2.Open; |
| 102 |
Application.Run; |
| 103 |
|
| 104 |
instead of Window1.OpenAndRun. |
| 105 |
This would be more explicit, and it makes sense if you really |
| 106 |
target only desktops (where multiple windows are supported). |
| 107 |
} |
| 108 |
Window2.Open; |
| 109 |
|
| 110 |
{ Handle command-line parameters like --fullscreen and --window. |
| 111 |
By doing this last, you let user to override your fullscreen / mode setup. } |
| 112 |
Application.MainWindow.ParseParameters; |
| 113 |
end. |