Removed dbc and replaced with plain asserts everywhere.
This commit is contained in:
parent
767147c301
commit
adc192c6dc
17 changed files with 69 additions and 185 deletions
|
|
@ -1,11 +1,12 @@
|
|||
#include "guecs/ui.hpp"
|
||||
#include "guecs/sfml/backend.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace guecs {
|
||||
using std::make_shared;
|
||||
|
||||
void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
||||
dbc::check(font_ptr != nullptr, "you failed to initialize this WideText");
|
||||
assert(font_ptr != nullptr && "you failed to initialize this WideText");
|
||||
if(font == nullptr) font = font_ptr;
|
||||
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size);
|
||||
text->setFillColor(color);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "guecs/sfml/config.hpp"
|
||||
#include "guecs/dbc.hpp"
|
||||
#include <fmt/core.h>
|
||||
|
||||
using nlohmann::json;
|
||||
|
|
@ -11,13 +10,14 @@ Config::Config(const std::string src_path) : $src_path(src_path) {
|
|||
}
|
||||
|
||||
json &Config::operator[](const std::string &key) {
|
||||
dbc::check($config.contains(key), fmt::format("ERROR in config, key {} doesn't exist.", key));
|
||||
assert($config.contains(key) &&
|
||||
"ERROR in config, key doesn't exist.");
|
||||
return $config[key];
|
||||
}
|
||||
|
||||
std::wstring Config::wstring(const std::string main_key, const std::string sub_key) {
|
||||
dbc::check($config.contains(main_key), fmt::format("ERROR wstring main/key in config, main_key {} doesn't exist.", main_key));
|
||||
dbc::check($config[main_key].contains(sub_key), fmt::format("ERROR wstring in config, main_key/key {}/{} doesn't exist.", main_key, sub_key));
|
||||
assert($config.contains(main_key) && "ERROR wstring main/key in config, main_key doesn't exist.");
|
||||
assert($config[main_key].contains(sub_key) && "ERROR wstring in config, main_key/key doesn't exist.");
|
||||
|
||||
const std::string& str_val = $config[main_key][sub_key];
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "guecs/sfml/shaders.hpp"
|
||||
#include "guecs/sfml/config.hpp"
|
||||
#include "guecs/dbc.hpp"
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <memory>
|
||||
|
|
@ -30,21 +29,21 @@ namespace shaders {
|
|||
|
||||
void init() {
|
||||
if(!INITIALIZED) {
|
||||
dbc::check(sf::Shader::isAvailable(), "no shaders?!");
|
||||
assert(sf::Shader::isAvailable() && "no shaders?!");
|
||||
INITIALIZED = true;
|
||||
Config config("assets/shaders.json");
|
||||
bool good = load_shader("ERROR", config["ERROR"]);
|
||||
dbc::check(good, "Failed to load ERROR shader. Look in assets/shaders.json");
|
||||
assert(good && "Failed to load ERROR shader. Look in assets/shaders.json");
|
||||
|
||||
for(auto& [name, settings] : config.json().items()) {
|
||||
if(name == "ERROR") continue;
|
||||
|
||||
dbc::check(!SMGR.shaders.contains(name),
|
||||
fmt::format("shader name '{}' duplicated in assets/shaders.json", name));
|
||||
assert(!SMGR.shaders.contains(name) &&
|
||||
"shader name duplicated in assets/shaders.json");
|
||||
good = load_shader(name, settings);
|
||||
|
||||
if(!good) {
|
||||
dbc::log(fmt::format("failed to load shader {}", name));
|
||||
fmt::println("[SOUND] failed to load shader {}", name);
|
||||
SMGR.shaders.insert_or_assign(name, SMGR.shaders.at("ERROR"));
|
||||
}
|
||||
}
|
||||
|
|
@ -52,9 +51,9 @@ namespace shaders {
|
|||
}
|
||||
|
||||
std::shared_ptr<sf::Shader> get(const std::string& name) {
|
||||
dbc::check(INITIALIZED, "you forgot to shaders::init()");
|
||||
dbc::check(SMGR.shaders.contains(name),
|
||||
fmt::format("shader name '{}' not in assets/shaders.json", name));
|
||||
assert(INITIALIZED && "you forgot to shaders::init()");
|
||||
assert(SMGR.shaders.contains(name) &&
|
||||
"shader name not in assets/shaders.json");
|
||||
auto& rec = SMGR.shaders.at(name);
|
||||
return rec.ptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "guecs/sfml/sound.hpp"
|
||||
#include "guecs/sfml/config.hpp"
|
||||
#include "guecs/dbc.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include <cassert>
|
||||
|
||||
namespace sound {
|
||||
static SoundManager SMGR;
|
||||
|
|
@ -13,14 +13,13 @@ namespace sound {
|
|||
namespace fs = std::filesystem;
|
||||
|
||||
SoundPair& get_sound_pair(const std::string& name) {
|
||||
dbc::check(initialized, "You need to call sound::init() first");
|
||||
assert(initialized && "You need to call sound::init() first");
|
||||
|
||||
if(SMGR.sounds.contains(name)) {
|
||||
// get the sound from the sound map
|
||||
return SMGR.sounds.at(name);
|
||||
} else {
|
||||
dbc::log(fmt::format("Attempted to stop {} sound but not available.",
|
||||
name));
|
||||
fmt::println("[SOUND] Attempted to stop {} sound but not available.", name);
|
||||
return SMGR.sounds.at("blank");
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +37,7 @@ namespace sound {
|
|||
}
|
||||
|
||||
void load(const std::string& name, const std::string& sound_path) {
|
||||
dbc::check(fs::exists(sound_path), fmt::format("sound file {} does not exist", sound_path));
|
||||
assert(fs::exists(sound_path) && "sound file does not exist");
|
||||
|
||||
// create the buffer and keep in the buffer map
|
||||
auto buffer = make_shared<sf::SoundBuffer>(sound_path);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#include "guecs/dbc.hpp"
|
||||
#include "guecs/sfml/textures.hpp"
|
||||
#include "guecs/sfml/config.hpp"
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
|
|
@ -36,16 +35,16 @@ namespace textures {
|
|||
}
|
||||
|
||||
SpriteTexture get(const std::string& name) {
|
||||
dbc::check(initialized, "you forgot to call textures::init()");
|
||||
dbc::check(TMGR.sprite_textures.contains(name),
|
||||
fmt::format("!!!!! texture pack does not contain {} sprite", name));
|
||||
assert(initialized && "you forgot to call textures::init()");
|
||||
assert(TMGR.sprite_textures.contains(name) &&
|
||||
"!!!!! texture pack does not contain sprite");
|
||||
|
||||
auto result = TMGR.sprite_textures.at(name);
|
||||
|
||||
dbc::check(result.sprite != nullptr,
|
||||
fmt::format("bad sprite from textures::get named {}", name));
|
||||
dbc::check(result.texture != nullptr,
|
||||
fmt::format("bad texture from textures::get named {}", name));
|
||||
assert(result.sprite != nullptr &&
|
||||
"bad sprite from textures::get named can't be null");
|
||||
assert(result.texture != nullptr &&
|
||||
"bad texture from textures::get named can't be null");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -53,7 +52,7 @@ namespace textures {
|
|||
sf::Image load_image(const std::string& filename) {
|
||||
sf::Image texture;
|
||||
bool good = texture.loadFromFile(filename);
|
||||
dbc::check(good, fmt::format("failed to load {}", filename));
|
||||
assert(good && "failed to load image file");
|
||||
return texture;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue