Merge branch 'tbyte/master' into 'master'

Tbyte/master

See merge request Archeus_00/arc!5
This commit is contained in:
herbglitch 2023-03-15 05:04:59 +00:00
commit f5949f272c
48 changed files with 851 additions and 88 deletions

View file

@ -11,37 +11,130 @@ endfunction()
option(ARCHEUS_STD_DEBUG "Build in debug mode" ON) option(ARCHEUS_STD_DEBUG "Build in debug mode" ON)
option(ARCHEUS_STD_DEFAULT_CONFIG "Build with default config keys" ON) option(ARCHEUS_STD_DEFAULT_CONFIG "Build with default config keys" ON)
option(ARCHEUS_STD_SDL "Build with SDL" OFF)
option(ARCHEUS_STD_GLFW "Build with GLFW window" OFF)
option(ARCHEUS_STD_GLEW "Build with GLEW" OFF)
option(ARCHEUS_STD_OPENGL "Build with OpenGL" OFF)
set(ARCHEUS_STD_FLAGS "") set(ARCHEUS_STD_FLAGS "")
if(ARCHEUS_STD_DEBUG) if(ARCHEUS_STD_DEBUG)
string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g ") string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g -ggdb ")
endif() endif()
if(ARCHEUS_STD_DEFAULT_CONFIG) if(ARCHEUS_STD_DEFAULT_CONFIG)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_DEFAULT_CONFIG ") string(APPEND ARCHEUS_STD_FLAGS "-DARC_DEFAULT_CONFIG ")
endif() endif()
if(ARCHEUS_STD_SDL)
if(NOT PNG AND WIN32 AND NOT MSVC)
set(PNG_LIBRARY "C:/Program Files(x86)/libpng")
set(PNG_PNG_INCLUDE_DIR "C:/Program Files(x86)/libpng/include")
endif()
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_SDL ")
endif()
if(ARCHEUS_STD_GLFW)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_GLFW ")
endif()
if(ARCHEUS_STD_GLEW)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_GLEW ")
endif()
if(ARCHEUS_STD_OPENGL)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_OPENGL")
endif()
set(CMAKE_C_FLAGS ${ARCHEUS_STD_FLAGS}) set(CMAKE_C_FLAGS ${ARCHEUS_STD_FLAGS})
add_library(archeus_std SHARED) set(ARCHEUS_STD_SOURCES
target_sources(archeus_std PRIVATE
src/std/config.c src/std/config.c
# src/arc_ecs.c src/std/handler.c
src/std/hashtable.c src/std/hashtable.c
src/std/io.c src/std/io.c
src/std/string.c src/std/string.c
src/std/vector.c src/std/vector.c
src/std/handler.c
src/std/defaults/config.c src/std/defaults/config.c
src/math/rectangle.c
src/math/vector2.c
src/files/config.c
src/engine/engine.c
src/engine/state.c
) )
target_include_directories(archeus_std PRIVATE set(ARCHEUS_STD_SDL_SOURCES
include src/input/sdl/keyboard.c
src/input/sdl/mouse.c
src/graphics/sdl/config.c
src/graphics/sdl/line.c
src/graphics/sdl/rectangle.c
src/graphics/sdl/renderer.c
src/graphics/sdl/sprite.c
src/graphics/sdl/spritesheet.c
src/graphics/sdl/window.c
) )
set(ARCHEUS_STD_OPENGL_SOURCES
src/graphics/opengl/config.c
src/graphics/opengl/line.c
src/graphics/opengl/rectangle.c
src/graphics/opengl/renderer.c
src/graphics/opengl/sprite.c
src/graphics/opengl/spritesheet.c
src/graphics/opengl/window.c
)
set(ARCHEUS_STD_GLFW_SOURCES
src/input/glfw/keyboard.c
src/input/glfw/mouse.c
)
if(ARCHEUS_STD_SDL)
list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_SDL_SOURCES})
endif()
if(ARCHEUS_STD_OPENGL)
list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_OPENGL_SOURCES})
endif()
if(ARCHEUS_STD_GLFW)
list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_GLFW_SOURCES})
endif()
if(WIN32 AND NOT MSVC)
add_library(archeus_std STATIC ${ARCHEUS_STD_SOURCES})
else()
add_library(archeus_std SHARED ${ARCHEUS_STD_SOURCES})
endif()
if(ARCHEUS_STD_SDL)
target_include_directories(archeus_std
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${SDL2_INCLUDE_DIRS}
PRIVATE ${SDL2IMAGE_INCLUDE_DIRS}
)
target_link_libraries(archeus_std PUBLIC ${SDL2_LIBRARIES} SDL2_image::SDL2_image)
endif()
if(ARCHEUS_STD_OPENGL)
target_include_directories(archeus_std PRIVATE
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
GL
glfw
GLEW
)
endif()
install(TARGETS archeus_std EXPORT archeus_std_Exports install(TARGETS archeus_std EXPORT archeus_std_Exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

View file

@ -0,0 +1,17 @@
#ifndef ARC_FILES_CONFIG_H_
#define ARC_FILES_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/std/config.h"
#include "arc/graphics/renderer.h"
void ARC_FilesConfig_Init(ARC_Config *config);
#ifdef __cplusplus
}
#endif
#endif // !ARC_FILES_CONFIG_H_

View file

@ -0,0 +1,36 @@
#ifndef ARC_OPENGL_RENDERER_H_
#define ARC_OPENGL_RENDERER_H_
#ifdef ARC_OPENGL
#ifdef ARC_GLEW
#define GLEW_STATIC
#include <GL/glew.h>
#endif // !ARC_GLEW
#ifdef ARC_GLFW
#include <GLFW/glfw3.h>
#endif
#include "arc/graphics/renderer.h"
#include "arc/graphics/window.h"
#ifdef ARC_GLFW
typedef struct ARC_RendererType {
GLFWwindow *window;
} ARC_RendererType;
/**
* @brief struct for info needed to create opengl 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
#endif // !ARC_OPENGL
#endif // !ARC_OPENGL_RENDERER_H_

View file

@ -0,0 +1,13 @@
#ifndef ARC_OPENGL_SPRITE_H_
#define ARC_OPENGL_SPRITE_H_
#ifdef ARC_OPENGL
#include "arc/graphics/sprite.h"
struct ARC_Sprite {
};
#endif // !ARC_OPENGL
#endif // !ARC_OPENGL_SPRITE_H_

View file

@ -0,0 +1,13 @@
#ifndef ARC_OPENGL_SPRITESHEET_H_
#define ARC_OPENGL_SPRITESHEET_H_
#ifdef ARC_OPENGL
#include "arc/graphics/spritesheet.h"
struct ARC_Spritesheet {
};
#endif // !ARC_OPENGL
#endif // !ARC_OPENGL_SPRITESHEET_H_

View file

@ -0,0 +1,29 @@
#ifndef ARC_OPENGL_WINDOW_H_
#define ARC_OPENGL_WINDOW_H_
#ifdef ARC_GLFW
#ifdef ARC_GLEW
#define GLEW_STATIC
#include <GL/glew.h>
#endif // !ARC_GLEW
#include "arc/graphics/window.h"
#include <GLFW/glfw3.h>
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
#endif // !ARC_GLFW_WINDOW_H_

View file

@ -12,6 +12,8 @@ extern "C" {
void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color); 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);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -5,7 +5,10 @@
extern "C" { extern "C" {
#endif #endif
typedef struct ARC_Renderer ARC_Renderer; /**
* @note ARC_RendererType is determined by which window library you are using
*/
typedef struct ARC_RendererType ARC_Renderer;
typedef struct ARC_RenderInfo ARC_RenderInfo; typedef struct ARC_RenderInfo ARC_RenderInfo;

View file

@ -2,15 +2,11 @@
#define ARC_SDL_RENDERER_H_ #define ARC_SDL_RENDERER_H_
#ifdef ARC_SDL #ifdef ARC_SDL
#include <SDL.h>
#include "arc/graphics/renderer.h" #include "arc/graphics/renderer.h"
#include "arc/graphics/window.h" #include "arc/graphics/window.h"
#include <SDL.h>
// Temp till I figure out a better solution typedef SDL_Renderer ARC_RendererType;
struct ARC_Renderer {
SDL_Renderer *renderer;
};
/** /**
* @brief struct for info needed to create SDL_Renderer * @brief struct for info needed to create SDL_Renderer
@ -24,6 +20,6 @@ struct ARC_RenderInfo {
Uint32 flags; Uint32 flags;
}; };
#endif // ARC_SDL #endif // !ARC_SDL
#endif // ARC_SDL_RENDERER_H_ #endif // !ARC_SDL_RENDERER_H_

View file

@ -2,9 +2,8 @@
#define ARC_SDL_SPRITE_H_ #define ARC_SDL_SPRITE_H_
#ifdef ARC_SDL #ifdef ARC_SDL
#include <SDL.h>
#include "arc/graphics/sprite.h" #include "arc/graphics/sprite.h"
#include <SDL.h>
struct ARC_Sprite { struct ARC_Sprite {
ARC_Spritesheet *spritesheet; ARC_Spritesheet *spritesheet;
@ -12,6 +11,6 @@ struct ARC_Sprite {
uint32_t *frameIndex; uint32_t *frameIndex;
}; };
#endif // ARC_SDL #endif // !ARC_SDL
#endif // ARC_SDL_SPRITE_H_ #endif // !ARC_SDL_SPRITE_H_

View file

@ -2,15 +2,14 @@
#define ARC_SDL_SPRITESHEET_H_ #define ARC_SDL_SPRITESHEET_H_
#ifdef ARC_SDL #ifdef ARC_SDL
#include <SDL.h>
#include "arc/graphics/spritesheet.h" #include "arc/graphics/spritesheet.h"
#include <SDL.h>
struct ARC_Spritesheet { struct ARC_Spritesheet {
SDL_Texture *texture; SDL_Texture *texture;
uint32_t *size; uint32_t *size;
}; };
#endif // ARC_SDL #endif // !ARC_SDL
#endif // ARC_SDL_SPRITESHEET_H_ #endif // !ARC_SDL_SPRITESHEET_H_

View file

@ -2,14 +2,10 @@
#define ARC_SDL_WINDOW_H_ #define ARC_SDL_WINDOW_H_
#ifdef ARC_SDL #ifdef ARC_SDL
#include <SDL.h>
#include "arc/graphics/window.h" #include "arc/graphics/window.h"
#include <SDL.h>
// Temp till I figure out a better solution typedef SDL_Window ARC_WindowType;
struct ARC_Window {
SDL_Window *window;
};
/** /**
* @brief struct for info needed to create SDL_Window * @brief struct for info needed to create SDL_Window
@ -25,6 +21,6 @@ struct ARC_WindowInfo {
Uint32 flags; Uint32 flags;
}; };
#endif // ARC_SDL #endif // !ARC_SDL
#endif // ARC_SDL_WINDOW_H_ #endif // !ARC_SDL_WINDOW_H_

View file

@ -5,8 +5,18 @@
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
#include "arc/math/point.h"
#include "arc/math/rectangle.h"
#include "arc/graphics/renderer.h"
typedef struct ARC_Spritesheet ARC_Spritesheet; typedef struct ARC_Spritesheet ARC_Spritesheet;
void ARC_Spritesheet_RenderArea(ARC_Spritesheet *spritesheet, ARC_Rect *sheetBounds, ARC_Renderer *renderer, ARC_Rect *renderBounds);
ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet);
uint32_t *ARC_Spritesheet_GetTileSize(ARC_Spritesheet *spritesheet);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -5,7 +5,10 @@
extern "C" { extern "C" {
#endif #endif
typedef struct ARC_Window ARC_Window; /**
* @note ARC_WindowType is determined by which window library you are using
*/
typedef struct ARC_WindowType ARC_Window;
typedef struct ARC_WindowInfo ARC_WindowInfo; typedef struct ARC_WindowInfo ARC_WindowInfo;

View file

@ -0,0 +1,21 @@
#ifndef ARC_GLFW_KEYBOARD_H_
#define ARC_GLFW_KEYBOARD_H_
#ifdef ARC_GLFW
#include <GLFW/glfw3.h>
#include "arc/input/keyboard.h"
struct ARC_Keyboard {
GLFWwindow *window;
ARC_KeyboardState *keys;
ARC_KeyboardState *released;
};
struct ARC_KeyboardInfo {
GLFWwindow *window;
};
#endif // !ARC_GLFW
#endif // !ARC_GLFW_KEYBOARD_H_

View file

@ -0,0 +1,25 @@
#ifndef ARC_GLFW_MOUSE_H_
#define ARC_GLFW_MOUSE_H_
#ifdef ARC_GLFW
#include <GLFW/glfw3.h>
#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
#endif // !ARC_GLFW_MOUSE_H_

View file

@ -23,7 +23,38 @@ void ARC_Keyboard_Create(ARC_Keyboard **keyboard, ARC_KeyboardInfo *info);
void ARC_Keyboard_Destroy(ARC_Keyboard *keyboard); void ARC_Keyboard_Destroy(ARC_Keyboard *keyboard);
void ARC_Keyboard_Update(ARC_Keyboard *keyboard); void ARC_Keyboard_Update(ARC_Keyboard *keyboard);
ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, uint8_t keys); typedef enum ARC_KeyboardKey {
ARC_KEY_A,
ARC_KEY_B,
ARC_KEY_C,
ARC_KEY_D,
ARC_KEY_E,
ARC_KEY_F,
ARC_KEY_G,
ARC_KEY_H,
ARC_KEY_I,
ARC_KEY_J,
ARC_KEY_K,
ARC_KEY_L,
ARC_KEY_M,
ARC_KEY_N,
ARC_KEY_O,
ARC_KEY_P,
ARC_KEY_Q,
ARC_KEY_R,
ARC_KEY_S,
ARC_KEY_T,
ARC_KEY_U,
ARC_KEY_V,
ARC_KEY_W,
ARC_KEY_X,
ARC_KEY_Y,
ARC_KEY_Z,
ARC_KEY_ESC,
} ARC_Keyboard_Key;
ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, enum ARC_KeyboardKey key);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -6,6 +6,7 @@ extern "C" {
#endif #endif
#include "arc/math/point.h" #include "arc/math/point.h"
#include <stdint.h>
typedef struct ARC_Mouse ARC_Mouse; typedef struct ARC_Mouse ARC_Mouse;
@ -32,6 +33,7 @@ void ARC_Mouse_Destroy(ARC_Mouse *mouse);
void ARC_Mouse_Update(ARC_Mouse *mouse); void ARC_Mouse_Update(ARC_Mouse *mouse);
ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse); ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse);
ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button); ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button);
int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -2,8 +2,8 @@
#define ARC_SDL_KEYBOARD_H_ #define ARC_SDL_KEYBOARD_H_
#ifdef ARC_SDL #ifdef ARC_SDL
#include <SDL.h>
#include "arc/input/keyboard.h" #include "arc/input/keyboard.h"
#include <SDL.h>
struct ARC_Keyboard { struct ARC_Keyboard {
SDL_Event *event; SDL_Event *event;

View file

@ -9,7 +9,7 @@
struct ARC_Mouse { struct ARC_Mouse {
SDL_Event *event; SDL_Event *event;
ARC_Point *coords; ARC_Point *coords;
int32_t *scroll; int32_t *scrollY;
ARC_MouseState *buttons; ARC_MouseState *buttons;
uint8_t *buttonsReleased; uint8_t *buttonsReleased;

View file

@ -3,16 +3,27 @@
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ARC_Point { typedef struct ARC_Point {
int32_t x, y; int32_t x;
int32_t y;
} ARC_Point; } ARC_Point;
typedef struct ARC_UPoint { typedef struct ARC_UPoint {
uint32_t x, y; uint32_t x;
uint32_t y;
} ARC_UPoint; } ARC_UPoint;
typedef struct ARC_FPoint { typedef struct ARC_FPoint {
float x, y; float x;
float y;
} ARC_FPoint; } ARC_FPoint;
#ifdef __cplusplus
}
#endif
#endif // ARC_MATH_POINT_H_ #endif // ARC_MATH_POINT_H_

View file

@ -3,6 +3,10 @@
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ARC_Rect { typedef struct ARC_Rect {
int32_t x; int32_t x;
int32_t y; int32_t y;
@ -21,4 +25,8 @@ int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2);
int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2); int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2);
#ifdef __cplusplus
}
#endif
#endif // ARC_MATH_POINT_H_ #endif // ARC_MATH_POINT_H_

View file

@ -1,6 +1,10 @@
#ifndef ARC_MATH_VECTOR2_H_ #ifndef ARC_MATH_VECTOR2_H_
#define ARC_MATH_VECTOR2_H_ #define ARC_MATH_VECTOR2_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ARC_Vector2 { typedef struct ARC_Vector2 {
float x, y; float x, y;
} ARC_Vector2; } ARC_Vector2;
@ -9,4 +13,23 @@ typedef struct ARC_DVector2 {
double x, y; double x, y;
} ARC_DVector2; } ARC_DVector2;
/**
* @brief normalizes a given ARC_Vector2
*
* @param vector the ARC_Vecotr2 to normallize
*/
void ARC_Vector2_Normalize(ARC_Vector2 *vector);
/**
* @brief rotates a given ARC_Vector2 by a given angle in degrees
*
* @param vector the ARC_Vector2 to rotate
* @param angle the angle in degrees to rotate by
*/
void ARC_Vector2_RotateDegree(ARC_Vector2 *vector, float angle);
#ifdef __cplusplus
}
#endif
#endif // ARC_MATH_VECTOR2_H_ #endif // ARC_MATH_VECTOR2_H_

