still working on adding frames to config
This commit is contained in:
parent
3fa74e8f9e
commit
0591b6ca6e
10 changed files with 199 additions and 53 deletions
|
|
@ -10,25 +10,33 @@
|
|||
#include "arc/graphics/sdl/sprite.h"
|
||||
#include "arc/graphics/spritesheet.h"
|
||||
#include "arc/graphics/sdl/spritesheet.h"
|
||||
#include "arc/math/point.h"
|
||||
#include "arc/math/rectangle.h"
|
||||
|
||||
// #define ARC_DEFAULT_CONFIG
|
||||
#include "arc/std/defaults/config.h"
|
||||
|
||||
SDL_Renderer *global_renderer;
|
||||
|
||||
int32_t ARC_SDL_Rect_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
|
||||
int32_t ARC_Point_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
|
||||
int32_t ARC_Rect_Read (ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value);
|
||||
int32_t ARC_RectArray_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_Point_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
|
||||
int32_t ARC_Rect_Delete (ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value);
|
||||
int32_t ARC_RectArray_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 *)"ARC_Point" , (ARC_ConfigKeyRead) ARC_Point_Read , (ARC_ConfigKeyDelete) ARC_Point_Delete );
|
||||
ARC_ConfigKey_Add(config, (char *)"ARC_Rect" , (ARC_ConfigKeyRead) ARC_Rect_Read , (ARC_ConfigKeyDelete) ARC_Rect_Delete );
|
||||
ARC_ConfigKey_Add(config, (char *)"ARC_RectArray" , (ARC_ConfigKeyRead) ARC_RectArray_Read , (ARC_ConfigKeyDelete) ARC_RectArray_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 );
|
||||
|
|
@ -50,14 +58,37 @@ int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ARC_SDL_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *subdata, void **value){
|
||||
int32_t ARC_Point_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));
|
||||
*value = malloc(sizeof(ARC_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_Point *) *value)->x = (int)ARC_String_ToUint64_t(data, &temp);
|
||||
|
||||
//y
|
||||
temp = (ARC_StringSubstr){ temp.index + split + 1, subdata->length - split - 1 };
|
||||
((SDL_Point *) *value)->y = (int)ARC_String_ToUint64_t(data, &temp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ARC_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(ARC_Rect));
|
||||
|
||||
//x
|
||||
int32_t err = ARC_String_Find(((char *)data) + subdata->index, (char *)",", &split);
|
||||
|
|
@ -82,11 +113,59 @@ int32_t ARC_SDL_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr
|
|||
temp.length = split;
|
||||
((SDL_Rect *) *value)->w = (int)ARC_String_ToUint64_t(data, &temp);
|
||||
|
||||
//hhttps://w2g.tv/8r0knvefgpciytccsw
|
||||
//h
|
||||
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_RectArray_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 arraySize = 1;
|
||||
uint8_t encapsulated = 0;
|
||||
for(uint64_t i = subdata->index; i < subdata->index + subdata->length; i++){
|
||||
if(data[i] == '{'){
|
||||
encapsulated++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(data[i] == '}'){
|
||||
encapsulated--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!encapsulated && data[i] == ','){
|
||||
arraySize++;
|
||||
}
|
||||
}
|
||||
|
||||
*value = malloc(sizeof(ARC_Rect) * arraySize);
|
||||
ARC_StringSubstr temp = { subdata->index, subdata->index };
|
||||
arraySize = 0;
|
||||
encapsulated = 0;
|
||||
for(uint64_t i = subdata->index; i < subdata->index + subdata->length; i++){
|
||||
if(data[i] == '{'){
|
||||
encapsulated++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(data[i] == '}'){
|
||||
encapsulated--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!encapsulated && data[i] == ','){
|
||||
temp.length = i - temp.index - 1;
|
||||
ARC_Rect *tempRect = ((ARC_Rect *) *value) + arraySize;
|
||||
arraySize++;
|
||||
ARC_Rect_Read(config, data, &temp, (void **) &tempRect);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -178,22 +257,39 @@ int32_t ARC_Sprite_Read(ARC_Config* config, const char *data, ARC_StringSubstr *
|
|||
//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);
|
||||
ARC_Rect *bounds = (ARC_Rect *)ARC_Config_GetReference(config, (char *)data, &temp);
|
||||
|
||||
if(!bounds){
|
||||
ARC_ConfigKey_Read_Uint64_t(config, data, &temp, (void **)&bounds);
|
||||
err = ARC_Rect_Read(config, data, &temp, (void **)&bounds);
|
||||
if(err){ return ARC_ERRNO_DATA; }
|
||||
}
|
||||
|
||||
//scale bounds on spritesheet size
|
||||
if(spritesheet->size){
|
||||
bounds->x *= *spritesheet->size;
|
||||
bounds->y *= *spritesheet->size;
|
||||
bounds->w *= *spritesheet->size;
|
||||
bounds->h *= *spritesheet->size;
|
||||
}
|
||||
|
||||
*value = malloc(sizeof(ARC_Sprite));
|
||||
((ARC_Sprite *) *value)->spritesheet = spritesheet;
|
||||
((ARC_Sprite *) *value)->bounds = bounds;
|
||||
((ARC_Sprite *) *value)->frames = 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); }
|
||||
int32_t ARC_Point_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
|
||||
if((ARC_Point *)value){ free((ARC_Point *)value); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ARC_Rect_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
|
||||
if((ARC_Rect *)value){ free((ARC_Rect *)value); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ARC_RectArray_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +361,7 @@ int32_t ARC_Sprite_Delete(ARC_Config* config, const char* data, ARC_StringSubstr
|
|||
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); }
|
||||
if(!bounds){ ARC_Rect_Delete(config, data, &temp, (void *)sprite->frames); }
|
||||
|
||||
free(sprite);
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue