summaryrefslogtreecommitdiffstats
path: root/game/code/cheats/cheatinputsystem.h
blob: e695ddfd920d76caa97ae6d4dcc84f4bdd155c60 (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
//===========================================================================
// Copyright (C) 2000 Radical Entertainment Ltd.  All rights reserved.
//
// Component:   CheatInputSystem
//
// Description: Interface for the CheatInputSystem class.
//
// Authors:     Tony Chu
//
// Revisions		Date			Author	    Revision
//                  2002/09/19      TChu        Created for SRR2
//
//===========================================================================

#ifndef CHEATINPUTSYSTEM_H
#define CHEATINPUTSYSTEM_H

//===========================================================================
// Nested Includes
//===========================================================================

#include <cheats/cheatinputs.h>
#include <cheats/cheats.h>

//===========================================================================
// Forward References
//===========================================================================

class CheatsDB;
class CheatInputHandler;

struct ICheatEnteredCallback
{
    virtual void OnCheatEntered( eCheatID cheatID, bool isEnabled ) = 0;
};

const unsigned int MAX_NUM_CHEAT_CALLBACKS = 32;

//===========================================================================
// Interface Definitions
//===========================================================================

class CheatInputSystem
{
public:
    // Static Methods for accessing this singleton.
    static CheatInputSystem* CreateInstance();
    static void DestroyInstance();
    static CheatInputSystem* GetInstance();

	CheatInputSystem();
    virtual ~CheatInputSystem();

    void Init();
    void Reset() { s_cheatsEnabled = 0; }

    void SetEnabled( bool enable );
    bool IsEnabled() const { return m_enabled; }

    void SetActivated( int controllerId, bool activated );
    bool IsActivated( int controllerId ) const;

    void SetCheatEnabled( eCheatID cheatID, bool enable );
    bool IsCheatEnabled( eCheatID cheatID ) const;

    void ReceiveInputs( eCheatInput* cheatInputs,
                        int numInputs = NUM_CHEAT_SEQUENCE_INPUTS );

    CheatsDB* GetCheatsDB() const { return m_cheatsDB; }

    void RegisterCallback( ICheatEnteredCallback* callback );
    void UnregisterCallback( ICheatEnteredCallback* callback );

private:
    //---------------------------------------------------------------------
    // Private Functions
    //---------------------------------------------------------------------

    // No copying or assignment. Declare but don't define.
    //
    CheatInputSystem( const CheatInputSystem& );
    CheatInputSystem& operator= ( const CheatInputSystem& );

    //---------------------------------------------------------------------
    // Private Data
    //---------------------------------------------------------------------

    // Pointer to the one and only instance of this singleton.
    static CheatInputSystem* spInstance;

    bool m_enabled;
    unsigned int m_activatedBitMask;

    static CHEATBITMASK s_cheatsEnabled;
    CheatsDB* m_cheatsDB;

    CheatInputHandler* m_cheatInputHandler;

    ICheatEnteredCallback* m_clientCallbacks[ MAX_NUM_CHEAT_CALLBACKS ];
    int m_numClientCallbacks;

};

// A little syntactic sugar for getting at this singleton.
inline CheatInputSystem* GetCheatInputSystem() { return( CheatInputSystem::GetInstance() ); }

#endif // CHEATINPUTSYSTEM_H