View file

@ -3,6 +3,10 @@
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* @brief a type that holds an array of data and its size * @brief a type that holds an array of data and its size
*/ */
@ -11,4 +15,8 @@ typedef struct ARC_Array {
void *data; void *data;
} ARC_Array; } ARC_Array;
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_ARRAY_H_ #endif //ARC_STD_ARRAY_H_

View file

@ -1,5 +1,4 @@
#include "arc/engine/engine.h" #include "arc/engine/engine.h"
#include <SDL_video.h>
#include <stdlib.h> #include <stdlib.h>
#include "arc/engine/state.h" #include "arc/engine/state.h"
#include "arc/graphics/window.h" #include "arc/graphics/window.h"
@ -11,12 +10,20 @@
//NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas //NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas
#ifdef ARC_SDL #ifdef ARC_SDL
#include <SDL.h>
#include "arc/graphics/sdl/window.h" #include "arc/graphics/sdl/window.h"
#include "arc/graphics/sdl/renderer.h" #include "arc/graphics/sdl/renderer.h"
#include "arc/input/sdl/mouse.h" #include "arc/input/sdl/mouse.h"
#include "arc/input/sdl/keyboard.h" #include "arc/input/sdl/keyboard.h"
#endif // ARC_SDL #include <SDL.h>
#include <SDL_video.h>
#elif ARC_OPENGL
#include "arc/graphics/opengl/window.h"
#include "arc/graphics/opengl/renderer.h"
#ifdef ARC_GLFW
#include "arc/input/glfw/mouse.h"
#include "arc/input/glfw/keyboard.h"
#endif // ARC_GLFW
#endif
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 = (ARC_EngineData *)malloc(sizeof(ARC_EngineData));
@ -35,6 +42,8 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf
#ifdef ARC_SDL #ifdef ARC_SDL
windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (*data)->windowSize.x, (*data)->windowSize.y, 0 }; windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (*data)->windowSize.x, (*data)->windowSize.y, 0 };
#elif ARC_GLFW
windowInfo = (ARC_WindowInfo){ "title", (*data)->windowSize.x, (*data)->windowSize.y };
#endif // ARC_SDL #endif // ARC_SDL
ARC_Window_Create(&((*data)->window), &windowInfo); ARC_Window_Create(&((*data)->window), &windowInfo);
@ -44,7 +53,9 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf
} }
#ifdef ARC_SDL #ifdef ARC_SDL
renderInfo = (ARC_RenderInfo){ (SDL_Window *)(*data)->window->window, -1, SDL_RENDERER_ACCELERATED }; renderInfo = (ARC_RenderInfo){ (SDL_Window *)(*data)->window, -1, SDL_RENDERER_ACCELERATED };
#elif ARC_GLFW
renderInfo = (ARC_RenderInfo){ (GLFWwindow *)(*data)->window };
#endif // ARC_SDL #endif // ARC_SDL
ARC_Renderer_Create(&((*data)->renderer), &renderInfo); ARC_Renderer_Create(&((*data)->renderer), &renderInfo);
@ -57,10 +68,12 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf
SDL_Event *event = (SDL_Event *)malloc(sizeof(SDL_Event)); SDL_Event *event = (SDL_Event *)malloc(sizeof(SDL_Event));
mouseInfo = (ARC_MouseInfo ){ event }; mouseInfo = (ARC_MouseInfo ){ event };
keyboardInfo = (ARC_KeyboardInfo){ event }; keyboardInfo = (ARC_KeyboardInfo){ event };
#elif ARC_GLFW
mouseInfo = (ARC_MouseInfo ){ (GLFWwindow *)(*data)->window };
keyboardInfo = (ARC_KeyboardInfo){ (GLFWwindow *)(*data)->window };
#endif // ARC_SDL #endif // ARC_SDL
ARC_Mouse_Create(&((*data)->mouse), &mouseInfo); ARC_Mouse_Create (&((*data)->mouse) , &mouseInfo );
ARC_Keyboard_Create(&((*data)->keyboard), &keyboardInfo); ARC_Keyboard_Create(&((*data)->keyboard), &keyboardInfo);
} }
@ -82,12 +95,13 @@ void ARC_Engine_Run(ARC_EngineData *data){
} }
#ifdef ARC_SDL #ifdef ARC_SDL
SDL_SetRenderDrawBlendMode((SDL_Renderer *)data->renderer, SDL_BLENDMODE_BLEND);
SDL_Event *event = data->mouse->event; SDL_Event *event = data->mouse->event;
double lastTime = 0, currentTime;
data->dt = 0;
#endif // ARC_SDL #endif // ARC_SDL
double lastTime = 0, currentTime;
data->dt = 0;
data->running = 0; data->running = 0;
while(!data->running){ while(!data->running){
@ -97,8 +111,10 @@ void ARC_Engine_Run(ARC_EngineData *data){
lastTime = currentTime; lastTime = currentTime;
SDL_PollEvent(data->mouse->event); SDL_PollEvent(data->mouse->event);
if(event->type == SDL_QUIT){ return; } if(event->type == SDL_QUIT){ data->running = 1; }
if(event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_ESCAPE){ return; } #elif ARC_GLFW
glfwPollEvents();
data->running = glfwWindowShouldClose((GLFWwindow *)data->window);
#endif // ARC_SDL #endif // ARC_SDL
ARC_Mouse_Update(data->mouse); ARC_Mouse_Update(data->mouse);

View file

@ -2,7 +2,6 @@
#include <stddef.h> #include <stddef.h>
void ARC_State_Update(void *data){ void ARC_State_Update(void *data){
ARC_State *temp = (ARC_State *)data;
((ARC_State *)data)->updateFn(((ARC_State *)data)->data); ((ARC_State *)data)->updateFn(((ARC_State *)data)->data);
} }

104
src/files/config.c Normal file
View file

@ -0,0 +1,104 @@
#include "arc/files/config.h"
#include "arc/std/io.h"
#include "arc/std/errno.h"
#include "arc/std/string.h"
#include "arc/std/array.h"
#include <stdlib.h>
#include <stdint.h>
uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value);
void ARC_CSV_Delete(ARC_Config *config, ARC_String *string, void *value);
void ARC_FilesConfig_Init(ARC_Config *config){
ARC_Config_AddKeyCString(config, (char *)"CSV", 3, ARC_CSV_Read, ARC_CSV_Delete);
}
uint8_t ARC_CSV_Read(ARC_Config *config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
ARC_String *fileData;
ARC_IO_FileToStr(string, &fileData);
if(arc_errno){
ARC_DEBUG_LOG(arc_errno, "ARC_CSV_Read(config, string, value) could not read in csv file: \"%s\"", string->data);
ARC_String_Destroy(fileData);
return 0;
}
uint32_t height = 0;
for(uint32_t i = 0; i < fileData->length; i++){
if(fileData->data[i] == '\n'){
height++;
}
}
*value = malloc(sizeof(ARC_Array));
((ARC_Array *)*value)->data = malloc(sizeof(ARC_Array *) * height);
((ARC_Array *)*value)->size = malloc(sizeof(uint32_t) );
*((ARC_Array *)*value)->size = height;
uint32_t index = 0;
for(uint32_t y = 0; y < height; y++){
uint32_t width = 0;
uint32_t x = 0;
for(uint32_t i = index; i < fileData->length; i++){
if(fileData->data[i] == ','){
width++;
}
if(fileData->data[i] == '\n'){
width++;
break;
}
}
if(!width){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG(arc_errno, "ARC_CSV_Read(config, string, value) no width of line %d", y);
ARC_String_Destroy(fileData);
return 0;
}
((ARC_Array **)((ARC_Array *)*value)->data)[y] = (ARC_Array *) malloc(sizeof(ARC_Array));
((ARC_Array **)((ARC_Array *)*value)->data)[y]->data = malloc(sizeof(int32_t ) * width);
((ARC_Array **)((ARC_Array *)*value)->data)[y]->size = malloc(sizeof(uint32_t) );
*((ARC_Array **)((ARC_Array *)*value)->data)[y]->size = width;
for(uint32_t i = index; i < fileData->length; i++){
if(fileData->data[i] != ',' && fileData->data[i] != '\n'){
continue;
}
ARC_String *indexValueString;
ARC_String_CopySubstring(&indexValueString, fileData, index, i - index);
index = i + 1;
((int32_t *)((ARC_Array **)((ARC_Array *)*value)->data)[y]->data)[x] = (int32_t)ARC_String_ToInt64_t(indexValueString);
ARC_String_Destroy(indexValueString);
x++;
if(fileData->data[i] == '\n'){
index = i + 1;
break;
}
}
}
return 0;
}
void ARC_CSV_Delete(ARC_Config *config, ARC_String *string, void *value){
ARC_Array *valueArray = value;
for(uint32_t i = 0; i < *valueArray->size; i++){
free((int32_t *)((ARC_Array **)valueArray->data)[i]->data);
free((uint32_t *)((ARC_Array **)valueArray->data)[i]->size);
free((ARC_Array *)((ARC_Array **)valueArray->data)[i]);
}
free((ARC_Array **)valueArray->data);
free((uint32_t *)valueArray->size);
free(valueArray);
}

View file

@ -0,0 +1,14 @@
#ifdef ARC_OPENGL
#include <stdio.h>
#include "arc/std/config.h"
#include "arc/std/string.h"
#include "arc/std/errno.h"
#include "arc/graphics/opengl/renderer.h"
void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){
}
#endif // ARC_OPENGL

View file

@ -0,0 +1,8 @@
#ifdef ARC_OPENGL
#include "arc/graphics/line.h"
#include <stdlib.h>
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

View file

@ -0,0 +1,11 @@
#ifdef ARC_OPENGL
#include "arc/graphics/rectangle.h"
#include <stdlib.h>
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

View file

@ -0,0 +1,55 @@
#ifdef ARC_OPENGL
#include "arc/graphics/renderer.h"
#include "arc/graphics/opengl/renderer.h"
#ifdef ARC_GLEW
#define GLEW_STATIC
#include <GL/glew.h>
#endif // ARC_GLEW
#ifdef ARC_GLFW
#include <GLFW/glfw3.h>
#endif
#include "arc/graphics/window.h"
#include "arc/std/errno.h"
#include <stdlib.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;
}
#ifdef ARC_GLFW
*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_GLFW
glfwSwapBuffers(renderer->window);
#endif // ARC_GLEW
}
#endif //ARC_SDL

