Debian Codegraph @

tools/castle-editor/data/project_templates/3d_fps_game/files/code/gameinitialize.pas

raw
1 { Game initialization.
2 This unit is cross-platform.
3 It will be used by the platform-specific program or library file.
4
5 Feel free to use this code as a starting point for your own projects.
6 This template code is in public domain, unlike most other CGE code which
7 is covered by BSD or LGPL (see https://castle-engine.io/license). }
8 unit GameInitialize;
9
10 interface
11
12 implementation
13
14 uses SysUtils,
15 CastleWindow, CastleLog, CastleUIControls, CastleSoundEngine, GameSound
16 {$region 'Castle Initialization Uses'}
17 // The content here may be automatically updated by CGE editor.
18 , GameViewMenu
19 , GameViewPlay
20 {$endregion 'Castle Initialization Uses'};
21
22 var
23 Window: TCastleWindow;
24
25 { One-time initialization of resources. }
26 procedure ApplicationInitialize;
27 begin
28 { Adjust container settings for a scalable UI (adjusts to any window size in a smart way). }
29 Window.Container.LoadSettings('castle-data:/CastleSettings.xml');
30
31 { Create views (see https://castle-engine.io/views ). }
32 {$region 'Castle View Creation'}
33 // The content here may be automatically updated by CGE editor.
34 ViewPlay := TViewPlay.Create(Application);
35 ViewMenu := TViewMenu.Create(Application);
36 {$endregion 'Castle View Creation'}
37
38 Window.Container.View := ViewMenu;
39
40 InitializeSounds;
41 SoundEngine.LoopingChannel[0].Sound := NamedSound('MainMusic');
42 end;
43
44 initialization
45 { This initialization section configures:
46 - Application.OnInitialize
47 - Application.MainWindow
48 - determines initial window size
49
50 You should not need to do anything more in this initialization section.
51 Most of your actual application initialization (in particular, any file reading)
52 should happen inside ApplicationInitialize. }
53
54 Application.OnInitialize := @ApplicationInitialize;
55
56 Window := TCastleWindow.Create(Application);
57 Application.MainWindow := Window;
58
59 { Optionally, adjust window fullscreen state and size at this point.
60 Examples:
61
62 Run fullscreen:
63
64 Window.FullScreen := true;
65
66 Run in a 600x400 window:
67
68 Window.FullScreen := false; // default
69 Window.Width := 600;
70 Window.Height := 400;
71
72 Run in a window taking 2/3 of screen (width and height):
73
74 Window.FullScreen := false; // default
75 Window.Width := Application.ScreenWidth * 2 div 3;
76 Window.Height := Application.ScreenHeight * 2 div 3;
77
78 Note that some platforms (like mobile) ignore these window sizes.
79 }
80
81 { Handle command-line parameters like --fullscreen and --window.
82 By doing this last, you let user to override your fullscreen / mode setup. }
83 Window.ParseParameters;
84 end.