Skip to content

Commit

Permalink
BLUGA-GRAPHICS: Change class
Browse files Browse the repository at this point in the history
MINOR
  • Loading branch information
Saverio976 committed Nov 3, 2023
1 parent 7789578 commit 636a521
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 356 deletions.
56 changes: 28 additions & 28 deletions libs/B-luga-graphics/include/B-luga-graphics/AudioSystems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@

namespace Systems {
namespace GraphicsSystems {
void soundEffectPlayer(std::size_t /*unused*/, std::size_t /*unused*/)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry::components<Raylib::SoundShared> arrSoundEffect =
Registry::getInstance().getComponents<Raylib::SoundShared>();

for (auto &soundEffect : arrSoundEffect) {
if (soundEffect->NeedToPlay() && !soundEffect->isPlaying()) {
soundEffect->play();
soundEffect->setNeedToPlay(false);
}
}
}
void musicPlayer(std::size_t /*unused*/, std::size_t /*unused*/)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry::components<Raylib::MusicShared> arrMusics =
Registry::getInstance().getComponents<Raylib::MusicShared>();
class AudioSystems {
public:
static void soundEffectPlayer(std::size_t /*unused*/, std::size_t /*unused*/)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry::components<Raylib::SoundShared> arrSoundEffect =
Registry::getInstance().getComponents<Raylib::SoundShared>();

for (auto &music : arrMusics) {
if (music->NeedToPlay()) {
music->play();
music->setNeedToPlay(false);
}
if (music->isPlaying()) {
music->update();
for (auto &soundEffect : arrSoundEffect) {
if (soundEffect->NeedToPlay() && !soundEffect->isPlaying()) {
soundEffect->play();
soundEffect->setNeedToPlay(false);
}
}
}
}
}
static void musicPlayer(std::size_t /*unused*/, std::size_t /*unused*/)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry::components<Raylib::MusicShared> arrMusics =
Registry::getInstance().getComponents<Raylib::MusicShared>();

class AudioSystems {
public:
for (auto &music : arrMusics) {
if (music->NeedToPlay()) {
music->play();
music->setNeedToPlay(false);
}
if (music->isPlaying()) {
music->update();
}
}
}
static std::vector<std::function<void(std::size_t, std::size_t)>> getAudioSystems()
{
return { soundEffectPlayer, musicPlayer };
Expand Down
65 changes: 33 additions & 32 deletions libs/B-luga-graphics/include/B-luga-graphics/GraphicsSystems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,46 @@

namespace Systems::GraphicsSystems {

static void startLoopRaylib(std::size_t /*unused*/)
{
Raylib::Drawing::beginDrawing();
Raylib::Drawing::clearBackground(Raylib::DarkGray);
}

static constexpr int screenWidth = 1920;
static constexpr int screenHeight = 1080;

static void beforeLoopRaylib(std::size_t /*unused*/)
{
Raylib::Window::initWindow(screenWidth, screenHeight, "R-Bus");
Raylib::Window::setWindowState(Raylib::ConfigFlags::WINDOW_RESIZABLE);
Raylib::Frame::setTargetFPS(Raylib::Window::getMonitorRefreshRate(Raylib::Window::getCurrentMonitor()));
Raylib::Audio::initAudioDevice();
}

static void endLoopRaylib(std::size_t /*unused*/)
class GraphicsPlugin : public IPlugin
{
Raylib::Drawing::endDrawing();
}
public:
static void startLoopRaylib(std::size_t /*unused*/)
{
Raylib::Drawing::beginDrawing();
Raylib::Drawing::clearBackground(Raylib::DarkGray);
}

static void afterLoopRaylib(std::size_t /*unused*/)
{
Raylib::Audio::closeAudioDevice();
Raylib::Window::closeWindow();
Raylib::TextureManager::getInstance().unloadTextures();
}
static void beforeLoopRaylib(std::size_t /*unused*/)
{
Raylib::Window::initWindow(screenWidth, screenHeight, "R-Bus");
Raylib::Window::setWindowState(Raylib::ConfigFlags::WINDOW_RESIZABLE);
Raylib::Frame::setTargetFPS(Raylib::Window::getMonitorRefreshRate(Raylib::Window::getCurrentMonitor()));
Raylib::Audio::initAudioDevice();
}

static void checkRaylibStop(std::size_t /*unused*/, std::size_t /*unused*/)
{
if (Raylib::Window::windowShouldClose()) {
Scene::SceneManager::getInstance().stop();
}
}
static void endLoopRaylib(std::size_t /*unused*/)
{
Raylib::Drawing::endDrawing();
}

class GraphicsPlugin : public IPlugin
{
public:
static void afterLoopRaylib(std::size_t /*unused*/)
{
Raylib::Audio::closeAudioDevice();
Raylib::Window::closeWindow();
Raylib::TextureManager::getInstance().unloadTextures();
}

static void checkRaylibStop(std::size_t /*unused*/, std::size_t /*unused*/)
{
if (Raylib::Window::windowShouldClose()) {
Scene::SceneManager::getInstance().stop();
}
}
void initPlugin() override
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Expand All @@ -75,8 +76,8 @@ namespace Systems::GraphicsSystems {
checkRaylibStop
};
std::vector<std::function<void(std::size_t, std::size_t)>> audioSystems = AudioSystems::getAudioSystems();
std::vector<std::function<void(std::size_t, std::size_t)>> spriteSystems = getSpriteSystems();
std::vector<std::function<void(std::size_t, std::size_t)>> textSystems = getTextSystems();
std::vector<std::function<void(std::size_t, std::size_t)>> spriteSystems = SpriteSystems::getSpriteSystems();
std::vector<std::function<void(std::size_t, std::size_t)>> textSystems = TextSystems::getTextSystems();
std::vector<std::function<void(std::size_t, std::size_t)>> parallaxSystems =
ParallaxSystems::getParallaxSystems();

Expand Down
82 changes: 43 additions & 39 deletions libs/B-luga-graphics/include/B-luga-graphics/ParallaxSystems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,47 @@
#include "B-luga/SystemManagers/SystemManagersDirector.hpp"
#include "B-luga-physics/ECSCustomTypes.hpp"

namespace Systems::ParallaxSystems {

constexpr int maxOutParallaxLeft = -100;
constexpr int maxOutParallaxRight = 100;

static void resetParallaxPosition(
std::size_t id,
Registry::components<Types::Parallax> &arrParallax,
Registry::components<Types::Position> &arrPosition)
{
if (Maths::intToFloatConservingDecimals(arrPosition[id].x) <= maxOutParallaxLeft) {
Maths::addNormalIntToDecimalInt(arrPosition[id].x, maxOutParallaxRight * 2);
arrPosition[id].y = Maths::floatToIntConservingDecimals(arrParallax[id].y);
}
}

void manageParallax(std::size_t /*unused*/, std::size_t /*unused*/)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry::components<Types::Position> arrPosition =
Registry::getInstance().getComponents<Types::Position>();
Registry::components<Types::Parallax> arrParallax =
Registry::getInstance().getComponents<Types::Parallax>();

std::vector<std::size_t> ids = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::Position), typeid(Types::Parallax), typeid(Types::Velocity)});

for (auto &id : ids) {
resetParallaxPosition(id, arrParallax, arrPosition);
}
}


std::vector<std::function<void(std::size_t, std::size_t)>> getParallaxSystems()
{
return {
manageParallax,
};
}
namespace Systems::GraphicsSystems {

static constexpr int maxOutParallaxLeft = -100;
static constexpr int maxOutParallaxRight = 100;



class ParallaxSystems {
public:
static std::vector<std::function<void(std::size_t, std::size_t)>> getParallaxSystems()
{
return {
manageParallax,
};
}

static void resetParallaxPosition(
std::size_t id,
Registry::components<Types::Parallax> &arrParallax,
Registry::components<Types::Position> &arrPosition)
{
if (Maths::intToFloatConservingDecimals(arrPosition[id].x) <= maxOutParallaxLeft) {
Maths::addNormalIntToDecimalInt(arrPosition[id].x, maxOutParallaxRight * 2);
arrPosition[id].y = Maths::floatToIntConservingDecimals(arrParallax[id].y);
}
}

static void manageParallax(std::size_t /*unused*/, std::size_t /*unused*/)
{
std::lock_guard<std::mutex> lock(Registry::getInstance().mutex);
Registry::components<Types::Position> arrPosition =
Registry::getInstance().getComponents<Types::Position>();
Registry::components<Types::Parallax> arrParallax =
Registry::getInstance().getComponents<Types::Parallax>();

std::vector<std::size_t> ids = Registry::getInstance().getEntitiesByComponents(
{typeid(Types::Position), typeid(Types::Parallax), typeid(Types::Velocity)});

for (auto &id : ids) {
resetParallaxPosition(id, arrParallax, arrPosition);
}
}
};
}
Loading

0 comments on commit 636a521

Please sign in to comment.