merged herbglitch/master with local changes
This commit is contained in:
commit
a0c02c0dcd
26 changed files with 329 additions and 38 deletions
|
|
@ -45,6 +45,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
|
||||
|
||||
|
|
|
|||
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
|
||||
|
|
|
|||
|
|
@ -87,6 +87,18 @@ uint8_t ARC_String_Equals(ARC_String *first, ARC_String *second);
|
|||
*/
|
||||
uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length);
|
||||
|
||||
/**
|
||||
* @brief check if ARC_String and cstring match
|
||||
*
|
||||
* @param string ARC_string to check
|
||||
* @param offset postion based on string to start comparing against cstring
|
||||
* @param cstring cstring to check
|
||||
* @param length length of cstring
|
||||
*
|
||||
* @return 1 if match, 0 if they don't match
|
||||
*/
|
||||
uint8_t ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length);
|
||||
|
||||
/**
|
||||
* @brief checks if string is alphabetic
|
||||
*
|
||||
|
|
@ -157,39 +169,39 @@ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring);
|
|||
/**
|
||||
* @brief strips the ends based on a given char
|
||||
*
|
||||
* @param original the string which whill have the matching char stripped from
|
||||
* @param stripped where to store the string which has witespace stripped
|
||||
* will be null if there is an error
|
||||
* @param original the string which whill have the matching char stripped from
|
||||
* @param charToStrip the char that will be stripped from the ends
|
||||
*/
|
||||
void ARC_String_StripEnds(ARC_String *original, ARC_String **stripped, char charToStrip);
|
||||
void ARC_String_StripEnds(ARC_String **stripped, ARC_String *original, char charToStrip);
|
||||
|
||||
/**
|
||||
* @brief strips whitespace from a ARC_String
|
||||
*
|
||||
* @param original the string which whill have whitespace stripped from
|
||||
* @param stripped where to store the string which has witespace stripped
|
||||
* will be null if there is an error
|
||||
* @param original the string which whill have whitespace stripped from
|
||||
*/
|
||||
void ARC_String_StripWhitespace(ARC_String *original, ARC_String **stripped);
|
||||
void ARC_String_StripWhitespace(ARC_String **stripped, ARC_String *original);
|
||||
|
||||
/**
|
||||
* @brief strips the whitespace from the ends of a string
|
||||
*
|
||||
* @param original the string which whill have the whitespace stripped from its ends
|
||||
* @param stripped where to store the string which has witespace stripped from the ends
|
||||
* will be null if there is an error
|
||||
* @param original the string which whill have the whitespace stripped from its ends
|
||||
*/
|
||||
void ARC_String_StripEndsWhitespace(ARC_String *original, ARC_String **stripped);
|
||||
void ARC_String_StripEndsWhitespace(ARC_String **stripped, ARC_String *original);
|
||||
|
||||
/**
|
||||
* @brief merges two strings together
|
||||
*
|
||||
* @param combined new ARC_String of combined strings frist + second
|
||||
* @param first first part of string to combine
|
||||
* @param second second part of string to combine
|
||||
* @param combined new ARC_String of combined strings frist + second
|
||||
*/
|
||||
void ARC_String_Merge(ARC_String *first, ARC_String *second, ARC_String **combined);
|
||||
void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *second);
|
||||
|
||||
/**
|
||||
* @brief copy a subtring from a givin ARC_String
|
||||
|
|
|
|||
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,12 +20,19 @@
|
|||
#include "arc/input/sdl/mouse.h"
|
||||
#include "arc/input/sdl/keyboard.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
<<<<<<< HEAD
|
||||
#endif
|
||||
|
||||
#include "arc/graphics/glfw/window.h"
|
||||
#include "arc/graphics/glfw/renderer.h"
|
||||
=======
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#elif ARC_OPENGL
|
||||
#include "arc/graphics/opengl/window.h"
|
||||
#include "arc/graphics/opengl/renderer.h"
|
||||
#ifdef ARC_GLFW
|
||||
>>>>>>> af9a1f1040e60a663e175a3b36d752913941b973
|
||||
#include "arc/input/glfw/mouse.h"
|
||||
#include "arc/input/glfw/keyboard.h"
|
||||
|
||||
|
|
@ -46,6 +53,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
|
||||
|
|
@ -88,6 +97,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);
|
||||
|
|
@ -103,7 +114,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){
|
|||
}
|
||||
|
||||
ARC_String_CopySubstring(&temp, current, 0, separator - 1);
|
||||
ARC_String_StripEndsWhitespace(temp, &tempStripped);
|
||||
ARC_String_StripEndsWhitespace(&tempStripped, temp);
|
||||
x = ARC_String_ToInt64_t(tempStripped);
|
||||
ARC_String_Destroy(temp);
|
||||
ARC_String_Destroy(tempStripped);
|
||||
|
|
@ -101,7 +101,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){
|
|||
}
|
||||
|
||||
ARC_String_CopySubstring(&temp, current, 0, separator - 1);
|
||||
ARC_String_StripEndsWhitespace(temp, &tempStripped);
|
||||
ARC_String_StripEndsWhitespace(&tempStripped, temp);
|
||||
y = ARC_String_ToInt64_t(tempStripped);
|
||||
ARC_String_Destroy(temp);
|
||||
ARC_String_Destroy(tempStripped);
|
||||
|
|
@ -117,7 +117,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){
|
|||
}
|
||||
|
||||
ARC_String_CopySubstring(&temp, current, 0, separator - 1);
|
||||
ARC_String_StripEndsWhitespace(temp, &tempStripped);
|
||||
ARC_String_StripEndsWhitespace(&tempStripped, temp);
|
||||
w = ARC_String_ToInt64_t(tempStripped);
|
||||
ARC_String_Destroy(temp);
|
||||
ARC_String_Destroy(tempStripped);
|
||||
|
|
@ -133,7 +133,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){
|
|||
}
|
||||
|
||||
ARC_String_CopySubstring(&temp, current, 0, separator);
|
||||
ARC_String_StripEndsWhitespace(temp, &tempStripped);
|
||||
ARC_String_StripEndsWhitespace(&tempStripped, temp);
|
||||
h = ARC_String_ToInt64_t(tempStripped);
|
||||
ARC_String_Destroy(temp);
|
||||
ARC_String_Destroy(tempStripped);
|
||||
|
|
@ -150,7 +150,7 @@ uint8_t ARC_Rect_Read(ARC_Config *config, ARC_String *string, void **value){
|
|||
void ARC_RectArray_ReadRect(ARC_Config* config, ARC_String *stripped, uint64_t index, uint64_t length, uint64_t *arrayIndex, void **value){
|
||||
ARC_String *substr, *temp;
|
||||
ARC_String_CopySubstring(&temp, stripped, index, length);
|
||||
ARC_String_StripEndsWhitespace(temp, &substr);
|
||||
ARC_String_StripEndsWhitespace(&substr, temp);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
// reading in reference
|
||||
|
|
@ -194,7 +194,7 @@ uint8_t ARC_RectArray_Read(ARC_Config* config, ARC_String *string, void **value)
|
|||
|
||||
ARC_String *temp, *stripped;
|
||||
ARC_String_CopySubstring(&temp, string, 1, string->length - 2);
|
||||
ARC_String_StripEndsWhitespace(temp, &stripped);
|
||||
ARC_String_StripEndsWhitespace(&stripped, temp);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
uint64_t arraySize = 1;
|
||||
|
|
|
|||
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
|
||||
};
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@ void ARC_Config_SetKeyGroup(ARC_Config *config, ARC_String **data, uint8_t *comm
|
|||
|
||||
ARC_String *name, *temp;
|
||||
ARC_String_CopySubstring(&temp, *data, index, nextIndex - index - 1);
|
||||
ARC_String_StripEndsWhitespace(temp, &name);
|
||||
ARC_String_StripEndsWhitespace(&name, temp);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
temp = *data;
|
||||
|
|
@ -258,11 +258,11 @@ void ARC_Config_GetNameAndValue(ARC_String *data, ARC_String **name, ARC_String
|
|||
index++;
|
||||
|
||||
ARC_String *dataTemp = *name;
|
||||
ARC_String_StripEndsWhitespace(dataTemp, name);
|
||||
ARC_String_StripEndsWhitespace(name, dataTemp);
|
||||
ARC_String_Destroy(dataTemp);
|
||||
|
||||
ARC_String_CopySubstring(&dataTemp, data, index, data->length - index);
|
||||
ARC_String_StripEndsWhitespace(dataTemp, value);
|
||||
ARC_String_StripEndsWhitespace(value, dataTemp);
|
||||
ARC_String_Destroy(dataTemp);
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group
|
|||
|
||||
while(*data && (*data)->length){
|
||||
ARC_String *dataTemp = *data;
|
||||
ARC_String_StripEndsWhitespace(dataTemp, data);
|
||||
ARC_String_StripEndsWhitespace(data, dataTemp);
|
||||
ARC_String_Destroy(dataTemp);
|
||||
|
||||
// break out of current group
|
||||
|
|
@ -302,7 +302,7 @@ void ARC_Config_Recurse(ARC_Config *config, ARC_String **data, ARC_String *group
|
|||
|
||||
ARC_String *keyType, *keyTypeTemp;
|
||||
ARC_String_CopySubstring(&keyTypeTemp, *data, 0, index);
|
||||
ARC_String_StripEndsWhitespace(keyTypeTemp, &keyType);
|
||||
ARC_String_StripEndsWhitespace(&keyType, keyTypeTemp);
|
||||
ARC_String_Destroy(keyTypeTemp);
|
||||
|
||||
if(ARC_String_EqualsCString(keyType, "group", 5)){
|
||||
|
|
@ -468,7 +468,7 @@ void ARC_Config_RunCommand(ARC_Config *config, ARC_String *command){
|
|||
|
||||
ARC_String *commandArgTemp, *commandArg;
|
||||
ARC_String_CopySubstring(&commandArgTemp, command, index + space->length, command->length - (index + space->length));
|
||||
ARC_String_StripWhitespace(commandArgTemp, &commandArg);
|
||||
ARC_String_StripWhitespace(&commandArg, commandArgTemp);
|
||||
ARC_String_Destroy(commandArgTemp);
|
||||
|
||||
if(ARC_String_EqualsCString(command, "load", 4)){
|
||||
|
|
@ -548,7 +548,7 @@ void ARC_Config_FileIO(ARC_Config *config, ARC_String *path, uint8_t command){
|
|||
ARC_String_Destroy(temp);
|
||||
|
||||
temp = data;
|
||||
ARC_String_StripEndsWhitespace(temp, &data);
|
||||
ARC_String_StripEndsWhitespace(&data, temp);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
ARC_Config_Recurse(config, &data, NULL, &command);
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ uint8_t ARC_ConfigKey_Read_String(ARC_Config* config, ARC_String *string, void *
|
|||
void ARC_ConfigKey_StringArray_ReadString(ARC_Config* config, ARC_String *stripped, uint64_t index, uint64_t length, uint64_t *arrayIndex, void **value){
|
||||
ARC_String *substr, *temp;
|
||||
ARC_String_CopySubstring(&temp, stripped, index, length);
|
||||
ARC_String_StripEndsWhitespace(temp, &substr);
|
||||
ARC_String_StripEndsWhitespace(&substr, temp);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
// reading in reference
|
||||
|
|
@ -239,7 +239,7 @@ uint8_t ARC_ConfigKey_Read_StringArray(ARC_Config* config, ARC_String *string, v
|
|||
|
||||
ARC_String *temp, *stripped;
|
||||
ARC_String_CopySubstring(&temp, string, 1, string->length - 2);
|
||||
ARC_String_StripEndsWhitespace(temp, &stripped);
|
||||
ARC_String_StripEndsWhitespace(&stripped, temp);
|
||||
ARC_String_Destroy(temp);
|
||||
|
||||
uint64_t arraySize = 1;
|
||||
|
|
|
|||
|
|
@ -100,6 +100,18 @@ uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64
|
|||
return 1;
|
||||
}
|
||||
|
||||
uint8_t ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length){
|
||||
if(string->length - offset < length){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strncmp(string->data + offset, cstring, length)){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t ARC_String_Alpha(ARC_String *string){
|
||||
for(uint64_t length = string->length; length; length--){
|
||||
if(string->data[length - 1] >= 'a' && string->data[length - 1] <= 'z'){
|
||||
|
|
@ -131,6 +143,7 @@ double ARC_String_ToDouble(ARC_String *string){
|
|||
|
||||
uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring){
|
||||
if(!string || !substring){
|
||||
ARC_DEBUG_ERR("ARC_String_Find(string, substring), string or substring was null");
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
return ~(uint64_t)0;
|
||||
}
|
||||
|
|
@ -152,6 +165,7 @@ uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring){
|
|||
uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_t length){
|
||||
if(!string || !cstring){
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
ARC_DEBUG_ERR("ARC_String_FindCString(string, cstring, length), string or cstring was null");
|
||||
return ~(uint64_t)0;
|
||||
}
|
||||
|
||||
|
|
@ -172,6 +186,7 @@ uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_
|
|||
uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){
|
||||
if(!string || !substring){
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
ARC_DEBUG_ERR("ARC_String_FindBack(string, substring), string or substring was null");
|
||||
return ~(uint64_t)0;
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +204,7 @@ uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring){
|
|||
return ~(uint64_t)0;
|
||||
}
|
||||
|
||||
void ARC_String_StripEnds(ARC_String *original, ARC_String **stripped, char charToStrip){
|
||||
void ARC_String_StripEnds(ARC_String **stripped, ARC_String *original, char charToStrip){
|
||||
if(!original){
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
*stripped = NULL;
|
||||
|
|
@ -232,7 +247,7 @@ void ARC_String_StripEnds(ARC_String *original, ARC_String **stripped, char char
|
|||
ARC_String_Create(stripped, original->data + start, length);
|
||||
}
|
||||
|
||||
void ARC_String_StripWhitespace(ARC_String *original, ARC_String **stripped){
|
||||
void ARC_String_StripWhitespace(ARC_String **stripped, ARC_String *original){
|
||||
if(!original){
|
||||
arc_errno = ARC_ERRNO_NULL;
|
||||
*stripped = NULL;
|
||||
|
|
@ -303,7 +318,7 @@ void ARC_String_StripWhitespace(ARC_String *original, ARC_String **stripped){
|
|||
ARC_String_Create(stripped, data, length);
|
||||
}
|
||||
|
||||
void ARC_String_StripEndsWhitespace(ARC_String *original, ARC_String **stripped){
|
||||
void ARC_String_StripEndsWhitespace(ARC_String **stripped, ARC_String *original){
|
||||
uint64_t index;
|
||||
for(uint64_t i = 0; i < original->length; i++){
|
||||
if(original->data[i] == ' '){
|
||||
|
|
@ -351,7 +366,7 @@ void ARC_String_StripEndsWhitespace(ARC_String *original, ARC_String **stripped)
|
|||
ARC_String_CopySubstring(stripped, original, index, endIndex - index);
|
||||
}
|
||||
|
||||
void ARC_String_Merge(ARC_String *first, ARC_String *second, ARC_String **combined){
|
||||
void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *second){
|
||||
char data[first->length + second->length];
|
||||
for(uint32_t i = 0; i < first->length; i++){
|
||||
data[i] = first->data[i];
|
||||
|
|
@ -385,7 +400,7 @@ void ARC_String_RemoveSection(ARC_String **newString, ARC_String *original, uint
|
|||
ARC_String_CopySubstring(&first , original, 0 , removeIndex );
|
||||
ARC_String_CopySubstring(&second, original, removeIndex + removeLength, original->length - (removeIndex + removeLength));
|
||||
|
||||
ARC_String_Merge(first, second, newString);
|
||||
ARC_String_Merge(newString, first, second);
|
||||
|
||||
ARC_String_Destroy(first );
|
||||
ARC_String_Destroy(second);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue