From be0a737fd1ced15bf3335b7c103dcf39a52a40ad Mon Sep 17 00:00:00 2001 From: Roman Sztergbaum Date: Sun, 13 Oct 2019 12:37:24 +0200 Subject: [PATCH] feat(tic-tac-toe): remove all sfml stuffs to use generics one --- examples/sfml/tic-tac-toe/game.scene.cpp | 38 ++++++++++++------- .../sfml/tic-tac-toe/tic.tac.toe.factory.cpp | 12 +++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/examples/sfml/tic-tac-toe/game.scene.cpp b/examples/sfml/tic-tac-toe/game.scene.cpp index 420a1e13..8b0aa3b3 100644 --- a/examples/sfml/tic-tac-toe/game.scene.cpp +++ b/examples/sfml/tic-tac-toe/game.scene.cpp @@ -14,15 +14,18 @@ * * ******************************************************************************/ -#include #include #include #include +#include +#include #include "tic.tac.toe.constants.hpp" #include "tic.tac.toe.components.hpp" #include "tic.tac.toe.factory.hpp" #include "game.scene.hpp" +using namespace antara::gaming; + namespace tictactoe::example { game_scene::game_scene(entt::registry &entity_registry) noexcept : base_scene(entity_registry) @@ -89,20 +92,26 @@ namespace tictactoe::example }; if (player_as_win_functor()) { this->current_state_ = static_cast(this->player_turn_); - this->entity_registry_.view>().less( - [this](entt::entity entity, antara::gaming::geometry::vertex_array &array_cmp) { - for (auto&& current_vertex : array_cmp.vertices) { - current_vertex.pixel_color = this->player_turn_ == player::x ? antara::gaming::graphics::magenta : antara::gaming::graphics::cyan; + this->entity_registry_.view>().less( + [this](entt::entity entity, geometry::vertex_array &array_cmp) { + for (auto &¤t_vertex : array_cmp.vertices) { + current_vertex.pixel_color = + this->player_turn_ == player::x ? graphics::magenta + : graphics::cyan; } - this->entity_registry_.assign_or_replace(entity, array_cmp.vertices, array_cmp.geometry_type); + this->entity_registry_.assign_or_replace(entity, + array_cmp.vertices, + array_cmp.geometry_type); }); } else if (tie_functor()) { - this->entity_registry_.view>().less( - [this](entt::entity entity, antara::gaming::geometry::vertex_array &array_cmp) { - for (auto&& current_vertex : array_cmp.vertices) { - current_vertex.pixel_color = antara::gaming::graphics::yellow; + this->entity_registry_.view>().less( + [this](entt::entity entity, geometry::vertex_array &array_cmp) { + for (auto &¤t_vertex : array_cmp.vertices) { + current_vertex.pixel_color = graphics::yellow; } - this->entity_registry_.assign_or_replace(entity, array_cmp.vertices, array_cmp.geometry_type); + this->entity_registry_.assign_or_replace(entity, + array_cmp.vertices, + array_cmp.geometry_type); }); this->current_state_ = game_state::tie; } @@ -134,7 +143,7 @@ namespace tictactoe::example } } - bool game_scene::on_mouse_button_pressed(const antara::gaming::event::mouse_button_pressed &pressed) noexcept + bool game_scene::on_mouse_button_pressed(const event::mouse_button_pressed &pressed) noexcept { if (this->current_state_ == game_state::running) { auto constants = entity_registry_.ctx(); @@ -167,7 +176,8 @@ namespace tictactoe::example void game_scene::prepare_constants() noexcept { - auto canvas_size = this->entity_registry_.ctx().getSize(); - this->entity_registry_.set(3ull, canvas_size.x, canvas_size.y); + auto[canvas_width, canvas_height] = this->entity_registry_.ctx().canvas.size.to(); + + this->entity_registry_.set(3ull, canvas_width, canvas_height); } } \ No newline at end of file diff --git a/examples/sfml/tic-tac-toe/tic.tac.toe.factory.cpp b/examples/sfml/tic-tac-toe/tic.tac.toe.factory.cpp index f6a4f251..63af6008 100644 --- a/examples/sfml/tic-tac-toe/tic.tac.toe.factory.cpp +++ b/examples/sfml/tic-tac-toe/tic.tac.toe.factory.cpp @@ -15,13 +15,13 @@ ******************************************************************************/ #include -#include #include #include #include #include #include #include +#include #include "tic.tac.toe.factory.hpp" #include "tic.tac.toe.constants.hpp" #include "tic.tac.toe.components.hpp" @@ -34,7 +34,7 @@ namespace tictactoe ::example entt::entity tic_tac_toe_factory::create_grid_entity(entt::registry &entity_registry) noexcept { - auto window_info = entity_registry.ctx().getSize(); + auto [canvas_width, canvas_height] = entity_registry.ctx().canvas.size; auto grid_entity = entity_registry.create(); std::vector lines{8 * 4}; @@ -58,13 +58,13 @@ namespace tictactoe ::example // Vertical lines[counter].pos = {offset_x + i * constants.cell_width - half_thickness, 0.f}; lines[counter + 1].pos = {offset_x + i * constants.cell_width + half_thickness, 0.f}; - lines[counter + 2].pos = {offset_x + i * constants.cell_width + half_thickness, static_cast(window_info.y)}; - lines[counter + 3].pos = {offset_x + i * constants.cell_width - half_thickness, static_cast(window_info.y)}; + lines[counter + 2].pos = {offset_x + i * constants.cell_width + half_thickness, canvas_height}; + lines[counter + 3].pos = {offset_x + i * constants.cell_width - half_thickness, canvas_height}; // Horizontal lines[counter + 4].pos = {offset_x + 0, offset_y + i * constants.cell_height - half_thickness}; - lines[counter + 5].pos = {offset_x + window_info.x, offset_y + i * constants.cell_height - half_thickness}; - lines[counter + 6].pos = {offset_x + window_info.x, offset_y + i * constants.cell_height + half_thickness}; + lines[counter + 5].pos = {offset_x + canvas_width, offset_y + i * constants.cell_height - half_thickness}; + lines[counter + 6].pos = {offset_x + canvas_width, offset_y + i * constants.cell_height + half_thickness}; lines[counter + 7].pos = {offset_x + 0, offset_y + i * constants.cell_height + half_thickness}; }