diff --git a/.gitignore b/.gitignore index e7bcb40..c7eb1b3 100644 --- a/.gitignore +++ b/.gitignore @@ -332,10 +332,6 @@ PublishScripts/ *.nupkg # NuGet Symbol Packages *.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/[Pp]ackages/repositories.config # NuGet v3's project.json files produces more ignorable files diff --git a/CMakeLists.txt b/CMakeLists.txt index daaa161..39b3ad3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,10 +18,13 @@ endif() # ~ OPTIONS ~ # option(ARCHEUS_STD_DEFAULT_CONFIG "Build with default config keys" ON) +set(ARCHEUS_STD_CONSOLE_BACKEND "NONE" CACHE STRING "Console Backend to build with") +set_property(CACHE ARCHEUS_STD_CONSOLE_BACKEND PROPERTY STRINGS NONE NCURSES) + set(ARCHEUS_STD_WINDOW_BACKEND "NONE" CACHE STRING "Window Backend to build with") set_property(CACHE ARCHEUS_STD_WINDOW_BACKEND PROPERTY STRINGS NONE SDL2 GLFW) -set(ARCHEUS_STD_INPUT_BACKEND "NONE" CACHE STRING "Input Backend to build with, most likely should match Window API") +set(ARCHEUS_STD_INPUT_BACKEND "NONE" CACHE STRING "Input Backend to build with, most likely should match Window Backend") set_property(CACHE ARCHEUS_STD_INPUT_BACKEND PROPERTY STRINGS NONE SDL2 GLFW) set(ARCHEUS_STD_GRAPHICS_BACKEND "NONE" CACHE STRING "Graphics Backend to build with") @@ -49,6 +52,7 @@ set(ARCHEUS_STD_SOURCES src/std/queue.c src/std/stack.c src/std/string.c + src/std/time.c src/std/vector.c src/std/defaults/config.c @@ -78,9 +82,13 @@ endif() include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_none.cmake) none_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND}) +# ~ NCURSES ~ # +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_ncurses.cmake) +ncurses_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_CONSOLE_BACKEND}) + # ~ SDL2 ~ # include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_sdl2.cmake) -sdl2_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ARCHEUS_STD_INCLUDE_DIRECTORIES ARCHEUS_STD_LINK_LIBRARIES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND}) +sdl2_check_and_init_needed(ARCHEUS_STD_SOURCES ARCHEUS_STD_INCLUDE_DIRECTORIES ARCHEUS_STD_LINK_LIBRARIES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND}) # ~ OPENGL ~ # include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_opengl.cmake) diff --git a/cmake/archeus_none.cmake b/cmake/archeus_none.cmake index 6617778..71e10cf 100644 --- a/cmake/archeus_none.cmake +++ b/cmake/archeus_none.cmake @@ -1,22 +1,23 @@ set(ARCHEUS_STD_NONE_WINDOW_SOURCES - src/graphics/none/window.c + src/graphics/window.c ) set(ARCHEUS_STD_NONE_INPUT_SOURCES - src/input/none/keyboard.c - src/input/none/mouse.c + src/input/input.c + src/input/keyboard.c + src/input/mouse.c ) set(ARCHEUS_STD_NONE_GRAPHICS_SOURCES - src/graphics/none/circle.c - src/graphics/none/config.c - src/graphics/none/line.c - src/graphics/none/obround.c - src/graphics/none/rectangle.c - src/graphics/none/renderer.c - src/graphics/none/sprite.c - src/graphics/none/spritesheet.c - src/graphics/none/text.c + src/graphics/circle.c + src/graphics/config.c + src/graphics/line.c + src/graphics/obround.c + src/graphics/rectangle.c + src/graphics/renderer.c + src/graphics/sprite.c + src/graphics/spritesheet.c + src/graphics/text.c ) function(none_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND) diff --git a/cmake/archeus_opengl.cmake b/cmake/archeus_opengl.cmake index 37ee242..087a0cb 100644 --- a/cmake/archeus_opengl.cmake +++ b/cmake/archeus_opengl.cmake @@ -1,11 +1,11 @@ set(ARCHEUS_STD_OPENGL_GRAPHICS_SOURCES - src/graphics/opengl/circle.c - src/graphics/opengl/line.c - src/graphics/opengl/obround.c - src/graphics/opengl/rectangle.c - src/graphics/opengl/sprite.c - src/graphics/opengl/spritesheet.c - src/graphics/opengl/text.c + packages/graphics/opengl/circle.c + packages/graphics/opengl/line.c + packages/graphics/opengl/obround.c + packages/graphics/opengl/rectangle.c + packages/graphics/opengl/sprite.c + packages/graphics/opengl/spritesheet.c + packages/graphics/opengl/text.c ) function(opengl_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES ARCHEUS_STD_GRAPHICS_BACKEND) diff --git a/cmake/archeus_sdl2.cmake b/cmake/archeus_sdl2.cmake index d530c9c..9b73011 100644 --- a/cmake/archeus_sdl2.cmake +++ b/cmake/archeus_sdl2.cmake @@ -1,25 +1,26 @@ set(ARCHEUS_STD_SDL2_WINDOW_SOURCES - src/graphics/sdl/window.c - src/graphics/sdl/renderer.c + packages/graphics/sdl/window.c + packages/graphics/sdl/renderer.c ) set(ARCHEUS_STD_SDL2_INPUT_SOURCES - src/input/sdl/keyboard.c - src/input/sdl/mouse.c + packages/input/sdl/input.c + packages/input/sdl/keyboard.c + packages/input/sdl/mouse.c ) set(ARCHEUS_STD_SDL2_GRAPHICS_SOURCES - src/graphics/sdl/circle.c - src/graphics/sdl/config.c - src/graphics/sdl/line.c - src/graphics/sdl/obround.c - src/graphics/sdl/rectangle.c - src/graphics/sdl/sprite.c - src/graphics/sdl/spritesheet.c - src/graphics/sdl/text.c + packages/graphics/sdl/circle.c + packages/graphics/sdl/config.c + packages/graphics/sdl/line.c + packages/graphics/sdl/obround.c + packages/graphics/sdl/rectangle.c + packages/graphics/sdl/sprite.c + packages/graphics/sdl/spritesheet.c + packages/graphics/sdl/text.c ) -function(sdl2_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES _ARCHEUS_STD_INCLUDE_DIRECTORIES _ARCHEUS_STD_LINK_LIBRARIES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND) +function(sdl2_check_and_init_needed _ARCHEUS_STD_SOURCES _ARCHEUS_STD_INCLUDE_DIRECTORIES _ARCHEUS_STD_LINK_LIBRARIES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND) #if no backend uses sdl return if(NOT ${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2") return() @@ -40,12 +41,10 @@ function(sdl2_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES _ARC #add matching files for the selected backends if(${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2") - string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_SDL2_WINDOW ") list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_WINDOW_SOURCES}) endif() if(${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2") - string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_SDL2_INPUT ") list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_INPUT_SOURCES}) endif() @@ -53,7 +52,6 @@ function(sdl2_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES _ARC find_package(SDL2_image REQUIRED) find_package(SDL2_ttf REQUIRED) - string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_SDL2_GRAPHICS ") list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_GRAPHICS_SOURCES}) #add to include directories @@ -68,7 +66,6 @@ function(sdl2_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES _ARC ) endif() - set(${_ARCHEUS_STD_FLAGS} ${${_ARCHEUS_STD_FLAGS}} PARENT_SCOPE) set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE) set(${_ARCHEUS_STD_INCLUDE_DIRECTORIES} ${${_ARCHEUS_STD_INCLUDE_DIRECTORIES}} PARENT_SCOPE) set(${_ARCHEUS_STD_LINK_LIBRARIES} ${${_ARCHEUS_STD_LINK_LIBRARIES}} PARENT_SCOPE) diff --git a/include/arc/audio/sdl/audio.h b/include/arc/audio/sdl/audio.h deleted file mode 100644 index 92afa3e..0000000 --- a/include/arc/audio/sdl/audio.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef ARC_SDL_AUDIO_H_ -#define ARC_SDL_AUDIO_H_ - -#ifdef ARC_SDL -#include - -typedef struct ARC_Audio { - Mix_Chunk *chunk; -} ARC_Audio; - -#endif // !ARC_SDL -#endif // !ARC_SDL_AUDIO_H_ diff --git a/include/arc/engine/engine.h b/include/arc/engine/engine.h index 0c75d81..64d1d29 100644 --- a/include/arc/engine/engine.h +++ b/include/arc/engine/engine.h @@ -7,37 +7,51 @@ extern "C" { #include "arc/graphics/window.h" #include "arc/graphics/renderer.h" +#include "arc/input/input.h" #include "arc/input/mouse.h" #include "arc/input/keyboard.h" -#include "arc/std/handler.h" #include "arc/math/point.h" +#include "arc/std/bool.h" +#include "arc/std/handler.h" typedef struct ARC_EngineData { ARC_Window *window; ARC_Renderer *renderer; ARC_Handler *state; + ARC_Input *input; ARC_Mouse *mouse; ARC_Keyboard *keyboard; double dt; - uint32_t running; + ARC_Bool running; ARC_Point windowSize; } ARC_EngineData; -//NOTE: most work below is temp, and will change once I figure out a better way to write this header - -void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanfn, ARC_Point windowSize); +/** + * @breif creates an ARC_EngineData type to be used when running an ARC_Engine + * + * @param data the ARC_EngineData to create + * @param cleanFn the state cleanup function + * @param windowSIze the size of window to create passed as an ARC_Point +*/ +void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanFn, ARC_Point windowSize); +/** + * @breif destroys an ARC_EngineData type + * + * @param data the ARC_EngineData to destroy +*/ void ARC_EngineData_Destroy(ARC_EngineData *data); /** - * @brief runs ARC_Engine + * @brief runs ARC_Engine with an uncapped framerate + * + * @note data must be created before this function + * @note data should be destroyed after this function * * @param data engine data that will be used - * data must be created before this function - * and must be destroyed after this function */ -void ARC_Engine_Run(ARC_EngineData *data); +void ARC_Engine_RunUncapped(ARC_EngineData *data); #ifdef __cplusplus } diff --git a/include/arc/graphics/glfw/renderer.h b/include/arc/graphics/glfw/renderer.h deleted file mode 100644 index 0fd013f..0000000 --- a/include/arc/graphics/glfw/renderer.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef ARC_OPENGL_RENDERER_H_ -#define ARC_OPENGL_RENDERER_H_ - -#ifdef ARC_GLFW_WINDOW - -#define GLEW_STATIC -#include - -#include - -#include "arc/graphics/renderer.h" -#include "arc/graphics/window.h" - -typedef struct ARC_RendererType { - GLFWwindow *window; -} ARC_RendererType; - -/** - * @brief struct for info needed to create glfw renderer - * - * @note this is what needs to be passed into the data parameter for ARC_Renderer_Create - */ -struct ARC_RenderInfo { - GLFWwindow *window; -}; - -#endif // !ARC_GLFW_WINDOW - -#endif // !ARC_OPENGL_RENDERER_H_ diff --git a/include/arc/graphics/glfw/window.h b/include/arc/graphics/glfw/window.h deleted file mode 100644 index 471eef3..0000000 --- a/include/arc/graphics/glfw/window.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef ARC_OPENGL_WINDOW_H_ -#define ARC_OPENGL_WINDOW_H_ - -#ifdef ARC_GLFW_WINDOW - -#define GLEW_STATIC -#include - -#include "arc/graphics/window.h" -#include - -typedef GLFWwindow ARC_WindowType; - -/** - * @brief struct for info needed to create a GLFWwindow - * - * @note this is what needs to be passed into the data parameter for ARC_Window_Create - */ -struct ARC_WindowInfo { - char *title; - int w; - int h; -}; - -#endif // !ARC_GLFW_WINDOW - -#endif // !ARC_GLFW_WINDOW_H_ diff --git a/include/arc/graphics/none/renderer.h b/include/arc/graphics/none/renderer.h index 72a3cf2..1031816 100644 --- a/include/arc/graphics/none/renderer.h +++ b/include/arc/graphics/none/renderer.h @@ -1,13 +1,11 @@ #ifdef ARC_NONE_GRAPHICS -#include "arc/graphics/renderer.h" +//#include "arc/graphics/renderer.h" #ifndef ARC_NONE_RENDERER_H_ #define ARC_NONE_RENDERER_H_ -typedef void ARC_RendererType; - -struct ARC_RenderInfo {}; +//typedef void ARC_RendererType; #endif // !ARC_NONE_RENDERER_H_ diff --git a/include/arc/graphics/none/window.h b/include/arc/graphics/none/window.h index d2594a2..91303c7 100644 --- a/include/arc/graphics/none/window.h +++ b/include/arc/graphics/none/window.h @@ -3,12 +3,10 @@ #ifndef ARC_NONE_WINDOW_H_ #define ARC_NONE_WINDOW_H_ -#include "arc/graphics/window.h" +//#include "arc/graphics/window.h" -typedef void ARC_WindowType; - -struct ARC_WindowInfo {}; +//typedef void ARC_WindowType; #endif // !ARC_SDL_WINDOW_H_ -#endif // !ARC_NONE_WINDOW \ No newline at end of file +#endif // !ARC_NONE_WINDOW diff --git a/include/arc/graphics/opengl/sprite.h b/include/arc/graphics/opengl/sprite.h deleted file mode 100644 index 8895174..0000000 --- a/include/arc/graphics/opengl/sprite.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ARC_OPENGL_SPRITE_H_ -#define ARC_OPENGL_SPRITE_H_ - -#ifdef ARC_OPENGL_GRAPHICS - -#include "arc/graphics/sprite.h" - -struct ARC_Sprite { -}; - -#endif // !ARC_OPENGL_GRAPHICS - -#endif // !ARC_OPENGL_SPRITE_H_ diff --git a/include/arc/graphics/opengl/spritesheet.h b/include/arc/graphics/opengl/spritesheet.h deleted file mode 100644 index a320d8c..0000000 --- a/include/arc/graphics/opengl/spritesheet.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef ARC_OPENGL_SPRITESHEET_H_ -#define ARC_OPENGL_SPRITESHEET_H_ - -#ifdef ARC_OPENGL_GRAPHICS - -#include "arc/graphics/spritesheet.h" - -struct ARC_Spritesheet { -}; - -#endif // !ARC_OPENGL_GRAPHICS - -#endif // !ARC_OPENGL_SPRITESHEET_H_ diff --git a/include/arc/graphics/opengl/text.h b/include/arc/graphics/opengl/text.h deleted file mode 100644 index 526b4ce..0000000 --- a/include/arc/graphics/opengl/text.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef ARC_OPENGL_TEXT_H_ -#define ARC_OPENGL_TEXT_H_ - -#include "arc/std/string.h" -#include "arc/graphics/color.h" -#include "arc/math/rectangle.h" - -#ifdef ARC_OPENGL_GRAPHICS - -typedef struct ARC_Text {} ARC_Text; - -#endif // !ARC_OPENGL_GRAPHICS - -#endif // !ARC_OPENGL_TEXT_H_ diff --git a/include/arc/graphics/renderer.h b/include/arc/graphics/renderer.h index 4343046..e5f7ab4 100644 --- a/include/arc/graphics/renderer.h +++ b/include/arc/graphics/renderer.h @@ -5,23 +5,26 @@ extern "C" { #endif +/** + * @brief predefien ARC_EngineData so as not to get circular reference +*/ +typedef struct ARC_EngineData ARC_EngineData; + /** * @note ARC_RendererType is determined by which window library you are using */ typedef struct ARC_RendererType ARC_Renderer; -typedef struct ARC_RenderInfo ARC_RenderInfo; - /** - * @brief creates ARC_Renderer type + * @brief creates ARC_Renderer type with ARC_EngineData * * @note the parameter data is determined by which graphics library you are using * please refer to the graphics library section to see what needs to be passed * * @param renderer ARC_Renderer to initialize - * @param info Info on how to create ARC_Window + * @param data the engine data to create from */ -void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info); +void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *data); /** * @brief destroys ARC_Renderer type @@ -30,8 +33,20 @@ void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info); */ void ARC_Renderer_Destroy(ARC_Renderer *renderer); +/** + * @breif clears the renderer + * + * @param renderer the renderer to clear +*/ void ARC_Renderer_Clear(ARC_Renderer *renderer); +/** + * @brief renders the renderer + * + * @note the renderer will most likely be drawn to from ARC_EngineData + * + * @param renderer the renderer to render +*/ void ARC_Renderer_Render(ARC_Renderer *renderer); #ifdef __cplusplus diff --git a/include/arc/graphics/sdl/renderer.h b/include/arc/graphics/sdl/renderer.h deleted file mode 100644 index 3ee8e8d..0000000 --- a/include/arc/graphics/sdl/renderer.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef ARC_SDL_RENDERER_H_ -#define ARC_SDL_RENDERER_H_ - -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/renderer.h" -#include "arc/graphics/window.h" -#include - -typedef SDL_Renderer ARC_RendererType; - -/** - * @brief struct for info needed to create SDL_Renderer - * - * @note this is what needs to be passed into the data parameter for ARC_Renderer_Create - */ - -struct ARC_RenderInfo { - SDL_Window *window; - int index; - Uint32 flags; -}; - -#endif // !ARC_SDL2_GRAPHICS - -#endif // !ARC_SDL_RENDERER_H_ diff --git a/include/arc/graphics/sdl/sprite.h b/include/arc/graphics/sdl/sprite.h deleted file mode 100644 index a181bb6..0000000 --- a/include/arc/graphics/sdl/sprite.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ARC_SDL_SPRITE_H_ -#define ARC_SDL_SPRITE_H_ - -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/sprite.h" -#include - -struct ARC_Sprite { - ARC_Spritesheet *spritesheet; - ARC_Array *frames; - uint32_t *frameIndex; - //TODO: temp - uint8_t opacity; -}; - -#endif // !ARC_SDL2_GRAPHICS - -#endif // !ARC_SDL_SPRITE_H_ diff --git a/include/arc/graphics/sdl/spritesheet.h b/include/arc/graphics/sdl/spritesheet.h deleted file mode 100644 index dfbf6b1..0000000 --- a/include/arc/graphics/sdl/spritesheet.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ARC_SDL_SPRITESHEET_H_ -#define ARC_SDL_SPRITESHEET_H_ - -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/spritesheet.h" -#include - -struct ARC_Spritesheet { - SDL_Texture *texture; - uint32_t *size; -}; - -#endif // !ARC_SDL2_GRPAHCIS - -#endif // !ARC_SDL_SPRITESHEET_H_ diff --git a/include/arc/graphics/sdl/text.h b/include/arc/graphics/sdl/text.h deleted file mode 100644 index 37a6a5c..0000000 --- a/include/arc/graphics/sdl/text.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ARC_SDL_TEXT_H_ -#define ARC_SDL_TEXT_H_ - -#include "arc/std/string.h" -#include "arc/graphics/color.h" -#include "arc/math/rectangle.h" - -#ifdef ARC_SDL2_GRAPHICS -#include - -typedef struct ARC_Text { - ARC_String *name; - int32_t size; - - ARC_Color color; - - SDL_Texture *texture; - ARC_Rect bounds; -} ARC_Text; - -#endif // !ARC_SDL2_Graphics - -#endif // !ARC_SDL_TEXT_H_ diff --git a/include/arc/graphics/sdl/window.h b/include/arc/graphics/sdl/window.h deleted file mode 100644 index dafe582..0000000 --- a/include/arc/graphics/sdl/window.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ARC_SDL_WINDOW_H_ -#define ARC_SDL_WINDOW_H_ - -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/window.h" -#include - -typedef SDL_Window ARC_WindowType; - -/** - * @brief struct for info needed to create SDL_Window - * - * @note this is what needs to be passed into the data parameter for ARC_Window_Create - */ -struct ARC_WindowInfo { - char *title; - int x; - int y; - int w; - int h; - Uint32 flags; -}; - -#endif // !ARC_SDL2_GRAPHICS - -#endif // !ARC_SDL_WINDOW_H_ diff --git a/include/arc/graphics/window.h b/include/arc/graphics/window.h index e63acf1..c30b23f 100644 --- a/include/arc/graphics/window.h +++ b/include/arc/graphics/window.h @@ -5,12 +5,21 @@ extern "C" { #endif +#include + /** - * @note ARC_WindowType is determined by which window library you are using + * @note ARC_WindowType is determined by which window backend you are using */ typedef struct ARC_WindowType ARC_Window; -typedef struct ARC_WindowInfo ARC_WindowInfo; +/** + * @note certain parts of ARC_WindowInfo may not be used by your selected backend +*/ +typedef struct ARC_WindowInfo { + char *title; + int32_t w; + int32_t h; +} ARC_WindowInfo; /** * @brief creates ARC_Window type diff --git a/include/arc/input/glfw/keyboard.h b/include/arc/input/glfw/keyboard.h deleted file mode 100644 index 451fb65..0000000 --- a/include/arc/input/glfw/keyboard.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ARC_GLFW_KEYBOARD_H_ -#define ARC_GLFW_KEYBOARD_H_ - -#ifdef ARC_GLFW_INPUT -#include -#include "arc/input/keyboard.h" - -struct ARC_Keyboard { - GLFWwindow *window; - - ARC_KeyboardState *keys; - ARC_KeyboardState *released; -}; - -struct ARC_KeyboardInfo { - GLFWwindow *window; -}; - -#endif // !ARC_GLFW_INPUT - -#endif // !ARC_GLFW_KEYBOARD_H_ \ No newline at end of file diff --git a/include/arc/input/glfw/mouse.h b/include/arc/input/glfw/mouse.h deleted file mode 100644 index 281ae00..0000000 --- a/include/arc/input/glfw/mouse.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef ARC_GLFW_MOUSE_H_ -#define ARC_GLFW_MOUSE_H_ - -#ifdef ARC_GLFW_INPUT -#include -#include "arc/input/mouse.h" -#include "arc/math/point.h" - -struct ARC_Mouse { - GLFWwindow *window; - - ARC_Point *coords; - int32_t *scrollY; - - ARC_MouseState *buttons; - uint8_t *buttonsReleased; -}; - -struct ARC_MouseInfo { - GLFWwindow *window; -}; - -#endif // !ARC_GLFW_INPUT - -#endif // !ARC_GLFW_MOUSE_H_ \ No newline at end of file diff --git a/include/arc/input/keyboard.h b/include/arc/input/keyboard.h index 10e7e5c..82b6c48 100644 --- a/include/arc/input/keyboard.h +++ b/include/arc/input/keyboard.h @@ -7,6 +7,11 @@ extern "C" { #include +/** + * @brief predefien ARC_Input so as not to get circular reference +*/ +typedef struct ARC_Input ARC_Input; + typedef struct ARC_Keyboard ARC_Keyboard; typedef struct ARC_KeyboardInfo ARC_KeyboardInfo; @@ -19,7 +24,8 @@ typedef enum ARC_KeyboardState { #define ARC_KEYBOARD_BUTTON_NUM 239 -void ARC_Keyboard_Create(ARC_Keyboard **keyboard, ARC_KeyboardInfo *info); +void ARC_Keyboard_CreateWithInput(ARC_Keyboard **keyboard, ARC_Input *input); + void ARC_Keyboard_Destroy(ARC_Keyboard *keyboard); void ARC_Keyboard_Update(ARC_Keyboard *keyboard); diff --git a/include/arc/input/mouse.h b/include/arc/input/mouse.h index a7e20d5..5f60780 100644 --- a/include/arc/input/mouse.h +++ b/include/arc/input/mouse.h @@ -8,9 +8,12 @@ extern "C" { #include "arc/math/point.h" #include -typedef struct ARC_Mouse ARC_Mouse; +/** + * @brief predefien ARC_Input so as not to get circular reference +*/ +typedef struct ARC_Input ARC_Input; -typedef struct ARC_MouseInfo ARC_MouseInfo; +typedef struct ARC_Mouse ARC_Mouse; typedef enum ARC_MouseState { ARC_MOUSE_NONE, @@ -28,7 +31,8 @@ typedef enum ARC_MouseButton { #define ARC_MOUSE_BUTTON_NUM 5 -void ARC_Mouse_Create(ARC_Mouse **mouse, ARC_MouseInfo *info); +void ARC_Mouse_CreateWithInput(ARC_Mouse **mouse, ARC_Input *input); + void ARC_Mouse_Destroy(ARC_Mouse *mouse); void ARC_Mouse_Update(ARC_Mouse *mouse); ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse); @@ -39,4 +43,4 @@ int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse); } #endif -#endif // !ARC_GRAPHICS_MOUSE_H_ \ No newline at end of file +#endif // !ARC_GRAPHICS_MOUSE_H_ diff --git a/include/arc/input/sdl/keyboard.h b/include/arc/input/sdl/keyboard.h deleted file mode 100644 index 0003aea..0000000 --- a/include/arc/input/sdl/keyboard.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ARC_SDL_KEYBOARD_H_ -#define ARC_SDL_KEYBOARD_H_ - -#ifdef ARC_SDL2_INPUT -#include "arc/input/keyboard.h" -#include - -struct ARC_Keyboard { - SDL_Event *event; - - ARC_KeyboardState *keys; - ARC_KeyboardState *released; -}; - -struct ARC_KeyboardInfo { - SDL_Event *event; -}; - -#endif // ARC_SDL2_INPUT - -#endif // !ARC_SDL_KEYBOARD_H_ \ No newline at end of file diff --git a/include/arc/input/sdl/mouse.h b/include/arc/input/sdl/mouse.h deleted file mode 100644 index d534946..0000000 --- a/include/arc/input/sdl/mouse.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef ARC_SDL_MOUSE_H_ -#define ARC_SDL_MOUSE_H_ - -#ifdef ARC_SDL2_INPUT -#include -#include "arc/input/mouse.h" -#include "arc/math/point.h" - -struct ARC_Mouse { - SDL_Event *event; - ARC_Point *coords; - int32_t *scrollY; - - ARC_MouseState *buttons; - uint8_t *buttonsReleased; -}; - -struct ARC_MouseInfo { - SDL_Event *event; -}; - -#endif // ARC_SDL2_INPUT - -#endif // !ARC_SDL_MOUSE_H_ \ No newline at end of file diff --git a/include/arc/std/errno.h b/include/arc/std/errno.h index 8949b29..15096a2 100644 --- a/include/arc/std/errno.h +++ b/include/arc/std/errno.h @@ -3,12 +3,13 @@ #include -#define ARC_ERRNO_NULL -0x01 -#define ARC_ERRNO_DATA -0x02 -#define ARC_ERRNO_COPY -0x03 -#define ARC_ERRNO_EXISTS -0x04 -#define ARC_ERRNO_OVERFLOW -0x05 -#define ARC_ERRNO_INIT -0x06 +#define ARC_ERRNO_NULL -0x01 +#define ARC_ERRNO_DATA -0x02 +#define ARC_ERRNO_COPY -0x03 +#define ARC_ERRNO_EXISTS -0x04 +#define ARC_ERRNO_OVERFLOW -0x05 +#define ARC_ERRNO_INIT -0x06 +#define ARC_ERRNO_CONNECTION -0x07 #ifdef __cplusplus extern "C" { diff --git a/include/arc/std/handler.h b/include/arc/std/handler.h index 4a5abe3..525af99 100644 --- a/include/arc/std/handler.h +++ b/include/arc/std/handler.h @@ -84,7 +84,7 @@ void ARC_Handler_Remove(ARC_Handler *handler, void *data, ARC_Handler_CompareDat * @param handler ARC_Handler to remove from * @param index index of data that is being removed */ -void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t *index); +void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index); /** * @brief calls provided function on each element in handler @@ -115,7 +115,7 @@ void ARC_Handler_Clean(ARC_Handler *handler); * * @param handler ARC_handler to get size from */ -uint32_t *ARC_Handler_Size(ARC_Handler *handler); +uint32_t ARC_Handler_Size(ARC_Handler *handler); #ifdef __cplusplus } diff --git a/include/arc/std/vector.h b/include/arc/std/vector.h index f38ec27..dad261c 100644 --- a/include/arc/std/vector.h +++ b/include/arc/std/vector.h @@ -57,7 +57,7 @@ void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn * @param vector ARC_Vector to remove from * @param index index of data that is being removed */ -void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index); +void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t index); /** * @brief gets size of vector @@ -66,7 +66,7 @@ void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index); * * @return the pointer of the vectors size, TODO: don't pass as a pointer */ -uint32_t *ARC_Vector_Size(ARC_Vector *vector); +uint32_t ARC_Vector_Size(ARC_Vector *vector); /** * @brief gets data from ARC_Vector at position index @@ -76,7 +76,7 @@ uint32_t *ARC_Vector_Size(ARC_Vector *vector); * * @return pointer to data on success, NULL on fail */ -void *ARC_Vector_Get(ARC_Vector *vector, uint32_t *index); +void *ARC_Vector_Get(ARC_Vector *vector, uint32_t index); #ifdef __cplusplus } diff --git a/src/audio/sdl/audio.c b/src/audio/sdl/audio.c deleted file mode 100644 index 8709787..0000000 --- a/src/audio/sdl/audio.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "arc/audio/audio.h" -#include "arc/audio/sdl/audio.h" -#include - -void ARC_Audio_Play(ARC_Audio *audio){ - Mix_PlayChannel(-1, audio->chunk, 0); -} \ No newline at end of file diff --git a/src/audio/sdl/config.c b/src/audio/sdl/config.c deleted file mode 100644 index 141b23d..0000000 --- a/src/audio/sdl/config.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "arc/audio/config.h" -#include "arc/audio/sdl/audio.h" -#include -#include -#include "arc/std/config.h" -#include "arc/std/errno.h" -#include "arc/audio/audio.h" - -// #define ARC_DEFAULT_CONFIG -#include "arc/std/defaults/config.h" - -void ARC_AudioConfig_Init(ARC_Config *config){ - ARC_Config_AddKeyCString(config, (char *)"ARC_Audio", 9, ARC_Audio_Read, ARC_Audio_Delete); -} - -uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value){ - ARC_Config_Get(config, string, value); - if(*value){ - return 1; - } - - if(string->data[0] != '"' || string->data[string->length - 1] != '"'){ - ARC_DEBUG_LOG(arc_errno, "in ARC_Point_Read(config, string, value); no matching quotes: %s", string->data); - arc_errno = ARC_ERRNO_DATA; - return 0; - } - - ARC_Audio *audio = (ARC_Audio *)malloc(sizeof(ARC_Audio)); - - ARC_String *path; - ARC_String_CopySubstring(&path, string, 1, string->length - 2); - audio->chunk = Mix_LoadWAV(path->data); - - //TODO: get error message if not loaded - - *value = (void *)audio; - return 0; -} - -void ARC_Audio_Delete(ARC_Config* config, ARC_String *string, void *value){ - Mix_FreeChunk(((ARC_Audio *)value)->chunk); - free((ARC_Audio *)value); -} \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index 35df2d7..522c9ba 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -1,94 +1,50 @@ #include "arc/engine/engine.h" + +//NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas #include #include "arc/engine/state.h" #include "arc/graphics/window.h" #include "arc/graphics/renderer.h" #include "arc/input/mouse.h" #include "arc/input/keyboard.h" +#include "arc/std/bool.h" #include "arc/std/errno.h" #include "arc/std/handler.h" -//NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas -#include "arc/graphics/none/window.h" -#include "arc/graphics/none/renderer.h" -#include "arc/input/none/mouse.h" -#include "arc/input/none/keyboard.h" - -#include "arc/graphics/sdl/window.h" -#include "arc/graphics/sdl/renderer.h" -#include "arc/input/sdl/mouse.h" -#include "arc/input/sdl/keyboard.h" - -#include "arc/graphics/glfw/window.h" -#include "arc/graphics/glfw/renderer.h" -#include "arc/input/glfw/mouse.h" -#include "arc/input/glfw/keyboard.h" - -void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanfn, ARC_Point windowSize){ +void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanFn, ARC_Point windowSize){ *data = (ARC_EngineData *)malloc(sizeof(ARC_EngineData)); (*data)->window = NULL; (*data)->renderer = NULL; + (*data)->input = NULL; + (*data)->keyboard = NULL; (*data)->mouse = NULL; - ARC_Handler_Create(&((*data)->state), cleanfn); + ARC_Handler_Create(&((*data)->state), cleanFn); - ARC_WindowInfo windowInfo; - ARC_RenderInfo renderInfo; - ARC_MouseInfo mouseInfo; - ARC_KeyboardInfo keyboardInfo; - + (*data)->dt = 0.0; + (*data)->running = ARC_False; (*data)->windowSize = windowSize; -//TEMP -#ifdef ARC_SDL - // TTF_Init(); - // Mix_Init(0); - // Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024); -#endif - -#ifdef ARC_SDL2_WINDOW - windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (*data)->windowSize.x, (*data)->windowSize.y, 0 }; -#elif ARC_GLFW_WINDOW - windowInfo = (ARC_WindowInfo){ "title", (*data)->windowSize.x, (*data)->windowSize.y }; -#endif // ARC_SDL + ARC_WindowInfo windowInfo = (ARC_WindowInfo){ "title", (*data)->windowSize.x, (*data)->windowSize.y }; ARC_Window_Create(&((*data)->window), &windowInfo); if(arc_errno){ free(data); return; } -#ifdef ARC_SDL2_WINDOW - renderInfo = (ARC_RenderInfo){ (SDL_Window *)(*data)->window, -1, SDL_RENDERER_ACCELERATED }; -#elif ARC_GLFW_WINDOW - renderInfo = (ARC_RenderInfo){ (GLFWwindow *)(*data)->window }; -#endif // ARC_SDL - - ARC_Renderer_Create(&((*data)->renderer), &renderInfo); + ARC_Renderer_CreateWithEngineData(&((*data)->renderer), *data); if(arc_errno){ ARC_Window_Destroy((*data)->window); free(data); } -#ifdef ARC_SDL2_INPUT - SDL_Event *event = (SDL_Event *)malloc(sizeof(SDL_Event)); - mouseInfo = (ARC_MouseInfo ){ event }; - keyboardInfo = (ARC_KeyboardInfo){ event }; -#elif ARC_GLFW - mouseInfo = (ARC_MouseInfo ){ (GLFWwindow *)(*data)->window }; - keyboardInfo = (ARC_KeyboardInfo){ (GLFWwindow *)(*data)->window }; -#endif // ARC_SDL + ARC_Input_CreateWithEngineData(&((*data)->input), *data); - ARC_Mouse_Create (&((*data)->mouse) , &mouseInfo ); - ARC_Keyboard_Create(&((*data)->keyboard), &keyboardInfo); + (*data)->keyboard = ARC_Input_GetKeyboard((*data)->input); + (*data)->mouse = ARC_Input_GetMouse((*data)->input); } void ARC_EngineData_Destroy(ARC_EngineData *data){ -#ifdef ARC_SDL2_INPUT - free(data->mouse->event); - // TTF_Quit(); - // Mix_Quit(); -#endif // ARC_SDL - ARC_Mouse_Destroy(data->mouse); ARC_Keyboard_Destroy(data->keyboard); ARC_Renderer_Destroy(data->renderer); @@ -96,35 +52,20 @@ void ARC_EngineData_Destroy(ARC_EngineData *data){ ARC_Handler_Destroy(data->state); } -void ARC_Engine_Run(ARC_EngineData *data){ +void ARC_Engine_RunUncapped(ARC_EngineData *data){ if(arc_errno){ return; } -#ifdef ARC_SDL2_INPUT - SDL_Event *event = data->mouse->event; - double lastTime = 0, currentTime; - data->dt = 0; -#endif // ARC_SDL + // double lastTime = 0, currentTime; - data->running = 0; + data->running = ARC_True; + while(data->running){ + // currentTime = SDL_GetTicks(); + // data->dt = currentTime - lastTime; + // lastTime = currentTime; - while(!data->running){ -#ifdef ARC_SDL2_INPUT - currentTime = SDL_GetTicks(); - data->dt = currentTime - lastTime; - lastTime = currentTime; - - SDL_PollEvent(data->mouse->event); - if(event->type == SDL_QUIT){ data->running = 1; } -#elif ARC_GLFW_WINDOW - glfwPollEvents(); - data->running = glfwWindowShouldClose((GLFWwindow *)data->window); -#endif // ARC_SDL - - ARC_Mouse_Update(data->mouse); - - ARC_Keyboard_Update(data->keyboard); + ARC_Input_Update(data->input); ARC_Handler_Clean(data->state); diff --git a/src/graphics/glfw/config.c b/src/graphics/glfw/config.c deleted file mode 100644 index b2a138b..0000000 --- a/src/graphics/glfw/config.c +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef ARC_GLFW_WINDOW - -#include -#include "arc/std/config.h" -#include "arc/std/string.h" -#include "arc/std/errno.h" - -#include "arc/graphics/glfw/renderer.h" - - -void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){ -} - -#endif // ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/glfw/renderer.c b/src/graphics/glfw/renderer.c deleted file mode 100644 index 1906fb7..0000000 --- a/src/graphics/glfw/renderer.c +++ /dev/null @@ -1,52 +0,0 @@ -#ifdef ARC_GLFW_WINDOW -#include "arc/graphics/renderer.h" -#include "arc/graphics/glfw/renderer.h" - -// #ifdef ARC_GLEW -#define GLEW_STATIC -#include -// #endif // ARC_GLEW - -#include - -#include "arc/graphics/window.h" -#include "arc/std/errno.h" -#include - -void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info){ - if(!info){ - arc_errno = ARC_ERRNO_NULL; - ARC_DEBUG_ERR("ARC_Renderer_Create(**renderer, NULL)"); - return; - } - -// #ifdef ARC_GLEW - *renderer = (ARC_Renderer *)malloc(sizeof(ARC_Renderer)); - (*renderer)->window = info->window; - - glewExperimental = GL_TRUE; - if(glewInit() != GLEW_OK){ - ARC_DEBUG_ERR("ARC_Renderer_Create(**renderer, info), GLEW failed to init"); - glfwTerminate(); - arc_errno = ARC_ERRNO_INIT; - } -// #endif // ARC_GLEW - - glClearColor(0.23f, 0.38f, 0.47f, 1.0f); -} - -void ARC_Renderer_Destroy(ARC_Renderer *renderer){ - free(renderer); -} - -void ARC_Renderer_Clear(ARC_Renderer *renderer){ - glClear(GL_COLOR_BUFFER_BIT); -} - -void ARC_Renderer_Render(ARC_Renderer *renderer){ -// #ifdef ARC_GLEW - glfwSwapBuffers(renderer->window); -// #endif // ARC_GLEW -} - -#endif //ARC_SDL diff --git a/src/graphics/glfw/window.c b/src/graphics/glfw/window.c deleted file mode 100644 index f40a10b..0000000 --- a/src/graphics/glfw/window.c +++ /dev/null @@ -1,36 +0,0 @@ -#ifdef ARC_GLFW_WINDOW -#include "arc/graphics/window.h" -#include "arc/graphics/glfw/window.h" - -#include "arc/std/errno.h" -#include -#include - -void framebufferSizeCallback(GLFWwindow *window, int width, int height){ - glViewport(0, 0, width, height); -} - -void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){ - glfwInit(); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - glfwWindowHint(GLFW_FLOATING, GLFW_TRUE); - - *window = (ARC_Window *) glfwCreateWindow(info->w, info->h, "learnopengl window", NULL, NULL); - if(*window == NULL){ - printf("Failed to create GLFW window\n"); - glfwTerminate(); - arc_errno = ARC_ERRNO_NULL; - } - - glfwMakeContextCurrent((GLFWwindow *)*window); - glViewport(0, 0, info->w, info->h); - glfwSetFramebufferSizeCallback((GLFWwindow *)*window, framebufferSizeCallback); -} - -void ARC_Window_Destroy(ARC_Window *window){ - glfwTerminate(); -} - -#endif //ARC_GLFW diff --git a/src/graphics/none/circle.c b/src/graphics/none/circle.c deleted file mode 100644 index ffe771b..0000000 --- a/src/graphics/none/circle.c +++ /dev/null @@ -1,10 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/circle.h" -#include - -void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -#endif // !ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/config.c b/src/graphics/none/config.c deleted file mode 100644 index c307299..0000000 --- a/src/graphics/none/config.c +++ /dev/null @@ -1,10 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/config.h" -#include - -void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){ - printf("No Graphics Backend Selected\n"); -} - -#endif //ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/line.c b/src/graphics/none/line.c deleted file mode 100644 index 2f59143..0000000 --- a/src/graphics/none/line.c +++ /dev/null @@ -1,10 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/line.h" -#include - -void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -#endif // !ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/obround.c b/src/graphics/none/obround.c deleted file mode 100644 index 4192c4f..0000000 --- a/src/graphics/none/obround.c +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/obround.h" -#include - -void ARC_Obround_Render(ARC_Obround *obround, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_FObround_Render(ARC_FObround *obround, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -#endif // ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/rectangle.c b/src/graphics/none/rectangle.c deleted file mode 100644 index a59b6f4..0000000 --- a/src/graphics/none/rectangle.c +++ /dev/null @@ -1,22 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/rectangle.h" -#include - -void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Rect_RenderFill(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_FRect_Render(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_FRect_RenderFill(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){ - printf("No Graphics Backend Selected\n"); -} - -#endif // !ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/renderer.c b/src/graphics/none/renderer.c deleted file mode 100644 index 96c722e..0000000 --- a/src/graphics/none/renderer.c +++ /dev/null @@ -1,22 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/renderer.h" -#include - -void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Renderer_Destroy(ARC_Renderer *renderer){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Renderer_Clear(ARC_Renderer *renderer){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Renderer_Render(ARC_Renderer *renderer){ - printf("No Graphics Backend Selected\n"); -} - -#endif // !ARC_NONE_GRAPHICS diff --git a/src/graphics/none/sprite.c b/src/graphics/none/sprite.c deleted file mode 100644 index 0b3cb6f..0000000 --- a/src/graphics/none/sprite.c +++ /dev/null @@ -1,48 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/sprite.h" -#include - -void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Array *frames){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Sprite_Destroy(ARC_Sprite *sprite){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Sprite_RenderFlip(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds, enum ARC_Sprite_Axis axis){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Sprite_RenderRotated(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds, ARC_Point *center, double angle){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Sprite_SetFrameIndex(ARC_Sprite *sprite, uint32_t index){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){ - printf("No Graphics Backend Selected\n"); -} - -ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite){ - printf("No Graphics Backend Selected\n"); - return NULL; -} - -ARC_Array *ARC_Sprite_GetAllBounds(ARC_Sprite *sprite){ - printf("No Graphics Backend Selected\n"); - return NULL; -} - -#endif // !ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/spritesheet.c b/src/graphics/none/spritesheet.c deleted file mode 100644 index a08d5ce..0000000 --- a/src/graphics/none/spritesheet.c +++ /dev/null @@ -1,21 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/spritesheet.h" -#include "arc/math/point.h" -#include - -void ARC_Spritesheet_RenderArea(ARC_Spritesheet *spritesheet, ARC_Rect *sheetBounds, ARC_Renderer *renderer, ARC_Rect *renderBounds){ - printf("No Graphics Backend Selected\n"); -} - -ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet){ - printf("No Graphics Backend Selected\n"); - return (ARC_Point){ 0, 0 }; -} - -uint32_t *ARC_Spritesheet_GetTileSize(ARC_Spritesheet *spritesheet){ - printf("No Graphics Backend Selected\n"); - return NULL; -} - -#endif // !ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/text.c b/src/graphics/none/text.c deleted file mode 100644 index 46efeea..0000000 --- a/src/graphics/none/text.c +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef ARC_NONE_GRAPHICS - -#include "arc/graphics/text.h" -#include - -void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Text_Destroy(ARC_Text *font){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *string){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){ - printf("No Graphics Backend Selected\n"); -} - -void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos){ - printf("No Graphics Backend Selected\n"); -} - -#endif // !ARC_NONE_GRAPHICS \ No newline at end of file diff --git a/src/graphics/none/window.c b/src/graphics/none/window.c deleted file mode 100644 index 1413c8a..0000000 --- a/src/graphics/none/window.c +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef ARC_NONE_WINDOW - -#include "arc/graphics/window.h" -#include - -void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){ - printf("No Window Backend Selected\n"); -} - -void ARC_Window_Destroy(ARC_Window *window){ - printf("No Window Backend Selected\n"); -} - -#endif // !ARC_NONE_WINDOW \ No newline at end of file diff --git a/src/graphics/opengl/circle.c b/src/graphics/opengl/circle.c deleted file mode 100644 index c6dee14..0000000 --- a/src/graphics/opengl/circle.c +++ /dev/null @@ -1,10 +0,0 @@ -#ifdef ARC_OPENGL_GRAPHICS - -#include "arc/graphics/circle.h" -#include - -void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){ - printf("OpenGL Backend Selected\n"); -} - -#endif // !ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/opengl/line.c b/src/graphics/opengl/line.c deleted file mode 100644 index d617d6c..0000000 --- a/src/graphics/opengl/line.c +++ /dev/null @@ -1,8 +0,0 @@ -#ifdef ARC_OPENGL_GRAPHICS -#include "arc/graphics/line.h" -#include - -void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Renderer *renderer, ARC_Color *color){ -} - -#endif // ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/opengl/obround.c b/src/graphics/opengl/obround.c deleted file mode 100644 index b28a16d..0000000 --- a/src/graphics/opengl/obround.c +++ /dev/null @@ -1,14 +0,0 @@ -#ifdef ARC_OPENGL_GRAPHICS - -#include "arc/graphics/obround.h" -#include - -void ARC_Obround_Render(ARC_Obround *obround, ARC_Renderer *renderer, ARC_Color *color){ - printf("OpenGL Backend Selected\n"); -} - -void ARC_FObround_Render(ARC_FObround *obround, ARC_Renderer *renderer, ARC_Color *color){ - printf("OpenGL Backend Selected\n"); -} - -#endif // ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/opengl/rectangle.c b/src/graphics/opengl/rectangle.c deleted file mode 100644 index bca8f6f..0000000 --- a/src/graphics/opengl/rectangle.c +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef ARC_OPENGL_GRAPHICS -#include "arc/graphics/rectangle.h" -#include - -void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ -} - -void ARC_Rect_RenderFill(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ -} - -#endif // ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/opengl/sprite.c b/src/graphics/opengl/sprite.c deleted file mode 100644 index 3507c60..0000000 --- a/src/graphics/opengl/sprite.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifdef ARC_OPENGL_GRAPHICS -#include "arc/graphics/sprite.h" -#include "arc/math/point.h" -#include "arc/math/rectangle.h" -#include - -void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Array *frames){ -} - -void ARC_Sprite_Destroy(ARC_Sprite *sprite){ -} - -void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite){ -} - -void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds){ -} - -void ARC_Sprite_RenderRotated(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds, ARC_Point *center, double angle){ -} - -void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){ -} - -ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite){ - return NULL; -} - -#endif // ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/opengl/spritesheet.c b/src/graphics/opengl/spritesheet.c deleted file mode 100644 index 20513ac..0000000 --- a/src/graphics/opengl/spritesheet.c +++ /dev/null @@ -1,17 +0,0 @@ -#ifdef ARC_OPENGL_GRAPHICS -#include "arc/graphics/spritesheet.h" -#include "arc/math/point.h" -#include - -void ARC_Spritesheet_RenderArea(ARC_Spritesheet *spritesheet, ARC_Rect *sheetBounds, ARC_Renderer *renderer, ARC_Rect *renderBounds){ -} - -ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet){ - return (ARC_Point){0, 0}; -} - -uint32_t *ARC_Spritesheet_GetTileSize(ARC_Spritesheet *spritesheet){ - return NULL; -} - -#endif // ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/opengl/text.c b/src/graphics/opengl/text.c deleted file mode 100644 index f5a2284..0000000 --- a/src/graphics/opengl/text.c +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef ARC_OPENGL_GRAPHICS - -#include "arc/graphics/text.h" -#include - -void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color){ - printf("OpenGL Backend Selected\n"); -} - -void ARC_Text_Destroy(ARC_Text *font){ - printf("OpenGL Backend Selected\n"); -} - -void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *string){ - printf("OpenGL Backend Selected\n"); -} - -void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){ - printf("OpenGL Backend Selected\n"); -} - -void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos){ - printf("OpenGL Backend Selected\n"); -} - -#endif // !ARC_OPENGL_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/circle.c b/src/graphics/sdl/circle.c deleted file mode 100644 index 4df9741..0000000 --- a/src/graphics/sdl/circle.c +++ /dev/null @@ -1,52 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/circle.h" -#include "arc/graphics/sdl/renderer.h" -#include - -//Modified from https://stackoverflow.com/questions/38334081/how-to-draw-circles-arcs-and-vector-graphics-in-sdl -void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){ - SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a); - - int32_t diameter = (circle->r * 2); - - int32_t x = (circle->r - 1); - int32_t y = 0; - int32_t tx = 1; - int32_t ty = 1; - int32_t error = (tx - diameter); - - while(x >= y){ - // Each of the following renders an octant of the circle - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y - y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y + y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y - y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y + y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y - x); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y + x); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y - x); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y + x); - - if(error <= 0){ - ++y; - error += ty; - ty += 2; - } - - if(error > 0){ - --x; - tx += 2; - error += (tx - diameter); - } - } -} - -//TODO: very temp -void ARC_Circle_RenderFill(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){ - ARC_Circle temp = *circle; - - for(; temp.r; temp.r--){ - ARC_Circle_Render(&temp, renderer, color); - } -} - -#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/config.c b/src/graphics/sdl/config.c deleted file mode 100644 index 633f013..0000000 --- a/src/graphics/sdl/config.c +++ /dev/null @@ -1,314 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/config.h" - -#include -#include -#include "arc/std/array.h" -#include "arc/std/string.h" -#include "arc/std/errno.h" -#include "arc/graphics/sdl/renderer.h" -#include "arc/graphics/sprite.h" -#include "arc/graphics/sdl/sprite.h" -#include "arc/graphics/spritesheet.h" -#include "arc/graphics/sdl/spritesheet.h" -#include "arc/math/config.h" -#include "arc/math/point.h" -#include "arc/math/rectangle.h" - -// #define ARC_DEFAULT_CONFIG -#include "arc/std/defaults/config.h" - -SDL_Renderer *global_renderer; - -uint8_t ARC_SDL_Texture_Read(ARC_Config *config, ARC_String *string, void **value); -uint8_t ARC_Spritesheet_Read(ARC_Config *config, ARC_String *string, void **value); -uint8_t ARC_Sprite_Read (ARC_Config *config, ARC_String *string, void **value); - -void ARC_SDL_Texture_Delete(ARC_Config *config, ARC_String *string, void *value); -void ARC_Spritesheet_Delete(ARC_Config *config, ARC_String *string, void *value); -void ARC_Sprite_Delete (ARC_Config *config, ARC_String *string, void *value); - -void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){ - global_renderer = (SDL_Renderer *)renderer; - ARC_Config_AddKeyCString(config, (char *)"SDL_Texture" , 11, ARC_SDL_Texture_Read, ARC_SDL_Texture_Delete); - ARC_Config_AddKeyCString(config, (char *)"ARC_Spritesheet", 15, ARC_Spritesheet_Read, ARC_Spritesheet_Delete); - ARC_Config_AddKeyCString(config, (char *)"ARC_Sprite" , 10, ARC_Sprite_Read , ARC_Sprite_Delete ); -} - -uint64_t ARC_GraphicsConfig_GetIndexAndErrorCheck(ARC_String *string, char *search, uint64_t searchLength){ - uint64_t separator = ARC_String_FindCString(string, ",", 1); - - if(separator == ~(uint64_t)0){ - arc_errno = ARC_ERRNO_DATA; - } - - return separator; -} - -int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){ - IMG_Init(IMG_INIT_PNG); - SDL_Surface *surface = IMG_Load(path); - if(!surface){ - printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError()); - return 1; // GE_SDL_ERRNO_ - } - - SDL_BlendMode tempMode; - SDL_GetSurfaceBlendMode(surface, &tempMode); - *texture = SDL_CreateTextureFromSurface(global_renderer, surface); - SDL_GetTextureBlendMode(*texture, &tempMode); - - SDL_FreeSurface(surface); - IMG_Quit(); - - return 0; -} - -uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **value){ - ARC_Config_Get(config, string, value); - if(*value){ - return 1; - } - - ARC_String *tempStr, *textureStr; - ARC_String_StripEndsWhitespace(&tempStr, string); - - ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2); - ARC_String_Destroy(tempStr); - - ARC_SDL_Texture_Load(textureStr->data, (SDL_Texture **)value); - - ARC_String_Destroy(textureStr); - return 0; -} - -void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_t *size, void **value){ - SDL_Texture *texture; - - ARC_String *tempStr, *textureStr; - ARC_String_StripEndsWhitespace(&tempStr, string); - - //check for reference - ARC_Config_Get(config, tempStr, (void **)&texture); - if(!texture && (tempStr->data[0] != '"' || tempStr->data[string->length - 1] != '"')){ - arc_errno = ARC_ERRNO_DATA; - } - - ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2); - ARC_String_Destroy(tempStr); - - //try reading in the texture - if(!texture){ - ARC_SDL_Texture_Read(config, string, (void **)&texture); - if(arc_errno){ - *value = NULL; - } - } - - ARC_String_Destroy(textureStr); - - *value = malloc(sizeof(ARC_Spritesheet)); - ((ARC_Spritesheet *) *value)->texture = texture; - ((ARC_Spritesheet *) *value)->size = size; -} - -uint8_t ARC_Spritesheet_Read(ARC_Config* config, ARC_String *string, void **value){ - if(string->data[0] != '{' || string->data[string->length - 1] != '}'){ - ARC_Spritesheet_ReadTexture(config, string, NULL, value); - return 0; - } - - uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1); - if(arc_errno){ - return 0; - } - - ARC_String *temp, *textureStr, *sizeStr; - ARC_String_CopySubstring(&temp, string, 1, split - 2); - ARC_String_StripEndsWhitespace(&textureStr, temp); - ARC_String_Destroy(temp); - - ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 1)); - ARC_String_StripEndsWhitespace(&sizeStr, temp); - ARC_String_Destroy(temp); - - uint32_t *size; - ARC_Config_Get(config, string, (void **)&size); - if(!size){ - ARC_ConfigKey_Read_Uint32_t(config, sizeStr, (void **)&size); - if(arc_errno){ - ARC_String_Destroy(sizeStr); - ARC_String_Destroy(textureStr); - return ARC_ERRNO_DATA; - } - } - - ARC_Spritesheet_ReadTexture(config, textureStr, size, value); - - ARC_String_Destroy(sizeStr); - ARC_String_Destroy(textureStr); - - return 0; -} - -uint8_t ARC_Sprite_Read(ARC_Config* config, ARC_String *string, void **value){ - ARC_Config_Get(config, string, value); - if(*value){ - return 1; - } - - if(string->data[0] != '{' || string->data[string->length - 1] != '}'){ - ARC_Spritesheet_ReadTexture(config, string, NULL, value); - return 0; - } - - uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1); - if(arc_errno){ - return 0; - } - - ARC_String *temp, *spritesheetStr, *framesStr; - ARC_String_CopySubstring(&temp, string, 1, split - 2); - ARC_String_StripEndsWhitespace(&spritesheetStr, temp); - ARC_String_Destroy(temp); - - ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2)); - ARC_String_StripEndsWhitespace(&framesStr, temp); - ARC_String_Destroy(temp); - - //spritesheet - ARC_Spritesheet *spritesheet; - ARC_Config_Get(config, spritesheetStr, (void **)&spritesheet); - - if(!spritesheet){ - ARC_Spritesheet_Read(config, spritesheetStr, (void **)&spritesheet); - if(arc_errno){ - ARC_String_Destroy(spritesheetStr); - ARC_String_Destroy(framesStr ); - return 0; - } - } - - //bounds - ARC_Array *frames; - ARC_Config_Get(config, framesStr, (void **)&frames); - - if(!frames){ - ARC_RectArray_Read(config, framesStr, (void **)&frames); - if(arc_errno){ - ARC_String_Destroy(spritesheetStr); - ARC_String_Destroy(framesStr ); - return 0; - } - } - - ARC_String_Destroy(spritesheetStr); - ARC_String_Destroy(framesStr ); - - // Scale frames to match spritesheet size - // TODO: possible bug for sheets that use same frames - if(spritesheet->size){ - for(uint32_t i = 0; i < frames->size; i++){ - ((ARC_Rect *)frames->data)[i].x *= *spritesheet->size; - ((ARC_Rect *)frames->data)[i].y *= *spritesheet->size; - ((ARC_Rect *)frames->data)[i].w *= *spritesheet->size; - ((ARC_Rect *)frames->data)[i].h *= *spritesheet->size; - } - } - //sprite - ARC_Sprite_Create((ARC_Sprite **)value, spritesheet, frames); - - return 0; -} - -void ARC_SDL_Texture_Delete(ARC_Config* config, ARC_String *string, void *value){ - SDL_DestroyTexture((SDL_Texture *) value); -} - -void ARC_Spritesheet_Delete(ARC_Config* config, ARC_String *string, void *value){ - ARC_Spritesheet *sheetValue = (ARC_Spritesheet *)value; - - //check if read in as a Textrue reference - void *temp; - ARC_Config_Get(config, string, &temp); - if(temp){ - //TODO: test to see if this breaks references - free(sheetValue); - return; - } - - uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1); - if(arc_errno){ - //TODO: test to make sure no edge cases - // free(sheetValue); - ARC_SDL_Texture_Delete(config, string, value); - arc_errno = 0; - return; - } - - if(split == ~0){ - - } - - //check if texture and size are references - ARC_String *tempStr, *textureStr, *sizeStr; - ARC_String_CopySubstring(&tempStr, string, 1, split - 1); - ARC_String_StripEndsWhitespace(&textureStr, tempStr); - ARC_String_Destroy(tempStr); - - ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1)); - ARC_String_StripEndsWhitespace(&sizeStr, tempStr); - ARC_String_Destroy(tempStr); - - ARC_Config_Get(config, sizeStr, (void **)&temp); - ARC_String_Destroy(sizeStr); - if(temp){ - free(sheetValue->size); - } - - ARC_Config_Get(config, textureStr, (void **)&temp); - ARC_String_Destroy(textureStr); - if(temp){ - free(sheetValue->size); - } - - free(sheetValue); -} - -void ARC_Sprite_Delete(ARC_Config* config, ARC_String *string, void *value){ - ARC_Sprite *spriteValue = (ARC_Sprite *)value; - - //check if read in as a Textrue reference - void *temp; - uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1); - if(arc_errno){ - free(spriteValue); - return; - } - - //check if texture and size are references - ARC_String *tempStr, *spritesheetStr, *framesStr; - ARC_String_CopySubstring(&tempStr, string, 1, split - 1); - ARC_String_StripEndsWhitespace(&spritesheetStr, tempStr); - ARC_String_Destroy(tempStr); - - ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1)); - ARC_String_StripEndsWhitespace(&framesStr, tempStr); - ARC_String_Destroy(tempStr); - - ARC_Config_Get(config, spritesheetStr, (void **)&temp); - ARC_String_Destroy(spritesheetStr); - if(temp){ - free(spriteValue->spritesheet); - } - - ARC_Config_Get(config, framesStr, (void **)&temp); - ARC_String_Destroy(framesStr); - if(temp){ - free(spriteValue->frames); - } - - free(spriteValue); -} - -#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/line.c b/src/graphics/sdl/line.c deleted file mode 100644 index e9a7ccf..0000000 --- a/src/graphics/sdl/line.c +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/line.h" -#include "arc/graphics/sdl/renderer.h" -#include - -void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Renderer *renderer, ARC_Color *color){ - SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a); - SDL_RenderDrawLine((SDL_Renderer *)renderer, *x1, *y1, *x2, *y2); -} - -#endif // ARC_SDL2_GRAPHCIS \ No newline at end of file diff --git a/src/graphics/sdl/obround.c b/src/graphics/sdl/obround.c deleted file mode 100644 index acabcca..0000000 --- a/src/graphics/sdl/obround.c +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/obround.h" -#include "arc/graphics/sdl/renderer.h" -#include - -//Modified from https://stackoverflow.com/questions/38334081/how-to-draw-circles-arcs-and-vector-graphics-in-sdl -void ARC_Obround_Render(ARC_Obround *obround, ARC_Renderer *renderer, ARC_Color *color){ - SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a); - - int32_t diameter = (obround->r * 2); - - int32_t x = (obround->r - 1); - int32_t y = 0; - int32_t tx = 1; - int32_t ty = 1; - int32_t error = (tx - diameter); - - SDL_RenderDrawLine((SDL_Renderer *)renderer, obround->x - obround->r, obround->y - (obround->h / 2), obround->x - obround->r, obround->y + (obround->h / 2)); - SDL_RenderDrawLine((SDL_Renderer *)renderer, obround->x + obround->r, obround->y - (obround->h / 2), obround->x + obround->r, obround->y + (obround->h / 2)); - - while(x >= y){ - // Each of the following renders an octant of the circle - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + x, obround->y - y - (obround->h / 2)); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + x, obround->y + y + (obround->h / 2)); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - x, obround->y - y - (obround->h / 2)); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - x, obround->y + y + (obround->h / 2)); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + y, obround->y - x - (obround->h / 2)); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + y, obround->y + x + (obround->h / 2)); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - y, obround->y - x - (obround->h / 2)); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - y, obround->y + x + (obround->h / 2)); - - if(error <= 0){ - ++y; - error += ty; - ty += 2; - } - - if(error > 0){ - --x; - tx += 2; - error += (tx - diameter); - } - } -} - -void ARC_FObround_Render(ARC_FObround *obround, ARC_Renderer *renderer, ARC_Color *color){ - ARC_Obround casted = ARC_FObround_CastToObround(obround); - ARC_Obround_Render(&casted, renderer, color); -} - -#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/rectangle.c b/src/graphics/sdl/rectangle.c deleted file mode 100644 index 2caedfb..0000000 --- a/src/graphics/sdl/rectangle.c +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/rectangle.h" -#include "arc/graphics/sdl/renderer.h" -#include - -void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ - SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a); - SDL_RenderDrawRect((SDL_Renderer *)renderer, (SDL_Rect *) rect); -} - -void ARC_Rect_RenderFill(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ - SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a); - SDL_RenderFillRect((SDL_Renderer *)renderer, (SDL_Rect *) rect); -} - -void ARC_FRect_Render(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){ - ARC_Rect casted = ARC_FRect_CastToRect(rect); - ARC_Rect_Render(&casted, renderer, color); -} - -void ARC_FRect_RenderFill(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){ - ARC_Rect casted = ARC_FRect_CastToRect(rect); - ARC_Rect_RenderFill(&casted, renderer, color); -} - -#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/renderer.c b/src/graphics/sdl/renderer.c deleted file mode 100644 index efe9935..0000000 --- a/src/graphics/sdl/renderer.c +++ /dev/null @@ -1,41 +0,0 @@ -#ifdef ARC_SDL2_WINDOW -#include "arc/graphics/renderer.h" -#include "arc/graphics/sdl/renderer.h" - -#include -#include -#include "arc/graphics/window.h" -#include "arc/std/errno.h" - -void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info){ - if(!info){ - arc_errno = ARC_ERRNO_NULL; - ARC_DEBUG_ERR("ARC_Renderer_Create(**renderer, NULL)"); - return; - } - - *renderer = (ARC_Renderer *)SDL_CreateRenderer((SDL_Window *)info->window, info->index, info->flags); - - if(!*renderer){ - arc_errno = ARC_ERRNO_NULL; - ARC_DEBUG_LOG(arc_errno, "SDL_CreateRenderer(%p, %d, %u);", info->window, info->index, info->flags); - free(renderer); - } - - SDL_SetRenderDrawBlendMode((SDL_Renderer *)*renderer, SDL_BLENDMODE_BLEND); -} - -void ARC_Renderer_Destroy(ARC_Renderer *renderer){ - SDL_DestroyRenderer((SDL_Renderer *) renderer); -} - -void ARC_Renderer_Clear(ARC_Renderer *renderer){ - SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x1c, 0x2c, 0x3c, 0x00); - SDL_RenderClear((SDL_Renderer *)renderer); -} - -void ARC_Renderer_Render(ARC_Renderer *renderer){ - SDL_RenderPresent((SDL_Renderer *)renderer); -} - -#endif //ARC_SDL2_WINDOW \ No newline at end of file diff --git a/src/graphics/sdl/sprite.c b/src/graphics/sdl/sprite.c deleted file mode 100644 index d4ce2c4..0000000 --- a/src/graphics/sdl/sprite.c +++ /dev/null @@ -1,92 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/sprite.h" -#include "arc/graphics/sdl/sprite.h" -#include "arc/graphics/sdl/spritesheet.h" -#include "arc/graphics/sdl/renderer.h" -#include "arc/math/point.h" -#include "arc/math/rectangle.h" -#include "arc/std/errno.h" -#include - -void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Array *frames){ - *sprite = (ARC_Sprite *)malloc(sizeof(ARC_Sprite)); - (*sprite)->spritesheet = spritesheet; - (*sprite)->frames = frames; - (*sprite)->frameIndex = (uint32_t *)malloc(sizeof(uint32_t)); - *(*sprite)->frameIndex = 0; - (*sprite)->opacity = 255; -} - -void ARC_Sprite_Destroy(ARC_Sprite *sprite){ - free(sprite); -} - -void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite){ - *newSprite = (ARC_Sprite *)malloc(sizeof(ARC_Sprite)); - (*newSprite)->spritesheet = oldSprite->spritesheet; - (*newSprite)->frames = oldSprite->frames; - (*newSprite)->frameIndex = (uint32_t *)malloc(sizeof(uint32_t)); - *(*newSprite)->frameIndex = *oldSprite->frameIndex; -} - -void ARC_Sprite_SetOpacity(ARC_Sprite *sprite, uint8_t opacity){ - sprite->opacity = opacity; -} - -void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds){ - //TODO: note, this is set here so not all entities in the sheet get opacity set - SDL_SetTextureAlphaMod((SDL_Texture *)sprite->spritesheet->texture, sprite->opacity); - SDL_RenderCopy((SDL_Renderer *)renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames->data + *sprite->frameIndex, (SDL_Rect *)renderBounds); -} - -void ARC_Sprite_RenderFlip(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds, enum ARC_Sprite_Axis axis){ - SDL_RendererFlip flip = SDL_FLIP_NONE; - if(axis & ARC_SPRITE_AXIS_X){ - flip |= SDL_FLIP_HORIZONTAL; - } - - if(axis & ARC_SPRITE_AXIS_Y){ - flip |= SDL_FLIP_VERTICAL; - } - - //TODO: note, this is set here so not all entities in the sheet get opacity set - SDL_SetTextureAlphaMod((SDL_Texture *)sprite->spritesheet->texture, sprite->opacity); - SDL_RenderCopyEx((SDL_Renderer *)renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames->data + *sprite->frameIndex, (SDL_Rect *)renderBounds, 0.0, NULL, flip); -} - -void ARC_Sprite_RenderRotated(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds, ARC_Point *center, double angle){ - //TODO: note, this is set here so not all entities in the sheet get opacity set - SDL_SetTextureAlphaMod((SDL_Texture *)sprite->spritesheet->texture, sprite->opacity); - SDL_RenderCopyEx((SDL_Renderer *)renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames->data + *sprite->frameIndex, (SDL_Rect *)renderBounds, angle, (SDL_Point *)center, SDL_FLIP_NONE); -} - -void ARC_Sprite_SetFrameIndex(ARC_Sprite *sprite, uint32_t index){ - if(sprite->frames->size <= index){ - arc_errno = ARC_ERRNO_DATA; - ARC_DEBUG_LOG(arc_errno, "in ARC_Sprite_SetFrameIndex(sprite, %d); index out of bounds", index); - return; - } - *sprite->frameIndex = index; -} - -void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){ - ++*sprite->frameIndex; - - if(*sprite->frameIndex == sprite->frames->size){ - *sprite->frameIndex = 0; - } -} - -uint32_t ARC_Sprite_GetFrameIndex(ARC_Sprite *sprite){ - return *sprite->frameIndex; -} - -ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite){ - return (ARC_Rect *)sprite->frames->data + *sprite->frameIndex; -} - -ARC_Array *ARC_Sprite_GetAllBounds(ARC_Sprite *sprite){ - return sprite->frames; -} - -#endif // ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/spritesheet.c b/src/graphics/sdl/spritesheet.c deleted file mode 100644 index 4d456c6..0000000 --- a/src/graphics/sdl/spritesheet.c +++ /dev/null @@ -1,22 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/spritesheet.h" -#include "arc/graphics/sdl/spritesheet.h" -#include "arc/graphics/sdl/renderer.h" -#include "arc/math/point.h" -#include - -void ARC_Spritesheet_RenderArea(ARC_Spritesheet *spritesheet, ARC_Rect *sheetBounds, ARC_Renderer *renderer, ARC_Rect *renderBounds){ - SDL_RenderCopy((SDL_Renderer *)renderer, spritesheet->texture, (SDL_Rect *)sheetBounds, (SDL_Rect *)renderBounds); -} - -ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet){ - ARC_Point size; - SDL_QueryTexture(spritesheet->texture, NULL, NULL, &size.x, &size.y); - return size; -} - -uint32_t *ARC_Spritesheet_GetTileSize(ARC_Spritesheet *spritesheet){ - return spritesheet->size; -} - -#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/text.c b/src/graphics/sdl/text.c deleted file mode 100644 index 3a0af8d..0000000 --- a/src/graphics/sdl/text.c +++ /dev/null @@ -1,59 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/text.h" -#include "arc/graphics/sdl/text.h" -#include "arc/graphics/color.h" -#include "arc/math/point.h" -#include "arc/math/rectangle.h" -#include "arc/std/string.h" - -#include - -void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color){ - *text = (ARC_Text *)malloc(sizeof(ARC_Text)); - ARC_String_Copy(&(*text)->name, path); - (*text)->size = size; - (*text)->color = color; - (*text)->texture = NULL; - (*text)->bounds = (ARC_Rect){ 0, 0, 0, 0 }; -} - -void ARC_Text_Destroy(ARC_Text *font){ - if(font->texture != NULL){ - SDL_DestroyTexture(font->texture); - } - ARC_String_Destroy(font->name); - free(font); -} - -void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *string){ - TTF_Font *ttfont = TTF_OpenFont(text->name->data, text->size); - SDL_Color textColor = (SDL_Color){ text->color.r, text->color.g, text->color.b, text->color.a }; - SDL_Surface *surface = TTF_RenderText_Blended_Wrapped(ttfont, string->data, textColor, 0); - - text->bounds.w = surface->w; - text->bounds.h = surface->h; - - if(text->texture){ - SDL_DestroyTexture(text->texture); - } - text->texture = SDL_CreateTextureFromSurface((SDL_Renderer *)renderer, surface); - - SDL_FreeSurface(surface); - TTF_CloseFont(ttfont); -} - -void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){ - if(text->texture == NULL){ - return; - } - - SDL_Rect bounds = (SDL_Rect){ text->bounds.x, text->bounds.y, text->bounds.w, text->bounds.h }; - SDL_RenderCopy((SDL_Renderer *)renderer, text->texture, NULL, &bounds); -} - -void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos){ - text->bounds.x = pos.x; - text->bounds.y = pos.y; -} - -#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/view.c b/src/graphics/sdl/view.c deleted file mode 100644 index 6ec006a..0000000 --- a/src/graphics/sdl/view.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifdef ARC_SDL2_GRAPHICS -#include "arc/graphics/view.h" - -#include "arc/std/errno.h" -#include -#include - -void ARC_View_Create(ARC_View **view, ARC_Renderer *renderer, ARC_Rect bounds){ - *view = (ARC_View *)malloc(sizeof(ARC_View)); - (*view)->renderer = renderer; - (*view)->bounds = bounds; -} - -void ARC_View_Destroy(ARC_View *view){ - free(view); -} - -void ARC_View_Render(ARC_View *view, ARC_View_RenderFn renderFn, void *data){ - int err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, (const SDL_Rect *)&(view->bounds)); - if(err){ - ARC_DEBUG_LOG(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, renderFn), SDL_RenderSetViewport(...) returned: %d", err); - return; - } - - renderFn(data); - - err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, NULL); - if(err){ - ARC_DEBUG_LOG(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, NULL), SDL_RenderSetViewport(...) returned: %d", err); - return; - } -} - -ARC_Rect ARC_View_GetBounds(ARC_View *view){ - return view->bounds; -} - -#endif //ARC_SDL2_GRAPHICS \ No newline at end of file diff --git a/src/graphics/sdl/window.c b/src/graphics/sdl/window.c deleted file mode 100644 index 8ae05b9..0000000 --- a/src/graphics/sdl/window.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifdef ARC_SDL2_WINDOW -#include "arc/graphics/window.h" -#include "arc/graphics/sdl/window.h" - -#include "arc/std/errno.h" -#include - -void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){ - if(!info){ - arc_errno = ARC_ERRNO_NULL; - ARC_DEBUG_ERR("ARC_Window_Create(**window, NULL)"); - return; - } - - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0){ - arc_errno = ARC_ERRNO_INIT; - printf("Error: initializing SDL\nSDL Error: %s\n", SDL_GetError()); - return; - } - - *window = (ARC_Window *)SDL_CreateWindow((const char *)info->title, info->x, info->y, info->w, info->h, info->flags); - - if(!*window){ - arc_errno = ARC_ERRNO_NULL; - ARC_DEBUG_LOG(arc_errno, "SDL_CreateWindow(%s, %d, %d, %d, %d, %x);", info->title, info->x, info->y, info->w, info->h, info->flags); - free(window); - } -} - -void ARC_Window_Destroy(ARC_Window *window){ - SDL_DestroyWindow((SDL_Window *) window); -} - -#endif //ARC_SDL2_WINDOW \ No newline at end of file diff --git a/src/input/glfw/keyboard.c b/src/input/glfw/keyboard.c deleted file mode 100644 index 30ca4f2..0000000 --- a/src/input/glfw/keyboard.c +++ /dev/null @@ -1,22 +0,0 @@ -#ifdef ARC_GLFW_INPUT -#include "arc/input/glfw/keyboard.h" -#include "arc/input/keyboard.h" -#include "arc/math/point.h" -#include "arc/std/errno.h" -#include -#include - -void ARC_Keyboard_Create(ARC_Keyboard **keyboard, ARC_KeyboardInfo *info){ -} - -void ARC_Keyboard_Destroy(ARC_Keyboard *keyboard){ -} - -void ARC_Keyboard_Update(ARC_Keyboard *keyboard){ -} - -ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, enum ARC_KeyboardKey key){ - return ARC_KEY_NONE; -} - -#endif // ARC_GLFW_INPUT \ No newline at end of file diff --git a/src/input/glfw/mouse.c b/src/input/glfw/mouse.c deleted file mode 100644 index f442958..0000000 --- a/src/input/glfw/mouse.c +++ /dev/null @@ -1,33 +0,0 @@ -#ifdef ARC_GLFW_INPUT -#include "arc/input/glfw/mouse.h" -#include "arc/input/mouse.h" -#include "arc/math/point.h" -#include "arc/std/errno.h" -#include -#include - -void ARC_Mouse_Create(ARC_Mouse **mouse, ARC_MouseInfo *info){ -} - -void ARC_Mouse_Destroy(ARC_Mouse *mouse){ -} - -void ARC_Mouse_UpdateButton(ARC_Mouse *mouse, uint8_t button, uint32_t *buttons, uint32_t mask){ -} - -void ARC_Mouse_Update(ARC_Mouse *mouse){ -} - -ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse){ - return mouse->coords; -} - -ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button){ - return mouse->buttons[button]; -} - -int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse){ - return mouse->scrollY; -} - -#endif // ARC_SDL_INPUT \ No newline at end of file diff --git a/src/input/none/keyboard.c b/src/input/none/keyboard.c deleted file mode 100644 index 262f4a8..0000000 --- a/src/input/none/keyboard.c +++ /dev/null @@ -1,23 +0,0 @@ -#ifdef ARC_NONE_INPUT - -#include "arc/input/keyboard.h" -#include - -void ARC_Keyboard_Create(ARC_Keyboard **keyboard, ARC_KeyboardInfo *info){ - printf("No Input Backend Selected\n"); -} - -void ARC_Keyboard_Destroy(ARC_Keyboard *keyboard){ - printf("No Input Backend Selected\n"); -} - -void ARC_Keyboard_Update(ARC_Keyboard *keyboard){ - printf("No Input Backend Selected\n"); -} - -ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, enum ARC_KeyboardKey key){ - printf("No Input Backend Selected\n"); - return ARC_KEY_NONE; -} - -#endif // !ARC_NONE_INPUT \ No newline at end of file diff --git a/src/input/none/mouse.c b/src/input/none/mouse.c deleted file mode 100644 index 5bf6e4f..0000000 --- a/src/input/none/mouse.c +++ /dev/null @@ -1,37 +0,0 @@ -#ifdef ARC_NONE_INPUT - -#include "arc/input/mouse.h" -#include - -void ARC_Mouse_Create(ARC_Mouse **mouse, ARC_MouseInfo *info){ - printf("No Input Backend Selected\n"); -} - -void ARC_Mouse_Destroy(ARC_Mouse *mouse){ - printf("No Input Backend Selected\n"); -} - -void ARC_Mouse_UpdateButton(ARC_Mouse *mouse, uint8_t button, uint32_t *buttons, uint32_t mask){ - printf("No Input Backend Selected\n"); -} - -void ARC_Mouse_Update(ARC_Mouse *mouse){ - printf("No Input Backend Selected\n"); -} - -ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse){ - printf("No Input Backend Selected\n"); - return NULL; -} - -ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button){ - printf("No Input Backend Selected\n"); - return ARC_MOUSE_NONE; -} - -int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse){ - printf("No Input Backend Selected\n"); - return NULL; -} - -#endif // !ARC_INPUT_NONE \ No newline at end of file diff --git a/src/input/sdl/keyboard.c b/src/input/sdl/keyboard.c deleted file mode 100644 index 6231577..0000000 --- a/src/input/sdl/keyboard.c +++ /dev/null @@ -1,101 +0,0 @@ -#ifdef ARC_SDL2_INPUT -#include "arc/input/sdl/keyboard.h" -#include "arc/input/keyboard.h" -#include "arc/math/point.h" -#include "arc/std/errno.h" -#include -#include -#include -#include - -void ARC_Keyboard_Create(ARC_Keyboard **keyboard, ARC_KeyboardInfo *info){ - *keyboard = (ARC_Keyboard *)malloc(sizeof(ARC_Keyboard)); - (*keyboard)->event = info->event; - (*keyboard)->keys = (ARC_KeyboardState *)malloc(sizeof(ARC_KeyboardState) * ARC_KEYBOARD_BUTTON_NUM); - - (*keyboard)->released = NULL; - - for(uint8_t i = 0; i < ARC_KEYBOARD_BUTTON_NUM; i++){ - (*keyboard)->keys[i] = ARC_KEY_NONE; - } -} - -void ARC_Keyboard_Destroy(ARC_Keyboard *keyboard){ - free(keyboard->keys); - - free(keyboard); -} - -void ARC_Keyboard_Update(ARC_Keyboard *keyboard){ - if(keyboard->released){ - *keyboard->released = ARC_KEY_NONE; - keyboard->released = NULL; - } - - if(keyboard->event->type != SDL_KEYDOWN && keyboard->event->type != SDL_KEYUP){ - return; - } - - if(keyboard->event->key.keysym.sym >= 239 || keyboard->event->key.keysym.sym < 0){ - return; - } - - if(keyboard->event->type == SDL_KEYDOWN){ - keyboard->keys[keyboard->event->key.keysym.sym] = ARC_KEY_PRESSED; - return; - } - - keyboard->keys[keyboard->event->key.keysym.sym] = ARC_KEY_RELEASED; - keyboard->released = (keyboard->keys + keyboard->event->key.keysym.sym); -} - -ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, enum ARC_KeyboardKey key){ - switch(key){ - case ARC_KEY_A: return keyboard->keys[SDLK_a]; - case ARC_KEY_B: return keyboard->keys[SDLK_b]; - case ARC_KEY_C: return keyboard->keys[SDLK_c]; - case ARC_KEY_D: return keyboard->keys[SDLK_d]; - case ARC_KEY_E: return keyboard->keys[SDLK_e]; - case ARC_KEY_F: return keyboard->keys[SDLK_f]; - case ARC_KEY_G: return keyboard->keys[SDLK_g]; - case ARC_KEY_H: return keyboard->keys[SDLK_h]; - case ARC_KEY_I: return keyboard->keys[SDLK_i]; - case ARC_KEY_J: return keyboard->keys[SDLK_j]; - case ARC_KEY_K: return keyboard->keys[SDLK_k]; - case ARC_KEY_L: return keyboard->keys[SDLK_l]; - case ARC_KEY_M: return keyboard->keys[SDLK_m]; - case ARC_KEY_N: return keyboard->keys[SDLK_n]; - case ARC_KEY_O: return keyboard->keys[SDLK_o]; - case ARC_KEY_P: return keyboard->keys[SDLK_p]; - case ARC_KEY_Q: return keyboard->keys[SDLK_q]; - case ARC_KEY_R: return keyboard->keys[SDLK_r]; - case ARC_KEY_S: return keyboard->keys[SDLK_s]; - case ARC_KEY_T: return keyboard->keys[SDLK_t]; - case ARC_KEY_U: return keyboard->keys[SDLK_u]; - case ARC_KEY_V: return keyboard->keys[SDLK_v]; - case ARC_KEY_W: return keyboard->keys[SDLK_w]; - case ARC_KEY_X: return keyboard->keys[SDLK_x]; - case ARC_KEY_Y: return keyboard->keys[SDLK_y]; - case ARC_KEY_Z: return keyboard->keys[SDLK_z]; - - case ARC_KEY_0: return keyboard->keys[SDLK_0]; - case ARC_KEY_1: return keyboard->keys[SDLK_1]; - case ARC_KEY_2: return keyboard->keys[SDLK_2]; - case ARC_KEY_3: return keyboard->keys[SDLK_3]; - case ARC_KEY_4: return keyboard->keys[SDLK_4]; - case ARC_KEY_5: return keyboard->keys[SDLK_5]; - case ARC_KEY_6: return keyboard->keys[SDLK_6]; - case ARC_KEY_7: return keyboard->keys[SDLK_7]; - case ARC_KEY_8: return keyboard->keys[SDLK_8]; - case ARC_KEY_9: return keyboard->keys[SDLK_9]; - - case ARC_KEY_SPACE: return keyboard->keys[SDLK_SPACE ]; - case ARC_KEY_ESC: return keyboard->keys[SDLK_ESCAPE]; - case ARC_KEY_ENTER: return keyboard->keys[SDLK_RETURN]; - - default: return ARC_KEY_NONE; - } - -} - -#endif // ARC_SDL2_INPUT \ No newline at end of file diff --git a/src/input/sdl/mouse.c b/src/input/sdl/mouse.c deleted file mode 100644 index 3a983e1..0000000 --- a/src/input/sdl/mouse.c +++ /dev/null @@ -1,108 +0,0 @@ -#ifdef ARC_SDL2_INPUT -#include "arc/input/sdl/mouse.h" -#include "arc/input/mouse.h" -#include "arc/math/point.h" -#include "arc/std/errno.h" -#include -#include -#include -#include - -void ARC_Mouse_Create(ARC_Mouse **mouse, ARC_MouseInfo *info){ - *mouse = (ARC_Mouse *)malloc(sizeof(ARC_Mouse)); - (*mouse)->event = info->event; - (*mouse)->coords = (ARC_Point *)malloc(sizeof(ARC_Point)); - (*mouse)->scrollY = (int32_t *)malloc(sizeof(int32_t )); - (*mouse)->buttons = (ARC_MouseState *)malloc(sizeof(ARC_MouseState) * ARC_MOUSE_BUTTON_NUM); - - (*mouse)->buttonsReleased = (uint8_t *)malloc(sizeof(uint8_t)); - - *(*mouse)->coords = (ARC_Point){0, 0}; - *(*mouse)->scrollY = 0; - - for(uint8_t i = 0; i < ARC_MOUSE_BUTTON_NUM; i++){ - (*mouse)->buttons[i] = ARC_MOUSE_NONE; - } - - *(*mouse)->buttonsReleased = 0; -} - -void ARC_Mouse_Destroy(ARC_Mouse *mouse){ - free(mouse->buttonsReleased); - - free(mouse->buttons); - free(mouse->scrollY); - free(mouse->coords ); - - free(mouse); -} - -void ARC_Mouse_UpdateButton(ARC_Mouse *mouse, uint8_t button, uint32_t *buttons, uint32_t mask){ - if(*buttons & mask){ - mouse->buttons[button] = ARC_MOUSE_PRESSED; - return; - } - - if(mouse->buttons[button] == ARC_MOUSE_NONE){ - return; - } - - if(mouse->buttons[button] == ARC_MOUSE_RELEASED){ - mouse->buttons[button] = ARC_MOUSE_NONE; - --*mouse->buttonsReleased; - return; - } - - mouse->buttons[button] = ARC_MOUSE_RELEASED; - ++*mouse->buttonsReleased; -} - -void ARC_Mouse_Update(ARC_Mouse *mouse){ - *mouse->scrollY = 0; - if(mouse->event->type == SDL_MOUSEWHEEL){ - *mouse->scrollY = mouse->event->wheel.y; - } - - uint32_t buttons = SDL_GetMouseState(&(mouse->coords->x), &(mouse->coords->y)); - - if(mouse->event->type != SDL_MOUSEBUTTONDOWN && mouse->event->type != SDL_MOUSEBUTTONUP){ - if(!*mouse->buttonsReleased){ - return; - } - - for(uint8_t i = *mouse->buttonsReleased; i > 0; i--){ - if(mouse->buttons[i - 1] == ARC_MOUSE_RELEASED){ - mouse->buttons[i - 1] = ARC_MOUSE_NONE; - --*mouse->buttonsReleased; - } - } - - // if(*mouse->buttonsReleased){ - // arc_errno = ARC_ERRNO_DATA; - // ARC_DEBUG_LOG(arc_errno, "in ARC_Mouse_Update mouse->buttonsReleased == %u, it needs to be 0\n", *(mouse->buttonsReleased)); - // } - return; - } - - ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_LEFT , &buttons, SDL_BUTTON_LMASK ); - ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_MIDDLE, &buttons, SDL_BUTTON_MMASK ); - ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_RIGHT , &buttons, SDL_BUTTON_RMASK ); - ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X1 , &buttons, SDL_BUTTON_X1MASK); - ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X2 , &buttons, SDL_BUTTON_X2MASK); - - -} - -ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse){ - return mouse->coords; -} - -ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button){ - return mouse->buttons[button]; -} - -int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse){ - return mouse->scrollY; -} - -#endif // ARC_SDL2_INPUT \ No newline at end of file diff --git a/src/std/handler.c b/src/std/handler.c index f482a94..209c155 100644 --- a/src/std/handler.c +++ b/src/std/handler.c @@ -37,8 +37,8 @@ void ARC_Handler_Remove(ARC_Handler *handler, void *data, ARC_Handler_CompareDat ARC_Vector_Remove(handler->data, data, (ARC_Vector_CompareDataFn) compare); } -void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t *index){ - if(!*ARC_Vector_Size(handler->data)){ +void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index){ + if(ARC_Vector_Size(handler->data) == 0){ return; } @@ -48,31 +48,31 @@ void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t *index){ } void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn){ - for(uint32_t i = 0; i < *ARC_Vector_Size(handler->data); i++){ - datafn(ARC_Vector_Get(handler->data, &i)); + for(uint32_t i = 0; i < ARC_Vector_Size(handler->data); i++){ + datafn(ARC_Vector_Get(handler->data, i)); } } void ARC_Handler_Clear(ARC_Handler *handler){ uint32_t zeroIndex = 0; - while(*ARC_Vector_Size(handler->data)){ - ARC_Handler_RemoveIndex(handler, &zeroIndex); + while(ARC_Vector_Size(handler->data)){ + ARC_Handler_RemoveIndex(handler, zeroIndex); } } void ARC_Handler_Clean(ARC_Handler *handler){ uint32_t i = 0; - while(*ARC_Vector_Size(handler->trash)){ - void *data = ARC_Vector_Get(handler->trash, &i); + while(ARC_Vector_Size(handler->trash)){ + void *data = ARC_Vector_Get(handler->trash, i); if(handler->cleanfn){ handler->cleanfn(data); } - ARC_Vector_RemoveIndex(handler->trash, &i); + ARC_Vector_RemoveIndex(handler->trash, i); } } -uint32_t *ARC_Handler_Size(ARC_Handler *handler){ +uint32_t ARC_Handler_Size(ARC_Handler *handler){ return ARC_Vector_Size(handler->data); } diff --git a/src/std/queue.c b/src/std/queue.c index b0842f7..53e4142 100644 --- a/src/std/queue.c +++ b/src/std/queue.c @@ -72,7 +72,7 @@ void ARC_Queue_Push(ARC_Queue *queue, void *data){ void *ARC_Queue_Pop(ARC_Queue *queue){ if(queue->currentSize == 0){ arc_errno = ARC_ERRNO_DATA; - ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but queue was not empty"); + ARC_DEBUG_ERR("ARC_Queue_Pop(queue) called, but queue was empty"); return NULL; } diff --git a/src/std/vector.c b/src/std/vector.c index 6ddba58..d9d5707 100644 --- a/src/std/vector.c +++ b/src/std/vector.c @@ -6,58 +6,53 @@ #include struct ARC_Vector { - uint32_t *currentSize, *capacity; + uint32_t currentSize, capacity; void **data; }; void ARC_Vector_Create(ARC_Vector **vector){ *vector = (ARC_Vector *) malloc(sizeof(ARC_Vector)); - (*vector)->currentSize = (uint32_t *)malloc(sizeof(uint32_t)); - (*vector)->capacity = (uint32_t *)malloc(sizeof(uint32_t)); - (*vector)->data = (void **)malloc(sizeof(void *)); - - *(*vector)->currentSize = 0; - *(*vector)->capacity = 1; + (*vector)->currentSize = 0; + (*vector)->capacity = 1; + (*vector)->data = (void **)malloc(sizeof(void *)); } void ARC_Vector_Destroy(ARC_Vector *vector){ - free(vector->currentSize); - free(vector->capacity); free(vector->data); free(vector); } void ARC_Vector_Add(ARC_Vector *vector, void *data){ - if(*vector->currentSize == ~((uint32_t)0)){ + if(vector->currentSize == ~((uint32_t)0)){ arc_errno = ARC_ERRNO_OVERFLOW; return; } - if(*vector->currentSize == *vector->capacity){ - if(!*vector->capacity){ - ++*vector->capacity; + if(vector->currentSize == vector->capacity){ + if(!vector->capacity){ + ++vector->capacity; } - *vector->capacity <<= 1; + vector->capacity <<= 1; - vector->data = (void *)realloc(vector->data, sizeof(void *) * *vector->capacity); + vector->data = (void *)realloc(vector->data, sizeof(void *) * vector->capacity); } - vector->data[*vector->currentSize] = data; - ++*(vector->currentSize); + vector->data[vector->currentSize] = data; + ++(vector->currentSize); } //this function removes the redundant checking currentSize and index that would happen if ARC_Vector_Remove called ARC_Vector_RemoveIndex -void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t *index); +void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t index); void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn compare){ - if(!*vector->currentSize){ + if(!vector->currentSize){ arc_errno = ARC_ERRNO_DATA; return; } - for(uint32_t i = 0; i < *vector->currentSize; i++){ + for(uint32_t i = 0; i < vector->currentSize; i++){ if(!compare(data, vector->data[i])){ - ARC_Vector_RemoveIndexNoCheck(vector, &i); + ARC_Vector_RemoveIndexNoCheck(vector, i); return; } } @@ -66,8 +61,8 @@ void ARC_Vector_Remove(ARC_Vector *vector, void *data, ARC_Vector_CompareDataFn arc_errno = ARC_ERRNO_DATA; } -void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index){ - if(!*vector->currentSize || *index >= *vector->currentSize){ +void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t index){ + if(!vector->currentSize || index >= vector->currentSize){ arc_errno = ARC_ERRNO_DATA; return; } @@ -75,36 +70,36 @@ void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t *index){ ARC_Vector_RemoveIndexNoCheck(vector, index); } -void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t *index){ - for(uint32_t i = *index; i <= *vector->currentSize; i++){ - if(i + 1 >= *vector->currentSize - 1){ +void ARC_Vector_RemoveIndexNoCheck(ARC_Vector *vector, uint32_t index){ + for(uint32_t i = index; i <= vector->currentSize; i++){ + if(i + 1 >= vector->currentSize - 1){ break; } vector->data[i] = vector->data[i + 1]; } - --*vector->currentSize; + --vector->currentSize; - if(*vector->currentSize != *vector->capacity >> 1){ + if(vector->currentSize != vector->capacity >> 1){ return; } - *vector->capacity >>= 1; - if(*vector->capacity <= 0){ - *vector->capacity = 1; + vector->capacity >>= 1; + if(vector->capacity <= 0){ + vector->capacity = 1; } - vector->data = (void *)realloc(vector->data, sizeof(void *) * *vector->capacity); + vector->data = (void *)realloc(vector->data, sizeof(void *) * vector->capacity); } -uint32_t *ARC_Vector_Size(ARC_Vector *vector){ +uint32_t ARC_Vector_Size(ARC_Vector *vector){ return vector->currentSize; } -void *ARC_Vector_Get(ARC_Vector *vector, uint32_t *index){ - if(*index >= *vector->currentSize){ +void *ARC_Vector_Get(ARC_Vector *vector, uint32_t index){ + if(index >= vector->currentSize){ return NULL; } - return vector->data[*index]; + return vector->data[index]; } \ No newline at end of file