-
Notifications
You must be signed in to change notification settings - Fork 1
[ADD] main core implementation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| ** EPITECH PROJECT, 2026 | ||
| ** Common | ||
| ** File description: | ||
| ** Common | ||
| */ | ||
|
|
||
| #ifndef COMMON | ||
| #define COMMON | ||
| #include <cstddef> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace Arcade { | ||
| enum class PluginType { | ||
| Game, | ||
| Graphics | ||
| }; | ||
|
|
||
| enum class InputAction { | ||
| None, | ||
| Quit, | ||
| NextGraphics, | ||
| PrevGraphics, | ||
| NextGame, | ||
| PrevGame, | ||
| Restart, | ||
| Menu, | ||
| Select, | ||
| Backspace, | ||
| Up, | ||
| Down, | ||
| Left, | ||
| Right, | ||
| Action | ||
| }; | ||
|
|
||
| struct KeyEvent { | ||
| InputAction action {InputAction::None}; | ||
| char text {'\0'}; | ||
| }; | ||
|
|
||
| enum class TileType { | ||
| Empty, | ||
| Wall, | ||
| Player, | ||
| Enemy, | ||
| Food, | ||
| Bonus, | ||
| Text | ||
| }; | ||
|
|
||
| struct Vec2i { | ||
| int x {0}; | ||
| int y {0}; | ||
| }; | ||
|
|
||
| enum class CellType { | ||
| Empty, | ||
| Wall, | ||
| Player, | ||
| Enemy, | ||
| Food, | ||
| Text | ||
| }; | ||
|
|
||
| struct Cell { | ||
| Vec2i pos; | ||
| CellType type; | ||
| std::string text; | ||
| }; | ||
|
|
||
| struct Drawable { | ||
| TileType type {TileType::Empty}; | ||
| Vec2i pos {}; | ||
| std::string text {}; | ||
| }; | ||
|
|
||
| struct GameState { | ||
| std::string name {"Unknown game"}; | ||
| std::vector<Drawable> drawables {}; | ||
| int score {0}; | ||
| bool finished {false}; | ||
| }; | ||
|
|
||
| struct MenuState { | ||
| std::vector<std::string> graphics {}; | ||
| std::vector<std::string> games {}; | ||
| std::string playerName {"player"}; | ||
| std::size_t selectedGraphics {0}; | ||
| std::size_t selectedGame {0}; | ||
| }; | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| ** EPITECH PROJECT, 2026 | ||
| ** IGame | ||
| ** File description: | ||
| ** IGame | ||
| */ | ||
|
|
||
| #ifndef IGAME | ||
| #define IGAME | ||
| #include <iostream> | ||
| #include "Common.hpp" | ||
|
|
||
| namespace Arcade { | ||
| class IGame { | ||
| public: | ||
| virtual ~IGame() = default; | ||
| virtual void reset() = 0; | ||
| virtual void update() = 0; | ||
| virtual void onInput(InputAction action) = 0; | ||
| virtual std::vector<Cell> getDisplay() const = 0; | ||
| virtual int getScore() const = 0; | ||
| virtual std::string getName() const = 0; | ||
| }; | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| ** EPITECH PROJECT, 2026 | ||
| ** IGame | ||
| ** File description: | ||
| ** IGame | ||
| */ | ||
|
|
||
| #ifndef IGRAPHICS | ||
| #define IGRAPHICS | ||
| #include <iostream> | ||
| #include "Common.hpp" | ||
|
|
||
| namespace Arcade { | ||
| class IGraphics { | ||
| public: | ||
| virtual ~IGraphics() = default; | ||
| virtual void init() = 0; | ||
| virtual void shutdown() = 0; | ||
| virtual void clear() = 0; | ||
| virtual void draw(const std::vector<Cell>& cells) = 0; | ||
| virtual void display() = 0; | ||
| virtual InputAction pollEvent() = 0; | ||
| virtual std::string getName() const = 0; | ||
| }; | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| ** EPITECH PROJECT, 2026 | ||
| ** PluginApi | ||
| ** File description: | ||
| ** PluginApi | ||
| */ | ||
|
|
||
| #ifndef PLUGINAPI | ||
| #define PLUGINAPI | ||
| #include "Common.hpp" | ||
|
|
||
| namespace Arcade { | ||
| using CreateFn = void* (*)(); | ||
| using DestroyFn = void (*)(void*); | ||
| using GetTypeFn = PluginType (*)(); | ||
| using GetNameFn = const char* (*)(); | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| ** EPITECH PROJECT, 2026 | ||
| ** core | ||
| ** File description: | ||
| ** core | ||
| */ | ||
|
|
||
| #include <cstddef> | ||
| #include <memory> | ||
| #include <algorithm> | ||
| #include <chrono> | ||
| #include <filesystem> | ||
| #include <iostream> | ||
| #include <dlfcn.h> | ||
| #include "Core.hpp" | ||
| #include "Errors.hpp" | ||
|
|
||
| namespace Arcade { | ||
| Core::Core(const std::string& graphicalPath) | ||
| : _graphicalPath(graphicalPath), | ||
| _graphicHandle(nullptr), | ||
| _graphics(nullptr), | ||
| _destroyGraphics(nullptr) | ||
| {} | ||
|
|
||
| Core::~Core(){ | ||
| unloadGraphics(); | ||
| } | ||
|
|
||
| void Core::loadGraphics(const std::string& path){ | ||
| // open graphic lib | ||
| _graphicHandle = dlopen(path.c_str(), RTLD_LAZY); | ||
| if (!_graphicHandle) | ||
| throw ARCError(dlerror()); | ||
|
|
||
| // load getType function of the lib | ||
| auto getType = reinterpret_cast<GetTypeFn>(dlsym(_graphicHandle, "getType")); | ||
| const char *error = dlerror(); | ||
| if (error) | ||
| throw ARCError(error); | ||
|
|
||
| // load the create function of the lib | ||
| auto create = reinterpret_cast<CreateFn>(dlsym(_graphicHandle, "create")); | ||
| error = dlerror(); | ||
| if (error) | ||
| throw ARCError(error); | ||
|
|
||
| //load the destroy fun of the lib | ||
| _destroyGraphics = reinterpret_cast<DestroyFn>(dlsym(_graphicHandle, "destroy")); | ||
| error = dlerror(); | ||
| if (error) | ||
| throw ARCError(error); | ||
|
|
||
| // Error Handling for wrong lib | ||
| if (getType() != PluginType::Graphics) | ||
| throw ARCError("'" + path + "' is not a graphical library"); | ||
|
|
||
| // create _graphics object for core use | ||
| _graphics = static_cast<IGraphics*>(create()); | ||
| if (!_graphics) | ||
| throw ARCError("failed to create graphics instance"); | ||
| } | ||
|
|
||
| void Core::unloadGraphics() | ||
| { | ||
| if (_graphics && _destroyGraphics) { | ||
| _destroyGraphics(_graphics); | ||
| _graphics = nullptr; | ||
| } | ||
| _destroyGraphics = nullptr; | ||
| if (_graphicHandle) { | ||
| dlclose(_graphicHandle); | ||
| _graphicHandle = nullptr; | ||
| } | ||
| } | ||
|
|
||
| void Core::run() { | ||
| loadGraphics(_graphicalPath); | ||
| _graphics->init(); | ||
|
|
||
| //temporary | ||
| std::cout << "Graphics library loaded successfully\n"; | ||
|
|
||
| _graphics->shutdown(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.