Skip to content

Commit

Permalink
Merge dev into rb42
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Sep 27, 2023
2 parents b4ca35b + b650a41 commit 4ce68d8
Show file tree
Hide file tree
Showing 20 changed files with 597 additions and 384 deletions.
6 changes: 6 additions & 0 deletions src/Client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ target_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)

target_sources(
${PROJECT_NAME_CLIENT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/SceneManager.cpp
)

add_subdirectory(Systems)
add_subdirectory(Raylib)
add_subdirectory(EventManager)
111 changes: 111 additions & 0 deletions src/Client/SceneManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** SceneManager implementation
*/

#include "SceneManager.hpp"
#include "ClientSystems.hpp"
#include "Registry.hpp"
#include "SystemManagersDirector.hpp"
#include "Raylib.hpp"

// to suppr
#include "CustomTypes.hpp"

constexpr int screenWidth = 800;
constexpr int screenHeight = 600;

// to suppr
constexpr int playerData = 10;

// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
bool SceneManager::_init = false;
SceneManager SceneManager::_instance = SceneManager();
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)

static void initRaylib()
{
Raylib::initWindow(screenWidth, screenHeight, "R-Bus");
Raylib::setTargetFPS(Raylib::getMonitorRefreshRate(Raylib::getCurrentMonitor()));
Raylib::initAudioDevice();
Registry::getInstance().addEntity();
Registry::getInstance().getComponents<Types::Position>().back() = {
playerData,
playerData};
Registry::getInstance().getComponents<Types::RectangleShape>().back() = {
playerData,
playerData};
Registry::getInstance().getComponents<Types::CollisionRect>().back() = {
playerData,
playerData};
SparseArray<std::size_t> &playerId =
Registry::getInstance().getCustomSparseArray<std::size_t>(
CustomIndex::PLAYER);
playerId.add();
playerId.back() =
std::optional<std::size_t>(Registry::getInstance().getEntitiesNb() - 1);
}

static void initSystemManagers()
{
auto &director = Systems::SystemManagersDirector::getInstance();

for (auto systems : Systems::getSystemsGroups()) {
director.addSystemManager(systems);
}
initRaylib();
}

SceneManager &SceneManager::getInstance()
{
if (!_init) {
_init = true;
initSystemManagers();
}
return _instance;
}

SceneManager::SceneManager() : _currentScene(Scene::MAIN_GAME), _stop(false)
{
}

static void destroyRaylib()
{
Raylib::closeAudioDevice();
Raylib::closeWindow();
}

int SceneManager::run()
{
auto &director = Systems::SystemManagersDirector::getInstance();

try {
while (!_stop && !WindowShouldClose()) {
Raylib::beginDrawing();
Raylib::clearBackground(Raylib::DarkGray);
auto scene = _scenes.at(_currentScene);
for (auto &systemManager : scene) {
director.getSystemManager(systemManager).updateSystems();
}
Raylib::endDrawing();
}
destroyRaylib();
} catch (std::exception &e) {
std::cout << e.what() << std::endl;
return ReturnValue::ERROR;
}
return ReturnValue::OK;
}

void SceneManager::changeScene(Scene scene)
{
_currentScene = scene;
Registry::getInstance().clear();
}

void SceneManager::stop()
{
_stop = true;
}
43 changes: 43 additions & 0 deletions src/Client/SceneManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** SceneManager
*/

#pragma once

#include <array>
#include <cstddef>
#include <functional>
#include <optional>
#include <vector>

enum ReturnValue { OK = 0, ERROR = 84 };

enum Scene { MAIN_GAME, MENU, SCENE_MAX };

enum SystemManagers { GAME, EVENTS, DISPLAY, MANAGER_MAX };

class SceneManager {
public:
static SceneManager &getInstance();
int run();
void changeScene(Scene scene);
void stop();

private:
SceneManager();

Scene _currentScene;
bool _stop;
const std::array<std::vector<SystemManagers>, 2> _scenes = {
std::vector<SystemManagers> {EVENTS, GAME, DISPLAY},
std::vector<SystemManagers> {EVENTS, DISPLAY }
};

// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
static bool _init;
static SceneManager _instance;
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
};
3 changes: 3 additions & 0 deletions src/Client/Systems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ target_sources(
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/ClientSystems.cpp
)

add_subdirectory(Graphic)
add_subdirectory(Events)
Loading

0 comments on commit 4ce68d8

Please sign in to comment.