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
|
@ -76,7 +76,7 @@ struct Calculator {
|
||||||
temp = left / right;
|
temp = left / right;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel("invalid op passed to op()");
|
assert(true && "invalid op passed to op()");
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.push_back(temp);
|
stack.push_back(temp);
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <fmt/core.h>
|
|
||||||
#include <functional>
|
|
||||||
#include <source_location>
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
namespace dbc {
|
|
||||||
class Error {
|
|
||||||
public:
|
|
||||||
const string message;
|
|
||||||
Error(string m) : message{m} {}
|
|
||||||
Error(const char *m) : message{m} {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class CheckError : public Error {};
|
|
||||||
class SentinelError : public Error {};
|
|
||||||
class PreCondError : public Error {};
|
|
||||||
class PostCondError : public Error {};
|
|
||||||
|
|
||||||
void log(const string &message,
|
|
||||||
const std::source_location location =
|
|
||||||
std::source_location::current());
|
|
||||||
|
|
||||||
[[noreturn]] void sentinel(const string &message,
|
|
||||||
const std::source_location location =
|
|
||||||
std::source_location::current());
|
|
||||||
|
|
||||||
void pre(const string &message, bool test,
|
|
||||||
const std::source_location location =
|
|
||||||
std::source_location::current());
|
|
||||||
|
|
||||||
void pre(const string &message, std::function<bool()> tester,
|
|
||||||
const std::source_location location =
|
|
||||||
std::source_location::current());
|
|
||||||
|
|
||||||
void post(const string &message, bool test,
|
|
||||||
const std::source_location location =
|
|
||||||
std::source_location::current());
|
|
||||||
|
|
||||||
void post(const string &message, std::function<bool()> tester,
|
|
||||||
const std::source_location location =
|
|
||||||
std::source_location::current());
|
|
||||||
|
|
||||||
void check(bool test, const string &message,
|
|
||||||
const std::source_location location =
|
|
||||||
std::source_location::current());
|
|
||||||
}
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "guecs/ui.hpp"
|
#include "guecs/ui.hpp"
|
||||||
|
|
||||||
namespace sfml {
|
namespace sfml {
|
||||||
|
using std::string;
|
||||||
|
|
||||||
class Backend : public guecs::Backend {
|
class Backend : public guecs::Backend {
|
||||||
int $shaders_version = 0;
|
int $shaders_version = 0;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include "guecs/lel.hpp"
|
#include "guecs/lel.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include "guecs/lel.hpp"
|
#include "guecs/lel.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -10,6 +9,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "guecs/theme.hpp"
|
#include "guecs/theme.hpp"
|
||||||
#include "guecs/sfml/components.hpp"
|
#include "guecs/sfml/components.hpp"
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace guecs {
|
namespace guecs {
|
||||||
using std::shared_ptr, std::wstring, std::string;
|
using std::shared_ptr, std::wstring, std::string;
|
||||||
|
@ -177,7 +177,7 @@ namespace guecs {
|
||||||
|
|
||||||
template <typename Comp>
|
template <typename Comp>
|
||||||
void set_init(Entity ent, Comp val) {
|
void set_init(Entity ent, Comp val) {
|
||||||
dbc::check(has<lel::Cell>(ent),"WRONG! slot is missing its cell?!");
|
assert(has<lel::Cell>(ent) && "WRONG! slot is missing its cell?!");
|
||||||
auto& cell = get<lel::Cell>(ent);
|
auto& cell = get<lel::Cell>(ent);
|
||||||
val.init(cell);
|
val.init(cell);
|
||||||
set<Comp>(ent, val);
|
set<Comp>(ent, val);
|
||||||
|
|
|
@ -70,7 +70,6 @@ dependencies += [
|
||||||
|
|
||||||
|
|
||||||
sources = [
|
sources = [
|
||||||
'src/guecs/dbc.cpp',
|
|
||||||
'src/guecs/ui.cpp',
|
'src/guecs/ui.cpp',
|
||||||
'src/guecs/lel.cpp',
|
'src/guecs/lel.cpp',
|
||||||
'src/guecs/theme.cpp',
|
'src/guecs/theme.cpp',
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
void dbc::log(const string &message, const std::source_location location) {
|
|
||||||
std::cout << '[' << location.file_name() << ':'
|
|
||||||
<< location.line() << "|"
|
|
||||||
<< location.function_name() << "] "
|
|
||||||
<< message << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbc::sentinel(const string &message, const std::source_location location) {
|
|
||||||
string err = fmt::format("[SENTINEL!] {}", message);
|
|
||||||
dbc::log(err, location);
|
|
||||||
throw dbc::SentinelError{err};
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbc::pre(const string &message, bool test, const std::source_location location) {
|
|
||||||
if(!test) {
|
|
||||||
string err = fmt::format("[PRE!] {}", message);
|
|
||||||
dbc::log(err, location);
|
|
||||||
throw dbc::PreCondError{err};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbc::pre(const string &message, std::function<bool()> tester, const std::source_location location) {
|
|
||||||
dbc::pre(message, tester(), location);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbc::post(const string &message, bool test, const std::source_location location) {
|
|
||||||
if(!test) {
|
|
||||||
string err = fmt::format("[POST!] {}", message);
|
|
||||||
dbc::log(err, location);
|
|
||||||
throw dbc::PostCondError{err};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbc::post(const string &message, std::function<bool()> tester, const std::source_location location) {
|
|
||||||
dbc::post(message, tester(), location);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dbc::check(bool test, const string &message, const std::source_location location) {
|
|
||||||
if(!test) {
|
|
||||||
string err = fmt::format("[CHECK!] {}\n", message);
|
|
||||||
dbc::log(err, location);
|
|
||||||
throw dbc::CheckError{err};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "guecs/lel.hpp"
|
#include "guecs/lel.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "./lel_parser.cpp"
|
#include "./lel_parser.cpp"
|
||||||
|
|
||||||
|
@ -27,8 +27,7 @@ namespace lel {
|
||||||
|
|
||||||
void Parser::id(std::string name) {
|
void Parser::id(std::string name) {
|
||||||
if(name != "_") {
|
if(name != "_") {
|
||||||
dbc::check(!cells.contains(name),
|
assert(!cells.contains(name) && "duplicate cell name");
|
||||||
fmt::format("duplicate cell name {}", name));
|
|
||||||
cells.insert_or_assign(name, cur);
|
cells.insert_or_assign(name, cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +43,8 @@ namespace lel {
|
||||||
for(auto& row : grid) {
|
for(auto& row : grid) {
|
||||||
size_t columns = row.size();
|
size_t columns = row.size();
|
||||||
int cell_width = grid_w / columns;
|
int cell_width = grid_w / columns;
|
||||||
dbc::check(cell_width > 0, "invalid cell width calc");
|
assert(cell_width > 0 && "invalid cell width calc");
|
||||||
dbc::check(cell_height > 0, "invalid cell height calc");
|
assert(cell_height > 0 && "invalid cell height calc");
|
||||||
|
|
||||||
for(auto& name : row) {
|
for(auto& name : row) {
|
||||||
if(name == "_") continue;
|
if(name == "_") continue;
|
||||||
|
@ -66,8 +65,8 @@ namespace lel {
|
||||||
cell.w = cell.expand ? std::min(cell.max_w, grid_w) : std::min(cell_width, cell.max_w);
|
cell.w = cell.expand ? std::min(cell.max_w, grid_w) : std::min(cell_width, cell.max_w);
|
||||||
cell.h = cell.expand ? std::min(cell.max_h, grid_h) : std::min(cell_height, cell.max_h);
|
cell.h = cell.expand ? std::min(cell.max_h, grid_h) : std::min(cell_height, cell.max_h);
|
||||||
|
|
||||||
dbc::check(cell.h > 0, fmt::format("invalid height cell {}", name));
|
assert(cell.h > 0 && "invalid height cell is <= 0");
|
||||||
dbc::check(cell.w > 0, fmt::format("invalid width cell {}", name));
|
assert(cell.w > 0 && "invalid width cell is <= 0");
|
||||||
|
|
||||||
cell.x = grid_x + (cell.col * cell_width);
|
cell.x = grid_x + (cell.col * cell_width);
|
||||||
cell.y = grid_y + (cell.row * cell_height);
|
cell.y = grid_y + (cell.row * cell_height);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#line 1 ".\\src\\guecs\\lel_parser.rl"
|
#line 1 "src/guecs/lel_parser.rl"
|
||||||
#include "guecs/lel.hpp"
|
#include "guecs/lel.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -7,11 +7,11 @@
|
||||||
namespace lel {
|
namespace lel {
|
||||||
|
|
||||||
|
|
||||||
#line 41 ".\\src\\guecs\\lel_parser.rl"
|
#line 41 "src/guecs/lel_parser.rl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#line 10 ".\\src\\guecs\\lel_parser.cpp"
|
#line 10 "src/guecs/lel_parser.cpp"
|
||||||
static const char _Parser_actions[] = {
|
static const char _Parser_actions[] = {
|
||||||
0, 1, 1, 1, 2, 1, 3, 1,
|
0, 1, 1, 1, 2, 1, 3, 1,
|
||||||
4, 1, 5, 1, 6, 1, 9, 1,
|
4, 1, 5, 1, 6, 1, 9, 1,
|
||||||
|
@ -84,7 +84,7 @@ static const int Parser_error = 0;
|
||||||
static const int Parser_en_main = 1;
|
static const int Parser_en_main = 1;
|
||||||
|
|
||||||
|
|
||||||
#line 44 ".\\src\\guecs\\lel_parser.rl"
|
#line 44 "src/guecs/lel_parser.rl"
|
||||||
|
|
||||||
bool Parser::parse(std::string input) {
|
bool Parser::parse(std::string input) {
|
||||||
reset();
|
reset();
|
||||||
|
@ -96,14 +96,14 @@ bool Parser::parse(std::string input) {
|
||||||
std::string tk;
|
std::string tk;
|
||||||
|
|
||||||
|
|
||||||
#line 91 ".\\src\\guecs\\lel_parser.cpp"
|
#line 91 "src/guecs/lel_parser.cpp"
|
||||||
{
|
{
|
||||||
cs = Parser_start;
|
cs = Parser_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 55 ".\\src\\guecs\\lel_parser.rl"
|
#line 55 "src/guecs/lel_parser.rl"
|
||||||
|
|
||||||
#line 94 ".\\src\\guecs\\lel_parser.cpp"
|
#line 94 "src/guecs/lel_parser.cpp"
|
||||||
{
|
{
|
||||||
int _klen;
|
int _klen;
|
||||||
unsigned int _trans;
|
unsigned int _trans;
|
||||||
|
@ -178,62 +178,62 @@ _match:
|
||||||
switch ( *_acts++ )
|
switch ( *_acts++ )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
#line 11 ".\\src\\guecs\\lel_parser.rl"
|
#line 11 "src/guecs/lel_parser.rl"
|
||||||
{tk = input.substr(start - begin, p - start); }
|
{tk = input.substr(start - begin, p - start); }
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
#line 13 ".\\src\\guecs\\lel_parser.rl"
|
#line 13 "src/guecs/lel_parser.rl"
|
||||||
{}
|
{}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
#line 14 ".\\src\\guecs\\lel_parser.rl"
|
#line 14 "src/guecs/lel_parser.rl"
|
||||||
{ grid.push_back(Row()); }
|
{ grid.push_back(Row()); }
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
#line 15 ".\\src\\guecs\\lel_parser.rl"
|
#line 15 "src/guecs/lel_parser.rl"
|
||||||
{ cur.bottom = (*p) == '.'; }
|
{ cur.bottom = (*p) == '.'; }
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
#line 16 ".\\src\\guecs\\lel_parser.rl"
|
#line 16 "src/guecs/lel_parser.rl"
|
||||||
{ id(input.substr(start - begin, p - start)); }
|
{ id(input.substr(start - begin, p - start)); }
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
#line 17 ".\\src\\guecs\\lel_parser.rl"
|
#line 17 "src/guecs/lel_parser.rl"
|
||||||
{ cur.col = 0; cur.row++; }
|
{ cur.col = 0; cur.row++; }
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
#line 18 ".\\src\\guecs\\lel_parser.rl"
|
#line 18 "src/guecs/lel_parser.rl"
|
||||||
{ cur.right = (*p) == '>'; }
|
{ cur.right = (*p) == '>'; }
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
#line 19 ".\\src\\guecs\\lel_parser.rl"
|
#line 19 "src/guecs/lel_parser.rl"
|
||||||
{cur.max_w = std::stoi(tk); }
|
{cur.max_w = std::stoi(tk); }
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
#line 20 ".\\src\\guecs\\lel_parser.rl"
|
#line 20 "src/guecs/lel_parser.rl"
|
||||||
{ cur.max_h = std::stoi(tk); }
|
{ cur.max_h = std::stoi(tk); }
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
#line 21 ".\\src\\guecs\\lel_parser.rl"
|
#line 21 "src/guecs/lel_parser.rl"
|
||||||
{ cur.expand = true; }
|
{ cur.expand = true; }
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
#line 22 ".\\src\\guecs\\lel_parser.rl"
|
#line 22 "src/guecs/lel_parser.rl"
|
||||||
{ cur.center = true; }
|
{ cur.center = true; }
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
#line 23 ".\\src\\guecs\\lel_parser.rl"
|
#line 23 "src/guecs/lel_parser.rl"
|
||||||
{ cur.percent = true; }
|
{ cur.percent = true; }
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
#line 33 ".\\src\\guecs\\lel_parser.rl"
|
#line 33 "src/guecs/lel_parser.rl"
|
||||||
{ start = p; }
|
{ start = p; }
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
#line 36 ".\\src\\guecs\\lel_parser.rl"
|
#line 36 "src/guecs/lel_parser.rl"
|
||||||
{start = p;}
|
{start = p;}
|
||||||
break;
|
break;
|
||||||
#line 209 ".\\src\\guecs\\lel_parser.cpp"
|
#line 209 "src/guecs/lel_parser.cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,13 +246,13 @@ _again:
|
||||||
_out: {}
|
_out: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 56 ".\\src\\guecs\\lel_parser.rl"
|
#line 56 "src/guecs/lel_parser.rl"
|
||||||
|
|
||||||
bool good = pe - p == 0;
|
bool good = pe - p == 0;
|
||||||
if(good) {
|
if(good) {
|
||||||
finalize();
|
finalize();
|
||||||
} else {
|
} else {
|
||||||
dbc::log("error at:");
|
std::cout << "error at:";
|
||||||
std::cout << p;
|
std::cout << p;
|
||||||
}
|
}
|
||||||
return good;
|
return good;
|
||||||
|
|
|
@ -58,7 +58,7 @@ bool Parser::parse(std::string input) {
|
||||||
if(good) {
|
if(good) {
|
||||||
finalize();
|
finalize();
|
||||||
} else {
|
} else {
|
||||||
dbc::log("error at:");
|
std::cout << "error at:";
|
||||||
std::cout << p;
|
std::cout << p;
|
||||||
}
|
}
|
||||||
return good;
|
return good;
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#include "guecs/ui.hpp"
|
#include "guecs/ui.hpp"
|
||||||
#include "guecs/sfml/backend.hpp"
|
#include "guecs/sfml/backend.hpp"
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace guecs {
|
namespace guecs {
|
||||||
using std::make_shared;
|
using std::make_shared;
|
||||||
|
|
||||||
void Textual::init(lel::Cell &cell, shared_ptr<sf::Font> font_ptr) {
|
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(font == nullptr) font = font_ptr;
|
||||||
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size);
|
if(text == nullptr) text = make_shared<sf::Text>(*font, content, size);
|
||||||
text->setFillColor(color);
|
text->setFillColor(color);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "guecs/sfml/config.hpp"
|
#include "guecs/sfml/config.hpp"
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
using nlohmann::json;
|
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) {
|
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];
|
return $config[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring Config::wstring(const std::string main_key, const std::string sub_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));
|
assert($config.contains(main_key) && "ERROR wstring main/key in config, main_key doesn't exist.");
|
||||||
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[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];
|
const std::string& str_val = $config[main_key][sub_key];
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "guecs/sfml/shaders.hpp"
|
#include "guecs/sfml/shaders.hpp"
|
||||||
#include "guecs/sfml/config.hpp"
|
#include "guecs/sfml/config.hpp"
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include <SFML/Graphics/Image.hpp>
|
#include <SFML/Graphics/Image.hpp>
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -30,21 +29,21 @@ namespace shaders {
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
if(!INITIALIZED) {
|
if(!INITIALIZED) {
|
||||||
dbc::check(sf::Shader::isAvailable(), "no shaders?!");
|
assert(sf::Shader::isAvailable() && "no shaders?!");
|
||||||
INITIALIZED = true;
|
INITIALIZED = true;
|
||||||
Config config("assets/shaders.json");
|
Config config("assets/shaders.json");
|
||||||
bool good = load_shader("ERROR", config["ERROR"]);
|
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()) {
|
for(auto& [name, settings] : config.json().items()) {
|
||||||
if(name == "ERROR") continue;
|
if(name == "ERROR") continue;
|
||||||
|
|
||||||
dbc::check(!SMGR.shaders.contains(name),
|
assert(!SMGR.shaders.contains(name) &&
|
||||||
fmt::format("shader name '{}' duplicated in assets/shaders.json", name));
|
"shader name duplicated in assets/shaders.json");
|
||||||
good = load_shader(name, settings);
|
good = load_shader(name, settings);
|
||||||
|
|
||||||
if(!good) {
|
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"));
|
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) {
|
std::shared_ptr<sf::Shader> get(const std::string& name) {
|
||||||
dbc::check(INITIALIZED, "you forgot to shaders::init()");
|
assert(INITIALIZED && "you forgot to shaders::init()");
|
||||||
dbc::check(SMGR.shaders.contains(name),
|
assert(SMGR.shaders.contains(name) &&
|
||||||
fmt::format("shader name '{}' not in assets/shaders.json", name));
|
"shader name not in assets/shaders.json");
|
||||||
auto& rec = SMGR.shaders.at(name);
|
auto& rec = SMGR.shaders.at(name);
|
||||||
return rec.ptr;
|
return rec.ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "guecs/sfml/sound.hpp"
|
#include "guecs/sfml/sound.hpp"
|
||||||
#include "guecs/sfml/config.hpp"
|
#include "guecs/sfml/config.hpp"
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace sound {
|
namespace sound {
|
||||||
static SoundManager SMGR;
|
static SoundManager SMGR;
|
||||||
|
@ -13,14 +13,13 @@ namespace sound {
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
SoundPair& get_sound_pair(const std::string& name) {
|
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)) {
|
if(SMGR.sounds.contains(name)) {
|
||||||
// get the sound from the sound map
|
// get the sound from the sound map
|
||||||
return SMGR.sounds.at(name);
|
return SMGR.sounds.at(name);
|
||||||
} else {
|
} else {
|
||||||
dbc::log(fmt::format("Attempted to stop {} sound but not available.",
|
fmt::println("[SOUND] Attempted to stop {} sound but not available.", name);
|
||||||
name));
|
|
||||||
return SMGR.sounds.at("blank");
|
return SMGR.sounds.at("blank");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +37,7 @@ namespace sound {
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(const std::string& name, const std::string& sound_path) {
|
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
|
// create the buffer and keep in the buffer map
|
||||||
auto buffer = make_shared<sf::SoundBuffer>(sound_path);
|
auto buffer = make_shared<sf::SoundBuffer>(sound_path);
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
#include "guecs/sfml/textures.hpp"
|
#include "guecs/sfml/textures.hpp"
|
||||||
#include "guecs/sfml/config.hpp"
|
#include "guecs/sfml/config.hpp"
|
||||||
#include <SFML/Graphics/Image.hpp>
|
#include <SFML/Graphics/Image.hpp>
|
||||||
|
@ -36,16 +35,16 @@ namespace textures {
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteTexture get(const std::string& name) {
|
SpriteTexture get(const std::string& name) {
|
||||||
dbc::check(initialized, "you forgot to call textures::init()");
|
assert(initialized && "you forgot to call textures::init()");
|
||||||
dbc::check(TMGR.sprite_textures.contains(name),
|
assert(TMGR.sprite_textures.contains(name) &&
|
||||||
fmt::format("!!!!! texture pack does not contain {} sprite", name));
|
"!!!!! texture pack does not contain sprite");
|
||||||
|
|
||||||
auto result = TMGR.sprite_textures.at(name);
|
auto result = TMGR.sprite_textures.at(name);
|
||||||
|
|
||||||
dbc::check(result.sprite != nullptr,
|
assert(result.sprite != nullptr &&
|
||||||
fmt::format("bad sprite from textures::get named {}", name));
|
"bad sprite from textures::get named can't be null");
|
||||||
dbc::check(result.texture != nullptr,
|
assert(result.texture != nullptr &&
|
||||||
fmt::format("bad texture from textures::get named {}", name));
|
"bad texture from textures::get named can't be null");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +52,7 @@ namespace textures {
|
||||||
sf::Image load_image(const std::string& filename) {
|
sf::Image load_image(const std::string& filename) {
|
||||||
sf::Image texture;
|
sf::Image texture;
|
||||||
bool good = texture.loadFromFile(filename);
|
bool good = texture.loadFromFile(filename);
|
||||||
dbc::check(good, fmt::format("failed to load {}", filename));
|
assert(good && "failed to load image file");
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "guecs/ui.hpp"
|
#include "guecs/ui.hpp"
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
#include <cassert>
|
||||||
|
#include <fmt/core.h>
|
||||||
|
|
||||||
namespace guecs {
|
namespace guecs {
|
||||||
using std::make_shared;
|
using std::make_shared;
|
||||||
|
@ -23,7 +25,7 @@ namespace guecs {
|
||||||
void UI::layout(const string& grid) {
|
void UI::layout(const string& grid) {
|
||||||
$grid = grid;
|
$grid = grid;
|
||||||
bool good = $parser.parse($grid);
|
bool good = $parser.parse($grid);
|
||||||
dbc::check(good, "LEL parsing failed.");
|
assert(good && "LEL parsing failed.");
|
||||||
|
|
||||||
for(auto& [name, cell] : $parser.cells) {
|
for(auto& [name, cell] : $parser.cells) {
|
||||||
auto ent = init_entity(name);
|
auto ent = init_entity(name);
|
||||||
|
@ -41,8 +43,8 @@ namespace guecs {
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity UI::entity(const string& name) {
|
Entity UI::entity(const string& name) {
|
||||||
dbc::check($name_ents.contains(name),
|
assert($name_ents.contains(name) &&
|
||||||
fmt::format("GUECS entity {} does not exist. Mispelled cell name?", name));
|
"GUECS entity does not exist. Mispelled cell name?");
|
||||||
return $name_ents.at(name);
|
return $name_ents.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,8 +192,8 @@ namespace guecs {
|
||||||
auto ent = entity(name);
|
auto ent = entity(name);
|
||||||
|
|
||||||
if(required) {
|
if(required) {
|
||||||
dbc::check(has<Clickable>(ent),
|
assert(has<Clickable>(ent) &&
|
||||||
fmt::format("click_on required '{}' to exist but it doesn't", name));
|
"click_on required '{}' to exist but it doesn't");
|
||||||
}
|
}
|
||||||
|
|
||||||
click_on(ent);
|
click_on(ent);
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
#include <catch2/catch_test_macros.hpp>
|
|
||||||
#include "guecs/dbc.hpp"
|
|
||||||
|
|
||||||
using namespace dbc;
|
|
||||||
|
|
||||||
TEST_CASE("basic feature tests", "[dbc]") {
|
|
||||||
log("Logging a message.");
|
|
||||||
|
|
||||||
pre("confirm positive cases work", 1 == 1);
|
|
||||||
|
|
||||||
pre("confirm positive lambda", [&]{ return 1 == 1;});
|
|
||||||
|
|
||||||
post("confirm positive post", 1 == 1);
|
|
||||||
|
|
||||||
post("confirm postitive post with lamdba", [&]{ return 1 == 1;});
|
|
||||||
|
|
||||||
check(1 == 1, "one equals 1");
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue