diff --git a/include/arc/graphics/renderer.h b/include/arc/graphics/renderer.h index c7b6f21..0d7e925 100644 --- a/include/arc/graphics/renderer.h +++ b/include/arc/graphics/renderer.h @@ -62,6 +62,21 @@ void ARC_Renderer_InitBuffer(ARC_Renderer *renderer, uint32_t zIndex); */ void ARC_Renderer_RemoveBuffer(ARC_Renderer *renderer, uint32_t zIndex); +/** + * @brief + * + * @param renderer + * @param zIndex +*/ +void ARC_Renderer_RenderBuffer(ARC_Renderer *renderer, uint32_t zIndex); + +/** + * @brief + * + * @param renderer +*/ +void ARC_Renderer_RenderBuffers(ARC_Renderer *renderer); + /** * @brief * diff --git a/include/arc/graphics/text.h b/include/arc/graphics/text.h index 3838fd7..9f6bcd2 100644 --- a/include/arc/graphics/text.h +++ b/include/arc/graphics/text.h @@ -9,22 +9,47 @@ extern "C" { #include "arc/graphics/color.h" #include "arc/graphics/renderer.h" #include "arc/math/point.h" +#include "arc/math/rectangle.h" #include "arc/std/string.h" -typedef struct ARC_Text ARC_Text; +typedef struct ARC_Text { + ARC_String *name; + int32_t fontSize; + ARC_FRect bounds; + + ARC_Color color; + + void *backendData; +} ARC_Text; + +/** + * @brief +*/ void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color); -void ARC_Text_Destroy(ARC_Text *font); +/** + * @brief +*/ +void ARC_Text_Destroy(ARC_Text *text); +/** + * @brief +*/ void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *string); +/** + * @brief +*/ void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer); +/** + * @brief +*/ void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos); #ifdef __cplusplus } #endif -#endif //ARC_STD_STRING_H_ \ No newline at end of file +#endif //ARC_STD_STRING_H_ diff --git a/include/arc/math/circle.h b/include/arc/math/circle.h index 60d9acb..b93f406 100644 --- a/include/arc/math/circle.h +++ b/include/arc/math/circle.h @@ -25,6 +25,8 @@ typedef struct ARC_DCircle { double r; } ARC_DCircle; +void TEMP_Circle_Placeholder(void); + #ifdef __cplusplus } #endif diff --git a/include/arc/math/point.h b/include/arc/math/point.h index 2af564b..8194524 100644 --- a/include/arc/math/point.h +++ b/include/arc/math/point.h @@ -27,8 +27,27 @@ typedef struct ARC_DPoint { double y; } ARC_DPoint; +typedef struct ARC_Rect ARC_Rect; +typedef struct ARC_FRect ARC_FRect; + ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t); +/** + * @brief centers point on given bounds + * + * @param point ARC_Point to be centered + * @param bounds ARC_Rect area to center point on + */ +void ARC_Point_CenterOn(ARC_Point *point, ARC_Rect bounds); + +/** + * @brief centers fpoint on given bounds + * + * @param point ARC_FPoint to be centered + * @param bounds ARC_FRect area to center point on + */ +void ARC_FPoint_CenterOn(ARC_FPoint *point, ARC_FRect bounds); + #ifdef __cplusplus } #endif diff --git a/include/arc/math/rectangle.h b/include/arc/math/rectangle.h index 577bf16..05b4210 100644 --- a/include/arc/math/rectangle.h +++ b/include/arc/math/rectangle.h @@ -47,6 +47,22 @@ void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect bounds); */ void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect bounds); +/** + * @brief centers rect on a given point + * + * @param rect ARC_Rect to be centered + * @param bounds ARC_Point point to center rect on + */ +void ARC_Rect_CenterOnPoint(ARC_Rect *rect, ARC_Point center); + +/** + * @brief centers rect on a given point + * + * @param rect ARC_FRect to be centered + * @param bounds ARC_FPoint point to center rect on + */ +void ARC_FRect_CenterOnPoint(ARC_FRect *rect, ARC_FPoint center); + /** * @brief casts Rect to FRect * diff --git a/packages/graphics/sdl3/config.c b/packages/graphics/sdl3/config.c index 7d6a911..082ac80 100644 --- a/packages/graphics/sdl3/config.c +++ b/packages/graphics/sdl3/config.c @@ -80,7 +80,7 @@ void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, AR //really large number in case a system has 64 digit pointer addresses char pointerCString[64]; - sprintf(pointerCString, "%p", sprite); + sprintf(pointerCString, "%p", (void *)sprite); /* ~ spritesheet ~ */ @@ -198,7 +198,7 @@ void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){ //really large number in case a system has 64 digit pointer addresses char pointerCString[64]; - sprintf(pointerCString, "%p", sprite); + sprintf(pointerCString, "%p", (void *)sprite); /* ~ spritesheet ~ */ //create a name based on the type and the sprite pointer to have a unique name for cleanup on remove @@ -206,8 +206,9 @@ void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){ ARC_String_CreateWithStrlen(&spritesheetName, pointerCString); ARC_String_AppendCStringWithStrlen(&spritesheetName, "ARC_Spritesheet"); + //TODO: FIX THIS //remove the spritesheet from the config (it won't error if it doesn't exist) - ARC_Config_RemoveWithCStr(config, spritesheetName->data, ARC_False); + //ARC_Config_RemoveWithCStr(config, spritesheetName->data, ARC_False); /* ~ ARC_FRect Array ~ */ //create a name based on the type and the sprite pointer to have a unique name for cleanup on remove @@ -215,8 +216,9 @@ void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){ ARC_String_CreateWithStrlen(&boundsName, pointerCString); ARC_String_AppendCStringWithStrlen(&boundsName, "ARC_FRect"); + //TODO: FIX THIS //remove the ARC_FRect from the config (it won't error if it doesn't exist) - ARC_Config_RemoveWithCStr(config, boundsName->data, ARC_False); + //ARC_Config_RemoveWithCStr(config, boundsName->data, ARC_False); //cleanup ARC_String_Destroy(boundsName); diff --git a/packages/graphics/sdl3/renderer.c b/packages/graphics/sdl3/renderer.c index 01f7005..939b62e 100644 --- a/packages/graphics/sdl3/renderer.c +++ b/packages/graphics/sdl3/renderer.c @@ -35,7 +35,7 @@ void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData * if((*renderer)->renderer == NULL){ arc_errno = ARC_ERRNO_NULL; - ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("SDL_CreateRenderer(%p, NULL);", data->window); + ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("SDL_CreateRenderer(%p, NULL);", (void *)data->window); free(renderer); return; } @@ -62,6 +62,8 @@ void ARC_Renderer_Clear(ARC_Renderer *renderer){ SDL_SetRenderTarget(renderer->renderer, NULL); SDL_SetRenderDrawColor(renderer->renderer, renderer->clearColor.r, renderer->clearColor.g, renderer->clearColor.b, renderer->clearColor.a); SDL_RenderClear(renderer->renderer); + + ARC_Renderer_ClearBuffers(renderer); } void ARC_Renderer_Render(ARC_Renderer *renderer){ @@ -90,6 +92,20 @@ void ARC_Renderer_RemoveBuffer(ARC_Renderer *renderer, uint32_t zIndex){ ARC_Hashtable_Remove(renderer->buffers, &zIndex); } +void ARC_Renderer_RenderBuffer(ARC_Renderer *renderer, uint32_t zIndex){ + SDL_Texture *buffer = (SDL_Texture *)ARC_Hashtable_Get(renderer->buffers, &zIndex); + + SDL_RenderTexture(renderer->renderer, buffer, NULL, NULL); +} + +//TODO: write this +void ARC_Renderer_BuffersHashtableRenderIteratorFn(void *key, void *value, void *userData){ +} + +//TODO: write this +void ARC_Renderer_RenderBuffers(ARC_Renderer *renderer){ +} + //private function to iterate and clear each available buffer void ARC_Renderer_BuffersHashtableClearIteratorFn(void *key, void *value, void *userData){ ARC_Renderer *renderer = (ARC_Renderer *)userData; diff --git a/packages/graphics/sdl3/sprite.c b/packages/graphics/sdl3/sprite.c index c07a4b7..6809bfd 100644 --- a/packages/graphics/sdl3/sprite.c +++ b/packages/graphics/sdl3/sprite.c @@ -42,7 +42,7 @@ void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite){ } void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_FRect renderBounds){ - SDL_RenderTexture(renderer->renderer, sprite->spritesheet->texture, (SDL_FRect *)(sprite->frames.data + sprite->frameIndex), (SDL_FRect *)&renderBounds); + SDL_RenderTexture(renderer->renderer, sprite->spritesheet->texture, ((SDL_FRect *)sprite->frames.data) + sprite->frameIndex, (SDL_FRect *)&renderBounds); } void ARC_Sprite_RenderAt(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_FPoint point, double scale){ diff --git a/packages/graphics/sdl3/text.c b/packages/graphics/sdl3/text.c index 39fdf16..50c2d76 100644 --- a/packages/graphics/sdl3/text.c +++ b/packages/graphics/sdl3/text.c @@ -1,6 +1,5 @@ #include "arc/graphics/text.h" -#include "text.h" #include "renderer.h" #include "arc/graphics/color.h" #include "arc/math/point.h" @@ -13,11 +12,13 @@ void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color color){ *text = (ARC_Text *)malloc(sizeof(ARC_Text)); + ARC_String_Copy(&(*text)->name, path); - (*text)->size = size; - (*text)->color = color; - (*text)->texture = NULL; - (*text)->bounds = (ARC_Rect){ 0, 0, 0, 0 }; + + (*text)->fontSize = size; + (*text)->bounds = (ARC_FRect){ 0.0f, 0.0f, 0.0f, 0.0f }; + (*text)->color = color; + (*text)->backendData = NULL; //TODO: fix this if(TTF_Init() == false) { @@ -27,15 +28,16 @@ void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color } void ARC_Text_Destroy(ARC_Text *font){ - if(font->texture != NULL){ - SDL_DestroyTexture(font->texture); + if(font->backendData != NULL){ + SDL_DestroyTexture((SDL_Texture *)font->backendData); } + ARC_String_Destroy(font->name); free(font); } void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *string){ - TTF_Font *ttfont = TTF_OpenFont(text->name->data, text->size); + TTF_Font *ttfont = TTF_OpenFont(text->name->data, text->fontSize); SDL_Color textColor = (SDL_Color){ text->color.r, text->color.g, text->color.b, text->color.a }; SDL_Surface *surface = TTF_RenderText_Blended(ttfont, string->data, 0, textColor); @@ -43,22 +45,22 @@ void ARC_Text_SetString(ARC_Text *text, ARC_Renderer *renderer, ARC_String *stri text->bounds.w = surface->w; text->bounds.h = surface->h; - if(text->texture){ - SDL_DestroyTexture(text->texture); + if(text->backendData != NULL){ + SDL_DestroyTexture((SDL_Texture *)text->backendData); } - text->texture = SDL_CreateTextureFromSurface(renderer->renderer, surface); + text->backendData = (void *)SDL_CreateTextureFromSurface(renderer->renderer, surface); SDL_DestroySurface(surface); TTF_CloseFont(ttfont); } void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){ - if(text->texture == NULL){ + if(text->backendData == NULL){ return; } SDL_FRect bounds = (SDL_FRect){ text->bounds.x, text->bounds.y, text->bounds.w, text->bounds.h }; - SDL_RenderTexture(renderer->renderer, text->texture, NULL, &bounds); + SDL_RenderTexture(renderer->renderer, (SDL_Texture *)(text->backendData), NULL, &bounds); } void ARC_Text_SetPos(ARC_Text *text, ARC_Point pos){ diff --git a/packages/graphics/sdl3/text.h b/packages/graphics/sdl3/text.h deleted file mode 100644 index 4c561ba..0000000 --- a/packages/graphics/sdl3/text.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ARC_SDL_TEXT_H_ -#define ARC_SDL_TEXT_H_ - -#include "arc/std/string.h" -#include "arc/graphics/color.h" -#include "arc/math/rectangle.h" - -#include - -typedef struct ARC_Text { - ARC_String *name; - int32_t size; - - ARC_Color color; - - SDL_Texture *texture; - ARC_Rect bounds; -} ARC_Text; - -#endif // !ARC_SDL_TEXT_H_ diff --git a/src/math/circle.c b/src/math/circle.c index e69de29..9a5e8d1 100644 --- a/src/math/circle.c +++ b/src/math/circle.c @@ -0,0 +1,4 @@ +#include "arc/math/circle.h" + +void TEMP_Circle_Placeholder(void){ +} diff --git a/src/math/config.c b/src/math/config.c index cec1f8f..6cfe34a 100644 --- a/src/math/config.c +++ b/src/math/config.c @@ -358,7 +358,10 @@ void ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC //copy the last value and free the temp value ARC_FRect *point = (ARC_FRect *)malloc(sizeof(ARC_FPoint)); - *point = (ARC_FRect){ pointX, pointY, pointW, *pointTemp }; + point->x = pointX; + point->y = pointY; + point->w = pointW; + point->h = *pointTemp; free(pointTemp); //set the type value diff --git a/src/math/point.c b/src/math/point.c index 7e1767c..042aff4 100644 --- a/src/math/point.c +++ b/src/math/point.c @@ -1,8 +1,26 @@ #include "arc/math/point.h" +#include "arc/math/rectangle.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 }; -} \ No newline at end of file +} + +void ARC_Point_CenterOn(ARC_Point *point, ARC_Rect bounds){ + *point = (ARC_Point){ + (bounds.w / 2) + bounds.x, + (bounds.h / 2) + bounds.y + }; +} + +void ARC_FPoint_CenterOn(ARC_FPoint *point, ARC_FRect bounds){ + *point = (ARC_FPoint){ + (bounds.w / 2.0f) + bounds.x, + (bounds.h / 2.0f) + bounds.y + }; +} + + diff --git a/src/math/rectangle.c b/src/math/rectangle.c index 994ce91..de2d90a 100644 --- a/src/math/rectangle.c +++ b/src/math/rectangle.c @@ -1,9 +1,6 @@ #include "arc/math/rectangle.h" #include "arc/std/bool.h" -//VERY TEMP -// #include - void ARC_Rect_CenterOn(ARC_Rect *rect, ARC_Rect bounds){ rect->x = (bounds.x + (bounds.w / 2)) - (rect->w / 2); rect->y = (bounds.y + (bounds.h / 2)) - (rect->h / 2); @@ -14,6 +11,16 @@ void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect bounds){ rect->y = (bounds.y + (bounds.h / 2.0f)) - (rect->h / 2.0f); } +void ARC_Rect_CenterOnPoint(ARC_Rect *rect, ARC_Point center){ + rect->x = center.x - (rect->w / 2); + rect->y = center.y - (rect->h / 2); +} + +void ARC_FRect_CenterOnPoint(ARC_FRect *rect, ARC_FPoint center){ + rect->x = center.x - (rect->w / 2.0f); + rect->y = center.y - (rect->h / 2.0f); +} + ARC_FRect ARC_Rect_CastToFRect(ARC_Rect rect){ return (ARC_FRect){ .x = (float)rect.x, diff --git a/src/std/config.c b/src/std/config.c index a8995e4..6e1d2e3 100644 --- a/src/std/config.c +++ b/src/std/config.c @@ -1428,7 +1428,8 @@ void ARC_ConfigType_DoubleDestroyFn(ARC_Config *config, void *type){ } void ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){ - if(parsedData->id != ARC_CONFIG_STRING){ + ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0); + if(childTagToken->id != ARC_CONFIG_STRING){ arc_errno = ARC_ERRNO_DATA; ARC_DEBUG_LOG_ERROR("ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), string was not passed in for ARC_String"); type = NULL; @@ -1436,7 +1437,8 @@ void ARC_ConfigType_StringCopyFn(void **type, ARC_ParserTagToken *parsedData, AR } //get the string chars between the quotes - ARC_ParserTagToken *stringCharsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 1); + ARC_ParserTagToken *stringCharsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 1); + ARC_String_Create((ARC_String **)type, NULL, 0); ARC_ParserData_HelperRecurseStringAdd((ARC_String **)type, stringCharsTagToken); } diff --git a/src/std/entity.c b/src/std/entity.c index 34975bf..2e89603 100644 --- a/src/std/entity.c +++ b/src/std/entity.c @@ -42,6 +42,10 @@ void ARC_EntitySystem_Create(ARC_EntitySystem **entitySystem){ //init an empty query (*entitySystem)->query = NULL; + + //add the first offset as 0 + uint32_t zero = 0; + ARC_VectorInline_Add(((*entitySystem)->offsetVector), (void *)&zero); } void ARC_EntitySystem_Destroy(ARC_EntitySystem *entitySystem){ @@ -76,10 +80,7 @@ uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint //get the total component size uint32_t offsetEndIndex = ARC_VectorInline_GetSize(entitySystem->offsetVector); - uint32_t totalSize = 0; - if(ARC_VectorInline_GetSize(entitySystem->offsetVector) != 0){ - totalSize = *(uint32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, offsetEndIndex - 1); - } + uint32_t totalSize = *(uint32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, offsetEndIndex - 1); //if the new component size would overflow, throw an error if(totalSize > (~(uint32_t)0) - componentSize){ @@ -88,16 +89,18 @@ uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint return ~(uint32_t)0; } + //add the component size to the total size for the next offset + totalSize += componentSize; + //add the component size to the total size and the offset vector array ARC_VectorInline_Add(entitySystem->offsetVector, &totalSize); ARC_VectorInline_Add(entitySystem->sizeVector , &componentSize); - totalSize += componentSize; //create the resized data vector that can now house the registered component ARC_VectorInline_Create(&(entitySystem->data), totalSize, NULL, NULL); //get the id (last index) in the offset vector - return ARC_VectorInline_GetSize(entitySystem->offsetVector) - 1; + return ARC_VectorInline_GetSize(entitySystem->sizeVector) - 1; } ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem){ @@ -169,7 +172,8 @@ ARC_Bool ARC_EntitySystem_HasComponent(ARC_EntitySystem *entitySystem, ARC_Entit void *ARC_EntitySystem_GetComponentData(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component){ //get the entity row, then offset that for the component to get the component data void *data = ARC_VectorInline_Get(entitySystem->data, (uint32_t)entity); - return data + *(int32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, (uint32_t)component); + int32_t temp = *(int32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, (uint32_t)component); + return data + temp; } ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, ARC_Array components){