forked from ericlangedijk/Lemmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prog.App.pas
90 lines (70 loc) · 3.09 KB
/
Prog.App.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
unit Prog.App; // todo: rename to global or something
{$include lem_directives.inc}
{-------------------------------------------------------------------------------
The TApp class is in fact just a global var which is used by all
screens. not much more than a placeholder for the program / game logic.
But at creation it load the configuration file and the style is set.
-------------------------------------------------------------------------------}
interface
uses
SysUtils,
GR32,
Base.Utils,
Styles.Base,
Level.Base,
Prog.Types, Prog.Base, Prog.Config, Prog.Cache,
Game, Game.Rendering;
type
TApp = class sealed
public
Config : TConfig; // loaded in contructor
ReplayFileName : string; // determined by mainform
Style : TStyle; // constructed and initialized by mainform
StyleCache : TStyleCache; // constructed and initialized by mainform
GlobalGame : TLemmingGame; // constructed and initialized by mainform, prepared in preview screen
CurrentLevelInfo : TLevelLoadingInformation; // ref only, initizialized by mainform, changed all over the place
ReplayCurrent : Boolean;
Level : TLevel; // constructed by mainform, loaded in preview screen
GraphicSet : TGraphicSet; // constructed by mainform, loaded in preview screen
Renderer : TRenderer; // constructed by mainform, prepared in preview screen
TargetBitmap : TBitmap32; // this is a reference only and filled in the player screen
GameResult : TGameResultsRec; // this is retrieved from the game and copied by postview screen
NewStyleName : string; // can only be changed by options screen
NewSectionIndex : Integer; // quick and dirty
NewLevelIndex : Integer; // quick and dirty
constructor Create;
destructor Destroy; override;
end;
var
App: TApp; // this is instantiated by the main form
implementation
{ TGameParams }
constructor TApp.Create;
begin
inherited Create;
Config.Load;
Consts.Init(Config.PathToStyles, Config.PathToMusic);
Consts.SetStyleName(Config.StyleName);
NewStyleName := Consts.StyleName; // prevent change
CurrentDisplay.MonitorIndex := Config.Monitor;
NewSectionIndex := -1;
NewLevelIndex := -1;
Level := Tlevel.Create;
Renderer := TRenderer.Create;
GlobalGame := TLemmingGame.Create;
end;
destructor TApp.Destroy;
begin
Config.StyleName := Consts.StyleName;
Config.Monitor := CurrentDisplay.MonitorIndex;
Config.Save;
FreeAndNil(GlobalGame);
FreeAndNil(Renderer);
FreeAndNil(Level);
// we do not free the style, because it is pooled
FreeAndNil(GraphicSet);
FreeAndNil(StyleCache);
Consts.Done;
inherited Destroy;
end;
end.