Dragonfly 4.19
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 bool m_networking; ///< True if networking enabled.
80 int m_quadtree_threshold; ///< Object threshold for quadtree split.
81 int m_quadtree_depth; ///< Max depth for quadtree.
82 int m_grid_width; ///< Grid width.
83 int m_grid_height; ///< Grid height.
84
85 public:
86 /// Get the singleton instance of the Config.
88
89 /// Get attributes.
90 std::string getConfig() const;
91 int getWindowHorizontalPixels() const;
92 int getWindowVerticalPixels() const;
93 int getWindowHorizontalChars() const;
94 int getWindowVerticalChars() const;
95 enum Color getWindowBackgroundColor() const;
96 int getWindowStyle() const;
97 int getFrameTime() const;
98 float getFontScale() const;
99 std::string getWindowTitle() const;
100 bool getShowMouse() const;
101 bool getHeadless() const;
102 std::string getFontFile() const;
103 std::string getLogFile() const;
104 int getRandomSeed() const;
105 bool getNetworking() const;
106 int getQuadtreeDepth() const;
107 int getQuadtreeThreshold() const;
108 int getGridWidth() const;
109 int getGridHeight() const;
110
111 /// Match key:value pair in global configuration, returning value.
112 /// Return empty string if no match.
113 std::string match(std::string find) const;
114
115 /// Set attributes.
116 void setConfig(std::string config);
117 void setWindowHorizontalPixels(int window_horizontal_pixels);
118 void setWindowVerticalPixels(int window_vertical_pixels);
119 void setWindowHorizontalChars(int window_horizontal_chars);
120 void setWindowVerticalChars(int window_vertical_chars);
121 void setWindowBackgroundColor(enum Color window_background_color);
122 void setWindowStyle(int window_style);
123 void setFrameTime(int frame_time);
124 void setFontScale(float font_scale);
125 void setWindowTitle(std::string window_title);
126 void setHeadless(bool headless=true);
127 void setShowMouse(bool show_mouse=true);
128 void setFontFile(std::string font_file);
129 void setLogFile(std::string logfile);
130 void setRandomSeed(int random_seed);
131 void setNetworking(bool networking);
132 void setQuadtreeDepth(int quadtree_thresh);
133 void setQuadtreeThreshold(int quadtree_depth);
134 void setGridWidth(int grid_width);
135 void setGridHeight(int grid_height);
136
137 // Write all parameters to logfile.
138 void writeToLog() const;
139
140 // Read config paramaters from CONFIG file into string.
141 // Format:
142 // Lines beginning with '#' are comments.
143 // Others are:
144 // "variable_1:value_1,"
145 // "variable_2:value_2,"
146 // Variable lines must end with comma (,)
147 std::string readConfig();
148
149 // Load config parameters from string.
150 // If str is empty, load from file.
151 void loadConfig(std::string str="");
152};
153
154} // end of namespace df
155#endif // __CONFIG_H__
Definition: Config.h:58
static Config & getInstance()
Get the singleton instance of the Config.
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:81
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:79
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:83
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:82
int m_quadtree_threshold
Object threshold for quadtree split.
Definition: Config.h:80
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