Commit 7f472654 authored by Florian Oetke's avatar Florian Oetke
Browse files

changed brace style to WebKit (break on function definition)

parent b15ba53b
......@@ -23,7 +23,7 @@ BraceWrapping: {AfterClass: false, AfterControlStatement: false, AfterEnum: true
AfterUnion: false, BeforeCatch: false, BeforeElse: false, IndentBraces: false}
BreakAfterJavaFieldAnnotations: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeBraces: WebKit
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true
......
......@@ -37,9 +37,12 @@ namespace mirrage {
renderer::make_pass_factory<renderer::Tone_mapping_pass_factory>(),
renderer::make_pass_factory<renderer::Bloom_pass_factory>(),
renderer::make_pass_factory<renderer::Blit_pass_factory>(),
renderer::make_pass_factory<renderer::Gui_pass_factory>()))) {}
renderer::make_pass_factory<renderer::Gui_pass_factory>())))
{
}
Game_engine::~Game_engine() {
Game_engine::~Game_engine()
{
screens().clear(); // destroy all screens before the engine
}
......
......@@ -35,11 +35,13 @@ namespace {
#ifdef main
int main(int argc, char** argv) {
int main(int argc, char** argv)
{
char* noEnv = nullptr;
char** env = &noEnv;
#else
int main(int argc, char** argv, char** env) {
int main(int argc, char** argv, char** env)
{
#endif
init_env(argc, argv, env);
......@@ -62,7 +64,8 @@ namespace {
char** env;
void init_env(int argc, char** argv, char** env) {
void init_env(int argc, char** argv, char** env)
{
auto write_dir = asset::write_dir(argv[0], org_name, app_name);
static auto fileAppender = plog::RollingFileAppender<plog::TxtFormatter>(
......@@ -84,7 +87,8 @@ namespace {
<< "Version-Subject: " << version_info::subject << "\n";
}
void init_engine() {
void init_engine()
{
bool debug = false;
#ifndef NDEBUG
debug = true;
......
......@@ -13,16 +13,19 @@ namespace mirrage {
: _entities(engine.assets(), this)
, _renderer(engine.renderer_factory().create_renderer(_entities, *this))
, _model_loading(std::make_unique<renderer::Loading_system>(_entities, engine.assets()))
, _nims(std::make_unique<systems::Nim_system>(_entities)) {
, _nims(std::make_unique<systems::Nim_system>(_entities))
{
_entities.register_component_type<ecs::components::Transform_comp>();
}
Meta_system::~Meta_system() {
Meta_system::~Meta_system()
{
_renderer->device().wait_idle();
_entities.clear();
}
void Meta_system::update(util::Time dt) {
void Meta_system::update(util::Time dt)
{
_entities.process_queued_actions();
_nims->update(dt);
......
......@@ -14,11 +14,13 @@ namespace mirrage::systems {
using namespace util::unit_literals;
void load_component(ecs::Deserializer& state, Nim_comp& comp) {
void load_component(ecs::Deserializer& state, Nim_comp& comp)
{
state.read_virtual(sf2::vmember("uid", comp._uid));
}
void save_component(ecs::Serializer& state, const Nim_comp& comp) {
void save_component(ecs::Serializer& state, const Nim_comp& comp)
{
state.write_virtual(sf2::vmember("uid", comp._uid));
}
......@@ -37,7 +39,8 @@ namespace mirrage::systems {
sf2_structDef(Frame_data, length, entities);
} // namespace
void load(sf2::JsonDeserializer& s, Nim_sequence& seq) {
void load(sf2::JsonDeserializer& s, Nim_sequence& seq)
{
auto frames = std::vector<Frame_data>();
s.read_virtual(sf2::vmember("frames", frames));
......@@ -76,12 +79,10 @@ namespace mirrage::systems {
state.positions.emplace_back(iter->second.position);
state.orientations.emplace_back(iter->second.orientation);
state.light_colors.emplace_back(iter->second.light_color);
} else if(state.positions.empty()) {
state.positions.emplace_back(0, 0, 0);
state.orientations.emplace_back(1, 0, 0, 0);
state.light_colors.emplace_back(1, 0.938374f, 0.88349f, 100.f);
} else {
state.positions.emplace_back(glm::vec3(state.positions.back()));
state.orientations.emplace_back(glm::quat(state.orientations.back()));
......@@ -91,7 +92,8 @@ namespace mirrage::systems {
}
}
void save(sf2::JsonSerializer& s, const Nim_sequence& seq) {
void save(sf2::JsonSerializer& s, const Nim_sequence& seq)
{
auto frames = std::vector<Frame_data>();
frames.reserve(seq.frames());
......@@ -116,7 +118,8 @@ namespace mirrage::systems {
namespace {
template <class T>
auto catmull_rom(float t, const std::vector<T>& points, bool closed) -> T {
auto catmull_rom(float t, const std::vector<T>& points, bool closed) -> T
{
MIRRAGE_INVARIANT(!points.empty(), "Can't interpolate between zero points!");
// calc points
......@@ -136,7 +139,6 @@ namespace mirrage::systems {
P1_idx = P1_idx % point_count;
P2_idx = P2_idx % point_count;
P3_idx = P3_idx % point_count;
} else {
P0_idx = util::min(P0_idx, point_count);
P1_idx = P0_idx > 0 ? P0_idx - 1 : P0_idx;
......@@ -162,7 +164,8 @@ namespace mirrage::systems {
}
} // namespace
void Nim_system::update(util::Time dt) {
void Nim_system::update(util::Time dt)
{
if(!_playing)
return;
......@@ -220,7 +223,8 @@ namespace mirrage::systems {
}
}
void Nim_system::play(Nim_sequence_ptr seq, int begin, int end, float speed) {
void Nim_system::play(Nim_sequence_ptr seq, int begin, int end, float speed)
{
if(_playing != seq) {
_playing = seq;
}
......@@ -232,14 +236,16 @@ namespace mirrage::systems {
_end_position = end >= 0 ? end : _playing->frames();
_loop = false;
}
void Nim_system::play_looped(Nim_sequence_ptr seq, float speed) {
void Nim_system::play_looped(Nim_sequence_ptr seq, float speed)
{
play(seq, 0, -1, speed);
_loop = true;
}
void Nim_system::stop() { _playing.reset(); }
void Nim_system::start_recording(Nim_sequence& seq) {
void Nim_system::start_recording(Nim_sequence& seq)
{
_update_lookup_table();
auto affected_entities = std::vector<util::Str_id>();
......@@ -251,7 +257,8 @@ namespace mirrage::systems {
seq = Nim_sequence(affected_entities);
}
void Nim_system::record(util::Time length, Nim_sequence& seq) {
void Nim_system::record(util::Time length, Nim_sequence& seq)
{
seq.push_back(length, [&](const auto& entity_uid) {
auto iter = _affected_entities.find(entity_uid);
if(iter == _affected_entities.end())
......@@ -270,7 +277,8 @@ namespace mirrage::systems {
});
}
void Nim_system::_update_lookup_table() {
void Nim_system::_update_lookup_table()
{
_affected_entities.clear();
for(auto& nim_comp : _nim_components) {
_affected_entities.emplace(nim_comp.uid(), nim_comp.owner());
......
......@@ -39,7 +39,9 @@ namespace mirrage::systems {
Nim_sequence() = default;
Nim_sequence(std::vector<util::Str_id> affected_entities)
: _affected_entities(std::move(affected_entities)), _entity_states(_affected_entities.size()) {}
: _affected_entities(std::move(affected_entities)), _entity_states(_affected_entities.size())
{
}
auto affected_entities() const noexcept -> auto& { return _affected_entities; }
......@@ -49,7 +51,8 @@ namespace mirrage::systems {
// F = void(Str_id, vector<vec3>, vector<quat>, vector<Rgba>)
template <typename F>
void apply(F&& callback) const {
void apply(F&& callback) const
{
for(auto i : util::range(_affected_entities.size())) {
callback(_affected_entities[i],
_entity_states[i].positions,
......@@ -60,7 +63,8 @@ namespace mirrage::systems {
// source = std::tuple<vec3, quat, Rgba>(Str_id)
template <typename F>
void push_back(util::Time length, F&& source) {
void push_back(util::Time length, F&& source)
{
_frame_lengths.emplace_back(length);
for(auto i : util::range(_affected_entities.size())) {
......
......@@ -67,7 +67,8 @@ namespace mirrage {
, _performance_log(util::nothing)
, _window_width(engine.window().width())
, _window_height(engine.window().height())
, _window_fullscreen(engine.window().fullscreen() != graphic::Fullscreen::no) {
, _window_fullscreen(engine.window().fullscreen() != graphic::Fullscreen::no)
{
_camera = _meta_system.entities().emplace("camera");
......@@ -193,7 +194,8 @@ namespace mirrage {
}
Test_screen::~Test_screen() noexcept = default;
void Test_screen::_set_preset(int preset_id) {
void Test_screen::_set_preset(int preset_id)
{
if(_selected_preset == preset_id) {
return;
}
......@@ -228,19 +230,22 @@ namespace mirrage {
_update_sun_position();
}
void Test_screen::_on_enter(util::maybe<Screen&> prev) {
void Test_screen::_on_enter(util::maybe<Screen&> prev)
{
_meta_system.shrink_to_fit();
_engine.input().enable_context("main"_strid);
_mailbox.enable();
}
void Test_screen::_on_leave(util::maybe<Screen&> next) {
void Test_screen::_on_leave(util::maybe<Screen&> next)
{
_mailbox.disable();
_engine.input().capture_mouse(false);
}
void Test_screen::_update(util::Time dt) {
void Test_screen::_update(util::Time dt)
{
_mailbox.update_subscriptions();
_record_timer += dt;
......@@ -305,7 +310,8 @@ namespace mirrage {
}
void Test_screen::_draw() {
void Test_screen::_draw()
{
_gui.start_frame();
if(_show_ui) {
......@@ -321,7 +327,8 @@ namespace mirrage {
_meta_system.draw();
}
void Test_screen::_draw_settings_window() {
void Test_screen::_draw_settings_window()
{
auto ctx = _gui.ctx();
if(nk_begin_titled(ctx,
"debug_controls",
......@@ -491,7 +498,8 @@ namespace mirrage {
}
namespace {
auto to_fixed_str(double num, int digits) {
auto to_fixed_str(double num, int digits)
{
auto ss = std::stringstream{};
ss << std::fixed << std::setprecision(digits) << num;
return ss.str();
......@@ -500,7 +508,8 @@ namespace mirrage {
auto pad_left(const std::string& str, int padding) { return std::string(padding, ' ') + str; }
template <std::size_t N, typename Container, typename Comp>
auto top_n(const Container& container, Comp&& less) {
auto top_n(const Container& container, Comp&& less)
{
auto max_elements = std::array<decltype(container.begin()), N>();
max_elements.fill(container.end());
......@@ -522,7 +531,8 @@ namespace mirrage {
}
template <typename Container, typename T>
auto index_of(const Container& container, const T& element) -> int {
auto index_of(const Container& container, const T& element) -> int
{
auto top_entry = std::find(container.begin(), container.end(), element);
if(top_entry == container.end())
return -1;
......@@ -530,7 +540,8 @@ namespace mirrage {
return gsl::narrow<int>(std::distance(container.begin(), top_entry));
}
} // namespace
void Test_screen::_draw_profiler_window() {
void Test_screen::_draw_profiler_window()
{
auto ctx = _gui.ctx();
if(nk_begin_titled(ctx,
"profiler",
......@@ -593,7 +604,8 @@ namespace mirrage {
nk_end(ctx);
}
void Test_screen::_update_sun_position() {
void Test_screen::_update_sun_position()
{
_sun.get<Transform_comp>().process([&](auto& transform) {
transform.orientation(glm::quat(glm::vec3(
(_sun_elevation - 2.f) * glm::pi<float>() / 2.f, glm::pi<float>() * _sun_azimuth, 0.f)));
......
......@@ -30,7 +30,8 @@ namespace mirrage {
void _on_enter(util::maybe<Screen&> prev) override;
void _on_leave(util::maybe<Screen&> next) override;
auto _prev_screen_policy() const noexcept -> Prev_screen_policy override {
auto _prev_screen_policy() const noexcept -> Prev_screen_policy override
{
return Prev_screen_policy::discard;
}
......
......@@ -13,7 +13,8 @@
namespace mirrage {
void create_directory(const std::string& dir) {
void create_directory(const std::string& dir)
{
#ifdef _WIN32
CreateDirectory(dir.c_str(), NULL);
#else
......
......@@ -20,7 +20,8 @@ auto extract_arg(std::vector<std::string>& args, const std::string& key) -> util
// ./mesh_converter sponza.obj
// ./mesh_converter --output=/foo/bar sponza.obj
int main(int argc, char** argv) {
int main(int argc, char** argv)
{
static auto fileAppender =
plog::RollingFileAppender<plog::TxtFormatter>("mesh_converter.log", 4L * 1024L, 4);
static auto consoleAppender = plog::ColorConsoleAppender<plog::TxtFormatter>();
......@@ -46,7 +47,8 @@ int main(int argc, char** argv) {
}
}
auto extract_arg(std::vector<std::string>& args, const std::string& key) -> util::maybe<std::string> {
auto extract_arg(std::vector<std::string>& args, const std::string& key) -> util::maybe<std::string>
{
auto found =
std::find_if(args.begin(), args.end(), [&](auto& str) { return util::starts_with(str, key); });
......
......@@ -53,22 +53,26 @@ namespace mirrage {
};
template <typename T>
auto operator+(const Pixel<T>& lhs, const Pixel<T>& rhs) {
auto operator+(const Pixel<T>& lhs, const Pixel<T>& rhs)
{
return Pixel<T>{lhs.r + rhs.r, lhs.g + rhs.g, lhs.b + rhs.b, lhs.a + rhs.a};
}
template <typename T>
auto operator*(const Pixel<T>& lhs, T rhs) {
auto operator*(const Pixel<T>& lhs, T rhs)
{
return Pixel<T>{lhs.r * rhs, lhs.g * rhs, lhs.b * rhs, lhs.a * rhs};
}
template <typename T>
auto operator*(T lhs, const Pixel<T>& rhs) {
auto operator*(T lhs, const Pixel<T>& rhs)
{
return Pixel<T>{lhs * rhs.r, lhs * rhs.g, lhs * rhs.b, lhs * rhs.a};
}
template <typename T>
auto operator/(const Pixel<T>& lhs, T rhs) {
auto operator/(const Pixel<T>& lhs, T rhs)
{
return Pixel<T>{lhs.r / rhs, lhs.g / rhs, lhs.b / rhs, lhs.a / rhs};
}
......@@ -83,9 +87,8 @@ namespace mirrage {
Image_data() = default;
Image_data(std::uint32_t width, std::uint32_t height)
: width(width)
, height(height)
, mip_levels(std::floor(std::log2(std::min(width, height))) + 1) {
: width(width), height(height), mip_levels(std::floor(std::log2(std::min(width, height))) + 1)
{
for(auto i = 0u; i < mip_levels.size(); i++) {
auto width = std::max(1u, this->width >> i);
auto height = std::max(1u, this->height >> i);
......@@ -94,12 +97,14 @@ namespace mirrage {
}
}
auto& pixel(std::uint32_t level, std::uint32_t x, std::uint32_t y) {
auto& pixel(std::uint32_t level, std::uint32_t x, std::uint32_t y)
{
return mip_levels.at(level).at(y * (width >> level) + x);
}
template <typename F>
void foreach(F&& f) {
void foreach(F&& f)
{
for(std::uint32_t i = 0u; i < mip_levels.size(); i++) {
auto width = std::max(1u, this->width >> i);
auto height = std::max(1u, this->height >> i);
......@@ -112,8 +117,8 @@ namespace mirrage {
}
};
auto get_texture_name(const aiMaterial& material, aiTextureType type)
-> util::maybe<std::string> {
auto get_texture_name(const aiMaterial& material, aiTextureType type) -> util::maybe<std::string>
{
auto count = material.GetTextureCount(type);
if(count == 0)
return util::nothing;
......@@ -124,7 +129,8 @@ namespace mirrage {
return std::string(str.C_Str());
}
auto load_texture2d(const std::string path, bool srgb = true) -> Image_data<float> {
auto load_texture2d(const std::string path, bool srgb = true) -> Image_data<float>
{
int width = 0;
int height = 0;
auto data = stbi_load(path.c_str(), &width, &height, nullptr, 4);
......@@ -136,11 +142,11 @@ namespace mirrage {
for(std::uint32_t y = 0; y < image.height; y++) {
for(std::uint32_t x = 0; x < image.width; x++) {
auto pixel = Pixel<float>{
static_cast<float>(data[(y * image.width + x) * 4 + 0]) / 255.f,
static_cast<float>(data[(y * image.width + x) * 4 + 1]) / 255.f,
static_cast<float>(data[(y * image.width + x) * 4 + 2]) / 255.f,
static_cast<float>(data[(y * image.width + x) * 4 + 3]) / 255.f};
auto pixel =
Pixel<float>{static_cast<float>(data[(y * image.width + x) * 4 + 0]) / 255.f,
static_cast<float>(data[(y * image.width + x) * 4 + 1]) / 255.f,
static_cast<float>(data[(y * image.width + x) * 4 + 2]) / 255.f,
static_cast<float>(data[(y * image.width + x) * 4 + 3]) / 255.f};
if(srgb) {
pixel.r = std::pow(pixel.r, 1.f / 2.2f);
......@@ -157,7 +163,8 @@ namespace mirrage {
}
template <typename T, typename F>
void generate_mip_maps(Image_data<T>& image, F&& f) {
void generate_mip_maps(Image_data<T>& image, F&& f)
{
for(std::uint32_t i = 1u; i < image.mip_levels.size(); i++) {
auto width = std::max(1u, image.width >> i);
auto height = std::max(1u, image.height >> i);
......@@ -172,7 +179,8 @@ namespace mirrage {
}
}
void store_texture(Image_data<float>& image, const std::string& ouput, bool srgb = true) {
void store_texture(Image_data<float>& image, const std::string& ouput, bool srgb = true)
{
if(srgb) {
for(auto& level_data : image.mip_levels) {
for(auto& pixel : level_data) {
......@@ -193,10 +201,10 @@ namespace mirrage {
for(std::uint32_t x = 0; x < width; x++) {
auto src = image.pixel(i, x, y);
auto& dst = rgb8_image.pixel(i, x, y);
dst.r = static_cast<std::uint8_t>(glm::clamp(src.r * 255.f, 0.f, 255.f));
dst.g = static_cast<std::uint8_t>(glm::clamp(src.g * 255.f, 0.f, 255.f));
dst.b = static_cast<std::uint8_t>(glm::clamp(src.b * 255.f, 0.f, 255.f));
dst.a = static_cast<std::uint8_t>(glm::clamp(src.a * 255.f, 0.f, 255.f));
dst.r = static_cast<std::uint8_t>(glm::clamp(src.r * 255.f, 0.f, 255.f));
dst.g = static_cast<std::uint8_t>(glm::clamp(src.g * 255.f, 0.f, 255.f));
dst.b = static_cast<std::uint8_t>(glm::clamp(src.b * 255.f, 0.f, 255.f));
dst.a = static_cast<std::uint8_t>(glm::clamp(src.a * 255.f, 0.f, 255.f));
}
}
}
......@@ -237,12 +245,13 @@ namespace mirrage {
bool convert_material(const std::string& name,
const aiMaterial& material,
const std::string& base_dir,
const std::string& output) {
const std::string& output)
{
auto texture_dir = output + "/textures/";
auto substance_id = util::Str_id(
get_texture_name(material, substamce_id_texture_type).get_or("default"));
auto substance_id =
util::Str_id(get_texture_name(material, substamce_id_texture_type).get_or("default"));
// load and combine textures
auto albedo_name_mb = get_texture_name(material, albedo_texture_type);
......@@ -252,8 +261,7 @@ namespace mirrage {
auto albedo_name = base_dir + "/" + albedo_name_mb.get_or_throw();
auto albedo = load_texture2d(albedo_name);
generate_mip_maps(albedo,
[](auto a, auto b, auto c, auto d) { return (a + b + c + d) / 4.f; });
generate_mip_maps(albedo, [](auto a, auto b, auto c, auto d) { return (a + b + c + d) / 4.f; });
albedo_name = name + "_albedo.ktx";
store_texture(albedo, texture_dir + albedo_name);
......@@ -268,24 +276,19 @@ namespace mirrage {
case "default"_strid:
default:
auto metallic = load_texture2d(
base_dir + "/"
+ get_texture_name(material, metallic_texture_type).get_or_throw(),
base_dir + "/" + get_texture_name(material, metallic_texture_type).get_or_throw(),
false);
auto roughness = load_texture2d(
base_dir + "/"
+ get_texture_name(material, roughness_texture_type).get_or_throw(),
base_dir + "/" + get_texture_name(material, roughness_texture_type).get_or_throw(),
false);
auto normal = load_texture2d(
base_dir + "/"
+ get_texture_name(material, normal_texture_type).get_or_throw(),
base_dir + "/" + get_texture_name(material, normal_texture_type).get_or_throw(),
false);
generate_mip_maps(metallic, [](auto a, auto b, auto c, auto d) {
return (a + b + c + d) / 4.f;
});
generate_mip_maps(roughness, [](auto a, auto b, auto c, auto d) {
return (a + b + c + d) / 4.f;
});
generate_mip_maps(metallic,
[](auto a, auto b, auto c, auto d) { return (a + b + c + d) / 4.f; });
generate_mip_maps(roughness,
[](auto a, auto b, auto c, auto d) { return (a + b + c + d) / 4.f; });
normal.foreach([&](auto& pixel, auto level, auto x, auto y) {
if(level > 0) {
......@@ -294,14 +297,10 @@ namespace mirrage {
auto n_11 = normal.pixel(level - 1, x * 2 + 1, y * 2 + 1);
auto n_01 = normal.pixel(level - 1, x * 2, y * 2 + 1);
auto n = glm::normalize(
glm::vec3(n_00.r * 2 - 1, n_00.g * 2 - 1, n_00.b * 2 - 1))
+ glm::normalize(glm::vec3(
n_10.r * 2 - 1, n_10.g * 2 - 1, n_10.b * 2 - 1))
+ glm::normalize(glm::vec3(
n_11.r * 2 - 1, n_11.g * 2 - 1, n_11.b * 2 - 1))
+ glm::normalize(glm::vec3(
n_01.r * 2 - 1, n_01.g * 2 - 1, n_01.b * 2 - 1));
auto n = glm::normalize(glm::vec3(n_00.r * 2 - 1, n_00.g * 2 - 1, n_00.b * 2 - 1))
+ glm::normalize(glm::vec3(n_10.r * 2 - 1, n_10.g * 2 - 1, n_10.b * 2 - 1))
+ glm::normalize(glm::vec3(n_11.r * 2 - 1, n_11.g *