Debian Codegraph @

tools/castle-editor/data/project_templates/empty/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
16 {$region 'Castle Initialization Uses'}
17 // The content here may be automatically updated by CGE editor.
18 , GameView${MAIN_VIEW}
19 {$endregion 'Castle Initialization Uses'};
20
21 var
22 Window: TCastleWindow;
23
24 { One-time initialization of resources. }
25 procedure ApplicationInitialize;
26 begin
27 { Adjust container settings for a scalable UI (adjusts to any window size in a smart way). }
28 Window.Container.LoadSettings('castle-data:/CastleSettings.xml');
29
30 { Create views (see https://castle-engine.io/views ). }
31 {$region 'Castle View Creation'}
32 // The content here may be automatically updated by CGE editor.
33 View${MAIN_VIEW} := TView${MAIN_VIEW}.Create(Application);
34 {$endregion 'Castle View Creation'}
35
36 Window.Container.View := View${MAIN_VIEW};
37 end;
38
39 initialization
40 { This initialization section configures:
41 - Application.OnInitialize
42 - Application.MainWindow
43 - determines initial window size
44
45 You should not need to do anything more in this initialization section.
46 Most of your actual application initialization (in particular, any file reading)
47 should happen inside ApplicationInitialize. }
48
49 Application.OnInitialize := @ApplicationInitialize;
50
51 Window := TCastleWindow.Create(Application);
52 Application.MainWindow := Window;
53
54 { Optionally, adjust window fullscreen state and size at this point.
55 Examples:
56
57 Run fullscreen:
58
59 Window.FullScreen := true;
60
61 Run in a 600x400 window:
62
63 Window.FullScreen := false; // default
64 Window.Width := 600;
65 Window.Height := 400;
66
67 Run in a window taking 2/3 of screen (width and height):
68
69 Window.FullScreen := false; // default
70 Window.Width := Application.ScreenWidth * 2 div 3;
71 Window.Height := Application.ScreenHeight * 2 div 3;
72
73 Note that some platforms (like mobile) ignore these window sizes.
74 }
75
76 { Handle command-line parameters like --fullscreen and --window.
77 By doing this last, you let user to override your fullscreen / mode setup. }
78 Window.ParseParameters;
79 end.