Best I can do to simplify the check(fmt::format)crap is to make a little macro to do the format part.

This commit is contained in:
Zed A. Shaw 2026-03-05 12:39:22 -05:00
parent 6710469ee1
commit f0b04107ab
28 changed files with 108 additions and 108 deletions

View file

@ -11,7 +11,8 @@ namespace ai {
inline void validate_profile(nlohmann::json& profile) { inline void validate_profile(nlohmann::json& profile) {
for(auto& [name_key, value] : profile.items()) { for(auto& [name_key, value] : profile.items()) {
check(value < STATE_MAX, check(value < STATE_MAX,
fmt::format("profile field {} has value {} greater than STATE_MAX {}", (std::string)name_key, (int)value, STATE_MAX)); $F("profile field {} has value {} greater than STATE_MAX {}",
(std::string)name_key, (int)value, STATE_MAX));
} }
} }
@ -22,17 +23,17 @@ namespace ai {
Action result(config["name"], config["cost"]); Action result(config["name"], config["cost"]);
check(config.contains("needs"), check(config.contains("needs"),
fmt::format("config_action: no 'needs' field", result.name)); $F("config_action: no 'needs' field", result.name));
check(config.contains("effects"), check(config.contains("effects"),
fmt::format("config_action: no 'effects' field", result.name)); $F("config_action: no 'effects' field", result.name));
for(auto& [name_key, value] : config["needs"].items()) { for(auto& [name_key, value] : config["needs"].items()) {
check(profile.contains(name_key), fmt::format("config_action({}): profile does not have need named {}", result.name, name_key)); check(profile.contains(name_key), $F("config_action({}): profile does not have need named {}", result.name, name_key));
result.needs(profile.at(name_key), bool(value)); result.needs(profile.at(name_key), bool(value));
} }
for(auto& [name_key, value] : config["effects"].items()) { for(auto& [name_key, value] : config["effects"].items()) {
check(profile.contains(name_key), fmt::format("config_action({}): profile does not have effect named {}", result.name, name_key)); check(profile.contains(name_key), $F("config_action({}): profile does not have effect named {}", result.name, name_key));
result.effect(profile.at(name_key), bool(value)); result.effect(profile.at(name_key), bool(value));
} }
@ -44,7 +45,7 @@ namespace ai {
State result; State result;
for(auto& [name_key, value] : config.items()) { for(auto& [name_key, value] : config.items()) {
check(profile.contains(name_key), fmt::format("config_state: profile does not have name {}", name_key)); check(profile.contains(name_key), $F("config_state: profile does not have name {}", name_key));
int name_id = profile.at(name_key); int name_id = profile.at(name_key);
result[name_id] = bool(value); result[name_id] = bool(value);
@ -95,7 +96,7 @@ namespace ai {
for(auto name : action_names) { for(auto name : action_names) {
check(AIMGR.actions.contains(name), check(AIMGR.actions.contains(name),
fmt::format("ai::init(): script {} uses action {} that doesn't exist", $F("ai::init(): script {} uses action {} that doesn't exist",
(std::string)script_name, (std::string)name)); (std::string)script_name, (std::string)name));
the_script.push_back(AIMGR.actions.at(name)); the_script.push_back(AIMGR.actions.at(name));
@ -111,14 +112,14 @@ namespace ai {
void check_valid_action(std::string name, std::string msg) { void check_valid_action(std::string name, std::string msg) {
dbc::check(AIMGR.actions.contains(name), dbc::check(AIMGR.actions.contains(name),
fmt::format("{} tried to access action that doesn't exist {}", $F("{} tried to access action that doesn't exist {}",
msg, name)); msg, name));
} }
State load_state(std::string state_name) { State load_state(std::string state_name) {
check(initialized, "you forgot to initialize the AI first."); check(initialized, "you forgot to initialize the AI first.");
check(AIMGR.states.contains(state_name), fmt::format( check(AIMGR.states.contains(state_name),
"ai::load_state({}): state does not exist in config", $F("ai::load_state({}): state does not exist in config",
state_name)); state_name));
return AIMGR.states.at(state_name); return AIMGR.states.at(state_name);
@ -126,15 +127,15 @@ namespace ai {
Action load_action(std::string action_name) { Action load_action(std::string action_name) {
check(initialized, "you forgot to initialize the AI first."); check(initialized, "you forgot to initialize the AI first.");
check(AIMGR.actions.contains(action_name), fmt::format( check(AIMGR.actions.contains(action_name),
"ai::load_action({}): action does not exist in config", $F("ai::load_action({}): action does not exist in config",
action_name)); action_name));
return AIMGR.actions.at(action_name); return AIMGR.actions.at(action_name);
} }
std::vector<Action> load_script(std::string script_name) { std::vector<Action> load_script(std::string script_name) {
check(AIMGR.scripts.contains(script_name), fmt::format( check(AIMGR.scripts.contains(script_name),
"ai::load_script(): no script named {} configured", script_name)); $F("ai::load_script(): no script named {} configured", script_name));
return AIMGR.scripts.at(script_name); return AIMGR.scripts.at(script_name);
} }
@ -148,9 +149,8 @@ namespace ai {
} }
int state_id(std::string name) { int state_id(std::string name) {
check(AIMGR.profile.contains(name), fmt::format( check(AIMGR.profile.contains(name),
"ai::state_id({}): id is not configured in profile", $F("ai::state_id({}): id is not configured in profile", name));
name));
return AIMGR.profile.at(name); return AIMGR.profile.at(name);
} }

View file

@ -69,8 +69,8 @@ namespace DinkyECS
for(auto [eid, is_set] : $constants) { for(auto [eid, is_set] : $constants) {
dbc::check(is_set == true, "is_set was not true? WHAT?!"); dbc::check(is_set == true, "is_set was not true? WHAT?!");
dbc::check(eid <= entity_count, fmt::format( dbc::check(eid <= entity_count,
"eid {} is not less than entity_count {}", eid, entity_count)); $F("eid {} is not less than entity_count {}", eid, entity_count));
for(const auto &[tid, eid_map] : $components) { for(const auto &[tid, eid_map] : $components) {
auto &their_map = to_world.$components[tid]; auto &their_map = to_world.$components[tid];
@ -146,8 +146,7 @@ namespace DinkyECS
Comp &get_the() { Comp &get_the() {
auto comp_id = std::type_index(typeid(Comp)); auto comp_id = std::type_index(typeid(Comp));
dbc::check($facts->contains(comp_id), dbc::check($facts->contains(comp_id),
fmt::format("!!!! ATTEMPT to access world fact that hasn't " $F("!!!! ATTEMPT to access world fact that hasn't been set yet: {}",
"been set yet: {}",
typeid(Comp).name())); typeid(Comp).name()));
// use .at to get std::out_of_range if fact not set // use .at to get std::out_of_range if fact not set

View file

@ -17,10 +17,10 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t
void Pathing::compute_paths(Matrix &walls) { void Pathing::compute_paths(Matrix &walls) {
INVARIANT(); INVARIANT();
dbc::check(walls[0].size() == $width, dbc::check(walls[0].size() == $width,
fmt::format("Pathing::compute_paths called with walls.width={} but paths $width={}", walls[0].size(), $width)); $F("Pathing::compute_paths called with walls.width={} but paths $width={}", walls[0].size(), $width));
dbc::check(walls.size() == $height, dbc::check(walls.size() == $height,
fmt::format("Pathing::compute_paths called with walls.height={} but paths $height={}", walls[0].size(), $height)); $F("Pathing::compute_paths called with walls.height={} but paths $height={}", walls[0].size(), $height));
// Initialize the new array with every pixel at limit distance // Initialize the new array with every pixel at limit distance
matrix::assign($paths, WALL_PATH_LIMIT); matrix::assign($paths, WALL_PATH_LIMIT);

View file

@ -4,7 +4,7 @@
void Stats::dump(std::string msg) void Stats::dump(std::string msg)
{ {
dbc::log(fmt::format("{}: sum: {}, sumsq: {}, n: {}, " dbc::log($F("{}: sum: {}, sumsq: {}, n: {}, "
"min: {}, max: {}, mean: {}, stddev: {}", "min: {}, max: {}, mean: {}, stddev: {}",
msg, sum, sumsq, n, min, max, mean(), msg, sum, sumsq, n, min, max, mean(),
stddev())); stddev()));

View file

@ -18,7 +18,7 @@ namespace boss {
{ {
$host_combat = $world->get_if<components::Combat>(player_id); $host_combat = $world->get_if<components::Combat>(player_id);
dbc::check($host_combat, dbc::check($host_combat,
fmt::format("No combat for host with player_id={}", player_id)); $F("No combat for host with player_id={}", player_id));
$ui.init(); $ui.init();
} }
@ -138,7 +138,7 @@ namespace boss {
using combat::BattleHostState; using combat::BattleHostState;
dbc::check(data.type() == typeid(components::CombatResult), dbc::check(data.type() == typeid(components::CombatResult),
fmt::format("Boss Fight wrong any data={}", data.type().name())); $F("Boss Fight wrong any data={}", data.type().name()));
auto result = std::any_cast<components::CombatResult>(data); auto result = std::any_cast<components::CombatResult>(data);

View file

@ -9,14 +9,14 @@ void dbc::log(const string &message, const std::source_location location) {
} }
void dbc::sentinel(const string &message, const std::source_location location) { void dbc::sentinel(const string &message, const std::source_location location) {
string err = fmt::format("[SENTINEL!] {}", message); string err = $F("[SENTINEL!] {}", message);
dbc::log(err, location); dbc::log(err, location);
throw dbc::SentinelError{err}; throw dbc::SentinelError{err};
} }
void dbc::pre(const string &message, bool test, const std::source_location location) { void dbc::pre(const string &message, bool test, const std::source_location location) {
if(!test) { if(!test) {
string err = fmt::format("[PRE!] {}", message); string err = $F("[PRE!] {}", message);
dbc::log(err, location); dbc::log(err, location);
throw dbc::PreCondError{err}; throw dbc::PreCondError{err};
} }
@ -28,7 +28,7 @@ void dbc::pre(const string &message, std::function<bool()> tester, const std::so
void dbc::post(const string &message, bool test, const std::source_location location) { void dbc::post(const string &message, bool test, const std::source_location location) {
if(!test) { if(!test) {
string err = fmt::format("[POST!] {}", message); string err = $F("[POST!] {}", message);
dbc::log(err, location); dbc::log(err, location);
throw dbc::PostCondError{err}; throw dbc::PostCondError{err};
} }
@ -40,7 +40,7 @@ void dbc::post(const string &message, std::function<bool()> tester, const std::s
void dbc::check(bool test, const string &message, const std::source_location location) { void dbc::check(bool test, const string &message, const std::source_location location) {
if(!test) { if(!test) {
string err = fmt::format("[CHECK!] {}\n", message); string err = $F("[CHECK!] {}\n", message);
dbc::log(err, location); dbc::log(err, location);
throw dbc::CheckError{err}; throw dbc::CheckError{err};
} }

View file

@ -5,6 +5,9 @@
#include <functional> #include <functional>
#include <source_location> #include <source_location>
// AKA the Fuckit macro
#define $F(FMT, ...) fmt::format(FMT, ##__VA_ARGS__)
namespace dbc { namespace dbc {
using std::string; using std::string;

View file

@ -230,7 +230,7 @@ void Autowalker::handle_player_walk(ai::State& start, ai::State& goal) {
fsm.autowalking = false; fsm.autowalking = false;
} else { } else {
close_status(); close_status();
dbc::log(fmt::format("Unknown action: {}", player_ai.to_string())); dbc::log($F("Unknown action: {}", player_ai.to_string()));
} }
} }

View file

@ -8,8 +8,8 @@ namespace components {
void configure_entity(DinkyECS::World& world, DinkyECS::Entity ent, json& data) { void configure_entity(DinkyECS::World& world, DinkyECS::Entity ent, json& data) {
for (auto &i : data) { for (auto &i : data) {
dbc::check(i.contains("_type") && i["_type"].is_string(), fmt::format("component has no _type: {}", data.dump())); dbc::check(i.contains("_type") && i["_type"].is_string(), $F("component has no _type: {}", data.dump()));
dbc::check(MAP.contains(i["_type"]), fmt::format("MAP doesn't have type {}", std::string(i["_type"]))); dbc::check(MAP.contains(i["_type"]), $F("MAP doesn't have type {}", std::string(i["_type"])));
MAP.at(i["_type"])(world, ent, i); MAP.at(i["_type"])(world, ent, i);
} }
} }

View file

@ -4,14 +4,13 @@
namespace settings { namespace settings {
using nlohmann::json; using nlohmann::json;
using fmt::format;
std::filesystem::path Config::BASE_DIR{"."}; std::filesystem::path Config::BASE_DIR{"."};
Config::Config(const std::string src_path) : $src_path(src_path) { Config::Config(const std::string src_path) : $src_path(src_path) {
auto path_to = Config::path_to($src_path); auto path_to = Config::path_to($src_path);
dbc::check(std::filesystem::exists(path_to), dbc::check(std::filesystem::exists(path_to),
fmt::format("requested config file {} doesn't exist", path_to.string())); $F("requested config file {} doesn't exist", path_to.string()));
std::ifstream infile(path_to); std::ifstream infile(path_to);
$config = json::parse(infile); $config = json::parse(infile);
} }
@ -21,13 +20,15 @@ namespace settings {
} }
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)); dbc::check($config.contains(key), $F("ERROR in config, key {} doesn't exist.", key));
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)); dbc::check($config.contains(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)); $F("ERROR wstring main/key in config, main_key {} doesn't exist.", main_key));
dbc::check($config[main_key].contains(sub_key),
$F("ERROR wstring in config, main_key/key {}/{} doesn't exist.", main_key, sub_key));
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;
@ -58,8 +59,8 @@ namespace settings {
} else { } else {
auto path = Config::BASE_DIR / fmt::format("assets/{}.json", name); auto path = Config::BASE_DIR / fmt::format("assets/{}.json", name);
dbc::check(std::filesystem::exists(path), fmt::format( dbc::check(std::filesystem::exists(path),
"config file {} does not exist", path.string())); $F("config file {} does not exist", path.string()));
return {path.string()}; return {path.string()};
} }

View file

@ -34,7 +34,7 @@ namespace inventory {
// NOTE: this was a reference but that caused corruption, just copy // NOTE: this was a reference but that caused corruption, just copy
auto slot = by_entity.at(ent); auto slot = by_entity.at(ent);
dbc::log(fmt::format("removing entity {} and slot {}", ent, slot)); dbc::log($F("removing entity {} and slot {}", ent, slot));
dbc::check(by_slot.contains(slot), "entity is in by_entity but the slot is not in by_slot"); dbc::check(by_slot.contains(slot), "entity is in by_entity but the slot is not in by_slot");
// NOTE: you have to erase the entity after the slot or else you get corruption // NOTE: you have to erase the entity after the slot or else you get corruption
@ -47,16 +47,16 @@ namespace inventory {
void Model::invariant() { void Model::invariant() {
for(auto& [slot, ent] : by_slot) { for(auto& [slot, ent] : by_slot) {
dbc::check(by_entity.contains(ent), dbc::check(by_entity.contains(ent),
fmt::format("entity {} in by_slot isn't in by_entity?", ent)); $F("entity {} in by_slot isn't in by_entity?", ent));
dbc::check(by_entity.at(ent) == slot, dbc::check(by_entity.at(ent) == slot,
fmt::format("mismatched slot {} in by_slot doesn't match entity {}", slot, ent)); $F("mismatched slot {} in by_slot doesn't match entity {}", slot, ent));
} }
for(auto& [ent, slot] : by_entity) { for(auto& [ent, slot] : by_entity) {
dbc::check(by_slot.contains(slot), dbc::check(by_slot.contains(slot),
fmt::format("slot {} in by_entity isn't in by_slot?", ent)); $F("slot {} in by_entity isn't in by_slot?", ent));
dbc::check(by_slot.at(slot) == ent, dbc::check(by_slot.at(slot) == ent,
fmt::format("mismatched entity {} in by_entity doesn't match entity {}", ent, slot)); $F("mismatched entity {} in by_entity doesn't match entity {}", ent, slot));
} }
dbc::check(by_slot.size() == by_entity.size(), "by_slot and by_entity have differing sizes"); dbc::check(by_slot.size() == by_entity.size(), "by_slot and by_entity have differing sizes");

View file

@ -106,10 +106,10 @@ bool Map::INVARIANT() {
for(auto room : $rooms) { for(auto room : $rooms) {
check(int(room.x) >= 0 && int(room.y) >= 0, check(int(room.x) >= 0 && int(room.y) >= 0,
format("room invalid position {},{}", $F("room invalid position {},{}",
room.x, room.y)); room.x, room.y));
check(int(room.width) > 0 && int(room.height) > 0, check(int(room.width) > 0 && int(room.height) > 0,
format("room has invalid dims {},{}", $F("room has invalid dims {},{}",
room.width, room.height)); room.width, room.height));
} }

View file

@ -59,7 +59,7 @@ namespace ritual {
void Engine::set_state(CraftingState& ritual, std::string name, bool setting) { void Engine::set_state(CraftingState& ritual, std::string name, bool setting) {
dbc::check($profile.contains(name), dbc::check($profile.contains(name),
fmt::format("ritual action named {} is not in profile, look in {} config", $F("ritual action named {} is not in profile, look in {} config",
name, $config.$src_path)); name, $config.$src_path));
ritual.start.set($profile.at(name), setting); ritual.start.set($profile.at(name), setting);

View file

@ -19,8 +19,7 @@ namespace sound {
// 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.", dbc::log($F("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)); dbc::check(fs::exists(sound_path), $F("sound file {} does not exist", sound_path));
// 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);

View file

@ -306,7 +306,7 @@ void System::collision() {
world.send<game::Event>(game::Event::COMBAT_START, entity, entity); world.send<game::Event>(game::Event::COMBAT_START, entity, entity);
} }
} else { } else {
dbc::log(fmt::format("UNKNOWN COLLISION TYPE {}", entity)); dbc::log($F("UNKNOWN COLLISION TYPE {}", entity));
} }
} }
@ -375,7 +375,7 @@ void System::pickup() {
void System::device(World &world, Entity actor, Entity item) { void System::device(World &world, Entity actor, Entity item) {
auto& device = world.get<Device>(item); auto& device = world.get<Device>(item);
dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item)); dbc::log($F("entity {} INTERACTED WITH DEVICE {}", actor, item));
for(auto event : device.events) { for(auto event : device.events) {
if(event == "STAIRS_DOWN") { if(event == "STAIRS_DOWN") {
@ -387,7 +387,7 @@ void System::device(World &world, Entity actor, Entity item) {
} else if(event == "LOOT_CONTAINER") { } else if(event == "LOOT_CONTAINER") {
world.send<game::Event>(game::Event::LOOT_CONTAINER, actor, device); world.send<game::Event>(game::Event::LOOT_CONTAINER, actor, device);
} else { } else {
dbc::log(fmt::format( dbc::log($F(
"INVALID EVENT {} for device {}", "INVALID EVENT {} for device {}",
event, (std::string)device.config["name"])); event, (std::string)device.config["name"]));
} }
@ -621,13 +621,13 @@ bool System::use_item(const string& slot_name) {
player_combat.hp = player_combat.max_hp; player_combat.hp = player_combat.max_hp;
} }
dbc::log(fmt::format("player health now {}", dbc::log($F("player health now {}",
player_combat.hp)); player_combat.hp));
world.remove<Curative>(what); world.remove<Curative>(what);
return true; return true;
} else { } else {
dbc::log(fmt::format("no usable item at {}", what)); dbc::log($F("no usable item at {}", what));
return false; return false;
} }
} }

View file

@ -22,9 +22,9 @@ void WorldBuilder::stylize_rooms() {
auto& style = styles[Random::uniform(size_t(0), styles.size() - 1)]; auto& style = styles[Random::uniform(size_t(0), styles.size() - 1)];
dbc::check(style.contains("floor"), dbc::check(style.contains("floor"),
fmt::format("no floor spec in style {}", (std::string)style["name"])); $F("no floor spec in style {}", (std::string)style["name"]));
dbc::check(style.contains("walls"), dbc::check(style.contains("walls"),
fmt::format("no walls spec in style {}", (std::string)style["name"])); $F("no walls spec in style {}", (std::string)style["name"]));
auto& floor_name = style["floor"]; auto& floor_name = style["floor"];
auto& wall_name = style["walls"]; auto& wall_name = style["walls"];
@ -79,7 +79,7 @@ bool WorldBuilder::find_open_spot(Point& pos_out) {
matrix::dump("FAIL PLACE!", $map.walls(), pos_out.x, pos_out.y); matrix::dump("FAIL PLACE!", $map.walls(), pos_out.x, pos_out.y);
dbc::sentinel(fmt::format("failed to place entity in the entire map?: i={}; width={};", i, $map.width())); dbc::sentinel($F("failed to place entity in the entire map?: i={}; width={};", i, $map.width()));
return false; return false;
} }

View file

@ -216,16 +216,16 @@ namespace animation {
void Animation::set_form(const std::string& as_form) { void Animation::set_form(const std::string& as_form) {
dbc::check(forms.contains(as_form), dbc::check(forms.contains(as_form),
fmt::format("form {} does not exist in animation", as_form)); $F("form {} does not exist in animation", as_form));
stop(); stop();
const auto& [seq_name, tr_name] = forms.at(as_form); const auto& [seq_name, tr_name] = forms.at(as_form);
dbc::check(sequences.contains(seq_name), dbc::check(sequences.contains(seq_name),
fmt::format("sequences do NOT have \"{}\" name", seq_name)); $F("sequences do NOT have \"{}\" name", seq_name));
dbc::check(transforms.contains(tr_name), dbc::check(transforms.contains(tr_name),
fmt::format("transforms do NOT have \"{}\" name", tr_name)); $F("transforms do NOT have \"{}\" name", tr_name));
// everything good, do the update // everything good, do the update
form_name = as_form; form_name = as_form;
@ -255,14 +255,14 @@ namespace animation {
auto data = json::parse(infile); auto data = json::parse(infile);
dbc::check(data.contains(anim_name), dbc::check(data.contains(anim_name),
fmt::format("{} animation config does not have animation {}", file, anim_name)); $F("{} animation config does not have animation {}", file, anim_name));
Animation anim; Animation anim;
animation::from_json(data[anim_name], anim); animation::from_json(data[anim_name], anim);
anim.name = anim_name; anim.name = anim_name;
dbc::check(anim.forms.contains("idle"), dbc::check(anim.forms.contains("idle"),
fmt::format("animation {} must have 'idle' form", anim_name)); $F("animation {} must have 'idle' form", anim_name));
anim.set_form("idle"); anim.set_form("idle");
@ -271,21 +271,19 @@ namespace animation {
void Sequence::INVARIANT(const std::source_location location) { void Sequence::INVARIANT(const std::source_location location) {
dbc::check(frames.size() == durations.size(), dbc::check(frames.size() == durations.size(),
fmt::format("frames.size={} doesn't match durations.size={}", $F("frames.size={} doesn't match durations.size={}",
frames.size(), durations.size()), location); frames.size(), durations.size()), location);
dbc::check(easing_duration > 0.0, dbc::check(easing_duration > 0.0, $F("bad easing duration: {}", easing_duration), location);
fmt::format("bad easing duration: {}", easing_duration), location);
dbc::check(frame_count == frames.size(), dbc::check(frame_count == frames.size(),
fmt::format("frame_count={} doesn't match frames.size={}", frame_count, frames.size()), location); $F("frame_count={} doesn't match frames.size={}", frame_count, frames.size()), location);
dbc::check(frame_count == durations.size(), dbc::check(frame_count == durations.size(),
fmt::format("frame_count={} doesn't match durations.size={}", frame_count, durations.size()), location); $F("frame_count={} doesn't match durations.size={}", frame_count, durations.size()), location);
dbc::check(current < durations.size(), dbc::check(current < durations.size(),
fmt::format("current={} went past end of fame durations.size={}", $F("current={} went past end of fame durations.size={}", current, durations.size()), location);
current, durations.size()), location);
} }
// BUG: BAAADD REMOVE // BUG: BAAADD REMOVE

View file

@ -128,13 +128,13 @@ namespace ease2 {
EaseFunc get_easing(const std::string& name) { EaseFunc get_easing(const std::string& name) {
dbc::check(map_of_easings.contains(name), dbc::check(map_of_easings.contains(name),
fmt::format("easing name {} does not exist", name)); $F("easing name {} does not exist", name));
return map_of_easings.at(name); return map_of_easings.at(name);
} }
MotionFunc get_motion(const std::string& name) { MotionFunc get_motion(const std::string& name) {
dbc::check(map_of_motions.contains(name), dbc::check(map_of_motions.contains(name),
fmt::format("motion name {} does not exist", name)); $F("motion name {} does not exist", name));
return map_of_motions.at(name); return map_of_motions.at(name);
} }

View file

@ -34,7 +34,7 @@ namespace palette {
for(auto [value, rgba] : value_specs.items()) { for(auto [value, rgba] : value_specs.items()) {
auto color_path = base_key + ":" + value; auto color_path = base_key + ":" + value;
dbc::check(!COLOR.palettes.contains(color_path), dbc::check(!COLOR.palettes.contains(color_path),
fmt::format("PALLETES config {} already has a color path {}", COLOR.config, color_path)); $F("PALLETES config {} already has a color path {}", COLOR.config, color_path));
if(rgba.type() == json::value_t::string) { if(rgba.type() == json::value_t::string) {
COLOR.pending_refs.try_emplace(color_path, rgba); COLOR.pending_refs.try_emplace(color_path, rgba);
@ -48,10 +48,10 @@ namespace palette {
for(auto [color_path, ref] : COLOR.pending_refs) { for(auto [color_path, ref] : COLOR.pending_refs) {
dbc::check(COLOR.palettes.contains(ref), dbc::check(COLOR.palettes.contains(ref),
fmt::format("In {} you have {} referring to {} but {} doesn't exist.", $F("In {} you have {} referring to {} but {} doesn't exist.",
COLOR.config, color_path, ref, ref)); COLOR.config, color_path, ref, ref));
dbc::check(!COLOR.palettes.contains(color_path), dbc::check(!COLOR.palettes.contains(color_path),
fmt::format("Color {} with ref {} is duplicated.", color_path, ref)); $F("Color {} with ref {} is duplicated.", color_path, ref));
auto color = COLOR.palettes.at(ref); auto color = COLOR.palettes.at(ref);
@ -62,7 +62,7 @@ namespace palette {
sf::Color get(const string& key) { sf::Color get(const string& key) {
dbc::check(COLOR.palettes.contains(key), dbc::check(COLOR.palettes.contains(key),
fmt::format("COLOR {} is missing from {}", key, COLOR.config)); $F("COLOR {} is missing from {}", key, COLOR.config));
return COLOR.palettes.at(key); return COLOR.palettes.at(key);
} }

View file

@ -39,7 +39,7 @@ namespace scene {
for(auto& config : $scene.actors) { for(auto& config : $scene.actors) {
auto element = config_scene_element(config, false); auto element = config_scene_element(config, false);
dbc::check(!$actor_name_ids.contains(element.name), dbc::check(!$actor_name_ids.contains(element.name),
fmt::format("actors key {} already exists", element.name)); $F("actors key {} already exists", element.name));
$actors.push_back(element); $actors.push_back(element);
$actor_name_ids.try_emplace(element.name, $actors.size() - 1); $actor_name_ids.try_emplace(element.name, $actors.size() - 1);
} }
@ -109,7 +109,7 @@ namespace scene {
} }
Element& Engine::actor_config(const std::string& actor) { Element& Engine::actor_config(const std::string& actor) {
dbc::check($actor_name_ids.contains(actor), fmt::format("scene does not contain actor {}", actor)); dbc::check($actor_name_ids.contains(actor), $F("scene does not contain actor {}", actor));
return $actors.at($actor_name_ids.at(actor)); return $actors.at($actor_name_ids.at(actor));
} }

View file

@ -41,11 +41,11 @@ namespace shaders {
if(name == "ERROR") continue; if(name == "ERROR") continue;
dbc::check(!SMGR.shaders.contains(name), dbc::check(!SMGR.shaders.contains(name),
fmt::format("shader name '{}' duplicated in assets/shaders.json", name)); $F("shader name '{}' duplicated in assets/shaders.json", name));
good = load_shader(name, settings); good = load_shader(name, settings);
if(!good) { if(!good) {
dbc::log(fmt::format("failed to load shader {}", name)); dbc::log($F("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"));
} }
} }
@ -55,7 +55,7 @@ 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()"); dbc::check(INITIALIZED, "you forgot to shaders::init()");
dbc::check(SMGR.shaders.contains(name), dbc::check(SMGR.shaders.contains(name),
fmt::format("shader name '{}' not in assets/shaders.json", name)); $F("shader name '{}' not in assets/shaders.json", name));
auto& rec = SMGR.shaders.at(name); auto& rec = SMGR.shaders.at(name);
return rec.ptr; return rec.ptr;
} }

View file

@ -18,7 +18,7 @@ namespace textures {
void load_sprite_textures(SpriteTextureMap &mapping, json &config, bool smooth) { void load_sprite_textures(SpriteTextureMap &mapping, json &config, bool smooth) {
for(auto& [name, settings] : config.items()) { for(auto& [name, settings] : config.items()) {
const string& path = settings["path"]; const string& path = settings["path"];
dbc::check(fs::exists(path), fmt::format("texture at {} doesn't exist", path)); dbc::check(fs::exists(path), $F("texture at {} doesn't exist", path));
auto texture = make_shared<sf::Texture>(path); auto texture = make_shared<sf::Texture>(path);
texture->setSmooth(smooth); texture->setSmooth(smooth);
@ -28,7 +28,7 @@ namespace textures {
int height = settings["frame_height"]; int height = settings["frame_height"];
dbc::check(width % 2 == 0 && height % 2 == 0, dbc::check(width % 2 == 0 && height % 2 == 0,
fmt::format("sprite {}:{} has invalid frame size {}:{}", $F("sprite {}:{} has invalid frame size {}:{}",
path, name, width, height)); path, name, width, height));
sf::Vector2i frame_size{width, height}; sf::Vector2i frame_size{width, height};
@ -36,7 +36,7 @@ namespace textures {
sprite->setTextureRect({{0,0}, frame_size}); sprite->setTextureRect({{0,0}, frame_size});
dbc::check(!mapping.contains(name), dbc::check(!mapping.contains(name),
fmt::format("duplicate sprite/icon name {}", (string)name)); $F("duplicate sprite/icon name {}", (string)name));
mapping.try_emplace(name, sprite, texture, frame_size); mapping.try_emplace(name, sprite, texture, frame_size);
} }
} }
@ -70,7 +70,7 @@ namespace textures {
size_t surface_i = config["id"]; size_t surface_i = config["id"];
dbc::check(!TMGR.name_to_id.contains(el.key()), dbc::check(!TMGR.name_to_id.contains(el.key()),
fmt::format("duplicate key in textures {}", $F("duplicate key in textures {}",
(string)el.key())); (string)el.key()));
TMGR.name_to_id.insert_or_assign(el.key(), surface_i); TMGR.name_to_id.insert_or_assign(el.key(), surface_i);
@ -87,7 +87,7 @@ namespace textures {
if(config.contains("ceiling")) { if(config.contains("ceiling")) {
const string& name = config["ceiling"]; const string& name = config["ceiling"];
dbc::check(tiles.contains(name), fmt::format("invalid ceiling name {} in tile config {}", name, (string)el.key())); dbc::check(tiles.contains(name), $F("invalid ceiling name {} in tile config {}", name, (string)el.key()));
auto& ceiling = tiles[name]; auto& ceiling = tiles[name];
TMGR.ceilings[surface_i] = ceiling["id"]; TMGR.ceilings[surface_i] = ceiling["id"];
@ -109,7 +109,7 @@ namespace textures {
wchar_t display = tile["display"]; wchar_t display = tile["display"];
dbc::check(!TMGR.map_sprites.contains(display), dbc::check(!TMGR.map_sprites.contains(display),
fmt::format("duplicate tile display {} in map_tiles.json", int(display))); $F("duplicate tile display {} in map_tiles.json", int(display)));
TMGR.map_sprites.try_emplace(display, sprite); TMGR.map_sprites.try_emplace(display, sprite);
} }
@ -134,14 +134,14 @@ namespace textures {
SpriteTexture& get(const string& name, SpriteTextureMap& mapping) { SpriteTexture& get(const string& name, SpriteTextureMap& mapping) {
dbc::check(initialized, "you forgot to call textures::init()"); dbc::check(initialized, "you forgot to call textures::init()");
dbc::check(mapping.contains(name), dbc::check(mapping.contains(name),
fmt::format("!!!!! textures do not contain {} sprite", name)); $F("!!!!! textures do not contain {} sprite", name));
auto& result = mapping.at(name); auto& result = mapping.at(name);
dbc::check(result.sprite != nullptr, dbc::check(result.sprite != nullptr,
fmt::format("bad sprite from textures::get named {}", name)); $F("bad sprite from textures::get named {}", name));
dbc::check(result.texture != nullptr, dbc::check(result.texture != nullptr,
fmt::format("bad texture from textures::get named {}", name)); $F("bad texture from textures::get named {}", name));
return result; return result;
} }
@ -163,7 +163,7 @@ namespace textures {
sf::Image load_image(const string& filename) { sf::Image load_image(const 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)); dbc::check(good, $F("failed to load {}", filename));
return texture; return texture;
} }
@ -190,13 +190,13 @@ namespace textures {
size_t get_id(const string& name) { size_t get_id(const string& name) {
dbc::check(TMGR.name_to_id.contains(name), dbc::check(TMGR.name_to_id.contains(name),
fmt::format("there is no texture named {} in tiles.json", name)); $F("there is no texture named {} in tiles.json", name));
return TMGR.name_to_id.at(name); return TMGR.name_to_id.at(name);
} }
sf::Sprite& get_map_sprite(wchar_t display) { sf::Sprite& get_map_sprite(wchar_t display) {
dbc::check(TMGR.map_sprites.contains(display), dbc::check(TMGR.map_sprites.contains(display),
fmt::format("map_sprites.json doesn't have {} sprite", int(display))); $F("map_sprites.json doesn't have {} sprite", int(display)));
return TMGR.map_sprites.at(display); return TMGR.map_sprites.at(display);
} }

View file

@ -51,7 +51,7 @@ namespace gui {
auto player_combat = level.world->get<components::Combat>(player.entity); auto player_combat = level.world->get<components::Combat>(player.entity);
auto map = level.map; auto map = level.map;
std::wstring stats = fmt::format(L"STATS\n" std::wstring stats = $F(L"STATS\n"
L"HP: {}\n" L"HP: {}\n"
L"mean:{:>8.5}\n" L"mean:{:>8.5}\n"
L"sdev: {:>8.5}\n" L"sdev: {:>8.5}\n"

View file

@ -23,7 +23,7 @@ namespace gui {
FSM_STATE(DNDState, INV_PICKUP, ev, data); FSM_STATE(DNDState, INV_PICKUP, ev, data);
FSM_STATE(DNDState, END, ev, data); FSM_STATE(DNDState, END, ev, data);
default: default:
dbc::log(fmt::format("event received with data but state={} is not handled", int($state))); dbc::log($F("event received with data but state={} is not handled", int($state)));
} }
return !in_state(DNDState::END); return !in_state(DNDState::END);
@ -174,7 +174,7 @@ namespace gui {
case TICK: // ignored case TICK: // ignored
break; break;
default: default:
dbc::log(fmt::format("invalid event: {}", int(ev))); dbc::log($F("invalid event: {}", int(ev)));
} }
} }

View file

@ -72,7 +72,7 @@ namespace gui {
set_event(game::Event::KEY_PRESS); set_event(game::Event::KEY_PRESS);
break; break;
default: default:
dbc::sentinel(fmt::format("invalid event: {}", int(ev))); dbc::sentinel($F("invalid event: {}", int(ev)));
} }
} }
@ -136,7 +136,7 @@ namespace gui {
break; break;
default: default:
// invalid events: 1 // invalid events: 1
dbc::sentinel(fmt::format("invalid events: {}", int(ev))); dbc::sentinel($F("invalid events: {}", int(ev)));
} }
} }
} }

View file

@ -92,7 +92,7 @@ namespace gui {
run_systems(); run_systems();
} break; } break;
default: default:
dbc::log(fmt::format("In ATTACKING state, unhandled event {}", (int)ev)); dbc::log($F("In ATTACKING state, unhandled event {}", (int)ev));
state(State::IDLE); state(State::IDLE);
} }
} }
@ -283,7 +283,7 @@ namespace gui {
} }
void FSM::END(Event ev) { void FSM::END(Event ev) {
dbc::log(fmt::format("END: received event after done: {}", int(ev))); dbc::log($F("END: received event after done: {}", int(ev)));
} }
sf::Vector2f FSM::mouse_position() { sf::Vector2f FSM::mouse_position() {
@ -469,13 +469,13 @@ namespace gui {
auto &damage = std::any_cast<components::CombatResult&>(data); auto &damage = std::any_cast<components::CombatResult&>(data);
if(damage.enemy_did > 0) { if(damage.enemy_did > 0) {
$map_ui.log(fmt::format(L"Enemy HIT YOU for {} damage!", damage.enemy_did)); $map_ui.log($F(L"Enemy HIT YOU for {} damage!", damage.enemy_did));
} else { } else {
$map_ui.log(L"Enemy MISSED YOU."); $map_ui.log(L"Enemy MISSED YOU.");
} }
if(damage.player_did > 0) { if(damage.player_did > 0) {
$map_ui.log(fmt::format(L"You HIT enemy for {} damage!", damage.player_did)); $map_ui.log($F(L"You HIT enemy for {} damage!", damage.player_did));
} else { } else {
$map_ui.log(L"You MISSED the enemy."); $map_ui.log(L"You MISSED the enemy.");
} }
@ -544,11 +544,11 @@ namespace gui {
case eGUI::NOOP: { case eGUI::NOOP: {
if(data.type() == typeid(std::string)) { if(data.type() == typeid(std::string)) {
auto name = std::any_cast<std::string>(data); auto name = std::any_cast<std::string>(data);
$map_ui.log(fmt::format(L"NOOP EVENT! {},{}", evt, entity)); $map_ui.log($F(L"NOOP EVENT! {},{}", evt, entity));
} }
} break; } break;
default: default:
dbc::log(fmt::format("Unhandled event: evt={}; enemy={}; data={}", dbc::log($F("Unhandled event: evt={}; enemy={}; data={}",
evt, entity, data.type().name())); evt, entity, data.type().name()));
event(game::Event(evt), data); event(game::Event(evt), data);
} }

View file

@ -56,7 +56,7 @@ namespace storyboard {
std::istringstream is{time}; std::istringstream is{time};
is >> std::chrono::parse("%M:%S", out); is >> std::chrono::parse("%M:%S", out);
dbc::check(!is.fail(), fmt::format("Time parse failed: {}", time)); dbc::check(!is.fail(), $F("Time parse failed: {}", time));
return sf::Time(out); return sf::Time(out);
} }

View file

@ -69,7 +69,7 @@ namespace arena {
$status.set<Rectangle>(button, {}); $status.set<Rectangle>(button, {});
$status.set<Clickable>(button, { $status.set<Clickable>(button, {
[this, name](auto, auto){ [this, name](auto, auto){
dbc::log(fmt::format("STATUS: {}", name)); dbc::log($F("STATUS: {}", name));
} }
}); });
if(name == "main_status") { if(name == "main_status") {
@ -84,7 +84,7 @@ namespace arena {
auto region = $overlay.entity(name); auto region = $overlay.entity(name);
$overlay.set<Clickable>(region, { $overlay.set<Clickable>(region, {
[this, name](auto, auto){ [this, name](auto, auto){
dbc::log(fmt::format("OVERLAY: {}", name)); dbc::log($F("OVERLAY: {}", name));
} }
}); });