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