Debian Codegraph @

examples/deprecated_to_upgrade/fixed_camera_game/code/gameinitialize.pas

raw
1 {
2 Copyright 2007-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 unit GameInitialize;
18
19 interface
20
21 implementation
22
23 uses SysUtils,
24 CastleScene, CastleControls, CastleLog, CastleWindow,
25 CastleFilesUtils, CastleSceneCore, CastleKeysMouse, CastleColors,
26 CastleUIControls, CastleApplicationProperties,
27 CastleGameNotifications, CastleVectors, CastleSoundEngine,
28 CastleTransform, CastleConfig,
29 GameSound, GameConfiguration, GameCreatures, GameLocations
30 {$region 'Castle Initialization Uses'}
31 // The content here may be automatically updated by CGE editor.
32 , GameViewIntro
33 , GameViewMainMenu
34 , GameViewPlay
35 {$endregion 'Castle Initialization Uses'};
36
37 var
38 Window: TCastleWindow;
39
40 { load / save user config ---------------------------------------------------- }
41
42 procedure LoadUserConfig;
43 begin
44 UserConfig.Load;
45 SoundEngine.Volume := UserConfig.GetFloat('sound/volume', TSoundEngine.DefaultVolume);
46 SoundEngine.LoopingChannel[0].Volume := UserConfig.GetFloat('sound/music/volume', TLoopingChannel.DefaultVolume);
47 end;
48
49 procedure SaveUserConfig;
50 begin
51 UserConfig.SetDeleteFloat('sound/volume',
52 SoundEngine.Volume, TSoundEngine.DefaultVolume);
53 UserConfig.SetDeleteFloat('sound/music/volume',
54 SoundEngine.LoopingChannel[0].Volume, TLoopingChannel.DefaultVolume);
55 UserConfig.Save;
56 end;
57
58 { routines ------------------------------------------------------------------- }
59
60 { One-time initialization of resources. }
61 procedure ApplicationInitialize;
62 begin
63 { Adjust container settings for a scalable UI (adjusts to any window size in a smart way). }
64 Window.Container.LoadSettings('castle-data:/CastleSettings.xml');
65 Window.Container.BackgroundColor := Black;
66
67 { configure Notifications }
68 Notifications.MaxMessages := 4;
69 Notifications.Color := Vector4(0.8, 0.8, 0.8, 1.0);
70
71 LoadUserConfig;
72 InitializeSound;
73
74 { load game configuration }
75 GameConfig := TCastleConfig.Create(nil);
76 GameConfig.URL := 'castle-data:/game.xml';
77 CreatureKinds := TCreatureKindList.Create;
78 Locations := TLocationList.Create;
79
80 { Create views (see https://castle-engine.io/views ). }
81 {$region 'Castle View Creation'}
82 // The content here may be automatically updated by CGE editor.
83 ViewIntro := TViewIntro.Create(Application);
84 ViewMainMenu := TViewMainMenu.Create(Application);
85 ViewPlay := TViewPlay.Create(Application);
86 {$endregion 'Castle View Creation'}
87
88 Window.Container.View := ViewIntro;
89 end;
90
91 initialization
92 { This initialization section configures:
93 - Application.OnInitialize
94 - Application.MainWindow
95 - determines initial window size
96
97 You should not need to do anything more in this initialization section.
98 Most of your actual application initialization (in particular, any file reading)
99 should happen inside ApplicationInitialize. }
100
101 Application.OnInitialize := @ApplicationInitialize;
102
103 Window := TCastleWindow.Create(Application);
104 Application.MainWindow := Window;
105
106 { Optionally, adjust window fullscreen state and size at this point.
107 Examples:
108
109 Run fullscreen:
110
111 Window.FullScreen := true;
112
113 Run in a 600x400 window:
114
115 Window.FullScreen := false; // default
116 Window.Width := 600;
117 Window.Height := 400;
118
119 Run in a window taking 2/3 of screen (width and height):
120
121 Window.FullScreen := false; // default
122 Window.Width := Application.ScreenWidth * 2 div 3;
123 Window.Height := Application.ScreenHeight * 2 div 3;
124
125 Note that some platforms (like mobile) ignore these window sizes.
126 }
127 Window.FpsShowOnCaption := true;
128 Window.FullScreen := true;
129
130 { Handle command-line parameters like --fullscreen and --window.
131 By doing this last, you let user to override your fullscreen / mode setup. }
132 Window.ParseParameters;
133 finalization
134 SaveUserConfig;
135 end.