summaryrefslogtreecommitdiffstats
path: root/game/code/main/game.h
blob: f090ce8007d6bff2350abc38bacff43be874e90a (plain) (blame)
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
//=============================================================================
// Copyright (C) 2002 Radical Entertainment Ltd.  All rights reserved.
//
// File:        game.h
//
// Description: The game loop
//
// History:     + Stolen and cleaned up from Svxy -- Darwin Chau
//
//=============================================================================

#ifndef GAME_H
#define GAME_H

//========================================
// Forward References
//========================================
class Platform;
struct IRadTimerList;
class GameFlow;
class RenderFlow;

#include <radtime.hpp>

class DemoProfiler
{
public:
    DemoProfiler(unsigned maxFrames);

    void AddChannel(unsigned c, const char* name);

    void NextFrame();

    void Start(unsigned c);  // start timing channel c
    void Stop(unsigned c);   // stop timing channel c
    void Set(unsigned c, unsigned val);  // set sample value for channel c
    unsigned GetSample(unsigned c);
    unsigned GetCurrentFrame();
    void Accumulate(unsigned c, unsigned val);  // add value to sample for channel c
    void Dump();  // print out all samples

    void StartRecording();
    bool IsRecording();
    enum AlertStatus { PROFILER_ALERT_GREEN, PROFILER_ALERT_YELLOW, PROFILER_ALERT_RED };
    AlertStatus GetAlertStatus();

private:    
    enum { MAX_CHANNEL = 64 };

    struct Channel
    {
        char name[255];
        unsigned* samples;
        radTime64 t0;
    };

    bool recording;
    unsigned maxFrames;

    Channel* channel[MAX_CHANNEL];
    unsigned nChannel;
    unsigned currentFrame;

    AlertStatus alertStatus;
    unsigned numFramesBelow_20;
    unsigned numFramesBetween_20_30;
    unsigned numFramesBetween_30_40;
    unsigned numFramesAbove_40;
};

extern DemoProfiler g_DemoProfiler;

//=============================================================================
//
// Synopsis:    The game loop
//
//=============================================================================
class Game
{
    public:

        // Static Methods (for creating and getting an instance of the game)
        static Game* CreateInstance( Platform* platform );
        static void  DestroyInstance();
        static Game* GetInstance();
        
        Platform* GetPlatform();


        // Game Flow Public Methods
        void Initialize();
        void Terminate();

        void Run();
        void Stop();
        
        IRadTimerList* GetTimerList() { return mpTimerList; }

        unsigned int GetFrameCount() const { return mFrameCount; };

        unsigned int GetDemoCount() const { return mDemoCount; };
        void IncrementDemoCount() { ++mDemoCount; };
        void SetTime( unsigned int timeMS ) { mTimeMS = timeMS; };
        unsigned int GetTime() { return mTimeMS; };

        static unsigned GetRandomSeed ();

    private:

        // Constructors, Destructors, and Operators
        Game( Platform* platform );
        virtual ~Game();

        // Unused Constructors, Destructors, and Operators
        Game();
        Game( const Game& aGame );
        Game& operator=( const Game& aGame );

        // Static Singleton Attribute
        static Game*    spInstance;

        // Private Attributes
        Platform*       mpPlatform;
        IRadTimerList*  mpTimerList;
        GameFlow*       mpGameFlow;
        RenderFlow*     mpRenderFlow;
        
        unsigned int mFrameCount;

        bool        mExitNow;

        unsigned int mDemoCount;
        unsigned int mTimeMS;
};

inline Game* GetGame() { return( Game::GetInstance() ); }

#endif // GAME_H