merged from herbglitch/master
This commit is contained in:
commit
2f221987af
21 changed files with 339 additions and 10 deletions
|
|
@ -31,7 +31,46 @@ set_property(CACHE ARCHEUS_STD_GRAPHICS_BACKEND PROPERTY STRINGS NONE SDL2 OPENG
|
|||
set(ARCHEUS_STD_FLAGS "")
|
||||
set(ARCHEUS_STD_LIBRARIES "")
|
||||
|
||||
<<<<<<< HEAD
|
||||
# ~ ARCHEUS_SOURCES ~ #
|
||||
=======
|
||||
if(ARCHEUS_STD_DEBUG)
|
||||
string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g -ggdb -DARC_DEBUG ")
|
||||
endif()
|
||||
|
||||
if(ARCHEUS_STD_DEFAULT_CONFIG)
|
||||
string(APPEND ARCHEUS_STD_FLAGS "-DARC_DEFAULT_CONFIG ")
|
||||
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)
|
||||
find_package(SDL2_ttf REQUIRED)
|
||||
find_package(SDL2_mixer 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})
|
||||
|
||||
>>>>>>> 5750185bd8a38ce2a450f47e3bd8d5315b455561
|
||||
set(ARCHEUS_STD_SOURCES
|
||||
src/std/config.c
|
||||
src/std/errno.c
|
||||
|
|
@ -45,6 +84,7 @@ set(ARCHEUS_STD_SOURCES
|
|||
src/math/circle.c
|
||||
src/math/config.c
|
||||
src/math/obround.c
|
||||
src/math/point.c
|
||||
src/math/rectangle.c
|
||||
src/math/vector2.c
|
||||
|
||||
|
|
@ -54,6 +94,7 @@ set(ARCHEUS_STD_SOURCES
|
|||
src/engine/state.c
|
||||
)
|
||||
|
||||
<<<<<<< HEAD
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g -ggdb -DARC_DEBUG ")
|
||||
endif()
|
||||
|
|
@ -85,6 +126,27 @@ if(ARCHEUS_STD_GLEW)
|
|||
endif()
|
||||
|
||||
set(CMAKE_C_FLAGS ${ARCHEUS_STD_FLAGS})
|
||||
=======
|
||||
set(ARCHEUS_STD_SDL_SOURCES
|
||||
src/audio/sdl/audio.c
|
||||
src/audio/sdl/config.c
|
||||
|
||||
src/input/sdl/keyboard.c
|
||||
src/input/sdl/mouse.c
|
||||
|
||||
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/renderer.c
|
||||
src/graphics/sdl/sprite.c
|
||||
src/graphics/sdl/spritesheet.c
|
||||
src/graphics/sdl/text.c
|
||||
src/graphics/sdl/view.c
|
||||
src/graphics/sdl/window.c
|
||||
)
|
||||
>>>>>>> 5750185bd8a38ce2a450f47e3bd8d5315b455561
|
||||
|
||||
set(ARCHEUS_STD_OPENGL_SOURCES
|
||||
src/graphics/opengl/config.c
|
||||
|
|
@ -119,9 +181,20 @@ target_include_directories(archeus_std
|
|||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
)
|
||||
|
||||
<<<<<<< HEAD
|
||||
target_link_libraries(archeus_std
|
||||
PUBLIC m
|
||||
)
|
||||
=======
|
||||
target_link_libraries(archeus_std PUBLIC ${SDL2_LIBRARIES} SDL2_image::SDL2_image SDL2_ttf::SDL2_ttf SDL2_mixer::SDL2_mixer)
|
||||
endif()
|
||||
|
||||
if(ARCHEUS_STD_OPENGL)
|
||||
target_include_directories(archeus_std PRIVATE
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
)
|
||||
endif()
|
||||
>>>>>>> 5750185bd8a38ce2a450f47e3bd8d5315b455561
|
||||
|
||||
install(TARGETS archeus_std EXPORT archeus_std_Exports
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
|
|
|
|||
16
include/arc/audio/audio.h
Normal file
16
include/arc/audio/audio.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef ARC_AUDIO_H_
|
||||
#define ARC_AUDIO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct ARC_Audio ARC_Audio;
|
||||
|
||||
void ARC_Audio_Play(ARC_Audio *audio);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !ARC_AUDIO_H_
|
||||
22
include/arc/audio/config.h
Normal file
22
include/arc/audio/config.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef ARC_AUDIO_CONFIG_H_
|
||||
#define ARC_AUDIO_CONFIG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "arc/std/string.h"
|
||||
|
||||
typedef struct ARC_Config ARC_Config;
|
||||
void ARC_AudioConfig_Init(ARC_Config *config);
|
||||
|
||||
uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value);
|
||||
|
||||
void ARC_Audio_Delete(ARC_Config *config, ARC_String *string, void *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ARC_AUDIO_CONFIG_H_
|
||||
12
include/arc/audio/sdl/audio.h
Normal file
12
include/arc/audio/sdl/audio.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef ARC_SDL_AUDIO_H_
|
||||
#define ARC_SDL_AUDIO_H_
|
||||
|
||||
#ifdef ARC_SDL
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
|
||||
typedef struct ARC_Audio {
|
||||
Mix_Chunk *chunk;
|
||||
} ARC_Audio;
|
||||
|
||||
#endif // !ARC_SDL
|
||||
#endif // !ARC_SDL_AUDIO_H_
|
||||
|
|
@ -12,7 +12,7 @@ extern "C" {
|
|||
|
||||
void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color);
|
||||
|
||||
// void ARC_Rect_RenderFill(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color);
|
||||
void ARC_Circle_RenderFill(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ struct ARC_Sprite {
|
|||
ARC_Spritesheet *spritesheet;
|
||||
ARC_Array *frames;
|
||||
uint32_t *frameIndex;
|
||||
//TODO: temp
|
||||
uint8_t opacity;
|
||||
};
|
||||
|
||||
#endif // !ARC_SDL
|
||||
|
|
|
|||
|
|
@ -42,6 +42,18 @@ void ARC_Sprite_Destroy(ARC_Sprite *sprite);
|
|||
*/
|
||||
void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite);
|
||||
|
||||
//TODO: temp
|
||||
/**
|
||||
* @brief sets ARC_Sprite's opacity
|
||||
*
|
||||
* @param sprite ARC_Sprite that is changing opacity
|
||||
* @param opacity new opacity for ARC_Sprite
|
||||
*
|
||||
* @note this is temp because opacity probably should be a value
|
||||
* bigger than 255
|
||||
*/
|
||||
void ARC_Sprite_SetOpacity(ARC_Sprite *sprite, uint8_t opacity);
|
||||
|
||||
/**
|
||||
* @brief renders ARC_Sprite type
|
||||
*
|
||||
|
|
@ -94,6 +106,15 @@ void ARC_Sprite_SetFrameIndex(ARC_Sprite *sprite, uint32_t index);
|
|||
*/
|
||||
void ARC_Sprite_IterateFrame(ARC_Sprite *sprite);
|
||||
|
||||
/**
|
||||
* @brief gets ARC_Sprite's current frame
|
||||
*
|
||||
* @param sprite ARC_Sprite to get frame from
|
||||
*
|
||||
* @return index ARC_Sprite's current frame index
|
||||
*/
|
||||
uint32_t ARC_Sprite_GetFrameIndex(ARC_Sprite *sprite);
|
||||
|
||||
/**
|
||||
* @brief returns the current bounds based on the ARC_Sprite's frames
|
||||
*
|
||||
|
|
|
|||
59
include/arc/graphics/view.h
Normal file
59
include/arc/graphics/view.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#ifndef ARC_GRAPHICS_VIEW_H_
|
||||
#define ARC_GRAPHICS_VIEW_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "arc/graphics/renderer.h"
|
||||
#include "arc/math/rectangle.h"
|
||||
|
||||
typedef struct ARC_View {
|
||||
ARC_Renderer *renderer;
|
||||
ARC_Rect bounds;
|
||||
} ARC_View;
|
||||
|
||||
/**
|
||||
* @brief a function for ARC_View where contents of the function will be rendered within a view
|
||||
*
|
||||
* @param data data to be used within ARC_View_RenderFn
|
||||
*/
|
||||
typedef void (* ARC_View_RenderFn)(void *data);
|
||||
|
||||
/**
|
||||
* @brief creates ARC_View type
|
||||
*
|
||||
* @param view ARC_View to initialize
|
||||
* @param renderer ARC_Renderer the view will render to
|
||||
* @param bounds ARC_Rect bounds of the view within the renderer
|
||||
*/
|
||||
void ARC_View_Create(ARC_View **view, ARC_Renderer *renderer, ARC_Rect bounds);
|
||||
|
||||
/**
|
||||
* @brief destroys ARC_View type
|
||||
*/
|
||||
void ARC_View_Destroy(ARC_View *view);
|
||||
|
||||
/**
|
||||
* @brief renders callbacks contents within an ARC_View
|
||||
*
|
||||
* @param view ARC_View to be renedered to
|
||||
* @param renderFn function which contents will render to given ARC_View
|
||||
* @param data data to be used in renderFn
|
||||
*/
|
||||
void ARC_View_Render(ARC_View *view, ARC_View_RenderFn renderFn, void *data);
|
||||
|
||||
/**
|
||||
* @brief gets bounds from ARC_View type
|
||||
*
|
||||
* @param view ARC_View to get bounds from
|
||||
*
|
||||
* @return bounds of the view
|
||||
*/
|
||||
ARC_Rect ARC_View_GetBounds(ARC_View *view);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !ARC_GRAPHICS_VIEW_H_
|
||||
|
|
@ -64,6 +64,7 @@ typedef enum ARC_KeyboardKey {
|
|||
|
||||
ARC_KEY_SPACE,
|
||||
ARC_KEY_ESC,
|
||||
ARC_KEY_ENTER,
|
||||
} ARC_Keyboard_Key;
|
||||
|
||||
ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, enum ARC_KeyboardKey key);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ typedef struct ARC_FPoint {
|
|||
float y;
|
||||
} ARC_FPoint;
|
||||
|
||||
ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
7
src/audio/sdl/audio.c
Normal file
7
src/audio/sdl/audio.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include "arc/audio/audio.h"
|
||||
#include "arc/audio/sdl/audio.h"
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
|
||||
void ARC_Audio_Play(ARC_Audio *audio){
|
||||
Mix_PlayChannel(-1, audio->chunk, 0);
|
||||
}
|
||||
43
src/audio/sdl/config.c
Normal file
43
src/audio/sdl/config.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "arc/audio/config.h"
|
||||
#include "arc/audio/sdl/audio.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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);
|
||||
}
|
||||
|
|
@ -20,8 +20,8 @@
|
|||
#include "arc/input/sdl/mouse.h"
|
||||
#include "arc/input/sdl/keyboard.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#elif ARC_OPENGL
|
||||
#include "arc/graphics/opengl/window.h"
|
||||
#include "arc/graphics/opengl/renderer.h"
|
||||
|
|
@ -48,6 +48,8 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf
|
|||
//TEMP
|
||||
#ifdef ARC_SDL
|
||||
TTF_Init();
|
||||
Mix_Init(0);
|
||||
Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
|
||||
#endif
|
||||
|
||||
#ifdef ARC_SDL
|
||||
|
|
@ -90,6 +92,8 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanf
|
|||
void ARC_EngineData_Destroy(ARC_EngineData *data){
|
||||
#ifdef ARC_SDL
|
||||
free(data->mouse->event);
|
||||
TTF_Quit();
|
||||
Mix_Quit();
|
||||
#endif // ARC_SDL
|
||||
|
||||
ARC_Mouse_Destroy(data->mouse);
|
||||
|
|
@ -105,7 +109,6 @@ void ARC_Engine_Run(ARC_EngineData *data){
|
|||
}
|
||||
|
||||
#ifdef ARC_SDL
|
||||
SDL_SetRenderDrawBlendMode((SDL_Renderer *)data->renderer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
SDL_Event *event = data->mouse->event;
|
||||
double lastTime = 0, currentTime;
|
||||
|
|
|
|||
|
|
@ -40,4 +40,13 @@ void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *co
|
|||
}
|
||||
}
|
||||
|
||||
//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_SDL
|
||||
|
|
@ -53,7 +53,10 @@ int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){
|
|||
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();
|
||||
|
|
@ -213,12 +216,7 @@ uint8_t ARC_Sprite_Read(ARC_Config* config, ARC_String *string, void **value){
|
|||
}
|
||||
}
|
||||
//sprite
|
||||
*value = malloc(sizeof(ARC_Sprite));
|
||||
((ARC_Sprite *) *value)->frameIndex = malloc(sizeof(uint32_t));
|
||||
|
||||
((ARC_Sprite *) *value)->spritesheet = spritesheet;
|
||||
((ARC_Sprite *) *value)->frames = frames;
|
||||
*((ARC_Sprite *) *value)->frameIndex = 0;
|
||||
ARC_Sprite_Create((ARC_Sprite **)value, spritesheet, frames);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ void ARC_Renderer_Create(ARC_Renderer **renderer, ARC_RenderInfo *info){
|
|||
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){
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Ar
|
|||
(*sprite)->frames = frames;
|
||||
(*sprite)->frameIndex = (uint32_t *)malloc(sizeof(uint32_t));
|
||||
*(*sprite)->frameIndex = 0;
|
||||
(*sprite)->opacity = 255;
|
||||
}
|
||||
|
||||
void ARC_Sprite_Destroy(ARC_Sprite *sprite){
|
||||
|
|
@ -28,7 +29,13 @@ void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite){
|
|||
*(*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);
|
||||
}
|
||||
|
||||
|
|
@ -42,10 +49,14 @@ void ARC_Sprite_RenderFlip(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +77,10 @@ void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
35
src/graphics/sdl/view.c
Normal file
35
src/graphics/sdl/view.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "arc/graphics/view.h"
|
||||
|
||||
#include "arc/std/errno.h"
|
||||
#include <SDL.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info){
|
|||
return;
|
||||
}
|
||||
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0){
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ ARC_KeyboardState ARC_Keyboard_GetState(ARC_Keyboard *keyboard, enum ARC_Keyboar
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
8
src/math/point.c
Normal file
8
src/math/point.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include "arc/math/point.h"
|
||||
|
||||
ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t){
|
||||
return (ARC_FPoint){
|
||||
(1.0f - t) * start->x + t * end->x,
|
||||
(1.0f - t) * start->y + t * end->y
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue