diff --git a/bloss1/src/ecs/scene_parser.cpp b/bloss1/src/ecs/scene_parser.cpp index 36f2ad3..e42c421 100644 --- a/bloss1/src/ecs/scene_parser.cpp +++ b/bloss1/src/ecs/scene_parser.cpp @@ -589,19 +589,19 @@ namespace bls vec3 fog_color = read_vec3(&iline, ','); vec2 min_max = read_vec2(&iline, ','); - for (auto &pass : AppConfig::render_passes) + auto it = std::find_if(AppConfig::render_passes.begin(), + AppConfig::render_passes.end(), + [](const auto &pass) { return typeid(*pass.pass) == typeid(FogPass); }); + + if (it != AppConfig::render_passes.end()) { - if (typeid(*pass.pass) == typeid(FogPass)) - { - auto *fog_pass = static_cast(pass.pass); - fog_pass->fog_color = fog_color; - fog_pass->min_max = min_max; - - pass.enabled = std::stoul(enabled); - pass.position = std::stoul(position); - post_processing->set_pass(pass.id, pass.enabled, pass.position); - break; - } + auto *fog_pass = static_cast(it->pass); + fog_pass->fog_color = fog_color; + fog_pass->min_max = min_max; + + it->enabled = std::stoul(enabled); + it->position = std::stoul(position); + post_processing->set_pass(it->id, it->enabled, it->position); } } @@ -617,21 +617,21 @@ namespace bls std::getline(iline, threshold, ','); std::getline(iline, amount, ';'); - for (auto &pass : AppConfig::render_passes) + auto it = std::find_if(AppConfig::render_passes.begin(), + AppConfig::render_passes.end(), + [](const auto &pass) { return typeid(*pass.pass) == typeid(BloomPass); }); + + if (it != AppConfig::render_passes.end()) { - if (typeid(*pass.pass) == typeid(BloomPass)) - { - auto *bloom_pass = static_cast(pass.pass); - bloom_pass->samples = std::stoul(samples); - bloom_pass->spread = std::stof(spread); - bloom_pass->threshold = std::stof(threshold); - bloom_pass->amount = std::stof(amount); - - pass.enabled = std::stoul(enabled); - pass.position = std::stoul(position); - post_processing->set_pass(pass.id, pass.enabled, pass.position); - break; - } + auto *bloom_pass = static_cast(it->pass); + bloom_pass->samples = std::stoul(samples); + bloom_pass->spread = std::stof(spread); + bloom_pass->threshold = std::stof(threshold); + bloom_pass->amount = std::stof(amount); + + it->enabled = std::stoul(enabled); + it->position = std::stoul(position); + post_processing->set_pass(it->id, it->enabled, it->position); } } @@ -644,18 +644,18 @@ namespace bls str amount; std::getline(iline, amount, ';'); - for (auto &pass : AppConfig::render_passes) + auto it = std::find_if(AppConfig::render_passes.begin(), + AppConfig::render_passes.end(), + [](const auto &pass) { return typeid(*pass.pass) == typeid(SharpenPass); }); + + if (it != AppConfig::render_passes.end()) { - if (typeid(*pass.pass) == typeid(SharpenPass)) - { - auto *sharpen_pass = static_cast(pass.pass); - sharpen_pass->amount = std::stof(amount); - - pass.enabled = std::stoul(enabled); - pass.position = std::stoul(position); - post_processing->set_pass(pass.id, pass.enabled, pass.position); - break; - } + auto *sharpen_pass = static_cast(it->pass); + sharpen_pass->amount = std::stof(amount); + + it->enabled = std::stoul(enabled); + it->position = std::stoul(position); + post_processing->set_pass(it->id, it->enabled, it->position); } } @@ -670,18 +670,19 @@ namespace bls str levels; std::getline(iline, levels, ';'); - for (auto &pass : AppConfig::render_passes) + auto it = + std::find_if(AppConfig::render_passes.begin(), + AppConfig::render_passes.end(), + [](const auto &pass) { return typeid(*pass.pass) == typeid(PosterizationPass); }); + + if (it != AppConfig::render_passes.end()) { - if (typeid(*pass.pass) == typeid(PosterizationPass)) - { - auto *post_pass = static_cast(pass.pass); - post_pass->levels = std::stof(levels); - - pass.enabled = std::stoul(enabled); - pass.position = std::stoul(position); - post_processing->set_pass(pass.id, pass.enabled, pass.position); - break; - } + auto *post_pass = static_cast(it->pass); + post_pass->levels = std::stof(levels); + + it->enabled = std::stoul(enabled); + it->position = std::stoul(position); + post_processing->set_pass(it->id, it->enabled, it->position); } } @@ -696,18 +697,18 @@ namespace bls str pixel_size; std::getline(iline, pixel_size, ';'); - for (auto &pass : AppConfig::render_passes) + auto it = std::find_if(AppConfig::render_passes.begin(), + AppConfig::render_passes.end(), + [](const auto &pass) { return typeid(*pass.pass) == typeid(PixelizationPass); }); + + if (it != AppConfig::render_passes.end()) { - if (typeid(*pass.pass) == typeid(PixelizationPass)) - { - auto *pixel_pass = static_cast(pass.pass); - pixel_pass->pixel_size = std::stoul(pixel_size); - - pass.enabled = std::stoul(enabled); - pass.position = std::stoul(position); - post_processing->set_pass(pass.id, pass.enabled, pass.position); - break; - } + auto *pixel_pass = static_cast(it->pass); + pixel_pass->pixel_size = std::stoul(pixel_size); + + it->enabled = std::stoul(enabled); + it->position = std::stoul(position); + post_processing->set_pass(it->id, it->enabled, it->position); } } @@ -717,15 +718,15 @@ namespace bls std::getline(iline, position, ','); std::getline(iline, enabled, ';'); - for (auto &pass : AppConfig::render_passes) + auto it = std::find_if(AppConfig::render_passes.begin(), + AppConfig::render_passes.end(), + [](const auto &pass) { return typeid(*pass.pass) == typeid(PixelizationPass); }); + + if (it != AppConfig::render_passes.end()) { - if (typeid(*pass.pass) == typeid(FXAAPass)) - { - pass.enabled = std::stoul(enabled); - pass.position = std::stoul(position); - post_processing->set_pass(pass.id, pass.enabled, pass.position); - break; - } + it->enabled = std::stoul(enabled); + it->position = std::stoul(position); + post_processing->set_pass(it->id, it->enabled, it->position); } } } diff --git a/bloss1/src/renderer/opengl/shader.cpp b/bloss1/src/renderer/opengl/shader.cpp index a97c54d..cf4c094 100644 --- a/bloss1/src/renderer/opengl/shader.cpp +++ b/bloss1/src/renderer/opengl/shader.cpp @@ -90,14 +90,9 @@ namespace bls std::vector error_message(log_length + 1); glGetProgramInfoLog(id, log_length, NULL, &error_message[0]); - str error = ""; - for (auto c : error_message) - { - error += c; - } LOG_ERROR("linking program"); LOG_ERROR("error when linking shader: '%s'", vertex_path.c_str()); - LOG_ERROR("error when linking program: '%s'", error.c_str()); + LOG_ERROR("error when linking program: '%s'", error_message.data()); throw std::runtime_error( "failed to link " @@ -140,12 +135,7 @@ namespace bls std::vector error_message(log_length + 1); glGetShaderInfoLog(ID, log_length, NULL, &error_message[0]); - str error = ""; - for (auto c : error_message) - { - error += c; - } - LOG_ERROR("error when compiling '%s': %s", path.c_str(), error.c_str()); + LOG_ERROR("error when compiling '%s': %s", path.c_str(), error_message.data()); } } diff --git a/justfile b/justfile index 081393d..2669600 100644 --- a/justfile +++ b/justfile @@ -1,13 +1,13 @@ set positional-arguments -@default: (build "profile") (run "profile") +@default: (lint) (format) (build "profile") (run "profile") -@debug: (build "debug") (run "debug") -@profile: (build "profile") (run "profile") -@release: (build "release") (run "release") +@debug: (lint) (format) (build "debug") (run "debug") +@profile: (lint) (format) (build "profile") (run "profile") +@release: (lint) (format) (build "release") (run "release") @lint: - cppcheck --enable=warning,performance,portability,unusedFunction,style,information --disable=missingInclude --std=c++20 bloss1/src/** + cppcheck --enable=warning,performance,portability,style,information --disable=missingInclude --std=c++20 bloss1/src/** @format: find bloss1/src/ -iname *.hpp -o -iname *.cpp | xargs clang-format -i -style=file