Commit 22068e60 authored by Florian Oetke's avatar Florian Oetke
Browse files

enabled clang-format (if you are doing a git-blame/bisect: Sorry, but this is...

enabled clang-format (if you are doing a git-blame/bisect: Sorry, but this is not the commit you are looking for *waves hand*)
parent 58e95a81
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
ExperimentalAutoDetectBinPacking: true
BraceWrapping: {AfterClass: false, AfterControlStatement: false, AfterEnum: true,
AfterFunction: false, AfterNamespace: false, AfterObjCDeclaration: false, AfterStruct: false,
AfterUnion: false, BeforeCatch: false, BeforeElse: false, IndentBraces: false}
BreakAfterJavaFieldAnnotations: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true
ColumnLimit: 110
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
IncludeCategories:
- {Priority: 1, Regex: ^<.*\.h>}
- {Priority: 2, Regex: ^<.*}
- {Priority: 3, Regex: .*}
IncludeIsMainRegex: ([-_](test|unittest))?$
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 3
NamespaceIndentation: All
ObjCBlockIndentWidth: 1
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 400
PenaltyBreakFirstLessLess: 200
PenaltyBreakString: 150
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 10000
PointerAlignment: Left
ReflowComments: false
SortIncludes: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: ForIndentation
......@@ -24,3 +24,7 @@ add_subdirectory(demo)
add_subdirectory(mesh_converter)
add_subdirectory(mirrage)
option(ENABLE_CLANG_FORMAT "Includes a clangformat target, that automatically formats the source files." OFF)
if(ENABLE_CLANG_FORMAT)
include(clang-format.cmake)
endif()
# additional target to perform clang-format run, requires clang-format
# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h*)
add_custom_target(
clangformat
COMMAND /usr/bin/clang-format
-i
${ALL_SOURCE_FILES}
)
......@@ -7,41 +7,39 @@
#include <mirrage/renderer/pass/gen_mipmap_pass.hpp>
#include <mirrage/renderer/pass/gi_pass.hpp>
#include <mirrage/renderer/pass/gui_pass.hpp>
#include <mirrage/renderer/pass/ssao_pass.hpp>
#include <mirrage/renderer/pass/shadowmapping_pass.hpp>
#include <mirrage/renderer/pass/ssao_pass.hpp>
#include <mirrage/renderer/pass/taa_pass.hpp>
#include <mirrage/renderer/pass/tone_mapping_pass.hpp>
namespace mirrage {
Game_engine::Game_engine(const std::string& title, std::uint32_t version_major,
std::uint32_t version_minor, bool debug,
int argc, char** argv, char** env)
Game_engine::Game_engine(const std::string& title,
std::uint32_t version_major,
std::uint32_t version_minor,
bool debug,
int argc,
char** argv,
char** env)
: Engine(title, version_major, version_minor, debug, argc, argv, env)
, _renderer_factory(std::make_unique<renderer::Deferred_renderer_factory>(
graphics_context(), window(),
util::make_vector(
renderer::make_pass_factory<renderer::Shadowmapping_pass_factory>(),
renderer::make_pass_factory<renderer::Deferred_pass_factory>(),
renderer::make_pass_factory<renderer::Gen_mipmap_pass_factory>(),
renderer::make_pass_factory<renderer::Ssao_pass_factory>(),
renderer::make_pass_factory<renderer::Gi_pass_factory>(),
renderer::make_pass_factory<renderer::Taa_pass_factory>(),
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>()
)
))
{
}
graphics_context(),
window(),
util::make_vector(renderer::make_pass_factory<renderer::Shadowmapping_pass_factory>(),
renderer::make_pass_factory<renderer::Deferred_pass_factory>(),
renderer::make_pass_factory<renderer::Gen_mipmap_pass_factory>(),
renderer::make_pass_factory<renderer::Ssao_pass_factory>(),
renderer::make_pass_factory<renderer::Gi_pass_factory>(),
renderer::make_pass_factory<renderer::Taa_pass_factory>(),
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>()))) {}
Game_engine::~Game_engine() {
screens().clear(); // destroy all screens before the engine
}
void Game_engine::_on_post_frame(util::Time) {
_renderer_factory->finish_frame();
}
void Game_engine::_on_post_frame(util::Time) { _renderer_factory->finish_frame(); }
}
......@@ -15,22 +15,27 @@
namespace mirrage {
namespace renderer {class Deferred_renderer_factory;}
namespace renderer {
class Deferred_renderer_factory;
}
class Game_engine : public Engine {
public:
Game_engine(const std::string& title, std::uint32_t version_major,
std::uint32_t version_minor, bool debug,
int argc, char** argv, char** env);
~Game_engine();
auto renderer_factory()noexcept -> auto& {return *_renderer_factory;}
protected:
void _on_post_frame(util::Time) override;
private:
std::unique_ptr<renderer::Deferred_renderer_factory> _renderer_factory;
public:
Game_engine(const std::string& title,
std::uint32_t version_major,
std::uint32_t version_minor,
bool debug,
int argc,
char** argv,
char** env);
~Game_engine();
auto renderer_factory() noexcept -> auto& { return *_renderer_factory; }
protected:
void _on_post_frame(util::Time) override;
private:
std::unique_ptr<renderer::Deferred_renderer_factory> _renderer_factory;
};
}
......@@ -17,8 +17,8 @@
#include <SDL2/SDL.h>
#include <glm/vec2.hpp>
#include <iostream>
#include <exception>
#include <iostream>
using namespace mirrage; // import game namespace
using namespace std::string_literals;
......@@ -36,8 +36,8 @@ namespace {
#ifdef main
int main(int argc, char** argv) {
char* noEnv = nullptr;
char** env = &noEnv;
char* noEnv = nullptr;
char** env = &noEnv;
#else
int main(int argc, char** argv, char** env) {
#endif
......@@ -56,9 +56,9 @@ int main(int argc, char** argv, char** env) {
namespace {
constexpr auto app_name = "BachelorProject";
int argc;
char** argv;
char** env;
int argc;
char** argv;
char** env;
void init_env(int argc, char** argv, char** env) {
......@@ -70,19 +70,29 @@ namespace {
::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");
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());
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in init: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in init", nullptr);
shutdown();
exit(1);
......@@ -96,25 +106,25 @@ namespace {
debug = true;
#endif
for(auto i=1; i<argc; i++) {
if(argv[i]=="--debug"s) {
for(auto i = 1; i < argc; i++) {
if(argv[i] == "--debug"s) {
debug = true;
}
if(argv[i]=="--no-debug"s) {
if(argv[i] == "--no-debug"s) {
debug = false;
}
}
engine = std::make_unique<Game_engine>(app_name, 0,1, debug, argc, argv, env);
engine = std::make_unique<Game_engine>(app_name, 0, 1, debug, argc, argv, env);
if(argc>1 && argv[1]=="test"s)
if(argc > 1 && argv[1] == "test"s)
engine->screens().enter<Test_screen>();
else
engine->screens().enter<Test_screen>();
} catch (const util::Error& ex) {
CRASH_REPORT("Exception in init: "<<ex.what());
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in init: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in init", nullptr);
shutdown();
exit(1);
......@@ -125,8 +135,8 @@ namespace {
try {
engine->on_frame();
} catch (const util::Error& ex) {
CRASH_REPORT("Exception in onFrame: "<<ex.what());
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in onFrame: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in onFrame", nullptr);
shutdown();
exit(2);
......@@ -137,8 +147,8 @@ namespace {
try {
engine.reset();
} catch (const util::Error& ex) {
CRASH_REPORT("Exception in shutdown: "<<ex.what());
} catch(const util::Error& ex) {
CRASH_REPORT("Exception in shutdown: " << ex.what());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sorry :-(", "Error in shutdown", nullptr);
exit(3);
}
......
......@@ -10,10 +10,10 @@
namespace mirrage {
Meta_system::Meta_system(Game_engine& engine)
: _entities(engine.assets(), this)
, _renderer(engine.renderer_factory().create_renderer(_entities, *this))
, _model_loading(std::make_unique<renderer::Loading_system>(_entities, _renderer->model_loader()))
, _nims(std::make_unique<systems::Nim_system>(_entities)) {
: _entities(engine.assets(), this)
, _renderer(engine.renderer_factory().create_renderer(_entities, *this))
, _model_loading(std::make_unique<renderer::Loading_system>(_entities, _renderer->model_loader()))
, _nims(std::make_unique<systems::Nim_system>(_entities)) {
_entities.register_component_type<ecs::components::Transform_comp>();
}
......@@ -29,12 +29,7 @@ namespace mirrage {
_model_loading->update(dt);
_renderer->update(dt);
}
void Meta_system::draw() {
_renderer->draw();
}
void Meta_system::shrink_to_fit() {
_renderer->shrink_to_fit();
}
void Meta_system::draw() { _renderer->draw(); }
void Meta_system::shrink_to_fit() { _renderer->shrink_to_fit(); }
}
......@@ -6,30 +6,35 @@
namespace mirrage {
namespace renderer {class Deferred_renderer;}
namespace renderer {class Loading_system;}
namespace systems {class Nim_system;}
namespace renderer {
class Deferred_renderer;
}
namespace renderer {
class Loading_system;
}
namespace systems {
class Nim_system;
}
class Meta_system {
public:
Meta_system(Game_engine&);
~Meta_system();
public:
Meta_system(Game_engine&);
~Meta_system();
void update(util::Time dt);
void draw();
void update(util::Time dt);
void draw();
void shrink_to_fit();
void shrink_to_fit();
auto entities()noexcept -> auto& {return _entities;}
auto renderer()noexcept -> auto& {return *_renderer;}
auto nims ()noexcept -> auto& {return *_nims;}
auto entities() noexcept -> auto& { return _entities; }
auto renderer() noexcept -> auto& { return *_renderer; }
auto nims() noexcept -> auto& { return *_nims; }
private:
ecs::Entity_manager _entities;
std::unique_ptr<renderer::Deferred_renderer> _renderer;
std::unique_ptr<renderer::Loading_system> _model_loading;
std::unique_ptr<systems::Nim_system> _nims;
private:
ecs::Entity_manager _entities;
std::unique_ptr<renderer::Deferred_renderer> _renderer;
std::unique_ptr<renderer::Loading_system> _model_loading;
std::unique_ptr<systems::Nim_system> _nims;
};
}
......@@ -2,28 +2,23 @@
#include "nim_system.hpp"
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/ecs/components/transform_comp.hpp>
#include <mirrage/ecs/ecs.hpp>
#include <mirrage/renderer/light_comp.hpp>
#include <mirrage/utils/sf2_glm.hpp>
#include <mirrage/utils/math.hpp>
#include <mirrage/utils/sf2_glm.hpp>
namespace mirrage {
namespace systems {
namespace mirrage::systems {
using namespace util::unit_literals;
void load_component(ecs::Deserializer& state, Nim_comp& comp) {
state.read_virtual(
sf2::vmember("uid", comp._uid)
);
state.read_virtual(sf2::vmember("uid", comp._uid));
}
void save_component(ecs::Serializer& state, const Nim_comp& comp) {
state.write_virtual(
sf2::vmember("uid", comp._uid)
);
state.write_virtual(sf2::vmember("uid", comp._uid));
}
namespace {
......@@ -73,10 +68,10 @@ namespace systems {
for(auto i : util::range(seq._affected_entities.size())) {
auto& entity_uid = seq._affected_entities[i];
auto& state = seq._entity_states.at(i);
auto& state = seq._entity_states.at(i);
auto iter = frame.entities.find(entity_uid);
if(iter!=frame.entities.end()) {
if(iter != frame.entities.end()) {
state.positions.emplace_back(iter->second.position);
state.orientations.emplace_back(iter->second.orientation);
state.light_colors.emplace_back(iter->second.light_color);
......@@ -100,14 +95,14 @@ namespace systems {
frames.reserve(seq.frames());
for(auto i : util::range(seq.frames())) {
auto& frame = frames.emplace_back();
auto& frame = frames.emplace_back();
frame.length = seq._frame_lengths.at(i) / second;
for(auto j : util::range(seq._affected_entities.size())) {
auto& entity_state = seq._entity_states[j];
auto position = entity_state.positions[i];
auto orientation = glm::eulerAngles(entity_state.orientations[i]);
auto light_color = entity_state.light_colors[i];
auto position = entity_state.positions[i];
auto orientation = glm::eulerAngles(entity_state.orientations[i]);
auto light_color = entity_state.light_colors[i];
frame.entities.emplace(seq._affected_entities[j],
Frame_obj_data{position, orientation, light_color});
}
......@@ -116,12 +111,10 @@ namespace systems {
s.write_virtual(sf2::vmember("frames", frames));
}
Nim_system::Nim_system(ecs::Entity_manager& ecs)
: _nim_components(ecs.list<Nim_comp>()) {
}
Nim_system::Nim_system(ecs::Entity_manager& ecs) : _nim_components(ecs.list<Nim_comp>()) {}
namespace {
template<class T>
template <class T>
auto catmull_rom(float t, const std::vector<T>& points, float closed) -> T {
INVARIANT(!points.empty(), "Can't interpolate between zero points!");
......@@ -134,7 +127,7 @@ namespace systems {
// clamp points
if(closed) {
P0_idx = P0_idx % points.size();
if(P0_idx<0) {
if(P0_idx < 0) {
P0_idx = points.size() + P0_idx;
}
P1_idx = P1_idx % points.size();
......@@ -143,7 +136,7 @@ namespace systems {
} else {
P0_idx = util::min(P0_idx, points.size());
P1_idx = P0_idx>0 ? P0_idx-1 : P0_idx;
P1_idx = P0_idx > 0 ? P0_idx - 1 : P0_idx;
P2_idx = util::min(P2_idx, points.size());
P3_idx = util::min(P3_idx, points.size());
}
......@@ -155,16 +148,13 @@ namespace systems {
auto P3 = points.at(P3_idx);
// calc relativ t
auto rt = std::fmod(t, 1.f);
auto rt2 = rt*rt;
auto rt3 = rt2*rt;
auto rt = std::fmod(t, 1.f);
auto rt2 = rt * rt;
auto rt3 = rt2 * rt;
// interpolate point
return 0.5f * (
(2.f * P1)
+ (-P0 + P2)*rt
+ (2.f * P0 + -5.f*P1 + 4.f*P2 + -P3) * rt2
+ (-P0 + 3.f*P1 + -3.f*P2 + P3) * rt3);
return 0.5f * ((2.f * P1) + (-P0 + P2) * rt + (2.f * P0 + -5.f * P1 + 4.f * P2 + -P3) * rt2
+ (-P0 + 3.f * P1 + -3.f * P2 + P3) * rt3);
}
}
......@@ -172,33 +162,33 @@ namespace systems {
if(!_playing)
return;
_current_position += dt /_playing->frame_length(static_cast<int>(_current_position))
* _playback_speed;
_current_position +=
dt / _playing->frame_length(static_cast<int>(_current_position)) * _playback_speed;
if(_loop) {
_current_position = std::fmod(_current_position, _playing->frames());
}
auto reached_end = _current_position>=_end_position && !_loop;
auto reached_end = _current_position >= _end_position && !_loop;
if(reached_end) {
_current_position = _end_position;
}
_playing->apply([&](const auto& entity_uid, const auto& positions, const auto& orientations,
const auto& colors) {
_playing->apply([&](
const auto& entity_uid, const auto& positions, const auto& orientations, const auto& colors) {
auto iter = _affected_entities.find(entity_uid);
if(iter!=_affected_entities.end()) {
ecs::Entity_facet& entity = iter->second;
auto& transform = entity.get<ecs::components::Transform_comp>().get_or_throw();
if(iter != _affected_entities.end()) {
ecs::Entity_facet& entity = iter->second;
auto& transform = entity.get<ecs::components::Transform_comp>().get_or_throw();
auto idx_0 = static_cast<int>(std::floor(_current_position));
auto idx_1 = _loop ? (idx_0 + 1) % orientations.size()
: util::min(idx_0 + 1, orientations.size());
auto t = std::fmod(_current_position, 1.f);
auto idx_1 =
_loop ? (idx_0 + 1) % orientations.size() : util::min(idx_0 + 1, orientations.size());
auto t = std::fmod(_current_position, 1.f);
auto orientation = glm::slerp(orientations[idx_0], orientations[idx_1], t);
auto position = catmull_rom(_current_position, positions, _loop);
auto position = catmull_rom(_current_position, positions, _loop);
auto light_color = catmull_rom(_current_position, colors, _loop);
......@@ -224,19 +214,17 @@ namespace systems {
_update_lookup_table();
_playback_speed = speed;
_playback_speed = speed;
_current_position = begin;
_end_position = end>=0 ? end : _playing->frames();
_loop = false;
_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();