This commit is contained in:
herbglitch 2025-06-21 18:27:40 -06:00
commit 788147b8f2
16 changed files with 171 additions and 56 deletions

View file

@ -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
*

View file

@ -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_
#endif //ARC_STD_STRING_H_

View file

@ -25,6 +25,8 @@ typedef struct ARC_DCircle {
double r;
} ARC_DCircle;
void TEMP_Circle_Placeholder(void);
#ifdef __cplusplus
}
#endif

View file

@ -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

View file

@ -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
*

View file

@ -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);

View file

@ -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;

View file

@ -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){

View file

@ -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){

View file

@ -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 <SDL3/SDL.h>
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_

View file

@ -0,0 +1,4 @@
#include "arc/math/circle.h"
void TEMP_Circle_Placeholder(void){
}

View file

@ -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

View file

@ -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
};
}
}
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
};
}

View file

@ -1,9 +1,6 @@
#include "arc/math/rectangle.h"
#include "arc/std/bool.h"
//VERY TEMP
// #include <SDL.h>
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,

View file

@ -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);
}

View file

@ -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){