diff options
102 files changed, 2004 insertions, 1481 deletions
diff --git a/.clang-format b/.clang-format index 1ee37ec..9ebf218 100644 --- a/.clang-format +++ b/.clang-format @@ -24,6 +24,9 @@ AlignEscapedNewlines: DontAlign BreakBeforeBinaryOperators: All AlwaysBreakTemplateDeclarations: Yes PackConstructorInitializers: CurrentLine +# only option that doesn't result in copious indentation +AlignAfterOpenBracket: BlockIndent +SpaceBeforeCpp11BracedList: true ... # vim: ft=yaml diff --git a/game/GameScene.cpp b/game/GameScene.cpp index 91da092..2511567 100644 --- a/game/GameScene.cpp +++ b/game/GameScene.cpp @@ -29,34 +29,36 @@ void GameScene::load_scene() { BackgroundSubScene background(*this); GameObject camera = new_object("camera", "camera", vec2(650, 0)); - camera.add_component<Camera>(ivec2(990, 720), vec2(VIEWPORT_X, VIEWPORT_Y), - Camera::Data{ - .bg_color = Color::RED, - }); + camera.add_component<Camera>( + ivec2(990, 720), vec2(VIEWPORT_X, VIEWPORT_Y), + Camera::Data { + .bg_color = Color::RED, + } + ); camera.add_component<BehaviorScript>().set_script<MoveCameraManualyScript>(); - camera.add_component<Rigidbody>(Rigidbody::Data{}); + camera.add_component<Rigidbody>(Rigidbody::Data {}); PlayerSubScene player(*this); GameObject floor = new_object("floor", "game_world", vec2(0, 325)); - floor.add_component<Rigidbody>(Rigidbody::Data{ + floor.add_component<Rigidbody>(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_TOP, }); floor.add_component<BoxCollider>(vec2(INFINITY, 200)); GameObject floor_low = new_object("floor_low", "game_world", vec2(0, 350)); - floor_low.add_component<Rigidbody>(Rigidbody::Data{ + floor_low.add_component<Rigidbody>(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_LOW, }); floor_low.add_component<BoxCollider>(vec2(INFINITY, 200)); GameObject floor_high = new_object("floor_high", "game_world", vec2(0, 300)); - floor_high.add_component<Rigidbody>(Rigidbody::Data{ + floor_high.add_component<Rigidbody>(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_HIGH, }); GameObject ceiling = new_object("ceiling", "game_world", vec2(0, -325)); - ceiling.add_component<Rigidbody>(Rigidbody::Data{ + ceiling.add_component<Rigidbody>(Rigidbody::Data { .body_type = Rigidbody::BodyType::STATIC, .collision_layer = COLL_LAY_BOT_TOP, }); diff --git a/game/MoveCameraManualyScript.cpp b/game/MoveCameraManualyScript.cpp index 0181333..9d75a75 100644 --- a/game/MoveCameraManualyScript.cpp +++ b/game/MoveCameraManualyScript.cpp @@ -4,8 +4,9 @@ using namespace crepe; using namespace std; void MoveCameraManualyScript::init() { - subscribe<KeyPressEvent>( - [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); + subscribe<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool { + return this->keypressed(ev); + }); } bool MoveCameraManualyScript::keypressed(const KeyPressEvent & event) { diff --git a/game/PlayerSubScene.cpp b/game/PlayerSubScene.cpp index b361a82..00b7810 100644 --- a/game/PlayerSubScene.cpp +++ b/game/PlayerSubScene.cpp @@ -13,46 +13,58 @@ using namespace std; PlayerSubScene::PlayerSubScene(Scene & scn) { GameObject player = scn.new_object("player", "player", vec2(-100, 200)); - Asset player_body_asset{"asset/barry/defaultBody.png"}; + Asset player_body_asset {"asset/barry/defaultBody.png"}; Sprite & player_body_sprite = player.add_component<Sprite>( - player_body_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 0, - .size = vec2(0, 50), - }); - player.add_component<Animator>(player_body_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data{ - .fps = 5, - .looping = true, - }); - Asset player_head_asset{"asset/barry/defaultHead.png"}; + player_body_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 0, + .size = vec2(0, 50), + } + ); + player.add_component<Animator>( + player_body_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_head_asset {"asset/barry/defaultHead.png"}; Sprite & player_head_sprite = player.add_component<Sprite>( - player_head_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 1, - .size = vec2(0, 50), - .position_offset = vec2(0, -20), - }); - player.add_component<Animator>(player_head_sprite, ivec2(32, 32), uvec2(4, 8), - Animator::Data{ - .fps = 5, - .looping = true, - }); - Asset player_jetpack_asset{"asset/barry/jetpackDefault.png"}; + player_head_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 1, + .size = vec2(0, 50), + .position_offset = vec2(0, -20), + } + ); + player.add_component<Animator>( + player_head_sprite, ivec2(32, 32), uvec2(4, 8), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + Asset player_jetpack_asset {"asset/barry/jetpackDefault.png"}; Sprite & player_jetpack_sprite = player.add_component<Sprite>( - player_jetpack_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_PLAYER, - .order_in_layer = 2, - .size = vec2(0, 60), - .position_offset = vec2(-20, 0), - }); + player_jetpack_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_PLAYER, + .order_in_layer = 2, + .size = vec2(0, 60), + .position_offset = vec2(-20, 0), + } + ); player_jetpack_sprite.active = false; - player.add_component<Animator>(player_jetpack_sprite, ivec2(32, 44), uvec2(4, 4), - Animator::Data{ - .fps = 5, - .looping = true, - }); - player.add_component<Rigidbody>(Rigidbody::Data{ + player.add_component<Animator>( + player_jetpack_sprite, ivec2(32, 44), uvec2(4, 4), + Animator::Data { + .fps = 5, + .looping = true, + } + ); + player.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 20, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = vec2(100, 0), diff --git a/game/background/AquariumSubScene.cpp b/game/background/AquariumSubScene.cpp index 579e633..8d5202a 100644 --- a/game/background/AquariumSubScene.cpp +++ b/game/background/AquariumSubScene.cpp @@ -16,73 +16,85 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { GameObject aquarium_begin = scn.new_object("aquarium_begin", "background", vec2(begin_x, 0)); - Asset aquarium_begin_asset{"asset/background/aquarium/glassTubeFG_1_TVOS.png"}; - aquarium_begin.add_component<Sprite>(aquarium_begin_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_begin_asset {"asset/background/aquarium/glassTubeFG_1_TVOS.png"}; + aquarium_begin.add_component<Sprite>( + aquarium_begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; GameObject aquarium_middle_1 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_1_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_1.add_component<Sprite>(aquarium_middle_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_1_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_1.add_component<Sprite>( + aquarium_middle_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; this->add_background(scn, begin_x - 200); GameObject aquarium_middle_2 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_2_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_2.add_component<Sprite>(aquarium_middle_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 3, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_2_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_2.add_component<Sprite>( + aquarium_middle_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; GameObject aquarium_middle_3 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_3_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_3.add_component<Sprite>(aquarium_middle_3_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 4, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_3_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_3.add_component<Sprite>( + aquarium_middle_3_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 4, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; this->add_background(scn, begin_x - 200); GameObject aquarium_middle_4 = scn.new_object("aquarium_middle", "background", vec2(begin_x, 0)); - Asset aquarium_middle_4_asset{"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; - aquarium_middle_4.add_component<Sprite>(aquarium_middle_4_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_middle_4_asset {"asset/background/aquarium/glassTubeFG_3_TVOS.png"}; + aquarium_middle_4.add_component<Sprite>( + aquarium_middle_4_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; this->add_background(scn, begin_x); GameObject aquarium_end = scn.new_object("aquarium_end", "background", vec2(begin_x, 0)); - Asset aquarium_end_asset{"asset/background/aquarium/glassTubeFG_2_TVOS.png"}; - aquarium_end.add_component<Sprite>(aquarium_end_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset aquarium_end_asset {"asset/background/aquarium/glassTubeFG_2_TVOS.png"}; + aquarium_end.add_component<Sprite>( + aquarium_end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; return begin_x; @@ -90,54 +102,66 @@ float AquariumSubScene::create(Scene & scn, float begin_x) { void AquariumSubScene::add_background(Scene & scn, float begin_x) { GameObject bg_1 = scn.new_object("aquarium_bg_1", "aquarium_background", vec2(begin_x, 0)); - Asset bg_1_1_asset{"asset/background/aquarium/AquariumBG1_1_TVOS.png"}; - bg_1.add_component<Sprite>(bg_1_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(-200, 100), - }); - Asset bg_1_2_asset{"asset/background/aquarium/AquariumBG1_2_TVOS.png"}; - bg_1.add_component<Sprite>(bg_1_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, 400), - .position_offset = vec2(200, 100), - }); + Asset bg_1_1_asset {"asset/background/aquarium/AquariumBG1_1_TVOS.png"}; + bg_1.add_component<Sprite>( + bg_1_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(-200, 100), + } + ); + Asset bg_1_2_asset {"asset/background/aquarium/AquariumBG1_2_TVOS.png"}; + bg_1.add_component<Sprite>( + bg_1_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 400), + .position_offset = vec2(200, 100), + } + ); GameObject bg_2 = scn.new_object("aquarium_bg_2", "aquarium_background", vec2(begin_x, 0)); - Asset bg_2_1_asset{"asset/background/aquarium/AquariumBG2_1_TVOS.png"}; - bg_2.add_component<Sprite>(bg_2_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, -50), - }); - Asset bg_2_2_asset{"asset/background/aquarium/AquariumBG2_2_TVOS.png"}; - bg_2.add_component<Sprite>(bg_2_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, -50), - }); + Asset bg_2_1_asset {"asset/background/aquarium/AquariumBG2_1_TVOS.png"}; + bg_2.add_component<Sprite>( + bg_2_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, -50), + } + ); + Asset bg_2_2_asset {"asset/background/aquarium/AquariumBG2_2_TVOS.png"}; + bg_2.add_component<Sprite>( + bg_2_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, -50), + } + ); GameObject bg_3 = scn.new_object("aquarium_bg_3", "aquarium_background", vec2(begin_x, 0)); - Asset bg_3_1_asset{"asset/background/aquarium/AquariumBG3_1_TVOS.png"}; - bg_3.add_component<Sprite>(bg_3_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(200, -200), - }); - Asset bg_3_2_asset{"asset/background/aquarium/AquariumBG3_2_TVOS.png"}; - bg_3.add_component<Sprite>(bg_3_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 400), - .position_offset = vec2(-200, -200), - }); + Asset bg_3_1_asset {"asset/background/aquarium/AquariumBG3_1_TVOS.png"}; + bg_3.add_component<Sprite>( + bg_3_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(200, -200), + } + ); + Asset bg_3_2_asset {"asset/background/aquarium/AquariumBG3_2_TVOS.png"}; + bg_3.add_component<Sprite>( + bg_3_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 400), + .position_offset = vec2(-200, -200), + } + ); } diff --git a/game/background/ForestParallaxScript.cpp b/game/background/ForestParallaxScript.cpp index 27e30eb..c72f85d 100644 --- a/game/background/ForestParallaxScript.cpp +++ b/game/background/ForestParallaxScript.cpp @@ -3,8 +3,9 @@ using namespace crepe; using namespace std; -ForestParallaxScript::ForestParallaxScript(float begin_x, float end_x, - std::string unique_bg_name) +ForestParallaxScript::ForestParallaxScript( + float begin_x, float end_x, std::string unique_bg_name +) : begin_x(begin_x), end_x(end_x), name(unique_bg_name) {} diff --git a/game/background/ForestSubScene.cpp b/game/background/ForestSubScene.cpp index 7eac53a..a807a36 100644 --- a/game/background/ForestSubScene.cpp +++ b/game/background/ForestSubScene.cpp @@ -17,52 +17,63 @@ using namespace std; float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_name) { GameObject script = scn.new_object("forest_script", "background"); script.add_component<BehaviorScript>().set_script<ForestParallaxScript>( - begin_x - 400, begin_x + 3000 + 400, unique_bg_name); + begin_x - 400, begin_x + 3000 + 400, unique_bg_name + ); this->add_background(scn, begin_x, unique_bg_name); GameObject begin = scn.new_object("forest_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/forest/forestFG_1_TVOS.png"}; - begin.add_component<Sprite>(begin_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset begin_asset {"asset/background/forest/forestFG_1_TVOS.png"}; + begin.add_component<Sprite>( + begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); GameObject middle_1 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); - Asset middle_1_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_1.add_component<Sprite>(middle_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_1_asset {"asset/background/forest/forestFG_3_TVOS.png"}; + middle_1.add_component<Sprite>( + middle_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); GameObject middle_2 = scn.new_object("forest_middle", "background", vec2(begin_x, 0)); - Asset middle_2_asset{"asset/background/forest/forestFG_3_TVOS.png"}; - middle_2.add_component<Sprite>(middle_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 3, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_2_asset {"asset/background/forest/forestFG_3_TVOS.png"}; + middle_2.add_component<Sprite>( + middle_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 800; this->add_background(scn, begin_x, unique_bg_name); GameObject end = scn.new_object("forest_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/forest/forestFG_2_TVOS.png"}; - end.add_component<Sprite>(end_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset end_asset {"asset/background/forest/forestFG_2_TVOS.png"}; + end.add_component<Sprite>( + end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; this->add_background(scn, begin_x + 200, unique_bg_name); @@ -73,69 +84,84 @@ float ForestSubScene::create(Scene & scn, float begin_x, std::string unique_bg_n void ForestSubScene::add_background(Scene & scn, float begin_x, std::string name) { GameObject bg_1 = scn.new_object("forest_bg_1_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_1_asset{"asset/background/forest/forestBG1_1_TVOS.png"}; - bg_1.add_component<Sprite>(bg_1_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, 800), - }); + Asset bg_1_asset {"asset/background/forest/forestBG1_1_TVOS.png"}; + bg_1.add_component<Sprite>( + bg_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, 800), + } + ); GameObject bg_2 = scn.new_object("forest_bg_2_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_2_1_asset{"asset/background/forest/forestBG2_1_TVOS.png"}; - bg_2.add_component<Sprite>(bg_2_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(200, 0), - }); - Asset bg_2_2_asset{"asset/background/forest/forestBG2_2_TVOS.png"}; - bg_2.add_component<Sprite>(bg_2_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 400), - .position_offset = vec2(-200, 0), - }); + Asset bg_2_1_asset {"asset/background/forest/forestBG2_1_TVOS.png"}; + bg_2.add_component<Sprite>( + bg_2_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(200, 0), + } + ); + Asset bg_2_2_asset {"asset/background/forest/forestBG2_2_TVOS.png"}; + bg_2.add_component<Sprite>( + bg_2_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 400), + .position_offset = vec2(-200, 0), + } + ); GameObject bg_3 = scn.new_object("forest_bg_3_" + name, "forest_background", vec2(begin_x, 0)); - Asset bg_3_1_asset{"asset/background/forest/forestBG3_1_TVOS.png"}; - bg_3.add_component<Sprite>(bg_3_1_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(300, 0), - }); - Asset bg_3_2_asset{"asset/background/forest/forestBG3_2_TVOS.png"}; - bg_3.add_component<Sprite>(bg_3_2_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(100, 0), - }); - Asset bg_3_3_asset{"asset/background/forest/forestBG3_3_TVOS.png"}; - bg_3.add_component<Sprite>(bg_3_3_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-100, 0), - }); - Asset bg_3_4_asset{"asset/background/forest/forestBG3_4_TVOS.png"}; - bg_3.add_component<Sprite>(bg_3_4_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = vec2(-300, 0), - }); - - bg_2.add_component<Rigidbody>(Rigidbody::Data{ + Asset bg_3_1_asset {"asset/background/forest/forestBG3_1_TVOS.png"}; + bg_3.add_component<Sprite>( + bg_3_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(300, 0), + } + ); + Asset bg_3_2_asset {"asset/background/forest/forestBG3_2_TVOS.png"}; + bg_3.add_component<Sprite>( + bg_3_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(100, 0), + } + ); + Asset bg_3_3_asset {"asset/background/forest/forestBG3_3_TVOS.png"}; + bg_3.add_component<Sprite>( + bg_3_3_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-100, 0), + } + ); + Asset bg_3_4_asset {"asset/background/forest/forestBG3_4_TVOS.png"}; + bg_3.add_component<Sprite>( + bg_3_4_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACK_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = vec2(-300, 0), + } + ); + + bg_2.add_component<Rigidbody>(Rigidbody::Data { .linear_velocity = vec2(30, 0), }); - bg_3.add_component<Rigidbody>(Rigidbody::Data{ + bg_3.add_component<Rigidbody>(Rigidbody::Data { .linear_velocity = vec2(40, 0), }); } diff --git a/game/background/HallwaySubScene.cpp b/game/background/HallwaySubScene.cpp index 2aa9bab..4d96c94 100644 --- a/game/background/HallwaySubScene.cpp +++ b/game/background/HallwaySubScene.cpp @@ -11,15 +11,19 @@ using namespace crepe; using namespace std; -float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_num, - Color sector_color) { +float HallwaySubScene::create( + Scene & scn, float begin_x, unsigned int sector_num, Color sector_color +) { GameObject begin = scn.new_object("hallway_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; - begin.add_component<Sprite>(begin_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset begin_asset {"asset/background/hallway/hallway1FG_1_TVOS.png"}; + begin.add_component<Sprite>( + begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; this->add_sector_number(begin, vec2(-200, 0), sector_num, sector_color); @@ -27,104 +31,128 @@ float HallwaySubScene::create(Scene & scn, float begin_x, unsigned int sector_nu this->add_lamp(begin, vec2(430, -120), 9); GameObject middle_1 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_1.add_component<Sprite>(middle_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 2, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_1.add_component<Sprite>( + middle_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 2, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; GameObject middle_2 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_2{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_2.add_component<Sprite>(middle_asset_2, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 3, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset_2 {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_2.add_component<Sprite>( + middle_asset_2, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 3, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 200; GameObject middle_3 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_3{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_3.add_component<Sprite>(middle_asset_3, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 4, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset_3 {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_3.add_component<Sprite>( + middle_asset_3, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 4, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 400; this->add_lamp(middle_3, vec2(0, -120)); GameObject middle_4 = scn.new_object("hallway_middle", "background", vec2(begin_x, 0)); - Asset middle_asset_4{"asset/background/hallway/hallway1FG_2_TVOS.png"}; - middle_4.add_component<Sprite>(middle_asset_4, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, GAME_HEIGHT), - }); + Asset middle_asset_4 {"asset/background/hallway/hallway1FG_2_TVOS.png"}; + middle_4.add_component<Sprite>( + middle_asset_4, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; GameObject end = scn.new_object("hallway_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/hallway/hallway1FG_1_TVOS.png"}; - end.add_component<Sprite>(end_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset end_asset {"asset/background/hallway/hallway1FG_1_TVOS.png"}; + end.add_component<Sprite>( + end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 600; return begin_x; } void HallwaySubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { - Asset lamp_asset{"asset/background/hallway/alarmLight_TVOS.png"}; - obj.add_component<Sprite>(lamp_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset lamp_glow_asset{"asset/background/hallway/alarmGlow_TVOS.png"}; + Asset lamp_asset {"asset/background/hallway/alarmLight_TVOS.png"}; + obj.add_component<Sprite>( + lamp_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset lamp_glow_asset {"asset/background/hallway/alarmGlow_TVOS.png"}; Sprite & lamp_glow_sprite = obj.add_component<Sprite>( - lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 300), - .position_offset = offset - vec2(65, -30), - }); - obj.add_component<Animator>(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), - Animator::Data{ - .fps = fps, - .looping = true, - }); + lamp_glow_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 300), + .position_offset = offset - vec2(65, -30), + } + ); + obj.add_component<Animator>( + lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), + Animator::Data { + .fps = fps, + .looping = true, + } + ); } -void HallwaySubScene::add_sector_number(GameObject & obj, vec2 offset, unsigned int sector_num, - Color sector_color) { - Asset sector_text_asset{"asset/background/hallway/sectorText_TVOS.png"}; - obj.add_component<Sprite>(sector_text_asset, - Sprite::Data{ - .color = sector_color, - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset sector_num_asset{"asset/background/hallway/sectorNumbers_TVOS.png"}; +void HallwaySubScene::add_sector_number( + GameObject & obj, vec2 offset, unsigned int sector_num, Color sector_color +) { + Asset sector_text_asset {"asset/background/hallway/sectorText_TVOS.png"}; + obj.add_component<Sprite>( + sector_text_asset, + Sprite::Data { + .color = sector_color, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset sector_num_asset {"asset/background/hallway/sectorNumbers_TVOS.png"}; Sprite & sector_num_sprite = obj.add_component<Sprite>( - sector_num_asset, Sprite::Data{ - .color = sector_color, - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset + vec2(200, 0), - }); + sector_num_asset, + Sprite::Data { + .color = sector_color, + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset + vec2(200, 0), + } + ); Animator & sector_num_anim = obj.add_component<Animator>( - sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data{}); + sector_num_sprite, ivec2(256, 128), uvec2(4, 4), Animator::Data {} + ); int column = (sector_num - 1) / 4; int row = (sector_num - 1) % 4; sector_num_anim.set_anim(column); diff --git a/game/background/HallwaySubScene.h b/game/background/HallwaySubScene.h index acc9329..c38b4a9 100644 --- a/game/background/HallwaySubScene.h +++ b/game/background/HallwaySubScene.h @@ -10,12 +10,15 @@ class Color; class HallwaySubScene { public: - float create(crepe::Scene & scn, float begin_x, unsigned int sector_num, - crepe::Color sector_color); + float create( + crepe::Scene & scn, float begin_x, unsigned int sector_num, crepe::Color sector_color + ); private: void add_lamp(crepe::GameObject & obj, crepe::vec2 offset, unsigned int fps = 10); - void add_sector_number(crepe::GameObject & obj, crepe::vec2 offset, - unsigned int sector_num, crepe::Color sector_color); + void add_sector_number( + crepe::GameObject & obj, crepe::vec2 offset, unsigned int sector_num, + crepe::Color sector_color + ); }; diff --git a/game/background/StartSubScene.cpp b/game/background/StartSubScene.cpp index a918c05..d68287b 100644 --- a/game/background/StartSubScene.cpp +++ b/game/background/StartSubScene.cpp @@ -18,20 +18,25 @@ float StartSubScene::create(Scene & scn, float begin_x) { this->create_wall_fragments(scn, begin_x - 300); GameObject begin = scn.new_object("start_begin", "background", vec2(begin_x, 0)); - Asset begin_asset{"asset/background/start/titleFG_1_TVOS.png"}; - begin.add_component<Sprite>(begin_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, GAME_HEIGHT), - }); + Asset begin_asset {"asset/background/start/titleFG_1_TVOS.png"}; + begin.add_component<Sprite>( + begin_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, GAME_HEIGHT), + } + ); GameObject hole = scn.new_object("start_hole", "background", vec2(begin_x - 250, 140)); - Asset hole_asset{"asset/background/start/titleWallHole.png"}; + Asset hole_asset {"asset/background/start/titleWallHole.png"}; Sprite & hole_sprite = hole.add_component<Sprite>( - hole_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 200), - }); + hole_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 200), + } + ); hole_sprite.active = false; begin_x += 700; @@ -40,12 +45,15 @@ float StartSubScene::create(Scene & scn, float begin_x) { this->add_jetpack_stand(begin, vec2(-125, 200)); GameObject end = scn.new_object("start_end", "background", vec2(begin_x, 0)); - Asset end_asset{"asset/background/start/titleFG_2_TVOS.png"}; - end.add_component<Sprite>(end_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, GAME_HEIGHT), - }); + Asset end_asset {"asset/background/start/titleFG_2_TVOS.png"}; + end.add_component<Sprite>( + end_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, GAME_HEIGHT), + } + ); begin_x += 100; this->add_lamp(end, vec2(-350, -95)); @@ -54,114 +62,143 @@ float StartSubScene::create(Scene & scn, float begin_x) { } void StartSubScene::add_lamp(GameObject & obj, vec2 offset, unsigned int fps) { - Asset lamp_asset{"asset/background/start/alarmLight_TVOS.png"}; - obj.add_component<Sprite>(lamp_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset lamp_glow_asset{"asset/background/start/alarmGlow_TVOS.png"}; + Asset lamp_asset {"asset/background/start/alarmLight_TVOS.png"}; + obj.add_component<Sprite>( + lamp_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset lamp_glow_asset {"asset/background/start/alarmGlow_TVOS.png"}; Sprite & lamp_glow_sprite = obj.add_component<Sprite>( - lamp_glow_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 300), - .position_offset = offset - vec2(65, -55), - }); + lamp_glow_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 300), + .position_offset = offset - vec2(65, -55), + } + ); lamp_glow_sprite.active = false; - obj.add_component<Animator>(lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), - Animator::Data{ - .fps = fps, - .looping = true, - }); + obj.add_component<Animator>( + lamp_glow_sprite, ivec2(422, 384), uvec2(6, 1), + Animator::Data { + .fps = fps, + .looping = true, + } + ); } void StartSubScene::add_table(GameObject & obj, vec2 offset) { - Asset table_asset{"asset/background/start/table.png"}; - obj.add_component<Sprite>(table_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset, - }); - Asset gramophone_asset{"asset/background/start/gramophone_TVOS.png"}; + Asset table_asset {"asset/background/start/table.png"}; + obj.add_component<Sprite>( + table_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset, + } + ); + Asset gramophone_asset {"asset/background/start/gramophone_TVOS.png"}; Sprite & gramophone_sprite = obj.add_component<Sprite>( - gramophone_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, -50), - }); - obj.add_component<Animator>(gramophone_sprite, ivec2(64, 128), uvec2(2, 1), - Animator::Data{ - .fps = 10, - .looping = true, - }); + gramophone_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, -50), + } + ); + obj.add_component<Animator>( + gramophone_sprite, ivec2(64, 128), uvec2(2, 1), + Animator::Data { + .fps = 10, + .looping = true, + } + ); } void StartSubScene::add_light(crepe::GameObject & obj, crepe::vec2 offset) { - Asset light_asset{"asset/background/start/title_light_TVOS.png"}; - obj.add_component<Sprite>(light_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 200), - .position_offset = offset, - }); - Asset light_glow_asset{"asset/background/start/lightEffect2.png"}; - obj.add_component<Sprite>(light_glow_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 75), - }); - Asset light_effect_asset{"asset/background/start/lightEffect.png"}; - obj.add_component<Sprite>(light_effect_asset, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - .position_offset = offset + vec2(0, 350), - }); + Asset light_asset {"asset/background/start/title_light_TVOS.png"}; + obj.add_component<Sprite>( + light_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 200), + .position_offset = offset, + } + ); + Asset light_glow_asset {"asset/background/start/lightEffect2.png"}; + obj.add_component<Sprite>( + light_glow_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 75), + } + ); + Asset light_effect_asset {"asset/background/start/lightEffect.png"}; + obj.add_component<Sprite>( + light_effect_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + .position_offset = offset + vec2(0, 350), + } + ); } void StartSubScene::add_jetpack_stand(crepe::GameObject & obj, crepe::vec2 offset) { - Asset jetpack_stand_asset{"asset/background/start/JetpackStand.png"}; + Asset jetpack_stand_asset {"asset/background/start/JetpackStand.png"}; Sprite & jetpeck_stand_sprite = obj.add_component<Sprite>( - jetpack_stand_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 70), - .position_offset = offset, - }); - obj.add_component<Animator>(jetpeck_stand_sprite, ivec2(34, 46), uvec2(2, 1), - Animator::Data{ - .fps = 10, - .looping = true, - }) + jetpack_stand_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 70), + .position_offset = offset, + } + ); + obj.add_component<Animator>( + jetpeck_stand_sprite, ivec2(34, 46), uvec2(2, 1), + Animator::Data { + .fps = 10, + .looping = true, + } + ) .pause(); Asset do_not_steal = {"asset/background/start/doNotTouchSign_TVOS.png"}; - obj.add_component<Sprite>(do_not_steal, - Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 1, - .size = vec2(0, 100), - .position_offset = offset + vec2(-75, -25), - }); + obj.add_component<Sprite>( + do_not_steal, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 1, + .size = vec2(0, 100), + .position_offset = offset + vec2(-75, -25), + } + ); } void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject frag_1 = scn.new_object("frag_1", "wall_fragment", vec2(begin_x, 200)); - Asset frag_1_asset{"asset/background/start/StartWall_frag1.png"}; + Asset frag_1_asset {"asset/background/start/StartWall_frag1.png"}; Sprite & frag_1_sprite = frag_1.add_component<Sprite>( - frag_1_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_1_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_1_sprite.active = false; - Rigidbody & frag_1_rb = frag_1.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_1_rb = frag_1.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 10, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.5, 0.6), @@ -175,15 +212,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_1.add_component<CircleCollider>(25); GameObject frag_2 = scn.new_object("frag_2", "wall_fragment", vec2(begin_x, 180)); - Asset frag_2_asset{"asset/background/start/StartWall_frag2.png"}; + Asset frag_2_asset {"asset/background/start/StartWall_frag2.png"}; Sprite & frag_2_sprite = frag_2.add_component<Sprite>( - frag_2_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_2_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_2_sprite.active = false; - Rigidbody & frag_2_rb = frag_2.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_2_rb = frag_2.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 20, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.35, 0.4), @@ -197,15 +236,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_2.add_component<CircleCollider>(55); GameObject frag_3 = scn.new_object("frag_3", "wall_fragment", vec2(begin_x, 170)); - Asset frag_3_asset{"asset/background/start/StartWall_frag3.png"}; + Asset frag_3_asset {"asset/background/start/StartWall_frag3.png"}; Sprite & frag_3_sprite = frag_3.add_component<Sprite>( - frag_3_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_3_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_3_sprite.active = false; - Rigidbody & frag_3_rb = frag_3.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_3_rb = frag_3.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 30, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.3, 0.3), @@ -219,15 +260,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_3.add_component<CircleCollider>(35); GameObject frag_4 = scn.new_object("frag_4", "wall_fragment", vec2(begin_x, 160)); - Asset frag_4_asset{"asset/background/start/StartWall_frag4.png"}; + Asset frag_4_asset {"asset/background/start/StartWall_frag4.png"}; Sprite & frag_4_sprite = frag_4.add_component<Sprite>( - frag_4_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_4_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_4_sprite.active = false; - Rigidbody & frag_4_rb = frag_4.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_4_rb = frag_4.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 40, .linear_velocity = vec2(700, 400), .linear_velocity_coefficient = vec2(0.2, 0.2), @@ -241,15 +284,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_4.add_component<CircleCollider>(60); GameObject frag_5 = scn.new_object("frag_5", "wall_fragment", vec2(begin_x, 150)); - Asset frag_5_asset{"asset/background/start/StartWall_frag5.png"}; + Asset frag_5_asset {"asset/background/start/StartWall_frag5.png"}; Sprite & frag_5_sprite = frag_5.add_component<Sprite>( - frag_5_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_5_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_5_sprite.active = false; - Rigidbody & frag_5_rb = frag_5.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_5_rb = frag_5.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 50, .linear_velocity = vec2(600, 800), .linear_velocity_coefficient = vec2(0.25, 0.15), @@ -263,15 +308,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_5.add_component<CircleCollider>(5); GameObject frag_6 = scn.new_object("frag_6", "wall_fragment", vec2(begin_x, 140)); - Asset frag_6_asset{"asset/background/start/StartWall_frag6.png"}; + Asset frag_6_asset {"asset/background/start/StartWall_frag6.png"}; Sprite & frag_6_sprite = frag_6.add_component<Sprite>( - frag_6_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_6_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_6_sprite.active = false; - Rigidbody & frag_6_rb = frag_6.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_6_rb = frag_6.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 30, .linear_velocity = vec2(300, 800), .linear_velocity_coefficient = vec2(0.35, 0.25), @@ -285,15 +332,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_6.add_component<CircleCollider>(30); GameObject frag_7 = scn.new_object("frag_7", "wall_fragment", vec2(begin_x, 130)); - Asset frag_7_asset{"asset/background/start/StartWall_frag7.png"}; + Asset frag_7_asset {"asset/background/start/StartWall_frag7.png"}; Sprite & frag_7_sprite = frag_7.add_component<Sprite>( - frag_7_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_7_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_7_sprite.active = false; - Rigidbody & frag_7_rb = frag_7.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_7_rb = frag_7.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 20, .linear_velocity = vec2(400, 500), .linear_velocity_coefficient = vec2(0.45, 0.6), @@ -307,15 +356,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_7.add_component<CircleCollider>(45); GameObject frag_8 = scn.new_object("frag_8", "wall_fragment", vec2(begin_x, 120)); - Asset frag_8_asset{"asset/background/start/StartWall_frag8.png"}; + Asset frag_8_asset {"asset/background/start/StartWall_frag8.png"}; Sprite & frag_8_sprite = frag_8.add_component<Sprite>( - frag_8_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_8_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_8_sprite.active = false; - Rigidbody & frag_8_rb = frag_8.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_8_rb = frag_8.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 30, .linear_velocity = vec2(400, 400), .linear_velocity_coefficient = vec2(0.5, 0.6), @@ -329,15 +380,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_8.add_component<CircleCollider>(25); GameObject frag_9 = scn.new_object("frag_9", "wall_fragment", vec2(begin_x, 110)); - Asset frag_9_asset{"asset/background/start/StartWall_frag9.png"}; + Asset frag_9_asset {"asset/background/start/StartWall_frag9.png"}; Sprite & frag_9_sprite = frag_9.add_component<Sprite>( - frag_9_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_9_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_9_sprite.active = false; - Rigidbody & frag_9_rb = frag_9.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_9_rb = frag_9.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 40, .linear_velocity = vec2(200, 400), .linear_velocity_coefficient = vec2(0.5, 0.25), @@ -351,15 +404,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_9.add_component<CircleCollider>(15); GameObject frag_10 = scn.new_object("frag_10", "wall_fragment", vec2(begin_x, 100)); - Asset frag_10_asset{"asset/background/start/StartWall_frag10.png"}; + Asset frag_10_asset {"asset/background/start/StartWall_frag10.png"}; Sprite & frag_10_sprite = frag_10.add_component<Sprite>( - frag_10_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_10_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_10_sprite.active = false; - Rigidbody & frag_10_rb = frag_10.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_10_rb = frag_10.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 50, .linear_velocity = vec2(400, 900), .linear_velocity_coefficient = vec2(0.35, 0.4), @@ -373,15 +428,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_10.add_component<CircleCollider>(60); GameObject frag_11 = scn.new_object("frag_11", "wall_fragment", vec2(begin_x, 70)); - Asset frag_11_asset{"asset/background/start/StartWall_frag11.png"}; + Asset frag_11_asset {"asset/background/start/StartWall_frag11.png"}; Sprite & frag_11_sprite = frag_11.add_component<Sprite>( - frag_11_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_11_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_11_sprite.active = false; - Rigidbody & frag_11_rb = frag_11.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_11_rb = frag_11.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 60, .linear_velocity = vec2(600, 800), .linear_velocity_coefficient = vec2(0.3, 0.3), @@ -395,15 +452,17 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { frag_11.add_component<CircleCollider>(5); GameObject frag_12 = scn.new_object("frag_12", "wall_fragment", vec2(begin_x, 80)); - Asset frag_12_asset{"asset/background/start/StartWall_frag12.png"}; + Asset frag_12_asset {"asset/background/start/StartWall_frag12.png"}; Sprite & frag_12_sprite = frag_12.add_component<Sprite>( - frag_12_asset, Sprite::Data{ - .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, - .order_in_layer = 5, - .size = vec2(0, 50), - }); + frag_12_asset, + Sprite::Data { + .sorting_in_layer = SORT_IN_LAY_FORE_BACKGROUND, + .order_in_layer = 5, + .size = vec2(0, 50), + } + ); frag_12_sprite.active = false; - Rigidbody & frag_12_rb = frag_12.add_component<Rigidbody>(Rigidbody::Data{ + Rigidbody & frag_12_rb = frag_12.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 70, .linear_velocity = vec2(500, 800), .linear_velocity_coefficient = vec2(0.25, 0.15), @@ -418,43 +477,51 @@ void StartSubScene::create_wall_fragments(crepe::Scene & scn, float begin_x) { GameObject smoke_particles_1 = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); - Asset smoke_asset_1{"asset/particles/smoke.png"}; + Asset smoke_asset_1 {"asset/particles/smoke.png"}; Sprite & smoke_sprite_1 = smoke_particles_1.add_component<Sprite>( - smoke_asset_1, Sprite::Data{ - .color = Color(255, 255, 255, 50), - .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, - .order_in_layer = 0, - .size = vec2(0, 100), - }); + smoke_asset_1, + Sprite::Data { + .color = Color(255, 255, 255, 50), + .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, + .order_in_layer = 0, + .size = vec2(0, 100), + } + ); ParticleEmitter & emitter_1 = smoke_particles_1.add_component<ParticleEmitter>( - smoke_sprite_1, ParticleEmitter::Data{ - .emission_rate = 20, - .min_speed = 40, - .max_speed = 100, - .min_angle = -30, - .max_angle = 10, - .end_lifespan = 4, - }); + smoke_sprite_1, + ParticleEmitter::Data { + .emission_rate = 20, + .min_speed = 40, + .max_speed = 100, + .min_angle = -30, + .max_angle = 10, + .end_lifespan = 4, + } + ); emitter_1.active = false; GameObject smoke_particles_2 = scn.new_object("smoke_particles", "particle_emitter", vec2(begin_x - 100, 200)); - Asset smoke_asset_2{"asset/particles/smoke.png"}; + Asset smoke_asset_2 {"asset/particles/smoke.png"}; Sprite & smoke_sprite_2 = smoke_particles_2.add_component<Sprite>( - smoke_asset_2, Sprite::Data{ - .color = Color(255, 255, 255, 50), - .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, - .order_in_layer = 0, - .size = vec2(0, 70), - }); + smoke_asset_2, + Sprite::Data { + .color = Color(255, 255, 255, 50), + .sorting_in_layer = SORT_IN_LAY_PARTICLES_FOREGROUND, + .order_in_layer = 0, + .size = vec2(0, 70), + } + ); ParticleEmitter & emitter_2 = smoke_particles_2.add_component<ParticleEmitter>( - smoke_sprite_2, ParticleEmitter::Data{ - .emission_rate = 30, - .min_speed = 40, - .max_speed = 100, - .min_angle = -45, - .max_angle = 5, - .end_lifespan = 3, - }); + smoke_sprite_2, + ParticleEmitter::Data { + .emission_rate = 30, + .min_speed = 40, + .max_speed = 100, + .min_angle = -45, + .max_angle = 5, + .end_lifespan = 3, + } + ); emitter_2.active = false; } diff --git a/mwe/ecs-homemade/inc/ComponentManager.hpp b/mwe/ecs-homemade/inc/ComponentManager.hpp index af9c3a1..7d26df4 100644 --- a/mwe/ecs-homemade/inc/ComponentManager.hpp +++ b/mwe/ecs-homemade/inc/ComponentManager.hpp @@ -54,8 +54,8 @@ void ComponentManager::DeleteComponents() { } template <typename T> -std::vector<std::reference_wrapper<T>> -ComponentManager::GetComponentsByID(std::uint32_t id) const { +std::vector<std::reference_wrapper<T>> ComponentManager::GetComponentsByID(std::uint32_t id +) const { //Determine the type of T (this is used as the key of the unordered_map<>) std::type_index type = typeid(T); diff --git a/mwe/ecs-homemade/src/ComponentManager.cpp b/mwe/ecs-homemade/src/ComponentManager.cpp index 33ba12e..835bdda 100644 --- a/mwe/ecs-homemade/src/ComponentManager.cpp +++ b/mwe/ecs-homemade/src/ComponentManager.cpp @@ -9,9 +9,8 @@ ComponentManager::ComponentManager() {} void ComponentManager::DeleteAllComponentsOfId(std::uint32_t id) { for (auto & [type, componentArray] : mComponents) { //Loop through all the types (in the unordered_map<>) - if (id - < componentArray - .size()) { //Make sure that the id (that we are looking for) is within the boundaries of the vector<> + if (id < componentArray.size( + )) { //Make sure that the id (that we are looking for) is within the boundaries of the vector<> componentArray[id].clear(); //Clear the components at this specific id } } diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h index ee1bf52..6df98ee 100644 --- a/mwe/events/include/event.h +++ b/mwe/events/include/event.h @@ -27,8 +27,8 @@ public: virtual ~Event() = default; virtual std::uint32_t getEventType() const = 0; virtual std::string toString() const; - void addArgument(const std::string & key, - const std::variant<int, std::string, float> & value); + void + addArgument(const std::string & key, const std::variant<int, std::string, float> & value); std::variant<int, std::string, float> getArgument(const std::string & key) const; diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h index 3a83b15..8598cee 100644 --- a/mwe/events/include/eventHandler.h +++ b/mwe/events/include/eventHandler.h @@ -22,8 +22,9 @@ private: template <typename EventType> class EventHandlerWrapper : public IEventHandlerWrapper { public: - explicit EventHandlerWrapper(const EventHandler<EventType> & handler, - const bool destroyOnSuccess = false) + explicit EventHandlerWrapper( + const EventHandler<EventType> & handler, const bool destroyOnSuccess = false + ) : m_handler(handler), m_handlerType(m_handler.target_type().name()), m_destroyOnSuccess(destroyOnSuccess) { @@ -42,5 +43,5 @@ private: EventHandler<EventType> m_handler; const std::string m_handlerType; - bool m_destroyOnSuccess{false}; + bool m_destroyOnSuccess {false}; }; diff --git a/mwe/events/include/eventManager.h b/mwe/events/include/eventManager.h index 30e927f..43906e8 100644 --- a/mwe/events/include/eventManager.h +++ b/mwe/events/include/eventManager.h @@ -18,8 +18,8 @@ public: } void shutdown(); - void subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler, - int eventId); + void + subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler, int eventId); void unsubscribe(int eventType, const std::string & handlerName, int eventId); void triggerEvent(const Event & event_, int eventId); void queueEvent(std::unique_ptr<Event> && event_, int eventId); @@ -35,19 +35,23 @@ private: }; template <typename EventType> -inline void subscribe(const EventHandler<EventType> & callback, int eventId = 0, - const bool unsubscribeOnSuccess = false) { +inline void subscribe( + const EventHandler<EventType> & callback, int eventId = 0, + const bool unsubscribeOnSuccess = false +) { std::unique_ptr<IEventHandlerWrapper> handler = std::make_unique<EventHandlerWrapper<EventType>>(callback, unsubscribeOnSuccess); - EventManager::getInstance().subscribe(EventType::getStaticEventType(), std::move(handler), - eventId); + EventManager::getInstance().subscribe( + EventType::getStaticEventType(), std::move(handler), eventId + ); } template <typename EventType> inline void unsubscribe(const EventHandler<EventType> & callback, int eventId = 0) { const std::string handlerName = callback.target_type().name(); - EventManager::getInstance().unsubscribe(EventType::getStaticEventType(), handlerName, - eventId); + EventManager::getInstance().unsubscribe( + EventType::getStaticEventType(), handlerName, eventId + ); } inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) { @@ -55,6 +59,7 @@ inline void triggerEvent(const Event & triggeredEvent, int eventId = 0) { } inline void queueEvent(std::unique_ptr<Event> && queuedEvent, int eventId = 0) { - EventManager::getInstance().queueEvent(std::forward<std::unique_ptr<Event>>(queuedEvent), - eventId); + EventManager::getInstance().queueEvent( + std::forward<std::unique_ptr<Event>>(queuedEvent), eventId + ); } diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp index 0040c73..5177199 100644 --- a/mwe/events/src/event.cpp +++ b/mwe/events/src/event.cpp @@ -3,8 +3,9 @@ // Event class methods Event::Event(std::string eventType) { eventData["eventType"] = eventType; } -void Event::addArgument(const std::string & key, - const std::variant<int, std::string, float> & value) { +void Event::addArgument( + const std::string & key, const std::variant<int, std::string, float> & value +) { eventData[key] = value; } diff --git a/mwe/events/src/eventManager.cpp b/mwe/events/src/eventManager.cpp index 9e7d880..b77a0a3 100644 --- a/mwe/events/src/eventManager.cpp +++ b/mwe/events/src/eventManager.cpp @@ -2,8 +2,9 @@ void EventManager::shutdown() { subscribers.clear(); } -void EventManager::subscribe(int eventType, std::unique_ptr<IEventHandlerWrapper> && handler, - int eventId) { +void EventManager::subscribe( + int eventType, std::unique_ptr<IEventHandlerWrapper> && handler, int eventId +) { if (eventId) { std::unordered_map< int, std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>>:: diff --git a/mwe/events/src/loopManager.cpp b/mwe/events/src/loopManager.cpp index c58a5e7..7be10df 100644 --- a/mwe/events/src/loopManager.cpp +++ b/mwe/events/src/loopManager.cpp @@ -51,8 +51,10 @@ void onKey(const KeyPressedEvent & e) { std::cout << "keycode pressed: " << keyCode << std::endl; } void onMouse(const MousePressedEvent & e) { - fprintf(stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first, - e.getMousePosition().second); + fprintf( + stderr, "mouse Position X: %d Y: %d\n", e.getMousePosition().first, + e.getMousePosition().second + ); } void LoopManager::setup() { gameRunning = window.initWindow(); diff --git a/mwe/events/src/uiObject.cpp b/mwe/events/src/uiObject.cpp index 947d1a2..6b5b326 100644 --- a/mwe/events/src/uiObject.cpp +++ b/mwe/events/src/uiObject.cpp @@ -10,7 +10,7 @@ Text::Text(int width, int height) : UIObject(width, height), size(12), font(nullptr), - color{255, 255, 255} { // Default size and color + color {255, 255, 255} { // Default size and color alignment.horizontal = Alignment::Horizontal::CENTER; alignment.vertical = Alignment::Vertical::MIDDLE; alignment.mode = Alignment::PositioningMode::RELATIVE; @@ -21,8 +21,8 @@ TextInput::TextInput(int width, int height) textBuffer(""), placeholder(""), isActive(false), - textColor{255, 255, 255}, - backgroundColor{0, 0, 0}, + textColor {255, 255, 255}, + backgroundColor {0, 0, 0}, maxLength(100), font(nullptr) { alignment.horizontal = Alignment::Horizontal::LEFT; diff --git a/mwe/events/src/window.cpp b/mwe/events/src/window.cpp index af2b627..5cdd425 100644 --- a/mwe/events/src/window.cpp +++ b/mwe/events/src/window.cpp @@ -11,8 +11,10 @@ bool WindowManager::initWindow() { return false; } - window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow( + "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, + SCREEN_HEIGHT, SDL_WINDOW_SHOWN + ); if (!window) { std::cerr << "Error creating SDL Window.\n"; return false; diff --git a/mwe/gameloop/include/gameObject.h b/mwe/gameloop/include/gameObject.h index 2764215..1955b59 100644 --- a/mwe/gameloop/include/gameObject.h +++ b/mwe/gameloop/include/gameObject.h @@ -3,8 +3,9 @@ class GameObject { public: GameObject(); - GameObject(std::string name, float x, float y, float width, float height, float velX, - float velY); + GameObject( + std::string name, float x, float y, float width, float height, float velX, float velY + ); std::string getName() const; float getX() const; float getY() const; diff --git a/mwe/gameloop/src/gameObject.cpp b/mwe/gameloop/src/gameObject.cpp index 809e25f..31503d1 100644 --- a/mwe/gameloop/src/gameObject.cpp +++ b/mwe/gameloop/src/gameObject.cpp @@ -24,8 +24,9 @@ void GameObject::setVelX(float value) { velX = value; } void GameObject::setVelY(float value) { velY = value; } -GameObject::GameObject(std::string name, float x, float y, float width, float height, - float velX, float velY) +GameObject::GameObject( + std::string name, float x, float y, float width, float height, float velX, float velY +) : name(name), x(x), y(y), diff --git a/mwe/gameloop/src/loopManager.cpp b/mwe/gameloop/src/loopManager.cpp index fb06995..70cea4c 100644 --- a/mwe/gameloop/src/loopManager.cpp +++ b/mwe/gameloop/src/loopManager.cpp @@ -18,11 +18,13 @@ void LoopManager::processInput() { if (event.key.keysym.sym == SDLK_ESCAPE) { gameRunning = false; } else if (event.key.keysym.sym == SDLK_i) { - LoopTimer::getInstance().setGameScale(LoopTimer::getInstance().getGameScale() - + 0.1); + LoopTimer::getInstance().setGameScale( + LoopTimer::getInstance().getGameScale() + 0.1 + ); } else if (event.key.keysym.sym == SDLK_k) { - LoopTimer::getInstance().setGameScale(LoopTimer::getInstance().getGameScale() - - 0.1); + LoopTimer::getInstance().setGameScale( + LoopTimer::getInstance().getGameScale() - 0.1 + ); } break; diff --git a/mwe/gameloop/src/window.cpp b/mwe/gameloop/src/window.cpp index 8f802e1..df17773 100644 --- a/mwe/gameloop/src/window.cpp +++ b/mwe/gameloop/src/window.cpp @@ -36,8 +36,10 @@ bool WindowManager::initWindow() { fprintf(stderr, "Error inititalising SDL.\n"); return false; } - window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow( + "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, + SCREEN_HEIGHT, SDL_WINDOW_SHOWN + ); if (!window) { fprintf(stderr, "Error creating SDL Window. \n"); return false; diff --git a/mwe/resource-manager/main.cpp b/mwe/resource-manager/main.cpp index 1910af8..e83d35f 100644 --- a/mwe/resource-manager/main.cpp +++ b/mwe/resource-manager/main.cpp @@ -23,8 +23,9 @@ int main() { SDL_Event event; - SDL_Window * window = SDL_CreateWindow("Tessting resources", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, 640, 480, 0); + SDL_Window * window = SDL_CreateWindow( + "Tessting resources", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0 + ); SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, 0); diff --git a/mwe/resource-manager/map_layer.cpp b/mwe/resource-manager/map_layer.cpp index 17792a6..82f8f24 100644 --- a/mwe/resource-manager/map_layer.cpp +++ b/mwe/resource-manager/map_layer.cpp @@ -9,8 +9,9 @@ MapLayer::MapLayer() {} MapLayer::~MapLayer() { m_subsets.clear(); } -bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex, - const std::vector<TextureMap *> & textures) { +bool MapLayer::create( + const tmx::Map & map, std::uint32_t layerIndex, const std::vector<TextureMap *> & textures +) { const auto & layers = map.getLayers(); assert(layers[layerIndex]->getType() == tmx::Layer::Type::Tile); @@ -68,9 +69,10 @@ bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex, verts.emplace_back(vert); vert = {{tilePosX + mapTileSize.x, tilePosY}, vertColour, {u + uNorm, v}}; verts.emplace_back(vert); - vert = {{tilePosX + mapTileSize.x, tilePosY + mapTileSize.y}, - vertColour, - {u + uNorm, v + vNorm}}; + vert + = {{tilePosX + mapTileSize.x, tilePosY + mapTileSize.y}, + vertColour, + {u + uNorm, v + vNorm}}; verts.emplace_back(vert); } } @@ -89,7 +91,9 @@ bool MapLayer::create(const tmx::Map & map, std::uint32_t layerIndex, void MapLayer::draw(SDL_Renderer * renderer) const { assert(renderer); for (const auto & s : m_subsets) { - SDL_RenderGeometry(renderer, s.texture, s.vertexData.data(), - static_cast<std::int32_t>(s.vertexData.size()), nullptr, 0); + SDL_RenderGeometry( + renderer, s.texture, s.vertexData.data(), + static_cast<std::int32_t>(s.vertexData.size()), nullptr, 0 + ); } } diff --git a/mwe/resource-manager/map_layer.h b/mwe/resource-manager/map_layer.h index fb656ed..2adbc0f 100644 --- a/mwe/resource-manager/map_layer.h +++ b/mwe/resource-manager/map_layer.h @@ -10,8 +10,8 @@ public: explicit MapLayer(); ~MapLayer(); - bool create(const tmx::Map &, std::uint32_t index, - const std::vector<TextureMap *> & textures); + bool + create(const tmx::Map &, std::uint32_t index, const std::vector<TextureMap *> & textures); void draw(SDL_Renderer *) const; private: diff --git a/mwe/resource-manager/stb_image.h b/mwe/resource-manager/stb_image.h index 3462f3a..43fa6a6 100644 --- a/mwe/resource-manager/stb_image.h +++ b/mwe/resource-manager/stb_image.h @@ -409,9 +409,12 @@ extern "C" { typedef struct { int (*read)( void * user, char * data, - int size); // fill 'data' with 'size' bytes. return number of bytes actually read - void (*skip)(void * user, - int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative + int size + ); // fill 'data' with 'size' bytes. return number of bytes actually read + void (*skip)( + void * user, + int n + ); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative int (*eof)(void * user); // returns nonzero if we are at end of file/data } stbi_io_callbacks; @@ -420,24 +423,29 @@ typedef struct { // 8-bits-per-channel interface // -STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels); -STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_uc * stbi_load_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +); +STBIDEF stbi_uc * stbi_load_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +); #ifndef STBI_NO_STDIO -STBIDEF stbi_uc * stbi_load(char const * filename, int * x, int * y, int * channels_in_file, - int desired_channels); -STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_uc * stbi_load( + char const * filename, int * x, int * y, int * channels_in_file, int desired_channels +); +STBIDEF stbi_uc * +stbi_load_from_file(FILE * f, int * x, int * y, int * channels_in_file, int desired_channels); // for stbi_load_from_file, file pointer is left pointing immediately after image #endif #ifndef STBI_NO_GIF -STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int ** delays, - int * x, int * y, int * z, int * comp, - int req_comp); +STBIDEF stbi_uc * stbi_load_gif_from_memory( + stbi_uc const * buffer, int len, int ** delays, int * x, int * y, int * z, int * comp, + int req_comp +); #endif #ifdef STBI_WINDOWS_UTF8 @@ -449,17 +457,22 @@ STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen, const wc // 16-bits-per-channel interface // -STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels); -STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_us * stbi_load_16_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +); +STBIDEF stbi_us * stbi_load_16_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +); #ifndef STBI_NO_STDIO -STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * channels_in_file, - int desired_channels); -STBIDEF stbi_us * stbi_load_from_file_16(FILE * f, int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF stbi_us * stbi_load_16( + char const * filename, int * x, int * y, int * channels_in_file, int desired_channels +); +STBIDEF stbi_us * stbi_load_from_file_16( + FILE * f, int * x, int * y, int * channels_in_file, int desired_channels +); #endif //////////////////////////////////// @@ -467,17 +480,21 @@ STBIDEF stbi_us * stbi_load_from_file_16(FILE * f, int * x, int * y, int * chann // float-per-channel interface // #ifndef STBI_NO_LINEAR -STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels); -STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x, - int * y, int * channels_in_file, - int desired_channels); +STBIDEF float * stbi_loadf_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +); +STBIDEF float * stbi_loadf_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +); #ifndef STBI_NO_STDIO -STBIDEF float * stbi_loadf(char const * filename, int * x, int * y, int * channels_in_file, - int desired_channels); -STBIDEF float * stbi_loadf_from_file(FILE * f, int * x, int * y, int * channels_in_file, - int desired_channels); +STBIDEF float * stbi_loadf( + char const * filename, int * x, int * y, int * channels_in_file, int desired_channels +); +STBIDEF float * +stbi_loadf_from_file(FILE * f, int * x, int * y, int * channels_in_file, int desired_channels); #endif #endif @@ -507,10 +524,11 @@ STBIDEF const char * stbi_failure_reason(void); STBIDEF void stbi_image_free(void * retval_from_stbi_load); // get image dimensions & components without fully decoding -STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp); -STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x, - int * y, int * comp); +STBIDEF int +stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, int * comp); +STBIDEF int stbi_info_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * comp +); STBIDEF int stbi_is_16_bit_from_memory(stbi_uc const * buffer, int len); STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const * clbk, void * user); @@ -542,17 +560,18 @@ STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_fli // ZLIB client - used by PNG, available for other purposes -STBIDEF char * stbi_zlib_decode_malloc_guesssize(const char * buffer, int len, - int initial_size, int * outlen); -STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer, int len, - int initial_size, int * outlen, - int parse_header); +STBIDEF char * stbi_zlib_decode_malloc_guesssize( + const char * buffer, int len, int initial_size, int * outlen +); +STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag( + const char * buffer, int len, int initial_size, int * outlen, int parse_header +); STBIDEF char * stbi_zlib_decode_malloc(const char * buffer, int len, int * outlen); STBIDEF int stbi_zlib_decode_buffer(char * obuffer, int olen, const char * ibuffer, int ilen); STBIDEF char * stbi_zlib_decode_noheader_malloc(const char * buffer, int len, int * outlen); -STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, - int ilen); +STBIDEF int +stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, int ilen); #ifdef __cplusplus } @@ -910,68 +929,79 @@ typedef struct { #ifndef STBI_NO_JPEG static int stbi__jpeg_test(stbi__context * s); -static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__jpeg_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__jpeg_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PNG static int stbi__png_test(stbi__context * s); -static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__png_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__png_info(stbi__context * s, int * x, int * y, int * comp); static int stbi__png_is16(stbi__context * s); #endif #ifndef STBI_NO_BMP static int stbi__bmp_test(stbi__context * s); -static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__bmp_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__bmp_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_TGA static int stbi__tga_test(stbi__context * s); -static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__tga_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PSD static int stbi__psd_test(stbi__context * s); -static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri, int bpc); +static void * stbi__psd_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri, + int bpc +); static int stbi__psd_info(stbi__context * s, int * x, int * y, int * comp); static int stbi__psd_is16(stbi__context * s); #endif #ifndef STBI_NO_HDR static int stbi__hdr_test(stbi__context * s); -static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static float * stbi__hdr_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__hdr_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PIC static int stbi__pic_test(stbi__context * s); -static void * stbi__pic_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__pic_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__pic_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_GIF static int stbi__gif_test(stbi__context * s); -static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); -static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int * y, int * z, - int * comp, int req_comp); +static void * stbi__gif_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); +static void * stbi__load_gif_main( + stbi__context * s, int ** delays, int * x, int * y, int * z, int * comp, int req_comp +); static int stbi__gif_info(stbi__context * s, int * x, int * y, int * comp); #endif #ifndef STBI_NO_PNM static int stbi__pnm_test(stbi__context * s); -static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri); +static void * stbi__pnm_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +); static int stbi__pnm_info(stbi__context * s, int * x, int * y, int * comp); static int stbi__pnm_is16(stbi__context * s); #endif @@ -1135,8 +1165,10 @@ STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_fli : stbi__vertically_flip_on_load_global) #endif // STBI_THREAD_LOCAL -static void * stbi__load_main(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri, int bpc) { +static void * stbi__load_main( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri, + int bpc +) { memset(ri, 0, sizeof(*ri)); // make sure it's initialized if we add new fields ri->bits_per_channel = 8; // default is 8 so most paths don't have to be changed @@ -1198,9 +1230,8 @@ static stbi_uc * stbi__convert_16_to_8(stbi__uint16 * orig, int w, int h, int ch if (reduced == NULL) return stbi__errpuc("outofmem", "Out of memory"); for (i = 0; i < img_len; ++i) - reduced[i] - = (stbi_uc) ((orig[i] >> 8) - & 0xFF); // top half of each byte is sufficient approx of 16->8 bit scaling + reduced[i] = (stbi_uc) ((orig[i] >> 8) & 0xFF + ); // top half of each byte is sufficient approx of 16->8 bit scaling STBI_FREE(orig); return reduced; @@ -1215,10 +1246,8 @@ static stbi__uint16 * stbi__convert_8_to_16(stbi_uc * orig, int w, int h, int ch if (enlarged == NULL) return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory"); for (i = 0; i < img_len; ++i) - enlarged[i] - = (stbi__uint16) ((orig[i] << 8) - + orig - [i]); // replicate to high and low byte, maps 0->0, 255->0xffff + enlarged[i] = (stbi__uint16) ((orig[i] << 8) + orig[i] + ); // replicate to high and low byte, maps 0->0, 255->0xffff STBI_FREE(orig); return enlarged; @@ -1248,8 +1277,8 @@ static void stbi__vertical_flip(void * image, int w, int h, int bytes_per_pixel) } #ifndef STBI_NO_GIF -static void stbi__vertical_flip_slices(void * image, int w, int h, int z, - int bytes_per_pixel) { +static void +stbi__vertical_flip_slices(void * image, int w, int h, int z, int bytes_per_pixel) { int slice; int slice_size = w * h * bytes_per_pixel; @@ -1261,8 +1290,9 @@ static void stbi__vertical_flip_slices(void * image, int w, int h, int z, } #endif -static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s, int * x, int * y, - int * comp, int req_comp) { +static unsigned char * stbi__load_and_postprocess_8bit( + stbi__context * s, int * x, int * y, int * comp, int req_comp +) { stbi__result_info ri; void * result = stbi__load_main(s, x, y, comp, req_comp, &ri, 8); @@ -1272,8 +1302,9 @@ static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s, int * STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); if (ri.bits_per_channel != 8) { - result = stbi__convert_16_to_8((stbi__uint16 *) result, *x, *y, - req_comp == 0 ? *comp : req_comp); + result = stbi__convert_16_to_8( + (stbi__uint16 *) result, *x, *y, req_comp == 0 ? *comp : req_comp + ); ri.bits_per_channel = 8; } @@ -1287,8 +1318,9 @@ static unsigned char * stbi__load_and_postprocess_8bit(stbi__context * s, int * return (unsigned char *) result; } -static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s, int * x, int * y, - int * comp, int req_comp) { +static stbi__uint16 * stbi__load_and_postprocess_16bit( + stbi__context * s, int * x, int * y, int * comp, int req_comp +) { stbi__result_info ri; void * result = stbi__load_main(s, x, y, comp, req_comp, &ri, 16); @@ -1298,8 +1330,9 @@ static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s, int * STBI_ASSERT(ri.bits_per_channel == 8 || ri.bits_per_channel == 16); if (ri.bits_per_channel != 16) { - result = stbi__convert_8_to_16((stbi_uc *) result, *x, *y, - req_comp == 0 ? *comp : req_comp); + result = stbi__convert_8_to_16( + (stbi_uc *) result, *x, *y, req_comp == 0 ? *comp : req_comp + ); ri.bits_per_channel = 16; } @@ -1315,8 +1348,8 @@ static stbi__uint16 * stbi__load_and_postprocess_16bit(stbi__context * s, int * } #if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR) -static void stbi__float_postprocess(float * result, int * x, int * y, int * comp, - int req_comp) { +static void +stbi__float_postprocess(float * result, int * x, int * y, int * comp, int req_comp) { if (stbi__vertically_flip_on_load && result != NULL) { int channels = req_comp ? req_comp : *comp; stbi__vertical_flip(result, *x, *y, channels * sizeof(float)); @@ -1328,19 +1361,22 @@ static void stbi__float_postprocess(float * result, int * x, int * y, int * comp #if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) STBI_EXTERN -__declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, - const char * str, int cbmb, - wchar_t * widestr, int cchwide); +__declspec(dllimport) int __stdcall MultiByteToWideChar( + unsigned int cp, unsigned long flags, const char * str, int cbmb, wchar_t * widestr, + int cchwide +); STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte( unsigned int cp, unsigned long flags, const wchar_t * widestr, int cchwide, char * str, - int cbmb, const char * defchar, int * used_default); + int cbmb, const char * defchar, int * used_default +); #endif #if defined(_WIN32) && defined(STBI_WINDOWS_UTF8) -STBIDEF int stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen, - const wchar_t * input) { - return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, - NULL); +STBIDEF int +stbi_convert_wchar_to_utf8(char * buffer, size_t bufferlen, const wchar_t * input) { + return WideCharToMultiByte( + 65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL + ); } #endif @@ -1350,13 +1386,16 @@ static FILE * stbi__fopen(char const * filename, char const * mode) { wchar_t wMode[64]; wchar_t wFilename[1024]; if (0 - == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, - sizeof(wFilename) / sizeof(*wFilename))) + == MultiByteToWideChar( + 65001 /* UTF8 */, 0, filename, -1, wFilename, + sizeof(wFilename) / sizeof(*wFilename) + )) return 0; if (0 - == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, - sizeof(wMode) / sizeof(*wMode))) + == MultiByteToWideChar( + 65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode) / sizeof(*wMode) + )) return 0; #if defined(_MSC_VER) && _MSC_VER >= 1400 @@ -1373,8 +1412,8 @@ static FILE * stbi__fopen(char const * filename, char const * mode) { return f; } -STBIDEF stbi_uc * stbi_load(char const * filename, int * x, int * y, int * comp, - int req_comp) { +STBIDEF stbi_uc * +stbi_load(char const * filename, int * x, int * y, int * comp, int req_comp) { FILE * f = stbi__fopen(filename, "rb"); unsigned char * result; if (!f) return stbi__errpuc("can't fopen", "Unable to open file"); @@ -1395,8 +1434,8 @@ STBIDEF stbi_uc * stbi_load_from_file(FILE * f, int * x, int * y, int * comp, in return result; } -STBIDEF stbi__uint16 * stbi_load_from_file_16(FILE * f, int * x, int * y, int * comp, - int req_comp) { +STBIDEF stbi__uint16 * +stbi_load_from_file_16(FILE * f, int * x, int * y, int * comp, int req_comp) { stbi__uint16 * result; stbi__context s; stbi__start_file(&s, f); @@ -1408,8 +1447,8 @@ STBIDEF stbi__uint16 * stbi_load_from_file_16(FILE * f, int * x, int * y, int * return result; } -STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * comp, - int req_comp) { +STBIDEF stbi_us * +stbi_load_16(char const * filename, int * x, int * y, int * comp, int req_comp) { FILE * f = stbi__fopen(filename, "rb"); stbi__uint16 * result; if (!f) return (stbi_us *) stbi__errpuc("can't fopen", "Unable to open file"); @@ -1420,39 +1459,45 @@ STBIDEF stbi_us * stbi_load_16(char const * filename, int * x, int * y, int * co #endif //!STBI_NO_STDIO -STBIDEF stbi_us * stbi_load_16_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * channels_in_file, int desired_channels) { +STBIDEF stbi_us * stbi_load_16_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * channels_in_file, + int desired_channels +) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels); } -STBIDEF stbi_us * stbi_load_16_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * channels_in_file, - int desired_channels) { +STBIDEF stbi_us * stbi_load_16_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * channels_in_file, + int desired_channels +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); return stbi__load_and_postprocess_16bit(&s, x, y, channels_in_file, desired_channels); } -STBIDEF stbi_uc * stbi_load_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp, int req_comp) { +STBIDEF stbi_uc * stbi_load_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp); } -STBIDEF stbi_uc * stbi_load_from_callbacks(stbi_io_callbacks const * clbk, void * user, - int * x, int * y, int * comp, int req_comp) { +STBIDEF stbi_uc * stbi_load_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); return stbi__load_and_postprocess_8bit(&s, x, y, comp, req_comp); } #ifndef STBI_NO_GIF -STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int ** delays, - int * x, int * y, int * z, int * comp, - int req_comp) { +STBIDEF stbi_uc * stbi_load_gif_from_memory( + stbi_uc const * buffer, int len, int ** delays, int * x, int * y, int * z, int * comp, + int req_comp +) { unsigned char * result; stbi__context s; stbi__start_mem(&s, buffer, len); @@ -1467,8 +1512,8 @@ STBIDEF stbi_uc * stbi_load_gif_from_memory(stbi_uc const * buffer, int len, int #endif #ifndef STBI_NO_LINEAR -static float * stbi__loadf_main(stbi__context * s, int * x, int * y, int * comp, - int req_comp) { +static float * +stbi__loadf_main(stbi__context * s, int * x, int * y, int * comp, int req_comp) { unsigned char * data; #ifndef STBI_NO_HDR if (stbi__hdr_test(s)) { @@ -1483,15 +1528,17 @@ static float * stbi__loadf_main(stbi__context * s, int * x, int * y, int * comp, return stbi__errpf("unknown image type", "Image not of any known type, or corrupt"); } -STBIDEF float * stbi_loadf_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp, int req_comp) { +STBIDEF float * stbi_loadf_from_memory( + stbi_uc const * buffer, int len, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__loadf_main(&s, x, y, comp, req_comp); } -STBIDEF float * stbi_loadf_from_callbacks(stbi_io_callbacks const * clbk, void * user, int * x, - int * y, int * comp, int req_comp) { +STBIDEF float * stbi_loadf_from_callbacks( + stbi_io_callbacks const * clbk, void * user, int * x, int * y, int * comp, int req_comp +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) clbk, user); return stbi__loadf_main(&s, x, y, comp, req_comp); @@ -1745,8 +1792,9 @@ static stbi_uc stbi__compute_y(int r, int g, int b) { && defined(STBI_NO_PNM) // nothing #else -static unsigned char * stbi__convert_format(unsigned char * data, int img_n, int req_comp, - unsigned int x, unsigned int y) { +static unsigned char * stbi__convert_format( + unsigned char * data, int img_n, int req_comp, unsigned int x, unsigned int y +) { int i, j; unsigned char * good; @@ -1843,8 +1891,9 @@ static stbi__uint16 stbi__compute_y_16(int r, int g, int b) { #if defined(STBI_NO_PNG) && defined(STBI_NO_PSD) // nothing #else -static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n, int req_comp, - unsigned int x, unsigned int y) { +static stbi__uint16 * stbi__convert_format16( + stbi__uint16 * data, int img_n, int req_comp, unsigned int x, unsigned int y +) { int i, j; stbi__uint16 * good; @@ -1920,8 +1969,9 @@ static stbi__uint16 * stbi__convert_format16(stbi__uint16 * data, int img_n, int STBI_ASSERT(0); STBI_FREE(data); STBI_FREE(good); - return (stbi__uint16 *) stbi__errpuc("unsupported", - "Unsupported format conversion"); + return (stbi__uint16 *) stbi__errpuc( + "unsupported", "Unsupported format conversion" + ); } #undef STBI__CASE } @@ -2079,10 +2129,13 @@ typedef struct { // kernels void (*idct_block_kernel)(stbi_uc * out, int out_stride, short data[64]); - void (*YCbCr_to_RGB_kernel)(stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, - const stbi_uc * pcr, int count, int step); - stbi_uc * (*resample_row_hv_2_kernel)(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs); + void (*YCbCr_to_RGB_kernel)( + stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, const stbi_uc * pcr, int count, + int step + ); + stbi_uc * (*resample_row_hv_2_kernel)( + stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs + ); } stbi__jpeg; static int stbi__build_huffman(stbi__huffman * h, int * count) { @@ -2215,8 +2268,9 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg * j, stbi__huffman * h) c = ((j->code_buffer >> (32 - k)) & stbi__bmask[k]) + h->delta[k]; if (c < 0 || c >= 256) // symbol id out of bounds! return -1; - STBI_ASSERT((((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) - == h->code[c]); + STBI_ASSERT( + (((j->code_buffer) >> (32 - h->size[c])) & stbi__bmask[h->size[c]]) == h->code[c] + ); // convert the id to a symbol j->code_bits -= k; @@ -2280,9 +2334,10 @@ static const stbi_uc stbi__jpeg_dezigzag[64 + 15] 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63}; // decode one 64-entry block-- -static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64], stbi__huffman * hdc, - stbi__huffman * hac, stbi__int16 * fac, int b, - stbi__uint16 * dequant) { +static int stbi__jpeg_decode_block( + stbi__jpeg * j, short data[64], stbi__huffman * hdc, stbi__huffman * hac, + stbi__int16 * fac, int b, stbi__uint16 * dequant +) { int diff, dc, k; int t; @@ -2314,8 +2369,9 @@ static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64], stbi__huffman k += (r >> 4) & 15; // run s = r & 15; // combined length if (s > j->code_bits) - return stbi__err("bad huffman code", - "Combined length longer than code bits available"); + return stbi__err( + "bad huffman code", "Combined length longer than code bits available" + ); j->code_buffer <<= s; j->code_bits -= s; // decode into unzigzag'd location @@ -2340,8 +2396,8 @@ static int stbi__jpeg_decode_block(stbi__jpeg * j, short data[64], stbi__huffman return 1; } -static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64], stbi__huffman * hdc, - int b) { +static int +stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64], stbi__huffman * hdc, int b) { int diff, dc; int t; if (j->spec_end != 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); @@ -2371,8 +2427,9 @@ static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg * j, short data[64], stbi_ // @OPTIMIZE: store non-zigzagged during the decode passes, // and only de-zigzag when dequantizing -static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64], stbi__huffman * hac, - stbi__int16 * fac) { +static int stbi__jpeg_decode_block_prog_ac( + stbi__jpeg * j, short data[64], stbi__huffman * hac, stbi__int16 * fac +) { int k; if (j->spec_start == 0) return stbi__err("can't merge dc and ac", "Corrupt JPEG"); @@ -2395,8 +2452,9 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64], stbi_ k += (r >> 4) & 15; // run s = r & 15; // combined length if (s > j->code_bits) - return stbi__err("bad huffman code", - "Combined length longer than code bits available"); + return stbi__err( + "bad huffman code", "Combined length longer than code bits available" + ); j->code_buffer <<= s; j->code_bits -= s; zig = stbi__jpeg_dezigzag[k++]; @@ -2443,7 +2501,8 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg * j, short data[64], stbi_ int r, s; int rs = stbi__jpeg_huff_decode( j, - hac); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh + hac + ); // @OPTIMIZE see if we can use the fast path here, advance-by-r is so slow, eh if (rs < 0) return stbi__err("bad huffman code", "Corrupt JPEG"); s = rs & 15; r = rs >> 4; @@ -2691,18 +2750,24 @@ static void stbi__idct_simd(stbi_uc * out, int out_stride, short data[64]) { = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f)); __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f(0.765366865f), stbi__f2f(0.5411961f)); - __m128i rot1_0 = dct_const(stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), - stbi__f2f(1.175875602f)); - __m128i rot1_1 = dct_const(stbi__f2f(1.175875602f), - stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f)); - __m128i rot2_0 = dct_const(stbi__f2f(-1.961570560f) + stbi__f2f(0.298631336f), - stbi__f2f(-1.961570560f)); - __m128i rot2_1 = dct_const(stbi__f2f(-1.961570560f), - stbi__f2f(-1.961570560f) + stbi__f2f(3.072711026f)); - __m128i rot3_0 = dct_const(stbi__f2f(-0.390180644f) + stbi__f2f(2.053119869f), - stbi__f2f(-0.390180644f)); - __m128i rot3_1 = dct_const(stbi__f2f(-0.390180644f), - stbi__f2f(-0.390180644f) + stbi__f2f(1.501321110f)); + __m128i rot1_0 = dct_const( + stbi__f2f(1.175875602f) + stbi__f2f(-0.899976223f), stbi__f2f(1.175875602f) + ); + __m128i rot1_1 = dct_const( + stbi__f2f(1.175875602f), stbi__f2f(1.175875602f) + stbi__f2f(-2.562915447f) + ); + __m128i rot2_0 = dct_const( + stbi__f2f(-1.961570560f) + stbi__f2f(0.298631336f), stbi__f2f(-1.961570560f) + ); + __m128i rot2_1 = dct_const( + stbi__f2f(-1.961570560f), stbi__f2f(-1.961570560f) + stbi__f2f(3.072711026f) + ); + __m128i rot3_0 = dct_const( + stbi__f2f(-0.390180644f) + stbi__f2f(2.053119869f), stbi__f2f(-0.390180644f) + ); + __m128i rot3_1 = dct_const( + stbi__f2f(-0.390180644f), stbi__f2f(-0.390180644f) + stbi__f2f(1.501321110f) + ); // rounding biases in column/row passes, see stbi__idct_block for explanation. __m128i bias_0 = _mm_set1_epi32(512); @@ -3091,13 +3156,15 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { for (j = 0; j < h; ++j) { for (i = 0; i < w; ++i) { int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block(z, data, z->huff_dc + z->img_comp[n].hd, - z->huff_ac + ha, z->fast_ac[ha], n, - z->dequant[z->img_comp[n].tq])) + if (!stbi__jpeg_decode_block( + z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, + z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq] + )) return 0; - z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 - + i * 8, - z->img_comp[n].w2, data); + z->idct_block_kernel( + z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, + z->img_comp[n].w2, data + ); // every data block is an MCU, so countdown the restart interval if (--z->todo <= 0) { if (z->code_bits < 24) stbi__grow_buffer_unsafe(z); @@ -3124,14 +3191,16 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { int x2 = (i * z->img_comp[n].h + x) * 8; int y2 = (j * z->img_comp[n].v + y) * 8; int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block(z, data, - z->huff_dc + z->img_comp[n].hd, - z->huff_ac + ha, z->fast_ac[ha], - n, z->dequant[z->img_comp[n].tq])) + if (!stbi__jpeg_decode_block( + z, data, z->huff_dc + z->img_comp[n].hd, + z->huff_ac + ha, z->fast_ac[ha], n, + z->dequant[z->img_comp[n].tq] + )) return 0; - z->idct_block_kernel(z->img_comp[n].data - + z->img_comp[n].w2 * y2 + x2, - z->img_comp[n].w2, data); + z->idct_block_kernel( + z->img_comp[n].data + z->img_comp[n].w2 * y2 + x2, + z->img_comp[n].w2, data + ); } } } @@ -3162,12 +3231,14 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); if (z->spec_start == 0) { if (!stbi__jpeg_decode_block_prog_dc( - z, data, &z->huff_dc[z->img_comp[n].hd], n)) + z, data, &z->huff_dc[z->img_comp[n].hd], n + )) return 0; } else { int ha = z->img_comp[n].ha; - if (!stbi__jpeg_decode_block_prog_ac(z, data, &z->huff_ac[ha], - z->fast_ac[ha])) + if (!stbi__jpeg_decode_block_prog_ac( + z, data, &z->huff_ac[ha], z->fast_ac[ha] + )) return 0; } // every data block is an MCU, so countdown the restart interval @@ -3195,7 +3266,8 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg * z) { short * data = z->img_comp[n].coeff + 64 * (x2 + y2 * z->img_comp[n].coeff_w); if (!stbi__jpeg_decode_block_prog_dc( - z, data, &z->huff_dc[z->img_comp[n].hd], n)) + z, data, &z->huff_dc[z->img_comp[n].hd], n + )) return 0; } } @@ -3231,9 +3303,10 @@ static void stbi__jpeg_finish(stbi__jpeg * z) { short * data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]); - z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 - + i * 8, - z->img_comp[n].w2, data); + z->idct_block_kernel( + z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, + z->img_comp[n].w2, data + ); } } } @@ -3283,7 +3356,8 @@ static int stbi__process_marker(stbi__jpeg * z, int m) { if (n > 256) return stbi__err( "bad DHT header", - "Corrupt JPEG"); // Loop over i < n would write past end of values! + "Corrupt JPEG" + ); // Loop over i < n would write past end of values! L -= 17; if (tc == 0) { if (!stbi__build_huffman(z->huff_dc + th, sizes)) return 0; @@ -3410,13 +3484,16 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) { if (Lf < 11) return stbi__err("bad SOF len", "Corrupt JPEG"); // JPEG p = stbi__get8(s); if (p != 8) - return stbi__err("only 8-bit", - "JPEG format not supported: 8-bit only"); // JPEG baseline + return stbi__err( + "only 8-bit", + "JPEG format not supported: 8-bit only" + ); // JPEG baseline s->img_y = stbi__get16be(s); if (s->img_y == 0) return stbi__err( "no header height", - "JPEG format not supported: delayed height"); // Legal, but we don't handle it--but neither does IJG + "JPEG format not supported: delayed height" + ); // Legal, but we don't handle it--but neither does IJG s->img_x = stbi__get16be(s); if (s->img_x == 0) return stbi__err("0 width", "Corrupt JPEG"); // JPEG requires if (s->img_y > STBI_MAX_DIMENSIONS) @@ -3493,8 +3570,9 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) { z->img_comp[i].linebuf = NULL; z->img_comp[i].raw_data = stbi__malloc_mad2(z->img_comp[i].w2, z->img_comp[i].h2, 15); if (z->img_comp[i].raw_data == NULL) - return stbi__free_jpeg_components(z, i + 1, - stbi__err("outofmem", "Out of memory")); + return stbi__free_jpeg_components( + z, i + 1, stbi__err("outofmem", "Out of memory") + ); // align blocks for idct using mmx/sse z->img_comp[i].data = (stbi_uc *) (((size_t) z->img_comp[i].raw_data + 15) & ~15); if (z->progressive) { @@ -3504,8 +3582,9 @@ static int stbi__process_frame_header(stbi__jpeg * z, int scan) { z->img_comp[i].raw_coeff = stbi__malloc_mad3(z->img_comp[i].w2, z->img_comp[i].h2, sizeof(short), 15); if (z->img_comp[i].raw_coeff == NULL) - return stbi__free_jpeg_components(z, i + 1, - stbi__err("outofmem", "Out of memory")); + return stbi__free_jpeg_components( + z, i + 1, stbi__err("outofmem", "Out of memory") + ); z->img_comp[i].coeff = (short *) (((size_t) z->img_comp[i].raw_coeff + 15) & ~15); } } @@ -3603,13 +3682,14 @@ static int stbi__decode_jpeg_image(stbi__jpeg * j) { // static jfif-centered resampling (across block boundaries) -typedef stbi_uc * (*resample_row_func)(stbi_uc * out, stbi_uc * in0, stbi_uc * in1, int w, - int hs); +typedef stbi_uc * (*resample_row_func)( + stbi_uc * out, stbi_uc * in0, stbi_uc * in1, int w, int hs +); #define stbi__div4(x) ((stbi_uc) ((x) >> 2)) -static stbi_uc * resample_row_1(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, - int hs) { +static stbi_uc * +resample_row_1(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { STBI_NOTUSED(out); STBI_NOTUSED(in_far); STBI_NOTUSED(w); @@ -3617,8 +3697,8 @@ static stbi_uc * resample_row_1(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_f return in_near; } -static stbi_uc * stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // need to generate two samples vertically for every one in input int i; STBI_NOTUSED(hs); @@ -3626,8 +3706,8 @@ static stbi_uc * stbi__resample_row_v_2(stbi_uc * out, stbi_uc * in_near, stbi_u return out; } -static stbi_uc * stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // need to generate two samples horizontally for every one in input int i; stbi_uc * input = in_near; @@ -3656,8 +3736,8 @@ static stbi_uc * stbi__resample_row_h_2(stbi_uc * out, stbi_uc * in_near, stbi_u #define stbi__div16(x) ((stbi_uc) ((x) >> 4)) -static stbi_uc * stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // need to generate 2x2 samples for every one in input int i, t0, t1; if (w == 1) { @@ -3681,8 +3761,9 @@ static stbi_uc * stbi__resample_row_hv_2(stbi_uc * out, stbi_uc * in_near, stbi_ } #if defined(STBI_SSE2) || defined(STBI_NEON) -static stbi_uc * stbi__resample_row_hv_2_simd(stbi_uc * out, stbi_uc * in_near, - stbi_uc * in_far, int w, int hs) { +static stbi_uc * stbi__resample_row_hv_2_simd( + stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs +) { // need to generate 2x2 samples for every one in input int i = 0, t0, t1; @@ -3797,8 +3878,8 @@ static stbi_uc * stbi__resample_row_hv_2_simd(stbi_uc * out, stbi_uc * in_near, } #endif -static stbi_uc * stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, - int w, int hs) { +static stbi_uc * +stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near, stbi_uc * in_far, int w, int hs) { // resample with nearest-neighbor int i, j; STBI_NOTUSED(in_far); @@ -3810,8 +3891,10 @@ static stbi_uc * stbi__resample_row_generic(stbi_uc * out, stbi_uc * in_near, st // this is a reduced-precision calculation of YCbCr-to-RGB introduced // to make sure the code produces the same results in both SIMD and scalar #define stbi__float2fixed(x) (((int) ((x) * 4096.0f + 0.5f)) << 8) -static void stbi__YCbCr_to_RGB_row(stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, - const stbi_uc * pcr, int count, int step) { +static void stbi__YCbCr_to_RGB_row( + stbi_uc * out, const stbi_uc * y, const stbi_uc * pcb, const stbi_uc * pcr, int count, + int step +) { int i; for (i = 0; i < count; ++i) { int y_fixed = (y[i] << 20) + (1 << 19); // rounding @@ -3846,8 +3929,10 @@ static void stbi__YCbCr_to_RGB_row(stbi_uc * out, const stbi_uc * y, const stbi_ } #if defined(STBI_SSE2) || defined(STBI_NEON) -static void stbi__YCbCr_to_RGB_simd(stbi_uc * out, stbi_uc const * y, stbi_uc const * pcb, - stbi_uc const * pcr, int count, int step) { +static void stbi__YCbCr_to_RGB_simd( + stbi_uc * out, stbi_uc const * y, stbi_uc const * pcb, stbi_uc const * pcr, int count, + int step +) { int i = 0; #ifdef STBI_SSE2 @@ -4031,8 +4116,8 @@ static stbi_uc stbi__blinn_8x8(stbi_uc x, stbi_uc y) { return (stbi_uc) ((t + (t >> 8)) >> 8); } -static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * comp, - int req_comp) { +static stbi_uc * +load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * comp, int req_comp) { int n, decode_n, is_rgb; z->s->img_n = 0; // make stbi__cleanup_jpeg safe @@ -4107,8 +4192,10 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * for (k = 0; k < decode_n; ++k) { stbi__resample * r = &res_comp[k]; int y_bot = r->ystep >= (r->vs >> 1); - coutput[k] = r->resample(z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0, - y_bot ? r->line0 : r->line1, r->w_lores, r->hs); + coutput[k] = r->resample( + z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0, + y_bot ? r->line0 : r->line1, r->w_lores, r->hs + ); if (++r->ystep >= r->vs) { r->ystep = 0; r->line0 = r->line1; @@ -4206,8 +4293,9 @@ static stbi_uc * load_jpeg_image(stbi__jpeg * z, int * out_x, int * out_y, int * } } -static void * stbi__jpeg_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__jpeg_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { unsigned char * result; stbi__jpeg * j = (stbi__jpeg *) stbi__malloc(sizeof(stbi__jpeg)); if (!j) return stbi__errpuc("outofmem", "Out of memory"); @@ -4432,8 +4520,10 @@ stbi_inline static int stbi__zhuffman_decode(stbi__zbuf * a, stbi__zhuffman * z) return stbi__zhuffman_decode_slowpath(a, z); } -static int stbi__zexpand(stbi__zbuf * z, char * zout, - int n) // need to make room for n bytes +static int stbi__zexpand( + stbi__zbuf * z, char * zout, + int n +) // need to make room for n bytes { char * q; unsigned int cur, limit, old_limit; @@ -4500,7 +4590,8 @@ static int stbi__parse_huffman_block(stbi__zbuf * a) { if (z >= 286) return stbi__err( "bad huffman code", - "Corrupt PNG"); // per DEFLATE, length codes 286 and 287 must not appear in compressed data + "Corrupt PNG" + ); // per DEFLATE, length codes 286 and 287 must not appear in compressed data z -= 257; len = stbi__zlength_base[z]; if (stbi__zlength_extra[z]) len += stbi__zreceive(a, stbi__zlength_extra[z]); @@ -4508,7 +4599,8 @@ static int stbi__parse_huffman_block(stbi__zbuf * a) { if (z < 0 || z >= 30) return stbi__err( "bad huffman code", - "Corrupt PNG"); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data + "Corrupt PNG" + ); // per DEFLATE, distance codes 30 and 31 must not appear in compressed data dist = stbi__zdist_base[z]; if (stbi__zdist_extra[z]) dist += stbi__zreceive(a, stbi__zdist_extra[z]); if (zout - a->zout_start < dist) return stbi__err("bad dist", "Corrupt PNG"); @@ -4617,8 +4709,10 @@ static int stbi__parse_zlib_header(stbi__zbuf * a) { if ((cmf * 256 + flg) % 31 != 0) return stbi__err("bad zlib header", "Corrupt PNG"); // zlib spec if (flg & 32) - return stbi__err("no preset dict", - "Corrupt PNG"); // preset dictionary not allowed in png + return stbi__err( + "no preset dict", + "Corrupt PNG" + ); // preset dictionary not allowed in png if (cm != 8) return stbi__err("bad compression", "Corrupt PNG"); // DEFLATE required for png @@ -4692,8 +4786,9 @@ static int stbi__do_zlib(stbi__zbuf * a, char * obuf, int olen, int exp, int par return stbi__parse_zlib(a, parse_header); } -STBIDEF char * stbi_zlib_decode_malloc_guesssize(const char * buffer, int len, - int initial_size, int * outlen) { +STBIDEF char * stbi_zlib_decode_malloc_guesssize( + const char * buffer, int len, int initial_size, int * outlen +) { stbi__zbuf a; char * p = (char *) stbi__malloc(initial_size); if (p == NULL) return NULL; @@ -4712,9 +4807,9 @@ STBIDEF char * stbi_zlib_decode_malloc(char const * buffer, int len, int * outle return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen); } -STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag(const char * buffer, int len, - int initial_size, int * outlen, - int parse_header) { +STBIDEF char * stbi_zlib_decode_malloc_guesssize_headerflag( + const char * buffer, int len, int initial_size, int * outlen, int parse_header +) { stbi__zbuf a; char * p = (char *) stbi__malloc(initial_size); if (p == NULL) return NULL; @@ -4752,8 +4847,8 @@ STBIDEF char * stbi_zlib_decode_noheader_malloc(char const * buffer, int len, in } } -STBIDEF int stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, - int ilen) { +STBIDEF int +stbi_zlib_decode_noheader_buffer(char * obuffer, int olen, const char * ibuffer, int ilen) { stbi__zbuf a; a.zbuffer = (stbi_uc *) ibuffer; a.zbuffer_end = (stbi_uc *) ibuffer + ilen; @@ -4831,8 +4926,8 @@ static const stbi_uc stbi__depth_scale_table[9] = {0, 0xff, 0x55, 0, 0x11, 0, 0, // adds an extra all-255 alpha channel // dest == src is legal // img_n must be 1 or 3 -static void stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src, stbi__uint32 x, - int img_n) { +static void +stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src, stbi__uint32 x, int img_n) { int i; // must process data backwards since we allow dest==src if (img_n == 1) { @@ -4852,9 +4947,10 @@ static void stbi__create_png_alpha_expand8(stbi_uc * dest, stbi_uc * src, stbi__ } // create the png data from post-deflated data -static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 raw_len, - int out_n, stbi__uint32 x, stbi__uint32 y, int depth, - int color) { +static int stbi__create_png_image_raw( + stbi__png * a, stbi_uc * raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, + stbi__uint32 y, int depth, int color +) { int bytes = (depth == 16 ? 2 : 1); stbi__context * s = a->s; stbi__uint32 i, j, stride = x * out_n * bytes; @@ -4869,8 +4965,10 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 int width = x; STBI_ASSERT(out_n == s->img_n || out_n == s->img_n + 1); - a->out = (stbi_uc *) stbi__malloc_mad3(x, y, output_bytes, - 0); // extra bytes to write off the end into + a->out = (stbi_uc *) stbi__malloc_mad3( + x, y, output_bytes, + 0 + ); // extra bytes to write off the end into if (!a->out) return stbi__err("outofmem", "Out of memory"); // note: error exits here don't need to clean up a->out individually, @@ -4937,11 +5035,13 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 case STBI__F_paeth: for (k = 0; k < filter_bytes; ++k) cur[k] = STBI__BYTECAST( - raw[k] + prior[k]); // prior[k] == stbi__paeth(0,prior[k],0) + raw[k] + prior[k] + ); // prior[k] == stbi__paeth(0,prior[k],0) for (k = filter_bytes; k < nk; ++k) - cur[k] = STBI__BYTECAST(raw[k] - + stbi__paeth(cur[k - filter_bytes], prior[k], - prior[k - filter_bytes])); + cur[k] = STBI__BYTECAST( + raw[k] + + stbi__paeth(cur[k - filter_bytes], prior[k], prior[k - filter_bytes]) + ); break; case STBI__F_avg_first: memcpy(cur, raw, filter_bytes); @@ -5022,16 +5122,18 @@ static int stbi__create_png_image_raw(stbi__png * a, stbi_uc * raw, stbi__uint32 return 1; } -static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data, - stbi__uint32 image_data_len, int out_n, int depth, int color, - int interlaced) { +static int stbi__create_png_image( + stbi__png * a, stbi_uc * image_data, stbi__uint32 image_data_len, int out_n, int depth, + int color, int interlaced +) { int bytes = (depth == 16 ? 2 : 1); int out_bytes = out_n * bytes; stbi_uc * final; int p; if (!interlaced) - return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, - a->s->img_y, depth, color); + return stbi__create_png_image_raw( + a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color + ); // de-interlacing final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); @@ -5047,8 +5149,9 @@ static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data, y = (a->s->img_y - yorig[p] + yspc[p] - 1) / yspc[p]; if (x && y) { stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y; - if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, - color)) { + if (!stbi__create_png_image_raw( + a, image_data, image_data_len, out_n, x, y, depth, color + )) { STBI_FREE(final); return 0; } @@ -5056,8 +5159,10 @@ static int stbi__create_png_image(stbi__png * a, stbi_uc * image_data, for (i = 0; i < x; ++i) { int out_y = j * yspc[p] + yorig[p]; int out_x = i * xspc[p] + xorig[p]; - memcpy(final + out_y * a->s->img_x * out_bytes + out_x * out_bytes, - a->out + (j * x + i) * out_bytes, out_bytes); + memcpy( + final + out_y * a->s->img_x * out_bytes + out_x * out_bytes, + a->out + (j * x + i) * out_bytes, out_bytes + ); } } STBI_FREE(a->out); @@ -5270,8 +5375,9 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { z->depth = stbi__get8(s); if (z->depth != 1 && z->depth != 2 && z->depth != 4 && z->depth != 8 && z->depth != 16) - return stbi__err("1/2/4/8/16-bit only", - "PNG not supported: 1/2/4/8/16-bit only"); + return stbi__err( + "1/2/4/8/16-bit only", "PNG not supported: 1/2/4/8/16-bit only" + ); color = stbi__get8(s); if (color > 6) return stbi__err("bad ctype", "Corrupt PNG"); if (color == 3 && z->depth == 16) return stbi__err("bad ctype", "Corrupt PNG"); @@ -5385,15 +5491,17 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; z->expanded = (stbi_uc *) stbi_zlib_decode_malloc_guesssize_headerflag( - (char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone); + (char *) z->idata, ioff, raw_len, (int *) &raw_len, !is_iphone + ); if (z->expanded == NULL) return 0; // zlib should set error STBI_FREE(z->idata); z->idata = NULL; if ((req_comp == s->img_n + 1 && req_comp != 3 && !pal_img_n) || has_trans) s->img_out_n = s->img_n + 1; else s->img_out_n = s->img_n; - if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, z->depth, - color, interlace)) + if (!stbi__create_png_image( + z, z->expanded, raw_len, s->img_out_n, z->depth, color, interlace + )) return 0; if (has_trans) { if (z->depth == 16) { @@ -5432,8 +5540,9 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { invalid_chunk[2] = STBI__BYTECAST(c.type >> 8); invalid_chunk[3] = STBI__BYTECAST(c.type >> 0); #endif - return stbi__err(invalid_chunk, - "PNG not supported: unknown PNG chunk type"); + return stbi__err( + invalid_chunk, "PNG not supported: unknown PNG chunk type" + ); } stbi__skip(s, c.length); break; @@ -5443,25 +5552,30 @@ static int stbi__parse_png_file(stbi__png * z, int scan, int req_comp) { } } -static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n, int req_comp, - stbi__result_info * ri) { +static void * +stbi__do_png(stbi__png * p, int * x, int * y, int * n, int req_comp, stbi__result_info * ri) { void * result = NULL; if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error"); if (stbi__parse_png_file(p, STBI__SCAN_load, req_comp)) { if (p->depth <= 8) ri->bits_per_channel = 8; else if (p->depth == 16) ri->bits_per_channel = 16; else - return stbi__errpuc("bad bits_per_channel", - "PNG not supported: unsupported color depth"); + return stbi__errpuc( + "bad bits_per_channel", "PNG not supported: unsupported color depth" + ); result = p->out; p->out = NULL; if (req_comp && req_comp != p->s->img_out_n) { if (ri->bits_per_channel == 8) - result = stbi__convert_format((unsigned char *) result, p->s->img_out_n, - req_comp, p->s->img_x, p->s->img_y); + result = stbi__convert_format( + (unsigned char *) result, p->s->img_out_n, req_comp, p->s->img_x, + p->s->img_y + ); else - result = stbi__convert_format16((stbi__uint16 *) result, p->s->img_out_n, - req_comp, p->s->img_x, p->s->img_y); + result = stbi__convert_format16( + (stbi__uint16 *) result, p->s->img_out_n, req_comp, p->s->img_x, + p->s->img_y + ); p->s->img_out_n = req_comp; if (result == NULL) return result; } @@ -5479,8 +5593,9 @@ static void * stbi__do_png(stbi__png * p, int * x, int * y, int * n, int req_com return result; } -static void * stbi__png_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__png_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi__png p; p.s = s; return stbi__do_png(&p, x, y, comp, req_comp, ri); @@ -5667,12 +5782,16 @@ static void * stbi__bmp_parse_header(stbi__context * s, stbi__bmp_data * info) { if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE"); if (compress >= 4) - return stbi__errpuc("BMP JPEG/PNG", - "BMP type not supported: unsupported " - "compression"); // this includes PNG/JPEG modes + return stbi__errpuc( + "BMP JPEG/PNG", + "BMP type not supported: unsupported " + "compression" + ); // this includes PNG/JPEG modes if (compress == 3 && info->bpp != 16 && info->bpp != 32) - return stbi__errpuc("bad BMP", - "bad BMP"); // bitfields requires 16 or 32 bits/pixel + return stbi__errpuc( + "bad BMP", + "bad BMP" + ); // bitfields requires 16 or 32 bits/pixel stbi__get32le(s); // discard sizeof stbi__get32le(s); // discard hres stbi__get32le(s); // discard vres @@ -5723,8 +5842,9 @@ static void * stbi__bmp_parse_header(stbi__context * s, stbi__bmp_data * info) { return (void *) 1; } -static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__bmp_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * out; unsigned int mr = 0, mg = 0, mb = 0, ma = 0, all_a; stbi_uc pal[256][4]; @@ -5804,8 +5924,9 @@ static void * stbi__bmp_load(stbi__context * s, int * x, int * y, int * comp, in if (info.hsz != 12) stbi__get8(s); pal[i][3] = 255; } - stbi__skip(s, info.offset - info.extra_read - info.hsz - - psize * (info.hsz == 12 ? 3 : 4)); + stbi__skip( + s, info.offset - info.extra_read - info.hsz - psize * (info.hsz == 12 ? 3 : 4) + ); if (info.bpp == 1) width = (s->img_x + 7) >> 3; else if (info.bpp == 4) width = (s->img_x + 1) >> 1; else if (info.bpp == 8) width = s->img_x; @@ -6023,8 +6144,9 @@ static int stbi__tga_info(stbi__context * s, int * x, int * y, int * comp) { } tga_comp = stbi__tga_get_comp(tga_colormap_bpp, 0, NULL); } else { - tga_comp = stbi__tga_get_comp(tga_bits_per_pixel, - (tga_image_type == 3) || (tga_image_type == 11), NULL); + tga_comp = stbi__tga_get_comp( + tga_bits_per_pixel, (tga_image_type == 3) || (tga_image_type == 11), NULL + ); } if (!tga_comp) { stbi__rewind(s); @@ -6087,8 +6209,9 @@ static void stbi__tga_read_rgb16(stbi__context * s, stbi_uc * out) { // so let's treat all 15 and 16bit TGAs as RGB with no alpha. } -static void * stbi__tga_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__tga_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { // read in the TGA header stuff int tga_offset = stbi__get8(s); int tga_indexed = stbi__get8(s); @@ -6325,8 +6448,10 @@ static int stbi__psd_decode_rle(stbi__context * s, stbi_uc * p, int pixelCount) return 1; } -static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri, int bpc) { +static void * stbi__psd_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri, + int bpc +) { int pixelCount; int channelCount, compression; int channel, i; @@ -6349,8 +6474,9 @@ static void * stbi__psd_load(stbi__context * s, int * x, int * y, int * comp, in // Read the number of channels (R, G, B, A, etc). channelCount = stbi__get16be(s); if (channelCount < 0 || channelCount > 16) - return stbi__errpuc("wrong channel count", - "Unsupported number of channels in PSD image"); + return stbi__errpuc( + "wrong channel count", "Unsupported number of channels in PSD image" + ); // Read the rows and columns of the image. h = stbi__get32be(s); @@ -6575,8 +6701,8 @@ static void stbi__copyval(int channel, stbi_uc * dest, const stbi_uc * src) { if (channel & mask) dest[i] = src[i]; } -static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, int * comp, - stbi_uc * result) { +static stbi_uc * +stbi__pic_load_core(stbi__context * s, int width, int height, int * comp, stbi_uc * result) { int act_comp = 0, num_packets = 0, y, chained; stbi__pic_packet packets[10]; @@ -6632,8 +6758,9 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, i count = stbi__get8(s); if (stbi__at_eof(s)) - return stbi__errpuc("bad file", - "file too short (pure read count)"); + return stbi__errpuc( + "bad file", "file too short (pure read count)" + ); if (count > left) count = (stbi_uc) left; @@ -6650,8 +6777,9 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, i while (left > 0) { int count = stbi__get8(s), i; if (stbi__at_eof(s)) - return stbi__errpuc("bad file", - "file too short (mixed read count)"); + return stbi__errpuc( + "bad file", "file too short (mixed read count)" + ); if (count >= 128) { // Repeated stbi_uc value[4]; @@ -6684,8 +6812,9 @@ static stbi_uc * stbi__pic_load_core(stbi__context * s, int width, int height, i return result; } -static void * stbi__pic_load(stbi__context * s, int * px, int * py, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__pic_load( + stbi__context * s, int * px, int * py, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * result; int i, x, y, internal_comp; STBI_NOTUSED(ri); @@ -6780,8 +6909,9 @@ static int stbi__gif_test(stbi__context * s) { return r; } -static void stbi__gif_parse_colortable(stbi__context * s, stbi_uc pal[256][4], int num_entries, - int transp) { +static void stbi__gif_parse_colortable( + stbi__context * s, stbi_uc pal[256][4], int num_entries, int transp +) { int i; for (i = 0; i < num_entries; ++i) { pal[i][2] = stbi__get8(s); @@ -6957,8 +7087,9 @@ static stbi_uc * stbi__process_gif_raster(stbi__context * s, stbi__gif * g) { // this function is designed to support animated gifs, although stb_image doesn't support it // two back is the image from two frames ago, used for a very specific disposal format -static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * comp, - int req_comp, stbi_uc * two_back) { +static stbi_uc * stbi__gif_load_next( + stbi__context * s, stbi__gif * g, int * comp, int req_comp, stbi_uc * two_back +) { int dispose; int first_frame; int pi; @@ -6983,8 +7114,10 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * com // background colour is only used for pixels that are not rendered first frame, after that "background" // color refers to the color that was there the previous frame. memset(g->out, 0x00, 4 * pcount); - memset(g->background, 0x00, - 4 * pcount); // state of the background (starts transparent) + memset( + g->background, 0x00, + 4 * pcount + ); // state of the background (starts transparent) memset(g->history, 0x00, pcount); // pixels that were affected previous frame first_frame = 1; @@ -7066,8 +7199,10 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * com } if (g->lflags & 0x80) { - stbi__gif_parse_colortable(s, g->lpal, 2 << (g->lflags & 7), - g->eflags & 0x01 ? g->transparent : -1); + stbi__gif_parse_colortable( + s, g->lpal, 2 << (g->lflags & 7), + g->eflags & 0x01 ? g->transparent : -1 + ); g->color_table = (stbi_uc *) g->lpal; } else if (g->flags & 0x80) { g->color_table = (stbi_uc *) g->pal; @@ -7101,8 +7236,8 @@ static stbi_uc * stbi__gif_load_next(stbi__context * s, stbi__gif * g, int * com if (len == 4) { g->eflags = stbi__get8(s); g->delay = 10 - * stbi__get16le( - s); // delay - 1/100th of a second, saving as 1/1000ths. + * stbi__get16le(s + ); // delay - 1/100th of a second, saving as 1/1000ths. // unset old transparent if (g->transparent >= 0) { @@ -7148,8 +7283,9 @@ static void * stbi__load_gif_main_outofmem(stbi__gif * g, stbi_uc * out, int ** return stbi__errpuc("outofmem", "Out of memory"); } -static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int * y, int * z, - int * comp, int req_comp) { +static void * stbi__load_gif_main( + stbi__context * s, int ** delays, int * x, int * y, int * z, int * comp, int req_comp +) { if (stbi__gif_test(s)) { int layers = 0; stbi_uc * u = 0; @@ -7188,8 +7324,9 @@ static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int } if (delays) { - int * new_delays = (int *) STBI_REALLOC_SIZED(*delays, delays_size, - sizeof(int) * layers); + int * new_delays = (int *) STBI_REALLOC_SIZED( + *delays, delays_size, sizeof(int) * layers + ); if (!new_delays) return stbi__load_gif_main_outofmem(&g, out, delays); *delays = new_delays; delays_size = layers * sizeof(int); @@ -7231,8 +7368,9 @@ static void * stbi__load_gif_main(stbi__context * s, int ** delays, int * x, int } } -static void * stbi__gif_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__gif_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * u = 0; stbi__gif g; memset(&g, 0, sizeof(g)); @@ -7336,8 +7474,9 @@ static void stbi__hdr_convert(float * output, stbi_uc * input, int req_comp) { } } -static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static float * stbi__hdr_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { char buffer[STBI__HDR_BUFLEN]; char * token; int valid = 0; @@ -7404,8 +7543,9 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, i stbi_uc rgbe[4]; main_decode_loop: stbi__getn(s, rgbe, 4); - stbi__hdr_convert(hdr_data + j * width * req_comp + i * req_comp, rgbe, - req_comp); + stbi__hdr_convert( + hdr_data + j * width * req_comp + i * req_comp, rgbe, req_comp + ); } } } else { @@ -7472,8 +7612,9 @@ static float * stbi__hdr_load(stbi__context * s, int * x, int * y, int * comp, i } } for (i = 0; i < width; ++i) - stbi__hdr_convert(hdr_data + (j * width + i) * req_comp, scanline + i * 4, - req_comp); + stbi__hdr_convert( + hdr_data + (j * width + i) * req_comp, scanline + i * 4, req_comp + ); } if (scanline) STBI_FREE(scanline); } @@ -7689,8 +7830,9 @@ static int stbi__pnm_test(stbi__context * s) { return 1; } -static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, int req_comp, - stbi__result_info * ri) { +static void * stbi__pnm_load( + stbi__context * s, int * x, int * y, int * comp, int req_comp, stbi__result_info * ri +) { stbi_uc * out; STBI_NOTUSED(ri); @@ -7710,8 +7852,9 @@ static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, in if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0)) return stbi__errpuc("too large", "PNM too large"); - out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, - 0); + out = (stbi_uc *) stbi__malloc_mad4( + s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0 + ); if (!out) return stbi__errpuc("outofmem", "Out of memory"); if (!stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8))) { STBI_FREE(out); @@ -7720,8 +7863,9 @@ static void * stbi__pnm_load(stbi__context * s, int * x, int * y, int * comp, in if (req_comp && req_comp != s->img_n) { if (ri->bits_per_channel == 16) { - out = (stbi_uc *) stbi__convert_format16((stbi__uint16 *) out, s->img_n, req_comp, - s->img_x, s->img_y); + out = (stbi_uc *) stbi__convert_format16( + (stbi__uint16 *) out, s->img_n, req_comp, s->img_x, s->img_y + ); } else { out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y); } @@ -7753,8 +7897,10 @@ static int stbi__pnm_getinteger(stbi__context * s, char * c) { value = value * 10 + (*c - '0'); *c = (char) stbi__get8(s); if ((value > 214748364) || (value == 214748364 && *c > '7')) - return stbi__err("integer parse overflow", - "Parsing an integer in the PPM header overflowed a 32-bit int"); + return stbi__err( + "integer parse overflow", + "Parsing an integer in the PPM header overflowed a 32-bit int" + ); } return value; @@ -7795,8 +7941,9 @@ static int stbi__pnm_info(stbi__context * s, int * x, int * y, int * comp) { maxv = stbi__pnm_getinteger(s, &c); // read max value if (maxv > 65535) - return stbi__err("max value > 65535", - "PPM image supports only 8-bit and 16-bit images"); + return stbi__err( + "max value > 65535", "PPM image supports only 8-bit and 16-bit images" + ); else if (maxv > 255) return 16; else return 8; } @@ -7902,15 +8049,16 @@ STBIDEF int stbi_is_16_bit_from_file(FILE * f) { } #endif // !STBI_NO_STDIO -STBIDEF int stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, - int * comp) { +STBIDEF int +stbi_info_from_memory(stbi_uc const * buffer, int len, int * x, int * y, int * comp) { stbi__context s; stbi__start_mem(&s, buffer, len); return stbi__info_main(&s, x, y, comp); } -STBIDEF int stbi_info_from_callbacks(stbi_io_callbacks const * c, void * user, int * x, - int * y, int * comp) { +STBIDEF int stbi_info_from_callbacks( + stbi_io_callbacks const * c, void * user, int * x, int * y, int * comp +) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks *) c, user); return stbi__info_main(&s, x, y, comp); diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp index b340826..27fa97f 100644 --- a/src/crepe/Particle.cpp +++ b/src/crepe/Particle.cpp @@ -2,8 +2,9 @@ using namespace crepe; -void Particle::reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, - float angle) { +void Particle::reset( + unsigned int lifespan, const vec2 & position, const vec2 & velocity, float angle +) { // Initialize the particle state this->time_in_life = 0; this->lifespan = lifespan; diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h index ee0cd66..c013de5 100644 --- a/src/crepe/Particle.h +++ b/src/crepe/Particle.h @@ -41,8 +41,8 @@ public: * \param velocity The initial velocity of the particle. * \param angle The angle of the particle's trajectory or orientation. */ - void reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, - float angle); + void + reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, float angle); /** * \brief Updates the particle's state. * diff --git a/src/crepe/api/AI.cpp b/src/crepe/api/AI.cpp index 2195249..2fedaf4 100644 --- a/src/crepe/api/AI.cpp +++ b/src/crepe/api/AI.cpp @@ -8,8 +8,9 @@ namespace crepe { AI::AI(game_object_id_t id, float max_force) : Component(id), max_force(max_force) {} -void AI::make_circle_path(float radius, const vec2 & center, float start_angle, - bool clockwise) { +void AI::make_circle_path( + float radius, const vec2 & center, float start_angle, bool clockwise +) { if (radius <= 0) { throw std::runtime_error("Radius must be greater than 0"); } @@ -25,19 +26,25 @@ void AI::make_circle_path(float radius, const vec2 & center, float start_angle, if (clockwise) { for (float i = start_angle; i < 2 * M_PI + start_angle; i += step) { - path.push_back(vec2{static_cast<float>(center.x + radius * cos(i)), - static_cast<float>(center.y + radius * sin(i))}); + path.push_back(vec2 { + static_cast<float>(center.x + radius * cos(i)), + static_cast<float>(center.y + radius * sin(i)) + }); } } else { for (float i = start_angle; i > start_angle - 2 * M_PI; i -= step) { - path.push_back(vec2{static_cast<float>(center.x + radius * cos(i)), - static_cast<float>(center.y + radius * sin(i))}); + path.push_back(vec2 { + static_cast<float>(center.x + radius * cos(i)), + static_cast<float>(center.y + radius * sin(i)) + }); } } } -void AI::make_oval_path(float radius_x, float radius_y, const vec2 & center, float start_angle, - bool clockwise, float rotation) { +void AI::make_oval_path( + float radius_x, float radius_y, const vec2 & center, float start_angle, bool clockwise, + float rotation +) { if (radius_x <= 0 && radius_y <= 0) { throw std::runtime_error("Radius must be greater than 0"); } @@ -73,14 +80,16 @@ void AI::make_oval_path(float radius_x, float radius_y, const vec2 & center, flo if (clockwise) { for (float i = start_angle; i < 2 * M_PI + start_angle; i += step) { - vec2 point = {static_cast<float>(center.x + radius_x * cos(i)), - static_cast<float>(center.y + radius_y * sin(i))}; + vec2 point + = {static_cast<float>(center.x + radius_x * cos(i)), + static_cast<float>(center.y + radius_y * sin(i))}; path.push_back(rotate_point(point, center)); } } else { for (float i = start_angle; i > start_angle - 2 * M_PI; i -= step) { - vec2 point = {static_cast<float>(center.x + radius_x * cos(i)), - static_cast<float>(center.y + radius_y * sin(i))}; + vec2 point + = {static_cast<float>(center.x + radius_x * cos(i)), + static_cast<float>(center.y + radius_y * sin(i))}; path.push_back(rotate_point(point, center)); } } diff --git a/src/crepe/api/AI.h b/src/crepe/api/AI.h index c780a91..bee11b3 100644 --- a/src/crepe/api/AI.h +++ b/src/crepe/api/AI.h @@ -70,8 +70,10 @@ public: * \param start_angle The start angle of the circle (in radians) * \param clockwise The direction of the circle */ - void make_circle_path(float radius, const vec2 & center = {0, 0}, float start_angle = 0, - bool clockwise = true); + void make_circle_path( + float radius, const vec2 & center = {0, 0}, float start_angle = 0, + bool clockwise = true + ); /** * \brief Make an oval path (for the path following behavior) * @@ -84,8 +86,10 @@ public: * \param clockwise The direction of the oval * \param rotation The rotation of the oval (in radians) */ - void make_oval_path(float radius_x, float radius_y, const vec2 & center = {0, 0}, - float start_angle = 0, bool clockwise = true, float rotation = 0); + void make_oval_path( + float radius_x, float radius_y, const vec2 & center = {0, 0}, float start_angle = 0, + bool clockwise = true, float rotation = 0 + ); public: //! The maximum force that can be applied to the entity (higher values will make the entity adjust faster) diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index b7eefb8..c558d86 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -7,8 +7,10 @@ using namespace crepe; -Animator::Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, - const uvec2 & grid_size, const Animator::Data & data) +Animator::Animator( + game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, + const uvec2 & grid_size, const Animator::Data & data +) : Component(id), spritesheet(spritesheet), grid_size(grid_size), diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 5918800..102894d 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -83,8 +83,10 @@ public: * This constructor sets up the Animator with the given parameters, and initializes the * animation system. */ - Animator(game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, - const uvec2 & grid_size, const Animator::Data & data); + Animator( + game_object_id_t id, Sprite & spritesheet, const ivec2 & single_frame_size, + const uvec2 & grid_size, const Animator::Data & data + ); ~Animator(); // dbg_trace public: diff --git a/src/crepe/api/Asset.cpp b/src/crepe/api/Asset.cpp index e148367..bab82e7 100644 --- a/src/crepe/api/Asset.cpp +++ b/src/crepe/api/Asset.cpp @@ -50,5 +50,5 @@ string Asset::whereami() const noexcept { bool Asset::operator==(const Asset & other) const noexcept { return this->src == other.src; } size_t std::hash<const Asset>::operator()(const Asset & asset) const noexcept { - return std::hash<string>{}(asset.get_path()); + return std::hash<string> {}(asset.get_path()); }; diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index b20e490..eaa56e8 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -68,7 +68,7 @@ private: typeof(loop) last_loop = loop; //! \} //! This source's voice handle - SoundHandle voice{}; + SoundHandle voice {}; }; } // namespace crepe diff --git a/src/crepe/api/BoxCollider.cpp b/src/crepe/api/BoxCollider.cpp index a893d41..f6b358d 100644 --- a/src/crepe/api/BoxCollider.cpp +++ b/src/crepe/api/BoxCollider.cpp @@ -4,7 +4,8 @@ using namespace crepe; -BoxCollider::BoxCollider(game_object_id_t game_object_id, const vec2 & dimensions, - const vec2 & offset) +BoxCollider::BoxCollider( + game_object_id_t game_object_id, const vec2 & dimensions, const vec2 & offset +) : Collider(game_object_id, offset), dimensions(dimensions) {} diff --git a/src/crepe/api/BoxCollider.h b/src/crepe/api/BoxCollider.h index d643e7f..229b90f 100644 --- a/src/crepe/api/BoxCollider.h +++ b/src/crepe/api/BoxCollider.h @@ -13,8 +13,9 @@ namespace crepe { */ class BoxCollider : public Collider { public: - BoxCollider(game_object_id_t game_object_id, const vec2 & dimensions, - const vec2 & offset = {0, 0}); + BoxCollider( + game_object_id_t game_object_id, const vec2 & dimensions, const vec2 & offset = {0, 0} + ); //! Width and height of the box collider vec2 dimensions; diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index 19a3296..b1466b5 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -6,8 +6,9 @@ using namespace crepe; -Camera::Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, - const Data & data) +Camera::Camera( + game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, const Data & data +) : Component(id), screen(screen), viewport_size(viewport_size), diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 54d9a73..3191b04 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -44,8 +44,10 @@ public: * \param viewport_size is the view of the world in game units * \param data the camera component data */ - Camera(game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, - const Camera::Data & data); + Camera( + game_object_id_t id, const ivec2 & screen, const vec2 & viewport_size, + const Camera::Data & data + ); ~Camera(); // dbg_trace only public: diff --git a/src/crepe/api/CircleCollider.cpp b/src/crepe/api/CircleCollider.cpp index 90ab5e7..e72800c 100644 --- a/src/crepe/api/CircleCollider.cpp +++ b/src/crepe/api/CircleCollider.cpp @@ -2,7 +2,8 @@ using namespace crepe; -CircleCollider::CircleCollider(game_object_id_t game_object_id, float radius, - const vec2 & offset) +CircleCollider::CircleCollider( + game_object_id_t game_object_id, float radius, const vec2 & offset +) : Collider(game_object_id, offset), radius(radius) {} diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index 22da836..e6ad4fa 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -13,8 +13,9 @@ namespace crepe { */ class CircleCollider : public Collider { public: - CircleCollider(game_object_id_t game_object_id, float radius, - const vec2 & offset = {0, 0}); + CircleCollider( + game_object_id_t game_object_id, float radius, const vec2 & offset = {0, 0} + ); //! Radius of the circle collider. float radius; diff --git a/src/crepe/api/Color.cpp b/src/crepe/api/Color.cpp index 29bd77a..6858aa8 100644 --- a/src/crepe/api/Color.cpp +++ b/src/crepe/api/Color.cpp @@ -2,11 +2,11 @@ using namespace crepe; -const Color Color::WHITE{0xff, 0xff, 0xff}; -const Color Color::RED{0xff, 0x00, 0x00}; -const Color Color::GREEN{0x00, 0xff, 0x00}; -const Color Color::BLUE{0x00, 0x00, 0xff}; -const Color Color::BLACK{0x00, 0x00, 0x00}; -const Color Color::CYAN{0x00, 0xff, 0xff}; -const Color Color::YELLOW{0xff, 0xff, 0x00}; -const Color Color::MAGENTA{0xff, 0x00, 0xff}; +const Color Color::WHITE {0xff, 0xff, 0xff}; +const Color Color::RED {0xff, 0x00, 0x00}; +const Color Color::GREEN {0x00, 0xff, 0x00}; +const Color Color::BLUE {0x00, 0x00, 0xff}; +const Color Color::BLACK {0x00, 0x00, 0x00}; +const Color Color::CYAN {0x00, 0xff, 0xff}; +const Color Color::YELLOW {0xff, 0xff, 0x00}; +const Color Color::MAGENTA {0xff, 0x00, 0xff}; diff --git a/src/crepe/api/Engine.cpp b/src/crepe/api/Engine.cpp index 2e9d35a..cd9786b 100644 --- a/src/crepe/api/Engine.cpp +++ b/src/crepe/api/Engine.cpp @@ -46,8 +46,10 @@ void Engine::loop() { try { systems.fixed_update(); } catch (const exception & e) { - Log::logf(Log::Level::WARNING, - "Uncaught exception in fixed update function: {}\n", e.what()); + Log::logf( + Log::Level::WARNING, "Uncaught exception in fixed update function: {}\n", + e.what() + ); } timer.advance_fixed_elapsed_time(); } @@ -55,8 +57,10 @@ void Engine::loop() { try { systems.frame_update(); } catch (const exception & e) { - Log::logf(Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", - e.what()); + Log::logf( + Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", + e.what() + ); } timer.enforce_frame_rate(); } diff --git a/src/crepe/api/Engine.h b/src/crepe/api/Engine.h index 700a0cd..452a856 100644 --- a/src/crepe/api/Engine.h +++ b/src/crepe/api/Engine.h @@ -54,26 +54,26 @@ private: Mediator mediator; //! SystemManager - SystemManager system_manager{mediator}; + SystemManager system_manager {mediator}; //! SDLContext instance - SDLContext sdl_context{mediator}; + SDLContext sdl_context {mediator}; //! Resource manager instance - ResourceManager resource_manager{mediator}; + ResourceManager resource_manager {mediator}; //! Component manager instance - ComponentManager component_manager{mediator}; + ComponentManager component_manager {mediator}; //! Scene manager instance - SceneManager scene_manager{mediator}; + SceneManager scene_manager {mediator}; //! LoopTimerManager instance - LoopTimerManager loop_timer{mediator}; + LoopTimerManager loop_timer {mediator}; //! EventManager instance - EventManager event_manager{mediator}; + EventManager event_manager {mediator}; //! Save manager instance - SaveManager save_manager{mediator}; + SaveManager save_manager {mediator}; //! ReplayManager instance - ReplayManager replay_manager{mediator}; + ReplayManager replay_manager {mediator}; }; } // namespace crepe diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 9b94cad..100e210 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -7,13 +7,15 @@ using namespace crepe; using namespace std; -GameObject::GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, - const std::string & tag, const vec2 & position, double rotation, - double scale) +GameObject::GameObject( + Mediator & mediator, game_object_id_t id, const std::string & name, + const std::string & tag, const vec2 & position, double rotation, double scale +) : id(id), mediator(mediator), - transform(mediator.component_manager->add_component<Transform>(this->id, position, - rotation, scale)), + transform(mediator.component_manager->add_component<Transform>( + this->id, position, rotation, scale + )), metadata(mediator.component_manager->add_component<Metadata>(this->id, name, tag)) {} void GameObject::set_parent(const GameObject & parent) { diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index 572ce3a..043913a 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -30,8 +30,10 @@ private: * \param rotation The rotation of the GameObject * \param scale The scale of the GameObject */ - GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, - const std::string & tag, const vec2 & position, double rotation, double scale); + GameObject( + Mediator & mediator, game_object_id_t id, const std::string & name, + const std::string & tag, const vec2 & position, double rotation, double scale + ); //! ComponentManager instances GameObject friend class ComponentManager; diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index 9a70334..341c1e2 100644 --- a/src/crepe/api/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp @@ -4,8 +4,9 @@ using namespace crepe; using namespace std; -ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, - const Data & data) +ParticleEmitter::ParticleEmitter( + game_object_id_t game_object_id, const Sprite & sprite, const Data & data +) : Component(game_object_id), sprite(sprite), data(data) { @@ -15,7 +16,7 @@ ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & } unique_ptr<Component> ParticleEmitter::save() const { - return unique_ptr<Component>{new ParticleEmitter(*this)}; + return unique_ptr<Component> {new ParticleEmitter(*this)}; } void ParticleEmitter::restore(const Component & snapshot) { diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp index ad729d2..84da7e8 100644 --- a/src/crepe/api/Scene.cpp +++ b/src/crepe/api/Scene.cpp @@ -4,8 +4,10 @@ using namespace crepe; SaveManager & Scene::get_save_manager() const { return mediator->save_manager; } -GameObject Scene::new_object(const std::string & name, const std::string & tag, - const vec2 & position, double rotation, double scale) { +GameObject Scene::new_object( + const std::string & name, const std::string & tag, const vec2 & position, double rotation, + double scale +) { // Forward the call to ComponentManager's new_object method return mediator->component_manager->new_object(name, tag, position, rotation, scale); } diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h index d552a43..b50a0fc 100644 --- a/src/crepe/api/Scene.h +++ b/src/crepe/api/Scene.h @@ -69,9 +69,10 @@ public: SaveManager & get_save_manager() const; //! \copydoc ComponentManager::new_object - GameObject new_object(const std::string & name, const std::string & tag = "", - const vec2 & position = {0, 0}, double rotation = 0, - double scale = 1); + GameObject new_object( + const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0}, + double rotation = 0, double scale = 1 + ); //! \copydoc ResourceManager::set_persistent void set_persistent(const Asset & asset, bool persistent); diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index bbee920..b000d9d 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -129,12 +129,14 @@ protected: void subscribe(const EventHandler<EventType> & callback); //! \copydoc EventManager::trigger_event template <typename EventType> - void trigger_event(const EventType & event = {}, - event_channel_t channel = EventManager::CHANNEL_ALL); + void trigger_event( + const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL + ); //! \copydoc EventManager::queue_event template <typename EventType> - void queue_event(const EventType & event = {}, - event_channel_t channel = EventManager::CHANNEL_ALL); + void queue_event( + const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL + ); //! \} /** @@ -179,7 +181,7 @@ protected: OptionalRef<Mediator> & mediator; replay(OptionalRef<Mediator> & mediator) : mediator(mediator) {} friend class Script; - } replay{mediator}; + } replay {mediator}; /** * \brief Utility function to retrieve the keyboard state diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index 4462a41..c7fa6ff 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -14,7 +14,8 @@ T & Script::get_component() const { RefVector<T> all_components = this->get_components<T>(); if (all_components.size() < 1) throw runtime_error( - format("Script: no component found with type = {}", typeid(T).name())); + format("Script: no component found with type = {}", typeid(T).name()) + ); return all_components.back().get(); } @@ -35,8 +36,9 @@ void Script::logf(std::format_string<Args...> fmt, Args &&... args) { } template <typename EventType> -void Script::subscribe_internal(const EventHandler<EventType> & callback, - event_channel_t channel) { +void Script::subscribe_internal( + const EventHandler<EventType> & callback, event_channel_t channel +) { EventManager & mgr = this->mediator->event_manager; subscription_t listener = mgr.subscribe<EventType>( [this, callback](const EventType & data) -> bool { @@ -54,7 +56,8 @@ void Script::subscribe_internal(const EventHandler<EventType> & callback, // call user-provided callback return callback(data); }, - channel); + channel + ); this->listeners.push_back(listener); } diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp index 4a94180..b24f0ac 100644 --- a/src/crepe/api/Text.cpp +++ b/src/crepe/api/Text.cpp @@ -2,8 +2,10 @@ using namespace crepe; -Text::Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, - const std::string & font_family, const Data & data, const std::string & text) +Text::Text( + game_object_id_t id, const vec2 & dimensions, const vec2 & offset, + const std::string & font_family, const Data & data, const std::string & text +) : UIObject(id, dimensions, offset), text(text), data(data), diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h index da40141..0289b85 100644 --- a/src/crepe/api/Text.h +++ b/src/crepe/api/Text.h @@ -48,8 +48,10 @@ public: * \param data Data struct containing extra text parameters. * \param font Optional font asset that can be passed or left empty. */ - Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, - const std::string & font_family, const Data & data, const std::string & text = ""); + Text( + game_object_id_t id, const vec2 & dimensions, const vec2 & offset, + const std::string & font_family, const Data & data, const std::string & text = "" + ); //! Label text. std::string text = ""; diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index fcfce14..b70174c 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -14,7 +14,7 @@ Transform::Transform(game_object_id_t id, const vec2 & point, double rotation, d } unique_ptr<Component> Transform::save() const { - return unique_ptr<Component>{new Transform(*this)}; + return unique_ptr<Component> {new Transform(*this)}; } void Transform::restore(const Component & snapshot) { diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp index 87f95ab..e284f5a 100644 --- a/src/crepe/facade/FontFacade.cpp +++ b/src/crepe/facade/FontFacade.cpp @@ -20,8 +20,9 @@ Asset FontFacade::get_font_asset(const string & font_family) { = FcNameParse(reinterpret_cast<const FcChar8 *>(font_family.c_str())); if (raw_pattern == NULL) throw runtime_error("Failed to create font pattern."); - unique_ptr<FcPattern, function<void(FcPattern *)>> pattern{ - raw_pattern, [](FcPattern * p) { FcPatternDestroy(p); }}; + unique_ptr<FcPattern, function<void(FcPattern *)>> pattern { + raw_pattern, [](FcPattern * p) { FcPatternDestroy(p); } + }; FcConfig * config = FcConfigGetCurrent(); if (config == NULL) throw runtime_error("Failed to get current Fontconfig configuration."); diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 64c1fe2..859f966 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -41,9 +41,10 @@ SDLContext::SDLContext(Mediator & mediator) { } auto & cfg = Config::get_instance().window_settings; - SDL_Window * tmp_window - = SDL_CreateWindow(cfg.window_title.c_str(), SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, cfg.default_size.x, cfg.default_size.y, 0); + SDL_Window * tmp_window = SDL_CreateWindow( + cfg.window_title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + cfg.default_size.x, cfg.default_size.y, 0 + ); if (!tmp_window) { throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError())); } @@ -52,8 +53,8 @@ SDLContext::SDLContext(Mediator & mediator) { SDL_Renderer * tmp_renderer = SDL_CreateRenderer(this->game_window.get(), -1, SDL_RENDERER_ACCELERATED); if (!tmp_renderer) { - throw runtime_error( - format("SDLContext: SDL_CreateRenderer error: {}", SDL_GetError())); + throw runtime_error(format("SDLContext: SDL_CreateRenderer error: {}", SDL_GetError()) + ); } this->game_renderer @@ -108,7 +109,7 @@ const keyboard_state_t & SDLContext::get_keyboard_state() { MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) { static const std::array<MouseButton, 5> MOUSE_BUTTON_LOOKUP_TABLE = [] { - std::array<MouseButton, 5> table{}; + std::array<MouseButton, 5> table {}; table.fill(MouseButton::NONE); table[SDL_BUTTON_LEFT] = MouseButton::LEFT_MOUSE; @@ -164,7 +165,7 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { - size / 2 + cam_aux_data.bar_size; } - return SDL_FRect{ + return SDL_FRect { .x = screen_pos.x, .y = screen_pos.y, .w = size.x, @@ -188,7 +189,7 @@ void SDLContext::draw(const RenderContext & ctx) { srcrect_ptr = &srcrect; } - SDL_FRect dstrect = this->get_dst_rect(SDLContext::DestinationRectangleData{ + SDL_FRect dstrect = this->get_dst_rect(SDLContext::DestinationRectangleData { .sprite = ctx.sprite, .texture = ctx.texture, .pos = ctx.pos, @@ -198,8 +199,10 @@ void SDLContext::draw(const RenderContext & ctx) { double angle = ctx.angle + data.angle_offset; this->set_color_texture(ctx.texture, ctx.sprite.data.color); - SDL_RenderCopyExF(this->game_renderer.get(), ctx.texture.get_img(), srcrect_ptr, &dstrect, - angle, NULL, render_flip); + SDL_RenderCopyExF( + this->game_renderer.get(), ctx.texture.get_img(), srcrect_ptr, &dstrect, angle, NULL, + render_flip + ); } void SDLContext::draw_text(const RenderText & data) { @@ -210,7 +213,7 @@ void SDLContext::draw_text(const RenderText & data) { std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface *)>> font_surface; std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> font_texture; - SDL_Color color{ + SDL_Color color { .r = text.data.text_color.r, .g = text.data.text_color.g, .b = text.data.text_color.b, @@ -232,20 +235,21 @@ void SDLContext::draw_text(const RenderText & data) { = {tmp_font_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; vec2 size = text.dimensions * cam_aux_data.render_scale * data.transform.scale; - vec2 screen_pos - = (absoluut_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2) - * cam_aux_data.render_scale - - size / 2 + cam_aux_data.bar_size; + vec2 screen_pos = (absoluut_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2 + ) * cam_aux_data.render_scale + - size / 2 + cam_aux_data.bar_size; - SDL_FRect dstrect{ + SDL_FRect dstrect { .x = screen_pos.x, .y = screen_pos.y, .w = size.x, .h = size.y, }; - SDL_RenderCopyExF(this->game_renderer.get(), font_texture.get(), NULL, &dstrect, - data.transform.rotation, NULL, SDL_FLIP_NONE); + SDL_RenderCopyExF( + this->game_renderer.get(), font_texture.get(), NULL, &dstrect, data.transform.rotation, + NULL, SDL_FLIP_NONE + ); } void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) { @@ -291,8 +295,10 @@ void SDLContext::update_camera_view(const Camera & cam, const vec2 & new_pos) { render_scale.x = render_scale.y = scale; } - SDL_SetRenderDrawColor(this->game_renderer.get(), cam_data.bg_color.r, cam_data.bg_color.g, - cam_data.bg_color.b, cam_data.bg_color.a); + SDL_SetRenderDrawColor( + this->game_renderer.get(), cam_data.bg_color.r, cam_data.bg_color.g, + cam_data.bg_color.b, cam_data.bg_color.a + ); SDL_Rect bg = { .x = 0, @@ -427,11 +433,12 @@ std::vector<EventData> SDLContext::get_events() { return event_list; } -void SDLContext::handle_window_event(const SDL_WindowEvent & window_event, - std::vector<EventData> & event_list) { +void SDLContext::handle_window_event( + const SDL_WindowEvent & window_event, std::vector<EventData> & event_list +) { switch (window_event.event) { case SDL_WINDOWEVENT_EXPOSED: - event_list.push_back(EventData{EventType::WINDOW_EXPOSE}); + event_list.push_back(EventData {EventType::WINDOW_EXPOSE}); break; case SDL_WINDOWEVENT_RESIZED: event_list.push_back(EventData{ @@ -455,16 +462,16 @@ void SDLContext::handle_window_event(const SDL_WindowEvent & window_event, break; case SDL_WINDOWEVENT_MINIMIZED: - event_list.push_back(EventData{EventType::WINDOW_MINIMIZE}); + event_list.push_back(EventData {EventType::WINDOW_MINIMIZE}); break; case SDL_WINDOWEVENT_MAXIMIZED: - event_list.push_back(EventData{EventType::WINDOW_MAXIMIZE}); + event_list.push_back(EventData {EventType::WINDOW_MAXIMIZE}); break; case SDL_WINDOWEVENT_FOCUS_GAINED: - event_list.push_back(EventData{EventType::WINDOW_FOCUS_GAIN}); + event_list.push_back(EventData {EventType::WINDOW_FOCUS_GAIN}); break; case SDL_WINDOWEVENT_FOCUS_LOST: - event_list.push_back(EventData{EventType::WINDOW_FOCUS_LOST}); + event_list.push_back(EventData {EventType::WINDOW_FOCUS_LOST}); break; } } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index e570073..bc118f9 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -116,8 +116,9 @@ public: * This method checks if any window events are triggered and adds them to the event_list. * */ - void handle_window_event(const SDL_WindowEvent & window_event, - std::vector<EventData> & event_list); + void handle_window_event( + const SDL_WindowEvent & window_event, std::vector<EventData> & event_list + ); /** * \brief Converts an SDL scan code to the custom Keycode type. * @@ -254,7 +255,7 @@ private: private: //! instance of the font_facade - FontFacade font_facade{}; + FontFacade font_facade {}; public: /** diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index 745ddae..245419d 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -46,14 +46,16 @@ void ComponentManager::delete_all_components() { this->next_id = 0; } -GameObject ComponentManager::new_object(const string & name, const string & tag, - const vec2 & position, double rotation, double scale) { +GameObject ComponentManager::new_object( + const string & name, const string & tag, const vec2 & position, double rotation, + double scale +) { // Find the first available id (taking persistent objects into account) while (this->persistent[this->next_id]) { this->next_id++; } - GameObject object{this->mediator, this->next_id, name, tag, position, rotation, scale}; + GameObject object {this->mediator, this->next_id, name, tag, position, rotation, scale}; this->next_id++; return object; @@ -64,23 +66,25 @@ void ComponentManager::set_persistent(game_object_id_t id, bool persistent) { } set<game_object_id_t> ComponentManager::get_objects_by_name(const string & name) const { - return this->get_objects_by_predicate<Metadata>( - [name](const Metadata & data) { return data.name == name; }); + return this->get_objects_by_predicate<Metadata>([name](const Metadata & data) { + return data.name == name; + }); } set<game_object_id_t> ComponentManager::get_objects_by_tag(const string & tag) const { - return this->get_objects_by_predicate<Metadata>( - [tag](const Metadata & data) { return data.tag == tag; }); + return this->get_objects_by_predicate<Metadata>([tag](const Metadata & data) { + return data.tag == tag; + }); } ComponentManager::Snapshot ComponentManager::save() { - Snapshot snapshot{}; + Snapshot snapshot {}; for (const auto & [type, by_id_index] : this->components) { for (game_object_id_t id = 0; id < by_id_index.size(); id++) { const auto & components = by_id_index[id]; for (size_t index = 0; index < components.size(); index++) { const Component & component = *components[index]; - snapshot.components.push_back(SnapshotComponent{ + snapshot.components.push_back(SnapshotComponent { .type = type, .id = id, .index = index, diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h index c3a5b4a..2eb1f7e 100644 --- a/src/crepe/manager/ComponentManager.h +++ b/src/crepe/manager/ComponentManager.h @@ -38,9 +38,10 @@ public: * * \note This method automatically assigns a new entity ID */ - GameObject new_object(const std::string & name, const std::string & tag = "", - const vec2 & position = {0, 0}, double rotation = 0, - double scale = 1); + GameObject new_object( + const std::string & name, const std::string & tag = "", const vec2 & position = {0, 0}, + double rotation = 0, double scale = 1 + ); public: /** diff --git a/src/crepe/manager/ComponentManager.hpp b/src/crepe/manager/ComponentManager.hpp index 9e70865..6d32edb 100644 --- a/src/crepe/manager/ComponentManager.hpp +++ b/src/crepe/manager/ComponentManager.hpp @@ -11,8 +11,10 @@ template <class T, typename... Args> T & ComponentManager::add_component(game_object_id_t id, Args &&... args) { using namespace std; - static_assert(is_base_of<Component, T>::value, - "add_component must recieve a derivative class of Component"); + static_assert( + is_base_of<Component, T>::value, + "add_component must recieve a derivative class of Component" + ); // Determine the type of T (this is used as the key of the unordered_map<>) type_index type = typeid(T); @@ -40,8 +42,8 @@ T & ComponentManager::add_component(game_object_id_t id, Args &&... args) { // Check if the vector size is not greater than get_instances_max int max_instances = instance->get_instances_max(); if (max_instances != -1 && components[type][id].size() >= max_instances) { - throw std::runtime_error( - "Exceeded maximum number of instances for this component type"); + throw std::runtime_error("Exceeded maximum number of instances for this component type" + ); } // store its unique_ptr in the vector<> @@ -95,8 +97,10 @@ template <typename T> RefVector<T> ComponentManager::get_components_by_id(game_object_id_t id) const { using namespace std; - static_assert(is_base_of<Component, T>::value, - "get_components_by_id must recieve a derivative class of Component"); + static_assert( + is_base_of<Component, T>::value, + "get_components_by_id must recieve a derivative class of Component" + ); type_index type = typeid(T); if (!this->components.contains(type)) return {}; @@ -170,8 +174,8 @@ ComponentManager::get_objects_by_predicate(const std::function<bool(const T &)> } template <typename T> -RefVector<T> -ComponentManager::get_components_by_ids(const std::set<game_object_id_t> & ids) const { +RefVector<T> ComponentManager::get_components_by_ids(const std::set<game_object_id_t> & ids +) const { using namespace std; RefVector<T> out = {}; diff --git a/src/crepe/manager/EventManager.h b/src/crepe/manager/EventManager.h index 0a57fb1..5766a0c 100644 --- a/src/crepe/manager/EventManager.h +++ b/src/crepe/manager/EventManager.h @@ -49,8 +49,8 @@ public: * \return A unique subscription ID associated with the registered callback. */ template <typename EventType> - subscription_t subscribe(const EventHandler<EventType> & callback, - event_channel_t channel = CHANNEL_ALL); + subscription_t + subscribe(const EventHandler<EventType> & callback, event_channel_t channel = CHANNEL_ALL); /** * \brief Unsubscribe a previously registered callback. diff --git a/src/crepe/manager/EventManager.hpp b/src/crepe/manager/EventManager.hpp index b2090d0..1f44943 100644 --- a/src/crepe/manager/EventManager.hpp +++ b/src/crepe/manager/EventManager.hpp @@ -5,22 +5,24 @@ namespace crepe { template <typename EventType> -subscription_t EventManager::subscribe(const EventHandler<EventType> & callback, - event_channel_t channel) { +subscription_t +EventManager::subscribe(const EventHandler<EventType> & callback, event_channel_t channel) { subscription_counter++; std::type_index event_type = typeid(EventType); std::unique_ptr<EventHandlerWrapper<EventType>> handler = std::make_unique<EventHandlerWrapper<EventType>>(callback); std::vector<CallbackEntry> & handlers = this->subscribers[event_type]; - handlers.emplace_back(CallbackEntry{ - .callback = std::move(handler), .channel = channel, .id = subscription_counter}); + handlers.emplace_back(CallbackEntry { + .callback = std::move(handler), .channel = channel, .id = subscription_counter + }); return subscription_counter; } template <typename EventType> void EventManager::queue_event(const EventType & event, event_channel_t channel) { - static_assert(std::is_base_of<Event, EventType>::value, - "EventType must derive from Event"); + static_assert( + std::is_base_of<Event, EventType>::value, "EventType must derive from Event" + ); this->events_queue.push_back(QueueEntry{ // unique_ptr w/ custom destructor implementation is used because the base Event interface // can't be polymorphic (= have default virtual destructor) diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp index e78f92f..b4cd07f 100644 --- a/src/crepe/manager/LoopTimerManager.cpp +++ b/src/crepe/manager/LoopTimerManager.cpp @@ -17,9 +17,9 @@ LoopTimerManager::LoopTimerManager(Mediator & mediator) : Manager(mediator) { void LoopTimerManager::start() { this->last_frame_time = std::chrono::steady_clock::now(); - this->elapsed_time = elapsed_time_t{0}; - this->elapsed_fixed_time = elapsed_time_t{0}; - this->delta_time = duration_t{0}; + this->elapsed_time = elapsed_time_t {0}; + this->elapsed_fixed_time = elapsed_time_t {0}; + this->delta_time = duration_t {0}; } void LoopTimerManager::update() { diff --git a/src/crepe/manager/LoopTimerManager.h b/src/crepe/manager/LoopTimerManager.h index 2f1e6b6..279d6b2 100644 --- a/src/crepe/manager/LoopTimerManager.h +++ b/src/crepe/manager/LoopTimerManager.h @@ -157,17 +157,17 @@ private: //! Time scale for speeding up or slowing down the game (0 = pause, < 1 = slow down, 1 = normal speed, > 1 = speed up). float time_scale = 1; //! Maximum delta time in seconds to avoid large jumps. - duration_t maximum_delta_time{0.25}; + duration_t maximum_delta_time {0.25}; //! Delta time for the current frame in seconds. - duration_t delta_time{0.0}; + duration_t delta_time {0.0}; //! Target time per frame in seconds - duration_t frame_target_time{1.0 / target_fps}; + duration_t frame_target_time {1.0 / target_fps}; //! Fixed delta time for fixed updates in seconds. - duration_t fixed_delta_time{1.0 / 50.0}; + duration_t fixed_delta_time {1.0 / 50.0}; //! Total elapsed game time in microseconds. - elapsed_time_t elapsed_time{0}; + elapsed_time_t elapsed_time {0}; //! Total elapsed time for fixed updates in microseconds. - elapsed_time_t elapsed_fixed_time{0}; + elapsed_time_t elapsed_fixed_time {0}; typedef std::chrono::steady_clock::time_point time_point_t; //! Time of the last frame. diff --git a/src/crepe/manager/ResourceManager.hpp b/src/crepe/manager/ResourceManager.hpp index cf5c949..4ca6be0 100644 --- a/src/crepe/manager/ResourceManager.hpp +++ b/src/crepe/manager/ResourceManager.hpp @@ -9,17 +9,20 @@ namespace crepe { template <typename T> T & ResourceManager::get(const Asset & asset) { using namespace std; - static_assert(is_base_of<Resource, T>::value, - "cache must recieve a derivative class of Resource"); + static_assert( + is_base_of<Resource, T>::value, "cache must recieve a derivative class of Resource" + ); CacheEntry & entry = this->get_entry(asset); if (entry.resource == nullptr) entry.resource = make_unique<T>(asset, this->mediator); T * concrete_resource = dynamic_cast<T *>(entry.resource.get()); if (concrete_resource == nullptr) - throw runtime_error(format("ResourceManager: mismatch between requested type and " - "actual type of resource ({})", - asset.get_path())); + throw runtime_error(format( + "ResourceManager: mismatch between requested type and " + "actual type of resource ({})", + asset.get_path() + )); return *concrete_resource; } diff --git a/src/crepe/manager/SceneManager.cpp b/src/crepe/manager/SceneManager.cpp index d4ca90b..e6f92db 100644 --- a/src/crepe/manager/SceneManager.cpp +++ b/src/crepe/manager/SceneManager.cpp @@ -17,10 +17,12 @@ void SceneManager::load_next_scene() { // next scene not set if (this->next_scene.empty()) return; - auto it = find_if(this->scenes.begin(), this->scenes.end(), - [&next_scene = this->next_scene](unique_ptr<Scene> & scene) { - return scene.get()->get_name() == next_scene; - }); + auto it = find_if( + this->scenes.begin(), this->scenes.end(), + [&next_scene = this->next_scene](unique_ptr<Scene> & scene) { + return scene.get()->get_name() == next_scene; + } + ); // next scene not found if (it == this->scenes.end()) return; diff --git a/src/crepe/manager/SystemManager.hpp b/src/crepe/manager/SystemManager.hpp index 8d06eb1..addd274 100644 --- a/src/crepe/manager/SystemManager.hpp +++ b/src/crepe/manager/SystemManager.hpp @@ -11,8 +11,9 @@ namespace crepe { template <class T> T & SystemManager::get_system() { using namespace std; - static_assert(is_base_of<System, T>::value, - "get_system must recieve a derivative class of System"); + static_assert( + is_base_of<System, T>::value, "get_system must recieve a derivative class of System" + ); const type_info & type = typeid(T); if (!this->systems.contains(type)) @@ -28,8 +29,9 @@ T & SystemManager::get_system() { template <class T> void SystemManager::load_system() { using namespace std; - static_assert(is_base_of<System, T>::value, - "load_system must recieve a derivative class of System"); + static_assert( + is_base_of<System, T>::value, "load_system must recieve a derivative class of System" + ); const type_info & type = typeid(T); if (this->systems.contains(type)) diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp index 0f35010..94445c7 100644 --- a/src/crepe/system/AISystem.cpp +++ b/src/crepe/system/AISystem.cpp @@ -28,7 +28,8 @@ void AISystem::fixed_update() { = mgr.get_components_by_id<Rigidbody>(ai.game_object_id); if (rigidbodies.empty()) { throw std::runtime_error( - "AI component must be attached to a GameObject with a Rigidbody component"); + "AI component must be attached to a GameObject with a Rigidbody component" + ); } Rigidbody & rigidbody = rigidbodies.front().get(); if (!rigidbody.active) { @@ -110,8 +111,8 @@ bool AISystem::accumulate_force(const AI & ai, vec2 & running_total, vec2 & forc return true; } -vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity vec2 desired_velocity = ai.seek_target - transform.position; desired_velocity.normalize(); @@ -120,12 +121,12 @@ vec2 AISystem::seek(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } -vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity if the entity is within the panic distance vec2 desired_velocity = transform.position - ai.flee_target; if (desired_velocity.length_squared() > ai.square_flee_panic_distance) { - return vec2{0, 0}; + return vec2 {0, 0}; } desired_velocity.normalize(); desired_velocity *= rigidbody.data.max_linear_velocity; @@ -133,8 +134,8 @@ vec2 AISystem::flee(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } -vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, - const Transform & transform) const { +vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, const Transform & transform) + const { // Calculate the desired velocity (taking into account the deceleration rate) vec2 to_target = ai.arrive_target - transform.position; float distance = to_target.length(); @@ -150,12 +151,12 @@ vec2 AISystem::arrive(const AI & ai, const Rigidbody & rigidbody, return desired_velocity - rigidbody.data.linear_velocity; } - return vec2{0, 0}; + return vec2 {0, 0}; } vec2 AISystem::path_follow(AI & ai, const Rigidbody & rigidbody, const Transform & transform) { if (ai.path.empty()) { - return vec2{0, 0}; + return vec2 {0, 0}; } // Get the target node diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 654d4c6..571ac70 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -50,9 +50,11 @@ void CollisionSystem::fixed_update() { for (BoxCollider & boxcollider : boxcolliders) { if (boxcollider.game_object_id != id) continue; if (!boxcollider.active) continue; - all_colliders.push_back({.id = id, - .collider = collider_variant{boxcollider}, - .info = {transform, rigidbody, metadata}}); + all_colliders.push_back( + {.id = id, + .collider = collider_variant {boxcollider}, + .info = {transform, rigidbody, metadata}} + ); } // Check if the circlecollider is active and has the same id as the rigidbody. RefVector<CircleCollider> circlecolliders @@ -60,9 +62,11 @@ void CollisionSystem::fixed_update() { for (CircleCollider & circlecollider : circlecolliders) { if (circlecollider.game_object_id != id) continue; if (!circlecollider.active) continue; - all_colliders.push_back({.id = id, - .collider = collider_variant{circlecollider}, - .info = {transform, rigidbody, metadata}}); + all_colliders.push_back( + {.id = id, + .collider = collider_variant {circlecollider}, + .info = {transform, rigidbody, metadata}} + ); } } @@ -110,8 +114,9 @@ CollisionSystem::gather_collisions(std::vector<CollisionInternal> & colliders) { return collisions_ret; } -bool CollisionSystem::should_collide(const CollisionInternal & self, - const CollisionInternal & other) const { +bool CollisionSystem::should_collide( + const CollisionInternal & self, const CollisionInternal & other +) const { const Rigidbody::Data & self_rigidbody = self.info.rigidbody.data; const Rigidbody::Data & other_rigidbody = other.info.rigidbody.data; @@ -133,9 +138,9 @@ bool CollisionSystem::should_collide(const CollisionInternal & self, return false; } -CollisionSystem::CollisionInternalType -CollisionSystem::get_collider_type(const collider_variant & collider1, - const collider_variant & collider2) const { +CollisionSystem::CollisionInternalType CollisionSystem::get_collider_type( + const collider_variant & collider1, const collider_variant & collider2 +) const { if (std::holds_alternative<std::reference_wrapper<CircleCollider>>(collider1)) { if (std::holds_alternative<std::reference_wrapper<CircleCollider>>(collider2)) { return CollisionInternalType::CIRCLE_CIRCLE; @@ -151,8 +156,9 @@ CollisionSystem::get_collider_type(const collider_variant & collider1, } } -bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionInternal & other, - const CollisionInternalType & type) { +bool CollisionSystem::detect_collision( + CollisionInternal & self, CollisionInternal & other, const CollisionInternalType & type +) { vec2 resolution; switch (type) { case CollisionInternalType::BOX_BOX: { @@ -177,10 +183,11 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern = {.collider = std::get<std::reference_wrapper<BoxCollider>>(self.collider), .transform = self.info.transform, .rigidbody = self.info.rigidbody}; - const CircleColliderInternal CIRCLE2 = { - .collider = std::get<std::reference_wrapper<CircleCollider>>(other.collider), - .transform = other.info.transform, - .rigidbody = other.info.rigidbody}; + const CircleColliderInternal CIRCLE2 + = {.collider + = std::get<std::reference_wrapper<CircleCollider>>(other.collider), + .transform = other.info.transform, + .rigidbody = other.info.rigidbody}; // Get resolution vector from box-circle collision detection resolution = this->get_box_circle_detection(BOX1, CIRCLE2); // If no collision (NaN values), return false @@ -195,10 +202,11 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern = {.collider = std::get<std::reference_wrapper<CircleCollider>>(self.collider), .transform = self.info.transform, .rigidbody = self.info.rigidbody}; - const CircleColliderInternal CIRCLE2 = { - .collider = std::get<std::reference_wrapper<CircleCollider>>(other.collider), - .transform = other.info.transform, - .rigidbody = other.info.rigidbody}; + const CircleColliderInternal CIRCLE2 + = {.collider + = std::get<std::reference_wrapper<CircleCollider>>(other.collider), + .transform = other.info.transform, + .rigidbody = other.info.rigidbody}; // Get resolution vector from circle-circle collision detection resolution = this->get_circle_circle_detection(CIRCLE1, CIRCLE2); // If no collision (NaN values), return false @@ -239,9 +247,10 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern return true; } -vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, - const BoxColliderInternal & box2) const { - vec2 resolution{NAN, NAN}; +vec2 CollisionSystem::get_box_box_detection( + const BoxColliderInternal & box1, const BoxColliderInternal & box2 +) const { + vec2 resolution {NAN, NAN}; // Get current positions of colliders vec2 pos1 = AbsolutePosition::get_position(box1.transform, box1.collider.offset); vec2 pos2 = AbsolutePosition::get_position(box2.transform, box2.collider.offset); @@ -282,8 +291,9 @@ vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, return resolution; } -vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box, - const CircleColliderInternal & circle) const { +vec2 CollisionSystem::get_box_circle_detection( + const BoxColliderInternal & box, const CircleColliderInternal & circle +) const { /// Get current positions of colliders vec2 box_pos = AbsolutePosition::get_position(box.transform, box.collider.offset); vec2 circle_pos = AbsolutePosition::get_position(circle.transform, circle.collider.offset); @@ -324,14 +334,15 @@ vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box, float penetration_depth = scaled_circle_radius - distance; // Compute the resolution vector - return vec2{collision_normal * penetration_depth}; + return vec2 {collision_normal * penetration_depth}; } // No collision - return vec2{NAN, NAN}; + return vec2 {NAN, NAN}; } vec2 CollisionSystem::get_circle_circle_detection( - const CircleColliderInternal & circle1, const CircleColliderInternal & circle2) const { + const CircleColliderInternal & circle1, const CircleColliderInternal & circle2 +) const { // Get current positions of colliders vec2 final_position1 = AbsolutePosition::get_position(circle1.transform, circle1.collider.offset); @@ -371,7 +382,7 @@ vec2 CollisionSystem::get_circle_circle_detection( return resolution; } // No collision - return vec2{NAN, NAN}; + return vec2 {NAN, NAN}; ; } @@ -402,17 +413,17 @@ CollisionSystem::resolution_correction(vec2 & resolution, const Rigidbody::Data return resolution_direction; } -CollisionSystem::CollisionInfo -CollisionSystem::get_collision_info(const CollisionInternal & in_self, - const CollisionInternal & in_other) const { +CollisionSystem::CollisionInfo CollisionSystem::get_collision_info( + const CollisionInternal & in_self, const CollisionInternal & in_other +) const { - crepe::CollisionSystem::ColliderInfo self{ + crepe::CollisionSystem::ColliderInfo self { .transform = in_self.info.transform, .rigidbody = in_self.info.rigidbody, .metadata = in_self.info.metadata, }; - crepe::CollisionSystem::ColliderInfo other{ + crepe::CollisionSystem::ColliderInfo other { .transform = in_other.info.transform, .rigidbody = in_other.info.rigidbody, .metadata = in_other.info.metadata, diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 3fb9723..ff2d35f 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -60,8 +60,8 @@ public: private: //! A variant type that can hold either a BoxCollider or a CircleCollider. - using collider_variant = std::variant<std::reference_wrapper<BoxCollider>, - std::reference_wrapper<CircleCollider>>; + using collider_variant = std::variant< + std::reference_wrapper<BoxCollider>, std::reference_wrapper<CircleCollider>>; //! Enum representing the types of collider pairs for collision detection. enum class CollisionInternalType { @@ -114,8 +114,9 @@ private: * \param collider2 Second collider variant (BoxCollider or CircleCollider). * \return The combined type of the two colliders. */ - CollisionInternalType get_collider_type(const collider_variant & collider1, - const collider_variant & collider2) const; + CollisionInternalType get_collider_type( + const collider_variant & collider1, const collider_variant & collider2 + ) const; private: /** @@ -128,8 +129,8 @@ private: * \param data1 Collision data for the first collider. * \param data2 Collision data for the second collider. */ - CollisionInfo get_collision_info(const CollisionInternal & data1, - const CollisionInternal & data2) const; + CollisionInfo + get_collision_info(const CollisionInternal & data1, const CollisionInternal & data2) const; /** * \brief Corrects the collision resolution vector and determines its direction. @@ -221,8 +222,10 @@ private: * \param other_metadata Rigidbody of second object * \return Returns true if there is at least one comparison found. */ - bool should_collide(const CollisionInternal & self, - const CollisionInternal & other) const; //done + bool should_collide( + const CollisionInternal & self, + const CollisionInternal & other + ) const; //done /** * \brief Checks for collision between two colliders. @@ -236,8 +239,10 @@ private: * \param type The type of collider pair. * \return True if a collision is detected, otherwise false. */ - bool detect_collision(CollisionInternal & first_info, CollisionInternal & second_info, - const CollisionInternalType & type); + bool detect_collision( + CollisionInternal & first_info, CollisionInternal & second_info, + const CollisionInternalType & type + ); /** * \brief Detects collisions between two BoxColliders. @@ -250,8 +255,9 @@ private: * \param box2 Information about the second BoxCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_box_box_detection(const BoxColliderInternal & box1, - const BoxColliderInternal & box2) const; + vec2 get_box_box_detection( + const BoxColliderInternal & box1, const BoxColliderInternal & box2 + ) const; /** * \brief Check collision for box on circle collider @@ -264,8 +270,9 @@ private: * \param circle2 Information about the circleCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_box_circle_detection(const BoxColliderInternal & box1, - const CircleColliderInternal & circle2) const; + vec2 get_box_circle_detection( + const BoxColliderInternal & box1, const CircleColliderInternal & circle2 + ) const; /** * \brief Check collision for circle on circle collider @@ -278,8 +285,9 @@ private: * \param circle2 Information about the second circleCollider. * \return If colliding, returns the resolution vector; otherwise, returns {NaN, NaN}. */ - vec2 get_circle_circle_detection(const CircleColliderInternal & circle1, - const CircleColliderInternal & circle2) const; + vec2 get_circle_circle_detection( + const CircleColliderInternal & circle1, const CircleColliderInternal & circle2 + ) const; }; /** diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 8e9f763..b4a0633 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -44,8 +44,9 @@ void InputSystem::fixed_update() { } } -void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camera_origin, - const Camera & current_cam) { +void InputSystem::handle_mouse_event( + const EventData & event, const vec2 & camera_origin, const Camera & current_cam +) { EventManager & event_mgr = this->mediator.event_manager; vec2 adjusted_mouse; adjusted_mouse.x = event.data.mouse_data.mouse_position.x + camera_origin.x; @@ -82,8 +83,9 @@ void InputSystem::handle_mouse_event(const EventData & event, const vec2 & camer .mouse_pos = adjusted_mouse, .button = event.data.mouse_data.mouse_button, }); - this->handle_click(event.data.mouse_data.mouse_button, adjusted_mouse, - current_cam); + this->handle_click( + event.data.mouse_data.mouse_button, adjusted_mouse, current_cam + ); } break; } @@ -115,7 +117,8 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { case EventType::KEY_DOWN: event_mgr.queue_event<KeyPressEvent>( - {.repeat = event.data.key_data.key_repeat, .key = event.data.key_data.key}); + {.repeat = event.data.key_data.key_repeat, .key = event.data.key_data.key} + ); break; case EventType::KEY_UP: event_mgr.queue_event<KeyReleaseEvent>({.key = event.data.key_data.key}); @@ -128,11 +131,13 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { break; case EventType::WINDOW_RESIZE: event_mgr.queue_event<WindowResizeEvent>( - WindowResizeEvent{.dimensions = event.data.window_data.resize_dimension}); + WindowResizeEvent {.dimensions = event.data.window_data.resize_dimension} + ); break; case EventType::WINDOW_MOVE: event_mgr.queue_event<WindowMoveEvent>( - {.delta_move = event.data.window_data.move_delta}); + {.delta_move = event.data.window_data.move_delta} + ); break; case EventType::WINDOW_MINIMIZE: event_mgr.queue_event<WindowMinimizeEvent>({}); @@ -151,8 +156,9 @@ void InputSystem::handle_non_mouse_event(const EventData & event) { } } -void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_pos, - const Camera & current_cam) { +void InputSystem::handle_move( + const EventData & event_data, const vec2 & mouse_pos, const Camera & current_cam +) { ComponentManager & mgr = this->mediator.component_manager; EventManager & event_mgr = this->mediator.event_manager; const RefVector<Button> buttons = mgr.get_components_by_type<Button>(); @@ -182,8 +188,9 @@ void InputSystem::handle_move(const EventData & event_data, const vec2 & mouse_p } } -void InputSystem::handle_click(const MouseButton & mouse_button, const vec2 & mouse_pos, - const Camera & current_cam) { +void InputSystem::handle_click( + const MouseButton & mouse_button, const vec2 & mouse_pos, const Camera & current_cam +) { ComponentManager & mgr = this->mediator.component_manager; EventManager & event_mgr = this->mediator.event_manager; const RefVector<Button> buttons = mgr.get_components_by_type<Button>(); @@ -201,9 +208,10 @@ void InputSystem::handle_click(const MouseButton & mouse_button, const vec2 & mo } } -bool InputSystem::is_mouse_inside_button(const vec2 & mouse_pos, const Button & button, - const Transform & transform, - const Transform & cam_transform) { +bool InputSystem::is_mouse_inside_button( + const vec2 & mouse_pos, const Button & button, const Transform & transform, + const Transform & cam_transform +) { vec2 actual_pos = transform.position + button.offset; if (!button.world_space) { actual_pos += cam_transform.position; diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 45b238b..37311cc 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -79,8 +79,9 @@ private: * This method processes mouse events, adjusts the mouse position to world coordinates, * and triggers the appropriate mouse-specific event handling logic. */ - void handle_mouse_event(const EventData & event, const vec2 & camera_origin, - const Camera & current_cam); + void handle_mouse_event( + const EventData & event, const vec2 & camera_origin, const Camera & current_cam + ); /** * \brief Handles non-mouse-related events. * \param event The event data for the non-mouse event. @@ -98,8 +99,9 @@ private: * * This method processes the mouse click event and triggers the corresponding button action. */ - void handle_click(const MouseButton & mouse_button, const vec2 & mouse_pos, - const Camera & current_cam); + void handle_click( + const MouseButton & mouse_button, const vec2 & mouse_pos, const Camera & current_cam + ); /** * \brief Handles the mouse movement event. @@ -110,8 +112,9 @@ private: * * This method processes the mouse movement event and updates the button hover state. */ - void handle_move(const EventData & event_data, const vec2 & mouse_pos, - const Camera & current_cam); + void handle_move( + const EventData & event_data, const vec2 & mouse_pos, const Camera & current_cam + ); /** * \brief Checks if the mouse position is inside the bounds of the button. @@ -122,8 +125,10 @@ private: * \param cam_transform the transform of the current active camera * \return True if the mouse is inside the button, false otherwise. */ - bool is_mouse_inside_button(const vec2 & mouse_pos, const Button & button, - const Transform & transform, const Transform & cam_transform); + bool is_mouse_inside_button( + const vec2 & mouse_pos, const Button & button, const Transform & transform, + const Transform & cam_transform + ); /** * \brief Handles the button press event, calling the on_click callback if necessary. diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index 5e575e4..f026390 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -50,9 +50,10 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & constexpr float DEG_TO_RAD = M_PI / 180.0; vec2 initial_position = AbsolutePosition::get_position(transform, emitter.data.offset); - float random_angle - = this->generate_random_angle(emitter.data.min_angle + transform.rotation, - emitter.data.max_angle + transform.rotation); + float random_angle = this->generate_random_angle( + emitter.data.min_angle + transform.rotation, + emitter.data.max_angle + transform.rotation + ); float random_speed = this->generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); @@ -63,8 +64,9 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & for (Particle & particle : emitter.particles) { if (!particle.active) { - particle.reset(emitter.data.end_lifespan, initial_position, velocity, - random_angle); + particle.reset( + emitter.data.end_lifespan, initial_position, velocity, random_angle + ); break; } } @@ -82,8 +84,9 @@ void ParticleSystem::check_bounds(ParticleEmitter & emitter, const Transform & t for (Particle & particle : emitter.particles) { const vec2 & position = particle.position; - bool within_bounds = (position.x >= left && position.x <= right && position.y >= top - && position.y <= bottom); + bool within_bounds + = (position.x >= left && position.x <= right && position.y >= top + && position.y <= bottom); //if not within bounds do a reset or stop velocity if (!within_bounds) { if (emitter.data.boundary.reset_on_exit) { diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 698301e..30bb422 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -92,7 +92,7 @@ void RenderSystem::render_text() { const Font & font = resource_manager.get<Font>(text.font.value()); const auto & transform = mgr.get_components_by_id<Transform>(text.game_object_id).front().get(); - ctx.draw_text(SDLContext::RenderText{ + ctx.draw_text(SDLContext::RenderText { .text = text, .font = font, .transform = transform, @@ -120,7 +120,7 @@ bool RenderSystem::render_particle(const Sprite & sprite, const Transform & tran if (!p.active) continue; if (p.time_in_life < em.data.begin_lifespan) continue; - ctx.draw(SDLContext::RenderContext{ + ctx.draw(SDLContext::RenderContext { .sprite = sprite, .texture = res, .pos = p.position, @@ -136,7 +136,7 @@ void RenderSystem::render_normal(const Sprite & sprite, const Transform & transf ResourceManager & resource_manager = this->mediator.resource_manager; const Texture & res = resource_manager.get<Texture>(sprite.source); vec2 pos = AbsolutePosition::get_position(transform, sprite.data.position_offset); - ctx.draw(SDLContext::RenderContext{ + ctx.draw(SDLContext::RenderContext { .sprite = sprite, .texture = res, .pos = pos, diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index 93b4853..ed0c7cc 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -19,8 +19,9 @@ void ScriptSystem::frame_update() { this->update(&Script::frame_update, delta_time); } -void ScriptSystem::update(void (Script::*update_function)(duration_t), - const duration_t & delta_time) { +void ScriptSystem::update( + void (Script::*update_function)(duration_t), const duration_t & delta_time +) { ComponentManager & mgr = this->mediator.component_manager; RefVector<BehaviorScript> behavior_scripts = mgr.get_components_by_type<BehaviorScript>(); diff --git a/src/crepe/util/dbg.h b/src/crepe/util/dbg.h index c7283ee..e448070 100644 --- a/src/crepe/util/dbg.h +++ b/src/crepe/util/dbg.h @@ -5,10 +5,13 @@ // utility macros #define _crepe_logf_here(level, fmt, ...) \ - crepe::Log::logf(level, "{}" fmt, \ - crepe::LogColor().fg_white(false).str(std::format( \ - "{} ({}:{})", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__)), \ - __VA_ARGS__) + crepe::Log::logf( \ + level, "{}" fmt, \ + crepe::LogColor().fg_white(false).str( \ + std::format("{} ({}:{})", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__) \ + ), \ + __VA_ARGS__ \ + ) // very illegal global function-style macros // NOLINTBEGIN diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp index 93ba500..4c4e25e 100644 --- a/src/example/AITest.cpp +++ b/src/example/AITest.cpp @@ -30,10 +30,12 @@ class Script1 : public Script { } void init() { - subscribe<ShutDownEvent>( - [this](const ShutDownEvent & ev) -> bool { return this->shutdown(ev); }); - subscribe<MouseMoveEvent>( - [this](const MouseMoveEvent & ev) -> bool { return this->mousemove(ev); }); + subscribe<ShutDownEvent>([this](const ShutDownEvent & ev) -> bool { + return this->shutdown(ev); + }); + subscribe<MouseMoveEvent>([this](const MouseMoveEvent & ev) -> bool { + return this->mousemove(ev); + }); } }; @@ -43,21 +45,23 @@ public: Mediator & mediator = this->mediator; ComponentManager & mgr = mediator.component_manager; - GameObject game_object1 = mgr.new_object("", "", vec2{0, 0}, 0, 1); - GameObject game_object2 = mgr.new_object("", "", vec2{0, 0}, 0, 1); + GameObject game_object1 = mgr.new_object("", "", vec2 {0, 0}, 0, 1); + GameObject game_object2 = mgr.new_object("", "", vec2 {0, 0}, 0, 1); - Asset img{"asset/texture/test_ap43.png"}; + Asset img {"asset/texture/test_ap43.png"}; Sprite & test_sprite = game_object1.add_component<Sprite>( - img, Sprite::Data{ - .color = Color::MAGENTA, - .flip = Sprite::FlipSettings{false, false}, - .sorting_in_layer = 2, - .order_in_layer = 2, - .size = {0, 100}, - .angle_offset = 0, - .position_offset = {0, 0}, - }); + img, + Sprite::Data { + .color = Color::MAGENTA, + .flip = Sprite::FlipSettings {false, false}, + .sorting_in_layer = 2, + .order_in_layer = 2, + .size = {0, 100}, + .angle_offset = 0, + .position_offset = {0, 0}, + } + ); AI & ai = game_object1.add_component<AI>(3000); // ai.arrive_on(); @@ -65,17 +69,19 @@ public: ai.path_follow_on(); ai.make_oval_path(500, 1000, {0, -1000}, 1.5708, true); ai.make_oval_path(1000, 500, {0, 500}, 4.7124, false); - game_object1.add_component<Rigidbody>(Rigidbody::Data{ + game_object1.add_component<Rigidbody>(Rigidbody::Data { .mass = 0.1f, .max_linear_velocity = 40, }); game_object1.add_component<BehaviorScript>().set_script<Script1>(); - game_object2.add_component<Camera>(ivec2{1080, 720}, vec2{5000, 5000}, - Camera::Data{ - .bg_color = Color::WHITE, - .zoom = 1, - }); + game_object2.add_component<Camera>( + ivec2 {1080, 720}, vec2 {5000, 5000}, + Camera::Data { + .bg_color = Color::WHITE, + .zoom = 1, + } + ); } string get_name() const override { return "Scene1"; } diff --git a/src/example/button.cpp b/src/example/button.cpp index 4220588..ea7f528 100644 --- a/src/example/button.cpp +++ b/src/example/button.cpp @@ -21,14 +21,16 @@ using namespace std; int main(int argc, char * argv[]) { Mediator mediator; - ComponentManager mgr{mediator}; - RenderSystem sys{mediator}; - EventManager event_mgr{mediator}; - InputSystem input_sys{mediator}; - SDLContext sdl_context{mediator}; - GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1); + ComponentManager mgr {mediator}; + RenderSystem sys {mediator}; + EventManager event_mgr {mediator}; + InputSystem input_sys {mediator}; + SDLContext sdl_context {mediator}; + GameObject obj = mgr.new_object("camera", "camera", vec2 {0, 0}, 0, 1); auto & camera = obj.add_component<Camera>( - ivec2{500, 500}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + ivec2 {500, 500}, vec2 {500, 500}, + Camera::Data {.bg_color = Color::WHITE, .zoom = 1.0f} + ); auto start = std::chrono::steady_clock::now(); while (true) { const keyboard_state_t & keyboard_state = sdl_context.get_keyboard_state(); diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp index e459332..dd7caff 100644 --- a/src/example/loadfont.cpp +++ b/src/example/loadfont.cpp @@ -15,19 +15,21 @@ int main() { // SDLFontContext font_facade; Mediator mediator; - FontFacade font_facade{}; - SDLContext sdl_context{mediator}; + FontFacade font_facade {}; + SDLContext sdl_context {mediator}; // ComponentManager component_manager{mediator}; - ResourceManager resource_manager{mediator}; + ResourceManager resource_manager {mediator}; try { // Correct way to create a unique pointer for Text std::unique_ptr<Text> label = std::make_unique<Text>( - 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{}, "test text"); + 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data {}, "test text" + ); // std::cout << "Path: " << label->font.get_path() << std::endl; Asset asset1 = font_facade.get_font_asset("OpenSymbol"); std::cout << asset1.get_path() << std::endl; std::unique_ptr<Text> label2 = std::make_unique<Text>( - 1, vec2(100, 100), vec2(0, 0), "fsaafdafsdafsdafsdasfdds", Text::Data{}); + 1, vec2(100, 100), vec2(0, 0), "fsaafdafsdafsdafsdasfdds", Text::Data {} + ); Asset asset = Asset("test test"); label->font.emplace(asset); std::cout << label->font.value().get_path() << std::endl; diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 5440fdd..7942fce 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -23,38 +23,44 @@ using namespace std; class TestScene : public Scene { public: void load_scene() { - GameObject game_object = new_object("", "", vec2{0, 0}, 0, 1); + GameObject game_object = new_object("", "", vec2 {0, 0}, 0, 1); Color color(255, 255, 255, 255); - Asset img{"asset/texture/square.png"}; + Asset img {"asset/texture/square.png"}; Sprite & test_sprite = game_object.add_component<Sprite>( - img, Sprite::Data{ - .color = color, - .flip = Sprite::FlipSettings{false, false}, - .sorting_in_layer = 2, - .order_in_layer = 2, - .size = {1, 1}, - .angle_offset = 0, - .position_offset = {0, 1}, - .world_space = false, - }); + img, + Sprite::Data { + .color = color, + .flip = Sprite::FlipSettings {false, false}, + .sorting_in_layer = 2, + .order_in_layer = 2, + .size = {1, 1}, + .angle_offset = 0, + .position_offset = {0, 1}, + .world_space = false, + } + ); //auto & emitter = game_object.add_component<ParticleEmitter>(test_sprite, ParticleEmitter::Data{}); - Sprite & test_sprite1 - = game_object.add_component<Sprite>(img, Sprite::Data{ - .color = color, - .size = {1, 1}, - .position_offset = {0, -1}, - .world_space = false, - }); + Sprite & test_sprite1 = game_object.add_component<Sprite>( + img, + Sprite::Data { + .color = color, + .size = {1, 1}, + .position_offset = {0, -1}, + .world_space = false, + } + ); - auto & cam = game_object.add_component<Camera>(ivec2{1280, 720}, vec2{5, 5}, - Camera::Data{ - .bg_color = Color::WHITE, - .postion_offset = {1000, 1000}, - }); + auto & cam = game_object.add_component<Camera>( + ivec2 {1280, 720}, vec2 {5, 5}, + Camera::Data { + .bg_color = Color::WHITE, + .postion_offset = {1000, 1000}, + } + ); /* game_object.add_component<Text>(vec2{1, 1}, vec2{0, -0.5}, "ComicSansMS", diff --git a/src/example/replay.cpp b/src/example/replay.cpp index 82fd478..00a6502 100644 --- a/src/example/replay.cpp +++ b/src/example/replay.cpp @@ -55,15 +55,20 @@ public: ComponentManager & mgr = mediator.component_manager; GameObject cam = mgr.new_object("cam"); - cam.add_component<Camera>(ivec2{640, 480}, vec2{3, 3}, - Camera::Data{ - .bg_color = Color::WHITE, - }); + cam.add_component<Camera>( + ivec2 {640, 480}, vec2 {3, 3}, + Camera::Data { + .bg_color = Color::WHITE, + } + ); GameObject square = mgr.new_object("square"); - square.add_component<Sprite>(Asset{"asset/texture/square.png"}, Sprite::Data{ - .size = {0.5, 0.5}, - }); + square.add_component<Sprite>( + Asset {"asset/texture/square.png"}, + Sprite::Data { + .size = {0.5, 0.5}, + } + ); square.add_component<BehaviorScript>().set_script<AnimationScript>(); GameObject scapegoat = mgr.new_object(""); diff --git a/src/test/AssetTest.cpp b/src/test/AssetTest.cpp index 93fd6a9..f41e9de 100644 --- a/src/test/AssetTest.cpp +++ b/src/test/AssetTest.cpp @@ -7,15 +7,15 @@ using namespace std; using namespace crepe; using namespace testing; -TEST(AssetTest, Existant) { ASSERT_NO_THROW(Asset{"asset/texture/img.png"}); } +TEST(AssetTest, Existant) { ASSERT_NO_THROW(Asset {"asset/texture/img.png"}); } -TEST(AssetTest, Nonexistant) { ASSERT_ANY_THROW(Asset{"asset/nonexistant"}); } +TEST(AssetTest, Nonexistant) { ASSERT_ANY_THROW(Asset {"asset/nonexistant"}); } TEST(AssetTest, Rootless) { Config & cfg = Config::get_instance(); cfg.asset.root_pattern.clear(); string arbitrary = "\\/this is / /../passed through as-is"; - Asset asset{arbitrary}; + Asset asset {arbitrary}; ASSERT_EQ(arbitrary, asset.get_path()); } diff --git a/src/test/AudioTest.cpp b/src/test/AudioTest.cpp index 415a12e..3844c73 100644 --- a/src/test/AudioTest.cpp +++ b/src/test/AudioTest.cpp @@ -31,11 +31,11 @@ private: private: Mediator mediator; - ComponentManager component_manager{mediator}; - ResourceManager resource_manager{mediator}; + ComponentManager component_manager {mediator}; + ResourceManager resource_manager {mediator}; public: - TestAudioSystem system{mediator}; + TestAudioSystem system {mediator}; TestSoundContext & context = system.context; private: diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index c8d804c..c571c1a 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -39,8 +39,9 @@ public: } void init() { - subscribe<CollisionEvent>( - [this](const CollisionEvent & ev) -> bool { return this->on_collision(ev); }); + subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { + return this->on_collision(ev); + }); } void update() { // Retrieve component from the same GameObject this script is on @@ -50,11 +51,11 @@ public: class CollisionTest : public Test { public: Mediator m; - EventManager event_mgr{m}; - ComponentManager mgr{m}; - CollisionSystem collision_sys{m}; - ScriptSystem script_sys{m}; - LoopTimerManager loop_timer{m}; + EventManager event_mgr {m}; + ComponentManager mgr {m}; + CollisionSystem collision_sys {m}; + ScriptSystem script_sys {m}; + LoopTimerManager loop_timer {m}; GameObject world = mgr.new_object("world", "", {50, 50}); GameObject game_object1 = mgr.new_object("object1", "", {50, 50}); @@ -64,17 +65,17 @@ public: CollisionHandler * script_object2_ref = nullptr; void SetUp() override { - world.add_component<Rigidbody>(Rigidbody::Data{ + world.add_component<Rigidbody>(Rigidbody::Data { // TODO: remove unrelated properties: .body_type = Rigidbody::BodyType::STATIC, }); // Create a box with an inner size of 10x10 units - world.add_component<BoxCollider>(vec2{100, 100}, vec2{0, -100}); // Top - world.add_component<BoxCollider>(vec2{100, 100}, vec2{0, 100}); // Bottom - world.add_component<BoxCollider>(vec2{100, 100}, vec2{-100, 0}); // Left - world.add_component<BoxCollider>(vec2{100, 100}, vec2{100, 0}); // right + world.add_component<BoxCollider>(vec2 {100, 100}, vec2 {0, -100}); // Top + world.add_component<BoxCollider>(vec2 {100, 100}, vec2 {0, 100}); // Bottom + world.add_component<BoxCollider>(vec2 {100, 100}, vec2 {-100, 0}); // Left + world.add_component<BoxCollider>(vec2 {100, 100}, vec2 {100, 0}); // right - game_object1.add_component<Rigidbody>(Rigidbody::Data{ + game_object1.add_component<Rigidbody>(Rigidbody::Data { .mass = 1, .gravity_scale = 0.01, .body_type = Rigidbody::BodyType::DYNAMIC, @@ -83,13 +84,13 @@ public: .elasticity_coefficient = 1, .collision_layers = {0}, }); - game_object1.add_component<BoxCollider>(vec2{10, 10}, vec2{0, 0}); + game_object1.add_component<BoxCollider>(vec2 {10, 10}, vec2 {0, 0}); BehaviorScript & script_object1 = game_object1.add_component<BehaviorScript>().set_script<CollisionHandler>(1); script_object1_ref = static_cast<CollisionHandler *>(script_object1.script.get()); ASSERT_NE(script_object1_ref, nullptr); - game_object2.add_component<Rigidbody>(Rigidbody::Data{ + game_object2.add_component<Rigidbody>(Rigidbody::Data { .mass = 1, .gravity_scale = 0.01, .body_type = Rigidbody::BodyType::DYNAMIC, @@ -98,7 +99,7 @@ public: .elasticity_coefficient = 1, .collision_layers = {0}, }); - game_object2.add_component<BoxCollider>(vec2{10, 10}, vec2{0, 0}); + game_object2.add_component<BoxCollider>(vec2 {10, 10}, vec2 {0, 0}); BehaviorScript & script_object2 = game_object2.add_component<BehaviorScript>().set_script<CollisionHandler>(2); script_object2_ref = static_cast<CollisionHandler *>(script_object2.script.get()); @@ -154,16 +155,18 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) { EXPECT_EQ(ev.info.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 0); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::X_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION + ); }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; EXPECT_EQ(ev.info.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, 0); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::X_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION + ); }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); @@ -179,16 +182,18 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) { EXPECT_EQ(ev.info.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 0); EXPECT_EQ(ev.info.resolution.y, -5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::Y_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION + ); }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; EXPECT_EQ(ev.info.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, 0); EXPECT_EQ(ev.info.resolution.y, 5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::Y_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION + ); }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); @@ -231,16 +236,18 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) { EXPECT_EQ(ev.info.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::X_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION + ); }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; EXPECT_EQ(ev.info.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::X_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION + ); }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); @@ -260,16 +267,18 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) { EXPECT_EQ(ev.info.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::Y_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION + ); }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; EXPECT_EQ(ev.info.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::Y_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION + ); }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); @@ -309,8 +318,9 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) { EXPECT_EQ(ev.info.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::X_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION + ); }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { // is static should not be called @@ -334,8 +344,9 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) { EXPECT_EQ(ev.info.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); - EXPECT_EQ(ev.info.resolution_direction, - crepe::CollisionSystem::Direction::Y_DIRECTION); + EXPECT_EQ( + ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION + ); }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { // is static should not be called diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index 8f86a91..92436a9 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -16,7 +16,7 @@ class ECSTest : public ::testing::Test { Mediator m; public: - ComponentManager mgr{m}; + ComponentManager mgr {m}; class TestComponent : public Component { using Component::Component; @@ -24,7 +24,7 @@ public: }; TEST_F(ECSTest, createGameObject) { - GameObject obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); + GameObject obj = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>(); vector<reference_wrapper<Transform>> transform = mgr.get_components_by_type<Transform>(); @@ -44,8 +44,8 @@ TEST_F(ECSTest, createGameObject) { } TEST_F(ECSTest, deleteAllGameObjects) { - GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); - GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); + GameObject obj0 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); mgr.delete_all_components(); @@ -55,7 +55,7 @@ TEST_F(ECSTest, deleteAllGameObjects) { EXPECT_EQ(metadata.size(), 0); EXPECT_EQ(transform.size(), 0); - GameObject obj2 = mgr.new_object("body2", "person2", vec2{1, 0}, 5, 1); + GameObject obj2 = mgr.new_object("body2", "person2", vec2 {1, 0}, 5, 1); metadata = mgr.get_components_by_type<Metadata>(); transform = mgr.get_components_by_type<Transform>(); @@ -77,8 +77,8 @@ TEST_F(ECSTest, deleteAllGameObjects) { } TEST_F(ECSTest, deleteGameObject) { - GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); - GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); + GameObject obj0 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); mgr.delete_all_components_of_id(0); @@ -103,7 +103,7 @@ TEST_F(ECSTest, deleteGameObject) { TEST_F(ECSTest, manyGameObjects) { for (int i = 0; i < 5000; i++) { - GameObject obj = mgr.new_object("body", "person", vec2{0, 0}, 0, i); + GameObject obj = mgr.new_object("body", "person", vec2 {0, 0}, 0, i); } vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>(); @@ -135,7 +135,7 @@ TEST_F(ECSTest, manyGameObjects) { for (int i = 0; i < 10000 - 5000; i++) { string tag = "person" + to_string(i); - GameObject obj = mgr.new_object("body", tag, vec2{0, 0}, i, 0); + GameObject obj = mgr.new_object("body", tag, vec2 {0, 0}, i, 0); } metadata = mgr.get_components_by_type<Metadata>(); @@ -168,7 +168,7 @@ TEST_F(ECSTest, manyGameObjects) { for (int i = 0; i < 10000; i++) { string name = "body" + to_string(i); - GameObject obj = mgr.new_object(name, "person", vec2{0, 0}, 0, 0); + GameObject obj = mgr.new_object(name, "person", vec2 {0, 0}, 0, 0); } metadata = mgr.get_components_by_type<Metadata>(); @@ -193,8 +193,8 @@ TEST_F(ECSTest, manyGameObjects) { } TEST_F(ECSTest, getComponentsByID) { - GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); - GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); + GameObject obj0 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_id<Metadata>(0); vector<reference_wrapper<Transform>> transform = mgr.get_components_by_id<Transform>(1); @@ -217,19 +217,21 @@ TEST_F(ECSTest, getComponentsByID) { TEST_F(ECSTest, tooMuchComponents) { try { - GameObject obj0 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); - obj0.add_component<Transform>(vec2{10, 10}, 0, 1); + GameObject obj0 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); + obj0.add_component<Transform>(vec2 {10, 10}, 0, 1); } catch (const exception & e) { - EXPECT_EQ(e.what(), - string("Exceeded maximum number of instances for this component type")); + EXPECT_EQ( + e.what(), string("Exceeded maximum number of instances for this component type") + ); } try { - GameObject obj1 = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); obj1.add_component<Metadata>("body", "person"); } catch (const exception & e) { - EXPECT_EQ(e.what(), - string("Exceeded maximum number of instances for this component type")); + EXPECT_EQ( + e.what(), string("Exceeded maximum number of instances for this component type") + ); } vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>(); @@ -241,11 +243,11 @@ TEST_F(ECSTest, tooMuchComponents) { TEST_F(ECSTest, partentChild) { { - GameObject body = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); - GameObject right_leg = mgr.new_object("rightLeg", "person", vec2{1, 1}, 0, 1); - GameObject left_leg = mgr.new_object("leftLeg", "person", vec2{1, 1}, 0, 1); - GameObject right_foot = mgr.new_object("rightFoot", "person", vec2{2, 2}, 0, 1); - GameObject left_foot = mgr.new_object("leftFoot", "person", vec2{2, 2}, 0, 1); + GameObject body = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); + GameObject right_leg = mgr.new_object("rightLeg", "person", vec2 {1, 1}, 0, 1); + GameObject left_leg = mgr.new_object("leftLeg", "person", vec2 {1, 1}, 0, 1); + GameObject right_foot = mgr.new_object("rightFoot", "person", vec2 {2, 2}, 0, 1); + GameObject left_foot = mgr.new_object("leftFoot", "person", vec2 {2, 2}, 0, 1); // Set the parent of each GameObject right_foot.set_parent(right_leg); @@ -290,10 +292,10 @@ TEST_F(ECSTest, partentChild) { } TEST_F(ECSTest, persistent) { - GameObject obj0 = mgr.new_object("obj0", "obj0", vec2{0, 0}, 0, 1); - GameObject obj1 = mgr.new_object("obj1", "obj1", vec2{0, 0}, 0, 1); + GameObject obj0 = mgr.new_object("obj0", "obj0", vec2 {0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("obj1", "obj1", vec2 {0, 0}, 0, 1); obj1.set_persistent(); - GameObject obj2 = mgr.new_object("obj2", "obj2", vec2{0, 0}, 0, 1); + GameObject obj2 = mgr.new_object("obj2", "obj2", vec2 {0, 0}, 0, 1); vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>(); vector<reference_wrapper<Transform>> transform = mgr.get_components_by_type<Transform>(); @@ -329,8 +331,8 @@ TEST_F(ECSTest, persistent) { EXPECT_EQ(transform[0].get().position.x, 0); EXPECT_EQ(transform[0].get().position.y, 0); - GameObject obj3 = mgr.new_object("obj3", "obj3", vec2{0, 0}, 0, 5); - GameObject obj4 = mgr.new_object("obj4", "obj4", vec2{0, 0}, 0, 5); + GameObject obj3 = mgr.new_object("obj3", "obj3", vec2 {0, 0}, 0, 5); + GameObject obj4 = mgr.new_object("obj4", "obj4", vec2 {0, 0}, 0, 5); metadata = mgr.get_components_by_type<Metadata>(); transform = mgr.get_components_by_type<Transform>(); @@ -358,10 +360,10 @@ TEST_F(ECSTest, persistent) { } TEST_F(ECSTest, resetPersistent) { - GameObject obj0 = mgr.new_object("obj0", "obj0", vec2{0, 0}, 0, 1); - GameObject obj1 = mgr.new_object("obj1", "obj1", vec2{0, 0}, 0, 1); + GameObject obj0 = mgr.new_object("obj0", "obj0", vec2 {0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("obj1", "obj1", vec2 {0, 0}, 0, 1); obj1.set_persistent(); - GameObject obj2 = mgr.new_object("obj2", "obj2", vec2{0, 0}, 0, 1); + GameObject obj2 = mgr.new_object("obj2", "obj2", vec2 {0, 0}, 0, 1); vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>(); vector<reference_wrapper<Transform>> transform = mgr.get_components_by_type<Transform>(); @@ -478,5 +480,5 @@ TEST_F(ECSTest, Snapshot) { mgr.restore(snapshot); - EXPECT_EQ(foo.transform.position, (vec2{1, 1})); + EXPECT_EQ(foo.transform.position, (vec2 {1, 1})); } diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp index f8be3fe..6105679 100644 --- a/src/test/EventTest.cpp +++ b/src/test/EventTest.cpp @@ -10,7 +10,7 @@ using namespace crepe; class EventManagerTest : public ::testing::Test { protected: Mediator mediator; - EventManager event_mgr{mediator}; + EventManager event_mgr {mediator}; void SetUp() override { // Clear any existing subscriptions or events before each test event_mgr.clear(); @@ -30,18 +30,20 @@ TEST_F(EventManagerTest, EventSubscription) { // Verify subscription (not directly verifiable; test by triggering event) event_mgr.trigger_event<KeyPressEvent>( - KeyPressEvent{ + KeyPressEvent { .repeat = true, .key = Keycode::A, }, - 1); + 1 + ); event_mgr.trigger_event<KeyPressEvent>( - KeyPressEvent{ + KeyPressEvent { .repeat = true, .key = Keycode::A, }, - EventManager::CHANNEL_ALL); + EventManager::CHANNEL_ALL + ); } TEST_F(EventManagerTest, EventManagerTest_trigger_all_channels) { bool triggered = false; @@ -55,7 +57,7 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_all_channels) { }; event_mgr.subscribe<MouseClickEvent>(mouse_handler, EventManager::CHANNEL_ALL); - MouseClickEvent click_event{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; + MouseClickEvent click_event {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL); EXPECT_TRUE(triggered); @@ -72,7 +74,7 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_one_channel) { }; event_mgr.subscribe<MouseClickEvent>(mouse_handler, test_channel); - MouseClickEvent click_event{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; + MouseClickEvent click_event {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL); EXPECT_FALSE(triggered); @@ -103,7 +105,7 @@ TEST_F(EventManagerTest, EventManagerTest_callback_propagation) { }; // Test event - MouseClickEvent click_event{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; + MouseClickEvent click_event {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}; event_mgr.subscribe<MouseClickEvent>(mouse_handler_true, EventManager::CHANNEL_ALL); event_mgr.subscribe<MouseClickEvent>(mouse_handler_false, EventManager::CHANNEL_ALL); @@ -151,10 +153,12 @@ TEST_F(EventManagerTest, EventManagerTest_queue_dispatch) { event_mgr.subscribe<MouseClickEvent>(mouse_handler2, test_channel); event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE} + ); event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}, - test_channel); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}, + test_channel + ); event_mgr.dispatch_events(); EXPECT_TRUE(triggered1); EXPECT_TRUE(triggered2); @@ -188,7 +192,8 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { // Queue events event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE} + ); // Dispatch events - both handlers should be triggered event_mgr.dispatch_events(); @@ -204,7 +209,8 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { // Queue the same event again event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE} + ); // Dispatch events - only handler 2 should be triggered, handler 1 should NOT event_mgr.dispatch_events(); @@ -219,7 +225,8 @@ TEST_F(EventManagerTest, EventManagerTest_unsubscribe) { // Queue the event again event_mgr.queue_event<MouseClickEvent>( - MouseClickEvent{.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE}); + MouseClickEvent {.mouse_pos = {100, 200}, .button = MouseButton::LEFT_MOUSE} + ); // Dispatch events - no handler should be triggered event_mgr.dispatch_events(); diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp index 0243bd8..9a541a0 100644 --- a/src/test/InputTest.cpp +++ b/src/test/InputTest.cpp @@ -28,22 +28,23 @@ using namespace crepe; class InputTest : public ::testing::Test { public: Mediator mediator; - ComponentManager mgr{mediator}; - SDLContext sdl_context{mediator}; + ComponentManager mgr {mediator}; + SDLContext sdl_context {mediator}; - InputSystem input_system{mediator}; - ResourceManager resman{mediator}; - RenderSystem render{mediator}; - EventManager event_manager{mediator}; + InputSystem input_system {mediator}; + ResourceManager resman {mediator}; + RenderSystem render {mediator}; + EventManager event_manager {mediator}; //GameObject camera; vec2 offset = {100, 200}; protected: void SetUp() override { GameObject obj = mgr.new_object("camera", "camera", offset, 0, 1); - auto & camera - = obj.add_component<Camera>(ivec2{500, 500}, vec2{500, 500}, - Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + auto & camera = obj.add_component<Camera>( + ivec2 {500, 500}, vec2 {500, 500}, + Camera::Data {.bg_color = Color::WHITE, .zoom = 1.0f} + ); render.frame_update(); //mediator.event_manager = event_manager; //mediator.component_manager = mgr; @@ -208,14 +209,14 @@ TEST_F(InputTest, MouseClick) { } TEST_F(InputTest, testButtonClick) { - GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); + GameObject button_obj = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); bool button_clicked = false; event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) { button_clicked = true; EXPECT_EQ(event.metadata.game_object_id, button_obj.id); return false; }); - auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}); + auto & button = button_obj.add_component<Button>(vec2 {100, 100}, vec2 {0, 0}); bool hover = false; button.active = true; @@ -230,14 +231,14 @@ TEST_F(InputTest, testButtonClick) { EXPECT_TRUE(button_clicked); } TEST_F(InputTest, buttonPositionCamera) { - GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1); + GameObject button_obj = mgr.new_object("body", "person", vec2 {50, 50}, 0, 1); bool button_clicked = false; event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) { button_clicked = true; EXPECT_EQ(event.metadata.game_object_id, button_obj.id); return false; }); - auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0}); + auto & button = button_obj.add_component<Button>(vec2 {10, 10}, vec2 {0, 0}); button.world_space = false; bool hover = false; @@ -253,14 +254,14 @@ TEST_F(InputTest, buttonPositionCamera) { EXPECT_TRUE(button_clicked); } TEST_F(InputTest, buttonPositionWorld) { - GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1); + GameObject button_obj = mgr.new_object("body", "person", vec2 {50, 50}, 0, 1); bool button_clicked = false; event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) { button_clicked = true; EXPECT_EQ(event.metadata.game_object_id, button_obj.id); return false; }); - auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0}); + auto & button = button_obj.add_component<Button>(vec2 {10, 10}, vec2 {0, 0}); button.world_space = true; bool hover = false; button.active = true; @@ -275,7 +276,7 @@ TEST_F(InputTest, buttonPositionWorld) { EXPECT_FALSE(button_clicked); } TEST_F(InputTest, testButtonHover) { - GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); + GameObject button_obj = mgr.new_object("body", "person", vec2 {0, 0}, 0, 1); bool button_hover = false; event_manager.subscribe<ButtonEnterEvent>([&](const ButtonEnterEvent & event) { button_hover = true; @@ -287,7 +288,7 @@ TEST_F(InputTest, testButtonHover) { EXPECT_EQ(event.metadata.game_object_id, button_obj.id); return false; }); - auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}); + auto & button = button_obj.add_component<Button>(vec2 {100, 100}, vec2 {0, 0}); button.active = true; // Mouse on button SDL_Event hover_event; diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp index f6653fa..302d96c 100644 --- a/src/test/LoopManagerTest.cpp +++ b/src/test/LoopManagerTest.cpp @@ -72,7 +72,7 @@ TEST_F(DISABLED_LoopManagerTest, ShutDown) { // Start the loop in a separate thread std::thread loop_thread([&]() { test_loop.start(); }); std::this_thread::sleep_for(std::chrono::milliseconds(1)); - test_loop.event_manager.trigger_event<ShutDownEvent>(ShutDownEvent{}); + test_loop.event_manager.trigger_event<ShutDownEvent>(ShutDownEvent {}); // Wait for the loop thread to finish loop_thread.join(); } diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp index 7bd6305..52e412e 100644 --- a/src/test/LoopTimerTest.cpp +++ b/src/test/LoopTimerTest.cpp @@ -14,7 +14,7 @@ using namespace crepe; class LoopTimerTest : public ::testing::Test { protected: Mediator mediator; - LoopTimerManager loop_timer{mediator}; + LoopTimerManager loop_timer {mediator}; void SetUp() override { loop_timer.start(); } }; diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 7a731a3..eee7a73 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -22,45 +22,49 @@ class ParticlesTest : public ::testing::Test { Mediator m; public: - ComponentManager component_manager{m}; - ParticleSystem particle_system{m}; - LoopTimerManager loop_timer{m}; + ComponentManager component_manager {m}; + ParticleSystem particle_system {m}; + LoopTimerManager loop_timer {m}; void SetUp() override { ComponentManager & mgr = this->component_manager; std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(0); if (transforms.empty()) { - GameObject game_object = mgr.new_object("", "", vec2{0, 0}, 0, 0); + GameObject game_object = mgr.new_object("", "", vec2 {0, 0}, 0, 0); Color color(0, 0, 0, 0); auto s1 = Asset("asset/texture/img.png"); Sprite & test_sprite = game_object.add_component<Sprite>( - s1, Sprite::Data{ - .color = color, - .flip = Sprite::FlipSettings{true, true}, - .size = {10, 10}, - }); + s1, + Sprite::Data { + .color = color, + .flip = Sprite::FlipSettings {true, true}, + .size = {10, 10}, + } + ); - game_object.add_component<ParticleEmitter>(test_sprite, - ParticleEmitter::Data{ - .offset = {0, 0}, - .max_particles = 100, - .emission_rate = 0, - .min_speed = 0, - .max_speed = 0, - .min_angle = 0, - .max_angle = 0, - .begin_lifespan = 0, - .end_lifespan = 0, - .force_over_time = vec2{0, 0}, - .boundary{ - .width = 0, - .height = 0, - .offset = vec2{0, 0}, - .reset_on_exit = false, - }, - }); + game_object.add_component<ParticleEmitter>( + test_sprite, + ParticleEmitter::Data { + .offset = {0, 0}, + .max_particles = 100, + .emission_rate = 0, + .min_speed = 0, + .max_speed = 0, + .min_angle = 0, + .max_angle = 0, + .begin_lifespan = 0, + .end_lifespan = 0, + .force_over_time = vec2 {0, 0}, + .boundary { + .width = 0, + .height = 0, + .offset = vec2 {0, 0}, + .reset_on_exit = false, + }, + } + ); } transforms = mgr.get_components_by_id<Transform>(0); Transform & transform = transforms.front().get(); @@ -78,8 +82,8 @@ public: emitter.data.max_angle = 0; emitter.data.begin_lifespan = 0; emitter.data.end_lifespan = 0; - emitter.data.force_over_time = vec2{0, 0}; - emitter.data.boundary = {0, 0, vec2{0, 0}, false}; + emitter.data.force_over_time = vec2 {0, 0}; + emitter.data.boundary = {0, 0, vec2 {0, 0}, false}; for (auto & particle : emitter.particles) { particle.active = false; } @@ -204,9 +208,13 @@ TEST_F(ParticlesTest, boundaryParticleStop) { EXPECT_NEAR(emitter.particles[0].velocity.x, 0, TOLERANCE); EXPECT_NEAR(emitter.particles[0].velocity.y, 0, TOLERANCE); if (emitter.particles[0].velocity.x != 0) - EXPECT_NEAR(std::abs(emitter.particles[0].position.x), - emitter.data.boundary.height / 2, TOLERANCE); + EXPECT_NEAR( + std::abs(emitter.particles[0].position.x), emitter.data.boundary.height / 2, + TOLERANCE + ); if (emitter.particles[0].velocity.y != 0) - EXPECT_NEAR(std::abs(emitter.particles[0].position.y), emitter.data.boundary.width / 2, - TOLERANCE); + EXPECT_NEAR( + std::abs(emitter.particles[0].position.y), emitter.data.boundary.width / 2, + TOLERANCE + ); } diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 79ed0b8..85eb6d5 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -16,17 +16,17 @@ class PhysicsTest : public ::testing::Test { Mediator m; public: - ComponentManager component_manager{m}; - PhysicsSystem system{m}; - LoopTimerManager loop_timer{m}; + ComponentManager component_manager {m}; + PhysicsSystem system {m}; + LoopTimerManager loop_timer {m}; void SetUp() override { ComponentManager & mgr = this->component_manager; vector<reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(0); if (transforms.empty()) { - auto entity = mgr.new_object("", "", vec2{0, 0}, 0, 0); - entity.add_component<Rigidbody>(Rigidbody::Data{ + auto entity = mgr.new_object("", "", vec2 {0, 0}, 0, 0); + entity.add_component<Rigidbody>(Rigidbody::Data { .mass = 1, .gravity_scale = 1, .body_type = Rigidbody::BodyType::DYNAMIC, diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index d1da5a0..d8bd09d 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -36,8 +36,9 @@ class TestScript : public Script { return true; } void init() { - subscribe<CollisionEvent>( - [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); + subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool { + return this->oncollision(ev); + }); } void fixed_update() { // Retrieve component from the same GameObject this script is on @@ -57,17 +58,17 @@ public: const std::chrono::microseconds duration = 16000us; Mediator m; - SDLContext sdl_context{m}; - ResourceManager resman{m}; - ComponentManager mgr{m}; + SDLContext sdl_context {m}; + ResourceManager resman {m}; + ComponentManager mgr {m}; // Add system used for profling tests - EventManager evmgr{m}; - LoopTimerManager loopmgr{m}; - CollisionSystem collision_sys{m}; - PhysicsSystem physics_sys{m}; - ParticleSystem particle_sys{m}; - RenderSystem render_sys{m}; - ScriptSystem script_sys{m}; + EventManager evmgr {m}; + LoopTimerManager loopmgr {m}; + CollisionSystem collision_sys {m}; + PhysicsSystem physics_sys {m}; + ParticleSystem particle_sys {m}; + RenderSystem render_sys {m}; + ScriptSystem script_sys {m}; // Test data std::map<std::string, std::chrono::microseconds> timings; @@ -77,11 +78,13 @@ public: void SetUp() override { GameObject do_not_use = mgr.new_object("DO_NOT_USE", "", {0, 0}); - do_not_use.add_component<Camera>(ivec2{1080, 720}, vec2{2000, 2000}, - Camera::Data{ - .bg_color = Color::WHITE, - .zoom = 1.0f, - }); + do_not_use.add_component<Camera>( + ivec2 {1080, 720}, vec2 {2000, 2000}, + Camera::Data { + .bg_color = Color::WHITE, + .zoom = 1.0f, + } + ); // initialize systems here: //calls init script_sys.fixed_update(); @@ -168,23 +171,25 @@ TEST_F(DISABLED_ProfilingTest, Profiling_2) { { //define gameobject used for testing GameObject gameobject = mgr.new_object( - "gameobject", "", {static_cast<float>(game_object_count * 2), 0}); - gameobject.add_component<Rigidbody>(Rigidbody::Data{ + "gameobject", "", {static_cast<float>(game_object_count * 2), 0} + ); + gameobject.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 0.0, .body_type = Rigidbody::BodyType::STATIC, }); - gameobject.add_component<BoxCollider>(vec2{0, 0}, vec2{1, 1}); + gameobject.add_component<BoxCollider>(vec2 {0, 0}, vec2 {1, 1}); gameobject.add_component<BehaviorScript>().set_script<TestScript>(); Sprite & test_sprite = gameobject.add_component<Sprite>( - Asset{"asset/texture/square.png"}, - Sprite::Data{ + Asset {"asset/texture/square.png"}, + Sprite::Data { .color = {0, 0, 0, 0}, .flip = {.flip_x = false, .flip_y = false}, .sorting_in_layer = 1, .order_in_layer = 1, .size = {.y = 500}, - }); + } + ); } this->game_object_count++; @@ -207,35 +212,39 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) { { //define gameobject used for testing GameObject gameobject = mgr.new_object( - "gameobject", "", {static_cast<float>(game_object_count * 2), 0}); - gameobject.add_component<Rigidbody>(Rigidbody::Data{ + "gameobject", "", {static_cast<float>(game_object_count * 2), 0} + ); + gameobject.add_component<Rigidbody>(Rigidbody::Data { .gravity_scale = 0, .body_type = Rigidbody::BodyType::STATIC, }); - gameobject.add_component<BoxCollider>(vec2{0, 0}, vec2{1, 1}); + gameobject.add_component<BoxCollider>(vec2 {0, 0}, vec2 {1, 1}); gameobject.add_component<BehaviorScript>().set_script<TestScript>(); Sprite & test_sprite = gameobject.add_component<Sprite>( - Asset{"asset/texture/square.png"}, - Sprite::Data{ + Asset {"asset/texture/square.png"}, + Sprite::Data { .color = {0, 0, 0, 0}, .flip = {.flip_x = false, .flip_y = false}, .sorting_in_layer = 1, .order_in_layer = 1, .size = {.y = 500}, - }); + } + ); auto & test = gameobject.add_component<ParticleEmitter>( - test_sprite, ParticleEmitter::Data{ - .max_particles = 10, - .emission_rate = 100, - .end_lifespan = 100000, - .boundary{ - .width = 1000, - .height = 1000, - .offset = vec2{0, 0}, - .reset_on_exit = false, - }, - - }); + test_sprite, + ParticleEmitter::Data { + .max_particles = 10, + .emission_rate = 100, + .end_lifespan = 100000, + .boundary { + .width = 1000, + .height = 1000, + .offset = vec2 {0, 0}, + .reset_on_exit = false, + }, + + } + ); } render_sys.frame_update(); this->game_object_count++; diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp index 689a6d4..bdd87ee 100644 --- a/src/test/RenderSystemTest.cpp +++ b/src/test/RenderSystemTest.cpp @@ -26,10 +26,10 @@ class RenderSystemTest : public Test { Mediator m; public: - ComponentManager mgr{m}; - SDLContext ctx{m}; - ResourceManager resource_manager{m}; - RenderSystem sys{m}; + ComponentManager mgr {m}; + SDLContext ctx {m}; + ResourceManager resource_manager {m}; + RenderSystem sys {m}; GameObject entity1 = this->mgr.new_object("name"); GameObject entity2 = this->mgr.new_object("name"); GameObject entity3 = this->mgr.new_object("name"); @@ -40,44 +40,52 @@ public: auto s2 = Asset("asset/texture/img.png"); auto s3 = Asset("asset/texture/img.png"); auto s4 = Asset("asset/texture/img.png"); - auto & sprite1 - = entity1.add_component<Sprite>(s1, Sprite::Data{ - .color = Color(0, 0, 0, 0), - .flip = Sprite::FlipSettings{false, false}, - .sorting_in_layer = 5, - .order_in_layer = 5, - .size = {10, 10}, - }); + auto & sprite1 = entity1.add_component<Sprite>( + s1, + Sprite::Data { + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings {false, false}, + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = {10, 10}, + } + ); EXPECT_EQ(sprite1.data.order_in_layer, 5); EXPECT_EQ(sprite1.data.sorting_in_layer, 5); - auto & sprite2 - = entity2.add_component<Sprite>(s2, Sprite::Data{ - .color = Color(0, 0, 0, 0), - .flip = Sprite::FlipSettings{false, false}, - .sorting_in_layer = 2, - .order_in_layer = 1, - }); + auto & sprite2 = entity2.add_component<Sprite>( + s2, + Sprite::Data { + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings {false, false}, + .sorting_in_layer = 2, + .order_in_layer = 1, + } + ); EXPECT_EQ(sprite2.data.sorting_in_layer, 2); EXPECT_EQ(sprite2.data.order_in_layer, 1); - auto & sprite3 - = entity3.add_component<Sprite>(s3, Sprite::Data{ - .color = Color(0, 0, 0, 0), - .flip = Sprite::FlipSettings{false, false}, - .sorting_in_layer = 1, - .order_in_layer = 2, - }); + auto & sprite3 = entity3.add_component<Sprite>( + s3, + Sprite::Data { + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings {false, false}, + .sorting_in_layer = 1, + .order_in_layer = 2, + } + ); EXPECT_EQ(sprite3.data.sorting_in_layer, 1); EXPECT_EQ(sprite3.data.order_in_layer, 2); - auto & sprite4 - = entity4.add_component<Sprite>(s4, Sprite::Data{ - .color = Color(0, 0, 0, 0), - .flip = Sprite::FlipSettings{false, false}, - .sorting_in_layer = 1, - .order_in_layer = 1, - }); + auto & sprite4 = entity4.add_component<Sprite>( + s4, + Sprite::Data { + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings {false, false}, + .sorting_in_layer = 1, + .order_in_layer = 1, + } + ); EXPECT_EQ(sprite4.data.sorting_in_layer, 1); EXPECT_EQ(sprite4.data.order_in_layer, 1); } @@ -128,8 +136,10 @@ TEST_F(RenderSystemTest, sorting_sprites) { } TEST_F(RenderSystemTest, Update) { - entity1.add_component<Camera>(ivec2{100, 100}, vec2{100, 100}, - Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + entity1.add_component<Camera>( + ivec2 {100, 100}, vec2 {100, 100}, + Camera::Data {.bg_color = Color::WHITE, .zoom = 1.0f} + ); { vector<reference_wrapper<Sprite>> sprites = this->mgr.get_components_by_type<Sprite>(); ASSERT_EQ(sprites.size(), 4); @@ -157,8 +167,10 @@ TEST_F(RenderSystemTest, Camera) { EXPECT_NE(cameras.size(), 1); } { - entity1.add_component<Camera>(ivec2{100, 100}, vec2{100, 100}, - Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + entity1.add_component<Camera>( + ivec2 {100, 100}, vec2 {100, 100}, + Camera::Data {.bg_color = Color::WHITE, .zoom = 1.0f} + ); auto cameras = this->mgr.get_components_by_type<Camera>(); EXPECT_EQ(cameras.size(), 1); @@ -167,8 +179,10 @@ TEST_F(RenderSystemTest, Camera) { //TODO improve with newer version } TEST_F(RenderSystemTest, Color) { - entity1.add_component<Camera>(ivec2{100, 100}, vec2{100, 100}, - Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + entity1.add_component<Camera>( + ivec2 {100, 100}, vec2 {100, 100}, + Camera::Data {.bg_color = Color::WHITE, .zoom = 1.0f} + ); auto & sprite = this->mgr.get_components_by_id<Sprite>(entity1.id).front().get(); //ASSERT_NE(sprite.texture.texture.get(), nullptr); diff --git a/src/test/ReplayManagerTest.cpp b/src/test/ReplayManagerTest.cpp index 5ee4b40..b2619eb 100644 --- a/src/test/ReplayManagerTest.cpp +++ b/src/test/ReplayManagerTest.cpp @@ -14,9 +14,9 @@ class ReplayManagerTest : public Test { Mediator mediator; public: - ComponentManager component_manager{mediator}; - ReplayManager replay_manager{mediator}; - ReplaySystem replay_system{mediator}; + ComponentManager component_manager {mediator}; + ReplayManager replay_manager {mediator}; + ReplaySystem replay_system {mediator}; GameObject entity = component_manager.new_object("foo"); Transform & entity_transform diff --git a/src/test/ResourceManagerTest.cpp b/src/test/ResourceManagerTest.cpp index 965eeab..e5a7fad 100644 --- a/src/test/ResourceManagerTest.cpp +++ b/src/test/ResourceManagerTest.cpp @@ -16,14 +16,14 @@ class ResourceManagerTest : public Test { Mediator mediator; public: - ResourceManager resource_manager{mediator}; + ResourceManager resource_manager {mediator}; class Unrelated : public Resource { using Resource::Resource; }; - Asset asset_a{"asset/texture/img.png"}; - Asset asset_b{"asset/texture/ERROR.png"}; + Asset asset_a {"asset/texture/img.png"}; + Asset asset_b {"asset/texture/ERROR.png"}; class TestResource : public Resource { public: diff --git a/src/test/SaveManagerTest.cpp b/src/test/SaveManagerTest.cpp index 7609e69..fd53200 100644 --- a/src/test/SaveManagerTest.cpp +++ b/src/test/SaveManagerTest.cpp @@ -14,12 +14,12 @@ class SaveManagerTest : public Test { using SaveManager::SaveManager; // in-memory database for testing - DB db{}; + DB db {}; virtual DB & get_db() override { return this->db; } }; public: - TestSaveManager mgr{m}; + TestSaveManager mgr {m}; }; TEST_F(SaveManagerTest, ReadWrite) { diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp index 480e07a..e58ce36 100644 --- a/src/test/SceneManagerTest.cpp +++ b/src/test/SceneManagerTest.cpp @@ -15,9 +15,9 @@ using namespace crepe; class ConcreteScene1 : public Scene { public: void load_scene() { - GameObject object1 = new_object("scene_1", "tag_scene_1", vec2{0, 0}, 0, 1); - GameObject object2 = new_object("scene_1", "tag_scene_1", vec2{1, 0}, 0, 1); - GameObject object3 = new_object("scene_1", "tag_scene_1", vec2{2, 0}, 0, 1); + GameObject object1 = new_object("scene_1", "tag_scene_1", vec2 {0, 0}, 0, 1); + GameObject object2 = new_object("scene_1", "tag_scene_1", vec2 {1, 0}, 0, 1); + GameObject object3 = new_object("scene_1", "tag_scene_1", vec2 {2, 0}, 0, 1); } string get_name() const { return "scene1"; } @@ -26,10 +26,10 @@ public: class ConcreteScene2 : public Scene { public: void load_scene() { - GameObject object1 = new_object("scene_2", "tag_scene_2", vec2{0, 0}, 0, 1); - GameObject object2 = new_object("scene_2", "tag_scene_2", vec2{0, 1}, 0, 1); - GameObject object3 = new_object("scene_2", "tag_scene_2", vec2{0, 2}, 0, 1); - GameObject object4 = new_object("scene_2", "tag_scene_2", vec2{0, 3}, 0, 1); + GameObject object1 = new_object("scene_2", "tag_scene_2", vec2 {0, 0}, 0, 1); + GameObject object2 = new_object("scene_2", "tag_scene_2", vec2 {0, 1}, 0, 1); + GameObject object3 = new_object("scene_2", "tag_scene_2", vec2 {0, 2}, 0, 1); + GameObject object4 = new_object("scene_2", "tag_scene_2", vec2 {0, 3}, 0, 1); } string get_name() const { return "scene2"; } @@ -40,7 +40,7 @@ public: ConcreteScene3(const string & name) : name(name) {} void load_scene() { - GameObject object1 = new_object("scene_3", "tag_scene_3", vec2{0, 0}, 0, 1); + GameObject object1 = new_object("scene_3", "tag_scene_3", vec2 {0, 0}, 0, 1); } string get_name() const { return name; } @@ -53,8 +53,8 @@ class SceneManagerTest : public ::testing::Test { Mediator m; public: - ComponentManager component_mgr{m}; - SceneManager scene_mgr{m}; + ComponentManager component_mgr {m}; + SceneManager scene_mgr {m}; }; TEST_F(SceneManagerTest, loadScene) { diff --git a/src/test/ScriptSaveManagerTest.cpp b/src/test/ScriptSaveManagerTest.cpp index 64403c4..e2debae 100644 --- a/src/test/ScriptSaveManagerTest.cpp +++ b/src/test/ScriptSaveManagerTest.cpp @@ -19,11 +19,11 @@ public: using SaveManager::SaveManager; // in-memory database for testing - DB db{}; + DB db {}; virtual DB & get_db() override { return this->db; } }; - TestSaveManager save_mgr{mediator}; + TestSaveManager save_mgr {mediator}; }; TEST_F(ScriptSaveManagerTest, GetSaveManager) { diff --git a/src/test/ScriptSceneTest.cpp b/src/test/ScriptSceneTest.cpp index 2568049..7d01f14 100644 --- a/src/test/ScriptSceneTest.cpp +++ b/src/test/ScriptSceneTest.cpp @@ -13,7 +13,7 @@ using namespace testing; class ScriptSceneTest : public ScriptTest { public: - SceneManager scene_manager{mediator}; + SceneManager scene_manager {mediator}; class MyScene : public Scene {}; }; diff --git a/src/test/ScriptTest.h b/src/test/ScriptTest.h index 8637df0..f953aab 100644 --- a/src/test/ScriptTest.h +++ b/src/test/ScriptTest.h @@ -17,11 +17,11 @@ protected: static constexpr const char * OBJ_NAME = "foo"; public: - crepe::ComponentManager component_manager{mediator}; - crepe::ScriptSystem system{mediator}; - crepe::EventManager event_mgr{mediator}; - crepe::LoopTimerManager loop_timer{mediator}; - crepe::SaveManager save_manager{mediator}; + crepe::ComponentManager component_manager {mediator}; + crepe::ScriptSystem system {mediator}; + crepe::EventManager event_mgr {mediator}; + crepe::LoopTimerManager loop_timer {mediator}; + crepe::SaveManager save_manager {mediator}; crepe::GameObject entity = component_manager.new_object(OBJ_NAME); class MyScript : public crepe::Script { diff --git a/src/test/ValueBrokerTest.cpp b/src/test/ValueBrokerTest.cpp index e6bb058..5928c37 100644 --- a/src/test/ValueBrokerTest.cpp +++ b/src/test/ValueBrokerTest.cpp @@ -13,7 +13,7 @@ public: int write_count = 0; int value = 0; - ValueBroker<int> broker{ + ValueBroker<int> broker { [this](const int & target) -> void { this->write_count++; this->value = target; @@ -23,7 +23,7 @@ public: return this->value; }, }; - Proxy<int> proxy{broker}; + Proxy<int> proxy {broker}; void SetUp() override { ASSERT_EQ(read_count, 0); |