Verified Commit 112ff322 authored by RobLoach's avatar RobLoach
Browse files

Move config to its own object

parent 3c02c554
......@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Removed global objects, use `love` namespace instead
- Before: `graphics.draw()`
- After: `love.graphics.draw()`
- Cleaned up global `love.config`
## 0.13.0 - 2017-12-20
### Added
......
......@@ -5,7 +5,7 @@ SOURCES_CXX += $(wildcard \
src/love/Types/Audio/*.cpp \
src/love/Types/Graphics/*.cpp \
src/love/Types/Input/*.cpp \
src/love/Types/System/*.cpp \
src/love/Types/Config/*.cpp \
test/*.cpp \
)
......
......@@ -31,6 +31,7 @@
* ## Modules
*
* - \link love::audio audio \endlink Provides an interface to output sound to the user's speakers.
* - \link love::config config \endlink Global ChaiLove configuration.
* - \link love::event event \endlink Manages events, like keypresses.
* - \link love::filesystem filesystem \endlink Provides an interface to the user's filesystem.
* - \link love::font font \endlink Allows you to work with fonts.
......@@ -51,14 +52,14 @@
#define SRC_CHAILOVE_H_
#define CHAILOVE_VERSION_MAJOR 0
#define CHAILOVE_VERSION_MINOR 13
#define CHAILOVE_VERSION_MINOR 14
#define CHAILOVE_VERSION_PATCH 0
#define CHAILOVE_VERSION_STRING "0.13.0"
#define CHAILOVE_VERSION_STRING "0.14.0"
#include "SDL.h"
#include "libretro.h"
#include "love/keyboard.h"
#include "love/Types/System/Config.h"
#include "love/config.h"
#include "love/script.h"
#include "love/filesystem.h"
#include "love/graphics.h"
......@@ -78,8 +79,6 @@
#include "test/Test.h"
#endif
using love::Types::System::Config;
class ChaiLove {
public:
static ChaiLove* getInstance();
......@@ -89,7 +88,7 @@ class ChaiLove {
static retro_input_state_t input_state_cb;
static retro_input_poll_t input_poll_cb;
Config config;
love::config config;
love::keyboard keyboard;
love::script* script;
love::filesystem filesystem;
......
#ifndef SRC_LOVE_TYPES_CONFIG_MODULECONFIG_H_
#define SRC_LOVE_TYPES_CONFIG_MODULECONFIG_H_
namespace love {
namespace Types {
namespace Config {
/**
* @brief Allows enabling or disiabling modules during initialization.
*/
struct ModuleConfig {
/**
* @brief Enable or disable the sound module.
*/
bool sound = true;
};
} // namespace Config
} // namespace Types
} // namespace love
#endif // SRC_LOVE_TYPES_CONFIG_MODULECONFIG_H_
#ifndef SRC_LOVE_TYPES_CONFIG_WINDOWCONFIG_H_
#define SRC_LOVE_TYPES_CONFIG_WINDOWCONFIG_H_
#include <string>
namespace love {
namespace Types {
namespace Config {
/**
* @brief Configuration for how the application is set up.
*/
struct WindowConfig {
/**
* @brief The width of the screen.
*/
int width = 800;
/**
* @brief The height of the screen.
*/
int height = 600;
/**
* @brief The number of bits used to represent each pixel in a surface.
*/
int bbp = 32;
/**
* @brief The name of the application. Defaults to "ChaiLove".
*/
std::string title = "ChaiLove";
bool asyncblit = true;
bool hwsurface = true;
bool doublebuffering = true;
};
} // namespace Config
} // namespace Types
} // namespace love
#endif // SRC_LOVE_TYPES_CONFIG_WINDOWCONFIG_H_
#include "Config.h"
#include "../../../ChaiLove.h"
#include "config.h"
#include "../ChaiLove.h"
namespace love {
namespace Types {
namespace System {
Config::Config() {
config::config() {
options["alphablending"] = true;
options["highquality"] = true;
version = CHAILOVE_VERSION_STRING;
}
} // namespace System
} // namespace Types
} // namespace love
#ifndef SRC_LOVE_TYPES_SYSTEM_CONFIG_H_
#define SRC_LOVE_TYPES_SYSTEM_CONFIG_H_
#ifndef SRC_LOVE_CONFIG_H_
#define SRC_LOVE_CONFIG_H_
#include <string>
#include <map>
#include <string>
namespace love {
namespace Types {
namespace System {
#include "Types/Config/ModuleConfig.h"
#include "Types/Config/WindowConfig.h"
/**
* @brief Configuration for how the application is set up.
*/
struct windowConfig {
/**
* @brief The width of the screen.
*/
int width = 800;
/**
* @brief The height of the screen.
*/
int height = 600;
int bbp = 32;
/**
* @brief The name of the application. Defaults to "ChaiLove".
*/
std::string title = "ChaiLove";
bool asyncblit = true;
bool hwsurface = true;
bool doublebuffering = true;
};
using love::Types::Config::ModuleConfig;
using love::Types::Config::WindowConfig;
/**
* @brief Allows enabling or disiabling modules during initialization.
*/
struct moduleConfig {
/**
* @brief Enable or disable the sound module.
*/
bool sound = true;
};
namespace love {
/**
* @brief The configuration object for ChaiLove.
*/
class Config {
class config {
public:
Config();
config();
/**
* @brief The machine name of the project.
*/
......@@ -59,12 +32,12 @@ class Config {
/**
* @brief The window configuration.
*/
windowConfig window;
WindowConfig window;
/**
* @brief Enable or disable modules.
*/
moduleConfig modules;
ModuleConfig modules;
/**
* @brief Generic map of boolean configuration options.
......@@ -72,8 +45,6 @@ class Config {
std::map<std::string, bool> options;
};
} // namespace System
} // namespace Types
} // namespace love
#endif // SRC_LOVE_TYPES_SYSTEM_CONFIG_H_
#endif // SRC_LOVE_CONFIG_H_
......@@ -13,10 +13,9 @@ using love::Types::Graphics::Image;
using love::Types::Graphics::Font;
using love::Types::Graphics::Point;
using love::Types::Graphics::Color;
using love::Types::System::Config;
using love::Types::Input::Joystick;
using love::Types::System::windowConfig;
using love::Types::System::moduleConfig;
using love::Types::Config::WindowConfig;
using love::Types::Config::ModuleConfig;
using love::Types::Audio::SoundData;
using love::graphics;
......@@ -141,22 +140,22 @@ script::script(const std::string& file) {
chai.add(fun<int, Font, const std::string&>(&Font::getWidth), "getWidth");
// Config
chai.add(user_type<windowConfig>(), "windowConfig");
chai.add(fun(&windowConfig::width), "width");
chai.add(fun(&windowConfig::height), "height");
chai.add(fun(&windowConfig::bbp), "bbp");
chai.add(fun(&windowConfig::title), "title");
chai.add(fun(&windowConfig::asyncblit), "asyncblit");
chai.add(fun(&windowConfig::hwsurface), "hwsurface");
chai.add(fun(&windowConfig::doublebuffering), "doublebuffering");
chai.add(user_type<moduleConfig>(), "moduleConfig");
chai.add(fun(&moduleConfig::sound), "sound");
chai.add(user_type<Config>(), "Config");
chai.add(fun(&Config::identity), "identity");
chai.add(fun(&Config::version), "version");
chai.add(fun(&Config::window), "window");
chai.add(fun(&Config::modules), "modules");
chai.add(fun(&Config::options), "options");
chai.add(user_type<WindowConfig>(), "WindowConfig");
chai.add(fun(&WindowConfig::width), "width");
chai.add(fun(&WindowConfig::height), "height");
chai.add(fun(&WindowConfig::bbp), "bbp");
chai.add(fun(&WindowConfig::title), "title");
chai.add(fun(&WindowConfig::asyncblit), "asyncblit");
chai.add(fun(&WindowConfig::hwsurface), "hwsurface");
chai.add(fun(&WindowConfig::doublebuffering), "doublebuffering");
chai.add(user_type<ModuleConfig>(), "ModuleConfig");
chai.add(fun(&ModuleConfig::sound), "sound");
chai.add(user_type<config>(), "Config");
chai.add(fun(&config::identity), "identity");
chai.add(fun(&config::version), "version");
chai.add(fun(&config::window), "window");
chai.add(fun(&config::modules), "modules");
chai.add(fun(&config::options), "options");
// Joystick
chai.add(user_type<Joystick>(), "Joystick");
......@@ -335,7 +334,7 @@ script::script(const std::string& file) {
hasUpdate = false;
}
try {
chaiconf = chai.eval<std::function<void(Config&)> >("conf");
chaiconf = chai.eval<std::function<void(config&)> >("conf");
}
catch (const std::exception& e) {
std::cout << "[ChaiLove] [script] conf(t) " << e.what() << std::endl;
......@@ -414,7 +413,7 @@ script::script(const std::string& file) {
#endif
}
void script::conf(Config& t) {
void script::conf(config& t) {
#ifdef __HAVE_CHAISCRIPT__
if (hasconf) {
try {
......
......@@ -2,7 +2,7 @@
#define SRC_LOVE_SCRIPT_H_
#include <string>
#include "Types/System/Config.h"
#include "config.h"
#ifdef __HAVE_CHAISCRIPT__
#include <chaiscript/chaiscript.hpp>
......@@ -11,8 +11,6 @@
// #include <chaiscript/chaiscript_stdlib.hpp>
#endif
using love::Types::System::Config;
namespace love {
/**
......@@ -25,7 +23,7 @@ class script {
/**
* @brief Modify some configuration options.
*
* @param t The Config object to modify.
* @param t The config object to modify.
*
* ### Example
*
......@@ -36,7 +34,7 @@ class script {
* }
* @endcode
*/
void conf(Config& t);
void conf(config& t);
/**
* @brief This function is called exactly once at the beginning of the game.
......@@ -235,7 +233,7 @@ class script {
#ifdef __HAVE_CHAISCRIPT__
chaiscript::ChaiScript chai;
std::function<void()> chaiload;
std::function<void(Config&)> chaiconf;
std::function<void(config&)> chaiconf;
std::function<void(float)> chaiupdate;
std::function<void()> chaidraw;
std::function<void()> chaireset;
......
......@@ -3,15 +3,14 @@
#include <iostream>
#include "../ChaiLove.h"
#include "SDL.h"
#include "Types/System/Config.h"
#include "config.h"
using ::ChaiLove;
using love::Types::System::Config;
using std::string;
namespace love {
bool window::load(const Config& config) {
bool window::load(const config& conf) {
ChaiLove* app = ChaiLove::getInstance();
// Initialize SDL.
......@@ -27,18 +26,18 @@ bool window::load(const Config& config) {
// Build the Screen.
Uint32 flags;
if (config.window.hwsurface) {
if (conf.window.hwsurface) {
flags = SDL_HWSURFACE;
} else {
flags = SDL_SWSURFACE;
}
if (config.window.asyncblit) {
if (conf.window.asyncblit) {
flags |= SDL_ASYNCBLIT;
}
if (config.window.doublebuffering) {
if (conf.window.doublebuffering) {
flags |= SDL_DOUBLEBUF;
}
app->screen = SDL_SetVideoMode(config.window.width, config.window.height, config.window.bbp, flags);
app->screen = SDL_SetVideoMode(conf.window.width, conf.window.height, conf.window.bbp, flags);
if (app->screen == NULL) {
const char* errorChar = SDL_GetError();
std::string errString("");
......@@ -54,7 +53,7 @@ bool window::load(const Config& config) {
app->videoBuffer = (unsigned int *)app->screen->pixels;
// Set the title.
setTitle(config.window.title);
setTitle(conf.window.title);
return true;
}
......
......@@ -2,7 +2,7 @@
#define SRC_LOVE_WINDOW_H_
#include <string>
#include "Types/System/Config.h"
#include "config.h"
namespace love {
......@@ -11,7 +11,7 @@ namespace love {
*/
class window {
public:
bool load(const Types::System::Config& config);
bool load(const config& conf);
bool unload();
/**
......
......@@ -23,7 +23,7 @@ def load() {
throw(failure)
}
event.quit()
love.event.quit()
}
def draw() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment