From 1fa3293df0ca0b00faef7045daf01c25f2ed8170 Mon Sep 17 00:00:00 2001 From: Andrew Haynes Macbook Date: Fri, 9 Jan 2026 14:56:59 -0500 Subject: [PATCH] fixes and optimizations --- .clang-format | 6 +- include/data.hpp | 22 ---- include/elements.hpp | 36 ++++--- include/globals.hpp | 8 +- include/maps.hpp | 18 ++-- include/scheduler.hpp | 4 +- src/data.cpp | 1 - src/elements.cpp | 80 ++++++--------- src/main.cpp | 47 +++------ src/maps.cpp | 234 ++++++++++++++---------------------------- src/scheduler.cpp | 3 +- 11 files changed, 163 insertions(+), 296 deletions(-) delete mode 100644 include/data.hpp delete mode 100644 src/data.cpp diff --git a/.clang-format b/.clang-format index ff24801..b6a510e 100644 --- a/.clang-format +++ b/.clang-format @@ -13,7 +13,7 @@ TabWidth: 8 IndentWidth: 8 ContinuationIndentWidth: 8 AlignAfterOpenBracket: Align -PointerAlignment: Right +PointerAlignment: Left # Braces BreakBeforeBraces: Custom @@ -36,6 +36,10 @@ SpaceBeforeParensOptions: AfterControlStatements: true SpaceBeforeRangeBasedForLoopColon: true AllowShortFunctionsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: true +AllowShortLoopsOnASingleLine: true +RemoveEmptyLinesInUnwrappedLines: true +SeparateDefinitionBlocks: Always # Preprocessor IndentPPDirectives: AfterHash diff --git a/include/data.hpp b/include/data.hpp deleted file mode 100644 index cb25cce..0000000 --- a/include/data.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef DATA_HPP -#define DATA_HPP - -#include "globals.hpp" -#include -#include - -struct Map { - const char map[MAX_ROWS][MAX_COLS]; -}; - -struct Player { - sf::Vector2 size { TILESIZE / 2.0f, TILESIZE / 2.0f }; - sf::Vector2 pos { TILESIZE, TILESIZE }; - float max_velocity_y { 15.0f }; - float border_size { -1.0f }; - - float dash_distance { 20.0f }; - sf::Vector2f velocity { 3.0f, 0 }; -}; - -#endif diff --git a/include/elements.hpp b/include/elements.hpp index 78f8b66..514981f 100644 --- a/include/elements.hpp +++ b/include/elements.hpp @@ -1,24 +1,27 @@ #ifndef PLAYER_HPP #define PLAYER_HPP +#include "globals.hpp" +#include "scheduler.hpp" + #include #include #include -#include "scheduler.hpp" -#include "globals.hpp" enum class CollisionDir { None, Left, Right, Top, Bottom }; + class Entity { -public: - Entity(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, sf::Color inside_color = sf::Color::Black, sf::Color border_color = sf::Color::White); - CollisionDir find_intersection(Entity &entity); + public: + Entity(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, + sf::Color inside_color = sf::Color::Black, sf::Color border_color = sf::Color::White); + CollisionDir find_intersection(Entity& entity); void set_velocity(sf::Vector2f velocity); void set_velocity_x(int velocity); void set_velocity_y(int velocity); sf::Vector2 get_velocity(); sf::RectangleShape rect; -protected: + protected: sf::Vector2f _velocity; sf::Color _inside_color; sf::Color _border_color; @@ -26,8 +29,10 @@ protected: }; class Player : public Entity { -public: - Player(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, float gravity, float max_acceleration, float dash_distance, sf::Color inside_color, sf::Color border_color); + public: + Player(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, + float gravity, float max_acceleration, float dash_distance, sf::Color inside_color, + sf::Color border_color); float m_acceleration; float m_jump_strength; float m_dash_distance; @@ -37,13 +42,14 @@ public: void handle_movment(); void handle_gravity(); bool get_jumping(); - void horizontal_no_out_of_bounds(Entity &base); - void vertical_no_out_of_bounds(Entity &base); - bool get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]); - bool get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]); - bool get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]); -private: - bool get_vertical_bottom_collision_by_offset(Entity *wall_list[MAX_ROWS][MAX_COLS]); + void horizontal_no_out_of_bounds(Entity& base); + void vertical_no_out_of_bounds(Entity& base); + bool get_horizontal_collision(std::array, MAX_ROWS>); + bool get_vertical_top_collision(std::array, MAX_ROWS>); + bool get_vertical_bottom_collision(std::array, MAX_ROWS>); + + private: + bool get_vertical_bottom_collision_by_offset(std::array, MAX_ROWS>); sf::Vector2f _min_velocity; }; diff --git a/include/globals.hpp b/include/globals.hpp index 54b8944..700ceac 100644 --- a/include/globals.hpp +++ b/include/globals.hpp @@ -1,10 +1,10 @@ #ifndef GLOBALS_HPP #define GLOBALS_HPP #define TILESIZE 32 -#define WIDTH 608 -#define HEIGHT 416 +#define MAX_COLS 8 // 19 cols +#define MAX_ROWS 8 // 13 rows +#define WIDTH TILESIZE * MAX_COLS +#define HEIGHT TILESIZE * MAX_ROWS #define FPS 60 #define GRAVITY 1 -#define MAX_COLS WIDTH / TILESIZE // 19 cols -#define MAX_ROWS HEIGHT / TILESIZE // 13 rows #endif diff --git a/include/maps.hpp b/include/maps.hpp index 33be985..481f94f 100644 --- a/include/maps.hpp +++ b/include/maps.hpp @@ -1,10 +1,11 @@ #ifndef MAPS_HPP #define MAPS_HPP +#include "elements.hpp" +#include "globals.hpp" + #include #include -#include "globals.hpp" -#include "elements.hpp" struct Level { char data[MAX_ROWS][MAX_COLS]; @@ -12,15 +13,8 @@ struct Level { }; extern Level levels[]; +extern const char map[MAX_ROWS][MAX_COLS]; -void clear_map(std::array, MAX_ROWS> wall_list); -void load_map(std::array, MAX_ROWS> wall_list, const std::array, MAX_ROWS> map_data); -std::array, MAX_ROWS> create_map(sf::RenderWindow &window, - sf::Vector2i &local_position, - sf::Vector2i &start_mouse_pos, - sf::Vector2i &end_mouse_pos, - bool &dragging, - bool &prev_dragging, - std::array, MAX_ROWS> wall_list); - +void clear_map(std::array, MAX_ROWS>& wall_list); +void load_map(std::array, MAX_ROWS>& wall_list, const char map_data[MAX_ROWS][MAX_COLS]); #endif diff --git a/include/scheduler.hpp b/include/scheduler.hpp index fb0648e..8014e2e 100644 --- a/include/scheduler.hpp +++ b/include/scheduler.hpp @@ -3,12 +3,12 @@ struct Times { float dash_cooldown { 0 }; - float dash_cooldown_max { 5 }; + float dash_cooldown_max { .5 }; float level_switch_cooldown { 0 }; float level_switch_cooldown_max { 1 }; }; struct Timer { - void update_timers(bool &running, Times ×); + void update_timers(bool& running, Times& times); }; #endif diff --git a/src/data.cpp b/src/data.cpp deleted file mode 100644 index fcd5616..0000000 --- a/src/data.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "data.hpp" diff --git a/src/elements.cpp b/src/elements.cpp index 547b8fa..91cbb1a 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -9,8 +9,10 @@ #ifdef __APPLE__ #include #include +namespace rv = ranges::views; #else #include +namespace rv = std::views; #endif Entity::Entity(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, @@ -31,7 +33,7 @@ void Entity::set_velocity_y(int velocity) { _velocity.y = velocity; } sf::Vector2 Entity::get_velocity() { return _velocity; } -CollisionDir Entity::find_intersection(Entity &entity) { +CollisionDir Entity::find_intersection(Entity& entity) { sf::FloatRect a = rect.getGlobalBounds(); sf::FloatRect b = entity.rect.getGlobalBounds(); auto inter = a.findIntersection(b); @@ -66,10 +68,10 @@ Player::Player(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f vel void Player::handle_movment() { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) { - rect.move({_velocity.x, 0}); + rect.move({ _velocity.x, 0 }); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { - rect.move({-_velocity.x, 0}); + rect.move({ -_velocity.x, 0 }); } if (timers.dash_cooldown <= 0) { m_dash = false; @@ -91,72 +93,56 @@ void Player::handle_gravity() { } set_velocity_y(get_velocity().y + m_acceleration); - rect.move({0, get_velocity().y}); + rect.move({ 0, get_velocity().y }); } -void Player::horizontal_no_out_of_bounds(Entity &base) { +void Player::horizontal_no_out_of_bounds(Entity& base) { float right_border = WIDTH - rect.getSize().x; if (rect.getPosition().x > right_border) { - rect.setPosition({right_border, rect.getPosition().y}); + rect.setPosition({ right_border, rect.getPosition().y }); } if (rect.getPosition().x < std::abs(rect.getOutlineThickness())) { - rect.setPosition({0, rect.getPosition().y}); + rect.setPosition({ 0, rect.getPosition().y }); } } -void Player::vertical_no_out_of_bounds(Entity &base) { +void Player::vertical_no_out_of_bounds(Entity& base) { float groundY = base.rect.getPosition().y - base.rect.getSize().y - rect.getSize().y - base.rect.getOutlineThickness() - rect.getOutlineThickness(); if (rect.getPosition().y >= groundY) { - rect.setPosition({rect.getPosition().x, groundY}); + rect.setPosition({ rect.getPosition().x, groundY }); set_velocity_y(0); m_jumping = false; } } -bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) { -#ifdef __APPLE__ - for (auto [i, j] : - ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { -#else - for (auto [i, j] : - std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { -#endif - if (wall_list[i][j] == nullptr) - continue; +bool Player::get_horizontal_collision(std::array, MAX_ROWS> wall_list) { + for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { + if (wall_list[i][j] == nullptr) continue; auto collision = wall_list[i][j]->find_intersection(*this); - if (collision == CollisionDir::None) - continue; + if (collision == CollisionDir::None) continue; if (collision == CollisionDir::Left) { rect.setPosition( - {wall_list[i][j]->rect.getPosition().x - rect.getSize().x, rect.getPosition().y}); + { wall_list[i][j]->rect.getPosition().x - rect.getSize().x, rect.getPosition().y }); return true; } if (collision == CollisionDir::Right) { - rect.setPosition({wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x, - rect.getPosition().y}); + rect.setPosition({ wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x, + rect.getPosition().y }); return true; } } return false; } -bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) { -#ifdef __APPLE__ - for (auto [i, j] : - ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { -#else - for (auto [i, j] : - std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { -#endif - if (wall_list[i][j] == nullptr) - continue; +bool Player::get_vertical_top_collision(std::array, MAX_ROWS> wall_list) { + for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { + if (wall_list[i][j] == nullptr) continue; auto collision = find_intersection(*wall_list[i][j]); - if (collision == CollisionDir::None) - continue; + if (collision == CollisionDir::None) continue; if (collision == CollisionDir::Top) { - rect.setPosition({rect.getPosition().x, - wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y}); + rect.setPosition({ rect.getPosition().x, + wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y }); set_velocity_y(0); return true; } @@ -164,22 +150,14 @@ bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) { return false; } -bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) { -#ifdef __APPLE__ - for (auto [i, j] : - ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { -#else - for (auto [i, j] : - std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { -#endif - if (wall_list[i][j] == nullptr) - continue; +bool Player::get_vertical_bottom_collision(std::array, MAX_ROWS> wall_list) { + for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { + if (wall_list[i][j] == nullptr) continue; auto collision = find_intersection(*wall_list[i][j]); - if (collision == CollisionDir::None) - continue; + if (collision == CollisionDir::None) continue; if (collision == CollisionDir::Bottom && get_velocity().y > 0) { rect.setPosition( - {rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y}); + { rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y }); m_jumping = false; set_velocity_y(0); return true; diff --git a/src/main.cpp b/src/main.cpp index 2bb7e4c..5665909 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,17 +5,17 @@ #include #include #include -#include #include #include -#include #include #ifdef __APPLE__ #include #include +namespace rv = ranges::views; #else #include +namespace rv = std::views; #endif #include "elements.hpp" @@ -25,29 +25,22 @@ int main() { Timer time; - Entity *wall_list[MAX_ROWS][MAX_COLS] = {}; - sf::Vector2i local_position; - sf::Vector2i start_mouse_pos; - sf::Vector2i end_mouse_pos; + std::array, MAX_ROWS> wall_list = {}; bool dragging = false; bool prev_dragging = false; int current_level = 0; - load_map(wall_list, ); + load_map(wall_list, levels[3].data); player_data player_data; Player player { player_data.size, player_data.pos, player_data.velocity, - player_data.border_size, GRAVITY, player_data.max_velocity_y, - player_data.dash_distance, sf::Color::Black, sf::Color::White }; + player_data.border_size, GRAVITY, player_data.max_velocity_y, + player_data.dash_distance, sf::Color::Black, sf::Color::White }; sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default); window.setFramerateLimit(FPS); -#ifdef __APPLE__ sf::Font font("/Users/andrew/personal/Projects/CPP/engine/assets/pixel.ttf"); -#else - sf::Font font("/home/andrew/personal/Projects/CPP/engine/assets/pixel.ttf"); -#endif sf::Text text(font, "0, 0", 16); text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5) }); @@ -55,10 +48,8 @@ int main() { bool running = true; std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); }); while (window.isOpen()) { - local_position = sf::Mouse::getPosition(window); window.clear(sf::Color::Black); - text.setString(std::to_string((int)std::floor(local_position.x / 32)) + ", " + - std::to_string((int)std::floor(local_position.y / 32))); + text.setString("Test"); while (const std::optional event = window.pollEvent()) { if (event->is()) { running = false; @@ -76,20 +67,19 @@ int main() { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { dragging = false; } - create_map(window, local_position, start_mouse_pos, end_mouse_pos, dragging, prev_dragging, wall_list); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) { clear_map(wall_list); if (current_level == 0) { - load_map(wall_list, test_level_1); + load_map(wall_list, levels[1].data); current_level = 1; player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; } else if (current_level == 1) { - load_map(wall_list, test_level_2); + load_map(wall_list, levels[2].data); current_level = 2; player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; } else if (current_level == 2) { - load_map(wall_list, test_level_0); + load_map(wall_list, levels[3].data); current_level = 0; player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; } @@ -117,25 +107,18 @@ int main() { std::cout << "Yes vertical bottom collision\n"; } -#ifdef __APPLE__ - for (auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), - ranges::views::iota(0, MAX_COLS))) { - if (wall_list[i][j] == nullptr) + for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { + if (wall_list[i][j] == nullptr) { continue; + } window.draw(wall_list[i][j]->rect); } -#else - for (auto [i, j] : - std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { - if (wall_list[i][j] == nullptr) - continue; - window.draw(wall_list[i][j]->rect); - } -#endif + window.draw(player.rect); window.draw(text); window.display(); } + clear_map(wall_list); player_dash_cooldown.join(); return 0; diff --git a/src/maps.cpp b/src/maps.cpp index 50827cf..ff4815e 100644 --- a/src/maps.cpp +++ b/src/maps.cpp @@ -14,7 +14,7 @@ namespace rv = ranges::views; namespace rv = std::views; #endif -void clear_map(std::array, MAX_ROWS> wall_list) { +void clear_map(std::array, MAX_ROWS>& wall_list) { for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { delete wall_list[i][j]; wall_list[i][j] = nullptr; @@ -23,8 +23,7 @@ void clear_map(std::array, MAX_ROWS> wall_list) { bool is_tiles_clear_x(std::array, MAX_ROWS> draw_list, int y_level, int start_x, int end_x) { for (int i : rv::iota(start_x, end_x)) { - if (draw_list[i][y_level] == ' ') - continue; + if (draw_list[i][y_level] == ' ') continue; return false; } return true; @@ -32,105 +31,15 @@ bool is_tiles_clear_x(std::array, MAX_ROWS> draw_list bool is_tiles_clear_y(std::array, MAX_ROWS> draw_list, int x_level, int start_y, int end_y) { for (int i : rv::iota(start_y, end_y)) { - if (draw_list[i][x_level] == ' ') - continue; + if (draw_list[i][x_level] == ' ') continue; return false; } return true; } -std::array, MAX_ROWS> create_map(sf::RenderWindow &window, sf::Vector2i &local_position, - sf::Vector2i &start_mouse_pos, sf::Vector2i &end_mouse_pos, - bool &dragging, bool &prev_dragging, - Entity *wall_list[MAX_ROWS][MAX_COLS]) { - std::array, MAX_ROWS> draw_list {}; - - for (auto &row : draw_list) { - row.fill(' '); - } - static bool vertical = false; - if (local_position.x > 0 && local_position.x < WIDTH && local_position.y > 0 && local_position.y < HEIGHT) { - if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && !dragging) { - dragging = true; - start_mouse_pos = local_position; - } - if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging) { - prev_dragging = true; - end_mouse_pos = local_position; - sf::RectangleShape rect; - if (end_mouse_pos.x - start_mouse_pos.x > end_mouse_pos.y - start_mouse_pos.y) { - rect.setSize({ (float)(end_mouse_pos.x - start_mouse_pos.x), 1.0f }); - rect.setPosition({ (float)start_mouse_pos.x, - (float)(std::floor(start_mouse_pos.y / 32) * TILESIZE + - ((float)TILESIZE / 2)) }); - vertical = false; - } else { - rect.setSize({ - 1.0f, - (float)(end_mouse_pos.y - start_mouse_pos.y), - }); - rect.setPosition({ (float)(std::floor(start_mouse_pos.x / 32) * TILESIZE + - ((float)TILESIZE / 2)), - (float)start_mouse_pos.y }); - vertical = true; - } - window.draw(rect); - } - if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging && prev_dragging) { - sf::Vector2i start_integers = { (int)std::floor(start_mouse_pos.x / 32), - (int)std::floor(start_mouse_pos.y / 32) }; - sf::Vector2i end_integers = { (int)std::floor(end_mouse_pos.x / 32), - (int)std::floor(end_mouse_pos.y / 32) }; - - if (!vertical) { - if (wall_list[start_integers.y][start_integers.x] == nullptr) { - wall_list[start_integers.y][start_integers.x] = - new Entity { { float(end_integers.x - start_integers.x + 1) * TILESIZE, - TILESIZE }, - { (float)(start_integers.x * TILESIZE), - (float)(start_integers.y * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black }; - draw_list[start_integers.y][start_integers.x] = '1'; - draw_list[end_integers.y][end_integers.x] = '2'; - for (int i : rv::iota(start_integers.x, end_integers.x)) { - draw_list[start_integers.y][i] = '-'; - } - } - } else if (vertical) { - if (wall_list[start_integers.y][start_integers.x] == nullptr) { - // if(is_tiles_clear_y(draw_list, start_integers.x, start_integers.y, - // end_integers.y)) { - wall_list[start_integers.y][start_integers.x] = new Entity { - { TILESIZE, float(end_integers.y - start_integers.y + 1) * TILESIZE }, - { (float)(start_integers.x * TILESIZE), - (float)(start_integers.y * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black - }; - draw_list[start_integers.y][start_integers.x] = '1'; - draw_list[end_integers.y][end_integers.x] = '2'; - for (int i : rv::iota(start_integers.y, end_integers.y)) { - draw_list[i][start_integers.x] = '|'; - } - // } - } - // } - prev_dragging = false; - dragging = false; - } - } - } - return draw_list; -} - -void load_map(std::array, MAX_ROWS> wall_list, - const std::array, MAX_ROWS> map_data) { +void load_map(std::array, MAX_ROWS>& wall_list, const char map_data[MAX_ROWS][MAX_COLS]) { for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { - if (map_data[i][j] == ' ') - continue; + if (map_data[i][j] == ' ') continue; if (map_data[i][j] == '0') { wall_list[i][j] = new Entity { { TILESIZE, TILESIZE }, { float(j * TILESIZE), float(i * TILESIZE) }, @@ -156,10 +65,8 @@ void load_map(std::array, MAX_ROWS> wall_list, } if (map_data[i][j] == '1' && map_data[i][j + 1] == '-') { int start = j, end = j; - while (end + 1 < MAX_COLS && map_data[i][end + 1] != '2') - end++; - if (map_data[i][end + 1] == '2') - end++; + while (end + 1 < MAX_COLS && map_data[i][end + 1] != '2') end++; + if (map_data[i][end + 1] == '2') end++; wall_list[i][j] = new Entity { { float(end - start + 1) * TILESIZE, TILESIZE }, { float(j * TILESIZE), float(i * TILESIZE) }, { 0, 0 }, @@ -168,10 +75,8 @@ void load_map(std::array, MAX_ROWS> wall_list, } if (map_data[i][j] == '1' && map_data[i + 1][j] == '|') { int start = i, end = i; - while (end + 1 < MAX_ROWS && map_data[end + 1][j] != '2') - end++; - if (map_data[end + 1][j] == '2') - end++; + while (end + 1 < MAX_ROWS && map_data[end + 1][j] != '2') end++; + if (map_data[end + 1][j] == '2') end++; wall_list[i][j] = new Entity { { TILESIZE, float(end - start + 1) * TILESIZE }, { float(j * TILESIZE), float(i * TILESIZE) }, { 0, 0 }, @@ -183,7 +88,8 @@ void load_map(std::array, MAX_ROWS> wall_list, Level levels[] = { { - .data = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + .data = { + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, @@ -197,55 +103,73 @@ Level levels[] = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, }, .name = "Empty" - }, - { - .data = { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, - { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, - { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, - { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, }, - .name = "Default" - }, - { - .data = { - { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, - { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, - { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, - { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, }, - .name = "1" - }, - { - .data = { - { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, - { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, - { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, - { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, - { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, - { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, - { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, - { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, - { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, - { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, - { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, - { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, - { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, }, - .name = "3" } }; +// Level levels[] = { +// { +// .data = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, +// {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, }, +// .name = "Empty" +// }, +// { +// .data = { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, +// { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, +// { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, +// { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, }, +// .name = "Default" +// }, +// { +// .data = { +// { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, +// { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, +// { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, +// { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, +// { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, }, +// .name = "1" +// }, +// { +// .data = { +// { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, +// { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, +// { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, +// { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, +// { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, +// { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, +// { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, +// { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, +// { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, +// { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, +// { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, +// { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, +// { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, }, +// .name = "3" +// } +// }; diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 0f3fcdf..01e6c93 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -4,7 +4,8 @@ #include #include -void Timer::update_timers(bool &running, Times ×) { + +void Timer::update_timers(bool& running, Times& times) { while (running) { std::this_thread::sleep_for(std::chrono::seconds(1)); times.dash_cooldown--;