From db51c6369affbabcab7547c1fb2b43048933dadb Mon Sep 17 00:00:00 2001 From: Crizomb Date: Thu, 12 Jun 2025 09:19:04 +0200 Subject: [PATCH] delete src_original --- SimpleGame/CMakeLists.txt | 1 - SimpleGame/src_original/CMakeLists.txt | 13 --- SimpleGame/src_original/Include/Game.hpp | 38 ------- .../src_original/Include/StringHelpers.hpp | 11 --- .../src_original/Include/StringHelpers.inl | 6 -- SimpleGame/src_original/Source/Game.cpp | 99 ------------------- SimpleGame/src_original/Source/Main.cpp | 6 -- 7 files changed, 174 deletions(-) delete mode 100644 SimpleGame/src_original/CMakeLists.txt delete mode 100644 SimpleGame/src_original/Include/Game.hpp delete mode 100644 SimpleGame/src_original/Include/StringHelpers.hpp delete mode 100644 SimpleGame/src_original/Include/StringHelpers.inl delete mode 100644 SimpleGame/src_original/Source/Game.cpp delete mode 100644 SimpleGame/src_original/Source/Main.cpp diff --git a/SimpleGame/CMakeLists.txt b/SimpleGame/CMakeLists.txt index 64f8408..a67f88a 100644 --- a/SimpleGame/CMakeLists.txt +++ b/SimpleGame/CMakeLists.txt @@ -18,6 +18,5 @@ FetchContent_MakeAvailable(sfml) set(CMAKE_CXX_STANDARD 23) -add_subdirectory(src_original) add_subdirectory(src) diff --git a/SimpleGame/src_original/CMakeLists.txt b/SimpleGame/src_original/CMakeLists.txt deleted file mode 100644 index d151490..0000000 --- a/SimpleGame/src_original/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_executable(simpleGameOriginal - Source/Game.cpp Source/Main.cpp - ) - -target_include_directories(simpleGameOriginal - PRIVATE - Include -) - -target_link_libraries(simpleGameOriginal PUBLIC sfml-graphics) - -# The following command is executed only when cmake is executed -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../media DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) \ No newline at end of file diff --git a/SimpleGame/src_original/Include/Game.hpp b/SimpleGame/src_original/Include/Game.hpp deleted file mode 100644 index c4390cd..0000000 --- a/SimpleGame/src_original/Include/Game.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef BOOK_GAME_HPP -#define BOOK_GAME_HPP - -#include - -class Game { -public: - Game(); - Game(const Game &) = delete; - Game &operator=(const Game &) = delete; - void run(); - -private: - void processEvents(); - void update(sf::Time elapsedTime); - void render(); - - void updateStatistics(sf::Time elapsedTime); - void handlePlayerInput(sf::Keyboard::Key key, bool isPressed); - - static const float PlayerSpeed; - static const sf::Time TimePerFrame; - - sf::RenderWindow mWindow{sf::VideoMode({640, 480}), "SFML Application"}; - sf::Texture mTexture; - sf::CircleShape mTarget; - sf::Font mFont; - sf::Text mStatisticsText{mFont}; - sf::Time mStatisticsUpdateTime; - - std::size_t mStatisticsNumFrames{0}; - bool mIsMovingUp{false}; - bool mIsMovingDown{false}; - bool mIsMovingRight{false}; - bool mIsMovingLeft{false}; -}; - -#endif // BOOK_GAME_HPP diff --git a/SimpleGame/src_original/Include/StringHelpers.hpp b/SimpleGame/src_original/Include/StringHelpers.hpp deleted file mode 100644 index d3ecd27..0000000 --- a/SimpleGame/src_original/Include/StringHelpers.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef BOOK_STRINGHELPERS_HPP -#define BOOK_STRINGHELPERS_HPP - -#include - -// Since std::to_string doesn't work on MinGW we have to implement -// our own to support all platforms. -template std::string toString(const T &value); - -#include "StringHelpers.inl" -#endif // BOOK_STRINGHELPERS_HPP diff --git a/SimpleGame/src_original/Include/StringHelpers.inl b/SimpleGame/src_original/Include/StringHelpers.inl deleted file mode 100644 index ce1b36d..0000000 --- a/SimpleGame/src_original/Include/StringHelpers.inl +++ /dev/null @@ -1,6 +0,0 @@ - -template std::string toString(const T &value) { - std::stringstream stream; - stream << value; - return stream.str(); -} diff --git a/SimpleGame/src_original/Source/Game.cpp b/SimpleGame/src_original/Source/Game.cpp deleted file mode 100644 index 34cdda1..0000000 --- a/SimpleGame/src_original/Source/Game.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "Game.hpp" -#include "StringHelpers.hpp" - -const float Game::PlayerSpeed = 100.f; -const sf::Time Game::TimePerFrame = sf::seconds(1.f / 60.f); - -Game::Game() { - mTarget.setRadius(50.f); - mTarget.setFillColor(sf::Color::Cyan); - mTarget.setPosition({100.f, 100.f}); - - assert(mFont.openFromFile("media/Sansation.ttf")); - // We do not need to do mStatisticsText.setFont(mFont); as mStatisticsText is - // initialized with a reference to mFont - mStatisticsText.setPosition({5.f, 5.f}); - mStatisticsText.setCharacterSize(10); -} - -void Game::run() { - sf::Clock clock; - sf::Time timeSinceLastUpdate = sf::Time::Zero; - while (mWindow.isOpen()) { - sf::Time elapsedTime = clock.restart(); - timeSinceLastUpdate += elapsedTime; - while (timeSinceLastUpdate > TimePerFrame) { - timeSinceLastUpdate -= TimePerFrame; - - processEvents(); - update(TimePerFrame); - } - - updateStatistics(elapsedTime); - render(); - } -} - -void Game::processEvents() { - while (const std::optional event = mWindow.pollEvent()) { - if (const auto *keyPressed = event->getIf()) { - handlePlayerInput(keyPressed->code, true); - } else if (const auto *keyReleased = - event->getIf()) { - handlePlayerInput(keyReleased->code, false); - } else if (event->is()) { - mWindow.close(); - } - } -} - -void Game::update(sf::Time elapsedTime) { - sf::Vector2f movement(0.f, 0.f); - if (mIsMovingUp) - movement.y -= PlayerSpeed; - if (mIsMovingDown) - movement.y += PlayerSpeed; - if (mIsMovingLeft) - movement.x -= PlayerSpeed; - if (mIsMovingRight) - movement.x += PlayerSpeed; - - mTarget.move(movement * elapsedTime.asSeconds()); -} - -void Game::render() { - mWindow.clear(); - mWindow.draw(mTarget); - mWindow.draw(mStatisticsText); - mWindow.display(); -} - -void Game::updateStatistics(const sf::Time elapsedTime) { - mStatisticsUpdateTime += elapsedTime; - mStatisticsNumFrames += 1; - - if (mStatisticsUpdateTime >= sf::seconds(1.0f)) { - mStatisticsText.setString( - "Frames / Second = " + toString(mStatisticsNumFrames) + "\n" + - "Time / Update = " + - toString(mStatisticsUpdateTime.asMicroseconds() / - mStatisticsNumFrames) + - " us"); - - mStatisticsUpdateTime -= sf::seconds(1.0f); - mStatisticsNumFrames = 0; - } -} - -void Game::handlePlayerInput(const sf::Keyboard::Key key, - const bool isPressed) { - using enum sf::Keyboard::Key; - if (key == Z) - mIsMovingUp = isPressed; - else if (key == S) - mIsMovingDown = isPressed; - else if (key == Q) - mIsMovingLeft = isPressed; - else if (key == D) - mIsMovingRight = isPressed; -} diff --git a/SimpleGame/src_original/Source/Main.cpp b/SimpleGame/src_original/Source/Main.cpp deleted file mode 100644 index e0c0f03..0000000 --- a/SimpleGame/src_original/Source/Main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Game.hpp" - -int main() { - Game game; - game.run(); -}