-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
597 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.