View file

@ -0,0 +1,29 @@
#ifdef ARC_OPENGL
#include "arc/graphics/sprite.h"
#include "arc/math/point.h"
#include "arc/math/rectangle.h"
#include <stdlib.h>
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

View file

@ -0,0 +1,17 @@
#ifdef ARC_OPENGL
#include "arc/graphics/spritesheet.h"
#include "arc/math/point.h"
#include <stdlib.h>
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

View file

@ -0,0 +1,36 @@
#ifdef ARC_GLFW
#include "arc/graphics/window.h"
#include "arc/graphics/opengl/window.h"
#include "arc/std/errno.h"
#include <GLFW/glfw3.h>
#include <stdio.h>
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

View file

@ -34,7 +34,7 @@ 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_Sprite_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){ void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){
global_renderer = renderer->renderer; global_renderer = (SDL_Renderer *)renderer;
ARC_Config_AddKeyCString(config, (char *)"ARC_Point" , 9, ARC_Point_Read , ARC_Point_Delete ); ARC_Config_AddKeyCString(config, (char *)"ARC_Point" , 9, ARC_Point_Read , ARC_Point_Delete );
ARC_Config_AddKeyCString(config, (char *)"ARC_Rect" , 8, ARC_Rect_Read , ARC_Rect_Delete ); ARC_Config_AddKeyCString(config, (char *)"ARC_Rect" , 8, ARC_Rect_Read , ARC_Rect_Delete );
ARC_Config_AddKeyCString(config, (char *)"ARC_Rect[]" , 10, ARC_RectArray_Read , ARC_RectArray_Delete ); ARC_Config_AddKeyCString(config, (char *)"ARC_Rect[]" , 10, ARC_RectArray_Read , ARC_RectArray_Delete );

View file

@ -1,11 +1,11 @@
#include "arc/graphics/line.h"
#ifdef ARC_SDL #ifdef ARC_SDL
#include "arc/graphics/line.h"
#include "arc/graphics/sdl/renderer.h" #include "arc/graphics/sdl/renderer.h"
#include <stdlib.h> #include <stdlib.h>
void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Renderer *renderer, ARC_Color *color){ void ARC_Line_Render(int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2, ARC_Renderer *renderer, ARC_Color *color){
SDL_SetRenderDrawColor(renderer->renderer, color->r, color->g, color->b, color->a); SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a);
SDL_RenderDrawLine(renderer->renderer, *x1, *y1, *x2, *y2); SDL_RenderDrawLine((SDL_Renderer *)renderer, *x1, *y1, *x2, *y2);
} }
#endif // ARC_SDL #endif // ARC_SDL

