Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2ad6834
CLIENT-GAME: Add isReady method
kw4ntiq Oct 4, 2023
8e6e565
CLIENT-GAME: Fix raylib comp unload
kw4ntiq Oct 4, 2023
f6ee02e
CLIENT-GAME: Fix clang tidy warnings
kw4ntiq Oct 4, 2023
1c05d43
CLIENT-GAME: Fix = by copy
kw4ntiq Oct 4, 2023
3bc3418
CLIENT-GAME: Add debug
kw4ntiq Oct 4, 2023
b615895
CLIENT-GAME: Clean code
kw4ntiq Oct 6, 2023
0192ae0
CLIENT-GAME: Set win size to 1920 1080
kw4ntiq Oct 6, 2023
3168c2b
Merge branch 'dev' into fix/RB-66
kw4ntiq Oct 6, 2023
1ba7ba7
FORMAT-AUTO: automatic format on pull request #47
github-actions[bot] Oct 6, 2023
3ab5cd3
CLIENT-GAME: Fix system merge
kw4ntiq Oct 6, 2023
7e2caa2
Merge branch after formating
kw4ntiq Oct 6, 2023
1810c14
CLIENT-GAME: Remove useless line
kw4ntiq Oct 6, 2023
e370312
FORMAT-AUTO: automatic format on pull request #47
github-actions[bot] Oct 6, 2023
865e23b
Merge branch 'fix/RB-66-Sound-effect-still-playing' of github.com:X-R…
kw4ntiq Oct 6, 2023
cc31b6d
CLIENT-GAME: Fix cmake
kw4ntiq Oct 6, 2023
6e52327
CLIENT-GAME: Fix eof
kw4ntiq Oct 6, 2023
6406d59
CLIENT-GAME: Add compile definition
kw4ntiq Oct 7, 2023
39665ff
FORMAT-AUTO: automatic format on pull request #47
github-actions[bot] Oct 7, 2023
fd43d4b
Merge branch 'dev' into fix/RB-66-Sound-effect-still-playing
kw4ntiq Oct 9, 2023
c4eebc1
FORMAT-AUTO: automatic format on pull request #47
github-actions[bot] Oct 9, 2023
9c20e8a
CLIENT-GAME: Fix system.cpp
kw4ntiq Oct 9, 2023
15bcf3f
Merge branch 'dev' into fix/RB-66-Sound-effect-still-playing
kw4ntiq Oct 9, 2023
8b43476
CLIENT-GAME: Fix const parameter in sparse array
kw4ntiq Oct 9, 2023
8381dbf
CLIENT-GAME: Move initAudio to client systems
kw4ntiq Oct 9, 2023
b919a98
Merge branch 'dev' into fix/RB-66
kw4ntiq Oct 9, 2023
dce7875
FORMAT-AUTO: automatic format on pull request #47
github-actions[bot] Oct 9, 2023
046903a
CLIENT-GAME: Fix merge conflicts
kw4ntiq Oct 9, 2023
14d72cb
FORMAT-AUTO: automatic format on pull request #47
github-actions[bot] Oct 9, 2023
023a21c
CLIENT-GAME: Fix build
kw4ntiq Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ if(CLANG_TIDY_EXE)
endif()
endif()

# Add server or client definitions

target_compile_definitions(
${PROJECT_NAME_CLIENT}
PUBLIC
CLIENT
)

target_compile_definitions(
${PROJECT_NAME_SERVER}
PUBLIC
SERVER
)

# Add compile options

