config setup
This commit is contained in:
parent
a70e2256e2
commit
cd5471c9c8
8 changed files with 124 additions and 27 deletions
|
|
@ -10,6 +10,7 @@ extern "C" {
|
|||
#include "arc/input/mouse.h"
|
||||
#include "arc/input/keyboard.h"
|
||||
#include "arc/std/handler.h"
|
||||
#include "arc/math/point.h"
|
||||
|
||||
typedef struct ARC_EngineData {
|
||||
ARC_Window *window;
|
||||
|
|
@ -20,6 +21,7 @@ typedef struct ARC_EngineData {
|
|||
|
||||
double dt;
|
||||
uint32_t running;
|
||||
ARC_Point windowSize;
|
||||
|
||||
ARC_Handler_CleanDataFn cleanfn;
|
||||
} ARC_EngineData;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ void ARC_Sprite_Destroy(ARC_Sprite *sprite);
|
|||
|
||||
void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds);
|
||||
|
||||
void ARC_Sprite_IterateFrame(ARC_Sprite *sprite);
|
||||
|
||||
ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -31,8 +31,10 @@ void ARC_EngineData_Create(ARC_EngineData **data){
|
|||
ARC_MouseInfo mouseInfo;
|
||||
ARC_KeyboardInfo keyboardInfo;
|
||||
|
||||
(*data)->windowSize = (ARC_Point){ 2560, 1440 };
|
||||
|
||||
#ifdef ARC_SDL
|
||||
windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 2560, 1440, 0 };
|
||||
windowInfo = (ARC_WindowInfo){ "title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (*data)->windowSize.x, (*data)->windowSize.y, 0 };
|
||||
#endif // ARC_SDL
|
||||
|
||||
ARC_Window_Create(&((*data)->window), &windowInfo);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@
|
|||
|
||||
SDL_Renderer *global_renderer;
|
||||
|
||||
typedef struct ARC_Array {
|
||||
uint32_t *size;
|
||||
void *data;
|
||||
} ARC_Array;
|
||||
|
||||
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);
|
||||
|
|
@ -95,7 +100,8 @@ int32_t ARC_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *su
|
|||
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);
|
||||
((ARC_Rect *) *value)->x = (int)ARC_String_ToUint64_t(data, &temp);
|
||||
int32_t ttt = ((ARC_Rect *) *value)->x;
|
||||
|
||||
//y
|
||||
temp.index = subdata->index + split + 1;
|
||||
|
|
@ -104,6 +110,7 @@ int32_t ARC_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *su
|
|||
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);
|
||||
ttt = ((ARC_Rect *) *value)->y;
|
||||
|
||||
//w
|
||||
temp.index = temp.index + split + 1;
|
||||
|
|
@ -112,10 +119,12 @@ int32_t ARC_Rect_Read(ARC_Config* config, const char *data, ARC_StringSubstr *su
|
|||
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);
|
||||
ttt = ((ARC_Rect *) *value)->w;
|
||||
|
||||
//h
|
||||
temp = (ARC_StringSubstr){ temp.index + split + 1, subdata->length - split - 1 };
|
||||
((SDL_Rect *) *value)->h = (int)ARC_String_ToUint64_t(data, &temp);
|
||||
ttt = ((ARC_Rect *) *value)->h;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -126,9 +135,9 @@ int32_t ARC_RectArray_Read(ARC_Config* config, const char *data, ARC_StringSubst
|
|||
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++){
|
||||
uint32_t arraySize = 1;
|
||||
int32_t encapsulated = 0;
|
||||
for(uint32_t i = subdata->index; i < subdata->index + subdata->length; i++){
|
||||
if(data[i] == '{'){
|
||||
encapsulated++;
|
||||
continue;
|
||||
|
|
@ -144,8 +153,18 @@ int32_t ARC_RectArray_Read(ARC_Config* config, const char *data, ARC_StringSubst
|
|||
}
|
||||
}
|
||||
|
||||
*value = malloc(sizeof(ARC_Rect) * arraySize);
|
||||
ARC_StringSubstr temp = { subdata->index, subdata->index };
|
||||
if(encapsulated){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_LOG(arc_errno, "in ARC_RectArray_Read(config, data, subdata, value); after looping encapsulated was %d", encapsulated);
|
||||
return arc_errno;
|
||||
}
|
||||
|
||||
*value = malloc(sizeof(ARC_Array));
|
||||
((ARC_Array *) *value)->data = malloc(sizeof(ARC_Rect) * arraySize);
|
||||
((ARC_Array *) *value)->size = malloc(sizeof(uint32_t));
|
||||
*((ARC_Array *) *value)->size = arraySize;
|
||||
|
||||
ARC_StringSubstr temp = { subdata->index, 0 };
|
||||
arraySize = 0;
|
||||
encapsulated = 0;
|
||||
for(uint64_t i = subdata->index; i < subdata->index + subdata->length; i++){
|
||||
|
|
@ -160,12 +179,48 @@ int32_t ARC_RectArray_Read(ARC_Config* config, const char *data, ARC_StringSubst
|
|||
}
|
||||
|
||||
if(!encapsulated && data[i] == ','){
|
||||
temp.length = i - temp.index - 1;
|
||||
ARC_Rect *tempRect = ((ARC_Rect *) *value) + arraySize;
|
||||
temp.length = i - temp.index;
|
||||
|
||||
ARC_Rect *tempRect = (ARC_Rect *)ARC_Config_GetReference(config, (char *)data, &temp);
|
||||
if(!tempRect){
|
||||
ARC_Rect_Read(config, data, &temp, (void **) &tempRect);
|
||||
if(arc_errno){
|
||||
return arc_errno;
|
||||
}
|
||||
}
|
||||
|
||||
((ARC_Rect *)((ARC_Array *) *value)->data)[arraySize] = *tempRect;
|
||||
|
||||
ARC_Rect_Delete(config, data, &temp, (void *)tempRect);
|
||||
if(arc_errno){
|
||||
return arc_errno;
|
||||
}
|
||||
|
||||
arraySize++;
|
||||
ARC_Rect_Read(config, data, &temp, (void **) &tempRect);
|
||||
temp = (ARC_StringSubstr){ i + 1, 0 };
|
||||
|
||||
if(arraySize == *((ARC_Array *) *value)->size){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
temp.length = (subdata->index + subdata->length) - temp.index;
|
||||
ARC_Rect *tempRect = (ARC_Rect *)ARC_Config_GetReference(config, (char *)data, &temp);
|
||||
if(!tempRect){
|
||||
int32_t ttt = ARC_Rect_Read(config, data, &temp, (void **) &tempRect);
|
||||
if(arc_errno){
|
||||
return arc_errno;
|
||||
}
|
||||
}
|
||||
|
||||
((ARC_Rect *)((ARC_Array *) *value)->data)[arraySize] = *tempRect;
|
||||
ARC_Rect ttt = ((ARC_Rect *)((ARC_Array *) *value)->data)[arraySize];
|
||||
|
||||
ARC_Rect_Delete(config, data, &temp, (void *)tempRect);
|
||||
if(arc_errno){
|
||||
return arc_errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -255,26 +310,42 @@ int32_t ARC_Sprite_Read(ARC_Config* config, const char *data, ARC_StringSubstr *
|
|||
}
|
||||
|
||||
//bounds
|
||||
uint8_t isRectArray = 0;
|
||||
temp = (ARC_StringSubstr){ subdata->index + split + 1, subdata->length - split - 1 };
|
||||
ARC_StringSubstr_StripWhitespaceEnds((char *)data, &temp);
|
||||
ARC_Rect *bounds = (ARC_Rect *)ARC_Config_GetReference(config, (char *)data, &temp);
|
||||
ARC_Array *bounds = (ARC_Array *)ARC_Config_GetReference(config, (char *)data, &temp);
|
||||
|
||||
if(!bounds){
|
||||
err = ARC_Rect_Read(config, data, &temp, (void **)&bounds);
|
||||
err = ARC_RectArray_Read(config, data, &temp, (void **)&bounds);
|
||||
if(err){ return ARC_ERRNO_DATA; }
|
||||
isRectArray = 1;
|
||||
}
|
||||
|
||||
//scale bounds on spritesheet size
|
||||
// TODO: possible bug for sheets that use the same bounds
|
||||
if(spritesheet->size){
|
||||
bounds->x *= *spritesheet->size;
|
||||
bounds->y *= *spritesheet->size;
|
||||
bounds->w *= *spritesheet->size;
|
||||
bounds->h *= *spritesheet->size;
|
||||
for(uint32_t i = 0; i < *bounds->size; i++){
|
||||
((ARC_Rect *)bounds->data)[i].x *= *spritesheet->size;
|
||||
((ARC_Rect *)bounds->data)[i].y *= *spritesheet->size;
|
||||
((ARC_Rect *)bounds->data)[i].w *= *spritesheet->size;
|
||||
((ARC_Rect *)bounds->data)[i].h *= *spritesheet->size;
|
||||
}
|
||||
}
|
||||
|
||||
*value = malloc(sizeof(ARC_Sprite));
|
||||
((ARC_Sprite *) *value)->spritesheet = spritesheet;
|
||||
((ARC_Sprite *) *value)->frames = bounds;
|
||||
((ARC_Sprite *) *value)->frameIndex = malloc(sizeof(uint32_t));
|
||||
|
||||
((ARC_Sprite *) *value)->spritesheet = spritesheet;
|
||||
((ARC_Sprite *) *value)->frames = bounds->data;
|
||||
((ARC_Sprite *) *value)->frameSize = bounds->size;
|
||||
*((ARC_Sprite *) *value)->frameIndex = 0;
|
||||
|
||||
ARC_Rect *ttt = (ARC_Rect *)bounds->data;
|
||||
ARC_Rect ttf = ttt[0];
|
||||
|
||||
if(isRectArray){
|
||||
free(bounds);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -290,6 +361,7 @@ int32_t ARC_Rect_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *
|
|||
}
|
||||
|
||||
int32_t ARC_RectArray_Delete(ARC_Config* config, const char* data, ARC_StringSubstr *subdata, void *value){
|
||||
if((ARC_Array *)value){ free((ARC_Array *)value); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -308,9 +380,14 @@ int32_t ARC_Spritesheet_Delete(ARC_Config* config, const char* data, ARC_StringS
|
|||
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); }
|
||||
if(!texture){
|
||||
ARC_SDL_Texture_Delete(config, data, subdata, (void *)spritesheet->texture);
|
||||
}
|
||||
|
||||
// if(spritesheet){
|
||||
// free(spritesheet);
|
||||
// }
|
||||
|
||||
free(spritesheet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -361,8 +438,12 @@ 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_Rect_Delete(config, data, &temp, (void *)sprite->frames); }
|
||||
if(!bounds){
|
||||
free(sprite->frames);
|
||||
free(sprite->frameSize);
|
||||
}
|
||||
|
||||
free(sprite->frameIndex);
|
||||
free(sprite);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#include "arc/graphics/sprite.h"
|
||||
#ifdef ARC_SDL
|
||||
#include "arc/graphics/sdl/sprite.h"
|
||||
#include "arc/graphics/sdl/spritesheet.h"
|
||||
#include "arc/graphics/sdl/renderer.h"
|
||||
#include "arc/math/rectangle.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Rect *frames){
|
||||
|
|
@ -17,7 +19,16 @@ void ARC_Sprite_Destroy(ARC_Sprite *sprite){
|
|||
}
|
||||
|
||||
void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_Rect *renderBounds){
|
||||
SDL_RenderCopy(renderer->renderer, sprite->spritesheet->texture, (SDL_Rect *)sprite->frames, (SDL_Rect *)renderBounds);
|
||||
ARC_Rect *temp = &sprite->frames[*sprite->frameIndex];
|
||||
SDL_RenderCopy(renderer->renderer, sprite->spritesheet->texture, (SDL_Rect *)&sprite->frames[*sprite->frameIndex], (SDL_Rect *)renderBounds);
|
||||
}
|
||||
|
||||
void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){
|
||||
++*sprite->frameIndex;
|
||||
|
||||
if(*sprite->frameIndex == *sprite->frameSize){
|
||||
*sprite->frameIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ARC_Rect *ARC_Sprite_GetBounds(ARC_Sprite *sprite){
|
||||
|
|
|
|||
|
|
@ -77,10 +77,10 @@ void ARC_Mouse_Update(ARC_Mouse *mouse){
|
|||
}
|
||||
}
|
||||
|
||||
if(*mouse->buttonsReleased){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_LOG(arc_errno, "in ARC_Mouse_Update mouse->buttonsReleased == %u, it needs to be 0\n", *(mouse->buttonsReleased));
|
||||
}
|
||||
// if(*mouse->buttonsReleased){
|
||||
// arc_errno = ARC_ERRNO_DATA;
|
||||
// ARC_DEBUG_LOG(arc_errno, "in ARC_Mouse_Update mouse->buttonsReleased == %u, it needs to be 0\n", *(mouse->buttonsReleased));
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,6 @@ int32_t ARC_Config_Get(ARC_Config *config, char *keyname, void **value){
|
|||
|
||||
int32_t ARC_Config_Remove(ARC_Config *config, const char *keyname, const char* data, ARC_StringSubstr *subdata){
|
||||
ARC_DeleteUserData deldata = { .config = config, .data = data, .subdata = subdata };
|
||||
printf("data: %s\n\n", data);
|
||||
return ARC_Hashtable_Remove(config->currgroup, (void *)keyname, strlen(keyname), ARC_ConfigGroupNode_Destroy, (void *)&deldata);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue