mirror of
https://github.com/zoriya/Bomberman.git
synced 2025-12-21 13:55:10 +00:00
Merge branch 'develop' into renderer
# Conflicts: # CMakeLists.txt # lib/wal/CMakeLists.txt # sources/Component/Movable/MovableComponent.cpp # sources/Component/Position/PositionComponent.cpp # sources/Component/Position/PositionComponent.hpp # sources/System/Movable/MovableSystem.cpp # sources/System/Movable/MovableSystem.hpp # sources/main.cpp
This commit is contained in:
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
run: |
|
||||
mkdir build && cd build
|
||||
cmake ..
|
||||
cmake --build . -t wal_tests
|
||||
cmake --build . -t unit_tests
|
||||
- name: Run tests
|
||||
run: |
|
||||
./build/lib/wal/wal_tests
|
||||
./build/unit_tests
|
||||
|
||||
@@ -10,18 +10,44 @@ include_directories(bomberman sources)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/wal)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray)
|
||||
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
sources/Component/Drawable/Drawable3DComponent.hpp
|
||||
sources/Component/Drawable/Drawable2DComponent.hpp
|
||||
sources/Component/Movable/MovableComponent.cpp
|
||||
sources/Component/Movable/MovableComponent.hpp
|
||||
sources/Component/Position/PositionComponent.cpp
|
||||
sources/Component/Position/PositionComponent.hpp
|
||||
sources/System/Movable/MovableSystem.cpp
|
||||
sources/System/Movable/MovableSystem.hpp
|
||||
sources/System/Renderer/Renderer3DSystem.hpp
|
||||
sources/System/Renderer/Renderer2DSystem.hpp
|
||||
)
|
||||
set(SOURCES
|
||||
sources/Models/GameState.hpp
|
||||
sources/Runner/Runner.cpp
|
||||
sources/Runner/Runner.hpp
|
||||
sources/Component/Position/PositionComponent.cpp
|
||||
sources/Component/Position/PositionComponent.hpp
|
||||
sources/Component/Movable/MovableComponent.cpp
|
||||
sources/Component/Movable/MovableComponent.hpp
|
||||
sources/System/Movable/MovableSystem.hpp
|
||||
sources/System/Movable/MovableSystem.cpp
|
||||
sources/Models/Vector3.hpp
|
||||
sources/Component/Drawable/Drawable3DComponent.hpp
|
||||
sources/Component/Drawable/Drawable2DComponent.hpp
|
||||
sources/System/Renderer/Renderer3DSystem.hpp
|
||||
sources/System/Renderer/Renderer2DSystem.hpp
|
||||
)
|
||||
|
||||
target_link_libraries(bomberman wal ray)
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
${SOURCES}
|
||||
)
|
||||
target_include_directories(bomberman PUBLIC sources)
|
||||
target_link_libraries(bomberman PUBLIC wal ray)
|
||||
|
||||
|
||||
add_executable(unit_tests EXCLUDE_FROM_ALL
|
||||
${SOURCES}
|
||||
tests/EntityTests.cpp
|
||||
tests/MainTest.cpp
|
||||
tests/EngineTests.cpp
|
||||
tests/CallbackTest.cpp
|
||||
)
|
||||
target_include_directories(unit_tests PUBLIC sources)
|
||||
target_link_libraries(unit_tests PUBLIC wal ray)
|
||||
|
||||
find_package(Catch2 QUIET)
|
||||
if (NOT Catch2_FOUND)
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/lib/catch2)
|
||||
find_package(Catch2 REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(unit_tests PRIVATE Catch2::Catch2)
|
||||
|
||||
@@ -4,37 +4,19 @@ project(wal)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_library(wal
|
||||
sources/Entity/Entity.hpp
|
||||
sources/Component/Component.hpp
|
||||
sources/System/System.hpp
|
||||
sources/Wal.cpp
|
||||
sources/Wal.hpp
|
||||
sources/Scene/Scene.cpp
|
||||
sources/Scene/Scene.hpp
|
||||
sources/Exception/WalError.cpp
|
||||
sources/Exception/WalError.hpp
|
||||
sources/Entity/Entity.cpp
|
||||
sources/Component/Component.cpp
|
||||
sources/Models/Vector3.hpp
|
||||
sources/System/System.cpp
|
||||
sources/Models/Callback.hpp
|
||||
)
|
||||
|
||||
target_include_directories(wal PUBLIC sources)
|
||||
|
||||
add_executable(wal_tests EXCLUDE_FROM_ALL
|
||||
tests/EntityTests.cpp
|
||||
tests/MainTest.cpp
|
||||
tests/EngineTests.cpp
|
||||
tests/CallbackTest.cpp
|
||||
sources/Entity/Entity.hpp
|
||||
sources/Component/Component.hpp
|
||||
sources/System/System.hpp
|
||||
sources/Wal.cpp
|
||||
sources/Wal.hpp
|
||||
sources/Scene/Scene.cpp
|
||||
sources/Scene/Scene.hpp
|
||||
sources/Exception/WalError.cpp
|
||||
sources/Exception/WalError.hpp
|
||||
sources/Entity/Entity.cpp
|
||||
sources/Component/Component.cpp
|
||||
sources/System/System.cpp
|
||||
sources/Models/Callback.hpp
|
||||
)
|
||||
|
||||
target_link_libraries(wal_tests PRIVATE wal)
|
||||
|
||||
find_package(Catch2 QUIET)
|
||||
if (NOT Catch2_FOUND)
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../catch2)
|
||||
find_package(Catch2 REQUIRED)
|
||||
endif()
|
||||
|
||||
target_link_libraries(wal_tests PRIVATE Catch2::Catch2)
|
||||
target_include_directories(wal PUBLIC sources)
|
||||
@@ -52,5 +52,11 @@ namespace WAL
|
||||
~Callback() = default;
|
||||
//! @brief A default assignment operator
|
||||
Callback &operator=(const Callback &) = default;
|
||||
|
||||
//! @brief Implicitly transform a function into a callback.
|
||||
Callback(std::function<void (Types...)> callback) // NOLINT(google-explicit-constructor)
|
||||
{
|
||||
this->addCallback(callback);
|
||||
}
|
||||
};
|
||||
} // namespace WAL
|
||||
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// Created by Zoe Roux on 2021-05-14.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <queue>
|
||||
#include "Scene/Scene.hpp"
|
||||
|
||||
namespace WAL
|
||||
{
|
||||
//! @brief A class to manage scenes
|
||||
class SceneManager
|
||||
{
|
||||
private:
|
||||
std::deque<Scene> _scenes = {};
|
||||
public:
|
||||
//! @brief Add a scene to the container and move to it.
|
||||
//! @return The manager instance used to call this function is returned. This allow method chaining.
|
||||
SceneManager &addScene(Scene &&scene);
|
||||
|
||||
//! @brief Add a scene before the current scene. This could be useful for lobbies or scene where the next scene can be constructed.
|
||||
//! @return The manager instance used to call this function is returned. This allow method chaining.
|
||||
SceneManager &addBackScene(Scene &&scene);
|
||||
|
||||
//! @brief Get the current scene
|
||||
Scene &getCurrent();
|
||||
|
||||
//! @brief Remove the current scene and switch to the previous scene on the stack.
|
||||
//! @return The manager instance used to call this function is returned. This allow method chaining.
|
||||
SceneManager &closeCurrent();
|
||||
|
||||
//! @brief A default constructor
|
||||
SceneManager() = default;
|
||||
//! @brief A scene manager is copy constructable
|
||||
SceneManager(const SceneManager &) = default;
|
||||
//! @brief A default destructor.
|
||||
~SceneManager() = default;
|
||||
//! @brief A scene manager is assignable
|
||||
SceneManager &operator=(const SceneManager &) = default;
|
||||
};
|
||||
}
|
||||
@@ -10,25 +10,6 @@ namespace WAL
|
||||
{
|
||||
std::chrono::nanoseconds Wal::timestep = std::chrono::milliseconds(8);
|
||||
|
||||
void Wal::run()
|
||||
{
|
||||
auto lastTick = std::chrono::steady_clock::now();
|
||||
std::chrono::nanoseconds fBehind(0);
|
||||
|
||||
while (!this->_shouldClose) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
std::chrono::nanoseconds dtime = now - lastTick;
|
||||
fBehind += dtime;
|
||||
lastTick = now;
|
||||
|
||||
while (fBehind > Wal::timestep) {
|
||||
fBehind -= Wal::timestep;
|
||||
this->_fixedUpdate();
|
||||
}
|
||||
this->_update(dtime);
|
||||
}
|
||||
}
|
||||
|
||||
void Wal::_update(std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &entities = this->_scene.getEntities();
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <typeinfo>
|
||||
#include <Exception/WalError.hpp>
|
||||
#include "Exception/WalError.hpp"
|
||||
#include "Scene/Scene.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "System/System.hpp"
|
||||
#include "Models/Callback.hpp"
|
||||
|
||||
namespace WAL
|
||||
{
|
||||
@@ -101,7 +102,40 @@ namespace WAL
|
||||
}
|
||||
|
||||
//! @brief Start the game loop
|
||||
void run();
|
||||
//! @param callback A callback called after each update of the game. It allow you to update the engine based on a specific game state. (you can also update the game state here)
|
||||
//! @param state An initial game state. If not specified, it will be defaulted.
|
||||
//! @tparam T A type used to track your game state. It must be default constructable.
|
||||
template<typename T>
|
||||
void run(const std::function<void (Wal &, T &)> &callback, T state = T())
|
||||
{
|
||||
Callback<Wal &, T &> update(callback);
|
||||
return this->run(update, state);
|
||||
}
|
||||
|
||||
//! @brief Start the game loop
|
||||
//! @param callback A callback called after each update of the game. It allow you to update the engine based on a specific game state. (you can also update the game state here)
|
||||
//! @param state An initial game state. If not specified, it will be defaulted.
|
||||
//! @tparam T A type used to track your game state. It must be default constructable.
|
||||
template<typename T>
|
||||
void run(const Callback<Wal &, T &> &callback, T state = T())
|
||||
{
|
||||
auto lastTick = std::chrono::steady_clock::now();
|
||||
std::chrono::nanoseconds fBehind(0);
|
||||
|
||||
while (!this->_shouldClose) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
std::chrono::nanoseconds dtime = now - lastTick;
|
||||
fBehind += dtime;
|
||||
lastTick = now;
|
||||
|
||||
while (fBehind > Wal::timestep) {
|
||||
fBehind -= Wal::timestep;
|
||||
this->_fixedUpdate();
|
||||
}
|
||||
this->_update(dtime);
|
||||
callback(*this, state);
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief A default constructor
|
||||
Wal() = default;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/17/21.
|
||||
//
|
||||
|
||||
#include "MovableComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
MovableComponent::MovableComponent(WAL::Entity &entity)
|
||||
: Component(entity)
|
||||
{}
|
||||
|
||||
WAL::Component *MovableComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new MovableComponent(entity);
|
||||
}
|
||||
|
||||
void MovableComponent::addForce(WAL::Vector3f force)
|
||||
{
|
||||
this->_acceleration += force;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/17/21.
|
||||
//
|
||||
|
||||
#include "PositionComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Component/Component.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
PositionComponent::PositionComponent(WAL::Entity &entity)
|
||||
: WAL::Component(entity),
|
||||
position()
|
||||
{}
|
||||
|
||||
PositionComponent::PositionComponent(WAL::Entity &entity, WAL::Vector3f pos)
|
||||
: WAL::Component(entity),
|
||||
position(pos)
|
||||
{}
|
||||
|
||||
PositionComponent::PositionComponent(WAL::Entity &entity, float x, float y, float z)
|
||||
: WAL::Component(entity),
|
||||
position(x, y, z)
|
||||
{}
|
||||
|
||||
WAL::Component *PositionComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new PositionComponent(entity, this->position);
|
||||
}
|
||||
|
||||
float PositionComponent::getX() const
|
||||
{
|
||||
return this->position.x;
|
||||
}
|
||||
|
||||
float PositionComponent::getY() const
|
||||
{
|
||||
return this->position.y;
|
||||
}
|
||||
|
||||
float PositionComponent::getZ() const
|
||||
{
|
||||
return this->position.z;
|
||||
}
|
||||
}
|
||||
31
sources/Models/GameState.hpp
Normal file
31
sources/Models/GameState.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <Scene/Scene.hpp>
|
||||
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A class representing the current game state. This allow one to retain information between update calls.
|
||||
class GameState
|
||||
{
|
||||
//! @brief The list of scenes available.
|
||||
enum SceneID
|
||||
{
|
||||
MainMenu,
|
||||
GameScene
|
||||
};
|
||||
|
||||
|
||||
//! @brief The currently loaded scene
|
||||
SceneID currentScene = MainMenu;
|
||||
|
||||
//! @brief The list of loaded scenes.
|
||||
std::unordered_map<SceneID, WAL::Scene> _loadedScenes = {};
|
||||
};
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
namespace WAL
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A Vector3 data type. (templated to allow any kind of vector3)
|
||||
template<typename T>
|
||||
@@ -160,7 +160,7 @@ namespace WAL
|
||||
} // namespace WAL
|
||||
|
||||
template<typename T>
|
||||
std::ostream &operator<<(std::ostream &s, const WAL::Vector3<T> &v)
|
||||
std::ostream &operator<<(std::ostream &s, const BBM::Vector3<T> &v)
|
||||
{
|
||||
s << "Vector3<" << typeid(T).name() << ">("<< v.x << ", " << v.y << ", " << v.z << ")";
|
||||
return s;
|
||||
32
sources/Runner/Runner.cpp
Normal file
32
sources/Runner/Runner.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
#include <Wal.hpp>
|
||||
#include <iostream>
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
void updateState(WAL::Wal &engine, GameState &state)
|
||||
{
|
||||
// You can change the scene here or update the game state based on entities values.
|
||||
|
||||
// If you want to keep a scene loaded but not running, store it in the state.loadedScenes.
|
||||
// If you don't need the scene anymore, remember to remove it from the loadedScene array.
|
||||
}
|
||||
|
||||
int run()
|
||||
{
|
||||
WAL::Wal wal;
|
||||
|
||||
try {
|
||||
wal.run<GameState>(updateState);
|
||||
return 0;
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << ex.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
sources/Runner/Runner.hpp
Normal file
12
sources/Runner/Runner.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/24/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief Start the game and run a Bomberman.
|
||||
//! @return 0 on success, another value on error.
|
||||
int run();
|
||||
}
|
||||
@@ -6,7 +6,10 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "Wal.hpp"
|
||||
#include <iostream>
|
||||
#include "Runner/Runner.hpp"
|
||||
|
||||
// Dependencies of the demo
|
||||
#include "Camera/Camera3D.hpp"
|
||||
#include "Controllers/Keyboard.hpp"
|
||||
#include "Drawables/2D/Text.hpp"
|
||||
@@ -35,7 +38,7 @@ std::string get_full_path(const std::string &color)
|
||||
return path;
|
||||
}
|
||||
|
||||
int main()
|
||||
int demo()
|
||||
{
|
||||
WAL::Wal wal;
|
||||
const int screenWidth = 800;
|
||||
@@ -50,10 +53,10 @@ int main()
|
||||
window.setIcon(icon);
|
||||
RAY::Model model(modelPath);
|
||||
RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f),
|
||||
RAY::Vector3(0.0f, 0.0f, 0.0f),
|
||||
RAY::Vector3(0.0f, 1.0f, 0.0f),
|
||||
45.0f, CAMERA_PERSPECTIVE
|
||||
);
|
||||
RAY::Vector3(0.0f, 0.0f, 0.0f),
|
||||
RAY::Vector3(0.0f, 1.0f, 0.0f),
|
||||
45.0f, CAMERA_PERSPECTIVE
|
||||
);
|
||||
WAL::Entity entityPlayer("roger");
|
||||
RAY::Drawables::Drawables3D::Circle circle({300, 300, 300}, 50, 0XFFFFFFF, {0, 0, 0}, 0);
|
||||
BBM::Drawable3DComponent<RAY::Drawables::Drawables3D::Circle> circleComponent(entityPlayer, circle);
|
||||
@@ -105,3 +108,22 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void usage(const std::string &bin)
|
||||
{
|
||||
std::cout << "Bomberman." << std::endl
|
||||
<< "\tUsage: " << bin << " [options]" << std::endl
|
||||
<< "Options:" << std::endl
|
||||
<< "\t-h:\tPrint this help message" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 2 && std::string(argv[1]) == "-h") {
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
return demo();
|
||||
return BBM::run();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
using namespace BBM;
|
||||
using namespace WAL;
|
||||
using namespace BBM;
|
||||
|
||||
TEST_CASE("Component", "[Entity]")
|
||||
{
|
||||
Reference in New Issue
Block a user