if(MSVC)
target_compile_options(
${PROJECT_NAME_CLIENT}
Expand Down
7 changes: 6 additions & 1 deletion src/Client/Raylib/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ namespace Raylib {
SetSoundVolume(_sound, volume);
}

bool Sound::isReady() const
{
return IsSoundReady(_sound);
}

void Sound::unload()
{
UnloadSound(_sound);
Expand Down Expand Up @@ -115,7 +120,7 @@ namespace Raylib {

bool Music::isReady() const
{
return IsMusicStreamPlaying(_music);
return IsMusicReady(_music);
}

void Music::play() const
Expand Down
1 change: 1 addition & 0 deletions src/Client/Raylib/Audio/Audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Raylib {
class Sound {
public:
Sound(const std::string& fileName, float volume = 0.5f);
bool isReady() const;
void unload();
void play() const;
void stop() const;
Expand Down
6 changes: 6 additions & 0 deletions src/Client/Raylib/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}/UnloadRaylib.cpp
)

add_subdirectory(Geometry)
add_subdirectory(Graphics)
add_subdirectory(Audio)
Expand Down
55 changes: 55 additions & 0 deletions src/Client/Raylib/UnloadRaylib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** unloadRaylib
*/

#include "Raylib.hpp"
#include "Registry.hpp"

static void unloadSounds(std::size_t id)
{
Registry::components<Raylib::Sound> arrSound = Registry::getInstance().getComponents<Raylib::Sound>();

if (arrSound.exist(id)) {
arrSound[id].unload();
}
}

static void unloadMusic(std::size_t id)
{
Registry::components<Raylib::Music> arrMusic = Registry::getInstance().getComponents<Raylib::Music>();

if (arrMusic.exist(id)) {
arrMusic[id].unload();
}
}

static void unloadSprite(std::size_t id)
{
Registry::components<Raylib::Sprite> arrSprite =
Registry::getInstance().getComponents<Raylib::Sprite>();

if (arrSprite.exist(id)) {
arrSprite[id].unloadSprite();
}
}

static void unloadImage(std::size_t id)
{
Registry::components<Raylib::Image> arrImage = Registry::getInstance().getComponents<Raylib::Image>();

if (arrImage.exist(id)) {
arrImage[id].unloadImage();
}
}

// NOLINTNEXTLINE(readability-convert-member-functions-to-static,-warnings-as-errors)
void Registry::unloadRaylibComponents(std::size_t id)
{
unloadSounds(id);
unloadMusic(id);
unloadSprite(id);
unloadImage(id);
}
3 changes: 1 addition & 2 deletions src/Client/SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

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

#include "CustomTypes.hpp"

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

Expand Down
8 changes: 8 additions & 0 deletions src/ECS/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ std::size_t Registry::addEntity()

void Registry::removeEntity(std::size_t id)
{
#ifdef CLIENT
unloadRaylibComponents(id);
#endif
for (auto function : _removeComponentFunctions) {
function(*this, id);
}
}

void Registry::clear()
{
#ifdef CLIENT
for (std::size_t i = 0; i < _entitiesNb; i++) {
unloadRaylibComponents(i);
}
#endif
_data.clear();
_addComponentPlaceFunctions.clear();
_removeComponentFunctions.clear();
Expand Down
4 changes: 4 additions & 0 deletions src/ECS/Registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class Registry {

Clock &getClock();

#ifdef CLIENT
void unloadRaylibComponents(std::size_t id);
#endif

Logger::Logger &getLogger();

private:
Expand Down
4 changes: 2 additions & 2 deletions src/ECS/SparseArray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class SparseArray {
}

if (static_cast<int>(_sparse[id]) > -1) {
_dense[_sparse[id]] = value;
_dense[_sparse[id]] = std::move(value);
_revSparse[_sparse[id]] = id;
return;
}

_sparse[id] = _dense.size();
_dense.push_back(value);
_dense.push_back(std::move(value));
_revSparse.push_back(id);
}

Expand Down
16 changes: 16 additions & 0 deletions src/ECS/Systems/Systems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,28 @@ namespace Systems {
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
}

void initAudio(std::size_t /*managerId*/, std::size_t /*systemId*/)
{
const std::string musicPath = "assets/Audio/Musics/Title.mp3";
const std::string soundPath = "assets/Audio/Sounds/fire.ogg";
constexpr float musicVolume = 0.10F;
constexpr float soundVolume = 0.13F;

Raylib::Music music(musicPath, musicVolume);
Raylib::Sound sound(soundPath, soundVolume);

Registry::getInstance().addEntity();
Registry::getInstance().getComponents<Raylib::Music>().insertBack(music);
Registry::getInstance().getComponents<Raylib::Sound>().insertBack(sound);
}

std::vector<std::function<void(std::size_t, std::size_t)>> getECSSystems()
{
return {
windowCollision,
initPlayer,
initParalax,
initAudio,
entitiesCollision,
moveEntities,
#ifndef NDEBUG
Expand Down