diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index d5e5e60..68f008b 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,16 +1,3 @@ -## Related Tickets & Documents - -- Related Issue # -- Closes (optional) # - -## What type of PR is this? (check all applicable) - -- [ ] Refactor -- [ ] Feature -- [ ] Bug Fix -- [ ] Optimization -- [ ] Documentation Update - ## Changes made _Please replace this line with a description of the changes in this PR. Include diff --git a/.gitignore b/.gitignore index 8c5ced8..5b89776 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ ## CMake build +cmake-build-debug ## MacOS .DS_Store @@ -8,8 +9,13 @@ build .vscode .idea +## Github +common/.github +common/.gitignore + ## Binary arcade +lib *.gcno *.gcda *.o diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 9e25602..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "common"] - path = common - url = https://github.com/G-Epitech/MAYBDF-ArcadeShared.git diff --git a/CMakeLists.txt b/CMakeLists.txt index d7479f7..3c3e8e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,18 @@ cmake_minimum_required(VERSION 3.27) project(arcade) +set(ARCADE_BIN_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(ARCADE_LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/lib) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20") -add_subdirectory(src) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ARCADE_BIN_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ARCADE_LIB_DIR}) +set(CMAKE_SHARED_LIBRARY_PREFIX "arcade_") + +add_subdirectory(core) +add_subdirectory(games) +add_subdirectory(graphics) + target_include_directories (arcade PUBLIC ${CMAKE_CURRENT_LIST_DIR}/common/) diff --git a/Jenkinsfile b/Jenkinsfile index f09f005..11a238f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,13 +2,6 @@ pipeline { agent any stages { - stage('Project setup') { - steps { - sh 'git rm --cached common' - sh 'make update' - } - } - stage('Project compilation') { agent { docker { diff --git a/Makefile b/Makefile index 88a6311..b0ddc84 100644 --- a/Makefile +++ b/Makefile @@ -5,28 +5,28 @@ ## Makefile ## -NAME = arcade -BUILD_PATH = build +NAME = arcade +BUILD_PATH = build +LIB_PATH = lib -all: update - @cmake -S . -B build - cmake --build $(BUILD_PATH) - @cp $(BUILD_PATH)/src/$(NAME) . +all: + @cmake -S . -B build + cmake --build $(BUILD_PATH) clean: - @rm -rf $(BUILD_PATH) + @rm -rf $(BUILD_PATH) fclean: clean - @rm -f $(NAME) + @rm -f $(NAME) + @rm -rf $(LIB_PATH) -re: fclean all +re: fclean all tests_run: - echo "pass" + echo "pass" update: - @git submodule init - @git submodule update + @cd common && ./pull.sh . .PHONY: all clean fclean re tests_run update DEFAULT_GOAL := all diff --git a/common b/common deleted file mode 160000 index 740723c..0000000 --- a/common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 740723c681c0c106ffdba313aea8fd3b153f40ea diff --git a/common/README.md b/common/README.md new file mode 100644 index 0000000..bf34730 --- /dev/null +++ b/common/README.md @@ -0,0 +1,11 @@ +# 📦 Arcade Shared Library +Shared library for Arcade project + +## Description +This library contains shared code for the Arcade project in order to unify interfaces between collaborative groups. + +## Groups + - **[G-Epitech](https://github.com/G-Epitech/FMY-Arcade)** : [Flavien Chenu](https://github.com/flavien-chenu), [Math](https://github.com/tekmath) & [Yann Masson](https://github.com/Yann-Masson) + + - **[Carapace Retro](https://github.com/G-Epitech)** : [Baptiste Moreau](https://github.com/BxptisteM), [Axel Fradet](https://github.com/AxelF44) & [Suceveanu Dragos](https://github.com/sdragos1) + diff --git a/common/games/IEntity.hpp b/common/games/IEntity.hpp new file mode 100644 index 0000000..e251824 --- /dev/null +++ b/common/games/IEntity.hpp @@ -0,0 +1,52 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IEntity +*/ + +#pragma once + +#include +#include + +#include "../types/UUId.hpp" + +namespace shared::games +{ + class IGame; + + namespace entity + { + class IEntity; + + typedef std::map> EntitiesMap; + } + + namespace components + { + class IComponent; + + typedef std::map> ComponentsMap; + } +} + +class shared::games::entity::IEntity +{ +public: + virtual ~IEntity() = default; + + /** + * @brief Get the id of the entity + * + * @return Entity unique id + */ + virtual const types::UUId &getId(void) const noexcept = 0; + + /** + * @brief Get the components of the entity + * + * @return Components of the entity + */ + virtual const components::ComponentsMap &getComponents(void) const noexcept = 0; +}; diff --git a/common/games/IGame.hpp b/common/games/IGame.hpp new file mode 100644 index 0000000..d888a3f --- /dev/null +++ b/common/games/IGame.hpp @@ -0,0 +1,68 @@ +/* +** EPITECH PROJECT, 2024 +** shared-arcade +** File description: +** IGame +*/ + +#pragma once + +#include +#include "IEntity.hpp" +#include "../types/types.hpp" +#include "types/GameManifest.hpp" + +using namespace shared::types; + +namespace shared::games +{ + class IGame; + + typedef unsigned long DeltaTime; +} + +class shared::games::IGame +{ +public: + virtual ~IGame() = default; + + /** + * @brief Compute the game each tick of the program + * + * @param dt Time since last tick (Time in `milliseconds`) + */ + virtual void compute(DeltaTime dt) = 0; + + /** + * @brief Manifest with informations of the game + * + */ + virtual const GameManifest &getManifest(void) const noexcept = 0; + + /** + * @brief The minimum window size required for the game (pixels) + * + */ + virtual const Vector2u getWindowMinSize(void) const noexcept = 0; + + /** + * @brief Number of tiles that represent the game + * Tile size is managed by the renderer + * + */ + virtual const Vector2u getSize(void) const noexcept = 0; + + /** + * @brief Get map of entities + * + */ + virtual const entity::EntitiesMap &getEntities(void) const = 0; + + /** + * @brief Get entity by id + * + * @param id Id of the entity + * @return The specific entity + */ + virtual std::shared_ptr getEntityById(const UUId &id) const = 0; +}; diff --git a/common/games/IGameProvider.hpp b/common/games/IGameProvider.hpp new file mode 100644 index 0000000..bd4b07d --- /dev/null +++ b/common/games/IGameProvider.hpp @@ -0,0 +1,36 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IGameProvider +*/ + +#pragma once + +#include +#include "IGame.hpp" +#include "types/GameManifest.hpp" + +namespace shared::games { + class IGameProvider; +} + +class shared::games::IGameProvider +{ +public: + virtual ~IGameProvider() = default; + + /** + * @brief Provides the game manifest + * + * @return Manifest of current game + */ + virtual const GameManifest &getManifest() const noexcept = 0; + + /** + * @brief Provides a new instance of the game + * + * @return Created game instance + */ + virtual std::shared_ptr createInstance(void) = 0; +}; diff --git a/common/games/components/ICollidableComponent.hpp b/common/games/components/ICollidableComponent.hpp new file mode 100644 index 0000000..f6ce1c3 --- /dev/null +++ b/common/games/components/ICollidableComponent.hpp @@ -0,0 +1,29 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** ICollidableComponent +*/ + +#pragma once + +#include "../IGame.hpp" +#include "IPositionComponent.hpp" +#include "../../types/Vector.hpp" + +namespace shared::games::components { + class ICollidableComponent; +} + +class shared::games::components::ICollidableComponent: public virtual IPositionComponent +{ +public: + virtual ~ICollidableComponent() = default; + + /** + * @brief On collide event handler for the component + * @param ctx Context of the game + * @param target Target entity + */ + virtual void onCollide(std::shared_ptr &ctx, std::shared_ptr target) = 0; +}; diff --git a/common/games/components/IComponent.hpp b/common/games/components/IComponent.hpp new file mode 100644 index 0000000..a0be931 --- /dev/null +++ b/common/games/components/IComponent.hpp @@ -0,0 +1,49 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IComponent +*/ + +#pragma once + +#include "../IEntity.hpp" +#include "../../types/UUId.hpp" + +namespace shared::games::components { + typedef enum { + DISPLAYABLE, + SOUND, + COLLIDABLE, + POSITION, + KEYBOARD + } ComponentType; + + class IComponent; +} + +class shared::games::components::IComponent { +public: + virtual ~IComponent() = default; + + /** + * @brief Get the type of the component + * + * @return Type of the component + */ + virtual const ComponentType getType() const noexcept = 0; + + /** + * @brief Get the uuid of component + * + * @return Component id + */ + virtual const types::UUId &getId() const noexcept = 0; + + /** + * @brief Get the parent entity of the component + * + * @return Entity of the component + */ + virtual std::shared_ptr getEntity() noexcept = 0; +}; diff --git a/common/games/components/IDisplayableComponent.hpp b/common/games/components/IDisplayableComponent.hpp new file mode 100644 index 0000000..c492e3b --- /dev/null +++ b/common/games/components/IDisplayableComponent.hpp @@ -0,0 +1,71 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared [WSL: Ubuntu-22.04] +** File description: +** ADisplaybleComponent +*/ + +#pragma once + +#include "IPositionComponent.hpp" +#include "../IGame.hpp" +#include "../../types/Vector.hpp" + +namespace shared::games::components { + class IDisplayableComponent; + + typedef struct + { + const std::string ascii; // ASCII image representation path + const std::string bin; // Binary image path + Vector2f binTileSize; // Size of the binary tile + } TextureSources; + + typedef struct + { + TextureSources sources; // Sources of textures + Vector2u origin; // Origin of the texture + } TextureProps; +} + +class shared::games::components::IDisplayableComponent: public virtual IPositionComponent +{ +public: + virtual ~IDisplayableComponent() = default; + + /** + * @brief Get size of the entity (tiles) + * + */ + virtual Vector2u &getSize(void) noexcept = 0; + + /** + * @brief Get Z index that is usefull for display prioroty + * + */ + virtual unsigned int &getZIndex(void) noexcept = 0; + + /** + * @brief Get texture properties + * + */ + virtual TextureProps &getTextureProps(void) noexcept = 0; + + /** + * @brief On click event handler for the entity + * @param ctx Context of the game + */ + virtual void onMousePress(std::shared_ptr &ctx) = 0; + + /** + * @brief On release event handler for the entity + * @param ctx Context of the game + */ + virtual void onMouseRelease(std::shared_ptr &ctx) = 0; + + /** + * @brief On hover event handler for the entity + * @param ctx Context of the game + */ + virtual void onMouseHover(std::shared_ptr &ctx) = 0; +}; diff --git a/common/games/components/IKeyboardComponent.hpp b/common/games/components/IKeyboardComponent.hpp new file mode 100644 index 0000000..097b293 --- /dev/null +++ b/common/games/components/IKeyboardComponent.hpp @@ -0,0 +1,73 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IKeyboardComponent +*/ + +#pragma once + +#include "../IGame.hpp" +#include "IComponent.hpp" + +namespace shared::games::components { + class IKeyboardComponent; + + typedef enum + { + CONTROL, // Control key (`Ctrl`, `Shift`, `Alt`) + ARROW, // Arrow key (`Up`, `Down`, `Left`, `Right`) + FUNC, // Function key (`F1`, `F2`, `F3`, etc.) + CHAR, // Character key (`a`, `1`, `&`, etc.) + UNKNOWN // Unknown key + } KeyType; + + typedef enum + { + CTRL, // `Ctrl` key + SHIFT, // `Shift` key + ALT // `Alt` key + } ControlCode; + + typedef enum + { + UP, // `Up` arrow key + DOWN, // `Down` arrow key + LEFT, // `Left` arrow key + RIGHT // `Right` arrow key + } ArrowCode; + + typedef union + { + ControlCode control; // Control key + ArrowCode arrow; // Arrow key + char character; // ASCII character value + unsigned char func; // Function key number + } KeyCode; + + typedef struct + { + KeyCode code; // Key code. Interpretation depends on the type + KeyType type; // Type of the key + } KeyData; +} + +class shared::games::components::IKeyboardComponent: public virtual IComponent +{ +public: + virtual ~IKeyboardComponent() = default; + + /** + * @brief On key pressed event handler for the entity + * @param ctx Context of the game + * @param keyData Key data of key pressed + */ + virtual void onKeyPress(std::shared_ptr &ctx, KeyData keyData) = 0; + + /** + * @brief On key release event handler for the entity + * @param ctx Context of the game + * @param keyData Key data of key released + */ + virtual void onKeyRelease(std::shared_ptr &ctx, KeyData keyData) = 0; +}; diff --git a/common/games/components/IPositionComponent.hpp b/common/games/components/IPositionComponent.hpp new file mode 100644 index 0000000..4e508df --- /dev/null +++ b/common/games/components/IPositionComponent.hpp @@ -0,0 +1,27 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IPositionComponent +*/ + +#pragma once + +#include "IComponent.hpp" +#include "../../types/Vector.hpp" + +namespace shared::games::components { + class IPositionComponent; +} + +class shared::games::components::IPositionComponent: public virtual IComponent +{ + public: + virtual ~IPositionComponent() = default; + + /** + * @brief Get position of the entity (tiles) + * + */ + virtual types::Vector2i &getPosition(void) noexcept = 0; +}; diff --git a/common/games/components/ISoundComponent.hpp b/common/games/components/ISoundComponent.hpp new file mode 100644 index 0000000..fd4ab9c --- /dev/null +++ b/common/games/components/ISoundComponent.hpp @@ -0,0 +1,67 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** ISoundComponent +*/ + +#pragma once + +#include "IComponent.hpp" +#include "../IGame.hpp" +#include "../../types/Vector.hpp" + +namespace shared::games::components { + class ISoundComponent; + + typedef enum + { + PLAY, + PAUSE, + STOP + } SoundState; + + typedef unsigned char SoundVolume; +} + +class shared::games::components::ISoundComponent: public virtual IComponent +{ +public: + virtual ~ISoundComponent() = default; + + /** + * @brief Get path of the sound + * + * @return Sound path + */ + virtual const std::string &getPath(void) const noexcept = 0; + + /** + * @brief Get state of the sound + * + * @return Sound state + */ + virtual SoundState &getState(void) noexcept = 0; + + /** + * @brief Get volume of the sound + * + * @return Sound volume + */ + virtual SoundVolume &getVolume(void) noexcept = 0; + + /** + * @brief Get loop of the sound + * + * @return Sound loop + */ + virtual bool &getLoop(void) noexcept = 0; + + /** + * @brief On state change event handler for the component + * + * @param ctx Context of the game + * @param state New state of the sound + */ + virtual void onStateChange(std::shared_ptr &ctx, SoundState state) = 0; +}; diff --git a/common/games/export.cpp.example b/common/games/export.cpp.example new file mode 100644 index 0000000..4fe9f03 --- /dev/null +++ b/common/games/export.cpp.example @@ -0,0 +1,21 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** export +*/ + +#include "IGame.hpp" +#include "../types/LibraryType.hpp" + +extern "C" { + shared::types::LibraryType SHARED_LIBRARY_TYPE_GETTER_NAME(void) + { + return shared::types::LibraryType::GAME; + } + + std::shared_ptr SHARED_GRAPHICS_FACTORY_LOADER_NAME(void) + { + return std::make_shared(...) + } +} diff --git a/common/games/types/GameManifest.hpp b/common/games/types/GameManifest.hpp new file mode 100644 index 0000000..4c6efbf --- /dev/null +++ b/common/games/types/GameManifest.hpp @@ -0,0 +1,28 @@ +/* +** EPITECH PROJECT, 2024 +** shared-arcade +** File description: +** GameManifest +*/ + +#pragma once +#include +#include + +namespace shared::games +{ + typedef struct + { + std::string name; // Name of the author + std::string email; // Public contact email + std::string website; // Website of the author (`github`, `gitlab`, etc.) + } Author; + + typedef struct + { + const std::string name; // Name of the game + const std::string description; // Description of the game + const std::string version; // Version of the game + const std::vector authors; // Authors + } GameManifest; +} diff --git a/common/graphics/IGraphicsProvider.hpp b/common/graphics/IGraphicsProvider.hpp new file mode 100644 index 0000000..16dc666 --- /dev/null +++ b/common/graphics/IGraphicsProvider.hpp @@ -0,0 +1,64 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IRendererFactory +*/ + +#pragma once + +#include + +#include "ISound.hpp" +#include "ITexture.hpp" +#include "window/IWindow.hpp" +#include "types/GraphicsManifest.hpp" + +namespace shared::graphics { + class IGraphicsProvider; +} + +class shared::graphics::IGraphicsProvider { + public: + virtual ~IGraphicsProvider() = default; + + + /** + * @brief Get the manifest of the graphics library + * + * @return Manifest of the graphics library + */ + virtual const GameManifest &getManifest(void) const noexcept = 0; + + /** + * @brief Create a renderer object + * + * @param windowProps Properties to use to init the window + * @return Created renderer object + */ + virtual std::unique_ptr createWindow(const WindowInitProps &windowProps) = 0; + + /** + * @brief Create a sound object + * + * @param path Path of the sound file + * @return Created sound object + */ + virtual std::shared_ptr createSound(const std::string &path) = 0; + + /** + * @brief Create a texture object + * + * @param path Path of the texture file + * @return Created texture object + */ + virtual std::shared_ptr createTexture(const std::string &path) = 0; + + /** + * @brief Create a window icon object + * + * @param path Path of the window icon file + * @return Created window icon object + */ + virtual std::unique_ptr createWindowIcon(const std::string &path) = 0; +}; diff --git a/common/graphics/ISound.hpp b/common/graphics/ISound.hpp new file mode 100644 index 0000000..96f192c --- /dev/null +++ b/common/graphics/ISound.hpp @@ -0,0 +1,69 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** ISound +*/ + +#pragma once + +namespace shared::graphics +{ + class ISound; + + typedef unsigned char SoundVolume; + typedef enum + { + PLAY, + PAUSE, + STOP + } SoundState; +} + +class shared::graphics::ISound { + public: + virtual ~ISound() = default; + + /** + * @brief Get the state of the sound + * + * @param state State of sound playing + * @return SoundState + */ + virtual void setState(SoundState state) = 0; + + /** + * @brief Get the state of the sound + * + * @return Current state of the sound + */ + virtual SoundState getState() const = 0; + + /** + * @brief Set the volume of the sound + * + * @param volume Volume of the sound + */ + virtual void setVolume(SoundVolume volume) = 0; + + /** + * @brief Get the volume of the sound + * + * @return Volume of the sound + */ + virtual SoundVolume getVolume() const = 0; + + /** + * @brief Set the loop state of sound + * + * @param loop Loop state of sound + */ + virtual void setLoopState(bool loop) = 0; + + /** + * @brief Get the loop state of sound + * + * @return Loop state of sound + */ + virtual bool getLoopState(void) const = 0; +}; diff --git a/common/graphics/ITexture.hpp b/common/graphics/ITexture.hpp new file mode 100644 index 0000000..69649da --- /dev/null +++ b/common/graphics/ITexture.hpp @@ -0,0 +1,17 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** ITexture +*/ + +#pragma once + +namespace shared::graphics { + class ITexture; +} + +class ITexture { + public: + virtual ~ITexture() = default; +}; diff --git a/common/graphics/events/IEvent.hpp b/common/graphics/events/IEvent.hpp new file mode 100644 index 0000000..ab455d0 --- /dev/null +++ b/common/graphics/events/IEvent.hpp @@ -0,0 +1,35 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IEvent +*/ + +#pragma once + +namespace shared::graphics::events +{ + class IEvent; + + typedef enum + { + KEY_PRESS, // Key pressed + KEY_RELEASE, // Key released + MOUSE_BTN_PRESS, // Mouse button pressed + MOUSE_BTN_RELEASE, // Mouse button released + MOUSE_MOVE, // Mouse moved + WINDOW_CLOSE, // Window closed + WINDOW_RESIZE, // Window resized + } EventType; +} + +class shared::graphics::events::IEvent +{ + public: + virtual ~IEvent() = default; + + /** + * @brief Event type + */ + virtual const EventType getType() const noexcept = 0; +}; diff --git a/common/graphics/events/key/AKeyEvent.hpp b/common/graphics/events/key/AKeyEvent.hpp new file mode 100644 index 0000000..ff4c436 --- /dev/null +++ b/common/graphics/events/key/AKeyEvent.hpp @@ -0,0 +1,87 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** AKeyEvent +*/ + +#pragma once + +#include "../IEvent.hpp" + +namespace shared::graphics::events { + template + class AKeyEvent; + + typedef enum + { + CONTROL, // Control key (`Ctrl`, `Shift`, `Alt`) + ARROW, // Arrow key (`Up`, `Down`, `Left`, `Right`) + FUNC, // Function key (`F1`, `F2`, `F3`, etc.) + CHAR, // Character key (`a`, `1`, `&`, etc.) + UNKNOWN // Unknown key + } KeyType; + + typedef enum + { + CTRL, // `Ctrl` key + SHIFT, // `Shift` key + ALT // `Alt` key + } ControlCode; + + typedef enum + { + UP, // `Up` arrow key + DOWN, // `Down` arrow key + LEFT, // `Left` arrow key + RIGHT // `Right` arrow key + } ArrowCode; + + typedef union + { + ControlCode control; // Control key + ArrowCode arrow; // Arrow key + char character; // ASCII character value + unsigned char func; // Function key number + } KeyCode; +} + +template +class shared::graphics::events::AKeyEvent: public IEvent { + public: + ~AKeyEvent() = default; + + /** + * @brief Event type + * + */ + const EventType getType(void) const noexcept + { + return this->_type; + } + + /** + * @brief Key code content + * + */ + const KeyCode getKeyCode(void) const noexcept + { + return this->_keyCode; + } + + /** + * @brief Key type + * + */ + const KeyType getKeyType(void) const noexcept + { + return this->_keyType; + } + + protected: + AKeyEvent(KeyType keyType, KeyCode keyCode) : _keyType(keyType), _keyCode(keyCode) {} + + EventType _type = T; + KeyType _keyType; + KeyCode _keyCode; +}; diff --git a/common/graphics/events/key/KeyPressEvent.hpp b/common/graphics/events/key/KeyPressEvent.hpp new file mode 100644 index 0000000..58016b8 --- /dev/null +++ b/common/graphics/events/key/KeyPressEvent.hpp @@ -0,0 +1,19 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** AKeyEvent +*/ + +#pragma once + +#include "AKeyEvent.hpp" + +namespace shared::graphics::events { + class KeyPressEvent; +} + +class shared::graphics::events::KeyPressEvent: public AKeyEvent { + public: + KeyPressEvent(KeyType keyType, KeyCode keyCode): AKeyEvent(keyType, keyCode) {} +}; diff --git a/common/graphics/events/key/KeyReleaseEvent.hpp b/common/graphics/events/key/KeyReleaseEvent.hpp new file mode 100644 index 0000000..8800f90 --- /dev/null +++ b/common/graphics/events/key/KeyReleaseEvent.hpp @@ -0,0 +1,18 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IKeyEvent +*/ + +#pragma once + +#include "AKeyEvent.hpp" + +namespace shared::graphics::events { + class KeyReleaseEvent; +} +class shared::graphics::events::KeyReleaseEvent: public AKeyEvent { + public: + KeyReleaseEvent(KeyType keyType, KeyCode keyCode): AKeyEvent(keyType, keyCode) {} +}; diff --git a/common/graphics/events/mouse/AMouseButtonEvent.hpp b/common/graphics/events/mouse/AMouseButtonEvent.hpp new file mode 100644 index 0000000..17342c3 --- /dev/null +++ b/common/graphics/events/mouse/AMouseButtonEvent.hpp @@ -0,0 +1,39 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IMouseEvent +*/ + +#pragma once + +#include "AMouseEvent.hpp" + +namespace shared::graphics::events +{ + template + class AMouseButtonEvent; +} + +template +class shared::graphics::events::AMouseButtonEvent: public AMouseEvent +{ + public: + ~AMouseButtonEvent() = default; + + /** + * @brief Mouse button released + * + */ + const MouseButton getButton(void) const noexcept { + return this->_button; + } + + protected: + AMouseButtonEvent( + MouseButton button, + types::Vector2f position + ): AMouseEvent(position), _button(button) {} + + MouseButton _button; +}; diff --git a/common/graphics/events/mouse/AMouseEvent.hpp b/common/graphics/events/mouse/AMouseEvent.hpp new file mode 100644 index 0000000..18bc030 --- /dev/null +++ b/common/graphics/events/mouse/AMouseEvent.hpp @@ -0,0 +1,50 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IMouseEvent +*/ + +#pragma once + +#include "../../../types/types.hpp" +#include "../IEvent.hpp" + +namespace shared::graphics::events +{ + template + class AMouseEvent; + + typedef enum { + LEFT, + RIGHT + } MouseButton; +} + +template +class shared::graphics::events::AMouseEvent : public IEvent +{ + public: + ~AMouseEvent() = default; + + /** + * @brief Event type + * + */ + const EventType getType(void) const noexcept { + return T; + } + + /** + * @brief Mouse position + * + */ + const shared::types::Vector2f getPosition(void) const noexcept { + return this->_position; + } + + protected: + AMouseEvent(types::Vector2f position): _position(position) {} + + types::Vector2f _position; +}; diff --git a/common/graphics/events/mouse/MouseButtonPressEvent.hpp b/common/graphics/events/mouse/MouseButtonPressEvent.hpp new file mode 100644 index 0000000..3a92d1e --- /dev/null +++ b/common/graphics/events/mouse/MouseButtonPressEvent.hpp @@ -0,0 +1,24 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IMouseEvent +*/ + +#pragma once + +#include "AMouseButtonEvent.hpp" + +namespace shared::graphics::events +{ + class MouseButtonPressEvent; +} + +class shared::graphics::events::MouseButtonPressEvent : + public AMouseButtonEvent +{ + public: + MouseButtonPressEvent(MouseButton button, types::Vector2f position) + : AMouseButtonEvent(button, position) {} + ~MouseButtonPressEvent() = default; +}; diff --git a/common/graphics/events/mouse/MouseButtonReleaseEvent.hpp b/common/graphics/events/mouse/MouseButtonReleaseEvent.hpp new file mode 100644 index 0000000..960c6bc --- /dev/null +++ b/common/graphics/events/mouse/MouseButtonReleaseEvent.hpp @@ -0,0 +1,24 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IMouseEvent +*/ + +#pragma once + +#include "AMouseButtonEvent.hpp" + +namespace shared::graphics::events +{ + class MouseButtonReleaseEvent; +} + +class shared::graphics::events::MouseButtonReleaseEvent : + public AMouseButtonEvent +{ + public: + MouseButtonReleaseEvent(MouseButton button, types::Vector2f position) + : AMouseButtonEvent(button, position) {} + ~MouseButtonReleaseEvent() = default; +}; diff --git a/common/graphics/events/mouse/MouseMoveEvent.hpp b/common/graphics/events/mouse/MouseMoveEvent.hpp new file mode 100644 index 0000000..c0be8db --- /dev/null +++ b/common/graphics/events/mouse/MouseMoveEvent.hpp @@ -0,0 +1,22 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IMouseEvent +*/ + +#pragma once + +#include "AMouseEvent.hpp" + +namespace shared::graphics::events +{ + class MouseMoveEvent; +} + +class shared::graphics::events::MouseMoveEvent : public AMouseEvent +{ + public: + MouseMoveEvent(types::Vector2f position) : AMouseEvent(position) {} + ~MouseMoveEvent() = default; +}; diff --git a/common/graphics/events/window/WindowCloseEvent.hpp b/common/graphics/events/window/WindowCloseEvent.hpp new file mode 100644 index 0000000..dcf9d52 --- /dev/null +++ b/common/graphics/events/window/WindowCloseEvent.hpp @@ -0,0 +1,29 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IWindowCloseEvent +*/ + +#pragma once + +#include "../IEvent.hpp" + +namespace shared::graphics::events { + class WindowCloseEvent; +} + +class shared::graphics::events::WindowCloseEvent: public IEvent { + public: + WindowCloseEvent() = default; + ~WindowCloseEvent() = default; + + /** + * @brief Event type + * + */ + const EventType getType() const noexcept + { + return WINDOW_CLOSE; + } +}; diff --git a/common/graphics/events/window/WindowResizeEvent.hpp b/common/graphics/events/window/WindowResizeEvent.hpp new file mode 100644 index 0000000..e8bddce --- /dev/null +++ b/common/graphics/events/window/WindowResizeEvent.hpp @@ -0,0 +1,43 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IWindowResizeEvent +*/ + +#pragma once + +#include "../IEvent.hpp" +#include "../../../types/types.hpp" + +namespace shared::graphics::events { + class WindowResizeEvent; +} + +class shared::graphics::events::WindowResizeEvent: public IEvent { + public: + WindowResizeEvent(types::Vector2u newSize) : _newSize(newSize) {} + ~WindowResizeEvent() = default; + + /** + * @brief Event type + * + */ + const EventType getType() const noexcept + { + return WINDOW_RESIZE; + } + + /** + * @brief Get the new window size + * + * @return New window size + */ + const types::Vector2u &getNewSize() const noexcept + { + return this->_newSize; + } + + protected: + types::Vector2u _newSize; +}; diff --git a/common/graphics/export.cpp.example b/common/graphics/export.cpp.example new file mode 100644 index 0000000..ae4ef20 --- /dev/null +++ b/common/graphics/export.cpp.example @@ -0,0 +1,21 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** export +*/ + +#include "IGraphicsFactory.hpp" +#include "../types/Libraries.hpp" + +extern "C" { + shared::types::LibraryType SHARED_LIBRARY_TYPE_GETTER_NAME(void) + { + return shared::types::LibraryType::GRAPHIC; + } + + std::shared_ptr SHARED_GAME_PROVIDER_LOADER_NAME(void) + { + return std::make_shared(...); + } +} diff --git a/common/graphics/types/EntityProps.hpp b/common/graphics/types/EntityProps.hpp new file mode 100644 index 0000000..2e3b8e5 --- /dev/null +++ b/common/graphics/types/EntityProps.hpp @@ -0,0 +1,32 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** Texture +*/ + +#pragma once + +#include + +#include "../ITexture.hpp" +#include "../../types/types.hpp" + +using namespace shared::types; + +namespace shared::graphics +{ + typedef struct + { + const std::shared_ptr texture; // Texture of the entity + const Vector2f binTileSize; // Size of a binary tile + const Vector2u origin; // Origin of the texture + } EntityTextureProps; + + typedef struct + { + EntityTextureProps textureProps; // Properties to use with the texture for the entity + Vector2u size; // Size of the entity + Vector2i position; // Position of the entity + } EntityProps; +} diff --git a/common/graphics/types/GraphicsManifest.hpp b/common/graphics/types/GraphicsManifest.hpp new file mode 100644 index 0000000..fc45e15 --- /dev/null +++ b/common/graphics/types/GraphicsManifest.hpp @@ -0,0 +1,28 @@ +/* +** EPITECH PROJECT, 2024 +** shared-arcade +** File description: +** GameManifest +*/ + +#pragma once +#include +#include + +namespace shared::graphics +{ + typedef struct + { + std::string name; // Name of the author + std::string email; // Public contact email + std::string website; // Website of the author (`github`, `gitlab`, etc.) + } Author; + + typedef struct + { + const std::string name; // Name of the graphics library + const std::string description; // Description of the library + const std::string version; // Version of the library + const std::vector authors; // Authors + } GraphicsManifest; +} diff --git a/common/graphics/window/IWindow.hpp b/common/graphics/window/IWindow.hpp new file mode 100644 index 0000000..95fac0f --- /dev/null +++ b/common/graphics/window/IWindow.hpp @@ -0,0 +1,155 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IWindow +*/ + +#pragma once + +#include +#include + +#include "IWindowIcon.hpp" +#include "../events/IEvent.hpp" +#include "../../types/types.hpp" +#include "../types/EntityProps.hpp" + +using namespace shared::types; + +namespace shared::graphics +{ + class IWindow; + + typedef enum + { + WINDOWED, + FULLSCREEN + } WindowMode; + + typedef struct { + Vector2u size; //Initial size of the window + WindowMode mode; //Initial mode of the window + unsigned int fps; //Initial framerate of the window + const std::string title; //Initial title of the window + const std::string icon; //Initial icon of the window + } WindowInitProps; +} + +class shared::graphics::IWindow { + public: + virtual ~IWindow() = default; + + /** + * @brief Set the title of current window + * + * @param title Title of the window + */ + virtual void setTitle(const std::string &title) = 0; + + /** + * @brief Get the title of current window + * + * @return Title of the window + */ + virtual std::string getTitle() const = 0; + + /** + * @brief Set the size of the window + * + * @param size Size of the window + */ + virtual void setSize(Vector2u size) = 0; + + /** + * @brief Get the size of the window + * + * @return Size of the window + */ + virtual Vector2u getSize() const = 0; + + /** + * @brief Set the framerate Limit of the window + * + * @param fps Frame per seconds + */ + virtual void setFramerateLimit(unsigned int fps) = 0; + + /** + * @brief Get the framerate Limit of the window + * + * @return Frame per seconds + */ + virtual unsigned int getFramerateLimit() const = 0; + + /** + * @brief Set the mode of the window + * + * @param mode Mode to apply to the window + */ + virtual void setMode(WindowMode mode) = 0; + + /** + * @brief Get the mode of the window + * + * @return Mode of the window + */ + virtual WindowMode getMode(void) const = 0; + + /** + * @brief Set the icon of the window + * + * @param icon Icon to use + */ + virtual void setIcon(std::unique_ptr icon) = 0; + + /** + * @brief Get the icon of the window + * + * @return Icon object of the window + */ + virtual const IWindowIcon &getIcon(void) const = 0; + + /** + * @brief Render the entity with given properties + * + * @param props Properties of the entity to render + */ + virtual void render(const EntityProps &props) = 0; + + /** + * @brief Clear the content of the window + * + */ + virtual void clear(void) = 0; + + /** + * @brief Display the content of the window + * + */ + virtual void display(void) = 0; + + /** + * @brief Close the window + * + */ + virtual void close(void) = 0; + + /** + * @brief Check if the window is open + * + * @return Open status of the window + */ + virtual bool isOpen(void) const = 0; + + /** + * @brief Get the events object + * + * @return Last events occured + * @warning Call successively this method will result in losing events + * @note Call `A` return `eventsA` containing 2 events, + * but make another call `B` (directly after call `A`) `eventsB` + * will result to an empty vector + */ + virtual std::vector getEvents(void) = 0; +}; diff --git a/common/graphics/window/IWindowIcon.hpp b/common/graphics/window/IWindowIcon.hpp new file mode 100644 index 0000000..9dfdb83 --- /dev/null +++ b/common/graphics/window/IWindowIcon.hpp @@ -0,0 +1,17 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** IWindowIcon +*/ + +#pragma once + +namespace shared::graphics { + class IWindowIcon; +} + +class shared::graphics::IWindowIcon { + public: + virtual ~IWindowIcon() = default; +}; diff --git a/common/pull.sh b/common/pull.sh new file mode 100755 index 0000000..057581f --- /dev/null +++ b/common/pull.sh @@ -0,0 +1,40 @@ +#! /bin/bash + +gitfiles=(.git .gitmodules .gitattributes) +tmp_dir="/tmp/$(uuidgen)" +repo_url=git@github.com:G-Epitech/MAYBDF-ArcadeShared.git + +if [ -z "$1" ]; then + echo "Usage: pull.sh " + exit 1 +fi + +echo "Pulling from remote repository" +git clone $repo_url $tmp_dir + +if [ $? -ne 0 ]; then + echo "Error: unable to clone the remote repository" + exit 1 +fi + +echo "Removing git files" +for i in ${gitfiles[@]}; do + rm -rf $tmp_dir/$i +done + +## Are you sure to proceed? +if [ -d $1 ]; then + echo -n "Are you sure to proceed? (y/n): " + read proceed + if [ "$proceed" != "y" ]; then + echo "Aborted." + rm -rf $tmp_dir + exit 0 + fi +fi + +## Clear current directory except current shell script +find $1 -maxdepth 1 ! -wholename $0 ! -name "." ! -name ".." ! -name "pull.sh" -exec rm -rf {} \; +cp -r $tmp_dir/. $1 +rm -rf $tmp_dir +echo "Done. Up to date." diff --git a/common/types/Libraries.hpp b/common/types/Libraries.hpp new file mode 100644 index 0000000..08c954b --- /dev/null +++ b/common/types/Libraries.hpp @@ -0,0 +1,28 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** LibraryType +*/ + +#pragma once + +#include "../games/IGameProvider.hpp" +#include "../graphics/IGraphicsProvider.hpp" + +#define SHARED_GAME_PROVIDER_LOADER_NAME arcadeLibGetGameProvider +#define SHARED_GRAPHICS_PROVIDER_LOADER_NAME arcadeLibGetGraphicsProvider +#define SHARED_LIBRARY_TYPE_GETTER_NAME arcadeLibGetType +#define SHARED_STRINGIFY(x) #x + +namespace shared::types +{ + typedef enum { + GAME, + GRAPHIC, + } LibraryType; + + typedef std::shared_ptr (*GameProvider)(void); + typedef std::shared_ptr (*GraphicsProvider)(void); + typedef LibraryType (*LibraryTypeGetter)(void); +} diff --git a/common/types/UUId.cpp b/common/types/UUId.cpp new file mode 100644 index 0000000..87086f2 --- /dev/null +++ b/common/types/UUId.cpp @@ -0,0 +1,63 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** UUId +*/ + +#include "UUId.hpp" + + +shared::types::UUId::UUId() +{ + uuid_generate(_uuid); +} + +shared::types::UUId::~UUId() +{ +} + +shared::types::UUId &shared::types::UUId::operator=(const UUId &other) +{ + if (this != &other) + uuid_copy(_uuid, other._uuid); + return *this; +} + +bool shared::types::UUId::operator==(const UUId &other) const +{ + return uuid_compare(_uuid, other._uuid) == 0; +} + +bool shared::types::UUId::operator!=(const UUId &other) const +{ + return uuid_compare(_uuid, other._uuid) != 0; +} + +bool shared::types::UUId::operator<(const UUId &other) const +{ + return uuid_compare(_uuid, other._uuid) < 0; +} + +bool shared::types::UUId::operator>(const UUId &other) const +{ + return uuid_compare(_uuid, other._uuid) > 0; +} + +bool shared::types::UUId::operator<=(const UUId &other) const +{ + return uuid_compare(_uuid, other._uuid) <= 0; +} + +bool shared::types::UUId::operator>=(const UUId &other) const +{ + return uuid_compare(_uuid, other._uuid) >= 0; +} + +std::string shared::types::UUId::toString() const +{ + char str[37]; + + uuid_unparse(_uuid, str); + return std::string(str); +} diff --git a/common/types/UUId.hpp b/common/types/UUId.hpp new file mode 100644 index 0000000..39ad2ad --- /dev/null +++ b/common/types/UUId.hpp @@ -0,0 +1,89 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** UUId +*/ + +#pragma once + +#include + +#include + +namespace shared::types { + class UUId; +} + +class shared::types::UUId +{ + public: + UUId(void); + ~UUId(); + + /** + * @brief Assign same value to this UUId + * + * @param other UUId in whcih value is to be assigned + * @return Passed instance of UUId + */ + UUId &operator=(const UUId &other); + + /** + * @brief Equality operator + * + * @param other UUId to be compared + * @return Equality status + */ + bool operator==(const UUId &other) const; + + /** + * @brief Different operator + * + * @param other UUId to be compared + * @return Difference status + */ + bool operator!=(const UUId &other) const; + + /** + * @brief Operator to compare if current UUId is less than other UUId + * + * @param other Other UUId to be compared + * @return Status of comparison + */ + bool operator<(const UUId &other) const; + + /** + * @brief Operator to compare if current UUId is greter than other UUId + * + * @param other Other UUId to be compared + * @return Status of comparison + */ + bool operator>(const UUId &other) const; + + /** + * @brief Operator to compare if current UUId is less than or equal to other UUId + * + * @param other Other UUId to be compared + * @return Status of comparison + */ + bool operator<=(const UUId &other) const; + + /** + * @brief Operator to compare if current UUId is greater than or equal to other UUId + * + * @param other Other UUId to be compared + * @return Status of comparison + */ + bool operator>=(const UUId &other) const; + + /** + * @brief Convert UUId to string + * + * @return String representation of UUId + */ + std::string toString(void) const; + + private: + uuid_t _uuid; +}; diff --git a/common/types/Vector.hpp b/common/types/Vector.hpp new file mode 100644 index 0000000..5905a04 --- /dev/null +++ b/common/types/Vector.hpp @@ -0,0 +1,27 @@ +/* +** EPITECH PROJECT, 2024 +** shared-arcade +** File description: +** Vector +*/ + +#pragma once + +namespace shared::types +{ + template + struct Vector; + + typedef struct Vector Vector2i; + typedef struct Vector Vector2f; + typedef struct Vector Vector2u; +} + +template +struct shared::types::Vector +{ + Vector(T x, T y) : x(x), y(y){}; + + T x; + T y; +}; diff --git a/common/types/types.hpp b/common/types/types.hpp new file mode 100644 index 0000000..dcfa739 --- /dev/null +++ b/common/types/types.hpp @@ -0,0 +1,12 @@ +/* +** EPITECH PROJECT, 2024 +** arcade-shared +** File description: +** types +*/ + +#pragma once + +#include "Vector.hpp" +#include "UUId.hpp" +#include "Libraries.hpp" diff --git a/src/CMakeLists.txt b/core/CMakeLists.txt similarity index 100% rename from src/CMakeLists.txt rename to core/CMakeLists.txt diff --git a/src/main.cpp b/core/main.cpp similarity index 100% rename from src/main.cpp rename to core/main.cpp diff --git a/games/CMakeLists.txt b/games/CMakeLists.txt new file mode 100644 index 0000000..4c39731 --- /dev/null +++ b/games/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(snake) diff --git a/games/snake/CMakeLists.txt b/games/snake/CMakeLists.txt new file mode 100644 index 0000000..dab7a02 --- /dev/null +++ b/games/snake/CMakeLists.txt @@ -0,0 +1,5 @@ +project(snake) + +add_library(${PROJECT_NAME} SHARED + src/main.cpp +) diff --git a/games/snake/src/main.cpp b/games/snake/src/main.cpp new file mode 100644 index 0000000..c17bdd9 --- /dev/null +++ b/games/snake/src/main.cpp @@ -0,0 +1,13 @@ +/* +** EPITECH PROJECT, 2024 +** arcade +** File description: +** main +*/ + +int main(int ac, char **av) +{ + (void) ac; + (void) av; + return 0; +} diff --git a/graphics/CMakeLists.txt b/graphics/CMakeLists.txt new file mode 100644 index 0000000..c166dc2 --- /dev/null +++ b/graphics/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ncurses) diff --git a/graphics/ncurses/CMakeLists.txt b/graphics/ncurses/CMakeLists.txt new file mode 100644 index 0000000..fc9d7f8 --- /dev/null +++ b/graphics/ncurses/CMakeLists.txt @@ -0,0 +1,5 @@ +project(ncurses) + +add_library(${PROJECT_NAME} SHARED + src/main.cpp +) diff --git a/graphics/ncurses/src/main.cpp b/graphics/ncurses/src/main.cpp new file mode 100644 index 0000000..c17bdd9 --- /dev/null +++ b/graphics/ncurses/src/main.cpp @@ -0,0 +1,13 @@ +/* +** EPITECH PROJECT, 2024 +** arcade +** File description: +** main +*/ + +int main(int ac, char **av) +{ + (void) ac; + (void) av; + return 0; +}