From 845b80329ebf3270f9d4c202e6fd68f27ef16d3b Mon Sep 17 00:00:00 2001 From: herbglitch Date: Thu, 3 Nov 2022 21:28:58 -0600 Subject: [PATCH 1/5] working on getting ARC_Spritesheet and ARC_Sprite for SDL moved over from old ARC_SDL --- include/arc/graphics/sdl/renderer.h | 8 -------- include/arc/graphics/sdl/window.h | 8 -------- include/arc/graphics/window.h | 8 ++++++++ 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/include/arc/graphics/sdl/renderer.h b/include/arc/graphics/sdl/renderer.h index 70c8923..5920b99 100644 --- a/include/arc/graphics/sdl/renderer.h +++ b/include/arc/graphics/sdl/renderer.h @@ -3,10 +3,6 @@ #ifdef ARC_SDL -#ifdef __cplusplus -extern "C" { -#endif - #include #include "arc/graphics/renderer.h" #include "arc/graphics/window.h" @@ -28,10 +24,6 @@ struct ARC_RenderInfo { Uint32 flags; }; -#ifdef __cplusplus -} -#endif - #endif // ARC_SDL #endif // ARC_SDL_RENDERER_H_ diff --git a/include/arc/graphics/sdl/window.h b/include/arc/graphics/sdl/window.h index 942437f..aebcd64 100644 --- a/include/arc/graphics/sdl/window.h +++ b/include/arc/graphics/sdl/window.h @@ -3,10 +3,6 @@ #ifdef ARC_SDL -#ifdef __cplusplus -extern "C" { -#endif - #include #include "arc/graphics/window.h" @@ -29,10 +25,6 @@ struct ARC_WindowInfo { Uint32 flags; }; -#ifdef __cplusplus -} -#endif - #endif // ARC_SDL #endif // ARC_SDL_WINDOW_H_ diff --git a/include/arc/graphics/window.h b/include/arc/graphics/window.h index bbb0e7d..a6ba8f2 100644 --- a/include/arc/graphics/window.h +++ b/include/arc/graphics/window.h @@ -1,6 +1,10 @@ #ifndef ARC_GRAPHICS_WINDOW_H_ #define ARC_GRAPHICS_WINDOW_H_ +#ifdef __cplusplus +extern "C" { +#endif + typedef struct ARC_Window ARC_Window; typedef struct ARC_WindowInfo ARC_WindowInfo; @@ -21,4 +25,8 @@ void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info); */ void ARC_Window_Destroy(ARC_Window *window); +#ifdef __cplusplus +} +#endif + #endif // !ARC_GRAPHICS_WINDOW_H_ From 81b3ed91445c799dc7918f9ddb4213cc3fe85ac2 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Thu, 3 Nov 2022 21:29:08 -0600 Subject: [PATCH 2/5] working on getting ARC_Spritesheet and ARC_Sprite for SDL moved over from old ARC_SDL --- include/arc/graphics/config.h | 15 ++ include/arc/graphics/sdl/sprite.h | 16 ++ include/arc/graphics/sdl/spritesheet.h | 16 ++ include/arc/graphics/sprite.h | 14 ++ include/arc/graphics/spritesheet.h | 14 ++ src/graphics/sdl/temp.c | 266 +++++++++++++++++++++++++ 6 files changed, 341 insertions(+) create mode 100644 include/arc/graphics/config.h create mode 100644 include/arc/graphics/sdl/sprite.h create mode 100644 include/arc/graphics/sdl/spritesheet.h create mode 100644 include/arc/graphics/sprite.h create mode 100644 include/arc/graphics/spritesheet.h create mode 100644 src/graphics/sdl/temp.c diff --git a/include/arc/graphics/config.h b/include/arc/graphics/config.h new file mode 100644 index 0000000..bdda530 --- /dev/null +++ b/include/arc/graphics/config.h @@ -0,0 +1,15 @@ +#ifndef ARC_GRAPHICS_CONFIG_H_ +#define ARC_GRAPHICS_CONFIG_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// ARC_Config_Create(); +// ARC_Config_Destroy(); + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_GRAPHICS_CONFIG_H_ diff --git a/include/arc/graphics/sdl/sprite.h b/include/arc/graphics/sdl/sprite.h new file mode 100644 index 0000000..4287860 --- /dev/null +++ b/include/arc/graphics/sdl/sprite.h @@ -0,0 +1,16 @@ +#ifndef ARC_SDL_SPRITE_H_ +#define ARC_SDL_SPRITE_H_ + +#ifdef ARC_SDL + +#include +#include "arc/graphics/spritesheet.h" + +struct ARC_Sprite { + ARC_Spritesheet *spritesheet; + SDL_Rect *bounds; +}; + +#endif // ARC_SDL + +#endif // ARC_SDL_SPRITE_H_ diff --git a/include/arc/graphics/sdl/spritesheet.h b/include/arc/graphics/sdl/spritesheet.h new file mode 100644 index 0000000..3804119 --- /dev/null +++ b/include/arc/graphics/sdl/spritesheet.h @@ -0,0 +1,16 @@ +#ifndef ARC_SDL_SPRITESHEET_H_ +#define ARC_SDL_SPRITESHEET_H_ + +#ifdef ARC_SDL + +#include +#include "arc/graphics/spritesheet.h" + +struct ARC_Spritesheet { + SDL_Texture *texture; + uint32_t *size; +}; + +#endif // ARC_SDL + +#endif // ARC_SDL_SPRITESHEET_H_ diff --git a/include/arc/graphics/sprite.h b/include/arc/graphics/sprite.h new file mode 100644 index 0000000..f5ddc32 --- /dev/null +++ b/include/arc/graphics/sprite.h @@ -0,0 +1,14 @@ +#ifndef ARC_GRAPHICS_SPRITE_H_ +#define ARC_GRAPHICS_SPRITE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ARC_Sprite ARC_Sprite; + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_GRAPHICS_SPRITE_H_ diff --git a/include/arc/graphics/spritesheet.h b/include/arc/graphics/spritesheet.h new file mode 100644 index 0000000..285bf31 --- /dev/null +++ b/include/arc/graphics/spritesheet.h @@ -0,0 +1,14 @@ +#ifndef ARC_GRAPHICS_SPRITESHEET_H_ +#define ARC_GRAPHICS_SPRITESHEET_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ARC_Spritesheet ARC_Spritesheet; + +#ifdef __cplusplus +} +#endif + +#endif // !ARC_GRAPHICS_SPRITESHEET_H_ diff --git a/src/graphics/sdl/temp.c b/src/graphics/sdl/temp.c new file mode 100644 index 0000000..3d5a6ef --- /dev/null +++ b/src/graphics/sdl/temp.c @@ -0,0 +1,266 @@ +#include "types.h" +#include +#include +#include +#include + +#define ARC_DEFAULT_CONFIG +#include + +SDL_Renderer *global_renderer; + +int32_t ARC_SDL_Rect_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); +int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); +int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); +int32_t ARC_Sprite_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); + +int32_t ARC_SDL_Rect_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); +int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); +int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); +int32_t ARC_Sprite_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); + +int32_t ARC_Types_Init(ARC_Config *config, SDL_Renderer *renderer){ + global_renderer = renderer; + ARC_ConfigKey_Add(config, (char *)"SDL_Rect" , (ARC_ConfigKeyRead) ARC_SDL_Rect_Read , (ARC_ConfigKeyDelete) ARC_SDL_Rect_Delete ); + ARC_ConfigKey_Add(config, (char *)"SDL_Texture" , (ARC_ConfigKeyRead) ARC_SDL_Texture_Read, (ARC_ConfigKeyDelete) ARC_SDL_Texture_Delete); + ARC_ConfigKey_Add(config, (char *)"ARC_Spritesheet", (ARC_ConfigKeyRead) ARC_Spritesheet_Read, (ARC_ConfigKeyDelete) ARC_Spritesheet_Delete); + ARC_ConfigKey_Add(config, (char *)"ARC_Sprite" , (ARC_ConfigKeyRead) ARC_Sprite_Read , (ARC_ConfigKeyDelete) ARC_Sprite_Delete ); + return 0; +} + +int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){ + IMG_Init(IMG_INIT_PNG); + SDL_Surface *surface = IMG_Load(path); + if(!surface){ + printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError()); + return 1; // GE_SDL_ERRNO_ + } + + *texture = SDL_CreateTextureFromSurface(global_renderer, surface); + + SDL_FreeSurface(surface); + IMG_Quit(); + + return 0; +} + +int32_t ARC_SDL_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; + + uint64_t split; + *value = malloc(sizeof(SDL_Rect)); + + //x + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + ARC_StringSubstr temp = { subdata->index, split }; + ((SDL_Rect *) *value)->x = (int)ARC_String_ToUint64_t(data, &temp); + + //y + temp.index = subdata->index + split + 1; + err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + temp.length = split; + ((SDL_Rect *) *value)->y = (int)ARC_String_ToUint64_t(data, &temp); + + //w + temp.index = temp.index + split + 1; + err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + temp.length = split; + ((SDL_Rect *) *value)->w = (int)ARC_String_ToUint64_t(data, &temp); + + //hhttps://w2g.tv/8r0knvefgpciytccsw + temp = (ARC_StringSubstr){ temp.index + split + 1, subdata->length - split - 1 }; + ((SDL_Rect *) *value)->h = (int)ARC_String_ToUint64_t(data, &temp); + + SDL_Rect *ntemp = ((SDL_Rect *) *value); + return 0; +} + +int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + ARC_StringSubstr_StripEnds((char *)data, (char *)"\"", subdata); + + char path[subdata->length + 1]; + strncpy(path, data + subdata->index, subdata->length); + path[subdata->length] = 0; + + return ARC_SDL_Texture_Load(path, (SDL_Texture **)value); +} + +int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{'){ + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata); + if(!texture && data[subdata->index] != '"'){ return ARC_ERRNO_DATA; } + + if(!texture){ + int32_t err = ARC_SDL_Texture_Read(config, data, subdata, (void **)&texture); + if(err){ return ARC_ERRNO_DATA; } + } + + *value = malloc(sizeof(ARC_Spritesheet)); + ((ARC_Spritesheet *) *value)->texture = texture; + ((ARC_Spritesheet *) *value)->size = NULL; + return 0; + } + + if(data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; //remove the starting { and ending } + + //Texture + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!texture && data[temp.index] != '"'){ return ARC_ERRNO_DATA; } + + if(!texture){ + err = ARC_SDL_Texture_Read(config, data, &temp, (void **)&texture); + if(err){ return ARC_ERRNO_DATA; } + } + + //uint32_t size + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!size){ + ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&size); + if(err){ return ARC_ERRNO_DATA; } + } + + *value = malloc(sizeof(ARC_Spritesheet)); + ((ARC_Spritesheet *) *value)->texture = texture; + ((ARC_Spritesheet *) *value)->size = size; + + return 0; +} + +int32_t ARC_Sprite_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; //remove the starting { and ending } + + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + //spritesheet + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp); + + if(!spritesheet){ + err = ARC_Spritesheet_Read(config, data, &temp, (void **)&spritesheet); + if(err){ return ARC_ERRNO_DATA; } + } + + //bounds + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Rect *bounds = (SDL_Rect *)ARC_Config_GetReference(config, (char *)data, &temp); + + if(!bounds){ + ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&bounds); + if(err){ return ARC_ERRNO_DATA; } + } + + *value = malloc(sizeof(ARC_Sprite)); + ((ARC_Sprite *) *value)->spritesheet = spritesheet; + ((ARC_Sprite *) *value)->bounds = bounds; + + return 0; +} + +int32_t ARC_SDL_Rect_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + if((SDL_Rect *)value){ free((SDL_Rect *)value); } + return 0; +} + +int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + //if((SDL_Texture *) value){ SDL_DestroyTexture((SDL_Texture *) value); } + return 0; +} + +int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + ARC_Spritesheet *spritesheet = (ARC_Spritesheet *) value; + if(!data){ //there is no data, kill everything, most likely was called by a data type being destroyed + free(spritesheet); + return 0; + } + + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{'){ + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata); + if(!texture){ ARC_SDL_Texture_Delete(config, data, subdata, (void *)spritesheet->texture); } + + free(spritesheet); + return 0; + } + + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!texture){ ARC_SDL_Texture_Delete(config, data, &temp, (void *)spritesheet->texture); } + + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!size){ ARC_ConfigKey_Delete_Uint64_t(config, data, &temp, (void *)spritesheet->size); } + + free(spritesheet); + return 0; +} + +int32_t ARC_Sprite_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + ARC_Sprite *sprite = (ARC_Sprite *) value; + if(!data){ + free(sprite); + return 0; + } + + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; //remove the starting { and ending } + + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + //spritesheet + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!spritesheet){ ARC_Spritesheet_Delete(config, data, &temp, (void *)sprite->spritesheet); } + + //bounds + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Rect *bounds = (SDL_Rect *)ARC_Config_GetReference(config, (char *)data, &temp); + + if(!bounds){ ARC_SDL_Rect_Delete(config, data, &temp, (void *)sprite->bounds); } + + free(sprite); + return 0; +} From c5bef3bd1646efe60a0a923fe31fcf07215161bc Mon Sep 17 00:00:00 2001 From: herbglitch Date: Mon, 7 Nov 2022 02:23:53 -0700 Subject: [PATCH 3/5] config working, commented out the line throwing error for closing window. will fix soon --- include/arc/engine/engine.h | 2 + include/arc/graphics/config.h | 6 +- src/engine/engine.c | 10 +- src/graphics/sdl/temp.c | 266 ---------------------------------- src/std/handler.c | 2 +- 5 files changed, 12 insertions(+), 274 deletions(-) delete mode 100644 src/graphics/sdl/temp.c diff --git a/include/arc/engine/engine.h b/include/arc/engine/engine.h index 81a4c93..0da5f25 100644 --- a/include/arc/engine/engine.h +++ b/include/arc/engine/engine.h @@ -13,6 +13,8 @@ typedef struct ARC_EngineData { ARC_Window *window; ARC_Renderer *renderer; ARC_Handler *state; + + double dt; } ARC_EngineData; //NOTE: most work below is temp, and will change once I figure out a better way to write this header diff --git a/include/arc/graphics/config.h b/include/arc/graphics/config.h index bdda530..9b9e021 100644 --- a/include/arc/graphics/config.h +++ b/include/arc/graphics/config.h @@ -4,9 +4,11 @@ #ifdef __cplusplus extern "C" { #endif + +#include "arc/std/config.h" +#include "arc/graphics/renderer.h" -// ARC_Config_Create(); -// ARC_Config_Destroy(); +void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer); #ifdef __cplusplus } diff --git a/src/engine/engine.c b/src/engine/engine.c index 390857e..767963a 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -29,7 +29,7 @@ void ARC_EngineData_Create(ARC_EngineData **data){ return; } - windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, 0 }; + windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 2560, 1440, 0 }; #endif // ARC_SDL ARC_Window_Create(&((*data)->window), &windowInfo); @@ -59,11 +59,11 @@ void ARC_Engine_Run(ARC_EngineData *data){ #endif // ARC_SDL while(1){ - // currentTime = SDL_GetTicks(); - // data->dt = currentTime - lastTime; - // lastTime = currentTime; - #ifdef ARC_SDL + currentTime = SDL_GetTicks(); + data->dt = currentTime - lastTime; + lastTime = currentTime; + while(SDL_PollEvent(&event)){ if(event.type == SDL_QUIT){ return; } if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE){ return; } diff --git a/src/graphics/sdl/temp.c b/src/graphics/sdl/temp.c deleted file mode 100644 index 3d5a6ef..0000000 --- a/src/graphics/sdl/temp.c +++ /dev/null @@ -1,266 +0,0 @@ -#include "types.h" -#include -#include -#include -#include - -#define ARC_DEFAULT_CONFIG -#include - -SDL_Renderer *global_renderer; - -int32_t ARC_SDL_Rect_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); -int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); -int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); -int32_t ARC_Sprite_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); - -int32_t ARC_SDL_Rect_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); -int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); -int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); -int32_t ARC_Sprite_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); - -int32_t ARC_Types_Init(ARC_Config *config, SDL_Renderer *renderer){ - global_renderer = renderer; - ARC_ConfigKey_Add(config, (char *)"SDL_Rect" , (ARC_ConfigKeyRead) ARC_SDL_Rect_Read , (ARC_ConfigKeyDelete) ARC_SDL_Rect_Delete ); - ARC_ConfigKey_Add(config, (char *)"SDL_Texture" , (ARC_ConfigKeyRead) ARC_SDL_Texture_Read, (ARC_ConfigKeyDelete) ARC_SDL_Texture_Delete); - ARC_ConfigKey_Add(config, (char *)"ARC_Spritesheet", (ARC_ConfigKeyRead) ARC_Spritesheet_Read, (ARC_ConfigKeyDelete) ARC_Spritesheet_Delete); - ARC_ConfigKey_Add(config, (char *)"ARC_Sprite" , (ARC_ConfigKeyRead) ARC_Sprite_Read , (ARC_ConfigKeyDelete) ARC_Sprite_Delete ); - return 0; -} - -int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){ - IMG_Init(IMG_INIT_PNG); - SDL_Surface *surface = IMG_Load(path); - if(!surface){ - printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError()); - return 1; // GE_SDL_ERRNO_ - } - - *texture = SDL_CreateTextureFromSurface(global_renderer, surface); - - SDL_FreeSurface(surface); - IMG_Quit(); - - return 0; -} - -int32_t ARC_SDL_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ - ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); - if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } - subdata->index++; - subdata->length -= 2; - - uint64_t split; - *value = malloc(sizeof(SDL_Rect)); - - //x - int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); - if(err){ return err; } - if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } - ARC_StringSubstr temp = { subdata->index, split }; - ((SDL_Rect *) *value)->x = (int)ARC_String_ToUint64_t(data, &temp); - - //y - temp.index = subdata->index + split + 1; - err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split); - if(err){ return err; } - if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } - temp.length = split; - ((SDL_Rect *) *value)->y = (int)ARC_String_ToUint64_t(data, &temp); - - //w - temp.index = temp.index + split + 1; - err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split); - if(err){ return err; } - if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } - temp.length = split; - ((SDL_Rect *) *value)->w = (int)ARC_String_ToUint64_t(data, &temp); - - //hhttps://w2g.tv/8r0knvefgpciytccsw - temp = (ARC_StringSubstr){ temp.index + split + 1, subdata->length - split - 1 }; - ((SDL_Rect *) *value)->h = (int)ARC_String_ToUint64_t(data, &temp); - - SDL_Rect *ntemp = ((SDL_Rect *) *value); - return 0; -} - -int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ - ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); - ARC_StringSubstr_StripEnds((char *)data, (char *)"\"", subdata); - - char path[subdata->length + 1]; - strncpy(path, data + subdata->index, subdata->length); - path[subdata->length] = 0; - - return ARC_SDL_Texture_Load(path, (SDL_Texture **)value); -} - -int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ - ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); - if(data[subdata->index] != '{'){ - SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata); - if(!texture && data[subdata->index] != '"'){ return ARC_ERRNO_DATA; } - - if(!texture){ - int32_t err = ARC_SDL_Texture_Read(config, data, subdata, (void **)&texture); - if(err){ return ARC_ERRNO_DATA; } - } - - *value = malloc(sizeof(ARC_Spritesheet)); - ((ARC_Spritesheet *) *value)->texture = texture; - ((ARC_Spritesheet *) *value)->size = NULL; - return 0; - } - - if(data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } - subdata->index++; - subdata->length -= 2; //remove the starting { and ending } - - //Texture - uint64_t split; - int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); - if(err){ return err; } - if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } - - ARC_StringSubstr temp = { subdata->index, split }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp); - if(!texture && data[temp.index] != '"'){ return ARC_ERRNO_DATA; } - - if(!texture){ - err = ARC_SDL_Texture_Read(config, data, &temp, (void **)&texture); - if(err){ return ARC_ERRNO_DATA; } - } - - //uint32_t size - temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp); - if(!size){ - ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&size); - if(err){ return ARC_ERRNO_DATA; } - } - - *value = malloc(sizeof(ARC_Spritesheet)); - ((ARC_Spritesheet *) *value)->texture = texture; - ((ARC_Spritesheet *) *value)->size = size; - - return 0; -} - -int32_t ARC_Sprite_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ - ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); - if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } - subdata->index++; - subdata->length -= 2; //remove the starting { and ending } - - uint64_t split; - int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); - if(err){ return err; } - if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } - - //spritesheet - ARC_StringSubstr temp = { subdata->index, split }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp); - - if(!spritesheet){ - err = ARC_Spritesheet_Read(config, data, &temp, (void **)&spritesheet); - if(err){ return ARC_ERRNO_DATA; } - } - - //bounds - temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - SDL_Rect *bounds = (SDL_Rect *)ARC_Config_GetReference(config, (char *)data, &temp); - - if(!bounds){ - ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&bounds); - if(err){ return ARC_ERRNO_DATA; } - } - - *value = malloc(sizeof(ARC_Sprite)); - ((ARC_Sprite *) *value)->spritesheet = spritesheet; - ((ARC_Sprite *) *value)->bounds = bounds; - - return 0; -} - -int32_t ARC_SDL_Rect_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ - if((SDL_Rect *)value){ free((SDL_Rect *)value); } - return 0; -} - -int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ - //if((SDL_Texture *) value){ SDL_DestroyTexture((SDL_Texture *) value); } - return 0; -} - -int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ - ARC_Spritesheet *spritesheet = (ARC_Spritesheet *) value; - if(!data){ //there is no data, kill everything, most likely was called by a data type being destroyed - free(spritesheet); - return 0; - } - - ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); - if(data[subdata->index] != '{'){ - SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata); - if(!texture){ ARC_SDL_Texture_Delete(config, data, subdata, (void *)spritesheet->texture); } - - free(spritesheet); - return 0; - } - - uint64_t split; - int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); - if(err){ return err; } - if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } - - ARC_StringSubstr temp = { subdata->index, split }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp); - if(!texture){ ARC_SDL_Texture_Delete(config, data, &temp, (void *)spritesheet->texture); } - - temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp); - if(!size){ ARC_ConfigKey_Delete_Uint64_t(config, data, &temp, (void *)spritesheet->size); } - - free(spritesheet); - return 0; -} - -int32_t ARC_Sprite_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ - ARC_Sprite *sprite = (ARC_Sprite *) value; - if(!data){ - free(sprite); - return 0; - } - - ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); - if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } - subdata->index++; - subdata->length -= 2; //remove the starting { and ending } - - uint64_t split; - int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); - if(err){ return err; } - if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } - - //spritesheet - ARC_StringSubstr temp = { subdata->index, split }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp); - if(!spritesheet){ ARC_Spritesheet_Delete(config, data, &temp, (void *)sprite->spritesheet); } - - //bounds - temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; - ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); - SDL_Rect *bounds = (SDL_Rect *)ARC_Config_GetReference(config, (char *)data, &temp); - - if(!bounds){ ARC_SDL_Rect_Delete(config, data, &temp, (void *)sprite->bounds); } - - free(sprite); - return 0; -} diff --git a/src/std/handler.c b/src/std/handler.c index 876f62c..2ece4b5 100644 --- a/src/std/handler.c +++ b/src/std/handler.c @@ -32,7 +32,7 @@ void ARC_Handler_Add(ARC_Handler *handler, void *data){ int8_t ARC_Handler_RemoveCompareFn(void *a, void *b){ return a == b; } void ARC_Handler_Remove(ARC_Handler *handler, void *data){ - ARC_Vector_Add(handler->trash, data); + // ARC_Vector_Add(handler->trash, data); ARC_Vector_Remove(handler->data, data, ARC_Handler_RemoveCompareFn); } From 7ceb7695c4378cf72b02fe82731dfd86cc31e418 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Mon, 7 Nov 2022 02:24:00 -0700 Subject: [PATCH 4/5] config working, commented out the line throwing error for closing window. will fix soon --- src/graphics/sdl/config.c | 274 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 src/graphics/sdl/config.c diff --git a/src/graphics/sdl/config.c b/src/graphics/sdl/config.c new file mode 100644 index 0000000..a90142e --- /dev/null +++ b/src/graphics/sdl/config.c @@ -0,0 +1,274 @@ +#ifdef ARC_SDL +#include "arc/graphics/config.h" + +#include +#include +#include "arc/std/string.h" +#include "arc/std/errno.h" +#include "arc/graphics/sdl/renderer.h" +#include "arc/graphics/sprite.h" +#include "arc/graphics/sdl/sprite.h" +#include "arc/graphics/spritesheet.h" +#include "arc/graphics/sdl/spritesheet.h" + +// #define ARC_DEFAULT_CONFIG +#include "arc/std/defaults/config.h" + +SDL_Renderer *global_renderer; + +int32_t ARC_SDL_Rect_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); +int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); +int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); +int32_t ARC_Sprite_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value); + +int32_t ARC_SDL_Rect_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); +int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); +int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); +int32_t ARC_Sprite_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value); + +void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){ + global_renderer = renderer->renderer; + ARC_ConfigKey_Add(config, (char *)"SDL_Rect" , (ARC_ConfigKeyRead) ARC_SDL_Rect_Read , (ARC_ConfigKeyDelete) ARC_SDL_Rect_Delete ); + ARC_ConfigKey_Add(config, (char *)"SDL_Texture" , (ARC_ConfigKeyRead) ARC_SDL_Texture_Read, (ARC_ConfigKeyDelete) ARC_SDL_Texture_Delete); + ARC_ConfigKey_Add(config, (char *)"ARC_Spritesheet", (ARC_ConfigKeyRead) ARC_Spritesheet_Read, (ARC_ConfigKeyDelete) ARC_Spritesheet_Delete); + ARC_ConfigKey_Add(config, (char *)"ARC_Sprite" , (ARC_ConfigKeyRead) ARC_Sprite_Read , (ARC_ConfigKeyDelete) ARC_Sprite_Delete ); +} + +int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){ + IMG_Init(IMG_INIT_PNG); + SDL_Surface *surface = IMG_Load(path); + if(!surface){ + printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError()); + return 1; // GE_SDL_ERRNO_ + } + + *texture = SDL_CreateTextureFromSurface(global_renderer, surface); + + SDL_FreeSurface(surface); + IMG_Quit(); + + return 0; +} + +int32_t ARC_SDL_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; + + uint64_t split; + *value = malloc(sizeof(SDL_Rect)); + + //x + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + ARC_StringSubstr temp = { subdata->index, split }; + ((SDL_Rect *) *value)->x = (int)ARC_String_ToUint64_t(data, &temp); + + //y + temp.index = subdata->index + split + 1; + err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + temp.length = split; + ((SDL_Rect *) *value)->y = (int)ARC_String_ToUint64_t(data, &temp); + + //w + temp.index = temp.index + split + 1; + err = ARC_String_Find(((char *)data) + temp.index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + temp.length = split; + ((SDL_Rect *) *value)->w = (int)ARC_String_ToUint64_t(data, &temp); + + //hhttps://w2g.tv/8r0knvefgpciytccsw + temp = (ARC_StringSubstr){ temp.index + split + 1, subdata->length - split - 1 }; + ((SDL_Rect *) *value)->h = (int)ARC_String_ToUint64_t(data, &temp); + + SDL_Rect *ntemp = ((SDL_Rect *) *value); + return 0; +} + +int32_t ARC_SDL_Texture_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + ARC_StringSubstr_StripEnds((char *)data, (char *)"\"", subdata); + + char path[subdata->length + 1]; + strncpy(path, data + subdata->index, subdata->length); + path[subdata->length] = 0; + + return ARC_SDL_Texture_Load(path, (SDL_Texture **)value); +} + +int32_t ARC_Spritesheet_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{'){ + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata); + if(!texture && data[subdata->index] != '"'){ return ARC_ERRNO_DATA; } + + if(!texture){ + int32_t err = ARC_SDL_Texture_Read(config, data, subdata, (void **)&texture); + if(err){ return ARC_ERRNO_DATA; } + } + + *value = malloc(sizeof(ARC_Spritesheet)); + ((ARC_Spritesheet *) *value)->texture = texture; + ((ARC_Spritesheet *) *value)->size = NULL; + return 0; + } + + if(data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; //remove the starting { and ending } + + //Texture + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!texture && data[temp.index] != '"'){ return ARC_ERRNO_DATA; } + + if(!texture){ + err = ARC_SDL_Texture_Read(config, data, &temp, (void **)&texture); + if(err){ return ARC_ERRNO_DATA; } + } + + //uint32_t size + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!size){ + ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&size); + if(err){ return ARC_ERRNO_DATA; } + } + + *value = malloc(sizeof(ARC_Spritesheet)); + ((ARC_Spritesheet *) *value)->texture = texture; + ((ARC_Spritesheet *) *value)->size = size; + + return 0; +} + +int32_t ARC_Sprite_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){ + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; //remove the starting { and ending } + + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + //spritesheet + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp); + + if(!spritesheet){ + err = ARC_Spritesheet_Read(config, data, &temp, (void **)&spritesheet); + if(err){ return ARC_ERRNO_DATA; } + } + + //bounds + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Rect *bounds = (SDL_Rect *)ARC_Config_GetReference(config, (char *)data, &temp); + + if(!bounds){ + ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&bounds); + if(err){ return ARC_ERRNO_DATA; } + } + + *value = malloc(sizeof(ARC_Sprite)); + ((ARC_Sprite *) *value)->spritesheet = spritesheet; + ((ARC_Sprite *) *value)->bounds = bounds; + + return 0; +} + +int32_t ARC_SDL_Rect_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + if((SDL_Rect *)value){ free((SDL_Rect *)value); } + return 0; +} + +int32_t ARC_SDL_Texture_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + //if((SDL_Texture *) value){ SDL_DestroyTexture((SDL_Texture *) value); } + return 0; +} + +int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + ARC_Spritesheet *spritesheet = (ARC_Spritesheet *) value; + if(!data){ //there is no data, kill everything, most likely was called by a data type being destroyed + free(spritesheet); + return 0; + } + + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{'){ + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, subdata); + if(!texture){ ARC_SDL_Texture_Delete(config, data, subdata, (void *)spritesheet->texture); } + + free(spritesheet); + return 0; + } + + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Texture *texture = (SDL_Texture *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!texture){ ARC_SDL_Texture_Delete(config, data, &temp, (void *)spritesheet->texture); } + + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + uint32_t *size = (uint32_t *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!size){ ARC_ConfigKey_Delete_Uint64_t(config, data, &temp, (void *)spritesheet->size); } + + free(spritesheet); + return 0; +} + +int32_t ARC_Sprite_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){ + ARC_Sprite *sprite = (ARC_Sprite *) value; + if(!data){ + free(sprite); + return 0; + } + + ARC_StringSubstr_StripWhitespaceEnds((char *)data, subdata); + if(data[subdata->index] != '{' || data[subdata->index + subdata->length - 1] != '}'){ return ARC_ERRNO_DATA; } + subdata->index++; + subdata->length -= 2; //remove the starting { and ending } + + uint64_t split; + int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split); + if(err){ return err; } + if(split == ~((uint64_t)0) || split > subdata->length){ return ARC_ERRNO_DATA; } + + //spritesheet + ARC_StringSubstr temp = { subdata->index, split }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + ARC_Spritesheet *spritesheet = (ARC_Spritesheet *)ARC_Config_GetReference(config, (char *)data, &temp); + if(!spritesheet){ ARC_Spritesheet_Delete(config, data, &temp, (void *)sprite->spritesheet); } + + //bounds + temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 }; + ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp); + SDL_Rect *bounds = (SDL_Rect *)ARC_Config_GetReference(config, (char *)data, &temp); + + if(!bounds){ ARC_SDL_Rect_Delete(config, data, &temp, (void *)sprite->bounds); } + + free(sprite); + return 0; +} + +#endif //ARC_SDL \ No newline at end of file From bd06213ff4be69fd5a36b9d863371c728d2cbc42 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Mon, 7 Nov 2022 21:45:43 -0700 Subject: [PATCH 5/5] res change --- src/engine/engine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/engine.c b/src/engine/engine.c index 767963a..35180c9 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -29,7 +29,7 @@ void ARC_EngineData_Create(ARC_EngineData **data){ return; } - windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 2560, 1440, 0 }; + windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 720, 480, 0 }; #endif // ARC_SDL ARC_Window_Create(&((*data)->window), &windowInfo);