View file

@ -1,11 +1,16 @@
#include "arc/graphics/rectangle.h"
#ifdef ARC_SDL #ifdef ARC_SDL
#include "arc/graphics/rectangle.h"
#include "arc/graphics/sdl/renderer.h" #include "arc/graphics/sdl/renderer.h"
#include <stdlib.h> #include <stdlib.h>
void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){ void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){
SDL_SetRenderDrawColor(renderer->renderer, color->r, color->g, color->b, color->a); SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a);
SDL_RenderDrawRect(renderer->renderer, (SDL_Rect *) rect); 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);
} }
#endif // ARC_SDL #endif // ARC_SDL

View file

@ -14,10 +14,9 @@ void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info){
return; return;
} }
*renderer = (ARC_Renderer *)malloc(sizeof(ARC_Renderer)); *renderer = (ARC_Renderer *)SDL_CreateRenderer((SDL_Window *)info->window, info->index, info->flags);
(*renderer)->renderer = SDL_CreateRenderer((SDL_Window *)info->window, info->index, info->flags);
if(!(*renderer)->renderer){ if(!*renderer){
arc_errno = ARC_ERRNO_NULL; arc_errno = ARC_ERRNO_NULL;
ARC_DEBUG_LOG(arc_errno, "SDL_CreateRenderer(%p, %d, %u);", info->window, info->index, info->flags); ARC_DEBUG_LOG(arc_errno, "SDL_CreateRenderer(%p, %d, %u);", info->window, info->index, info->flags);
free(renderer); free(renderer);
@ -25,17 +24,16 @@ void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info){
} }
void ARC_Renderer_Destroy(ARC_Renderer *renderer){ void ARC_Renderer_Destroy(ARC_Renderer *renderer){
SDL_DestroyRenderer((SDL_Renderer *) renderer->renderer); SDL_DestroyRenderer((SDL_Renderer *) renderer);
free(renderer);
} }
void ARC_Renderer_Clear(ARC_Renderer *renderer){ void ARC_Renderer_Clear(ARC_Renderer *renderer){
SDL_SetRenderDrawColor((SDL_Renderer *)renderer->renderer, 0x1c, 0x2c, 0x3c, 0x00); SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x1c, 0x2c, 0x3c, 0x00);
SDL_RenderClear((SDL_Renderer *)renderer->renderer); SDL_RenderClear((SDL_Renderer *)renderer);
} }
void ARC_Renderer_Render(ARC_Renderer *renderer){ void ARC_Renderer_Render(ARC_Renderer *renderer){
SDL_RenderPresent((SDL_Renderer *)renderer->renderer); SDL_RenderPresent((SDL_Renderer *)renderer);
} }
#endif //ARC_SDL #endif //ARC_SDL

View file

@ -1,5 +1,5 @@
#include "arc/graphics/sprite.h"
#ifdef ARC_SDL #ifdef ARC_SDL
#include "arc/graphics/sprite.h"
#include "arc/graphics/sdl/sprite.h" #include "arc/graphics/sdl/sprite.h"
#include "arc/graphics/sdl/spritesheet.h" #include "arc/graphics/sdl/spritesheet.h"
#include "arc/graphics/sdl/renderer.h" #include "arc/graphics/sdl/renderer.h"
@ -28,12 +28,11 @@ 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_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds){
ARC_Rect *temp = (ARC_Rect *)sprite->frames->data + *sprite->frameIndex; SDL_RenderCopy((SDL_Renderer *)renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames->data + *sprite->frameIndex, (SDL_Rect *)renderBounds);
SDL_RenderCopy(renderer->renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames->data + *sprite->frameIndex, (SDL_Rect *)renderBounds);
} }
void ARC_Sprite_RenderRotated(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds, ARC_Point *center, double angle){ void ARC_Sprite_RenderRotated(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds, ARC_Point *center, double angle){
SDL_RenderCopyEx(renderer->renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames->data + *sprite->frameIndex, (SDL_Rect *)renderBounds, angle, (SDL_Point *)center, SDL_FLIP_NONE); 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_IterateFrame(ARC_Sprite *sprite){ void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){

View file

@ -0,0 +1,21 @@
#ifdef ARC_SDL
#include "arc/graphics/spritesheet.h"
#include "arc/graphics/sdl/spritesheet.h"
#include "arc/graphics/sdl/renderer.h"
#include "arc/math/point.h"
#include <SDL_render.h>
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_SDL

View file

@ -2,8 +2,8 @@
#include "arc/graphics/window.h" #include "arc/graphics/window.h"
#include "arc/graphics/sdl/window.h" #include "arc/graphics/sdl/window.h"
#include <SDL.h>
#include "arc/std/errno.h" #include "arc/std/errno.h"
#include <SDL.h>
void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){
if(!info){ if(!info){
@ -18,10 +18,9 @@ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){
return; return;
} }
*window = (ARC_Window *)malloc(sizeof(ARC_Window)); *window = (ARC_Window *)SDL_CreateWindow((const char *)info->title, info->x, info->y, info->w, info->h, info->flags);
(*window)->window = SDL_CreateWindow((const char *)info->title, info->x, info->y, info->w, info->h, info->flags);
if(!(*window)->window){ if(!*window){
arc_errno = ARC_ERRNO_NULL; 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); 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); free(window);
@ -29,8 +28,7 @@ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){
} }
void ARC_Window_Destroy(ARC_Window *window){ void ARC_Window_Destroy(ARC_Window *window){
SDL_DestroyWindow((SDL_Window *) window->window); SDL_DestroyWindow((SDL_Window *) window);
free(window);
} }
#endif //ARC_SDL #endif //ARC_SDL

22
src/input/glfw/keyboard.c Normal file
View file

@ -0,0 +1,22 @@
#ifdef ARC_GLFW
#include "arc/input/glfw/keyboard.h"
#include "arc/input/keyboard.h"
#include "arc/math/point.h"
#include "arc/std/errno.h"
#include <stdlib.h>
#include <stdint.h>
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

33
src/input/glfw/mouse.c Normal file
View file

@ -0,0 +1,33 @@
#ifdef ARC_GLFW
#include "arc/input/glfw/mouse.h"
#include "arc/input/mouse.h"
#include "arc/math/point.h"
#include "arc/std/errno.h"
#include <stdlib.h>
#include <stdint.h>
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

View file

@ -1,3 +1,4 @@
#include "SDL_keycode.h"
#ifdef ARC_SDL #ifdef ARC_SDL
#include "arc/input/sdl/keyboard.h" #include "arc/input/sdl/keyboard.h"
#include "arc/input/keyboard.h" #include "arc/input/keyboard.h"
@ -49,8 +50,40 @@ void ARC_Keyboard_Update(ARC_Keyboard *keyboard){
keyboard->released = (keyboard->keys + keyboard->event->key.keysym.sym); keyboard->released = (keyboard->keys + keyboard->event->key.keysym.sym);
} }
ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, uint8_t key){ ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, enum ARC_KeyboardKey key){
return keyboard->keys[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_ESC: return keyboard->keys[SDLK_ESCAPE];
default: return ARC_KEY_NONE;
}
} }
#endif // ARC_SDL #endif // ARC_SDL

View file

@ -12,13 +12,13 @@ void ARC_Mouse_Create(ARC_Mouse **mouse, ARC_MouseInfo *info){
*mouse = (ARC_Mouse *)malloc(sizeof(ARC_Mouse)); *mouse = (ARC_Mouse *)malloc(sizeof(ARC_Mouse));
(*mouse)->event = info->event; (*mouse)->event = info->event;
(*mouse)->coords = (ARC_Point *)malloc(sizeof(ARC_Point)); (*mouse)->coords = (ARC_Point *)malloc(sizeof(ARC_Point));
(*mouse)->scroll = (int32_t *)malloc(sizeof(int32_t )); (*mouse)->scrollY = (int32_t *)malloc(sizeof(int32_t ));
(*mouse)->buttons = (ARC_MouseState *)malloc(sizeof(ARC_MouseState) * ARC_MOUSE_BUTTON_NUM); (*mouse)->buttons = (ARC_MouseState *)malloc(sizeof(ARC_MouseState) * ARC_MOUSE_BUTTON_NUM);
(*mouse)->buttonsReleased = (uint8_t *)malloc(sizeof(uint8_t)); (*mouse)->buttonsReleased = (uint8_t *)malloc(sizeof(uint8_t));
*(*mouse)->coords = (ARC_Point){0, 0}; *(*mouse)->coords = (ARC_Point){0, 0};
*(*mouse)->scroll = 0; *(*mouse)->scrollY = 0;
for(uint8_t i = 0; i < ARC_MOUSE_BUTTON_NUM; i++){ for(uint8_t i = 0; i < ARC_MOUSE_BUTTON_NUM; i++){
(*mouse)->buttons[i] = ARC_MOUSE_NONE; (*mouse)->buttons[i] = ARC_MOUSE_NONE;
@ -31,7 +31,7 @@ void ARC_Mouse_Destroy(ARC_Mouse *mouse){
free(mouse->buttonsReleased); free(mouse->buttonsReleased);
free(mouse->buttons); free(mouse->buttons);
free(mouse->scroll ); free(mouse->scrollY);
free(mouse->coords ); free(mouse->coords );
free(mouse); free(mouse);
@ -58,9 +58,9 @@ void ARC_Mouse_UpdateButton(ARC_Mouse *mouse, uint8_t button, uint32_t *buttons,
} }
void ARC_Mouse_Update(ARC_Mouse *mouse){ void ARC_Mouse_Update(ARC_Mouse *mouse){
*mouse->scroll = 0; *mouse->scrollY = 0;
if(mouse->event->type == SDL_MOUSEWHEEL){ if(mouse->event->type == SDL_MOUSEWHEEL){
*mouse->scroll = mouse->event->wheel.y; *mouse->scrollY = mouse->event->wheel.y;
} }
uint32_t buttons = SDL_GetMouseState(&(mouse->coords->x), &(mouse->coords->y)); uint32_t buttons = SDL_GetMouseState(&(mouse->coords->x), &(mouse->coords->y));
@ -89,6 +89,8 @@ void ARC_Mouse_Update(ARC_Mouse *mouse){
ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_RIGHT , &buttons, SDL_BUTTON_RMASK ); 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_X1 , &buttons, SDL_BUTTON_X1MASK);
ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X2 , &buttons, SDL_BUTTON_X2MASK); ARC_Mouse_UpdateButton(mouse, ARC_MOUSE_X2 , &buttons, SDL_BUTTON_X2MASK);
} }
ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse){ ARC_Point *ARC_Mouse_GetCoords(ARC_Mouse *mouse){
@ -99,4 +101,8 @@ ARC_MouseState ARC_Mouse_GetState(ARC_Mouse *mouse, ARC_MouseButton button){
return mouse->buttons[button]; return mouse->buttons[button];
} }
int32_t *ARC_Mouse_GetScrollY(ARC_Mouse *mouse){
return mouse->scrollY;
}
#endif // ARC_SDL #endif // ARC_SDL

View file

@ -1,7 +1,7 @@
#include "arc/math/rectangle.h" #include "arc/math/rectangle.h"
//VERY TEMP //VERY TEMP
#include <SDL.h> // #include <SDL.h>
int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2){ int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2){
if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x && if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
@ -13,6 +13,7 @@ int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2){
int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2){ int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2){
//TODO: Replace soon //TODO: Replace soon
return SDL_IntersectRectAndLine((SDL_Rect *) rect, x1, y1, x2, y2); // return SDL_IntersectRectAndLine((SDL_Rect *) rect, x1, y1, x2, y2);
return 1;
} }

14
src/math/vector2.c Normal file
View file

@ -0,0 +1,14 @@
#include "arc/math/vector2.h"
#include <math.h>
void ARC_Vector2_Normalize(ARC_Vector2 *vector){
float length = sqrtf((vector->x * vector->x) + (vector->y * vector->y));
vector->x /= length;
vector->y /= length;
}
void ARC_Vector2_RotateDegree(ARC_Vector2 *vector, float angle){
ARC_Vector2 temp = *vector;
vector->x = (temp.x * cos(angle)) - (temp.y * sin(angle));
vector->y = (temp.x * sin(angle)) + (temp.y * cos(angle));
}

View file

@ -156,6 +156,12 @@ void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value){
if(group){ if(group){
ARC_String_Destroy(group); ARC_String_Destroy(group);
} }
if(temp == NULL){
*value = NULL;
return;
}
*value = temp->data; *value = temp->data;
return; return;
} }