Commit c09d5ed7 authored by Florian Oetke's avatar Florian Oetke
Browse files

update clang-format and mingw compatibilty fixes

parent 2221ef0b
......@@ -38,4 +38,4 @@ namespace mirrage {
private:
std::unique_ptr<renderer::Deferred_renderer_factory> _renderer_factory;
};
}
} // namespace mirrage
......@@ -31,7 +31,7 @@ namespace {
void init_engine();
void onFrame();
void shutdown();
}
} // namespace
#ifdef main
......@@ -64,35 +64,25 @@ namespace {
void init_env(int argc, char** argv, char** env) {
//auto testC = glm::vec2{1,2} - glm::vec2{1,1}; (void)testC;
//INVARIANT(testC.y==(testA.y - testB.y), "XXX: "<<testC.y<<" != "<<(testA.y - testB.y));
//MIRRAGE_INVARIANT(testC.y==(testA.y - testB.y), "XXX: "<<testC.y<<" != "<<(testA.y - testB.y));
::argc = argc;
::argv = argv;
::env = env;
INFO("Game started from: " << argv[0] << "\n"
<< "Working dir: "
<< asset::pwd()
<< "\n"
<< "Version: "
<< version_info::name
<< "\n"
<< "Version-Hash: "
<< version_info::hash
<< "\n"
<< "Version-Date: "
<< version_info::date
<< "\n"
<< "Version-Subject: "
<< version_info::subject
<< "\n");
MIRRAGE_INFO("Game started from: " << argv[0] << "\n"
<< "Working dir: " << asset::pwd() << "\n"
<< "Version: " << version_info::name << "\n"
<< "Version-Hash: " << version_info::hash << "\n"
<< "Version-Date: " << version_info::date << "\n"
<< "Version-Subject: " << version_info::subject << "\n");
try {
util::init_stacktrace(argv[0]);
mirrage::asset::setup_storage();
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in init: " << ex.what());
MIRRAGE_CRASH_REPORT("Exception in init: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in init", nullptr);
shutdown();
exit(1);
......@@ -124,7 +114,7 @@ namespace {
engine->screens().enter<Test_screen>();
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in init: " << ex.what());
MIRRAGE_CRASH_REPORT("Exception in init: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in init", nullptr);
shutdown();
exit(1);
......@@ -136,7 +126,7 @@ namespace {
engine->on_frame();
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in onFrame: " << ex.what());
MIRRAGE_CRASH_REPORT("Exception in onFrame: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in onFrame", nullptr);
shutdown();
exit(2);
......@@ -148,9 +138,9 @@ namespace {
engine.reset();
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in shutdown: " << ex.what());
MIRRAGE_CRASH_REPORT("Exception in shutdown: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in shutdown", nullptr);
exit(3);
}
}
}
} // namespace
......@@ -32,4 +32,4 @@ namespace mirrage {
void Meta_system::draw() { _renderer->draw(); }
void Meta_system::shrink_to_fit() { _renderer->shrink_to_fit(); }
}
} // namespace mirrage
......@@ -37,4 +37,4 @@ namespace mirrage {
std::unique_ptr<renderer::Loading_system> _model_loading;
std::unique_ptr<systems::Nim_system> _nims;
};
}
} // namespace mirrage
......@@ -116,7 +116,7 @@ namespace mirrage::systems {
namespace {
template <class T>
auto catmull_rom(float t, const std::vector<T>& points, bool closed) -> T {
INVARIANT(!points.empty(), "Can't interpolate between zero points!");
MIRRAGE_INVARIANT(!points.empty(), "Can't interpolate between zero points!");
// calc points
auto P1_idx = static_cast<int>(std::floor(t));
......
......@@ -20,8 +20,8 @@ namespace mirrage::systems {
class Nim_comp : public ecs::Component<Nim_comp> {
public:
static constexpr const char* name() { return "NIM"; }
friend void load_component(ecs::Deserializer& state, Nim_comp&);
friend void save_component(ecs::Serializer& state, const Nim_comp&);
friend void load_component(ecs::Deserializer& state, Nim_comp&);
friend void save_component(ecs::Serializer& state, const Nim_comp&);
Nim_comp() = default;
Nim_comp(ecs::Entity_manager& manager, ecs::Entity_handle owner) : Component(manager, owner) {}
......@@ -121,4 +121,4 @@ namespace mirrage::systems {
void _update_lookup_table();
};
}
} // namespace mirrage::systems
......@@ -108,13 +108,13 @@ namespace mirrage {
case "print"_strid: {
auto cam = _camera.get<Transform_comp>().get_or_throw().position();
INFO(
"Setup: \n"
<< " Camera position: " << cam.x << "/" << cam.y << "/" << cam.z << "\n"
<< " Camera orientation: " << _cam_yaw << "/" << _cam_pitch << "\n"
<< " Sun orientation: " << _sun_elevation << "/" << _sun_azimuth << "\n"
<< " Sun color: " << _sun_color_temperature << "\n"
<< " Disected: " << _meta_system.renderer().settings().debug_disect);
MIRRAGE_INFO("Setup: \n"
<< " Camera position: " << cam.x << "/" << cam.y << "/" << cam.z << "\n"
<< " Camera orientation: " << _cam_yaw << "/" << _cam_pitch << "\n"
<< " Sun orientation: " << _sun_elevation << "/" << _sun_azimuth << "\n"
<< " Sun color: " << _sun_color_temperature << "\n"
<< " Disected: "
<< _meta_system.renderer().settings().debug_disect);
break;
}
......
......@@ -77,4 +77,4 @@ namespace mirrage {
void _draw_settings_window();
void _draw_profiler_window();
};
}
} // namespace mirrage
......@@ -18,8 +18,8 @@ namespace mirrage {
CreateDirectory(dir.c_str(), NULL);
#else
auto status = mkdir(dir.c_str(), 0755);
INVARIANT(status == 0 || errno == EEXIST,
"Couldn't create directory \"" << dir << "\": " << int(errno));
MIRRAGE_INVARIANT(status == 0 || errno == EEXIST,
"Couldn't create directory \"" << dir << "\": " << int(errno));
#endif
}
}
} // namespace mirrage
......@@ -27,8 +27,8 @@ int main(int argc, char** argv) {
return 1;
}
auto args = std::vector<std::string>{const_cast<const char**>(argv + 1),
const_cast<const char**>(argv + argc)};
auto args = std::vector<std::string>{const_cast<const char**>(argv + 1),
const_cast<const char**>(argv + argc)};
auto output = extract_arg(args, "--output").get_or_other("output");
create_directory(output);
......
......@@ -125,7 +125,7 @@ namespace mirrage {
int width = 0;
int height = 0;
auto data = stbi_load(path.c_str(), &width, &height, nullptr, 4);
INVARIANT(data, "Texture '" << path << "' couldn't be loaded!");
MIRRAGE_INVARIANT(data, "Texture '" << path << "' couldn't be loaded!");
ON_EXIT { stbi_image_free(data); };
......@@ -229,7 +229,7 @@ namespace mirrage {
out.write(reinterpret_cast<char*>(rgb8_image.mip_levels[i].data()), size);
}
}
}
} // namespace
bool convert_material(const std::string& name,
const aiMaterial& material,
......@@ -316,4 +316,4 @@ namespace mirrage {
return true;
}
}
} // namespace mirrage
......@@ -63,29 +63,25 @@ namespace mirrage {
out.write(reinterpret_cast<const char*>(value.data()), value.size() * sizeof(T));
}
}
} // namespace
void convert_model(const std::string& path, const std::string& output) {
INFO("Convert model \"" << path << "\" with output directory \"" << output << "\"");
MIRRAGE_INFO("Convert model \"" << path << "\" with output directory \"" << output << "\"");
auto base_dir = extract_dir(path);
auto model_name = extract_file_name(path);
auto importer = Assimp::Importer();
auto scene = importer.ReadFile(path,
aiProcess_JoinIdenticalVertices | aiProcess_GenSmoothNormals
| aiProcess_Triangulate
| aiProcess_PreTransformVertices
| aiProcess_ImproveCacheLocality
| aiProcess_RemoveRedundantMaterials
| aiProcess_OptimizeMeshes
| aiProcess_ValidateDataStructure
| aiProcess_FlipUVs
| aiProcess_FixInfacingNormals);
auto scene = importer.ReadFile(
path,
aiProcess_JoinIdenticalVertices | aiProcess_GenSmoothNormals | aiProcess_Triangulate
| aiProcess_PreTransformVertices | aiProcess_ImproveCacheLocality
| aiProcess_RemoveRedundantMaterials | aiProcess_OptimizeMeshes
| aiProcess_ValidateDataStructure | aiProcess_FlipUVs | aiProcess_FixInfacingNormals);
INVARIANT(scene, "Unable to load model '" << path << "': " << importer.GetErrorString());
MIRRAGE_INVARIANT(scene, "Unable to load model '" << path << "': " << importer.GetErrorString());
// load materials
auto materials = gsl::span<const aiMaterial* const>(scene->mMaterials, scene->mNumMaterials);
......@@ -94,14 +90,14 @@ namespace mirrage {
for(auto& mat : materials) {
aiString name;
if(mat->Get(AI_MATKEY_NAME, name) != aiReturn_SUCCESS) {
WARN("material number " << loaded_material_ids.size() << " has no name!");
MIRRAGE_WARN("material number " << loaded_material_ids.size() << " has no name!");
loaded_material_ids.emplace_back(util::nothing);
continue;
}
auto mat_id = model_name + "_" + name.C_Str();
if(!convert_material(mat_id, *mat, base_dir, output)) {
WARN("Unable to parse material \"" << name.C_Str() << "\"!");
MIRRAGE_WARN("Unable to parse material \"" << name.C_Str() << "\"!");
loaded_material_ids.emplace_back(util::nothing);
continue;
}
......@@ -143,7 +139,7 @@ namespace mirrage {
if(mat.is_some()) {
sub_meshes.emplace_back(indices.size(), mesh->mNumFaces * 3, mat.get_or_throw());
} else {
WARN("Required material is missing/defect!");
MIRRAGE_WARN("Required material is missing/defect!");
}
}
......@@ -159,7 +155,8 @@ namespace mirrage {
auto model_out_filename = output + "/models/" + model_name + ".mmf";
auto model_out_file = std::ofstream(model_out_filename, std::ostream::binary | std::ostream::trunc);
INVARIANT(model_out_file.is_open(), "Unable to open output file \"" << model_out_filename << "\"!");
MIRRAGE_INVARIANT(model_out_file.is_open(),
"Unable to open output file \"" << model_out_filename << "\"!");
auto header = renderer::Model_file_header();
header.vertex_count = gsl::narrow<std::uint32_t>(vertices.size() * sizeof(renderer::Model_vertex));
......@@ -188,6 +185,6 @@ namespace mirrage {
// write footer
write(model_out_file, renderer::Model_file_header::type_tag_value);
INFO("Done.");
MIRRAGE_INFO("Done.");
}
}
} // namespace mirrage
......@@ -28,7 +28,7 @@ namespace mirrage::asset {
bool operator==(const AID& o) const noexcept;
bool operator!=(const AID& o) const noexcept;
bool operator<(const AID& o) const noexcept;
operator bool() const noexcept;
operator bool() const noexcept;
auto str() const noexcept -> std::string;
auto type() const noexcept { return _type; }
......@@ -38,7 +38,7 @@ namespace mirrage::asset {
Asset_type _type;
std::string _name;
};
}
} // namespace mirrage::asset
inline mirrage::asset::AID operator"" _aid(const char* str, std::size_t) {
return mirrage::asset::AID(str);
......@@ -51,4 +51,4 @@ namespace std {
return 71 * hash<mirrage::asset::Asset_type>()(aid.type()) + hash<string>()(aid.name());
}
};
}
} // namespace std
......@@ -135,8 +135,8 @@ namespace mirrage::asset {
std::unordered_map<AID, Asset> _assets;
std::unordered_map<AID, std::string> _dispatcher;
std::vector<Watch_entry> _watchlist;
uint32_t _next_watch_id = 0;
std::vector<Watch_entry> _watchlist;
uint32_t _next_watch_id = 0;
void _add_asset(const AID& id,
const std::string& path,
......@@ -159,7 +159,7 @@ namespace mirrage::asset {
util::maybe<const T&> unpack(util::maybe<Ptr<T>> m) {
return m.process(util::maybe<const T&>{}, [](Ptr<T>& p) { return util::maybe<const T&>{*p}; });
}
}
} // namespace mirrage::asset
#define ASSETMANAGER_INCLUDED
#include "asset_manager.hxx"
......@@ -79,7 +79,7 @@ namespace mirrage::asset {
}
template <class R>
const R& Ptr<R>::operator*() const {
INVARIANT(*this, "Access to unloaded resource");
MIRRAGE_INVARIANT(*this, "Access to unloaded resource");
return *_ptr.get();
}
......@@ -90,7 +90,7 @@ namespace mirrage::asset {
}
template <class R>
const R* Ptr<R>::operator->() const {
INVARIANT(*this, "Access to unloaded resource");
MIRRAGE_INVARIANT(*this, "Access to unloaded resource");
return _ptr.get();
}
......@@ -112,8 +112,8 @@ namespace mirrage::asset {
template <class R>
void Ptr<R>::load() {
if(!_ptr) {
INVARIANT(_mgr, "Tried to load unintialized resource-ref");
INVARIANT(_aid, "Tried to load unnamed resource");
MIRRAGE_INVARIANT(_mgr, "Tried to load unintialized resource-ref");
MIRRAGE_INVARIANT(_aid, "Tried to load unnamed resource");
*this = _mgr->load<R>(_aid);
}
}
......@@ -121,8 +121,8 @@ namespace mirrage::asset {
template <class R>
bool Ptr<R>::try_load(bool cache, bool warn) {
if(!_ptr) {
INVARIANT(_mgr, "Tried to load unintialized resource-ref");
INVARIANT(_aid, "Tried to load unnamed resource");
MIRRAGE_INVARIANT(_mgr, "Tried to load unintialized resource-ref");
MIRRAGE_INVARIANT(_aid, "Tried to load unnamed resource");
auto loaded = _mgr->load_maybe<R>(_aid, cache, warn);
if(loaded.is_some()) {
*this = loaded.get_or_throw();
......@@ -136,4 +136,4 @@ namespace mirrage::asset {
void Ptr<R>::unload() {
_ptr.reset();
}
}
} // namespace mirrage::asset
......@@ -79,7 +79,7 @@ namespace mirrage::asset {
auto operator=(ostream &&) -> ostream&;
};
}
} // namespace mirrage::asset
#ifdef ENABLE_SF2_ASSETS
#include <sf2/sf2.hpp>
......@@ -98,14 +98,13 @@ namespace mirrage::asset {
static auto load(istream in) -> std::shared_ptr<T> {
auto r = std::make_shared<T>();
sf2::deserialize_json(
in,
[&](auto& msg, uint32_t row, uint32_t column) {
ERROR("Error parsing JSON from " << in.aid().str() << " at " << row << ":" << column
<< ": "
<< msg);
},
*r);
sf2::deserialize_json(in,
[&](auto& msg, uint32_t row, uint32_t column) {
MIRRAGE_ERROR("Error parsing JSON from " << in.aid().str() << " at "
<< row << ":" << column << ": "
<< msg);
},
*r);
return r;
}
......@@ -116,12 +115,11 @@ namespace mirrage::asset {
struct Interceptor {
static auto on_intercept(Asset_manager&, const AID& interceptor_aid, const AID& org_aid)
-> std::shared_ptr<T> {
FAIL("Required Interceptor specialization not found loading '" << org_aid.str() << "' via '"
<< interceptor_aid.str()
<< "'");
MIRRAGE_FAIL("Required Interceptor specialization not found loading '"
<< org_aid.str() << "' via '" << interceptor_aid.str() << "'");
}
};
}
} // namespace mirrage::asset
#else
namespace mirrage::asset {
......@@ -137,5 +135,5 @@ namespace mirrage::asset {
static auto load(istream in) throw(Loading_failed) -> std::shared_ptr<T>;
static void store(ostream out, const T& asset) throw(Loading_failed);
};
}
} // namespace mirrage::asset
#endif
......@@ -20,5 +20,5 @@ namespace mirrage::asset {
bool AID::operator==(const AID& o) const noexcept { return _type == o._type && _name == o._name; }
bool AID::operator!=(const AID& o) const noexcept { return !(*this == o); }
bool AID::operator<(const AID& o) const noexcept { return _type < o._type || _name < o._name; }
AID::operator bool() const noexcept { return !_name.empty(); }
}
AID:: operator bool() const noexcept { return !_name.empty(); }
} // namespace mirrage::asset
......@@ -77,7 +77,7 @@ namespace {
auto wildcard = last_of(file, '*').get_or_other(file.length());
if(wildcard != (file.find_first_of('*') + 1)) {
WARN("More than one wildcard ist currently not supported. Found in: " << wildcard_path);
MIRRAGE_WARN("More than one wildcard ist currently not supported. Found in: " << wildcard_path);
}
auto prefix = file.substr(0, wildcard - 1);
......@@ -115,7 +115,7 @@ namespace {
}
constexpr auto default_source = {std::make_tuple("assets", false), std::make_tuple("assets.zip", true)};
}
} // namespace
namespace mirrage::asset {
......@@ -153,7 +153,7 @@ namespace mirrage::asset {
Module.print("end file sync..");
Module.syncdone = 1;
ccall('post_sync_handler', 'v');
}););
}););
}
bool storage_ready() { return initial_sync_done; }
......@@ -165,13 +165,13 @@ namespace mirrage::asset {
static Asset_manager* current_instance = nullptr;
auto get_asset_manager() -> Asset_manager& {
INVARIANT(current_instance != nullptr, "Asset_manager has not been initialized!");
return *current_instance;
MIRRAGE_INVARIANT(current_instance != nullptr, "Asset_manager has not been initialized!");
return *current_instance;
}
Asset_manager::Asset_manager(const std::string& exe_name, const std::string& app_name) {
if(!PHYSFS_init(exe_name.empty() ? nullptr : exe_name.c_str()))
FAIL("PhysFS-Init failed for \"" << exe_name << "\": " << PHYSFS_getLastError());
MIRRAGE_FAIL("PhysFS-Init failed for \"" << exe_name << "\": " << PHYSFS_getLastError());
// TODO: Windows savegames should be stored in FOLDERID_SavedGames, but the API and conventions are a pain in the ass
std::string write_dir_parent = append_file(PHYSFS_getUserDir(),
......@@ -180,17 +180,17 @@ namespace mirrage::asset {
#else
".config"
#endif
);
);
#ifdef EMSCRIPTEN
INVARIANT(storage_ready(), "Storage is not ready");
MIRRAGE_INVARIANT(storage_ready(), "Storage is not ready");
write_dir_parent = "/persistent_data";
#endif
if(!PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1)
|| !PHYSFS_addToSearchPath(append_file(PHYSFS_getBaseDir(), "..").c_str(), 1)
|| !PHYSFS_addToSearchPath(pwd().c_str(), 1))
FAIL("Unable to construct search path: " << PHYSFS_getLastError());
MIRRAGE_FAIL("Unable to construct search path: " << PHYSFS_getLastError());
// add optional search path
PHYSFS_addToSearchPath(
......@@ -207,18 +207,18 @@ namespace mirrage::asset {
std::string write_dir = append_file(write_dir_parent, app_name);
create_dir(write_dir);
INFO("Write dir: " << write_dir);
MIRRAGE_INFO("Write dir: " << write_dir);
if(!PHYSFS_addToSearchPath(write_dir.c_str(), 0))
FAIL("Unable to construct search path: " << PHYSFS_getLastError());
MIRRAGE_FAIL("Unable to construct search path: " << PHYSFS_getLastError());
if(!PHYSFS_setWriteDir(write_dir.c_str()))
FAIL("Unable to set write-dir to \"" << write_dir << "\": " << PHYSFS_getLastError());
MIRRAGE_FAIL("Unable to set write-dir to \"" << write_dir << "\": " << PHYSFS_getLastError());
auto add_source = [](const char* path) {
if(!PHYSFS_addToSearchPath(path, 1))
WARN("Error adding custom archive \"" << path << "\": " << PHYSFS_getLastError());
MIRRAGE_WARN("Error adding custom archive \"" << path << "\": " << PHYSFS_getLastError());
};
auto archive_file = _open("archives.lst");
......@@ -244,7 +244,7 @@ namespace mirrage::asset {
log << std::endl; // crash with error
} else {
INFO("No archives.lst found. Using defaults.");
MIRRAGE_INFO("No archives.lst found. Using defaults.");
}
} else {
......@@ -355,7 +355,7 @@ namespace mirrage::asset {
else if(util::contains(res->second, ":"))
return std::make_tuple(Location_type::indirection, res->second);
else if(warn)
INFO("Asset not found in configured place: " << res->second);
MIRRAGE_INFO("Asset not found in configured place: " << res->second);
}
if(exists_file(id.name()))
......@@ -368,7 +368,7 @@ namespace mirrage::asset {
if(exists_file(path))
return std::make_tuple(Location_type::file, std::move(path));
else if(warn)
DEBUG("asset " << id.str() << " not found in " << path);
MIRRAGE_DEBUG("asset " << id.str() << " not found in " << path);
}
return std::make_tuple(Location_type::none, std::string());
......@@ -454,7 +454,7 @@ namespace mirrage::asset {
auto last_mod = PHYSFS_getLastModTime(location.c_str());
if(last_mod != -1 && last_mod > a.second.last_modified) {
_open(location, a.first).process([&](istream& in) {
DEBUG("Reload: " << a.first.str());
MIRRAGE_DEBUG("Reload: " << a.first.str());
try {
a.second.reloader(a.second.data.get(), std::move(in));
......@@ -512,7 +512,7 @@ namespace mirrage::asset {
case Location_type::indirection: return true;
}
FAIL("Unexpected Location_type: " << static_cast<int>(type));
MIRRAGE_FAIL("Unexpected Location_type: " << static_cast<int>(type));
}
auto Asset_manager::load_raw(const AID& id) -> util::maybe<istream> {
......@@ -543,7 +543,7 @@ namespace mirrage::asset {
}
}
DEBUG("Couldn't finde asset for '" << path_cleared << "'");
MIRRAGE_DEBUG("Couldn't finde asset for '" << path_cleared << "'");
return util::nothing;
}
......@@ -579,4 +579,4 @@ namespace mirrage::asset {
}
}
}
}
} // namespace mirrage::asset
......@@ -110,7 +110,7 @@ namespace mirrage::asset {
stream::stream(AID aid, Asset_manager& manager, File_handle* file, const std::string& path)
: _file(file), _aid(aid), _manager(manager) {
INVARIANT(file, "Error opening file \"" << path << "\": " << PHYSFS_getLastError());
MIRRAGE_INVARIANT(file, "Error opening file \"" << path << "\": " << PHYSFS_getLastError());
_fbuf.reset(new fbuf(file));
}
......@@ -128,7 +128,7 @@ namespace mirrage::asset {
}
stream& stream::operator=(stream&& rhs) noexcept {