From 238ca7001d4705f353fc6c0e08a0c891b392bae9 Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 26 Sep 2023 14:31:30 +0200 Subject: [PATCH 01/23] CLIENT-GAME: Add raylib functions MINOR --- src/Client/CMakeLists.txt | 2 +- src/Client/Raylib.cpp | 8 +++ src/Client/Raylib.hpp | 134 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/Client/Raylib.cpp create mode 100644 src/Client/Raylib.hpp diff --git a/src/Client/CMakeLists.txt b/src/Client/CMakeLists.txt index ddaf84ab..fdbf3845 100644 --- a/src/Client/CMakeLists.txt +++ b/src/Client/CMakeLists.txt @@ -9,7 +9,7 @@ target_include_directories( target_sources( ${PROJECT_NAME_CLIENT} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/Raylib.cpp ) add_subdirectory(Systems) diff --git a/src/Client/Raylib.cpp b/src/Client/Raylib.cpp new file mode 100644 index 00000000..021e6340 --- /dev/null +++ b/src/Client/Raylib.cpp @@ -0,0 +1,8 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Raylib +*/ + +#include "Raylib.hpp" diff --git a/src/Client/Raylib.hpp b/src/Client/Raylib.hpp new file mode 100644 index 00000000..33dc18bf --- /dev/null +++ b/src/Client/Raylib.hpp @@ -0,0 +1,134 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Raylib +*/ + +#pragma once + +// encapsulate raylib in a namespace +namespace Raylib +{ + // Window-related functions + void initWindow(int width, int height, const char *title); + bool windowShouldClose(void); + void closeWindow(void); + bool isWindowReady(void); + bool isWindowFullscreen(void); + bool isWindowHidden(void); + bool isWindowMinimized(void); + bool isWindowMaximized(void); + bool isWindowFocused(void); + bool isWindowResized(void); + bool isWindowState(unsigned int flag); + void setWindowState(unsigned int flags); + void clearWindowState(unsigned int flags); + void toggleFullscreen(void); + void maximizeWindow(void); + void minimizeWindow(void); + void setWindowIcon(Image image); + void setWindowIcons(Image *images, int count); + void setWindowTitle(const char *title); + int getScreenWidth(void); + int getScreenHeight(void); + int getRenderWidth(void); + int getRenderHeight(void); + int getMonitorWidth(int monitor); + int getMonitorHeight(int monitor); + int getMonitorRefreshRate(int monitor); + void setClipboardText(const char *text); + const char *getClipboardText(void); + + // Cursor-related functions + void showCursor(void); + void hideCursor(void); + bool isCursorHidden(void); + void enableCursor(void); + void disableCursor(void); + bool isCursorOnScreen(void); + + // Drawing-related functions + void clearBackground(Color color); + void beginDrawing(void); + void endDrawing(void); + + // Timing-related functions + void setTargetFPS(int fps); + int getFPS(void); + float getFrameTime(void); + double getTime(void); + + // Misc. functions + void takeScreenshot(const char *fileName); + + // Input-related functions: keyboard + bool isKeyPressed(int key); + bool isKeyDown(int key); + bool isKeyReleased(int key); + bool isKeyUp(int key); + void setExitKey(int key); + int getKeyPressed(void); + int getCharPressed(void); + + // Input-related functions: mouse + bool isMouseButtonPressed(int button); + bool isMouseButtonDown(int button); + bool isMouseButtonReleased(int button); + bool isMouseButtonUp(int button); + int getMouseX(void); + int getMouseY(void); + Vector2 getMousePosition(void); + Vector2 getMouseDelta(void); + void setMousePosition(int x, int y); + void setMouseOffset(int offsetX, int offsetY); + void setMouseScale(float scaleX, float scaleY); + float getMouseWheelMove(void); + Vector2 getMouseWheelMoveV(void); + void setMouseCursor(int cursor); + + // Shapes-related functions + void drawPixel(int posX, int posY, Color color); + void drawCircle(int centerX, int centerY, float radius, Color color); + void drawRectangle(int posX, int posY, int width, int height, Color color); + + Image loadImage(const char *fileName); + Image loadImageFromTexture(Texture2D texture); + Image loadImageFromScreen(void); + bool isImageReady(Image image); + void unloadImage(Image image); + + // Texture drawing functions + void drawTexture(Texture2D texture, int posX, int posY, Color tint); + void drawTextureV(Texture2D texture, Vector2 position, Color tint); + void drawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); + void drawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint); + void drawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); + + // Color/pixel related functions + Color fade(Color color, float alpha); + int colorToInt(Color color); + Vector4 colorNormalize(Color color); + Color colorFromNormalized(Vector4 normalized); + Color getColor(unsigned int hexValue); + + // Font loading/unloading functions + Font getFontDefault(void); + Font loadFont(const char *fileName); + bool isFontReady(Font font); + void unloadFont(Font font); + + // Text drawing functions + void drawFPS(int posX, int posY); + void drawText(const char *text, int posX, int posY, int fontSize, Color color); + void drawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); + void drawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); + + // Text / fonts + int measureText(const char *text, int fontSize); + Vector2 measureTextEx(Font font, const char *text, float fontSize, float spacing); + char *loadUTF8(const int *codepoints, int length); + void unloadUTF8(char *text); + const char *textFormat(const char *text, ...); + void textAppend(char *text, const char *append, int *position); +} From 4ea1082d2aaf43725ede2a944f31a31f39f1d491 Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 26 Sep 2023 15:04:50 +0200 Subject: [PATCH 02/23] CLIENT-GAME: Add audio functions MINOR --- src/Client/Raylib.hpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Client/Raylib.hpp b/src/Client/Raylib.hpp index 33dc18bf..127a180a 100644 --- a/src/Client/Raylib.hpp +++ b/src/Client/Raylib.hpp @@ -7,7 +7,6 @@ #pragma once -// encapsulate raylib in a namespace namespace Raylib { // Window-related functions @@ -131,4 +130,43 @@ namespace Raylib void unloadUTF8(char *text); const char *textFormat(const char *text, ...); void textAppend(char *text, const char *append, int *position); + + // Audio device management functions + void initAudioDevice(void); + void closeAudioDevice(void); + bool isAudioDeviceReady(void); + void setMasterVolume(float volume); + + // Wave/Sound loading/unloading functions + Sound loadSound(const char *fileName); + Sound loadSoundFromWave(Wave wave); + bool isSoundReady(Sound sound); + void updateSound(Sound sound, const void *data, int sampleCount); + void unloadSound(Sound sound); + + // Wave/Sound management functions + void playSound(Sound sound); + void stopSound(Sound sound); + void pauseSound(Sound sound); + void resumeSound(Sound sound); + bool isSoundPlaying(Sound sound); + void setSoundVolume(Sound sound, float volume); + void setSoundPitch(Sound sound, float pitch); + void setSoundPan(Sound sound, float pan); + + // Music management functions + Music loadMusicStream(const char *fileName); + bool isMusicReady(Music music); + void unloadMusicStream(Music music); + void playMusicStream(Music music); + bool isMusicStreamPlaying(Music music); + void updateMusicStream(Music music); + void stopMusicStream(Music music); + void rauseMusicStream(Music music); + void resumeMusicStream(Music music); + void setMusicVolume(Music music, float volume); + void setMusicPitch(Music music, float pitch); + void setMusicPan(Music music, float pan); + float getMusicTimeLength(Music music); + float getMusicTimePlayed(Music music); } From ad986e7d6d22f1e1fca76ed795cb4c81f727964e Mon Sep 17 00:00:00 2001 From: tenshi Date: Tue, 26 Sep 2023 16:38:59 +0200 Subject: [PATCH 03/23] CLIENT-GAME: Fix compil problem --- src/Client/Raylib.cpp | 7 +++++++ src/Client/Raylib.hpp | 2 ++ src/Client/Systems/Managers/GraphicManager.cpp | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Client/Raylib.cpp b/src/Client/Raylib.cpp index 021e6340..c682c8a0 100644 --- a/src/Client/Raylib.cpp +++ b/src/Client/Raylib.cpp @@ -6,3 +6,10 @@ */ #include "Raylib.hpp" + +namespace Raylib { + void initWindow(int width, int height, const char *title) { + std::cout << "initWindow" << std::endl; + InitWindow(800, 600, "R-Type"); + } +} diff --git a/src/Client/Raylib.hpp b/src/Client/Raylib.hpp index 127a180a..82af872a 100644 --- a/src/Client/Raylib.hpp +++ b/src/Client/Raylib.hpp @@ -6,6 +6,8 @@ */ #pragma once +#include "raylib.h" +#include namespace Raylib { diff --git a/src/Client/Systems/Managers/GraphicManager.cpp b/src/Client/Systems/Managers/GraphicManager.cpp index 466ac1fa..43f6f3f7 100644 --- a/src/Client/Systems/Managers/GraphicManager.cpp +++ b/src/Client/Systems/Managers/GraphicManager.cpp @@ -10,6 +10,7 @@ #include "raylib.h" #include "ClientSystems.hpp" #include "CustomTypes.hpp" +#include "Raylib.hpp" namespace Systems { // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) @@ -21,7 +22,7 @@ namespace Systems { const int screenWidth = 800; const int screenHeight = 450; const int frameRate = 60; - InitWindow(screenWidth, screenHeight, "R-Type"); + Raylib::initWindow(screenWidth, screenHeight, "R-Type"); SetTargetFPS(frameRate); addSystem(GraphicSystems::rectRenderer); From 12738fff206c6bd4f40b2030cfe9c255cfd5f1a2 Mon Sep 17 00:00:00 2001 From: tenshi Date: Wed, 27 Sep 2023 11:11:31 +0200 Subject: [PATCH 04/23] CLIENT-GAME: Add functionnal audio --- src/Client/CMakeLists.txt | 7 +- src/Client/Raylib.cpp | 15 - src/Client/Raylib.hpp | 174 ------- src/Client/Raylib/Audio/Audio.cpp | 121 +++++ src/Client/Raylib/Audio/Audio.hpp | 51 ++ src/Client/Raylib/Audio/CMakeLists.txt | 13 + src/Client/Raylib/CMakeLists.txt | 11 + src/Client/Raylib/Geometry/CMakeLists.txt | 13 + src/Client/Raylib/Geometry/Geometry.cpp | 182 +++++++ src/Client/Raylib/Geometry/Geometry.hpp | 129 +++++ src/Client/Raylib/Graphics/CMakeLists.txt | 13 + src/Client/Raylib/Graphics/Graphics.cpp | 605 ++++++++++++++++++++++ src/Client/Raylib/Graphics/Graphics.hpp | 143 +++++ src/Client/Raylib/Raylib.hpp | 5 + 14 files changed, 1287 insertions(+), 195 deletions(-) delete mode 100644 src/Client/Raylib.cpp delete mode 100644 src/Client/Raylib.hpp create mode 100644 src/Client/Raylib/Audio/Audio.cpp create mode 100644 src/Client/Raylib/Audio/Audio.hpp create mode 100644 src/Client/Raylib/Audio/CMakeLists.txt create mode 100644 src/Client/Raylib/CMakeLists.txt create mode 100644 src/Client/Raylib/Geometry/CMakeLists.txt create mode 100644 src/Client/Raylib/Geometry/Geometry.cpp create mode 100644 src/Client/Raylib/Geometry/Geometry.hpp create mode 100644 src/Client/Raylib/Graphics/CMakeLists.txt create mode 100644 src/Client/Raylib/Graphics/Graphics.cpp create mode 100644 src/Client/Raylib/Graphics/Graphics.hpp create mode 100644 src/Client/Raylib/Raylib.hpp diff --git a/src/Client/CMakeLists.txt b/src/Client/CMakeLists.txt index fdbf3845..2ec80ae0 100644 --- a/src/Client/CMakeLists.txt +++ b/src/Client/CMakeLists.txt @@ -6,10 +6,5 @@ target_include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) -target_sources( - ${PROJECT_NAME_CLIENT} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/Raylib.cpp -) - add_subdirectory(Systems) +add_subdirectory(Raylib) diff --git a/src/Client/Raylib.cpp b/src/Client/Raylib.cpp deleted file mode 100644 index c682c8a0..00000000 --- a/src/Client/Raylib.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** Raylib -*/ - -#include "Raylib.hpp" - -namespace Raylib { - void initWindow(int width, int height, const char *title) { - std::cout << "initWindow" << std::endl; - InitWindow(800, 600, "R-Type"); - } -} diff --git a/src/Client/Raylib.hpp b/src/Client/Raylib.hpp deleted file mode 100644 index 82af872a..00000000 --- a/src/Client/Raylib.hpp +++ /dev/null @@ -1,174 +0,0 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** Raylib -*/ - -#pragma once -#include "raylib.h" -#include - -namespace Raylib -{ - // Window-related functions - void initWindow(int width, int height, const char *title); - bool windowShouldClose(void); - void closeWindow(void); - bool isWindowReady(void); - bool isWindowFullscreen(void); - bool isWindowHidden(void); - bool isWindowMinimized(void); - bool isWindowMaximized(void); - bool isWindowFocused(void); - bool isWindowResized(void); - bool isWindowState(unsigned int flag); - void setWindowState(unsigned int flags); - void clearWindowState(unsigned int flags); - void toggleFullscreen(void); - void maximizeWindow(void); - void minimizeWindow(void); - void setWindowIcon(Image image); - void setWindowIcons(Image *images, int count); - void setWindowTitle(const char *title); - int getScreenWidth(void); - int getScreenHeight(void); - int getRenderWidth(void); - int getRenderHeight(void); - int getMonitorWidth(int monitor); - int getMonitorHeight(int monitor); - int getMonitorRefreshRate(int monitor); - void setClipboardText(const char *text); - const char *getClipboardText(void); - - // Cursor-related functions - void showCursor(void); - void hideCursor(void); - bool isCursorHidden(void); - void enableCursor(void); - void disableCursor(void); - bool isCursorOnScreen(void); - - // Drawing-related functions - void clearBackground(Color color); - void beginDrawing(void); - void endDrawing(void); - - // Timing-related functions - void setTargetFPS(int fps); - int getFPS(void); - float getFrameTime(void); - double getTime(void); - - // Misc. functions - void takeScreenshot(const char *fileName); - - // Input-related functions: keyboard - bool isKeyPressed(int key); - bool isKeyDown(int key); - bool isKeyReleased(int key); - bool isKeyUp(int key); - void setExitKey(int key); - int getKeyPressed(void); - int getCharPressed(void); - - // Input-related functions: mouse - bool isMouseButtonPressed(int button); - bool isMouseButtonDown(int button); - bool isMouseButtonReleased(int button); - bool isMouseButtonUp(int button); - int getMouseX(void); - int getMouseY(void); - Vector2 getMousePosition(void); - Vector2 getMouseDelta(void); - void setMousePosition(int x, int y); - void setMouseOffset(int offsetX, int offsetY); - void setMouseScale(float scaleX, float scaleY); - float getMouseWheelMove(void); - Vector2 getMouseWheelMoveV(void); - void setMouseCursor(int cursor); - - // Shapes-related functions - void drawPixel(int posX, int posY, Color color); - void drawCircle(int centerX, int centerY, float radius, Color color); - void drawRectangle(int posX, int posY, int width, int height, Color color); - - Image loadImage(const char *fileName); - Image loadImageFromTexture(Texture2D texture); - Image loadImageFromScreen(void); - bool isImageReady(Image image); - void unloadImage(Image image); - - // Texture drawing functions - void drawTexture(Texture2D texture, int posX, int posY, Color tint); - void drawTextureV(Texture2D texture, Vector2 position, Color tint); - void drawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); - void drawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint); - void drawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); - - // Color/pixel related functions - Color fade(Color color, float alpha); - int colorToInt(Color color); - Vector4 colorNormalize(Color color); - Color colorFromNormalized(Vector4 normalized); - Color getColor(unsigned int hexValue); - - // Font loading/unloading functions - Font getFontDefault(void); - Font loadFont(const char *fileName); - bool isFontReady(Font font); - void unloadFont(Font font); - - // Text drawing functions - void drawFPS(int posX, int posY); - void drawText(const char *text, int posX, int posY, int fontSize, Color color); - void drawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); - void drawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint); - - // Text / fonts - int measureText(const char *text, int fontSize); - Vector2 measureTextEx(Font font, const char *text, float fontSize, float spacing); - char *loadUTF8(const int *codepoints, int length); - void unloadUTF8(char *text); - const char *textFormat(const char *text, ...); - void textAppend(char *text, const char *append, int *position); - - // Audio device management functions - void initAudioDevice(void); - void closeAudioDevice(void); - bool isAudioDeviceReady(void); - void setMasterVolume(float volume); - - // Wave/Sound loading/unloading functions - Sound loadSound(const char *fileName); - Sound loadSoundFromWave(Wave wave); - bool isSoundReady(Sound sound); - void updateSound(Sound sound, const void *data, int sampleCount); - void unloadSound(Sound sound); - - // Wave/Sound management functions - void playSound(Sound sound); - void stopSound(Sound sound); - void pauseSound(Sound sound); - void resumeSound(Sound sound); - bool isSoundPlaying(Sound sound); - void setSoundVolume(Sound sound, float volume); - void setSoundPitch(Sound sound, float pitch); - void setSoundPan(Sound sound, float pan); - - // Music management functions - Music loadMusicStream(const char *fileName); - bool isMusicReady(Music music); - void unloadMusicStream(Music music); - void playMusicStream(Music music); - bool isMusicStreamPlaying(Music music); - void updateMusicStream(Music music); - void stopMusicStream(Music music); - void rauseMusicStream(Music music); - void resumeMusicStream(Music music); - void setMusicVolume(Music music, float volume); - void setMusicPitch(Music music, float pitch); - void setMusicPan(Music music, float pan); - float getMusicTimeLength(Music music); - float getMusicTimePlayed(Music music); -} diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp new file mode 100644 index 00000000..e8a72a50 --- /dev/null +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -0,0 +1,121 @@ +#include "Audio.hpp" + +namespace Raylib { + + // Audio device management functions + + void initAudioDevice() { + InitAudioDevice(); + } + + void closeAudioDevice() { + CloseAudioDevice(); + } + + bool isAudioDeviceReady() { + return IsAudioDeviceReady(); + } + + void setMasterVolume(float volume) { + SetMasterVolume(volume); + } + + // Sounds + Sound::Sound(const std::string& fileName) { + sound = LoadSound(fileName.c_str()); + } + + Sound::~Sound() { + UnloadSound(sound); + } + + void Sound::play() const { + PlaySound(sound); + } + + void Sound::stop() const { + StopSound(sound); + } + + void Sound::pause() const { + PauseSound(sound); + } + + void Sound::resume() const { + ResumeSound(sound); + } + + bool Sound::isPlaying() const { + return IsSoundPlaying(sound); + } + + void Sound::setVolume(float volume) const { + SetSoundVolume(sound, volume); + } + + void Sound::setPitch(float pitch) const { + SetSoundPitch(sound, pitch); + } + + void Sound::setPan(float pan) const { + SetSoundPitch(sound, pan); + } + + // Music + + Music::Music(const std::string& fileName) { + music = LoadMusicStream(fileName.c_str()); + } + + Music::~Music() { + UnloadMusicStream(music); + } + + bool Music::isReady() const { + return IsMusicStreamPlaying(music); + } + + void Music::play() const { + PlayMusicStream(music); + } + + bool Music::isPlaying() const { + return IsMusicStreamPlaying(music); + } + + void Music::update() const { + UpdateMusicStream(music); + } + + void Music::stop() const { + StopMusicStream(music); + } + + void Music::pause() const { + PauseMusicStream(music); + } + + void Music::resume() const { + ResumeMusicStream(music); + } + + void Music::setVolume(float volume) const { + SetMusicVolume(music, volume); + } + + void Music::setPitch(float pitch) const { + SetMusicPitch(music, pitch); + } + + void Music::setPan(float pan) const { + SetMusicPitch(music, pan); + } + + float Music::getTimeLength() const { + return GetMusicTimeLength(music); + } + + float Music::getTimePlayed() const { + return GetMusicTimePlayed(music); + } +} diff --git a/src/Client/Raylib/Audio/Audio.hpp b/src/Client/Raylib/Audio/Audio.hpp new file mode 100644 index 00000000..6b6cdff5 --- /dev/null +++ b/src/Client/Raylib/Audio/Audio.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include +#include "raylib.h" + +namespace Raylib { + // Audio device management functions + void initAudioDevice(); + void closeAudioDevice(); + bool isAudioDeviceReady(); + void setMasterVolume(float volume); + + // Sounds + class Sound { + public: + Sound(const std::string& fileName); + ~Sound(); + + void play() const; + void stop() const; + void pause() const; + void resume() const; + bool isPlaying() const; + void setVolume(float volume) const; + void setPitch(float pitch) const; + void setPan(float pan) const; + + private: + ::Sound sound; + }; + + class Music { + public: + Music(const std::string& fileName); + ~Music(); + bool isReady() const; + void play() const; + bool isPlaying() const; + void update() const; + void stop() const; + void pause() const; + void resume() const; + void setVolume(float volume) const; + void setPitch(float pitch) const; + void setPan(float pan) const; + float getTimeLength() const; + float getTimePlayed() const; + private: + ::Music music; + }; +} diff --git a/src/Client/Raylib/Audio/CMakeLists.txt b/src/Client/Raylib/Audio/CMakeLists.txt new file mode 100644 index 00000000..35acd891 --- /dev/null +++ b/src/Client/Raylib/Audio/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Audio.cpp +) diff --git a/src/Client/Raylib/CMakeLists.txt b/src/Client/Raylib/CMakeLists.txt new file mode 100644 index 00000000..07c94c4f --- /dev/null +++ b/src/Client/Raylib/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_subdirectory(Geometry) +add_subdirectory(Graphics) +add_subdirectory(Audio) diff --git a/src/Client/Raylib/Geometry/CMakeLists.txt b/src/Client/Raylib/Geometry/CMakeLists.txt new file mode 100644 index 00000000..33e99b3e --- /dev/null +++ b/src/Client/Raylib/Geometry/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Geometry.cpp +) diff --git a/src/Client/Raylib/Geometry/Geometry.cpp b/src/Client/Raylib/Geometry/Geometry.cpp new file mode 100644 index 00000000..0f728acb --- /dev/null +++ b/src/Client/Raylib/Geometry/Geometry.cpp @@ -0,0 +1,182 @@ +#include "Geometry.hpp" +#include "raylib.h" + +namespace Raylib { + Vector2::Vector2(float x, float y) : _x(x), _y(y) + { + } + + float Vector2::X() const + { + return _x; + } + float Vector2::Y() const + { + return _y; + } + + void Vector2::X(float x) + { + _x = x; + } + void Vector2::Y(float y) + { + _y = y; + } + + Vector3::Vector3(float x, float y, float z) : _x(x), _y(y), _z(z) + { + } + + float Vector3::X() const + { + return _x; + } + float Vector3::Y() const + { + return _y; + } + float Vector3::Z() const + { + return _z; + } + + void Vector3::X(float x) + { + _x = x; + } + void Vector3::Y(float y) + { + _y = y; + } + void Vector3::Z(float z) + { + _z = z; + } + + Vector4::Vector4(float x, float y, float z, float w) + : _x(x), + _y(y), + _z(z), + _w(w) + { + } + + float Vector4::X() const + { + return _x; + } + float Vector4::Y() const + { + return _y; + } + float Vector4::Z() const + { + return _z; + } + float Vector4::W() const + { + return _w; + } + + void Vector4::X(float x) + { + _x = x; + } + void Vector4::Y(float y) + { + _y = y; + } + void Vector4::Z(float z) + { + _z = z; + } + void Vector4::W(float w) + { + _w = w; + } + + Rectangle::Rectangle(float x, float y, float width, float height) + : _x(x), + _y(y), + _width(width), + _height(height) + { + } + + float Rectangle::X() const + { + return _x; + } + float Rectangle::Y() const + { + return _y; + } + float Rectangle::Width() const + { + return _width; + } + float Rectangle::Height() const + { + return _height; + } + + void Rectangle::X(float x) + { + _x = x; + } + void Rectangle::Y(float y) + { + _y = y; + } + void Rectangle::Width(float width) + { + _width = width; + } + void Rectangle::Height(float height) + { + _height = height; + } + + Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + : _r(r), + _g(g), + _b(b), + _a(a) + { + } + + uint8_t Color::R() const + { + return _r; + } + uint8_t Color::G() const + { + return _g; + } + uint8_t Color::B() const + { + return _b; + } + uint8_t Color::A() const + { + return _a; + } + + void Color::R(uint8_t r) + { + _r = r; + } + void Color::G(uint8_t g) + { + _g = g; + } + void Color::B(uint8_t b) + { + _b = b; + } + void Color::A(uint8_t a) + { + _a = a; + } +} // namespace Raylib diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp new file mode 100644 index 00000000..b5576a2e --- /dev/null +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -0,0 +1,129 @@ +#pragma once + +#include +#include "raylib.h" + +namespace Raylib { + + class Vector2 { + public: + Vector2(float x, float y); + + float X() const; + float Y() const; + + void X(float x); + void Y(float y); + + private: + float _x; + float _y; + }; + + class Vector3 { + public: + Vector3(float x, float y, float z); + + float X() const; + float Y() const; + float Z() const; + + void X(float x); + void Y(float y); + void Z(float z); + + private: + float _x; + float _y; + float _z; + }; + + class Vector4 { + public: + Vector4(float x, float y, float z, float w); + + float X() const; + float Y() const; + float Z() const; + float W() const; + + void X(float x); + void Y(float y); + void Z(float z); + void W(float w); + + private: + float _x; + float _y; + float _z; + float _w; + }; + + class Rectangle { + public: + Rectangle(float x, float y, float width, float height); + + float X() const; + float Y() const; + float Width() const; + float Height() const; + + void X(float x); + void Y(float y); + void Width(float width); + void Height(float height); + + private: + float _x; + float _y; + float _width; + float _height; + }; + + class Color { + public: + Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); + + uint8_t R() const; + uint8_t G() const; + uint8_t B() const; + uint8_t A() const; + + void R(uint8_t r); + void G(uint8_t g); + void B(uint8_t b); + void A(uint8_t a); + + private: + uint8_t _r; + uint8_t _g; + uint8_t _b; + uint8_t _a; + }; + + // COLOR CONSTANTS + static const Color DarkGray = DARKGRAY; + static const Color Yellow = YELLOW; + static const Color Gold = GOLD; + static const Color Orange = ORANGE; + static const Color Pink = PINK; + static const Color Red = RED; + static const Color Maroon = MAROON; + static const Color Green = GREEN; + static const Color Lime = LIME; + static const Color DarkGreen = DARKGREEN; + static const Color SkyBlue = SKYBLUE; + static const Color Blue = BLUE; + static const Color DarkBlue = DARKBLUE; + static const Color Purple = PURPLE; + static const Color Violet = VIOLET; + static const Color DarkPurple = DARKPURPLE; + static const Color Beige = BEIGE; + static const Color Brown = BROWN; + static const Color DarkBrown = DARKBROWN; + static const Color White = WHITE; + static const Color Black = BLACK; + static const Color Blank = BLANK; + static const Color Magenta = MAGENTA; + static const Color RayWhite = RAYWHITE; +} // namespace Raylib diff --git a/src/Client/Raylib/Graphics/CMakeLists.txt b/src/Client/Raylib/Graphics/CMakeLists.txt new file mode 100644 index 00000000..e61fb88b --- /dev/null +++ b/src/Client/Raylib/Graphics/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Graphics.cpp +) diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp new file mode 100644 index 00000000..9d76b211 --- /dev/null +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -0,0 +1,605 @@ +#include "Graphics.hpp" +#include "raylib.h" + +namespace Raylib { + + // Window-related functions + + void initWindow(int width, int height, std::string title) + { + InitWindow(width, height, title.c_str()); + } + + bool windowShouldClose() + { + return WindowShouldClose(); + } + + void closeWindow() + { + CloseWindow(); + } + + bool isWindowReady() + { + return IsWindowReady(); + } + + bool isWindowFullscreen() + { + return IsWindowFullscreen(); + } + + bool isWindowHidden() + { + return IsWindowHidden(); + } + + bool isWindowMinimized() + { + return IsWindowMinimized(); + } + + bool isWindowMaximized() + { + return IsWindowMaximized(); + } + + bool isWindowFocused() + { + return IsWindowFocused(); + } + + bool isWindowResized() + { + return IsWindowResized(); + } + + bool isWindowState(size_t flag) + { + return IsWindowState(static_cast(flag)); + } + + void setWindowState(size_t flags) + { + SetWindowState(static_cast(flags)); + } + + void clearWindowState(size_t flags) + { + ClearWindowState(static_cast(flags)); + } + + void toggleFullscreen() + { + ToggleFullscreen(); + } + + void maximizeWindow() + { + MaximizeWindow(); + } + + void minimizeWindow() + { + MinimizeWindow(); + } + + void setWindowTitle(std::string title) + { + SetWindowTitle(title.c_str()); + } + + int getScreenWidth() + { + return GetScreenWidth(); + } + + int getScreenHeight() + { + return GetScreenHeight(); + } + + int getRenderWidth() + { + return GetRenderWidth(); + } + + int getRenderHeight() + { + return GetRenderHeight(); + } + + int getMonitorWidth(int monitor) + { + return GetMonitorWidth(monitor); + } + + int getMonitorHeight(int monitor) + { + return GetMonitorHeight(monitor); + } + + int getMonitorRefreshRate(int monitor) + { + return GetMonitorRefreshRate(monitor); + } + + void setClipboardText(std::string text) + { + SetClipboardText(text.c_str()); + } + + std::string getClipboardText() + { + return GetClipboardText(); + } + + void setWindowIcon(Image icon) + { + ::Image image; + + image.data = icon.getData(); + image.width = icon.getWidth(); + image.height = icon.getHeight(); + image.mipmaps = icon.getMipmaps(); + image.format = icon.getFormat(); + SetWindowIcon(image); + } + + // Cursor-related functions + + void showCursor() + { + ShowCursor(); + } + + void hideCursor() + { + HideCursor(); + } + + bool isCursorHidden() + { + return IsCursorHidden(); + } + + void enableCursor() + { + EnableCursor(); + } + + void disableCursor() + { + DisableCursor(); + } + + bool isCursorOnScreen() + { + return IsCursorOnScreen(); + } + + // Drawing-related functions + + void clearBackground(Raylib::Color color) + { + ClearBackground({color.R(), color.G(), color.B(), color.A()}); + } + + void beginDrawing() + { + BeginDrawing(); + } + + void endDrawing() + { + EndDrawing(); + } + + // Timing-related functions + + void setTargetFPS(int fps) + { + SetTargetFPS(fps); + } + + int getFPS() + { + return GetFPS(); + } + + float getFrameTime() + { + return GetFrameTime(); + } + + double getTime() + { + return GetTime(); + } + + // Misc. functions + + void takeScreenshot(std::string fileName) + { + TakeScreenshot(fileName.c_str()); + } + + // Input-related functions: keyboard + + bool isKeyPressed(int key) + { + return IsKeyPressed(key); + } + + bool isKeyDown(int key) + { + return IsKeyDown(key); + } + + bool isKeyReleased(int key) + { + return IsKeyReleased(key); + } + + bool isKeyUp(int key) + { + return IsKeyUp(key); + } + + void setExitKey(int key) + { + SetExitKey(key); + } + + int getKeyPressed() + { + return GetKeyPressed(); + } + + int getCharPressed() + { + return GetCharPressed(); + } + + // Input-related functions: mouse + + bool isMouseButtonPressed(int button) + { + return IsMouseButtonPressed(button); + } + + bool isMouseButtonDown(int button) + { + return IsMouseButtonDown(button); + } + + bool isMouseButtonReleased(int button) + { + return IsMouseButtonReleased(button); + } + + bool isMouseButtonUp(int button) + { + return IsMouseButtonUp(button); + } + + Vector2 getMousePosition() + { + ::Vector2 position = GetMousePosition(); + return Vector2(position.x, position.y); + } + + int getMouseX() + { + return GetMouseX(); + } + + int getMouseY() + { + return GetMouseY(); + } + + void setMousePosition(int x, int y) + { + SetMousePosition(x, y); + } + + Vector2 getMouseDelta() + { + ::Vector2 delta = GetMouseDelta(); + return Vector2(delta.x, delta.y); + } + + void setMouseOffset(int offsetX, int offsetY) + { + SetMouseOffset(offsetX, offsetY); + } + + void setMouseScale(float scaleX, float scaleY) + { + SetMouseScale(scaleX, scaleY); + } + + float getMouseWheelMove() + { + return GetMouseWheelMove(); + } + + Vector2 getMouseWheelMoveV() + { + ::Vector2 move = GetMouseWheelMoveV(); + return Vector2(move.x, move.y); + } + + void setMouseCursor(int cursor) + { + SetMouseCursor(cursor); + } + + // Shapes-related functions + void drawPixel(int posX, int posY, Color color) + { + DrawPixel(posX, posY, {color.R(), color.G(), color.B(), color.A()}); + } + + void drawCircle(int centerX, int centerY, float radius, Color color) + { + DrawCircle( + centerX, + centerY, + radius, + {color.R(), color.G(), color.B(), color.A()}); + } + + void drawRectangle(int posX, int posY, int width, int height, Color color) + { + DrawRectangle( + posX, + posY, + width, + height, + {color.R(), color.G(), color.B(), color.A()}); + } + + Image::Image(std::string fileName) + { + _image = LoadImage(fileName.c_str()); + + if (!isImageReady()) { + ::Color badTexture = {255, 16, 240, 255}; + static constexpr int badImageSize = 50; + _image = GenImageColor(badImageSize, badImageSize, badTexture); + } + } + + Image::Image(int width, int height, Color color) + { + _image = GenImageColor( + width, + height, + {color.R(), color.G(), color.B(), color.A()}); + } + + Image::~Image() + { + if (isImageReady()) { + unloadImage(); + } + } + + bool Image::isImageReady() + { + return IsImageReady(_image); + } + + void Image::unloadImage() + { + if (isImageReady()) { + UnloadImage(_image); + } + } + + int Image::getWidth() + { + return _image.width; + } + + int Image::getHeight() + { + return _image.height; + } + + int Image::getMipmaps() + { + return _image.mipmaps; + } + + int Image::getFormat() + { + return _image.format; + } + + void *Image::getData() + { + return _image.data; + } + + // Texture functions + + Texture2D::Texture2D(std::string fileName) + { + _texture = LoadTexture(fileName.c_str()); + if (!IsTextureReady(_texture)) { + ::Color badTexture = {255, 16, 240, 255}; + static constexpr int badImageSize = 50; + _texture = LoadTextureFromImage( + GenImageColor(badImageSize, badImageSize, badTexture)); + } + } + + Texture2D::Texture2D(Image image) + { + loadTextureFromImage(image); + } + + void Texture2D::loadTextureFromImage(Image image) + { + ::Image img; + img.data = image.getData(); + img.width = image.getWidth(); + img.height = image.getHeight(); + img.mipmaps = image.getMipmaps(); + img.format = image.getFormat(); + _texture = LoadTextureFromImage(img); + } + + Texture2D::~Texture2D() + { + UnloadTexture(_texture); + } + + int Texture2D::getId() + { + return _texture.id; + } + + int Texture2D::getWidth() + { + return _texture.width; + } + + int Texture2D::getHeight() + { + return _texture.height; + } + + int Texture2D::getMipmaps() + { + return _texture.mipmaps; + } + + int Texture2D::getFormat() + { + return _texture.format; + } + + // Texture drawing functions + + void Texture2D::draw(int posX, int posY, Color tint) + { + DrawTexture( + _texture, + posX, + posY, + {tint.R(), tint.G(), tint.B(), tint.A()}); + } + + void Texture2D::drawV(Vector2 position, Color tint) + { + ::Vector2 pos = {position.X(), position.Y()}; + DrawTextureV(_texture, pos, {tint.R(), tint.G(), tint.B(), tint.A()}); + } + + void + Texture2D::drawEx(Vector2 position, float rotation, float scale, Color tint) + { + ::Vector2 pos = {position.X(), position.Y()}; + DrawTextureEx( + _texture, + pos, + rotation, + scale, + {tint.R(), tint.G(), tint.B(), tint.A()}); + } + + void Texture2D::drawRec(Rectangle source, Vector2 position, Color tint) + { + ::Rectangle src = + {source.X(), source.Y(), source.Width(), source.Height()}; + ::Vector2 pos = {position.X(), position.Y()}; + DrawTextureRec( + _texture, + src, + pos, + {tint.R(), tint.G(), tint.B(), tint.A()}); + } + + void Texture2D::drawPro( + Rectangle source, + Rectangle dest, + Vector2 origin, + float rotation, + Color tint) + { + ::Rectangle src = + {source.X(), source.Y(), source.Width(), source.Height()}; + ::Rectangle dst = {dest.X(), dest.Y(), dest.Width(), dest.Height()}; + ::Vector2 ori = {origin.X(), origin.Y()}; + DrawTexturePro( + _texture, + src, + dst, + ori, + rotation, + {tint.R(), tint.G(), tint.B(), tint.A()}); + } + + // Color/pixel related functions + Color fade(Color color, float alpha) + { + ::Color c = {color.R(), color.G(), color.B(), color.A()}; + ::Color f = Fade(c, alpha); + return Color(f.r, f.g, f.b, f.a); + } + + int colorToInt(Color color) + { + ::Color c = {color.R(), color.G(), color.B(), color.A()}; + return ColorToInt(c); + } + + Vector4 colorNormalize(Color color) + { + ::Color c = {color.R(), color.G(), color.B(), color.A()}; + ::Vector4 v = ColorNormalize(c); + return Vector4(v.x, v.y, v.z, v.w); + } + + Color colorFromNormalized(Vector4 normalized) + { + ::Vector4 v = + {normalized.X(), normalized.Y(), normalized.Z(), normalized.W()}; + ::Color c = ColorFromNormalized(v); + return Color(c.r, c.g, c.b, c.a); + } + + Color getColor(unsigned int hexValue) + { + ::Color c = GetColor(hexValue); + return Color(c.r, c.g, c.b, c.a); + } + + // Text functions + void + drawText(std::string text, int posX, int posY, int fontSize, Color color) + { + DrawText( + text.c_str(), + posX, + posY, + fontSize, + {color.R(), color.G(), color.B(), color.A()}); + } + + void drawFPS(int posX, int posY) + { + DrawFPS(posX, posY); + } + + int measureText(const std::string text, int fontSize) + { + return MeasureText(text.c_str(), fontSize); + } + +} // namespace Raylib diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp new file mode 100644 index 00000000..35b01331 --- /dev/null +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -0,0 +1,143 @@ +#pragma once + +#include +#include "raylib.h" +#include "Geometry.hpp" + +namespace Raylib { + + // Window-related functions + void initWindow(int width, int height, std::string title); + bool windowShouldClose(); + void closeWindow(); + bool isWindowReady(); + bool isWindowFullscreen(); + bool isWindowHidden(); + bool isWindowMinimized(); + bool isWindowMaximized(); + bool isWindowFocused(); + bool isWindowResized(); + bool isWindowState(size_t flag); + void setWindowState(size_t flags); + void clearWindowState(size_t flags); + void toggleFullscreen(); + void maximizeWindow(); + void minimizeWindow(); + void setWindowTitle(std::string title); + int getScreenWidth(); + int getScreenHeight(); + int getRenderWidth(); + int getRenderHeight(); + int getMonitorWidth(int monitor); + int getMonitorHeight(int monitor); + int getMonitorRefreshRate(int monitor); + void setClipboardText(std::string); + std::string getClipboardText(); + void setWindowIcon(Image image); + + // Cursor-related functions + void showCursor(); + void hideCursor(); + bool isCursorHidden(); + void enableCursor(); + void disableCursor(); + bool isCursorOnScreen(); + + // Drawing-related functions + void clearBackground(Raylib::Color color); + void beginDrawing(); + void endDrawing(); + + // Timing-related functions + void setTargetFPS(int fps); + int getFPS(); + float getFrameTime(); + double getTime(); + + // Misc. functions + void takeScreenshot(std::string fileName); + + // Input-related functions: keyboard + bool isKeyPressed(int key); + bool isKeyDown(int key); + bool isKeyReleased(int key); + bool isKeyUp(int key); + void setExitKey(int key); + int getKeyPressed(); + int getCharPressed(); + + // Input-related functions: mouse + bool isMouseButtonPressed(int button); + bool isMouseButtonDown(int button); + bool isMouseButtonReleased(int button); + bool isMouseButtonUp(int button); + int getMouseX(); + int getMouseY(); + Vector2 getMousePosition(); + Vector2 getMouseDelta(); + void setMousePosition(int x, int y); + void setMouseOffset(int offsetX, int offsetY); + void setMouseScale(float scaleX, float scaleY); + float getMouseWheelMove(); + Vector2 getMouseWheelMoveV(); + void setMouseCursor(int cursor); + + // Shapes-related functions + void drawPixel(int posX, int posY, Color color); + void drawCircle(int centerX, int centerY, float radius, Color color); + void drawRectangle(int posX, int posY, int width, int height, Color color); + + class Image { + public: + Image(std::string fileName); + Image(int width, int height, Color color); + ~Image(); + bool isImageReady(); + void unloadImage(); + int getWidth(); + int getHeight(); + int getMipmaps(); + int getFormat(); + void *getData(); + + private: + ::Image _image; + }; + + class Texture2D { + public: + Texture2D(std::string fileName); + Texture2D(Image image); + ~Texture2D(); + int getId(); + int getWidth(); + int getHeight(); + int getMipmaps(); + int getFormat(); + + //draw texture functions + + void draw(int posX, int posY, Color tint); + void drawV(Vector2 position, Color tint); + void drawEx(Vector2 position, float rotation, float scale, Color tint); + void drawRec(Rectangle source, Vector2 position, Color tint); + void drawPro(Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); + + private: + void loadTextureFromImage(Image image); + ::Texture2D _texture; + }; + + // Color/pixel related functions + Color fade(Color color, float alpha); + int colorToInt(Color color); + Vector4 colorNormalize(Color color); + Color colorFromNormalized(Vector4 normalized); + Color getColor(unsigned int hexValue); + + // Text functions + void drawFPS(int posX, int posY); + void drawText(std::string text, int posX, int posY, int fontSize, Color color); + int measureText(const std::string text, int fontSize); + +} // namespace Raylib diff --git a/src/Client/Raylib/Raylib.hpp b/src/Client/Raylib/Raylib.hpp new file mode 100644 index 00000000..90525c61 --- /dev/null +++ b/src/Client/Raylib/Raylib.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include "Graphics.hpp" +#include "Geometry.hpp" +#include "Audio.hpp" From a2a44f549133fcbeff903d780cff47a456116c7e Mon Sep 17 00:00:00 2001 From: tenshi Date: Wed, 27 Sep 2023 13:53:16 +0200 Subject: [PATCH 05/23] CLIENT-GAME: Fix compilation --- src/Client/Raylib/Audio/Audio.cpp | 90 ++++++++++++------- src/Client/Raylib/Audio/Audio.hpp | 3 +- src/Client/Raylib/Geometry/Geometry.cpp | 1 - src/Client/Raylib/Geometry/Geometry.hpp | 46 +++++----- src/Client/Raylib/Graphics/Graphics.cpp | 52 ++++++----- src/Client/Raylib/Graphics/Graphics.hpp | 37 ++++---- src/Client/Raylib/Raylib.hpp | 4 +- src/Client/Systems/ClientSystems.cpp | 40 ++++----- .../Systems/Managers/GraphicManager.cpp | 11 ++- src/ECS/EventManager/EventManager.cpp | 4 +- src/ECS/Registry.hpp | 1 - src/main_client.cpp | 6 +- 12 files changed, 163 insertions(+), 132 deletions(-) diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp index e8a72a50..62755271 100644 --- a/src/Client/Raylib/Audio/Audio.cpp +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -4,118 +4,146 @@ namespace Raylib { // Audio device management functions - void initAudioDevice() { + void initAudioDevice() + { InitAudioDevice(); } - void closeAudioDevice() { + void closeAudioDevice() + { CloseAudioDevice(); } - bool isAudioDeviceReady() { + bool isAudioDeviceReady() + { return IsAudioDeviceReady(); } - void setMasterVolume(float volume) { + void setMasterVolume(float volume) + { SetMasterVolume(volume); } // Sounds - Sound::Sound(const std::string& fileName) { - sound = LoadSound(fileName.c_str()); + Sound::Sound(const std::string& fileName) + : sound(LoadSound(fileName.c_str())) + { } - Sound::~Sound() { + Sound::~Sound() + { UnloadSound(sound); } - void Sound::play() const { + void Sound::play() const + { PlaySound(sound); } - void Sound::stop() const { + void Sound::stop() const + { StopSound(sound); } - void Sound::pause() const { + void Sound::pause() const + { PauseSound(sound); } - void Sound::resume() const { + void Sound::resume() const + { ResumeSound(sound); } - bool Sound::isPlaying() const { + bool Sound::isPlaying() const + { return IsSoundPlaying(sound); } - void Sound::setVolume(float volume) const { + void Sound::setVolume(float volume) const + { SetSoundVolume(sound, volume); } - void Sound::setPitch(float pitch) const { + void Sound::setPitch(float pitch) const + { SetSoundPitch(sound, pitch); } - void Sound::setPan(float pan) const { + void Sound::setPan(float pan) const + { SetSoundPitch(sound, pan); } // Music - Music::Music(const std::string& fileName) { - music = LoadMusicStream(fileName.c_str()); + Music::Music(const std::string& fileName) + : music(LoadMusicStream(fileName.c_str())) + { } - Music::~Music() { + Music::~Music() + { UnloadMusicStream(music); } - bool Music::isReady() const { + bool Music::isReady() const + { return IsMusicStreamPlaying(music); } - void Music::play() const { + void Music::play() const + { PlayMusicStream(music); } - bool Music::isPlaying() const { + bool Music::isPlaying() const + { return IsMusicStreamPlaying(music); } - void Music::update() const { + void Music::update() const + { UpdateMusicStream(music); } - void Music::stop() const { + void Music::stop() const + { StopMusicStream(music); } - void Music::pause() const { + void Music::pause() const + { PauseMusicStream(music); } - void Music::resume() const { + void Music::resume() const + { ResumeMusicStream(music); } - void Music::setVolume(float volume) const { + void Music::setVolume(float volume) const + { SetMusicVolume(music, volume); } - void Music::setPitch(float pitch) const { + void Music::setPitch(float pitch) const + { SetMusicPitch(music, pitch); } - void Music::setPan(float pan) const { + void Music::setPan(float pan) const + { SetMusicPitch(music, pan); } - float Music::getTimeLength() const { + float Music::getTimeLength() const + { return GetMusicTimeLength(music); } - float Music::getTimePlayed() const { + float Music::getTimePlayed() const + { return GetMusicTimePlayed(music); } -} +} // namespace Raylib diff --git a/src/Client/Raylib/Audio/Audio.hpp b/src/Client/Raylib/Audio/Audio.hpp index 6b6cdff5..31d9aa5c 100644 --- a/src/Client/Raylib/Audio/Audio.hpp +++ b/src/Client/Raylib/Audio/Audio.hpp @@ -45,7 +45,8 @@ namespace Raylib { void setPan(float pan) const; float getTimeLength() const; float getTimePlayed() const; + private: ::Music music; }; -} +} // namespace Raylib diff --git a/src/Client/Raylib/Geometry/Geometry.cpp b/src/Client/Raylib/Geometry/Geometry.cpp index 0f728acb..e2e99056 100644 --- a/src/Client/Raylib/Geometry/Geometry.cpp +++ b/src/Client/Raylib/Geometry/Geometry.cpp @@ -1,5 +1,4 @@ #include "Geometry.hpp" -#include "raylib.h" namespace Raylib { Vector2::Vector2(float x, float y) : _x(x), _y(y) diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp index b5576a2e..61c67169 100644 --- a/src/Client/Raylib/Geometry/Geometry.hpp +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -102,28 +102,28 @@ namespace Raylib { }; // COLOR CONSTANTS - static const Color DarkGray = DARKGRAY; - static const Color Yellow = YELLOW; - static const Color Gold = GOLD; - static const Color Orange = ORANGE; - static const Color Pink = PINK; - static const Color Red = RED; - static const Color Maroon = MAROON; - static const Color Green = GREEN; - static const Color Lime = LIME; - static const Color DarkGreen = DARKGREEN; - static const Color SkyBlue = SKYBLUE; - static const Color Blue = BLUE; - static const Color DarkBlue = DARKBLUE; - static const Color Purple = PURPLE; - static const Color Violet = VIOLET; + static const Color DarkGray = DARKGRAY; + static const Color Yellow = YELLOW; + static const Color Gold = GOLD; + static const Color Orange = ORANGE; + static const Color Pink = PINK; + static const Color Red = RED; + static const Color Maroon = MAROON; + static const Color Green = GREEN; + static const Color Lime = LIME; + static const Color DarkGreen = DARKGREEN; + static const Color SkyBlue = SKYBLUE; + static const Color Blue = BLUE; + static const Color DarkBlue = DARKBLUE; + static const Color Purple = PURPLE; + static const Color Violet = VIOLET; static const Color DarkPurple = DARKPURPLE; - static const Color Beige = BEIGE; - static const Color Brown = BROWN; - static const Color DarkBrown = DARKBROWN; - static const Color White = WHITE; - static const Color Black = BLACK; - static const Color Blank = BLANK; - static const Color Magenta = MAGENTA; - static const Color RayWhite = RAYWHITE; + static const Color Beige = BEIGE; + static const Color Brown = BROWN; + static const Color DarkBrown = DARKBROWN; + static const Color White = WHITE; + static const Color Black = BLACK; + static const Color Blank = BLANK; + static const Color Magenta = MAGENTA; + static const Color RayWhite = RAYWHITE; } // namespace Raylib diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index 9d76b211..679c6a1b 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -287,7 +287,7 @@ namespace Raylib { Vector2 getMousePosition() { ::Vector2 position = GetMousePosition(); - return Vector2(position.x, position.y); + return Vector2 {position.x, position.y}; } int getMouseX() @@ -308,7 +308,7 @@ namespace Raylib { Vector2 getMouseDelta() { ::Vector2 delta = GetMouseDelta(); - return Vector2(delta.x, delta.y); + return Vector2 {delta.x, delta.y}; } void setMouseOffset(int offsetX, int offsetY) @@ -329,7 +329,7 @@ namespace Raylib { Vector2 getMouseWheelMoveV() { ::Vector2 move = GetMouseWheelMoveV(); - return Vector2(move.x, move.y); + return Vector2 {move.x, move.y}; } void setMouseCursor(int cursor) @@ -362,23 +362,21 @@ namespace Raylib { {color.R(), color.G(), color.B(), color.A()}); } - Image::Image(std::string fileName) + Image::Image(std::string fileName) : _image(LoadImage(fileName.c_str())) { - _image = LoadImage(fileName.c_str()); - if (!isImageReady()) { - ::Color badTexture = {255, 16, 240, 255}; + const ::Color badTexture = {255, 16, 240, 255}; static constexpr int badImageSize = 50; _image = GenImageColor(badImageSize, badImageSize, badTexture); } } Image::Image(int width, int height, Color color) - { - _image = GenImageColor( + : _image(GenImageColor( width, height, - {color.R(), color.G(), color.B(), color.A()}); + {color.R(), color.G(), color.B(), color.A()})) + { } Image::~Image() @@ -400,27 +398,27 @@ namespace Raylib { } } - int Image::getWidth() + int Image::getWidth() const { return _image.width; } - int Image::getHeight() + int Image::getHeight() const { return _image.height; } - int Image::getMipmaps() + int Image::getMipmaps() const { return _image.mipmaps; } - int Image::getFormat() + int Image::getFormat() const { return _image.format; } - void *Image::getData() + void *Image::getData() const { return _image.data; } @@ -428,17 +426,17 @@ namespace Raylib { // Texture functions Texture2D::Texture2D(std::string fileName) + : _texture(LoadTexture(fileName.c_str())) { - _texture = LoadTexture(fileName.c_str()); if (!IsTextureReady(_texture)) { - ::Color badTexture = {255, 16, 240, 255}; + static const ::Color badTexture = {255, 16, 240, 255}; static constexpr int badImageSize = 50; _texture = LoadTextureFromImage( GenImageColor(badImageSize, badImageSize, badTexture)); } } - Texture2D::Texture2D(Image image) + Texture2D::Texture2D(Image image) : _texture {0, 0, 0, 0, 0} { loadTextureFromImage(image); } @@ -459,27 +457,27 @@ namespace Raylib { UnloadTexture(_texture); } - int Texture2D::getId() + unsigned int Texture2D::getId() const { return _texture.id; } - int Texture2D::getWidth() + int Texture2D::getWidth() const { return _texture.width; } - int Texture2D::getHeight() + int Texture2D::getHeight() const { return _texture.height; } - int Texture2D::getMipmaps() + int Texture2D::getMipmaps() const { return _texture.mipmaps; } - int Texture2D::getFormat() + int Texture2D::getFormat() const { return _texture.format; } @@ -550,7 +548,7 @@ namespace Raylib { { ::Color c = {color.R(), color.G(), color.B(), color.A()}; ::Color f = Fade(c, alpha); - return Color(f.r, f.g, f.b, f.a); + return Color {f.r, f.g, f.b, f.a}; } int colorToInt(Color color) @@ -563,7 +561,7 @@ namespace Raylib { { ::Color c = {color.R(), color.G(), color.B(), color.A()}; ::Vector4 v = ColorNormalize(c); - return Vector4(v.x, v.y, v.z, v.w); + return Vector4 {v.x, v.y, v.z, v.w}; } Color colorFromNormalized(Vector4 normalized) @@ -571,13 +569,13 @@ namespace Raylib { ::Vector4 v = {normalized.X(), normalized.Y(), normalized.Z(), normalized.W()}; ::Color c = ColorFromNormalized(v); - return Color(c.r, c.g, c.b, c.a); + return Color {c.r, c.g, c.b, c.a}; } Color getColor(unsigned int hexValue) { ::Color c = GetColor(hexValue); - return Color(c.r, c.g, c.b, c.a); + return Color {c.r, c.g, c.b, c.a}; } // Text functions diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index 35b01331..789aee5e 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -94,11 +94,11 @@ namespace Raylib { ~Image(); bool isImageReady(); void unloadImage(); - int getWidth(); - int getHeight(); - int getMipmaps(); - int getFormat(); - void *getData(); + int getWidth() const; + int getHeight() const; + int getMipmaps() const; + int getFormat() const; + void *getData() const; private: ::Image _image; @@ -109,23 +109,29 @@ namespace Raylib { Texture2D(std::string fileName); Texture2D(Image image); ~Texture2D(); - int getId(); - int getWidth(); - int getHeight(); - int getMipmaps(); - int getFormat(); + unsigned int getId() const; + int getWidth() const; + int getHeight() const; + int getMipmaps() const; + int getFormat() const; - //draw texture functions + // draw texture functions void draw(int posX, int posY, Color tint); void drawV(Vector2 position, Color tint); - void drawEx(Vector2 position, float rotation, float scale, Color tint); + void + drawEx(Vector2 position, float rotation, float scale, Color tint); void drawRec(Rectangle source, Vector2 position, Color tint); - void drawPro(Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); + void drawPro( + Rectangle source, + Rectangle dest, + Vector2 origin, + float rotation, + Color tint); private: void loadTextureFromImage(Image image); - ::Texture2D _texture; + ::Texture2D _texture; }; // Color/pixel related functions @@ -137,7 +143,8 @@ namespace Raylib { // Text functions void drawFPS(int posX, int posY); - void drawText(std::string text, int posX, int posY, int fontSize, Color color); + void + drawText(std::string text, int posX, int posY, int fontSize, Color color); int measureText(const std::string text, int fontSize); } // namespace Raylib diff --git a/src/Client/Raylib/Raylib.hpp b/src/Client/Raylib/Raylib.hpp index 90525c61..b2978e32 100644 --- a/src/Client/Raylib/Raylib.hpp +++ b/src/Client/Raylib/Raylib.hpp @@ -1,5 +1,5 @@ #pragma once -#include "Graphics.hpp" -#include "Geometry.hpp" #include "Audio.hpp" +#include "Geometry.hpp" +#include "Graphics.hpp" diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index 0a3b6364..82aceb23 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -7,9 +7,9 @@ #include "ClientSystems.hpp" #include -#include "raylib.h" #include "CustomTypes.hpp" #include "Registry.hpp" +#include "Raylib.hpp" void GraphicSystems::rectRenderer(std::size_t /*unused*/) { @@ -28,16 +28,16 @@ void GraphicSystems::rectRenderer(std::size_t /*unused*/) Types::Position &position = positionIt->value(); Types::RectangleShape &rectangle = rectIt->value(); - float x = (position.x * static_cast(GetScreenWidth())) + float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; - float y = (position.y * static_cast(GetScreenHeight())) + float y = (position.y * static_cast(Raylib::getScreenHeight())) / denominator; float width = - (rectangle.width * static_cast(GetScreenWidth())) + (rectangle.width * static_cast(Raylib::getScreenWidth())) / denominator; float height = - (rectangle.height * static_cast(GetScreenHeight())) + (rectangle.height * static_cast(Raylib::getScreenHeight())) / denominator; DrawRectangle( @@ -66,16 +66,16 @@ void EventsSystems::playerMovement(std::size_t /*unused*/) while (positionIt != arrPosition.end() && playerIt != arrPlayer.end()) { if (playerIt->has_value() && positionIt->has_value() && playerIt->value().isMine) { - if (IsKeyDown(KEY_RIGHT)) { + if (Raylib::isKeyDown(KEY_RIGHT)) { positionIt->value().x += 1; } - if (IsKeyDown(KEY_LEFT)) { + if (Raylib::isKeyDown(KEY_LEFT)) { positionIt->value().x -= 1; } - if (IsKeyDown(KEY_UP)) { + if (Raylib::isKeyDown(KEY_UP)) { positionIt->value().y -= 1; } - if (IsKeyDown(KEY_DOWN)) { + if (Raylib::isKeyDown(KEY_DOWN)) { positionIt->value().y += 1; } } @@ -89,19 +89,19 @@ drawSpriteWithoutRect(Types::Position &position, Types::Sprite &sprite) { float scale = 1.0F; float rotation = 0; - auto tint = WHITE; + // Raylib::Color tint = Raylib::White; Vector2 spritePos = {0, 0}; const float denominator = 100.0; - float x = (position.x * static_cast(GetScreenWidth())) / denominator; + float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; float y = - (position.y * static_cast(GetScreenHeight())) / denominator; + (position.y * static_cast(Raylib::getScreenHeight())) / denominator; - scale = (sprite.width * static_cast(GetScreenWidth())) / denominator + scale = (sprite.width * static_cast(Raylib::getScreenWidth())) / denominator / static_cast(sprite.sprite.width); spritePos = {x, y}; - DrawTextureEx(sprite.sprite, spritePos, rotation, scale, tint); + DrawTextureEx(sprite.sprite, spritePos, rotation, scale, WHITE); } static void drawSpriteWithRect( @@ -111,17 +111,17 @@ static void drawSpriteWithRect( { Vector2 origin = {0, 0}; float rotation = 0; - auto tint = WHITE; + // Raylib::Color tint = Raylib::White; const float denominator = 100.0; - float x = (position.x * static_cast(GetScreenWidth())) / denominator; + float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; float y = - (position.y * static_cast(GetScreenHeight())) / denominator; + (position.y * static_cast(Raylib::getScreenHeight())) / denominator; float width = - (sprite.width * static_cast(GetScreenWidth())) / denominator; + (sprite.width * static_cast(Raylib::getScreenWidth())) / denominator; float height = - (sprite.height * static_cast(GetScreenHeight())) / denominator; + (sprite.height * static_cast(Raylib::getScreenHeight())) / denominator; DrawTexturePro( sprite.sprite, @@ -129,7 +129,7 @@ static void drawSpriteWithRect( Rectangle(x, y, width, height), origin, rotation, - tint); + WHITE); } void GraphicSystems::spriteRenderer(std::size_t /*unused*/) diff --git a/src/Client/Systems/Managers/GraphicManager.cpp b/src/Client/Systems/Managers/GraphicManager.cpp index 43f6f3f7..403f7043 100644 --- a/src/Client/Systems/Managers/GraphicManager.cpp +++ b/src/Client/Systems/Managers/GraphicManager.cpp @@ -7,7 +7,6 @@ #include "GraphicManager.hpp" #include -#include "raylib.h" #include "ClientSystems.hpp" #include "CustomTypes.hpp" #include "Raylib.hpp" @@ -23,7 +22,7 @@ namespace Systems { const int screenHeight = 450; const int frameRate = 60; Raylib::initWindow(screenWidth, screenHeight, "R-Type"); - SetTargetFPS(frameRate); + Raylib::setTargetFPS(frameRate); addSystem(GraphicSystems::rectRenderer); addSystem(GraphicSystems::spriteRenderer); @@ -31,7 +30,7 @@ namespace Systems { GraphicManager::~GraphicManager() { - CloseWindow(); + Raylib::closeWindow(); } GraphicManager &GraphicManager::getInstance() @@ -41,9 +40,9 @@ namespace Systems { void GraphicManager::updateSystems() { - BeginDrawing(); - ClearBackground(RAYWHITE); + Raylib::beginDrawing(); + Raylib::clearBackground(Raylib::Black); ASystemManager::updateSystems(); - EndDrawing(); + Raylib::endDrawing(); } } // namespace Systems diff --git a/src/ECS/EventManager/EventManager.cpp b/src/ECS/EventManager/EventManager.cpp index c8ebfcee..e137f6ce 100644 --- a/src/ECS/EventManager/EventManager.cpp +++ b/src/ECS/EventManager/EventManager.cpp @@ -7,7 +7,7 @@ #include "EventManager.hpp" #include -#include "raylib.h" +#include "Raylib.hpp" #include "Events.hpp" // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) @@ -23,7 +23,7 @@ void EventManager::updateEvents() { _activeEvents.clear(); for (auto event : Events::events) { - if (IsKeyDown(event)) { + if (Raylib::isKeyDown(event)) { _activeEvents.push_back(event); } } diff --git a/src/ECS/Registry.hpp b/src/ECS/Registry.hpp index 6a874ef4..79f443d1 100644 --- a/src/ECS/Registry.hpp +++ b/src/ECS/Registry.hpp @@ -15,7 +15,6 @@ #include #include #include -#include "raylib.h" #include "SparseArray.hpp" class Registry { diff --git a/src/main_client.cpp b/src/main_client.cpp index 2ec4bc3b..bc5f2ccc 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -45,9 +45,9 @@ int main() const Types::Position playerPosition = {0, 0}; const Types::Position squarePosition = {-5, 45}; const Types::Sprite playerSprite = { - LoadTexture("assets/R-TypeSheet/r-typesheet18.gif"), - 10, - 20}; + LoadTexture("assets/R-TypeSheet/r-typesheet18.gif"), + 10, + 20}; // add rectangle shape entity of 10% of the screen at the middle Registry::getInstance().addEntity(); From 3d07724a094c95e441911e61c488c7781eb75d8c Mon Sep 17 00:00:00 2001 From: tenshi Date: Wed, 27 Sep 2023 16:08:41 +0200 Subject: [PATCH 06/23] CLIENT-GAME: replace Texture2d by Sprite --- src/Client/Raylib/CMakeLists.txt | 1 + src/Client/Raylib/Events/CMakeLists.txt | 7 ++ src/Client/Raylib/Events/Inputs.hpp | 106 ++++++++++++++++++++++++ src/Client/Raylib/Graphics/Graphics.cpp | 88 +++++++++++--------- src/Client/Raylib/Graphics/Graphics.hpp | 42 ++++++---- src/Client/Raylib/Raylib.hpp | 1 + src/Client/Systems/ClientSystems.cpp | 43 +++++----- src/Client/Systems/CustomTypes.hpp | 6 -- src/ECS/EventManager/EventManager.cpp | 2 +- src/ECS/EventManager/Events.hpp | 10 +-- src/main_client.cpp | 11 ++- 11 files changed, 218 insertions(+), 99 deletions(-) create mode 100644 src/Client/Raylib/Events/CMakeLists.txt create mode 100644 src/Client/Raylib/Events/Inputs.hpp diff --git a/src/Client/Raylib/CMakeLists.txt b/src/Client/Raylib/CMakeLists.txt index 07c94c4f..ac0112b2 100644 --- a/src/Client/Raylib/CMakeLists.txt +++ b/src/Client/Raylib/CMakeLists.txt @@ -9,3 +9,4 @@ target_include_directories( add_subdirectory(Geometry) add_subdirectory(Graphics) add_subdirectory(Audio) +add_subdirectory(Events) diff --git a/src/Client/Raylib/Events/CMakeLists.txt b/src/Client/Raylib/Events/CMakeLists.txt new file mode 100644 index 00000000..979d4df7 --- /dev/null +++ b/src/Client/Raylib/Events/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.27) + +target_include_directories( + ${PROJECT_NAME_CLIENT} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/src/Client/Raylib/Events/Inputs.hpp b/src/Client/Raylib/Events/Inputs.hpp new file mode 100644 index 00000000..57a595f0 --- /dev/null +++ b/src/Client/Raylib/Events/Inputs.hpp @@ -0,0 +1,106 @@ +#pragma once + +namespace Raylib { + + enum class KeyboardKey: int { + KB_NULL = 0, + KB_APOSTROPHE = 39, + KB_COMMA = 44, + KB_MINUS = 45, + KB_PERIOD = 46, + KB_SLASH = 47, + KB_ZERO = 48, + KB_ONE = 49, + KB_TWO = 50, + KB_THREE = 51, + KB_FOUR = 52, + KB_FIVE = 53, + KB_SIX = 54, + KB_SEVEN = 55, + KB_EIGHT = 56, + KB_NINE = 57, + KB_SEMICOLON = 59, + KB_EQUAL = 61, + KB_A = 65, + KB_B = 66, + KB_C = 67, + KB_D = 68, + KB_E = 69, + KB_F = 70, + KB_G = 71, + KB_H = 72, + KB_I = 73, + KB_J = 74, + KB_K = 75, + KB_L = 76, + KB_M = 77, + KB_N = 78, + KB_O = 79, + KB_P = 80, + KB_Q = 81, + KB_R = 82, + KB_S = 83, + KB_T = 84, + KB_U = 85, + KB_V = 86, + KB_W = 87, + KB_X = 88, + KB_Y = 89, + KB_Z = 90, + KB_LEFT_BRACKET = 91, + KB_BACKSLASH = 92, + KB_RIGHT_BRACKET = 93, + KB_GRAVE = 96, + KB_SPACE = 32, + KB_ESCAPE = 256, + KB_ENTER = 257, + KB_TAB = 258, + KB_BACKSPACE = 259, + KB_INSERT = 260, + KB_DELETE = 261, + KB_RIGHT = 262, + KB_LEFT = 263, + KB_DOWN = 264, + KB_UP = 265, + KB_PAGE_UP = 266, + KB_PAGE_DOWN = 267, + KB_HOME = 268, + KB_END = 269, + KB_CAPS_LOCK = 280, + KB_SCROLL_LOCK = 281, + KB_NUM_LOCK = 282, + KB_PRINT_SCREEN = 283, + KB_PAUSE = 284, + KB_F1 = 290, + KB_F2 = 291, + KB_F3 = 292, + KB_F4 = 293, + KB_F5 = 294, + KB_F6 = 295, + KB_F7 = 296, + KB_F8 = 297, + KB_F9 = 298, + KB_F10 = 299, + KB_F11 = 300, + KB_F12 = 301, + KB_LEFT_SHIFT = 340, + KB_LEFT_CONTROL = 341, + KB_LEFT_ALT = 342, + KB_LEFT_SUPER = 343, + KB_RIGHT_SHIFT = 344, + KB_RIGHT_CONTROL = 345, + KB_RIGHT_ALT = 346, + KB_RIGHT_SUPER = 347, + KB_MENU = 348, + }; + + enum class MouseButton : int { + MOUSE_BTN_LEFT = 0, + MOUSE_BTN_RIGHT = 1, + MOUSE_BTN_MIDDLE = 2, + MOUSE_BTN_SIDE = 3, + MOUSE_BTN_EXTRA = 4, + MOUSE_BTN_FORWARD = 5, + MOUSE_BTN_BACK = 6 + }; +} diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index 679c6a1b..84162e53 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -1,5 +1,5 @@ #include "Graphics.hpp" -#include "raylib.h" +#include "Inputs.hpp" namespace Raylib { @@ -227,29 +227,29 @@ namespace Raylib { // Input-related functions: keyboard - bool isKeyPressed(int key) + bool isKeyPressed(KeyboardKey key) { - return IsKeyPressed(key); + return IsKeyPressed(static_cast(key)); } - bool isKeyDown(int key) + bool isKeyDown(KeyboardKey key) { - return IsKeyDown(key); + return IsKeyDown(static_cast(key)); } - bool isKeyReleased(int key) + bool isKeyReleased(KeyboardKey key) { - return IsKeyReleased(key); + return IsKeyReleased(static_cast(key)); } - bool isKeyUp(int key) + bool isKeyUp(KeyboardKey key) { - return IsKeyUp(key); + return IsKeyUp(static_cast(key)); } - void setExitKey(int key) + void setExitKey(KeyboardKey key) { - SetExitKey(key); + SetExitKey(static_cast(key)); } int getKeyPressed() @@ -264,24 +264,24 @@ namespace Raylib { // Input-related functions: mouse - bool isMouseButtonPressed(int button) + bool isMouseButtonPressed(MouseButton button) { - return IsMouseButtonPressed(button); + return IsMouseButtonPressed(static_cast(button)); } - bool isMouseButtonDown(int button) + bool isMouseButtonDown(MouseButton button) { - return IsMouseButtonDown(button); + return IsMouseButtonDown(static_cast(button)); } - bool isMouseButtonReleased(int button) + bool isMouseButtonReleased(MouseButton button) { - return IsMouseButtonReleased(button); + return IsMouseButtonReleased(static_cast(button)); } - bool isMouseButtonUp(int button) + bool isMouseButtonUp(MouseButton button) { - return IsMouseButtonUp(button); + return IsMouseButtonUp(static_cast(button)); } Vector2 getMousePosition() @@ -425,8 +425,7 @@ namespace Raylib { // Texture functions - Texture2D::Texture2D(std::string fileName) - : _texture(LoadTexture(fileName.c_str())) + Sprite::Sprite(std::string fileName, float width, float height): _texture(LoadTexture(fileName.c_str())), _width(width), _height(height) { if (!IsTextureReady(_texture)) { static const ::Color badTexture = {255, 16, 240, 255}; @@ -436,12 +435,13 @@ namespace Raylib { } } - Texture2D::Texture2D(Image image) : _texture {0, 0, 0, 0, 0} + Sprite::Sprite(Image image, float width, float height) + : _texture({0, 0, 0, 0}), _width(width), _height(height) { loadTextureFromImage(image); } - void Texture2D::loadTextureFromImage(Image image) + void Sprite::loadTextureFromImage(Image image) { ::Image img; img.data = image.getData(); @@ -452,39 +452,49 @@ namespace Raylib { _texture = LoadTextureFromImage(img); } - Texture2D::~Texture2D() + Sprite::~Sprite() { UnloadTexture(_texture); } - unsigned int Texture2D::getId() const + unsigned int Sprite::getId() const { return _texture.id; } - int Texture2D::getWidth() const + float Sprite::getWidth() const + { + return _width; + } + + float Sprite::getHeight() const + { + return _height; + } + + int Sprite::getTextureWidth() const { return _texture.width; } - int Texture2D::getHeight() const + int Sprite::getTextureHeight() const { return _texture.height; } - int Texture2D::getMipmaps() const + int Sprite::getMipmaps() const { return _texture.mipmaps; } - int Texture2D::getFormat() const + int Sprite::getFormat() const { return _texture.format; } // Texture drawing functions - void Texture2D::draw(int posX, int posY, Color tint) + void Sprite::draw(int posX, int posY, Color tint) { DrawTexture( _texture, @@ -493,14 +503,14 @@ namespace Raylib { {tint.R(), tint.G(), tint.B(), tint.A()}); } - void Texture2D::drawV(Vector2 position, Color tint) + void Sprite::drawV(Vector2 position, Color tint) { ::Vector2 pos = {position.X(), position.Y()}; DrawTextureV(_texture, pos, {tint.R(), tint.G(), tint.B(), tint.A()}); } void - Texture2D::drawEx(Vector2 position, float rotation, float scale, Color tint) + Sprite::drawEx(Vector2 position, float rotation, float scale, Color tint) { ::Vector2 pos = {position.X(), position.Y()}; DrawTextureEx( @@ -511,7 +521,7 @@ namespace Raylib { {tint.R(), tint.G(), tint.B(), tint.A()}); } - void Texture2D::drawRec(Rectangle source, Vector2 position, Color tint) + void Sprite::drawRec(Rectangle source, Vector2 position, Color tint) { ::Rectangle src = {source.X(), source.Y(), source.Width(), source.Height()}; @@ -523,22 +533,18 @@ namespace Raylib { {tint.R(), tint.G(), tint.B(), tint.A()}); } - void Texture2D::drawPro( + void Sprite::drawPro( Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint) { - ::Rectangle src = - {source.X(), source.Y(), source.Width(), source.Height()}; - ::Rectangle dst = {dest.X(), dest.Y(), dest.Width(), dest.Height()}; - ::Vector2 ori = {origin.X(), origin.Y()}; DrawTexturePro( _texture, - src, - dst, - ori, + {source.X(), source.Y(), source.Width(), source.Height()}, + {dest.X(), dest.Y(), dest.Width(), dest.Height()}, + {origin.X(), origin.Y()}, rotation, {tint.R(), tint.G(), tint.B(), tint.A()}); } diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index 789aee5e..b77e4e00 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -3,6 +3,7 @@ #include #include "raylib.h" #include "Geometry.hpp" +#include "Inputs.hpp" namespace Raylib { @@ -58,19 +59,19 @@ namespace Raylib { void takeScreenshot(std::string fileName); // Input-related functions: keyboard - bool isKeyPressed(int key); - bool isKeyDown(int key); - bool isKeyReleased(int key); - bool isKeyUp(int key); - void setExitKey(int key); + bool isKeyPressed(KeyboardKey key); + bool isKeyDown(KeyboardKey key); + bool isKeyReleased(KeyboardKey key); + bool isKeyUp(KeyboardKey key); + void setExitKey(KeyboardKey key); int getKeyPressed(); int getCharPressed(); // Input-related functions: mouse - bool isMouseButtonPressed(int button); - bool isMouseButtonDown(int button); - bool isMouseButtonReleased(int button); - bool isMouseButtonUp(int button); + bool isMouseButtonPressed(MouseButton button); + bool isMouseButtonDown(MouseButton button); + bool isMouseButtonReleased(MouseButton button); + bool isMouseButtonUp(MouseButton button); int getMouseX(); int getMouseY(); Vector2 getMousePosition(); @@ -104,24 +105,26 @@ namespace Raylib { ::Image _image; }; - class Texture2D { + class Sprite { public: - Texture2D(std::string fileName); - Texture2D(Image image); - ~Texture2D(); + Sprite(std::string fileName, float width, float height); + Sprite(Image image, float width, float height); + ~Sprite(); unsigned int getId() const; - int getWidth() const; - int getHeight() const; + float getWidth() const; + float getHeight() const; + int getTextureWidth() const; + int getTextureHeight() const; int getMipmaps() const; int getFormat() const; // draw texture functions void draw(int posX, int posY, Color tint); - void drawV(Vector2 position, Color tint); + void drawV(Raylib::Vector2 position, Color tint); void - drawEx(Vector2 position, float rotation, float scale, Color tint); - void drawRec(Rectangle source, Vector2 position, Color tint); + drawEx(Raylib::Vector2 position, float rotation, float scale, Color tint); + void drawRec(Raylib::Rectangle source, Raylib::Vector2 position, Color tint); void drawPro( Rectangle source, Rectangle dest, @@ -132,6 +135,9 @@ namespace Raylib { private: void loadTextureFromImage(Image image); ::Texture2D _texture; + // width and height in percentage of the screen + float _width; + float _height; }; // Color/pixel related functions diff --git a/src/Client/Raylib/Raylib.hpp b/src/Client/Raylib/Raylib.hpp index b2978e32..d7dedc1d 100644 --- a/src/Client/Raylib/Raylib.hpp +++ b/src/Client/Raylib/Raylib.hpp @@ -3,3 +3,4 @@ #include "Audio.hpp" #include "Geometry.hpp" #include "Graphics.hpp" +#include "Inputs.hpp" diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index 82aceb23..b11d6aaa 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -66,16 +66,16 @@ void EventsSystems::playerMovement(std::size_t /*unused*/) while (positionIt != arrPosition.end() && playerIt != arrPlayer.end()) { if (playerIt->has_value() && positionIt->has_value() && playerIt->value().isMine) { - if (Raylib::isKeyDown(KEY_RIGHT)) { + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_RIGHT)) { positionIt->value().x += 1; } - if (Raylib::isKeyDown(KEY_LEFT)) { + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_LEFT)) { positionIt->value().x -= 1; } - if (Raylib::isKeyDown(KEY_UP)) { + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_UP)) { positionIt->value().y -= 1; } - if (Raylib::isKeyDown(KEY_DOWN)) { + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_DOWN)) { positionIt->value().y += 1; } } @@ -85,33 +85,33 @@ void EventsSystems::playerMovement(std::size_t /*unused*/) } static void -drawSpriteWithoutRect(Types::Position &position, Types::Sprite &sprite) +drawSpriteWithoutRect(Types::Position &position, Raylib::Sprite &sprite) { float scale = 1.0F; float rotation = 0; - // Raylib::Color tint = Raylib::White; - Vector2 spritePos = {0, 0}; + Raylib::Color tint = Raylib::White; + Raylib::Vector2 spritePos = {0, 0}; const float denominator = 100.0; float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; float y = (position.y * static_cast(Raylib::getScreenHeight())) / denominator; - scale = (sprite.width * static_cast(Raylib::getScreenWidth())) / denominator - / static_cast(sprite.sprite.width); + scale = (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) / denominator + / static_cast(sprite.getTextureWidth()); spritePos = {x, y}; - DrawTextureEx(sprite.sprite, spritePos, rotation, scale, WHITE); + sprite.drawEx(spritePos, rotation, scale, tint); } static void drawSpriteWithRect( Types::Position &position, - Types::Sprite &sprite, + Raylib::Sprite &sprite, Types::Rect &rect) { - Vector2 origin = {0, 0}; + Raylib::Vector2 origin = {0, 0}; float rotation = 0; - // Raylib::Color tint = Raylib::White; + Raylib::Color tint = Raylib::White; const float denominator = 100.0; float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; @@ -119,23 +119,22 @@ static void drawSpriteWithRect( (position.y * static_cast(Raylib::getScreenHeight())) / denominator; float width = - (sprite.width * static_cast(Raylib::getScreenWidth())) / denominator; + (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) / denominator; float height = - (sprite.height * static_cast(Raylib::getScreenHeight())) / denominator; + (sprite.getHeight() * static_cast(Raylib::getScreenHeight())) / denominator; - DrawTexturePro( - sprite.sprite, - Rectangle(rect.x, rect.y, rect.width, rect.height), - Rectangle(x, y, width, height), + sprite.drawPro( + Raylib::Rectangle(rect.x, rect.y, rect.width, rect.height), + Raylib::Rectangle(x, y, width, height), origin, rotation, - WHITE); + tint); } void GraphicSystems::spriteRenderer(std::size_t /*unused*/) { - Registry::components arrSprite = - Registry::getInstance().getComponents(); + Registry::components arrSprite = + Registry::getInstance().getComponents(); Registry::components arrRect = Registry::getInstance().getComponents(); Registry::components arrPosition = diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index 3aaaa492..ca070f46 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -14,12 +14,6 @@ namespace Types { int y; }; - struct Sprite { - Texture2D sprite; - float width; - float height; - }; - struct Rect { float x; float y; diff --git a/src/ECS/EventManager/EventManager.cpp b/src/ECS/EventManager/EventManager.cpp index e137f6ce..05aa7f48 100644 --- a/src/ECS/EventManager/EventManager.cpp +++ b/src/ECS/EventManager/EventManager.cpp @@ -24,7 +24,7 @@ void EventManager::updateEvents() _activeEvents.clear(); for (auto event : Events::events) { if (Raylib::isKeyDown(event)) { - _activeEvents.push_back(event); + _activeEvents.push_back(static_cast(event)); } } } diff --git a/src/ECS/EventManager/Events.hpp b/src/ECS/EventManager/Events.hpp index f6890382..ad79e592 100644 --- a/src/ECS/EventManager/Events.hpp +++ b/src/ECS/EventManager/Events.hpp @@ -9,13 +9,13 @@ #include #include -#include "raylib.h" +#include "Raylib.hpp" namespace Events { static const auto events = { - KEY_LEFT, - KEY_RIGHT, - KEY_UP, - KEY_DOWN, + Raylib::KeyboardKey::KB_LEFT, + Raylib::KeyboardKey::KB_RIGHT, + Raylib::KeyboardKey::KB_UP, + Raylib::KeyboardKey::KB_DOWN, }; } diff --git a/src/main_client.cpp b/src/main_client.cpp index bc5f2ccc..b978be56 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -5,13 +5,12 @@ ** main */ -#include -#include "raylib.h" #include "CustomTypes.hpp" #include "GameManager.hpp" #include "GraphicManager.hpp" #include "Registry.hpp" #include "SystemEventsManager.hpp" +#include "Raylib.hpp" int main() { @@ -30,8 +29,8 @@ int main() Registry::components arrCollisionRect = Registry::getInstance().getComponents(); - Registry::components arrSprite = - Registry::getInstance().getComponents(); + Registry::components arrSprite = + Registry::getInstance().getComponents(); Registry::components arrRect = Registry::getInstance().getComponents(); @@ -44,8 +43,8 @@ int main() const Types::RectangleShape rectShape = {10, 10}; const Types::Position playerPosition = {0, 0}; const Types::Position squarePosition = {-5, 45}; - const Types::Sprite playerSprite = { - LoadTexture("assets/R-TypeSheet/r-typesheet18.gif"), + const Raylib::Sprite playerSprite = { + "assets/R-TypeSheet/r-typesheet18.gif", 10, 20}; From abf6147beba1f2c739ae899d8e54d539ae76480d Mon Sep 17 00:00:00 2001 From: tenshi Date: Wed, 27 Sep 2023 16:34:35 +0200 Subject: [PATCH 07/23] CLIENT-GAME: Fix compilation --- src/Client/Systems/ClientSystems.cpp | 270 +++++++++------------------ src/Client/Systems/CustomTypes.hpp | 5 + src/main_client.cpp | 60 +----- 3 files changed, 97 insertions(+), 238 deletions(-) diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index 91357a1a..1359b434 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -8,10 +8,11 @@ #include "ClientSystems.hpp" #include #include "CustomTypes.hpp" -#include "Registry.hpp" #include "Raylib.hpp" +#include "Registry.hpp" namespace Systems { + void GraphicSystems::rectRenderer(std::size_t /*unused*/) { Registry::components arrPosition = @@ -29,17 +30,19 @@ namespace Systems { Types::Position &position = positionIt->value(); Types::RectangleShape &rectangle = rectIt->value(); - float x = (position.x * static_cast(Raylib::getScreenWidth())) - / denominator; - float y = (position.y * static_cast(Raylib::getScreenHeight())) - / denominator; + float x = + (position.x * static_cast(Raylib::getScreenWidth())) + / denominator; + float y = + (position.y * static_cast(Raylib::getScreenHeight())) + / denominator; - float width = - (rectangle.width * static_cast(Raylib::getScreenWidth())) - / denominator; - float height = - (rectangle.height * static_cast(Raylib::getScreenHeight())) - / denominator; + float width = (rectangle.width + * static_cast(Raylib::getScreenWidth())) + / denominator; + float height = (rectangle.height + * static_cast(Raylib::getScreenHeight())) + / denominator; DrawRectangle( static_cast(x), @@ -53,65 +56,85 @@ namespace Systems { } } + void EventsSystems::playerMovement(std::size_t /*unused*/) + { + Registry::components arrPosition = + Registry::getInstance().getComponents(); + + Registry::components arrPlayer = + Registry::getInstance().getComponents(); + + auto positionIt = arrPosition.begin(); + auto playerIt = arrPlayer.begin(); + + while (positionIt != arrPosition.end() && playerIt != arrPlayer.end()) { + if (playerIt->has_value() && positionIt->has_value() + && playerIt->value().isMine) { + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_RIGHT)) { + positionIt->value().x += 1; + } + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_LEFT)) { + positionIt->value().x -= 1; + } + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_UP)) { + positionIt->value().y -= 1; + } + if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_DOWN)) { + positionIt->value().y += 1; + } + } + positionIt++; + playerIt++; + } + } + static void - drawSpriteWithoutRect(Types::Position &position, Types::Sprite &sprite) + drawSpriteWithoutRect(Types::Position &position, Raylib::Sprite &sprite) { - float scale = 1.0F; - float rotation = 0; - auto tint = WHITE; - Vector2 spritePos = {0, 0}; - const float denominator = 100.0; + float scale = 1.0F; + float rotation = 0; + Raylib::Color tint = Raylib::White; + Raylib::Vector2 spritePos = {0, 0}; + const float denominator = 100.0; - float x = - (position.x * static_cast(GetScreenWidth())) / denominator; - float y = - (position.y * static_cast(GetScreenHeight())) / denominator; + float x = (position.x * static_cast(Raylib::getScreenWidth())) + / denominator; + float y = (position.y * static_cast(Raylib::getScreenHeight())) + / denominator; - scale = (sprite.width * static_cast(GetScreenWidth())) - / denominator / static_cast(sprite.sprite.width); + scale = + (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) + / denominator / static_cast(sprite.getTextureWidth()); spritePos = {x, y}; - while (positionIt != arrPosition.end() && playerIt != arrPlayer.end()) { - if (playerIt->has_value() && positionIt->has_value() - && playerIt->value().isMine) { - if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_RIGHT)) { - positionIt->value().x += 1; - } - if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_LEFT)) { - positionIt->value().x -= 1; - } - if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_UP)) { - positionIt->value().y -= 1; - } - if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_DOWN)) { - positionIt->value().y += 1; - DrawTextureEx(sprite.sprite, spritePos, rotation, scale, tint); + sprite.drawEx(spritePos, rotation, scale, tint); } static void drawSpriteWithRect( Types::Position &position, - Types::Sprite &sprite, + Raylib::Sprite &sprite, Types::Rect &rect) { - Vector2 origin = {0, 0}; + Raylib::Vector2 origin = {0, 0}; float rotation = 0; - auto tint = WHITE; + Raylib::Color tint = Raylib::White; const float denominator = 100.0; - float x = - (position.x * static_cast(GetScreenWidth())) / denominator; - float y = - (position.y * static_cast(GetScreenHeight())) / denominator; + float x = (position.x * static_cast(Raylib::getScreenWidth())) + / denominator; + float y = (position.y * static_cast(Raylib::getScreenHeight())) + / denominator; float width = - (sprite.width * static_cast(GetScreenWidth())) / denominator; - float height = (sprite.height * static_cast(GetScreenHeight())) + (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) + / denominator; + float height = + (sprite.getHeight() * static_cast(Raylib::getScreenHeight())) / denominator; - DrawTexturePro( - sprite.sprite, - Rectangle(rect.x, rect.y, rect.width, rect.height), - Rectangle(x, y, width, height), + sprite.drawPro( + Raylib::Rectangle(rect.x, rect.y, rect.width, rect.height), + Raylib::Rectangle(x, y, width, height), origin, rotation, tint); @@ -119,8 +142,8 @@ namespace Systems { void GraphicSystems::spriteRenderer(std::size_t /*unused*/) { - Registry::components arrSprite = - Registry::getInstance().getComponents(); + Registry::components arrSprite = + Registry::getInstance().getComponents(); Registry::components arrRect = Registry::getInstance().getComponents(); Registry::components arrPosition = @@ -162,79 +185,23 @@ namespace Systems { } } - static void - drawSpriteWithoutRect(Types::Position &position, Raylib::Sprite &sprite) - { - float scale = 1.0F; - float rotation = 0; - Raylib::Color tint = Raylib::White; - Raylib::Vector2 spritePos = {0, 0}; - const float denominator = 100.0; - - float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; - float y = - (position.y * static_cast(Raylib::getScreenHeight())) / denominator; - - scale = (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) / denominator - / static_cast(sprite.getTextureWidth()); - spritePos = {x, y}; - - sprite.drawEx(spritePos, rotation, scale, tint); - } - - static void drawSpriteWithRect( - Types::Position &position, - Raylib::Sprite &sprite, - Types::Rect &rect) + void GraphicSystems::musicPlayer(std::size_t /*unused*/) { - Raylib::Vector2 origin = {0, 0}; - float rotation = 0; - Raylib::Color tint = Raylib::White; - const float denominator = 100.0; - - float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; - float y = - (position.y * static_cast(Raylib::getScreenHeight())) / denominator; - - float width = - (sprite.getWidth() * static_cast(Raylib::getScreenWidth())) / denominator; - float height = - (sprite.getHeight() * static_cast(Raylib::getScreenHeight())) / denominator; - - sprite.drawPro( - Raylib::Rectangle(rect.x, rect.y, rect.width, rect.height), - Raylib::Rectangle(x, y, width, height), - origin, - rotation, - tint); - } + Registry::components arrMusics = + Registry::getInstance().getComponents(); - void GraphicSystems::spriteRenderer(std::size_t /*unused*/) - { - Registry::components arrSprite = - Registry::getInstance().getComponents(); - Registry::components arrRect = - Registry::getInstance().getComponents(); - Registry::components arrPosition = - Registry::getInstance().getComponents(); - - auto positionIt = arrPosition.begin(); - auto spriteIt = arrSprite.begin(); - auto rectIt = arrRect.begin(); - - while (positionIt != arrPosition.end() && spriteIt != arrSprite.end()) { - if (positionIt->has_value() && spriteIt->has_value() - && rectIt->has_value()) { - drawSpriteWithRect( - positionIt->value(), - spriteIt->value(), - rectIt->value()); - } else if (positionIt->has_value() && spriteIt->has_value()) { - drawSpriteWithoutRect(positionIt->value(), spriteIt->value()); + for (auto &music : arrMusics) { + if (!music.has_value()) { + continue; + } + if (music.value().needToPlay) { + PlayMusicStream(music.value().music); + music.value().needToPlay = false; + music.value().isPlaying = true; + } + if (music.value().isPlaying) { + UpdateMusicStream(music.value().music); } - positionIt++; - spriteIt++; - rectIt++; } } @@ -278,67 +245,12 @@ namespace Systems { } } - void EventsSystems::playerMovement(std::size_t /*unused*/) - { - Registry::components arrPosition = - Registry::getInstance().getComponents(); - - Registry::components arrPlayer = - Registry::getInstance().getComponents(); - - auto positionIt = arrPosition.begin(); - auto playerIt = arrPlayer.begin(); - - while (positionIt != arrPosition.end() && playerIt != arrPlayer.end()) { - if (playerIt->has_value() && positionIt->has_value() - && playerIt->value().isMine) { - if (IsKeyDown(KEY_RIGHT)) { - positionIt->value().x += 1; - } - if (IsKeyDown(KEY_LEFT)) { - positionIt->value().x -= 1; - } - if (IsKeyDown(KEY_UP)) { - positionIt->value().y -= 1; - } - if (IsKeyDown(KEY_DOWN)) { - positionIt->value().y += 1; - } - } - positionIt++; - playerIt++; - } - } - - void GraphicSystems::musicPlayer(std::size_t /*unused*/) - { - Registry::components arrMusics = - Registry::getInstance().getComponents(); - - for (auto &music : arrMusics) { - if (!music.has_value()) { - continue; - } - if (music.value().needToPlay) { - PlayMusicStream(music.value().music); - music.value().needToPlay = false; - music.value().isPlaying = true; - } - if (music.value().isPlaying) { - UpdateMusicStream(music.value().music); - } - } - } - const std::vector> GraphicSystems::graphicSystems { rectRenderer, spriteRenderer, textRenderer, musicPlayer, - soundEffectPlayer - }; + soundEffectPlayer}; - const std::vector> - EventsSystems::eventSystems {playerMovement}; } // namespace Systems diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index 4c558a7f..59df414f 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -19,6 +19,11 @@ namespace Types { float height; }; + struct Position { + float x; + float y; + }; + struct SoundEffect { SoundEffect(std::string soundPath) : sound(LoadSound(soundPath.c_str())), diff --git a/src/main_client.cpp b/src/main_client.cpp index b978be56..feb1c814 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -5,66 +5,8 @@ ** main */ -#include "CustomTypes.hpp" -#include "GameManager.hpp" -#include "GraphicManager.hpp" -#include "Registry.hpp" -#include "SystemEventsManager.hpp" -#include "Raylib.hpp" int main() { - Systems::GameManager &gameManager = Systems::GameManager::getInstance(); - Systems::GraphicManager &graphicManager = - Systems::GraphicManager::getInstance(); - Systems::SystemEventsManager &systemEventsManager = - Systems::SystemEventsManager::getInstance(); - - Registry::components arrRectShape = - Registry::getInstance().getComponents(); - - Registry::components arrPosition = - Registry::getInstance().getComponents(); - - Registry::components arrCollisionRect = - Registry::getInstance().getComponents(); - - Registry::components arrSprite = - Registry::getInstance().getComponents(); - - Registry::components arrRect = - Registry::getInstance().getComponents(); - - Registry::components arrPlayer = - Registry::getInstance().getComponents(); - - const Types::CollisionRect playerCollisionRect = {10, 20}; - const Types::Rect playerRect = {2.0F, 5.0F, 30.5F, 25.2F}; - const Types::RectangleShape rectShape = {10, 10}; - const Types::Position playerPosition = {0, 0}; - const Types::Position squarePosition = {-5, 45}; - const Raylib::Sprite playerSprite = { - "assets/R-TypeSheet/r-typesheet18.gif", - 10, - 20}; - - // add rectangle shape entity of 10% of the screen at the middle - Registry::getInstance().addEntity(); - arrRectShape.back() = rectShape; - arrPosition.back() = squarePosition; - - // add player entity test - Registry::getInstance().addEntity(); - arrPosition.back() = playerPosition; - arrSprite.back() = playerSprite; - arrRect.back() = playerRect; - Types::Player myPlayer = {true}; - arrPlayer.back() = myPlayer; - arrCollisionRect.back() = playerCollisionRect; - - while (true) { - systemEventsManager.updateSystems(); - gameManager.updateSystems(); - graphicManager.updateSystems(); - } + return 0; } From 889327409d9926550088f304362de58e752b3f9d Mon Sep 17 00:00:00 2001 From: tenshi Date: Wed, 27 Sep 2023 17:18:52 +0200 Subject: [PATCH 08/23] CLIENT-GAME: Fix compilation --- src/Client/Systems/ClientSystems.cpp | 3 + src/main_client.cpp | 97 ++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 7 deletions(-) diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index 1359b434..49f14d9d 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -253,4 +253,7 @@ namespace Systems { musicPlayer, soundEffectPlayer}; + const std::vector> + EventsSystems::eventSystems {playerMovement}; + } // namespace Systems diff --git a/src/main_client.cpp b/src/main_client.cpp index feb1c814..f68436c5 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -1,12 +1,95 @@ -/* -** EPITECH PROJECT, 2023 -** R-Bus -** File description: -** main -*/ +#include +#include +#include "ClientSystems.hpp" +#include "CustomTypes.hpp" +#include "Raylib.hpp" +#include "Registry.hpp" +#include "SystemManagersDirector.hpp" +void init() +{ + Registry& registry = Registry::getInstance(); + const int initialEntityPositionX = 0; + const int initialEntityPositionY = 0; + const int collisionRectWidth = 10; + const int collisionRectHeight = 20; + const std::string spriteImagePath = "./assets/R-TypeSheet/r-typesheet18.gif"; + const int spriteWidth = 10; + const int spriteHeight = 20; + const float rectX = 2.0F; + const float rectY = 5.0F; + const float rectWidth = 30.5F; + const float rectHeight = 25.2F; + const int textPositionX = 40; + const int textPositionY = 40; + const std::string fontPath = "assets/Fonts/soliden/SolidenTrial-Black.otf"; + const float textFontSize = 5.5F; + const std::string soundEffectPath = "assets/Audio/Sounds/yes.ogg"; + const std::string musicStreamPath = "assets/Audio/Musics/Title.mp3"; + + registry.addEntity(); + registry.getComponents().back() = { + initialEntityPositionX, + initialEntityPositionY}; + registry.getComponents().back() = { + collisionRectWidth, + collisionRectHeight}; + registry.getComponents().back() = { + spriteImagePath, + spriteWidth, + spriteHeight}; + registry.getComponents() + .back() = {rectX, rectY, rectWidth, rectHeight}; + registry.getComponents().back() = Types::Player(true); + registry.addEntity(); + registry.getComponents().back() = { + initialEntityPositionX, + initialEntityPositionY}; + registry.getComponents().back() = { + collisionRectWidth, + collisionRectHeight}; + registry.addEntity(); + registry.getComponents().back() = { + textPositionX, + textPositionY}; + registry.getComponents() + .back() = {"Player", BLACK, LoadFont(fontPath.c_str()), textFontSize}; + registry.addEntity(); + registry.getComponents().back() = + Types::SoundEffect(soundEffectPath); + registry.addEntity(); + registry.getComponents().back() = + Types::MusicStream(musicStreamPath); +} int main() { - return 0; + const int screenWidth = 1920; + const int screenHeight = 1080; + const int fps = 60; + + Systems::SystemManagersDirector& director = + Systems::SystemManagersDirector::getInstance(); + director.addSystemManager(Systems::EventsSystems::eventSystems); + director.addSystemManager(Systems::GraphicSystems::graphicSystems); + std::vector managersIds = {1, 0, 2}; + + InitWindow( + screenWidth, + screenHeight, + "raylib [textures] examples - texture source and destination " + "rectangles"); + SetTargetFPS(fps); + InitAudioDevice(); + init(); + while (!WindowShouldClose()) { + BeginDrawing(); + ClearBackground(RAYWHITE); + for (auto id : managersIds) { + director.getSystemManager(id).updateSystems(); + } + EndDrawing(); + } + CloseAudioDevice(); + CloseWindow(); } From 5df50089cfea01fb3dfb942b9304c3b1b82d31aa Mon Sep 17 00:00:00 2001 From: Tenshi Date: Wed, 27 Sep 2023 18:08:26 +0200 Subject: [PATCH 09/23] CLIENT-GAME: Fix audio encapsulation --- src/Client/Raylib/Audio/Audio.cpp | 38 ++++++++++++++++++++++--- src/Client/Raylib/Audio/Audio.hpp | 15 ++++++++-- src/Client/Raylib/Graphics/Graphics.cpp | 7 ++++- src/Client/Raylib/Graphics/Graphics.hpp | 31 +++++++++++--------- src/Client/Systems/ClientSystems.cpp | 25 ++++++++-------- src/Client/Systems/CustomTypes.hpp | 23 --------------- src/main_client.cpp | 16 ++++++----- 7 files changed, 90 insertions(+), 65 deletions(-) diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp index 62755271..f16fb889 100644 --- a/src/Client/Raylib/Audio/Audio.cpp +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -26,11 +26,11 @@ namespace Raylib { // Sounds Sound::Sound(const std::string& fileName) - : sound(LoadSound(fileName.c_str())) + : sound(LoadSound(fileName.c_str())), _path(fileName) { } - Sound::~Sound() + void Sound::unload() { UnloadSound(sound); } @@ -75,14 +75,29 @@ namespace Raylib { SetSoundPitch(sound, pan); } + bool Sound::NeedToPlay() const + { + return _needToPlay; + } + + void Sound::setNeedToPlay(bool needToPlay) + { + _needToPlay = needToPlay; + } + + std::string Sound::getPath() const + { + return _path; + } + // Music Music::Music(const std::string& fileName) - : music(LoadMusicStream(fileName.c_str())) + : music(LoadMusicStream(fileName.c_str())), _path(fileName) { } - Music::~Music() + void Music::unload() { UnloadMusicStream(music); } @@ -146,4 +161,19 @@ namespace Raylib { { return GetMusicTimePlayed(music); } + + bool Music::NeedToPlay() const + { + return _needToPlay; + } + + void Music::setNeedToPlay(bool needToPlay) + { + _needToPlay = needToPlay; + } + + std::string Music::getPath() const + { + return _path; + } } // namespace Raylib diff --git a/src/Client/Raylib/Audio/Audio.hpp b/src/Client/Raylib/Audio/Audio.hpp index 31d9aa5c..16c2177e 100644 --- a/src/Client/Raylib/Audio/Audio.hpp +++ b/src/Client/Raylib/Audio/Audio.hpp @@ -14,8 +14,7 @@ namespace Raylib { class Sound { public: Sound(const std::string& fileName); - ~Sound(); - + void unload(); void play() const; void stop() const; void pause() const; @@ -24,15 +23,20 @@ namespace Raylib { void setVolume(float volume) const; void setPitch(float pitch) const; void setPan(float pan) const; + bool NeedToPlay() const; + void setNeedToPlay(bool needToPlay); + std::string getPath() const; private: ::Sound sound; + bool _needToPlay {false}; + std::string _path; }; class Music { public: Music(const std::string& fileName); - ~Music(); + void unload(); bool isReady() const; void play() const; bool isPlaying() const; @@ -45,8 +49,13 @@ namespace Raylib { void setPan(float pan) const; float getTimeLength() const; float getTimePlayed() const; + bool NeedToPlay() const; + void setNeedToPlay(bool needToPlay); + std::string getPath() const; private: ::Music music; + bool _needToPlay {false}; + std::string _path; }; } // namespace Raylib diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index 84162e53..b77d0d89 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -50,6 +50,11 @@ namespace Raylib { return IsWindowFocused(); } + void setConfigFlags(size_t flags) + { + SetConfigFlags(static_cast(flags)); + } + bool isWindowResized() { return IsWindowResized(); @@ -452,7 +457,7 @@ namespace Raylib { _texture = LoadTextureFromImage(img); } - Sprite::~Sprite() + void Sprite::unloadSprite() { UnloadTexture(_texture); } diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index b77e4e00..e66da599 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -17,6 +17,7 @@ namespace Raylib { bool isWindowMinimized(); bool isWindowMaximized(); bool isWindowFocused(); + void setConfigFlags(size_t flags); bool isWindowResized(); bool isWindowState(size_t flag); void setWindowState(size_t flags); @@ -88,6 +89,21 @@ namespace Raylib { void drawCircle(int centerX, int centerY, float radius, Color color); void drawRectangle(int posX, int posY, int width, int height, Color color); + // Color/pixel related functions + Color fade(Color color, float alpha); + int colorToInt(Color color); + Vector4 colorNormalize(Color color); + Color colorFromNormalized(Vector4 normalized); + Color getColor(unsigned int hexValue); + + // Text functions + void drawFPS(int posX, int posY); + void + drawText(std::string text, int posX, int posY, int fontSize, Color color); + int measureText(const std::string text, int fontSize); + + // Graphic classes + class Image { public: Image(std::string fileName); @@ -109,7 +125,6 @@ namespace Raylib { public: Sprite(std::string fileName, float width, float height); Sprite(Image image, float width, float height); - ~Sprite(); unsigned int getId() const; float getWidth() const; float getHeight() const; @@ -117,6 +132,7 @@ namespace Raylib { int getTextureHeight() const; int getMipmaps() const; int getFormat() const; + void unloadSprite(); // draw texture functions @@ -140,17 +156,4 @@ namespace Raylib { float _height; }; - // Color/pixel related functions - Color fade(Color color, float alpha); - int colorToInt(Color color); - Vector4 colorNormalize(Color color); - Color colorFromNormalized(Vector4 normalized); - Color getColor(unsigned int hexValue); - - // Text functions - void drawFPS(int posX, int posY); - void - drawText(std::string text, int posX, int posY, int fontSize, Color color); - int measureText(const std::string text, int fontSize); - } // namespace Raylib diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index 49f14d9d..b1378f78 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -171,36 +171,35 @@ namespace Systems { void GraphicSystems::soundEffectPlayer(std::size_t /*unused*/) { - Registry::components arrSoundEffect = - Registry::getInstance().getComponents(); + Registry::components arrSoundEffect = + Registry::getInstance().getComponents(); for (auto &soundEffect : arrSoundEffect) { if (!soundEffect.has_value()) { continue; } - if (soundEffect.value().needToPlay) { - PlaySound(soundEffect.value().sound); - soundEffect.value().needToPlay = false; + if (soundEffect.value().NeedToPlay()) { + soundEffect.value().play(); + soundEffect.value().setNeedToPlay(false); } } } void GraphicSystems::musicPlayer(std::size_t /*unused*/) { - Registry::components arrMusics = - Registry::getInstance().getComponents(); + Registry::components arrMusics = + Registry::getInstance().getComponents(); for (auto &music : arrMusics) { if (!music.has_value()) { continue; } - if (music.value().needToPlay) { - PlayMusicStream(music.value().music); - music.value().needToPlay = false; - music.value().isPlaying = true; + if (music.value().NeedToPlay()) { + music.value().play(); + music.value().setNeedToPlay(false); } - if (music.value().isPlaying) { - UpdateMusicStream(music.value().music); + if (music.value().isPlaying()) { + music.value().update(); } } } diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index 59df414f..ee1dbacd 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -24,29 +24,6 @@ namespace Types { float y; }; - struct SoundEffect { - SoundEffect(std::string soundPath) - : sound(LoadSound(soundPath.c_str())), - path(soundPath) - { - } - Sound sound; - bool needToPlay {false}; - std::string path; - }; - - struct MusicStream { - MusicStream(std::string musicPath) - : music(LoadMusicStream(musicPath.c_str())), - path(musicPath) - { - } - Music music; - bool needToPlay {false}; - bool isPlaying {false}; - std::string path; - }; - struct RectangleShape { float width; float height; diff --git a/src/main_client.cpp b/src/main_client.cpp index f68436c5..e9f1c0d1 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -13,7 +13,7 @@ void init() const int initialEntityPositionY = 0; const int collisionRectWidth = 10; const int collisionRectHeight = 20; - const std::string spriteImagePath = "./assets/R-TypeSheet/r-typesheet18.gif"; + const std::string spriteImagePath = "./assets/R-TypeSheet/r-typesheet18r.gif"; const int spriteWidth = 10; const int spriteHeight = 20; const float rectX = 2.0F; @@ -55,19 +55,21 @@ void init() registry.getComponents() .back() = {"Player", BLACK, LoadFont(fontPath.c_str()), textFontSize}; registry.addEntity(); - registry.getComponents().back() = - Types::SoundEffect(soundEffectPath); + registry.getComponents().back() = + Raylib::Sound(soundEffectPath); registry.addEntity(); - registry.getComponents().back() = - Types::MusicStream(musicStreamPath); + registry.getComponents().back() = + Raylib::Music(musicStreamPath); } int main() { - const int screenWidth = 1920; - const int screenHeight = 1080; + const int screenWidth = 800; + const int screenHeight = 600; const int fps = 60; + Raylib::setConfigFlags(FLAG_WINDOW_RESIZABLE); + Systems::SystemManagersDirector& director = Systems::SystemManagersDirector::getInstance(); director.addSystemManager(Systems::EventsSystems::eventSystems); From b4ca35b302e985290dbb66523e55099f2e63ad2e Mon Sep 17 00:00:00 2001 From: Tenshi Date: Wed, 27 Sep 2023 22:53:46 +0200 Subject: [PATCH 10/23] CLIENT-GAME: Add raylib encapsulation MINOR --- CMakeLists.txt | 20 +------ src/Client/Raylib/Graphics/Graphics.cpp | 74 +++++++++++++++++++++++++ src/Client/Raylib/Graphics/Graphics.hpp | 34 ++++++++++-- src/Client/Systems/ClientSystems.cpp | 36 +++++------- src/Client/Systems/CustomTypes.hpp | 8 --- src/main_client.cpp | 56 ++++++++++--------- 6 files changed, 145 insertions(+), 83 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0b76374..fad5f772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,25 +55,7 @@ install(TARGETS ${PROJECT_NAME_SERVER} add_subdirectory(deps) -# Clang-Tidy - -find_program(CLANG_TIDY_EXE NAMES "clang-tidy") - -if(CLANG_TIDY_EXE) - if (MSVC) - set_target_properties(${PROJECT_NAME_CLIENT} PROPERTIES - VS_GLOBAL_RunCodeAnalysis true - VS_GLOBAL_EnableClangTidyCodeAnalysis true - ) - set_target_properties(${PROJECT_NAME_SERVER} PROPERTIES - VS_GLOBAL_RunCodeAnalysis true - VS_GLOBAL_EnableClangTidyCodeAnalysis true - ) - else() - set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" "--fix-notes" "--fix-errors") - set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") - endif() -endif() + if(MSVC) target_compile_options( diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index b77d0d89..d2cd6f2e 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -130,6 +130,11 @@ namespace Raylib { return GetMonitorRefreshRate(monitor); } + int getCurrentMonitor() + { + return GetCurrentMonitor(); + } + void setClipboardText(std::string text) { SetClipboardText(text.c_str()); @@ -611,4 +616,73 @@ namespace Raylib { return MeasureText(text.c_str(), fontSize); } + Text::Text(std::string text, Vector2 position, float fontSize, Color color) + : _text(text), _position(position), _fontSize(fontSize), _color(color), _pixelPosition(position) + { + } + + void Text::draw() + { + DrawText( + _text.c_str(), + static_cast(_pixelPosition.X()), + static_cast(_pixelPosition.Y()), + static_cast(_fontSize), + {_color.R(), _color.G(), _color.B(), _color.A()}); + } + + void Text::drawEx(float spacing) + { + DrawTextEx( + GetFontDefault(), + _text.c_str(), + {_pixelPosition.X(), _pixelPosition.Y()}, + _fontSize, + spacing, + {_color.R(), _color.G(), _color.B(), _color.A()}); + } + + void Text::drawPro(Vector2 origin, float rotation, float spacing) + { + DrawTextPro( + GetFontDefault(), + _text.c_str(), + {_pixelPosition.X(), _pixelPosition.Y()}, + {origin.X(), origin.Y()}, + rotation, + _fontSize, + spacing, + {_color.R(), _color.G(), _color.B(), _color.A()}); + } + + float Text::x() const + { + return _position.X(); + } + + float Text::y() const + { + return _position.Y(); + } + + float Text::getFontSize() const + { + return _fontSize; + } + + void Text::setFontSize(float fontSize) + { + _fontSize = fontSize; + } + + Vector2 Text::getPosition() const + { + return _position; + } + + void Text::setPixelPosition(Vector2 position) + { + _pixelPosition = position; + } + } // namespace Raylib diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index e66da599..f8a5e107 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -33,6 +33,7 @@ namespace Raylib { int getMonitorWidth(int monitor); int getMonitorHeight(int monitor); int getMonitorRefreshRate(int monitor); + int getCurrentMonitor(); void setClipboardText(std::string); std::string getClipboardText(); void setWindowIcon(Image image); @@ -96,12 +97,6 @@ namespace Raylib { Color colorFromNormalized(Vector4 normalized); Color getColor(unsigned int hexValue); - // Text functions - void drawFPS(int posX, int posY); - void - drawText(std::string text, int posX, int posY, int fontSize, Color color); - int measureText(const std::string text, int fontSize); - // Graphic classes class Image { @@ -156,4 +151,31 @@ namespace Raylib { float _height; }; + // Text functions and classes + + class Text { + public: + Text(std::string text, Vector2 position = {0, 0}, float fontSize = 5.0F, Color color = BLACK); + void draw(); + void drawEx(float spacing); + void drawPro(Vector2 origin, float rotation, float spacing); + + float x() const; + float y() const; + float getFontSize() const; + void setFontSize(float fontSize); + Vector2 getPosition() const; + void setPixelPosition(Vector2 position); + + private: + std::string _text; + float _fontSize; + Color _color; + Vector2 _position; + Vector2 _pixelPosition; + }; + + void drawFPS(int posX, int posY); + + } // namespace Raylib diff --git a/src/Client/Systems/ClientSystems.cpp b/src/Client/Systems/ClientSystems.cpp index b1378f78..e071fd5b 100644 --- a/src/Client/Systems/ClientSystems.cpp +++ b/src/Client/Systems/ClientSystems.cpp @@ -204,42 +204,32 @@ namespace Systems { } } - static void drawTextResponsive(Types::Position &position, Types::Text &text) + static void drawTextResponsive(Raylib::Text &text) { const float denominator = 100.0; float x = - (position.x * static_cast(GetScreenWidth())) / denominator; + (text.x() * static_cast(GetScreenWidth())) / denominator; float y = - (position.y * static_cast(GetScreenHeight())) / denominator; + (text.y() * static_cast(GetScreenHeight())) / denominator; - float fsz = (text.fontSize * static_cast(GetScreenWidth())) - / denominator; - - DrawTextEx( - text.font, - text.text.data(), - Vector2(x, y), - fsz, - 0, - text.color); + + text.setPixelPosition({x, y}); + text.draw(); + std::cout << "text drawn at " << x << " " << y << std::endl; } void GraphicSystems::textRenderer(std::size_t /*unused*/) { - Registry::components arrText = - Registry::getInstance().getComponents(); - Registry::components arrPosition = - Registry::getInstance().getComponents(); + Registry::components arrText = + Registry::getInstance().getComponents(); - auto positionIt = arrPosition.begin(); - auto textIt = arrText.begin(); + auto textIt = arrText.begin(); - while (positionIt != arrPosition.end() && textIt != arrText.end()) { - if (textIt->has_value() && positionIt->has_value()) { - drawTextResponsive(positionIt->value(), textIt->value()); + while (textIt != arrText.end()) { + if (textIt->has_value()) { + drawTextResponsive(textIt->value()); } - positionIt++; textIt++; } } diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index ee1dbacd..1b066c8d 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -8,7 +8,6 @@ #pragma once #include -#include "raylib.h" namespace Types { @@ -38,11 +37,4 @@ namespace Types { bool isMine; }; - struct Text { - std::string text; - Color color; - Font font; - float fontSize; - }; - } // namespace Types diff --git a/src/main_client.cpp b/src/main_client.cpp index e9f1c0d1..fa402976 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -13,17 +13,17 @@ void init() const int initialEntityPositionY = 0; const int collisionRectWidth = 10; const int collisionRectHeight = 20; - const std::string spriteImagePath = "./assets/R-TypeSheet/r-typesheet18r.gif"; - const int spriteWidth = 10; - const int spriteHeight = 20; - const float rectX = 2.0F; - const float rectY = 5.0F; - const float rectWidth = 30.5F; - const float rectHeight = 25.2F; - const int textPositionX = 40; - const int textPositionY = 40; - const std::string fontPath = "assets/Fonts/soliden/SolidenTrial-Black.otf"; - const float textFontSize = 5.5F; + const std::string spriteImagePath = + "./assets/R-TypeSheet/r-typesheet18.gif"; + const int spriteWidth = 10; + const int spriteHeight = 20; + const float rectX = 2.0F; + const float rectY = 5.0F; + const float rectWidth = 30.5F; + const float rectHeight = 25.2F; + const Raylib::Vector2 textPosition = {50, 50}; + const float fontSize = 5.0F; + const std::string fontPath = "assets/Fonts/soliden/SolidenTrial-Black.otf"; const std::string soundEffectPath = "assets/Audio/Sounds/yes.ogg"; const std::string musicStreamPath = "assets/Audio/Musics/Title.mp3"; @@ -49,11 +49,11 @@ void init() collisionRectWidth, collisionRectHeight}; registry.addEntity(); - registry.getComponents().back() = { - textPositionX, - textPositionY}; - registry.getComponents() - .back() = {"Player", BLACK, LoadFont(fontPath.c_str()), textFontSize}; + registry.getComponents().back() = { + std::string("Hello World!"), + textPosition, + fontSize, + Raylib::Purple}; registry.addEntity(); registry.getComponents().back() = Raylib::Sound(soundEffectPath); @@ -66,7 +66,8 @@ int main() { const int screenWidth = 800; const int screenHeight = 600; - const int fps = 60; + int monitor = 0; + int fps = 0; Raylib::setConfigFlags(FLAG_WINDOW_RESIZABLE); @@ -76,22 +77,23 @@ int main() director.addSystemManager(Systems::GraphicSystems::graphicSystems); std::vector managersIds = {1, 0, 2}; - InitWindow( + Raylib::initWindow( screenWidth, screenHeight, - "raylib [textures] examples - texture source and destination " - "rectangles"); - SetTargetFPS(fps); - InitAudioDevice(); + "R-Type"); + monitor = Raylib::getCurrentMonitor(); + fps = Raylib::getMonitorRefreshRate(monitor); + Raylib::setTargetFPS(fps); + Raylib::initAudioDevice(); init(); while (!WindowShouldClose()) { - BeginDrawing(); - ClearBackground(RAYWHITE); + Raylib::beginDrawing(); + Raylib::clearBackground(Raylib::Green); for (auto id : managersIds) { director.getSystemManager(id).updateSystems(); } - EndDrawing(); + Raylib::endDrawing(); } - CloseAudioDevice(); - CloseWindow(); + Raylib::closeAudioDevice(); + Raylib::closeWindow(); } From 339237118817f9a2f8d711df8ba6af461908ccf7 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Wed, 27 Sep 2023 21:10:16 +0000 Subject: [PATCH 11/23] FORMAT-AUTO: automatic format on pull request #30 --- src/Client/EventManager/EventManager.cpp | 2 +- src/Client/Raylib/Audio/Audio.cpp | 6 +- src/Client/Raylib/Events/Inputs.hpp | 190 +++++++++--------- src/Client/Raylib/Graphics/Graphics.cpp | 15 +- src/Client/Raylib/Graphics/Graphics.hpp | 19 +- src/Client/SceneManager.cpp | 5 +- src/Client/Systems/Events/EventsSystems.cpp | 2 +- src/Client/Systems/Graphic/GraphicSystems.cpp | 3 +- 8 files changed, 131 insertions(+), 111 deletions(-) diff --git a/src/Client/EventManager/EventManager.cpp b/src/Client/EventManager/EventManager.cpp index 05aa7f48..4db10819 100644 --- a/src/Client/EventManager/EventManager.cpp +++ b/src/Client/EventManager/EventManager.cpp @@ -7,8 +7,8 @@ #include "EventManager.hpp" #include -#include "Raylib.hpp" #include "Events.hpp" +#include "Raylib.hpp" // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) EventManager EventManager::instance = EventManager(); diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp index f16fb889..73d79819 100644 --- a/src/Client/Raylib/Audio/Audio.cpp +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -26,7 +26,8 @@ namespace Raylib { // Sounds Sound::Sound(const std::string& fileName) - : sound(LoadSound(fileName.c_str())), _path(fileName) + : sound(LoadSound(fileName.c_str())), + _path(fileName) { } @@ -93,7 +94,8 @@ namespace Raylib { // Music Music::Music(const std::string& fileName) - : music(LoadMusicStream(fileName.c_str())), _path(fileName) + : music(LoadMusicStream(fileName.c_str())), + _path(fileName) { } diff --git a/src/Client/Raylib/Events/Inputs.hpp b/src/Client/Raylib/Events/Inputs.hpp index 57a595f0..b2d29c79 100644 --- a/src/Client/Raylib/Events/Inputs.hpp +++ b/src/Client/Raylib/Events/Inputs.hpp @@ -2,105 +2,105 @@ namespace Raylib { - enum class KeyboardKey: int { - KB_NULL = 0, - KB_APOSTROPHE = 39, - KB_COMMA = 44, - KB_MINUS = 45, - KB_PERIOD = 46, - KB_SLASH = 47, - KB_ZERO = 48, - KB_ONE = 49, - KB_TWO = 50, - KB_THREE = 51, - KB_FOUR = 52, - KB_FIVE = 53, - KB_SIX = 54, - KB_SEVEN = 55, - KB_EIGHT = 56, - KB_NINE = 57, - KB_SEMICOLON = 59, - KB_EQUAL = 61, - KB_A = 65, - KB_B = 66, - KB_C = 67, - KB_D = 68, - KB_E = 69, - KB_F = 70, - KB_G = 71, - KB_H = 72, - KB_I = 73, - KB_J = 74, - KB_K = 75, - KB_L = 76, - KB_M = 77, - KB_N = 78, - KB_O = 79, - KB_P = 80, - KB_Q = 81, - KB_R = 82, - KB_S = 83, - KB_T = 84, - KB_U = 85, - KB_V = 86, - KB_W = 87, - KB_X = 88, - KB_Y = 89, - KB_Z = 90, - KB_LEFT_BRACKET = 91, - KB_BACKSLASH = 92, + enum class KeyboardKey : int { + KB_NULL = 0, + KB_APOSTROPHE = 39, + KB_COMMA = 44, + KB_MINUS = 45, + KB_PERIOD = 46, + KB_SLASH = 47, + KB_ZERO = 48, + KB_ONE = 49, + KB_TWO = 50, + KB_THREE = 51, + KB_FOUR = 52, + KB_FIVE = 53, + KB_SIX = 54, + KB_SEVEN = 55, + KB_EIGHT = 56, + KB_NINE = 57, + KB_SEMICOLON = 59, + KB_EQUAL = 61, + KB_A = 65, + KB_B = 66, + KB_C = 67, + KB_D = 68, + KB_E = 69, + KB_F = 70, + KB_G = 71, + KB_H = 72, + KB_I = 73, + KB_J = 74, + KB_K = 75, + KB_L = 76, + KB_M = 77, + KB_N = 78, + KB_O = 79, + KB_P = 80, + KB_Q = 81, + KB_R = 82, + KB_S = 83, + KB_T = 84, + KB_U = 85, + KB_V = 86, + KB_W = 87, + KB_X = 88, + KB_Y = 89, + KB_Z = 90, + KB_LEFT_BRACKET = 91, + KB_BACKSLASH = 92, KB_RIGHT_BRACKET = 93, - KB_GRAVE = 96, - KB_SPACE = 32, - KB_ESCAPE = 256, - KB_ENTER = 257, - KB_TAB = 258, - KB_BACKSPACE = 259, - KB_INSERT = 260, - KB_DELETE = 261, - KB_RIGHT = 262, - KB_LEFT = 263, - KB_DOWN = 264, - KB_UP = 265, - KB_PAGE_UP = 266, - KB_PAGE_DOWN = 267, - KB_HOME = 268, - KB_END = 269, - KB_CAPS_LOCK = 280, - KB_SCROLL_LOCK = 281, - KB_NUM_LOCK = 282, - KB_PRINT_SCREEN = 283, - KB_PAUSE = 284, - KB_F1 = 290, - KB_F2 = 291, - KB_F3 = 292, - KB_F4 = 293, - KB_F5 = 294, - KB_F6 = 295, - KB_F7 = 296, - KB_F8 = 297, - KB_F9 = 298, - KB_F10 = 299, - KB_F11 = 300, - KB_F12 = 301, - KB_LEFT_SHIFT = 340, - KB_LEFT_CONTROL = 341, - KB_LEFT_ALT = 342, - KB_LEFT_SUPER = 343, - KB_RIGHT_SHIFT = 344, + KB_GRAVE = 96, + KB_SPACE = 32, + KB_ESCAPE = 256, + KB_ENTER = 257, + KB_TAB = 258, + KB_BACKSPACE = 259, + KB_INSERT = 260, + KB_DELETE = 261, + KB_RIGHT = 262, + KB_LEFT = 263, + KB_DOWN = 264, + KB_UP = 265, + KB_PAGE_UP = 266, + KB_PAGE_DOWN = 267, + KB_HOME = 268, + KB_END = 269, + KB_CAPS_LOCK = 280, + KB_SCROLL_LOCK = 281, + KB_NUM_LOCK = 282, + KB_PRINT_SCREEN = 283, + KB_PAUSE = 284, + KB_F1 = 290, + KB_F2 = 291, + KB_F3 = 292, + KB_F4 = 293, + KB_F5 = 294, + KB_F6 = 295, + KB_F7 = 296, + KB_F8 = 297, + KB_F9 = 298, + KB_F10 = 299, + KB_F11 = 300, + KB_F12 = 301, + KB_LEFT_SHIFT = 340, + KB_LEFT_CONTROL = 341, + KB_LEFT_ALT = 342, + KB_LEFT_SUPER = 343, + KB_RIGHT_SHIFT = 344, KB_RIGHT_CONTROL = 345, - KB_RIGHT_ALT = 346, - KB_RIGHT_SUPER = 347, - KB_MENU = 348, + KB_RIGHT_ALT = 346, + KB_RIGHT_SUPER = 347, + KB_MENU = 348, }; enum class MouseButton : int { - MOUSE_BTN_LEFT = 0, - MOUSE_BTN_RIGHT = 1, - MOUSE_BTN_MIDDLE = 2, - MOUSE_BTN_SIDE = 3, - MOUSE_BTN_EXTRA = 4, + MOUSE_BTN_LEFT = 0, + MOUSE_BTN_RIGHT = 1, + MOUSE_BTN_MIDDLE = 2, + MOUSE_BTN_SIDE = 3, + MOUSE_BTN_EXTRA = 4, MOUSE_BTN_FORWARD = 5, - MOUSE_BTN_BACK = 6 + MOUSE_BTN_BACK = 6 }; -} +} // namespace Raylib diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index d2cd6f2e..a005d6e7 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -435,7 +435,10 @@ namespace Raylib { // Texture functions - Sprite::Sprite(std::string fileName, float width, float height): _texture(LoadTexture(fileName.c_str())), _width(width), _height(height) + Sprite::Sprite(std::string fileName, float width, float height) + : _texture(LoadTexture(fileName.c_str())), + _width(width), + _height(height) { if (!IsTextureReady(_texture)) { static const ::Color badTexture = {255, 16, 240, 255}; @@ -446,7 +449,9 @@ namespace Raylib { } Sprite::Sprite(Image image, float width, float height) - : _texture({0, 0, 0, 0}), _width(width), _height(height) + : _texture({0, 0, 0, 0}), + _width(width), + _height(height) { loadTextureFromImage(image); } @@ -617,7 +622,11 @@ namespace Raylib { } Text::Text(std::string text, Vector2 position, float fontSize, Color color) - : _text(text), _position(position), _fontSize(fontSize), _color(color), _pixelPosition(position) + : _text(text), + _position(position), + _fontSize(fontSize), + _color(color), + _pixelPosition(position) { } diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index f8a5e107..e999d245 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -133,9 +133,15 @@ namespace Raylib { void draw(int posX, int posY, Color tint); void drawV(Raylib::Vector2 position, Color tint); - void - drawEx(Raylib::Vector2 position, float rotation, float scale, Color tint); - void drawRec(Raylib::Rectangle source, Raylib::Vector2 position, Color tint); + void drawEx( + Raylib::Vector2 position, + float rotation, + float scale, + Color tint); + void drawRec( + Raylib::Rectangle source, + Raylib::Vector2 position, + Color tint); void drawPro( Rectangle source, Rectangle dest, @@ -155,7 +161,11 @@ namespace Raylib { class Text { public: - Text(std::string text, Vector2 position = {0, 0}, float fontSize = 5.0F, Color color = BLACK); + Text( + std::string text, + Vector2 position = {0, 0}, + float fontSize = 5.0F, + Color color = BLACK); void draw(); void drawEx(float spacing); void drawPro(Vector2 origin, float rotation, float spacing); @@ -177,5 +187,4 @@ namespace Raylib { void drawFPS(int posX, int posY); - } // namespace Raylib diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index ddd1f29e..9df5e86d 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -7,9 +7,9 @@ #include "SceneManager.hpp" #include "ClientSystems.hpp" +#include "Raylib.hpp" #include "Registry.hpp" #include "SystemManagersDirector.hpp" -#include "Raylib.hpp" // to suppr #include "CustomTypes.hpp" @@ -28,7 +28,8 @@ SceneManager SceneManager::_instance = SceneManager(); static void initRaylib() { Raylib::initWindow(screenWidth, screenHeight, "R-Bus"); - Raylib::setTargetFPS(Raylib::getMonitorRefreshRate(Raylib::getCurrentMonitor())); + Raylib::setTargetFPS( + Raylib::getMonitorRefreshRate(Raylib::getCurrentMonitor())); Raylib::initAudioDevice(); Registry::getInstance().addEntity(); Registry::getInstance().getComponents().back() = { diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index 61fb0f7f..cc3f3efc 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -7,8 +7,8 @@ #include "EventsSystems.hpp" #include "CustomTypes.hpp" -#include "Registry.hpp" #include "Raylib.hpp" +#include "Registry.hpp" namespace Systems { diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 3bffa71b..56f1e29b 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -7,8 +7,8 @@ #include "GraphicSystems.hpp" #include "CustomTypes.hpp" -#include "Registry.hpp" #include "Raylib.hpp" +#include "Registry.hpp" namespace Systems { @@ -180,7 +180,6 @@ namespace Systems { float y = (text.y() * static_cast(GetScreenHeight())) / denominator; - text.setPixelPosition({x, y}); text.draw(); std::cout << "text drawn at " << x << " " << y << std::endl; From 2a8459d5ce1307ebf5ad6b42623f93fd0eedc0d6 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Thu, 28 Sep 2023 12:39:54 +0200 Subject: [PATCH 12/23] CLIENT-GAME: add sprite, music and test sound --- CMakeLists.txt | 20 +++- src/Client/Raylib/Audio/Audio.cpp | 6 +- src/Client/Raylib/Audio/Audio.hpp | 4 +- src/Client/Raylib/Graphics/Graphics.cpp | 10 +- src/Client/Raylib/Graphics/Graphics.hpp | 26 +++++- src/Client/SceneManager.cpp | 91 +++++++++++++++---- src/Client/Systems/CustomTypes.hpp | 4 - src/Client/Systems/Events/EventsSystems.cpp | 23 ++--- src/Client/Systems/Graphic/GraphicSystems.cpp | 1 - src/ECS/Registry.cpp | 2 +- src/ECS/Registry.hpp | 4 +- 11 files changed, 138 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fad5f772..e0b76374 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,25 @@ install(TARGETS ${PROJECT_NAME_SERVER} add_subdirectory(deps) - +# Clang-Tidy + +find_program(CLANG_TIDY_EXE NAMES "clang-tidy") + +if(CLANG_TIDY_EXE) + if (MSVC) + set_target_properties(${PROJECT_NAME_CLIENT} PROPERTIES + VS_GLOBAL_RunCodeAnalysis true + VS_GLOBAL_EnableClangTidyCodeAnalysis true + ) + set_target_properties(${PROJECT_NAME_SERVER} PROPERTIES + VS_GLOBAL_RunCodeAnalysis true + VS_GLOBAL_EnableClangTidyCodeAnalysis true + ) + else() + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "--fix" "--fix-notes" "--fix-errors") + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + endif() +endif() if(MSVC) target_compile_options( diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp index 73d79819..ecf5dab5 100644 --- a/src/Client/Raylib/Audio/Audio.cpp +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -25,10 +25,11 @@ namespace Raylib { } // Sounds - Sound::Sound(const std::string& fileName) + Sound::Sound(const std::string& fileName, float volume) : sound(LoadSound(fileName.c_str())), _path(fileName) { + SetSoundVolume(sound, volume); } void Sound::unload() @@ -93,10 +94,11 @@ namespace Raylib { // Music - Music::Music(const std::string& fileName) + Music::Music(const std::string& fileName, float volume) : music(LoadMusicStream(fileName.c_str())), _path(fileName) { + SetMusicVolume(music, volume); } void Music::unload() diff --git a/src/Client/Raylib/Audio/Audio.hpp b/src/Client/Raylib/Audio/Audio.hpp index 16c2177e..7e044121 100644 --- a/src/Client/Raylib/Audio/Audio.hpp +++ b/src/Client/Raylib/Audio/Audio.hpp @@ -13,7 +13,7 @@ namespace Raylib { // Sounds class Sound { public: - Sound(const std::string& fileName); + Sound(const std::string& fileName, float volume = 0.5f); void unload(); void play() const; void stop() const; @@ -35,7 +35,7 @@ namespace Raylib { class Music { public: - Music(const std::string& fileName); + Music(const std::string& fileName, float volume = 0.5f); void unload(); bool isReady() const; void play() const; diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index a005d6e7..62bda168 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -50,7 +50,7 @@ namespace Raylib { return IsWindowFocused(); } - void setConfigFlags(size_t flags) + void setConfigFlags(ConfigFlags flags) { SetConfigFlags(static_cast(flags)); } @@ -60,17 +60,17 @@ namespace Raylib { return IsWindowResized(); } - bool isWindowState(size_t flag) + bool isWindowState(ConfigFlags flag) { return IsWindowState(static_cast(flag)); } - void setWindowState(size_t flags) + void setWindowState(ConfigFlags flags) { SetWindowState(static_cast(flags)); } - void clearWindowState(size_t flags) + void clearWindowState(ConfigFlags flags) { ClearWindowState(static_cast(flags)); } @@ -622,7 +622,7 @@ namespace Raylib { } Text::Text(std::string text, Vector2 position, float fontSize, Color color) - : _text(text), + : _text(std::move(text)), _position(position), _fontSize(fontSize), _color(color), diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index e999d245..f0593d13 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -7,6 +7,24 @@ namespace Raylib { + enum class ConfigFlags { + VSYNC_HINT = 0x00000040, + FULLSCREEN_MODE = 0x00000002, + WINDOW_RESIZABLE = 0x00000004, + WINDOW_UNDECORATED = 0x00000008, + WINDOW_HIDDEN = 0x00000080, + WINDOW_MINIMIZED = 0x00000200, + WINDOW_MAXIMIZED = 0x00000400, + WINDOW_UNFOCUSED = 0x00000800, + WINDOW_TOPMOST = 0x00001000, + WINDOW_ALWAYS_RUN = 0x00000100, + WINDOW_TRANSPARENT = 0x00000010, + WINDOW_HIGHDPI = 0x00002000, + WINDOW_MOUSE_PASSTHROUGH = 0x00004000, + MSAA_4X_HINT = 0x00000020, + INTERLACED_HINT = 0x00010000 + }; + // Window-related functions void initWindow(int width, int height, std::string title); bool windowShouldClose(); @@ -17,11 +35,11 @@ namespace Raylib { bool isWindowMinimized(); bool isWindowMaximized(); bool isWindowFocused(); - void setConfigFlags(size_t flags); + void setConfigFlags(ConfigFlags flags); bool isWindowResized(); - bool isWindowState(size_t flag); - void setWindowState(size_t flags); - void clearWindowState(size_t flags); + bool isWindowState(ConfigFlags flag); + void setWindowState(ConfigFlags flag); + void clearWindowState(ConfigFlags flags); void toggleFullscreen(); void maximizeWindow(); void minimizeWindow(); diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 9df5e86d..44b35879 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -14,39 +14,92 @@ // to suppr #include "CustomTypes.hpp" -constexpr int screenWidth = 800; -constexpr int screenHeight = 600; - -// to suppr -constexpr int playerData = 10; +constexpr int screenWidth = 800; +constexpr int screenHeight = 600; +constexpr int playerData = 10; +const std::string musicPath = "assets/Audio/Musics/Title.mp3"; +const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; +const std::string playerPath = "assets/R-TypeSheet/r-typesheet14.gif"; +const Types::Rect spriteRect = {2, 2, 48, 48}; +const Types::CollisionRect collisionRect = {46, 46}; +const Raylib::Vector2 textPos = {20, 50}; +constexpr float musicVolume = 0.02F; +constexpr float soundVolume = 0.1F; +constexpr float fontScale = 20.0F; +const float playerWidth = 50.0F; +const float playerHeight = 50.0F; // 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() +// To remove +static void playSoundWithKey() +{ + Registry::components arrMusics = + Registry::getInstance().getComponents(); + Registry::components arrSounds = + Registry::getInstance().getComponents(); + + for (auto &music : arrMusics) { + if (!music.has_value()) { + continue; + } + if (music.value().getPath() == musicPath + && Raylib::isKeyPressed(Raylib::KeyboardKey::KB_SPACE)) { + music.value().setNeedToPlay(true); + } + } + for (auto &sound : arrSounds) { + if (!sound.has_value()) { + continue; + } + if (sound.value().getPath() == soundPath + && Raylib::isKeyPressed(Raylib::KeyboardKey::KB_ENTER)) { + sound.value().setNeedToPlay(true); + } + } +} +// To remove +static void addTestComponents() { - Raylib::initWindow(screenWidth, screenHeight, "R-Bus"); - Raylib::setTargetFPS( - Raylib::getMonitorRefreshRate(Raylib::getCurrentMonitor())); - Raylib::initAudioDevice(); Registry::getInstance().addEntity(); Registry::getInstance().getComponents().back() = { playerData, playerData}; - Registry::getInstance().getComponents().back() = { - playerData, - playerData}; - Registry::getInstance().getComponents().back() = { - playerData, - playerData}; + Registry::getInstance().getComponents().back() = { + playerPath, + playerWidth, playerHeight}; + Registry::getInstance().getComponents().back() = spriteRect; + Registry::getInstance().getComponents().back() = collisionRect; SparseArray &playerId = Registry::getInstance().getCustomSparseArray( CustomIndex::PLAYER); playerId.add(); playerId.back() = std::optional(Registry::getInstance().getEntitiesNb() - 1); + Registry::getInstance().getComponents().back() = { + musicPath, + musicVolume}; + Registry::getInstance().getComponents().back() = { + soundPath, + soundVolume}; + Registry::getInstance().getComponents().back() = { + "Press space to play music, enter to play sound", + textPos, + fontScale, + Raylib::DarkBlue + }; +} + +static void initRaylib() +{ + Raylib::initWindow(screenWidth, screenHeight, "R-Bus"); + Raylib::setWindowState(Raylib::ConfigFlags::WINDOW_RESIZABLE); + Raylib::setTargetFPS( + Raylib::getMonitorRefreshRate(Raylib::getCurrentMonitor())); + Raylib::initAudioDevice(); } static void initSystemManagers() @@ -57,6 +110,8 @@ static void initSystemManagers() director.addSystemManager(systems); } initRaylib(); + //to remove + addTestComponents(); } SceneManager &SceneManager::getInstance() @@ -83,10 +138,12 @@ int SceneManager::run() auto &director = Systems::SystemManagersDirector::getInstance(); try { - while (!_stop && !WindowShouldClose()) { + while (!_stop && !Raylib::windowShouldClose()) { Raylib::beginDrawing(); Raylib::clearBackground(Raylib::DarkGray); auto scene = _scenes.at(_currentScene); + //to remove + playSoundWithKey(); for (auto &systemManager : scene) { director.getSystemManager(systemManager).updateSystems(); } diff --git a/src/Client/Systems/CustomTypes.hpp b/src/Client/Systems/CustomTypes.hpp index 1b066c8d..8bfe60c5 100644 --- a/src/Client/Systems/CustomTypes.hpp +++ b/src/Client/Systems/CustomTypes.hpp @@ -33,8 +33,4 @@ namespace Types { float height; }; - struct Player { - bool isMine; - }; - } // namespace Types diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index cc3f3efc..64df7d11 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -17,30 +17,25 @@ namespace Systems { Registry::components arrPosition = Registry::getInstance().getComponents(); - Registry::components arrPlayer = - Registry::getInstance().getComponents(); + SparseArray &playerId = + Registry::getInstance().getCustomSparseArray( + CustomIndex::PLAYER); - auto positionIt = arrPosition.begin(); - auto playerIt = arrPlayer.begin(); - - while (positionIt != arrPosition.end() && playerIt != arrPlayer.end()) { - if (playerIt->has_value() && positionIt->has_value() - && playerIt->value().isMine) { + for (std::optional id : playerId) { + if (id.has_value() && arrPosition[id.value()].has_value()) { if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_RIGHT)) { - positionIt->value().x += 1; + arrPosition[id.value()].value().x += 1; } if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_LEFT)) { - positionIt->value().x -= 1; + arrPosition[id.value()].value().x -= 1; } if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_UP)) { - positionIt->value().y -= 1; + arrPosition[id.value()].value().y -= 1; } if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_DOWN)) { - positionIt->value().y += 1; + arrPosition[id.value()].value().y += 1; } } - positionIt++; - playerIt++; } } diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 56f1e29b..7964d3fb 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -182,7 +182,6 @@ namespace Systems { text.setPixelPosition({x, y}); text.draw(); - std::cout << "text drawn at " << x << " " << y << std::endl; } void GraphicSystems::textRenderer(std::size_t /*unused*/) diff --git a/src/ECS/Registry.cpp b/src/ECS/Registry.cpp index 6c381858..e57de67a 100644 --- a/src/ECS/Registry.cpp +++ b/src/ECS/Registry.cpp @@ -39,7 +39,7 @@ void Registry::clear() _entitiesNb = 0; } -std::size_t Registry::getEntitiesNb() +std::size_t Registry::getEntitiesNb() const { return (_entitiesNb); } diff --git a/src/ECS/Registry.hpp b/src/ECS/Registry.hpp index d7b794bb..a661f936 100644 --- a/src/ECS/Registry.hpp +++ b/src/ECS/Registry.hpp @@ -53,11 +53,11 @@ class Registry { return castedComponent; } catch (const std::bad_any_cast &e) { - throw std::runtime_error("Bad any cast"); + throw std::runtime_error("Bad cast: " + std::string(e.what())); } } - std::size_t getEntitiesNb(); + std::size_t getEntitiesNb() const; Registry &operator=(const Registry &) = delete; Registry(const Registry &) = delete; From e8ab87ebeeafec295f62af0699f860de12e84d1e Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 28 Sep 2023 10:41:41 +0000 Subject: [PATCH 13/23] FORMAT-AUTO: automatic format on pull request #30 --- src/Client/Raylib/Graphics/Graphics.hpp | 28 ++++++++++---------- src/Client/SceneManager.cpp | 35 +++++++++++++------------ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index f0593d13..8a5bd271 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -8,21 +8,21 @@ namespace Raylib { enum class ConfigFlags { - VSYNC_HINT = 0x00000040, - FULLSCREEN_MODE = 0x00000002, - WINDOW_RESIZABLE = 0x00000004, - WINDOW_UNDECORATED = 0x00000008, - WINDOW_HIDDEN = 0x00000080, - WINDOW_MINIMIZED = 0x00000200, - WINDOW_MAXIMIZED = 0x00000400, - WINDOW_UNFOCUSED = 0x00000800, - WINDOW_TOPMOST = 0x00001000, - WINDOW_ALWAYS_RUN = 0x00000100, - WINDOW_TRANSPARENT = 0x00000010, - WINDOW_HIGHDPI = 0x00002000, + VSYNC_HINT = 0x00000040, + FULLSCREEN_MODE = 0x00000002, + WINDOW_RESIZABLE = 0x00000004, + WINDOW_UNDECORATED = 0x00000008, + WINDOW_HIDDEN = 0x00000080, + WINDOW_MINIMIZED = 0x00000200, + WINDOW_MAXIMIZED = 0x00000400, + WINDOW_UNFOCUSED = 0x00000800, + WINDOW_TOPMOST = 0x00001000, + WINDOW_ALWAYS_RUN = 0x00000100, + WINDOW_TRANSPARENT = 0x00000010, + WINDOW_HIGHDPI = 0x00002000, WINDOW_MOUSE_PASSTHROUGH = 0x00004000, - MSAA_4X_HINT = 0x00000020, - INTERLACED_HINT = 0x00010000 + MSAA_4X_HINT = 0x00000020, + INTERLACED_HINT = 0x00010000 }; // Window-related functions diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 44b35879..13ae4fcc 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -14,20 +14,20 @@ // to suppr #include "CustomTypes.hpp" -constexpr int screenWidth = 800; -constexpr int screenHeight = 600; -constexpr int playerData = 10; -const std::string musicPath = "assets/Audio/Musics/Title.mp3"; -const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; +constexpr int screenWidth = 800; +constexpr int screenHeight = 600; +constexpr int playerData = 10; +const std::string musicPath = "assets/Audio/Musics/Title.mp3"; +const std::string soundPath = "assets/Audio/Sounds/fire.ogg"; const std::string playerPath = "assets/R-TypeSheet/r-typesheet14.gif"; const Types::Rect spriteRect = {2, 2, 48, 48}; const Types::CollisionRect collisionRect = {46, 46}; -const Raylib::Vector2 textPos = {20, 50}; -constexpr float musicVolume = 0.02F; -constexpr float soundVolume = 0.1F; -constexpr float fontScale = 20.0F; -const float playerWidth = 50.0F; -const float playerHeight = 50.0F; +const Raylib::Vector2 textPos = {20, 50}; +constexpr float musicVolume = 0.02F; +constexpr float soundVolume = 0.1F; +constexpr float fontScale = 20.0F; +const float playerWidth = 50.0F; +const float playerHeight = 50.0F; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) bool SceneManager::_init = false; @@ -70,9 +70,11 @@ static void addTestComponents() playerData}; Registry::getInstance().getComponents().back() = { playerPath, - playerWidth, playerHeight}; + playerWidth, + playerHeight}; Registry::getInstance().getComponents().back() = spriteRect; - Registry::getInstance().getComponents().back() = collisionRect; + Registry::getInstance().getComponents().back() = + collisionRect; SparseArray &playerId = Registry::getInstance().getCustomSparseArray( CustomIndex::PLAYER); @@ -89,8 +91,7 @@ static void addTestComponents() "Press space to play music, enter to play sound", textPos, fontScale, - Raylib::DarkBlue - }; + Raylib::DarkBlue}; } static void initRaylib() @@ -110,7 +111,7 @@ static void initSystemManagers() director.addSystemManager(systems); } initRaylib(); - //to remove + // to remove addTestComponents(); } @@ -142,7 +143,7 @@ int SceneManager::run() Raylib::beginDrawing(); Raylib::clearBackground(Raylib::DarkGray); auto scene = _scenes.at(_currentScene); - //to remove + // to remove playSoundWithKey(); for (auto &systemManager : scene) { director.getSystemManager(systemManager).updateSystems(); From 46ea1a862551ccc3dcfe5ddc18bb980719746a5d Mon Sep 17 00:00:00 2001 From: Tenshi Date: Thu, 28 Sep 2023 12:42:25 +0200 Subject: [PATCH 14/23] CLIENT-GAME: Fix cmake version --- src/Client/Raylib/Audio/CMakeLists.txt | 2 +- src/Client/Raylib/CMakeLists.txt | 2 +- src/Client/Raylib/Events/CMakeLists.txt | 2 +- src/Client/Raylib/Geometry/CMakeLists.txt | 2 +- src/Client/Raylib/Graphics/CMakeLists.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Client/Raylib/Audio/CMakeLists.txt b/src/Client/Raylib/Audio/CMakeLists.txt index 35acd891..e44afae6 100644 --- a/src/Client/Raylib/Audio/CMakeLists.txt +++ b/src/Client/Raylib/Audio/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.27) +cmake_minimum_required(VERSION 3.15) target_include_directories( ${PROJECT_NAME_CLIENT} diff --git a/src/Client/Raylib/CMakeLists.txt b/src/Client/Raylib/CMakeLists.txt index ac0112b2..32dfbde8 100644 --- a/src/Client/Raylib/CMakeLists.txt +++ b/src/Client/Raylib/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.27) +cmake_minimum_required(VERSION 3.15) target_include_directories( ${PROJECT_NAME_CLIENT} diff --git a/src/Client/Raylib/Events/CMakeLists.txt b/src/Client/Raylib/Events/CMakeLists.txt index 979d4df7..fc156dfc 100644 --- a/src/Client/Raylib/Events/CMakeLists.txt +++ b/src/Client/Raylib/Events/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.27) +cmake_minimum_required(VERSION 3.15) target_include_directories( ${PROJECT_NAME_CLIENT} diff --git a/src/Client/Raylib/Geometry/CMakeLists.txt b/src/Client/Raylib/Geometry/CMakeLists.txt index 33e99b3e..38cca0b5 100644 --- a/src/Client/Raylib/Geometry/CMakeLists.txt +++ b/src/Client/Raylib/Geometry/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.27) +cmake_minimum_required(VERSION 3.15) target_include_directories( ${PROJECT_NAME_CLIENT} diff --git a/src/Client/Raylib/Graphics/CMakeLists.txt b/src/Client/Raylib/Graphics/CMakeLists.txt index e61fb88b..e4c897ab 100644 --- a/src/Client/Raylib/Graphics/CMakeLists.txt +++ b/src/Client/Raylib/Graphics/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.27) +cmake_minimum_required(VERSION 3.15) target_include_directories( ${PROJECT_NAME_CLIENT} From 4b67ae255049bd0026582f204cdb2d5307151f66 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Thu, 28 Sep 2023 12:45:23 +0200 Subject: [PATCH 15/23] CLIENT-GAME: Add epitech headers --- src/Client/Raylib/Audio/Audio.cpp | 7 +++++++ src/Client/Raylib/Audio/Audio.hpp | 7 +++++++ src/Client/Raylib/Events/Inputs.hpp | 7 +++++++ src/Client/Raylib/Geometry/Geometry.cpp | 7 +++++++ src/Client/Raylib/Geometry/Geometry.hpp | 7 +++++++ src/Client/Raylib/Graphics/Graphics.cpp | 7 +++++++ src/Client/Raylib/Graphics/Graphics.hpp | 7 +++++++ src/Client/Raylib/Raylib.hpp | 7 +++++++ 8 files changed, 56 insertions(+) diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp index ecf5dab5..c1416f2f 100644 --- a/src/Client/Raylib/Audio/Audio.cpp +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Audio +*/ + #include "Audio.hpp" namespace Raylib { diff --git a/src/Client/Raylib/Audio/Audio.hpp b/src/Client/Raylib/Audio/Audio.hpp index 7e044121..e24826a1 100644 --- a/src/Client/Raylib/Audio/Audio.hpp +++ b/src/Client/Raylib/Audio/Audio.hpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Audio +*/ + #pragma once #include diff --git a/src/Client/Raylib/Events/Inputs.hpp b/src/Client/Raylib/Events/Inputs.hpp index b2d29c79..be14accf 100644 --- a/src/Client/Raylib/Events/Inputs.hpp +++ b/src/Client/Raylib/Events/Inputs.hpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Inputs +*/ + #pragma once namespace Raylib { diff --git a/src/Client/Raylib/Geometry/Geometry.cpp b/src/Client/Raylib/Geometry/Geometry.cpp index e2e99056..ed7e4bac 100644 --- a/src/Client/Raylib/Geometry/Geometry.cpp +++ b/src/Client/Raylib/Geometry/Geometry.cpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Geometry +*/ + #include "Geometry.hpp" namespace Raylib { diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp index 61c67169..d552a3d1 100644 --- a/src/Client/Raylib/Geometry/Geometry.hpp +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Geometry +*/ + #pragma once #include diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index 62bda168..07f8913e 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Graphics +*/ + #include "Graphics.hpp" #include "Inputs.hpp" diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index 8a5bd271..876a9990 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Graphics +*/ + #pragma once #include diff --git a/src/Client/Raylib/Raylib.hpp b/src/Client/Raylib/Raylib.hpp index d7dedc1d..acc6bb80 100644 --- a/src/Client/Raylib/Raylib.hpp +++ b/src/Client/Raylib/Raylib.hpp @@ -1,3 +1,10 @@ +/* +** EPITECH PROJECT, 2023 +** R-Bus +** File description: +** Raylib +*/ + #pragma once #include "Audio.hpp" From 21d99f18650b32dd7e27b54c9cadea899a15ee99 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Thu, 28 Sep 2023 12:55:46 +0200 Subject: [PATCH 16/23] CLIENT-GAME: Fix text responsive PATCH --- src/Client/Raylib/Graphics/Graphics.cpp | 14 ++++++++++---- src/Client/Raylib/Graphics/Graphics.hpp | 2 ++ src/Client/SceneManager.cpp | 2 +- src/Client/Systems/Graphic/GraphicSystems.cpp | 3 +++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index 07f8913e..5cae7941 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -633,7 +633,8 @@ namespace Raylib { _position(position), _fontSize(fontSize), _color(color), - _pixelPosition(position) + _pixelPosition(position), + _currentFontSize(fontSize) { } @@ -643,7 +644,7 @@ namespace Raylib { _text.c_str(), static_cast(_pixelPosition.X()), static_cast(_pixelPosition.Y()), - static_cast(_fontSize), + static_cast(_currentFontSize), {_color.R(), _color.G(), _color.B(), _color.A()}); } @@ -653,7 +654,7 @@ namespace Raylib { GetFontDefault(), _text.c_str(), {_pixelPosition.X(), _pixelPosition.Y()}, - _fontSize, + _currentFontSize, spacing, {_color.R(), _color.G(), _color.B(), _color.A()}); } @@ -666,7 +667,7 @@ namespace Raylib { {_pixelPosition.X(), _pixelPosition.Y()}, {origin.X(), origin.Y()}, rotation, - _fontSize, + _currentFontSize, spacing, {_color.R(), _color.G(), _color.B(), _color.A()}); } @@ -701,4 +702,9 @@ namespace Raylib { _pixelPosition = position; } + void Text::setCurrentFontSize(float fontSize) + { + _currentFontSize = fontSize; + } + } // namespace Raylib diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index 876a9990..67a73fa1 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -201,10 +201,12 @@ namespace Raylib { void setFontSize(float fontSize); Vector2 getPosition() const; void setPixelPosition(Vector2 position); + void setCurrentFontSize(float fontSize); private: std::string _text; float _fontSize; + float _currentFontSize; Color _color; Vector2 _position; Vector2 _pixelPosition; diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 13ae4fcc..01d266cf 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -25,7 +25,7 @@ const Types::CollisionRect collisionRect = {46, 46}; const Raylib::Vector2 textPos = {20, 50}; constexpr float musicVolume = 0.02F; constexpr float soundVolume = 0.1F; -constexpr float fontScale = 20.0F; +constexpr float fontScale = 2.0F; const float playerWidth = 50.0F; const float playerHeight = 50.0F; diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 7964d3fb..3f346101 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -179,8 +179,11 @@ namespace Systems { (text.x() * static_cast(GetScreenWidth())) / denominator; float y = (text.y() * static_cast(GetScreenHeight())) / denominator; + float fsz = (text.getFontSize() * static_cast(GetScreenWidth())) + / denominator; text.setPixelPosition({x, y}); + text.setCurrentFontSize(fsz); text.draw(); } From 7bfab12daa0d43ffab9f55733504ba512465ce49 Mon Sep 17 00:00:00 2001 From: Xavier Mitault Date: Thu, 28 Sep 2023 19:03:08 +0200 Subject: [PATCH 17/23] CICD: Fix windows build PATCH --- scripts/install-deps-windows.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/install-deps-windows.ps1 b/scripts/install-deps-windows.ps1 index 7d7fa28a..39aae57f 100644 --- a/scripts/install-deps-windows.ps1 +++ b/scripts/install-deps-windows.ps1 @@ -1,5 +1,12 @@ #!/bin/pwsh # Install deps -winget install --accept-package-agreements --accept-source-agreements LLVM -e -winget install --accept-package-agreements --accept-source-agreements CMake -e +winget list -e LLVM +if ($LASTEXITCODE -ne 0) { + winget install --accept-package-agreements --accept-source-agreements LLVM -e +} + +winget list -e CMake +if ($LASTEXITCODE -ne 0) { + winget install --accept-package-agreements --accept-source-agreements CMake -e +} From 205977de2e4b7d08dd4909c40e3feeb86caa4db5 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Thu, 28 Sep 2023 20:39:16 +0200 Subject: [PATCH 18/23] CLIENT-GAME: Fix merge request PATCH --- src/Client/EventManager/EventManager.cpp | 7 +- src/Client/EventManager/EventManager.hpp | 5 +- src/Client/Raylib/Audio/Audio.cpp | 52 ++--- src/Client/Raylib/Audio/Audio.hpp | 4 +- src/Client/Raylib/Events/Inputs.hpp | 193 +++++++++--------- src/Client/Raylib/Geometry/Geometry.cpp | 178 ++-------------- src/Client/Raylib/Geometry/Geometry.hpp | 113 +++------- src/Client/Raylib/Graphics/Graphics.cpp | 106 ++++++---- src/Client/Raylib/Graphics/Graphics.hpp | 42 ++-- src/Client/Systems/Graphic/GraphicSystems.cpp | 6 +- 10 files changed, 268 insertions(+), 438 deletions(-) diff --git a/src/Client/EventManager/EventManager.cpp b/src/Client/EventManager/EventManager.cpp index 4db10819..c72736f3 100644 --- a/src/Client/EventManager/EventManager.cpp +++ b/src/Client/EventManager/EventManager.cpp @@ -8,7 +8,6 @@ #include "EventManager.hpp" #include #include "Events.hpp" -#include "Raylib.hpp" // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) EventManager EventManager::instance = EventManager(); @@ -24,17 +23,17 @@ void EventManager::updateEvents() _activeEvents.clear(); for (auto event : Events::events) { if (Raylib::isKeyDown(event)) { - _activeEvents.push_back(static_cast(event)); + _activeEvents.push_back(event); } } } -bool EventManager::checkEvent(int event) +bool EventManager::checkEvent(Raylib::KeyboardKey event) { return std::any_of( _activeEvents.begin(), _activeEvents.end(), - [event](int e) { + [event](Raylib::KeyboardKey e) { return e == event; }); } diff --git a/src/Client/EventManager/EventManager.hpp b/src/Client/EventManager/EventManager.hpp index bb3adb0c..d524486b 100644 --- a/src/Client/EventManager/EventManager.hpp +++ b/src/Client/EventManager/EventManager.hpp @@ -8,12 +8,13 @@ #pragma once #include +#include "Raylib.hpp" class EventManager { public: static EventManager &getInstance(); void updateEvents(); - bool checkEvent(int event); + bool checkEvent(Raylib::KeyboardKey event); private: EventManager() = default; @@ -21,5 +22,5 @@ class EventManager { // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) static EventManager instance; // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) - std::vector _activeEvents; + std::vector _activeEvents; }; diff --git a/src/Client/Raylib/Audio/Audio.cpp b/src/Client/Raylib/Audio/Audio.cpp index c1416f2f..fe09c2a1 100644 --- a/src/Client/Raylib/Audio/Audio.cpp +++ b/src/Client/Raylib/Audio/Audio.cpp @@ -33,55 +33,55 @@ namespace Raylib { // Sounds Sound::Sound(const std::string& fileName, float volume) - : sound(LoadSound(fileName.c_str())), + : _sound(LoadSound(fileName.c_str())), _path(fileName) { - SetSoundVolume(sound, volume); + SetSoundVolume(_sound, volume); } void Sound::unload() { - UnloadSound(sound); + UnloadSound(_sound); } void Sound::play() const { - PlaySound(sound); + PlaySound(_sound); } void Sound::stop() const { - StopSound(sound); + StopSound(_sound); } void Sound::pause() const { - PauseSound(sound); + PauseSound(_sound); } void Sound::resume() const { - ResumeSound(sound); + ResumeSound(_sound); } bool Sound::isPlaying() const { - return IsSoundPlaying(sound); + return IsSoundPlaying(_sound); } void Sound::setVolume(float volume) const { - SetSoundVolume(sound, volume); + SetSoundVolume(_sound, volume); } void Sound::setPitch(float pitch) const { - SetSoundPitch(sound, pitch); + SetSoundPitch(_sound, pitch); } void Sound::setPan(float pan) const { - SetSoundPitch(sound, pan); + SetSoundPitch(_sound, pan); } bool Sound::NeedToPlay() const @@ -102,75 +102,75 @@ namespace Raylib { // Music Music::Music(const std::string& fileName, float volume) - : music(LoadMusicStream(fileName.c_str())), + : _music(LoadMusicStream(fileName.c_str())), _path(fileName) { - SetMusicVolume(music, volume); + SetMusicVolume(_music, volume); } void Music::unload() { - UnloadMusicStream(music); + UnloadMusicStream(_music); } bool Music::isReady() const { - return IsMusicStreamPlaying(music); + return IsMusicStreamPlaying(_music); } void Music::play() const { - PlayMusicStream(music); + PlayMusicStream(_music); } bool Music::isPlaying() const { - return IsMusicStreamPlaying(music); + return IsMusicStreamPlaying(_music); } void Music::update() const { - UpdateMusicStream(music); + UpdateMusicStream(_music); } void Music::stop() const { - StopMusicStream(music); + StopMusicStream(_music); } void Music::pause() const { - PauseMusicStream(music); + PauseMusicStream(_music); } void Music::resume() const { - ResumeMusicStream(music); + ResumeMusicStream(_music); } void Music::setVolume(float volume) const { - SetMusicVolume(music, volume); + SetMusicVolume(_music, volume); } void Music::setPitch(float pitch) const { - SetMusicPitch(music, pitch); + SetMusicPitch(_music, pitch); } void Music::setPan(float pan) const { - SetMusicPitch(music, pan); + SetMusicPitch(_music, pan); } float Music::getTimeLength() const { - return GetMusicTimeLength(music); + return GetMusicTimeLength(_music); } float Music::getTimePlayed() const { - return GetMusicTimePlayed(music); + return GetMusicTimePlayed(_music); } bool Music::NeedToPlay() const diff --git a/src/Client/Raylib/Audio/Audio.hpp b/src/Client/Raylib/Audio/Audio.hpp index e24826a1..b9f3e63c 100644 --- a/src/Client/Raylib/Audio/Audio.hpp +++ b/src/Client/Raylib/Audio/Audio.hpp @@ -35,7 +35,7 @@ namespace Raylib { std::string getPath() const; private: - ::Sound sound; + ::Sound _sound; bool _needToPlay {false}; std::string _path; }; @@ -61,7 +61,7 @@ namespace Raylib { std::string getPath() const; private: - ::Music music; + ::Music _music; bool _needToPlay {false}; std::string _path; }; diff --git a/src/Client/Raylib/Events/Inputs.hpp b/src/Client/Raylib/Events/Inputs.hpp index be14accf..6aafe81f 100644 --- a/src/Client/Raylib/Events/Inputs.hpp +++ b/src/Client/Raylib/Events/Inputs.hpp @@ -6,108 +6,109 @@ */ #pragma once +#include "raylib.h" namespace Raylib { enum class KeyboardKey : int { - KB_NULL = 0, - KB_APOSTROPHE = 39, - KB_COMMA = 44, - KB_MINUS = 45, - KB_PERIOD = 46, - KB_SLASH = 47, - KB_ZERO = 48, - KB_ONE = 49, - KB_TWO = 50, - KB_THREE = 51, - KB_FOUR = 52, - KB_FIVE = 53, - KB_SIX = 54, - KB_SEVEN = 55, - KB_EIGHT = 56, - KB_NINE = 57, - KB_SEMICOLON = 59, - KB_EQUAL = 61, - KB_A = 65, - KB_B = 66, - KB_C = 67, - KB_D = 68, - KB_E = 69, - KB_F = 70, - KB_G = 71, - KB_H = 72, - KB_I = 73, - KB_J = 74, - KB_K = 75, - KB_L = 76, - KB_M = 77, - KB_N = 78, - KB_O = 79, - KB_P = 80, - KB_Q = 81, - KB_R = 82, - KB_S = 83, - KB_T = 84, - KB_U = 85, - KB_V = 86, - KB_W = 87, - KB_X = 88, - KB_Y = 89, - KB_Z = 90, - KB_LEFT_BRACKET = 91, - KB_BACKSLASH = 92, - KB_RIGHT_BRACKET = 93, - KB_GRAVE = 96, - KB_SPACE = 32, - KB_ESCAPE = 256, - KB_ENTER = 257, - KB_TAB = 258, - KB_BACKSPACE = 259, - KB_INSERT = 260, - KB_DELETE = 261, - KB_RIGHT = 262, - KB_LEFT = 263, - KB_DOWN = 264, - KB_UP = 265, - KB_PAGE_UP = 266, - KB_PAGE_DOWN = 267, - KB_HOME = 268, - KB_END = 269, - KB_CAPS_LOCK = 280, - KB_SCROLL_LOCK = 281, - KB_NUM_LOCK = 282, - KB_PRINT_SCREEN = 283, - KB_PAUSE = 284, - KB_F1 = 290, - KB_F2 = 291, - KB_F3 = 292, - KB_F4 = 293, - KB_F5 = 294, - KB_F6 = 295, - KB_F7 = 296, - KB_F8 = 297, - KB_F9 = 298, - KB_F10 = 299, - KB_F11 = 300, - KB_F12 = 301, - KB_LEFT_SHIFT = 340, - KB_LEFT_CONTROL = 341, - KB_LEFT_ALT = 342, - KB_LEFT_SUPER = 343, - KB_RIGHT_SHIFT = 344, - KB_RIGHT_CONTROL = 345, - KB_RIGHT_ALT = 346, - KB_RIGHT_SUPER = 347, - KB_MENU = 348, + KB_NULL = KEY_NULL, + KB_APOSTROPHE = KEY_APOSTROPHE, + KB_COMMA = KEY_COMMA, + KB_MINUS = KEY_MINUS, + KB_PERIOD = KEY_PERIOD, + KB_SLASH = KEY_SLASH, + KB_ZERO = KEY_ZERO, + KB_ONE = KEY_ONE, + KB_TWO = KEY_TWO, + KB_THREE = KEY_THREE, + KB_FOUR = KEY_FOUR, + KB_FIVE = KEY_FIVE, + KB_SIX = KEY_SIX, + KB_SEVEN = KEY_SEVEN, + KB_EIGHT = KEY_EIGHT, + KB_NINE = KEY_NINE, + KB_SEMICOLON = KEY_SEMICOLON, + KB_EQUAL = KEY_EQUAL, + KB_A = KEY_A, + KB_B = KEY_B, + KB_C = KEY_C, + KB_D = KEY_D, + KB_E = KEY_E, + KB_F = KEY_F, + KB_G = KEY_G, + KB_H = KEY_H, + KB_I = KEY_I, + KB_J = KEY_J, + KB_K = KEY_K, + KB_L = KEY_L, + KB_M = KEY_M, + KB_N = KEY_N, + KB_O = KEY_O, + KB_P = KEY_P, + KB_Q = KEY_Q, + KB_R = KEY_R, + KB_S = KEY_S, + KB_T = KEY_T, + KB_U = KEY_U, + KB_V = KEY_V, + KB_W = KEY_W, + KB_X = KEY_X, + KB_Y = KEY_Y, + KB_Z = KEY_Z, + KB_LEFT_BRACKET = KEY_LEFT_BRACKET, + KB_BACKSLASH = KEY_BACKSLASH, + KB_RIGHT_BRACKET = KEY_RIGHT_BRACKET, + KB_GRAVE = KEY_GRAVE, + KB_SPACE = KEY_SPACE, + KB_ESCAPE = KEY_ESCAPE, + KB_ENTER = KEY_ENTER, + KB_TAB = KEY_TAB, + KB_BACKSPACE = KEY_BACKSPACE, + KB_INSERT = KEY_INSERT, + KB_DELETE = KEY_DELETE, + KB_RIGHT = KEY_RIGHT, + KB_LEFT = KEY_LEFT, + KB_DOWN = KEY_DOWN, + KB_UP = KEY_UP, + KB_PAGE_UP = KEY_PAGE_UP, + KB_PAGE_DOWN = KEY_PAGE_DOWN, + KB_HOME = KEY_HOME, + KB_END = KEY_END, + KB_CAPS_LOCK = KEY_CAPS_LOCK, + KB_SCROLL_LOCK = KEY_SCROLL_LOCK, + KB_NUM_LOCK = KEY_NUM_LOCK, + KB_PRINT_SCREEN = KEY_PRINT_SCREEN, + KB_PAUSE = KEY_PAUSE, + KB_F1 = KEY_F1, + KB_F2 = KEY_F2, + KB_F3 = KEY_F3, + KB_F4 = KEY_F4, + KB_F5 = KEY_F5, + KB_F6 = KEY_F6, + KB_F7 = KEY_F7, + KB_F8 = KEY_F8, + KB_F9 = KEY_F9, + KB_F10 = KEY_F10, + KB_F11 = KEY_F11, + KB_F12 = KEY_F12, + KB_LEFT_SHIFT = KEY_LEFT_SHIFT, + KB_LEFT_CONTROL = KEY_LEFT_CONTROL, + KB_LEFT_ALT = KEY_LEFT_ALT, + KB_LEFT_SUPER = KEY_LEFT_SUPER, + KB_RIGHT_SHIFT = KEY_RIGHT_SHIFT, + KB_RIGHT_CONTROL = KEY_RIGHT_CONTROL, + KB_RIGHT_ALT = KEY_RIGHT_ALT, + KB_RIGHT_SUPER = KEY_RIGHT_SUPER, + KB_MENU = KEY_MENU, }; enum class MouseButton : int { - MOUSE_BTN_LEFT = 0, - MOUSE_BTN_RIGHT = 1, - MOUSE_BTN_MIDDLE = 2, - MOUSE_BTN_SIDE = 3, - MOUSE_BTN_EXTRA = 4, - MOUSE_BTN_FORWARD = 5, - MOUSE_BTN_BACK = 6 + MOUSE_BTN_LEFT = MOUSE_BUTTON_LEFT, + MOUSE_BTN_RIGHT = MOUSE_BUTTON_RIGHT, + MOUSE_BTN_MIDDLE = MOUSE_BUTTON_LEFT, + MOUSE_BTN_SIDE = MOUSE_BUTTON_SIDE, + MOUSE_BTN_EXTRA = MOUSE_BUTTON_EXTRA, + MOUSE_BTN_FORWARD = MOUSE_BUTTON_FORWARD, + MOUSE_BTN_BACK = MOUSE_BUTTON_BACK, }; } // namespace Raylib diff --git a/src/Client/Raylib/Geometry/Geometry.cpp b/src/Client/Raylib/Geometry/Geometry.cpp index ed7e4bac..0f4ca8ba 100644 --- a/src/Client/Raylib/Geometry/Geometry.cpp +++ b/src/Client/Raylib/Geometry/Geometry.cpp @@ -8,181 +8,41 @@ #include "Geometry.hpp" namespace Raylib { - Vector2::Vector2(float x, float y) : _x(x), _y(y) - { - } - - float Vector2::X() const - { - return _x; - } - float Vector2::Y() const - { - return _y; - } - - void Vector2::X(float x) - { - _x = x; - } - void Vector2::Y(float y) - { - _y = y; - } - Vector3::Vector3(float x, float y, float z) : _x(x), _y(y), _z(z) + Vector2::Vector2(float x, float y) + : x(x), + y(y) { } - float Vector3::X() const - { - return _x; - } - float Vector3::Y() const - { - return _y; - } - float Vector3::Z() const + Vector3::Vector3(float x, float y, float z) + : x(x), + y(y), + z(z) { - return _z; - } - - void Vector3::X(float x) - { - _x = x; - } - void Vector3::Y(float y) - { - _y = y; - } - void Vector3::Z(float z) - { - _z = z; } Vector4::Vector4(float x, float y, float z, float w) - : _x(x), - _y(y), - _z(z), - _w(w) + : x(x), + y(y), + z(z), + w(w) { } - float Vector4::X() const - { - return _x; - } - float Vector4::Y() const - { - return _y; - } - float Vector4::Z() const - { - return _z; - } - float Vector4::W() const - { - return _w; - } - - void Vector4::X(float x) - { - _x = x; - } - void Vector4::Y(float y) - { - _y = y; - } - void Vector4::Z(float z) - { - _z = z; - } - void Vector4::W(float w) - { - _w = w; - } - Rectangle::Rectangle(float x, float y, float width, float height) - : _x(x), - _y(y), - _width(width), - _height(height) - { - } - - float Rectangle::X() const - { - return _x; - } - float Rectangle::Y() const - { - return _y; - } - float Rectangle::Width() const - { - return _width; - } - float Rectangle::Height() const - { - return _height; - } - - void Rectangle::X(float x) - { - _x = x; - } - void Rectangle::Y(float y) - { - _y = y; - } - void Rectangle::Width(float width) - { - _width = width; - } - void Rectangle::Height(float height) + : x(x), + y(y), + width(width), + height(height) { - _height = height; } Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) - : _r(r), - _g(g), - _b(b), - _a(a) - { - } - - uint8_t Color::R() const - { - return _r; - } - uint8_t Color::G() const - { - return _g; - } - uint8_t Color::B() const - { - return _b; - } - uint8_t Color::A() const - { - return _a; - } - - void Color::R(uint8_t r) - { - _r = r; - } - void Color::G(uint8_t g) - { - _g = g; - } - void Color::B(uint8_t b) - { - _b = b; - } - void Color::A(uint8_t a) + : r(r), + g(g), + b(b), + a(a) { - _a = a; } } // namespace Raylib diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp index d552a3d1..7c88a92e 100644 --- a/src/Client/Raylib/Geometry/Geometry.hpp +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -12,100 +12,41 @@ namespace Raylib { - class Vector2 { - public: - Vector2(float x, float y); - - float X() const; - float Y() const; - - void X(float x); - void Y(float y); - - private: - float _x; - float _y; + struct Vector2 { + Vector2(float x, float y); + float x; + float y; }; - class Vector3 { - public: - Vector3(float x, float y, float z); - - float X() const; - float Y() const; - float Z() const; - - void X(float x); - void Y(float y); - void Z(float z); - - private: - float _x; - float _y; - float _z; + struct Vector3 { + Vector3(float x, float y, float z); + float x; + float y; + float z; }; - class Vector4 { - public: - Vector4(float x, float y, float z, float w); - - float X() const; - float Y() const; - float Z() const; - float W() const; - - void X(float x); - void Y(float y); - void Z(float z); - void W(float w); - - private: - float _x; - float _y; - float _z; - float _w; + struct Vector4 { + Vector4(float x, float y, float z, float w); + float x; + float y; + float z; + float w; }; - class Rectangle { - public: - Rectangle(float x, float y, float width, float height); - - float X() const; - float Y() const; - float Width() const; - float Height() const; - - void X(float x); - void Y(float y); - void Width(float width); - void Height(float height); - - private: - float _x; - float _y; - float _width; - float _height; + struct Rectangle { + Rectangle(float x, float y, float width, float height); + float x; + float y; + float width; + float height; }; - class Color { - public: - Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); - - uint8_t R() const; - uint8_t G() const; - uint8_t B() const; - uint8_t A() const; - - void R(uint8_t r); - void G(uint8_t g); - void B(uint8_t b); - void A(uint8_t a); - - private: - uint8_t _r; - uint8_t _g; - uint8_t _b; - uint8_t _a; + struct Color { + Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; }; // COLOR CONSTANTS diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index 5cae7941..2a6d4c51 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -12,7 +12,7 @@ namespace Raylib { // Window-related functions - void initWindow(int width, int height, std::string title) + void initWindow(int width, int height, const std::string &title) { InitWindow(width, height, title.c_str()); } @@ -97,7 +97,7 @@ namespace Raylib { MinimizeWindow(); } - void setWindowTitle(std::string title) + void setWindowTitle(const std::string &title) { SetWindowTitle(title.c_str()); } @@ -142,7 +142,7 @@ namespace Raylib { return GetCurrentMonitor(); } - void setClipboardText(std::string text) + void setClipboardText(const std::string &text) { SetClipboardText(text.c_str()); } @@ -200,7 +200,7 @@ namespace Raylib { void clearBackground(Raylib::Color color) { - ClearBackground({color.R(), color.G(), color.B(), color.A()}); + ClearBackground({color.r, color.g, color.b, color.a}); } void beginDrawing() @@ -237,7 +237,7 @@ namespace Raylib { // Misc. functions - void takeScreenshot(std::string fileName) + void takeScreenshot(const std::string &fileName) { TakeScreenshot(fileName.c_str()); } @@ -357,29 +357,35 @@ namespace Raylib { // Shapes-related functions void drawPixel(int posX, int posY, Color color) { - DrawPixel(posX, posY, {color.R(), color.G(), color.B(), color.A()}); + ::Color c = {color.r, color.g, color.b, color.a}; + + DrawPixel(posX, posY, c); } void drawCircle(int centerX, int centerY, float radius, Color color) { + ::Color c = {color.r, color.g, color.b, color.a}; + DrawCircle( centerX, centerY, radius, - {color.R(), color.G(), color.B(), color.A()}); + c); } void drawRectangle(int posX, int posY, int width, int height, Color color) { + ::Color c = {color.r, color.g, color.b, color.a}; + DrawRectangle( posX, posY, width, height, - {color.R(), color.G(), color.B(), color.A()}); + c); } - Image::Image(std::string fileName) : _image(LoadImage(fileName.c_str())) + Image::Image(const std::string &fileName) : _image(LoadImage(fileName.c_str())) { if (!isImageReady()) { const ::Color badTexture = {255, 16, 240, 255}; @@ -392,7 +398,7 @@ namespace Raylib { : _image(GenImageColor( width, height, - {color.R(), color.G(), color.B(), color.A()})) + {color.r, color.g, color.b, color.a})) { } @@ -442,7 +448,7 @@ namespace Raylib { // Texture functions - Sprite::Sprite(std::string fileName, float width, float height) + Sprite::Sprite(const std::string &fileName, float width, float height) : _texture(LoadTexture(fileName.c_str())), _width(width), _height(height) @@ -518,41 +524,49 @@ namespace Raylib { void Sprite::draw(int posX, int posY, Color tint) { + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + DrawTexture( _texture, posX, posY, - {tint.R(), tint.G(), tint.B(), tint.A()}); + tnt); } void Sprite::drawV(Vector2 position, Color tint) { - ::Vector2 pos = {position.X(), position.Y()}; - DrawTextureV(_texture, pos, {tint.R(), tint.G(), tint.B(), tint.A()}); + ::Vector2 pos = {position.x, position.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + + DrawTextureV(_texture, pos, tnt); } void Sprite::drawEx(Vector2 position, float rotation, float scale, Color tint) { - ::Vector2 pos = {position.X(), position.Y()}; + ::Vector2 pos = {position.x, position.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + DrawTextureEx( _texture, pos, rotation, scale, - {tint.R(), tint.G(), tint.B(), tint.A()}); + tnt); } void Sprite::drawRec(Rectangle source, Vector2 position, Color tint) { ::Rectangle src = - {source.X(), source.Y(), source.Width(), source.Height()}; - ::Vector2 pos = {position.X(), position.Y()}; + {source.x, source.y, source.width, source.height}; + ::Vector2 pos = {position.x, position.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + DrawTextureRec( _texture, src, pos, - {tint.R(), tint.G(), tint.B(), tint.A()}); + tnt); } void Sprite::drawPro( @@ -562,32 +576,37 @@ namespace Raylib { float rotation, Color tint) { + ::Rectangle src = {source.x, source.y, source.width, source.height}; + ::Rectangle dst = {dest.x, dest.y, dest.width, dest.height}; + ::Vector2 org = {origin.x, origin.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + DrawTexturePro( _texture, - {source.X(), source.Y(), source.Width(), source.Height()}, - {dest.X(), dest.Y(), dest.Width(), dest.Height()}, - {origin.X(), origin.Y()}, + src, + dst, + org, rotation, - {tint.R(), tint.G(), tint.B(), tint.A()}); + tnt); } // Color/pixel related functions Color fade(Color color, float alpha) { - ::Color c = {color.R(), color.G(), color.B(), color.A()}; + ::Color c = {color.r, color.g, color.b, color.a}; ::Color f = Fade(c, alpha); return Color {f.r, f.g, f.b, f.a}; } int colorToInt(Color color) { - ::Color c = {color.R(), color.G(), color.B(), color.A()}; + ::Color c = {color.r, color.g, color.b, color.a}; return ColorToInt(c); } Vector4 colorNormalize(Color color) { - ::Color c = {color.R(), color.G(), color.B(), color.A()}; + ::Color c = {color.r, color.g, color.b, color.a}; ::Vector4 v = ColorNormalize(c); return Vector4 {v.x, v.y, v.z, v.w}; } @@ -595,7 +614,7 @@ namespace Raylib { Color colorFromNormalized(Vector4 normalized) { ::Vector4 v = - {normalized.X(), normalized.Y(), normalized.Z(), normalized.W()}; + {normalized.x, normalized.y, normalized.z, normalized.w}; ::Color c = ColorFromNormalized(v); return Color {c.r, c.g, c.b, c.a}; } @@ -610,12 +629,14 @@ namespace Raylib { void drawText(std::string text, int posX, int posY, int fontSize, Color color) { + ::Color textColor = {color.r, color.g, color.b, color.a}; + DrawText( text.c_str(), posX, posY, fontSize, - {color.R(), color.G(), color.B(), color.A()}); + textColor); } void drawFPS(int posX, int posY) @@ -640,46 +661,55 @@ namespace Raylib { void Text::draw() { + ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; + DrawText( _text.c_str(), - static_cast(_pixelPosition.X()), - static_cast(_pixelPosition.Y()), + static_cast(_pixelPosition.x), + static_cast(_pixelPosition.y), static_cast(_currentFontSize), - {_color.R(), _color.G(), _color.B(), _color.A()}); + textColor); } void Text::drawEx(float spacing) { + ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; + ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; + DrawTextEx( GetFontDefault(), _text.c_str(), - {_pixelPosition.X(), _pixelPosition.Y()}, + pos, _currentFontSize, spacing, - {_color.R(), _color.G(), _color.B(), _color.A()}); + textColor); } void Text::drawPro(Vector2 origin, float rotation, float spacing) { + ::Vector2 textOrigin = {origin.x, origin.y}; + ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; + ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; + DrawTextPro( GetFontDefault(), _text.c_str(), - {_pixelPosition.X(), _pixelPosition.Y()}, - {origin.X(), origin.Y()}, + pos, + textOrigin, rotation, _currentFontSize, spacing, - {_color.R(), _color.G(), _color.B(), _color.A()}); + textColor); } float Text::x() const { - return _position.X(); + return _position.x; } float Text::y() const { - return _position.Y(); + return _position.y; } float Text::getFontSize() const diff --git a/src/Client/Raylib/Graphics/Graphics.hpp b/src/Client/Raylib/Graphics/Graphics.hpp index 67a73fa1..f5b1a17f 100644 --- a/src/Client/Raylib/Graphics/Graphics.hpp +++ b/src/Client/Raylib/Graphics/Graphics.hpp @@ -15,25 +15,25 @@ namespace Raylib { enum class ConfigFlags { - VSYNC_HINT = 0x00000040, - FULLSCREEN_MODE = 0x00000002, - WINDOW_RESIZABLE = 0x00000004, - WINDOW_UNDECORATED = 0x00000008, - WINDOW_HIDDEN = 0x00000080, - WINDOW_MINIMIZED = 0x00000200, - WINDOW_MAXIMIZED = 0x00000400, - WINDOW_UNFOCUSED = 0x00000800, - WINDOW_TOPMOST = 0x00001000, - WINDOW_ALWAYS_RUN = 0x00000100, - WINDOW_TRANSPARENT = 0x00000010, - WINDOW_HIGHDPI = 0x00002000, - WINDOW_MOUSE_PASSTHROUGH = 0x00004000, - MSAA_4X_HINT = 0x00000020, - INTERLACED_HINT = 0x00010000 + VSYNC_HINT = FLAG_VSYNC_HINT, + FULLSCREEN_MODE = FLAG_FULLSCREEN_MODE, + WINDOW_RESIZABLE = FLAG_WINDOW_RESIZABLE, + WINDOW_UNDECORATED = FLAG_WINDOW_UNDECORATED, + WINDOW_HIDDEN = FLAG_WINDOW_HIDDEN, + WINDOW_MINIMIZED = FLAG_WINDOW_MINIMIZED, + WINDOW_MAXIMIZED = FLAG_WINDOW_MAXIMIZED, + WINDOW_UNFOCUSED = FLAG_WINDOW_UNFOCUSED, + WINDOW_TOPMOST = FLAG_WINDOW_TOPMOST, + WINDOW_ALWAYS_RUN = FLAG_WINDOW_ALWAYS_RUN, + WINDOW_TRANSPARENT = FLAG_WINDOW_TRANSPARENT, + WINDOW_HIGHDPI = FLAG_WINDOW_HIGHDPI, + WINDOW_MOUSE_PASSTHROUGH = FLAG_WINDOW_MOUSE_PASSTHROUGH, + MSAA_4X_HINT = FLAG_MSAA_4X_HINT, + INTERLACED_HINT = FLAG_INTERLACED_HINT, }; // Window-related functions - void initWindow(int width, int height, std::string title); + void initWindow(int width, int height, const std::string &title); bool windowShouldClose(); void closeWindow(); bool isWindowReady(); @@ -50,7 +50,7 @@ namespace Raylib { void toggleFullscreen(); void maximizeWindow(); void minimizeWindow(); - void setWindowTitle(std::string title); + void setWindowTitle(const std::string &title); int getScreenWidth(); int getScreenHeight(); int getRenderWidth(); @@ -59,7 +59,7 @@ namespace Raylib { int getMonitorHeight(int monitor); int getMonitorRefreshRate(int monitor); int getCurrentMonitor(); - void setClipboardText(std::string); + void setClipboardText(const std::string &text); std::string getClipboardText(); void setWindowIcon(Image image); @@ -83,7 +83,7 @@ namespace Raylib { double getTime(); // Misc. functions - void takeScreenshot(std::string fileName); + void takeScreenshot(const std::string &fileName); // Input-related functions: keyboard bool isKeyPressed(KeyboardKey key); @@ -126,7 +126,7 @@ namespace Raylib { class Image { public: - Image(std::string fileName); + Image(const std::string &fileName); Image(int width, int height, Color color); ~Image(); bool isImageReady(); @@ -143,7 +143,7 @@ namespace Raylib { class Sprite { public: - Sprite(std::string fileName, float width, float height); + Sprite(const std::string &fileName, float width, float height); Sprite(Image image, float width, float height); unsigned int getId() const; float getWidth() const; diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 3f346101..c15b29f1 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -175,10 +175,8 @@ namespace Systems { { const float denominator = 100.0; - float x = - (text.x() * static_cast(GetScreenWidth())) / denominator; - float y = - (text.y() * static_cast(GetScreenHeight())) / denominator; + float x = (text.x() * static_cast(GetScreenWidth())) / denominator; + float y = (text.y() * static_cast(GetScreenHeight())) / denominator; float fsz = (text.getFontSize() * static_cast(GetScreenWidth())) / denominator; From 7ab17d77a869497a60bd04f35f2e309918ba27de Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 28 Sep 2023 18:40:47 +0000 Subject: [PATCH 19/23] FORMAT-AUTO: automatic format on pull request #30 --- src/Client/Raylib/Geometry/Geometry.cpp | 9 +- src/Client/Raylib/Geometry/Geometry.hpp | 44 +++++----- src/Client/Raylib/Graphics/Graphics.cpp | 86 ++++++------------- src/Client/Systems/Graphic/GraphicSystems.cpp | 6 +- 4 files changed, 53 insertions(+), 92 deletions(-) diff --git a/src/Client/Raylib/Geometry/Geometry.cpp b/src/Client/Raylib/Geometry/Geometry.cpp index 0f4ca8ba..80f891a5 100644 --- a/src/Client/Raylib/Geometry/Geometry.cpp +++ b/src/Client/Raylib/Geometry/Geometry.cpp @@ -9,16 +9,11 @@ namespace Raylib { - Vector2::Vector2(float x, float y) - : x(x), - y(y) + Vector2::Vector2(float x, float y) : x(x), y(y) { } - Vector3::Vector3(float x, float y, float z) - : x(x), - y(y), - z(z) + Vector3::Vector3(float x, float y, float z) : x(x), y(y), z(z) { } diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp index 7c88a92e..07ea3caa 100644 --- a/src/Client/Raylib/Geometry/Geometry.hpp +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -13,40 +13,40 @@ namespace Raylib { struct Vector2 { - Vector2(float x, float y); - float x; - float y; + Vector2(float x, float y); + float x; + float y; }; struct Vector3 { - Vector3(float x, float y, float z); - float x; - float y; - float z; + Vector3(float x, float y, float z); + float x; + float y; + float z; }; struct Vector4 { - Vector4(float x, float y, float z, float w); - float x; - float y; - float z; - float w; + Vector4(float x, float y, float z, float w); + float x; + float y; + float z; + float w; }; struct Rectangle { - Rectangle(float x, float y, float width, float height); - float x; - float y; - float width; - float height; + Rectangle(float x, float y, float width, float height); + float x; + float y; + float width; + float height; }; struct Color { - Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t a; + Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; }; // COLOR CONSTANTS diff --git a/src/Client/Raylib/Graphics/Graphics.cpp b/src/Client/Raylib/Graphics/Graphics.cpp index 2a6d4c51..1e09d9c5 100644 --- a/src/Client/Raylib/Graphics/Graphics.cpp +++ b/src/Client/Raylib/Graphics/Graphics.cpp @@ -366,26 +366,18 @@ namespace Raylib { { ::Color c = {color.r, color.g, color.b, color.a}; - DrawCircle( - centerX, - centerY, - radius, - c); + DrawCircle(centerX, centerY, radius, c); } void drawRectangle(int posX, int posY, int width, int height, Color color) { ::Color c = {color.r, color.g, color.b, color.a}; - DrawRectangle( - posX, - posY, - width, - height, - c); + DrawRectangle(posX, posY, width, height, c); } - Image::Image(const std::string &fileName) : _image(LoadImage(fileName.c_str())) + Image::Image(const std::string &fileName) + : _image(LoadImage(fileName.c_str())) { if (!isImageReady()) { const ::Color badTexture = {255, 16, 240, 255}; @@ -395,10 +387,8 @@ namespace Raylib { } Image::Image(int width, int height, Color color) - : _image(GenImageColor( - width, - height, - {color.r, color.g, color.b, color.a})) + : _image( + GenImageColor(width, height, {color.r, color.g, color.b, color.a})) { } @@ -526,17 +516,13 @@ namespace Raylib { { ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; - DrawTexture( - _texture, - posX, - posY, - tnt); + DrawTexture(_texture, posX, posY, tnt); } void Sprite::drawV(Vector2 position, Color tint) { ::Vector2 pos = {position.x, position.y}; - ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; DrawTextureV(_texture, pos, tnt); } @@ -545,28 +531,18 @@ namespace Raylib { Sprite::drawEx(Vector2 position, float rotation, float scale, Color tint) { ::Vector2 pos = {position.x, position.y}; - ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; - DrawTextureEx( - _texture, - pos, - rotation, - scale, - tnt); + DrawTextureEx(_texture, pos, rotation, scale, tnt); } void Sprite::drawRec(Rectangle source, Vector2 position, Color tint) { - ::Rectangle src = - {source.x, source.y, source.width, source.height}; - ::Vector2 pos = {position.x, position.y}; - ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + ::Rectangle src = {source.x, source.y, source.width, source.height}; + ::Vector2 pos = {position.x, position.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; - DrawTextureRec( - _texture, - src, - pos, - tnt); + DrawTextureRec(_texture, src, pos, tnt); } void Sprite::drawPro( @@ -576,18 +552,12 @@ namespace Raylib { float rotation, Color tint) { - ::Rectangle src = {source.x, source.y, source.width, source.height}; - ::Rectangle dst = {dest.x, dest.y, dest.width, dest.height}; - ::Vector2 org = {origin.x, origin.y}; - ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; + ::Rectangle src = {source.x, source.y, source.width, source.height}; + ::Rectangle dst = {dest.x, dest.y, dest.width, dest.height}; + ::Vector2 org = {origin.x, origin.y}; + ::Color tnt = {tint.r, tint.g, tint.b, tint.a}; - DrawTexturePro( - _texture, - src, - dst, - org, - rotation, - tnt); + DrawTexturePro(_texture, src, dst, org, rotation, tnt); } // Color/pixel related functions @@ -613,9 +583,8 @@ namespace Raylib { Color colorFromNormalized(Vector4 normalized) { - ::Vector4 v = - {normalized.x, normalized.y, normalized.z, normalized.w}; - ::Color c = ColorFromNormalized(v); + ::Vector4 v = {normalized.x, normalized.y, normalized.z, normalized.w}; + ::Color c = ColorFromNormalized(v); return Color {c.r, c.g, c.b, c.a}; } @@ -631,12 +600,7 @@ namespace Raylib { { ::Color textColor = {color.r, color.g, color.b, color.a}; - DrawText( - text.c_str(), - posX, - posY, - fontSize, - textColor); + DrawText(text.c_str(), posX, posY, fontSize, textColor); } void drawFPS(int posX, int posY) @@ -673,8 +637,8 @@ namespace Raylib { void Text::drawEx(float spacing) { - ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; - ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; + ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; + ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; DrawTextEx( GetFontDefault(), @@ -688,7 +652,7 @@ namespace Raylib { void Text::drawPro(Vector2 origin, float rotation, float spacing) { ::Vector2 textOrigin = {origin.x, origin.y}; - ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; + ::Vector2 pos = {_pixelPosition.x, _pixelPosition.y}; ::Color textColor = {_color.r, _color.g, _color.b, _color.a}; DrawTextPro( diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index c15b29f1..3f346101 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -175,8 +175,10 @@ namespace Systems { { const float denominator = 100.0; - float x = (text.x() * static_cast(GetScreenWidth())) / denominator; - float y = (text.y() * static_cast(GetScreenHeight())) / denominator; + float x = + (text.x() * static_cast(GetScreenWidth())) / denominator; + float y = + (text.y() * static_cast(GetScreenHeight())) / denominator; float fsz = (text.getFontSize() * static_cast(GetScreenWidth())) / denominator; From 7dafa4de09a9ec2768fcaa6cd0fc02cd6bef059e Mon Sep 17 00:00:00 2001 From: Tenshi Date: Thu, 28 Sep 2023 21:09:11 +0200 Subject: [PATCH 20/23] CLIENT-GAME: Fix merge request PATCH --- src/Client/Raylib/Geometry/Geometry.hpp | 26 ------------------- src/Client/SceneManager.cpp | 6 +++-- src/Client/Systems/Graphic/GraphicSystems.cpp | 4 +-- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp index 7c88a92e..40520b91 100644 --- a/src/Client/Raylib/Geometry/Geometry.hpp +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -48,30 +48,4 @@ namespace Raylib { uint8_t b; uint8_t a; }; - - // COLOR CONSTANTS - static const Color DarkGray = DARKGRAY; - static const Color Yellow = YELLOW; - static const Color Gold = GOLD; - static const Color Orange = ORANGE; - static const Color Pink = PINK; - static const Color Red = RED; - static const Color Maroon = MAROON; - static const Color Green = GREEN; - static const Color Lime = LIME; - static const Color DarkGreen = DARKGREEN; - static const Color SkyBlue = SKYBLUE; - static const Color Blue = BLUE; - static const Color DarkBlue = DARKBLUE; - static const Color Purple = PURPLE; - static const Color Violet = VIOLET; - static const Color DarkPurple = DARKPURPLE; - static const Color Beige = BEIGE; - static const Color Brown = BROWN; - static const Color DarkBrown = DARKBROWN; - static const Color White = WHITE; - static const Color Black = BLACK; - static const Color Blank = BLANK; - static const Color Magenta = MAGENTA; - static const Color RayWhite = RAYWHITE; } // namespace Raylib diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 01d266cf..9a2cd8d3 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -28,6 +28,8 @@ constexpr float soundVolume = 0.1F; constexpr float fontScale = 2.0F; const float playerWidth = 50.0F; const float playerHeight = 50.0F; +const Raylib::Color darkBlue = {0, 0, 139, 255}; +const Raylib::Color darkGray = {169, 169, 169, 255}; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) bool SceneManager::_init = false; @@ -91,7 +93,7 @@ static void addTestComponents() "Press space to play music, enter to play sound", textPos, fontScale, - Raylib::DarkBlue}; + darkBlue}; } static void initRaylib() @@ -141,7 +143,7 @@ int SceneManager::run() try { while (!_stop && !Raylib::windowShouldClose()) { Raylib::beginDrawing(); - Raylib::clearBackground(Raylib::DarkGray); + Raylib::clearBackground(darkGray); auto scene = _scenes.at(_currentScene); // to remove playSoundWithKey(); diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index c15b29f1..001fddf8 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -60,7 +60,7 @@ namespace Systems { { float scale = 1.0F; float rotation = 0; - Raylib::Color tint = Raylib::White; + const Raylib::Color tint = {255, 255, 255, 255}; Raylib::Vector2 spritePos = {0, 0}; const float denominator = 100.0; @@ -84,7 +84,7 @@ namespace Systems { { Raylib::Vector2 origin = {0, 0}; float rotation = 0; - Raylib::Color tint = Raylib::White; + const Raylib::Color tint = {255, 255, 255, 255}; const float denominator = 100.0; float x = (position.x * static_cast(Raylib::getScreenWidth())) From aa9fcb31148b56613619902ff58fadac2c1333a0 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 28 Sep 2023 19:10:45 +0000 Subject: [PATCH 21/23] FORMAT-AUTO: automatic format on pull request #30 --- src/Client/SceneManager.cpp | 4 ++-- src/Client/Systems/Graphic/GraphicSystems.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 9a2cd8d3..8e1fe57f 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -28,8 +28,8 @@ constexpr float soundVolume = 0.1F; constexpr float fontScale = 2.0F; const float playerWidth = 50.0F; const float playerHeight = 50.0F; -const Raylib::Color darkBlue = {0, 0, 139, 255}; -const Raylib::Color darkGray = {169, 169, 169, 255}; +const Raylib::Color darkBlue = {0, 0, 139, 255}; +const Raylib::Color darkGray = {169, 169, 169, 255}; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) bool SceneManager::_init = false; diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 1416eaf7..23d35176 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -60,7 +60,7 @@ namespace Systems { { float scale = 1.0F; float rotation = 0; - const Raylib::Color tint = {255, 255, 255, 255}; + const Raylib::Color tint = {255, 255, 255, 255}; Raylib::Vector2 spritePos = {0, 0}; const float denominator = 100.0; @@ -82,10 +82,10 @@ namespace Systems { Raylib::Sprite &sprite, Types::Rect &rect) { - Raylib::Vector2 origin = {0, 0}; - float rotation = 0; - const Raylib::Color tint = {255, 255, 255, 255}; - const float denominator = 100.0; + Raylib::Vector2 origin = {0, 0}; + float rotation = 0; + const Raylib::Color tint = {255, 255, 255, 255}; + const float denominator = 100.0; float x = (position.x * static_cast(Raylib::getScreenWidth())) / denominator; From 62418403f799ddbf606cfc769235ca2c914ebd32 Mon Sep 17 00:00:00 2001 From: Tenshi Date: Thu, 28 Sep 2023 22:13:16 +0200 Subject: [PATCH 22/23] CLIENT-GAME: Fix pr request PATCH --- src/Client/Raylib/Geometry/Geometry.hpp | 26 +++++++++++++++++++ src/Client/SceneManager.cpp | 6 ++--- src/Client/Systems/Graphic/GraphicSystems.cpp | 4 +-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp index a957761a..1135da99 100644 --- a/src/Client/Raylib/Geometry/Geometry.hpp +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -48,4 +48,30 @@ namespace Raylib { uint8_t b; uint8_t a; }; + + // COLOR CONSTANTS + static const Color DarkGray = static_cast(DARKGRAY); + static const Color Yellow = static_cast(YELLOW); + static const Color Gold = static_cast(GOLD); + static const Color Orange = static_cast(ORANGE); + static const Color Pink = static_cast(PINK); + static const Color Red = static_cast(RED); + static const Color Maroon = static_cast(MAROON); + static const Color Green = static_cast(GREEN); + static const Color Lime = static_cast(LIME); + static const Color DarkGreen = static_cast(DARKGREEN); + static const Color SkyBlue = static_cast(SKYBLUE); + static const Color Blue = static_cast(BLUE); + static const Color DarkBlue = static_cast(DARKBLUE); + static const Color Purple = static_cast(PURPLE); + static const Color Violet = static_cast(VIOLET); + static const Color DarkPurple = static_cast(DARKPURPLE); + static const Color Beige = static_cast(BEIGE); + static const Color Brown = static_cast(BROWN); + static const Color DarkBrown = static_cast(DARKBROWN); + static const Color White = static_cast(WHITE); + static const Color Black = static_cast(BLACK); + static const Color Blank = static_cast(BLANK); + static const Color Magenta = static_cast(MAGENTA); + static const Color RayWhite = static_cast(RAYWHITE); } // namespace Raylib diff --git a/src/Client/SceneManager.cpp b/src/Client/SceneManager.cpp index 8e1fe57f..01d266cf 100644 --- a/src/Client/SceneManager.cpp +++ b/src/Client/SceneManager.cpp @@ -28,8 +28,6 @@ constexpr float soundVolume = 0.1F; constexpr float fontScale = 2.0F; const float playerWidth = 50.0F; const float playerHeight = 50.0F; -const Raylib::Color darkBlue = {0, 0, 139, 255}; -const Raylib::Color darkGray = {169, 169, 169, 255}; // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) bool SceneManager::_init = false; @@ -93,7 +91,7 @@ static void addTestComponents() "Press space to play music, enter to play sound", textPos, fontScale, - darkBlue}; + Raylib::DarkBlue}; } static void initRaylib() @@ -143,7 +141,7 @@ int SceneManager::run() try { while (!_stop && !Raylib::windowShouldClose()) { Raylib::beginDrawing(); - Raylib::clearBackground(darkGray); + Raylib::clearBackground(Raylib::DarkGray); auto scene = _scenes.at(_currentScene); // to remove playSoundWithKey(); diff --git a/src/Client/Systems/Graphic/GraphicSystems.cpp b/src/Client/Systems/Graphic/GraphicSystems.cpp index 23d35176..e21f2979 100644 --- a/src/Client/Systems/Graphic/GraphicSystems.cpp +++ b/src/Client/Systems/Graphic/GraphicSystems.cpp @@ -60,7 +60,7 @@ namespace Systems { { float scale = 1.0F; float rotation = 0; - const Raylib::Color tint = {255, 255, 255, 255}; + const Raylib::Color tint = Raylib::White; Raylib::Vector2 spritePos = {0, 0}; const float denominator = 100.0; @@ -84,7 +84,7 @@ namespace Systems { { Raylib::Vector2 origin = {0, 0}; float rotation = 0; - const Raylib::Color tint = {255, 255, 255, 255}; + const Raylib::Color tint = Raylib::White; const float denominator = 100.0; float x = (position.x * static_cast(Raylib::getScreenWidth())) From 33f03ebbce4f9138e3df578e40f639a8d0a5cce6 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 28 Sep 2023 20:14:57 +0000 Subject: [PATCH 23/23] FORMAT-AUTO: automatic format on pull request #30 --- src/Client/Raylib/Geometry/Geometry.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client/Raylib/Geometry/Geometry.hpp b/src/Client/Raylib/Geometry/Geometry.hpp index 1135da99..6212ed6a 100644 --- a/src/Client/Raylib/Geometry/Geometry.hpp +++ b/src/Client/Raylib/Geometry/Geometry.hpp @@ -49,7 +49,7 @@ namespace Raylib { uint8_t a; }; - // COLOR CONSTANTS + // COLOR CONSTANTS static const Color DarkGray = static_cast(DARKGRAY); static const Color Yellow = static_cast(YELLOW); static const Color Gold = static_cast(GOLD);