Dragonfly 4.20
A text-based game engine
Config.h
1//
2// Config.h - Global configuration parameters for Dragonfly
3//
4
5#ifndef __CONFIG_H__
6#define __CONFIG_H__
7
8// System includes.
9#include <string>
10
11// Engine includes.
12#include "Color.h"
13
14namespace df {
15
16////////////////////////////////////////////////////////////
17// Compiler warning for deprecated functions and classes
18//
19// Usage:
20//
21// class DF_DEPRECATED Class {
22// DF_DEPRECATED void method();
23// };
24//
25// DF_DEPRECATED void function();
26//
27
28#if defined(DF_NO_DEPRECATED_WARNINGS)
29
30 // User explicitly requests to disable deprecation warnings.
31 #define DF_DEPRECATED
32
33#elif defined(_MSC_VER)
34
35 // Microsoft C++ compiler
36 // Note: On newer MSVC versions, using deprecated functions causes
37 // compiler error. In order to trigger warning instead of error,
38 // compiler flag /sdl- (instead of /sdl) must be specified.
39#define DF_DEPRECATED __declspec(deprecated)
40
41#elif defined(__GNUC__)
42
43 // g++ and Clang
44#define DF_DEPRECATED __attribute__ ((deprecated))
45
46#else
47
48 // Other compilers are not supported, leave class or function as-is.
49 // Sometimes, #pragma directive works, otherwise users get
50 // a warning (no error!) for unrecognized #pragma.
51#pragma message("DF_DEPRECATED not supported by your compiler")
52
53#define DF_DEPRECATED
54
55#endif
56////////////////////////////////////////////////////////////
57
58class Config {
59
60 private:
61 Config(); ///< Private since a singleton.
62 Config(Config const&); ///< Don't allow copy.
63 void operator=(Config const&); ///< Don't allow assignment.
64 std::string m_config; ///< Aggregate string from config file.
65 int m_window_horizontal_pixels;///< Horizontal pixels in window.
66 int m_window_vertical_pixels; ///< Vertical pixels in window.
67 int m_window_horizontal_chars; ///< Horizontal ASCII spaces in window.
68 int m_window_vertical_chars; ///< Vertical ASCII spaces in window.
69 int m_window_style; ///< Style of window titlebar.
70 enum Color m_window_background_color; ///< Window background color.
71 int m_frame_time; ///< Target time for 1 game loop (in mlsecs).
72 float m_font_scale; ///< Font scale multiplier.
73 std::string m_window_title; ///< Title of window.
74 bool m_show_mouse; ///< True if should show mouse cursor.
75 bool m_headless; ///< True if run without graphics or input.
76 std::string m_font_file; ///< Filename for graphics fonts.
77 std::string m_logfile; ///< Filename for dragonfly log.
78 int m_random_seed; ///< Seed for random number generation.
79#ifndef NO_NETWORK
80 bool m_networking; ///< True if networking enabled.
81#endif
82 int m_quadtree_threshold; ///< Object threshold for quadtree split.
83 int m_quadtree_depth; ///< Max depth for quadtree.
84 int m_grid_width; ///< Grid width.
85 int m_grid_height; ///< Grid height.
86 bool m_signals; ///< True if catch signals.
87
88 public:
89 /// Get the singleton instance of the Config.
91
92 /// Get attributes.
93 std::string getConfig() const;
94 int getWindowHorizontalPixels() const;
95 int getWindowVerticalPixels() const;
96 int getWindowHorizontalChars() const;
97 int getWindowVerticalChars() const;
98 enum Color getWindowBackgroundColor() const;
99 int getWindowStyle() const;
100 int getFrameTime() const;
101 float getFontScale() const;
102 std::string getWindowTitle() const;
103 bool getShowMouse() const;
104 bool getHeadless() const;
105 std::string getFontFile() const;
106 std::string getLogFile() const;
107 int getRandomSeed() const;
108#ifndef NO_NETWORK
109 bool getNetworking() const;
110#endif
111 int getQuadtreeDepth() const;
112 int getQuadtreeThreshold() const;
113 int getGridWidth() const;
114 int getGridHeight() const;
115 bool getSignals() const;
116
117 /// Match key:value pair in global configuration, returning value.
118 /// Return empty string if no match.
119 std::string match(std::string find) const;
120
121 /// Set attributes.
122 void setConfig(std::string config);
123 void setWindowHorizontalPixels(int window_horizontal_pixels);
124 void setWindowVerticalPixels(int window_vertical_pixels);
125 void setWindowHorizontalChars(int window_horizontal_chars);
126 void setWindowVerticalChars(int window_vertical_chars);
127 void setWindowBackgroundColor(enum Color window_background_color);
128 void setWindowStyle(int window_style);
129 void setFrameTime(int frame_time);
130 void setFontScale(float font_scale);
131 void setWindowTitle(std::string window_title);
132 void setHeadless(bool headless=true);
133 void setShowMouse(bool show_mouse=true);
134 void setFontFile(std::string font_file);
135 void setLogFile(std::string logfile);
136 void setRandomSeed(int random_seed);
137#ifndef NO_NETWORK
138 void setNetworking(bool networking);
139#endif
140 void setQuadtreeDepth(int quadtree_thresh);
141 void setQuadtreeThreshold(int quadtree_depth);
142 void setGridWidth(int grid_width);
143 void setGridHeight(int grid_height);
144 void setSignals(bool signals);
145
146 // Write all parameters to logfile.
147 void writeToLog() const;
148
149 // Read config paramaters from CONFIG file into string.
150 // Format:
151 // Lines beginning with '#' are comments.
152 // Others are:
153 // "variable_1:value_1,"
154 // "variable_2:value_2,"
155 // Variable lines must end with comma (,)
156 std::string readConfig();
157
158 // Load config parameters from string.
159 // If str is empty, load from file.
160 void loadConfig(std::string str="");
161};
162
163} // end of namespace df
164#endif // __CONFIG_H__
Definition: Config.h:58
static Config & getInstance()
Get the singleton instance of the Config.
bool m_signals
True if catch signals.
Definition: Config.h:86
std::string m_font_file
Filename for graphics fonts.
Definition: Config.h:76
std::string getConfig() const
Get attributes.
Config()
Private since a singleton.
int m_quadtree_depth
Max depth for quadtree.
Definition: Config.h:83
int m_window_vertical_chars
Vertical ASCII spaces in window.
Definition: Config.h:68
Config(Config const &)
Don't allow copy.
float m_font_scale
Font scale multiplier.
Definition: Config.h:72
std::string m_config
Aggregate string from config file.
Definition: Config.h:64
bool m_networking
True if networking enabled.
Definition: Config.h:80
int m_random_seed
Seed for random number generation.
Definition: Config.h:78
int m_frame_time
Target time for 1 game loop (in mlsecs).
Definition: Config.h:71
int m_window_style
Style of window titlebar.
Definition: Config.h:69
int m_grid_height
Grid height.
Definition: Config.h:85
std::string m_window_title
Title of window.
Definition: Config.h:73
std::string match(std::string find) const
Match key:value pair in global configuration, returning value.
enum Color m_window_background_color
Window background color.
Definition: Config.h:70
int m_window_horizontal_pixels
Horizontal pixels in window.
Definition: Config.h:65
void operator=(Config const &)
Don't allow assignment.
int m_window_horizontal_chars
Horizontal ASCII spaces in window.
Definition: Config.h:67
int m_grid_width
Grid width.
Definition: Config.h:84
int m_quadtree_threshold
Object threshold for quadtree split.
Definition: Config.h:82
void setConfig(std::string config)
Set attributes.
int m_window_vertical_pixels
Vertical pixels in window.
Definition: Config.h:66
bool m_headless
True if run without graphics or input.
Definition: Config.h:75
bool m_show_mouse
True if should show mouse cursor.
Definition: Config.h:74
std::string m_logfile
Filename for dragonfly log.
Definition: Config.h:77
An animation for a sprite.
Definition: Animation.h:15
Color
Colors Dragonfly recognizes.
Definition: Color.h:11