-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from MasterLaplace/19-implement-engine-module
feat(Engine): Clock, Window, Config, Math and Engine module implemented
- Loading branch information
Showing
24 changed files
with
1,654 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,60 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Title: Engine-3D | ||
** Author: MasterLaplace | ||
** Created: 2023-10-12 | ||
** File description: | ||
** graphics | ||
*/ | ||
|
||
#ifndef GRAPHICS_H_ | ||
#define GRAPHICS_H_ | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Define an enum for the graphics libraries | ||
//////////////////////////////////////////////////////////// | ||
enum GraphicsLibrary { | ||
CSFML, | ||
SFML, | ||
SDL, | ||
OPENGL, | ||
VULKAN, | ||
DIRECTX | ||
}; | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Define the default graphics library | ||
//////////////////////////////////////////////////////////// | ||
#define GRAPHICS_LIBRARY_DEFALUT CSFML | ||
|
||
#ifndef GRAPHICS_LIBRARY | ||
#define GRAPHICS_LIBRARY GRAPHICS_LIBRARY_DEFALUT | ||
#endif | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Include the appropriate header based on the enum value | ||
//////////////////////////////////////////////////////////// | ||
#ifdef GRAPHICS_LIBRARY | ||
#if GRAPHICS_LIBRARY == CSFML | ||
#include <SFML/Graphics.h> | ||
#elif GRAPHICS_LIBRARY == SFML | ||
#include <SFML/Graphics.hpp> | ||
#elif GRAPHICS_LIBRARY == SDL | ||
#include <SDL2/SDL.h> | ||
#elif GRAPHICS_LIBRARY == OPENGL | ||
#include <GL/glew.h> | ||
#include <GL/gl.h> | ||
#include <GL/glu.h> | ||
#include <GLFW/glfw3.h> | ||
#elif GRAPHICS_LIBRARY == VULKAN | ||
#include <vulkan/vulkan.h> | ||
#include <GL/glew.h> | ||
#include <GLFW/glfw3.h> | ||
#elif GRAPHICS_LIBRARY == DIRECTX | ||
#include <d3d11.h> | ||
#else | ||
#error "[Config@GraphicsLibrary]: No graphics library or invalid graphics library." | ||
#endif | ||
#endif | ||
|
||
#endif /* !GRAPHICS_H_ */ |
This file contains 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,126 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Title: Engine-3D | ||
** Author: MasterLaplace | ||
** Created: 2023-10-12 | ||
** File description: | ||
** distribution | ||
*/ | ||
|
||
#ifndef DISTRIBUTION_H_ | ||
#define DISTRIBUTION_H_ | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Check if we need to mark functions as extern "C" | ||
//////////////////////////////////////////////////////////// | ||
#ifdef __cplusplus | ||
#define ENGINE_EXTERN_C extern "C" | ||
#else | ||
#define ENGINE_EXTERN_C extern | ||
#endif | ||
|
||
|
||
//////////////////////////////////////////////////////////// | ||
// Identify the operating system | ||
//////////////////////////////////////////////////////////// | ||
#if defined(_WIN32) || defined(__WIN32__) | ||
|
||
// Windows | ||
#define ENGINE_SYSTEM_WINDOWS | ||
|
||
#elif defined(linux) || defined(__linux) | ||
|
||
// Linux | ||
#define ENGINE_SYSTEM_LINUX | ||
|
||
#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh) | ||
|
||
// MacOS | ||
#define ENGINE_SYSTEM_MACOS | ||
|
||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | ||
|
||
// FreeBSD | ||
#define ENGINE_SYSTEM_FREEBSD | ||
|
||
#else | ||
|
||
// Unsupported system | ||
#error [Config@Distribution]: This operating system is not supported by ENGINE library. | ||
|
||
#endif | ||
|
||
|
||
//////////////////////////////////////////////////////////// | ||
// Define helpers to create portable import / export macros for each module | ||
//////////////////////////////////////////////////////////// | ||
#if defined(ENGINE_SYSTEM_WINDOWS) | ||
|
||
// Windows compilers need specific (and different) keywords for export and import | ||
#define ENGINE_API_EXPORT extern "C" __declspec(dllexport) | ||
#define ENGINE_API_IMPORT ENGINE_EXTERN_C __declspec(dllimport) | ||
|
||
// For Visual C++ compilers, we also need to turn off this annoying C4251 warning | ||
#ifdef _MSC_VER | ||
|
||
#pragma warning(disable : 4251) | ||
|
||
#endif | ||
|
||
#else // Linux, FreeBSD, Mac OS X | ||
|
||
#if __GNUC__ >= 4 | ||
|
||
// GCC 4 has special keywords for showing/hidding symbols, | ||
// the same keyword is used for both importing and exporting | ||
#define ENGINE_API_EXPORT extern "C" __attribute__ ((__visibility__ ("default"))) | ||
#define ENGINE_API_IMPORT ENGINE_EXTERN_C __attribute__ ((__visibility__ ("default"))) | ||
|
||
#else | ||
|
||
// GCC < 4 has no mechanism to explicitely hide symbols, everything's exported | ||
#define ENGINE_API_EXPORT extern "C" | ||
#define ENGINE_API_IMPORT ENGINE_EXTERN_C | ||
|
||
#endif | ||
|
||
#endif | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Cross-platform warning for deprecated functions and classes | ||
// | ||
// @example: | ||
// struct ENGINE_DEPRECATED MyStruct | ||
// { | ||
// ... | ||
// }; | ||
// | ||
// ENGINE_DEPRECATED void global_func(); | ||
//////////////////////////////////////////////////////////// | ||
#if defined(ENGINE_NO_DEPRECATED_WARNINGS) | ||
|
||
// User explicitly requests to disable deprecation warnings | ||
#define ENGINE_DEPRECATED | ||
|
||
#elif defined(_MSC_VER) | ||
|
||
// Microsoft C++ compiler | ||
// Note: On newer MSVC versions, using deprecated functions causes a compiler error. In order to | ||
// trigger a warning instead of an error, the compiler flag /sdl- (instead of /sdl) must be specified. | ||
#define ENGINE_DEPRECATED __declspec(deprecated) | ||
|
||
#elif defined(__GNUC__) | ||
|
||
// g++ and Clang | ||
#define ENGINE_DEPRECATED __attribute__ ((deprecated)) | ||
|
||
#else | ||
|
||
// Other compilers are not supported, leave class or function as-is. | ||
// With a bit of luck, the #pragma directive works, otherwise users get a warning (no error!) for unrecognized #pragma. | ||
#pragma message("ENGINE_DEPRECATED is not supported for your compiler, please contact the ENGINE team") | ||
#define ENGINE_DEPRECATED | ||
|
||
#endif | ||
|
||
#endif /* !DISTRIBUTION_H_ */ |
This file contains 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,46 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Title: Engine-3D | ||
** Author: MasterLaplace | ||
** Created: 2023-10-12 | ||
** File description: | ||
** version | ||
*/ | ||
|
||
#ifndef VERSION_H_ | ||
#define VERSION_H_ | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Define the ENGINE version | ||
//////////////////////////////////////////////////////////// | ||
#ifdef FLAG_VERSION_MAJOR | ||
#define ENGINE_VERSION_MAJOR FLAG_VERSION_MAJOR | ||
#else | ||
#define ENGINE_VERSION_MAJOR 0 | ||
#endif | ||
|
||
#ifdef FLAG_VERSION_MINOR | ||
#define ENGINE_VERSION_MINOR FLAG_VERSION_MINOR | ||
#else | ||
#define ENGINE_VERSION_MINOR 1 | ||
#endif | ||
|
||
#ifdef FLAG_VERSION_PATCH | ||
#define ENGINE_VERSION_PATCH FLAG_VERSION_PATCH | ||
#else | ||
#define ENGINE_VERSION_PATCH 0 | ||
#endif | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Define the ENGINE version string | ||
//////////////////////////////////////////////////////////// | ||
// Helper macro to convert a macro to a string | ||
#define STRINGIFY(x) STRINGIFY_(x) | ||
#define STRINGIFY_(x) #x | ||
|
||
#define ENGINE_VERSION_STRING \ | ||
STRINGIFY(ENGINE_VERSION_MAJOR) "." \ | ||
STRINGIFY(ENGINE_VERSION_MINOR) "." \ | ||
STRINGIFY(ENGINE_VERSION_PATCH) | ||
|
||
#endif /* !VERSION_H_ */ |
This file contains 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,23 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Title: Engine-3D | ||
** Author: MasterLaplace | ||
** Created: 2023-10-12 | ||
** File description: | ||
** config | ||
*/ | ||
|
||
#ifndef CONFIG_H_ | ||
#define CONFIG_H_ | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Include the appropriate header based on the platform used: | ||
// - the GraphicsLibrary used by the user (OpenGL, Vulkan, DirectX, etc.) | ||
// - the OperatingSystem used by the user (Windows, Linux, MacOS, etc.) | ||
// - the Version of the Engine used by the user (0.0.1, 0.1.0, 1.0.0, etc.) | ||
//////////////////////////////////////////////////////////// | ||
#include "GraphicsLibrary/graphics.h" | ||
#include "OperatingSystem/distribution.h" | ||
#include "Version/version.h" | ||
|
||
#endif /* !CONFIG_H_ */ |
This file contains 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,85 @@ | ||
/* | ||
** EPITECH PROJECT, 2023 | ||
** Title: Engine-3D | ||
** Author: MasterLaplace | ||
** Created: 2023-10-12 | ||
** File description: | ||
** clock | ||
*/ | ||
|
||
#include "engine_clock.h" | ||
|
||
engine_clock_t *clock_create(void) | ||
{ | ||
engine_clock_t *clock = (engine_clock_t*)malloc(sizeof(engine_clock_t)); | ||
#if GRAPHICS_LIBRARY == CSFML | ||
clock->clock = sfClock_create(); | ||
#elif GRAPHICS_LIBRARY == SFML | ||
clock->clock = new sf::Clock(); | ||
#elif GRAPHICS_LIBRARY == SDL | ||
clock->clock = SDL_CreateClock(); | ||
#elif GRAPHICS_LIBRARY == OPENGL | ||
clock->clock = GL_CreateClock(); | ||
#elif GRAPHICS_LIBRARY == VULKAN | ||
clock->clock = VK_CreateClock(); | ||
#endif | ||
return clock; | ||
} | ||
|
||
void clock_destroy(engine_clock_t *clock) | ||
{ | ||
#if GRAPHICS_LIBRARY == CSFML | ||
sfClock_destroy(clock->clock); | ||
#elif GRAPHICS_LIBRARY == SFML | ||
delete clock->clock; | ||
#elif GRAPHICS_LIBRARY == SDL | ||
SDL_DestroyClock(clock->clock); | ||
#elif GRAPHICS_LIBRARY == OPENGL //using glwf for opengl and vulkan | ||
GL_DestroyClock(clock->clock); | ||
#elif GRAPHICS_LIBRARY == VULKAN | ||
VK_DestroyClock(clock->clock); | ||
#elif GRAPHICS_LIBRARY == DIRECTX | ||
DX_DestroyClock(clock->clock); | ||
#endif | ||
free(clock); | ||
} | ||
|
||
void clock_restart(engine_clock_t *clock) | ||
{ | ||
#if GRAPHICS_LIBRARY == CSFML | ||
sfClock_restart(clock->clock); | ||
#elif GRAPHICS_LIBRARY == SFML | ||
clock->clock->restart(); | ||
#elif GRAPHICS_LIBRARY == SDL | ||
SDL_RestartClock(clock->clock); | ||
#elif GRAPHICS_LIBRARY == OPENGL | ||
GL_RestartClock(clock->clock); | ||
#elif GRAPHICS_LIBRARY == VULKAN | ||
VK_RestartClock(clock->clock); | ||
#elif GRAPHICS_LIBRARY == DIRECTX | ||
DX_RestartClock(clock->clock); | ||
#endif | ||
} | ||
|
||
float clock_get_f_delta_time(engine_clock_t *clock) | ||
{ | ||
#if GRAPHICS_LIBRARY == CSFML | ||
float delta_time = sfTime_asSeconds(sfClock_getElapsedTime(clock->clock)); | ||
return sfClock_restart(clock->clock), delta_time; | ||
#elif GRAPHICS_LIBRARY == SFML | ||
float delta_time = clock->clock->getElapsedTime().asSeconds(); | ||
return clock->clock->restart().asSeconds(), delta_time; | ||
#elif GRAPHICS_LIBRARY == SDL | ||
float delta_time = SDL_GetElapsedTime(clock->clock); | ||
return SDL_RestartClock(clock->clock), delta_time; | ||
#elif GRAPHICS_LIBRARY == OPENGL | ||
float delta_time = GL_GetElapsedTime(clock->clock); | ||
return GL_RestartClock(clock->clock), delta_time; | ||
#elif GRAPHICS_LIBRARY == VULKAN | ||
float delta_time = VK_GetElapsedTime(clock->clock); | ||
return VK_RestartClock(clock->clock), delta_time; | ||
#elif GRAPHICS_LIBRARY == DIRECTX | ||
float delta_time = DX_GetElapsedTime(clock->clock); | ||
return DX_RestartClock(clock->clock), delta_time; | ||
#endif | ||
} |
Oops, something went wrong.