summaryrefslogtreecommitdiffhomepage
path: root/Stars45/Game.h
blob: 37839061e02f54ceca34ab45cf157747bcb229a7 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    AUTHOR:       John DiCamillo

*/

#ifndef Game_h
#define Game_h

#include "Clock.h"
#include "Types.h"
#include "Screen.h"
#include "Video.h"
#include "VideoSettings.h"
#include "WndProc.h"

// +--------------------------------------------------------------------+

class Universe;
class Sound;
class SoundCard;
class Video;
class VideoFactory;
class Text;

// +--------------------------------------------------------------------+

class Game
{
public:
    static const char* TYPENAME() { return "Game"; }
    enum STATUS { OK, RUN, EXIT, INIT_FAILED, TOO_MANY };

    Game();
    virtual ~Game();

    //
    // MAIN GAME FUNCTIONALITY:
    //

    virtual bool      Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow);
    virtual int       Run();
    virtual void      Exit();
    virtual bool      OnPaint()      { return false;  }
    virtual bool      OnHelp()       { return false;  }

    virtual void      Activate(bool f);
    virtual void      Pause(bool f);
    int               Status() const { return status; }

    const RenderStats& GetPolyStats() { return stats;  }

    //
    // GENERAL GAME CLASS UTILITY METHODS:
    //

    static Game*       GetInstance();

    Clock*            GetClock();
    DWORD             Frame();

    void              SetMaxFrameLength(double seconds) { max_frame_length = seconds; }
    double            GetMaxFrameLength()               { return max_frame_length;    }

    bool              Active()       { return active;     }
    bool              Paused()       { return paused;     }
    bool              Server()       { return server;     }
    bool              ShowMouse()    { return show_mouse; }
    bool              IsWindowed();

    HINSTANCE         GetHINST();
    HWND              GetHWND();

    virtual bool      GameLoop();
    virtual void      UpdateWorld();
    virtual void      GameState();
    virtual void      UpdateScreen();
    virtual void      CollectStats();

    virtual bool      InitGame();
    virtual bool      InitVideo();
    virtual bool      ResizeVideo();
    virtual bool      ResetVideo();
    virtual bool      ToggleFullscreen();
    virtual bool      AdjustWindowForChange();

    virtual void      ShowStats();

protected:
    friend  LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM uParam, LPARAM lParam);

    Universe*         world;
    VideoFactory*     video_factory;
    Video*            video;
    VideoSettings*    video_settings;
    SoundCard*        soundcard;
    Screen*           screen;

    RenderStats       stats;
    DWORD             totaltime;

    HINSTANCE         hInst;
    HWND              hwnd;
    HMENU             hmenu;
    DWORD             winstyle;

    char*             app_name;
    char*             title_text;
    char*             palette_name;

    // Internal variables for the state of the app
    bool              is_windowed;
    bool              is_active;
    bool              is_device_lost;
    bool              is_minimized;
    bool              is_maximized;
    bool              ignore_size_change;
    bool              is_device_initialized;
    bool              is_device_restored;
    DWORD             window_style;        // Saved window style for mode switches
    RECT              bounds_rect;         // Saved window bounds for mode switches
    RECT              client_rect;         // Saved client area size for mode switches

    Clock             clock;

    int               status;
    int               exit_code;

    bool              active;
    bool              paused;
    bool              server;
    bool              show_mouse;
    DWORD             frame_number;

    double            max_frame_length;
};

// +--------------------------------------------------------------------+

#endif  // Game_h