summaryrefslogtreecommitdiff
path: root/source/logic/AllegroWrappers.h
blob: 851f219d16e7141db83bec166180c7a793f90129 (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
#ifndef ALLEGRO_WRAPPERS_H
#define ALLEGRO_WRAPPERS_H

#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>

/**
* @brief Exception to be thrown if any component of Allegro fails to install at runtime.
*
* @author Justin Wernick
* @author David Schneider
*/
class InstallFailure {};

/**
* @brief Class ensures that Allegro is initialized and uninstalled when appropriate.
*
* Any classes that use Allegro should include this class as a data member.
*
* @author Justin Wernick
* @author David Schneider
*/
class AllegroInit
{
    public:
        /**
        * @brief Constructor calls al_init() if it is the first instance.
        */
        AllegroInit();
        /**
        * @brief Copy constructor, implemented to be included in instance count.
        */
        AllegroInit(const AllegroInit& ref);
        /**
        * @brief Destructor calls al_uninstall_system() if it is the last instant.
        */

        //assignment operator provided by compiler. _initCount does not need incrementing on assignment,
        //because assignment does not make a new instance, just changes one.

        ~AllegroInit();
    private:
        static int _initCount; ///< Count of the current number of initialised AllegroInit objects.
};

/**
* @brief Class ensures that Allegro's keyboard is installed and uninstalled when appropriate.
*
* Any classes that use the keyboard for input should include this class as a data member.
* This class includes AllegroInit, so both of them do not need to be included.
*
* @author Justin Wernick
* @author David Schneider
*/
class AllegroKeyboardInit
{
    public:
        /**
        * @brief Constructor calls al_install_keyboard() if it is the first instance.
        */
        AllegroKeyboardInit();
        /**
        * @brief Copy constructor, implemented to be included in instance count.
        */
        AllegroKeyboardInit(const AllegroKeyboardInit& ref);
        /**
        * @brief Destructor calls al_uninstall_keyboard() if it is the last instant.
        */
        ~AllegroKeyboardInit();
    private:
        static int _initCount; ///< Count of the current number of initialised AllegroKeyboardInit objects.
        AllegroInit _allegro; ///< Depends on Allegro being initialised.

        //assignment operator provided by compiler. _initCount does not need incrementing on assignment,
        //because assignment does not make a new instance, just changes one.
};

/**
* @brief Class ensures that Allegro's primitive and text drawing is installed and uninstalled when appropriate.
*
* Any classes that draw primitives should include this class as a data member.
* This class includes AllegroInit, so both of them do not need to be included.
*
* @author Justin Wernick
* @author David Schneider
*/
class AllegroDrawingInit
{
    public:
        /**
        * @brief Constructor calls al_init_primitives_addon(), al_init_font_addon(), and al_init_ttf_addon() if it is the first instance.
        */
        AllegroDrawingInit();
        /**
        * @brief Copy constructor, implemented to be included in instance count.
        */
        AllegroDrawingInit(const AllegroDrawingInit& ref);
        /**
        * @brief Destructor calls al_shutdown_primitives_addon(), al_shutdown_font_addon(), and al_shutdown_ttf_addon() if it is the last instant.
        */
        ~AllegroDrawingInit();
    private:
        static int _initCount;
        AllegroInit _allegro;

        //assignment operator provided by compiler. _initCount does not need incrementing on assignment,
        //because assignment does not make a new instance, just changes one.
};

#endif