added FPoint and FRect to config, needs testing

This commit is contained in:
herbglitch 2025-03-25 19:19:47 -06:00
parent 8845cf78e0
commit 15ee2819b1
3 changed files with 212 additions and 6 deletions

View file

@ -26,6 +26,16 @@ void ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC
*/ */
void ARC_ConfigType_PointDestroyFn(ARC_Config *config, void *type); void ARC_ConfigType_PointDestroyFn(ARC_Config *config, void *type);
/**
* @brief
*/
void ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata);
/**
* @brief
*/
void ARC_ConfigType_FPointDestroyFn(ARC_Config *config, void *type);
/** /**
* @brief * @brief
*/ */
@ -36,6 +46,17 @@ void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
*/ */
void ARC_ConfigType_RectDestroyFn(ARC_Config *config, void *type); void ARC_ConfigType_RectDestroyFn(ARC_Config *config, void *type);
/**
* @brief
*/
void ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata);
/**
* @brief
*/
void ARC_ConfigType_FRectDestroyFn(ARC_Config *config, void *type);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -85,6 +85,8 @@ void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
} }
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0); ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
/* ~ spritesheet ~ */
//check if spritesheet exist //check if spritesheet exist
ARC_String *valueString; ARC_String *valueString;
ARC_String_Create(&valueString, NULL, 0); ARC_String_Create(&valueString, NULL, 0);
@ -108,9 +110,12 @@ void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
ARC_String_Destroy(spritesheetName); ARC_String_Destroy(spritesheetName);
} }
//cleanup
ARC_String_Destroy(valueString); ARC_String_Destroy(valueString);
valueString = NULL; valueString = NULL;
/* ~ bounds aka frames ~ */
//check if bounds exist //check if bounds exist
ARC_String_Create(&valueString, NULL, 0); ARC_String_Create(&valueString, NULL, 0);
ARC_ParserData_HelperRecurseStringAdd(&valueString, valueTagToken); ARC_ParserData_HelperRecurseStringAdd(&valueString, valueTagToken);
@ -121,6 +126,8 @@ void ARC_ConfigType_SpriteCopyFn(void **type, ARC_ParserTagToken *parsedData, AR
} }
ARC_String_Destroy(valueString); ARC_String_Destroy(valueString);
*type = sprite;
} }
void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){ void ARC_ConfigType_SpriteDestroyFn(ARC_Config *config, void *type){

View file

@ -1,16 +1,16 @@
#include "arc/math/config.h" #include "arc/math/config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "arc/std/array.h"
#include "arc/std/string.h"
#include "arc/std/errno.h" #include "arc/std/errno.h"
#include "arc/std/config.h" #include "arc/std/config.h"
#include "arc/math/point.h" #include "arc/math/point.h"
#include "arc/math/rectangle.h" #include "arc/math/rectangle.h"
void ARC_Config_InitMath(ARC_Config *config){ void ARC_Config_InitMath(ARC_Config *config){
ARC_Config_RegisterTypeWithCStr(config, "ARC_Point", (ARC_ConfigType){ ARC_ConfigType_PointCopyFn, ARC_ConfigType_PointDestroyFn, NULL }); ARC_Config_RegisterTypeWithCStr(config, "ARC_Point" , (ARC_ConfigType){ ARC_ConfigType_PointCopyFn , ARC_ConfigType_PointDestroyFn , NULL });
ARC_Config_RegisterTypeWithCStr(config, "ARC_Rect" , (ARC_ConfigType){ ARC_ConfigType_RectCopyFn , ARC_ConfigType_RectDestroyFn , NULL }); ARC_Config_RegisterTypeWithCStr(config, "ARC_FPoint", (ARC_ConfigType){ ARC_ConfigType_FPointCopyFn, ARC_ConfigType_FPointDestroyFn, NULL });
ARC_Config_RegisterTypeWithCStr(config, "ARC_Rect" , (ARC_ConfigType){ ARC_ConfigType_RectCopyFn , ARC_ConfigType_RectDestroyFn , NULL });
ARC_Config_RegisterTypeWithCStr(config, "ARC_FRect" , (ARC_ConfigType){ ARC_ConfigType_FRectCopyFn , ARC_ConfigType_FRectDestroyFn , NULL });
} }
void ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){ void ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
@ -79,11 +79,77 @@ void ARC_ConfigType_PointDestroyFn(ARC_Config *config, void *type){
free((ARC_Point *)type); free((ARC_Point *)type);
} }
void ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
if(childTagToken->id != ARC_CONFIG_NESTED_VALUE){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_FPoint");
type = NULL;
return;
}
//get the valueArgs
ARC_ParserTagToken *valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 2);
//if there is only a value with no comma break
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x } only had one value, fpoint needs two { x, y }");
return;
}
//get the first value
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
float *pointTemp = NULL;
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a float");
return;
}
//copy the xpoint value to stack and free the pointer
float pointX = *pointTemp;
free(pointTemp);
pointTemp = NULL;
//get the second value
valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4);
//if there is an empty comma break
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) > 1){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, ... } had too many values, fpoint needs two { x, y }");
return;
}
//get the second value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FPointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), second parameter was not a float");
return;
}
//copy the last value and free the temp value
ARC_FPoint *point = (ARC_FPoint *)malloc(sizeof(ARC_FPoint));
*point = (ARC_FPoint){ pointX, *pointTemp };
free(pointTemp);
//set the type value
*type = (void *)point;
}
void ARC_ConfigType_FPointDestroyFn(ARC_Config *config, void *type){
free((ARC_FPoint *)type);
}
void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){ void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0); ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
if(childTagToken->id != ARC_CONFIG_NESTED_VALUE){ if(childTagToken->id != ARC_CONFIG_NESTED_VALUE){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_Point"); ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_Rect");
type = NULL; type = NULL;
return; return;
} }
@ -104,7 +170,7 @@ void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata); ARC_ConfigType_Int32CopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){ if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA; arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_PointCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a int32"); ARC_DEBUG_LOG_ERROR("ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a int32");
return; return;
} }
@ -190,3 +256,115 @@ void ARC_ConfigType_RectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_
void ARC_ConfigType_RectDestroyFn(ARC_Config *config, void *type){ void ARC_ConfigType_RectDestroyFn(ARC_Config *config, void *type){
free((ARC_Rect *)type); free((ARC_Rect *)type);
} }
void ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata){
ARC_ParserTagToken *childTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0);
if(childTagToken->id != ARC_CONFIG_NESTED_VALUE){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nestedValue was not passed in for ARC_FRect");
type = NULL;
return;
}
//get the valueArgs
ARC_ParserTagToken *valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(childTagToken->tagTokens, 2);
//if there is only a value with no comma break
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x } only had one value, frect needs four { x, y, w, h }");
return;
}
//get the first value
ARC_ParserTagToken *valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
float *pointTemp = NULL;
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), first parameter was not a float");
return;
}
//copy the xpoint value to stack and free the pointer
float pointX = *pointTemp;
free(pointTemp);
pointTemp = NULL;
//get the second value
valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4);
//if there is only a value with no comma break
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y } only had two values, frect needs four { x, y, w, h }");
return;
}
//get the second value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), second parameter was not a float");
return;
}
float pointY = *pointTemp;
free(pointTemp);
pointTemp = NULL;
//get the third value
valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4);
//if there is an empty comma break
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) == 1){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, w } only had three values, frect needs four { x, y, w, h }");
return;
}
//get the third value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), third parameter was not a float");
return;
}
float pointW = *pointTemp;
free(pointTemp);
pointTemp = NULL;
//get the fourth value
valueArgsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 4);
//if there is an empty comma break
if(ARC_Vector_GetSize(valueArgsTagToken->tagTokens) > 1){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), nested value { x, y, w, h, ... } had too many values, frect needs four { x, y, w, h }");
return;
}
//get the fourth value
valueTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(valueArgsTagToken->tagTokens, 0);
ARC_ConfigType_FloatCopyFn((void **)&pointTemp, valueTagToken, config, userdata);
if(pointTemp == NULL){
arc_errno = ARC_ERRNO_DATA;
ARC_DEBUG_LOG_ERROR("ARC_ConfigType_FRectCopyFn(void **type, ARC_ParserTagToken *parsedData, ARC_Config *config, void *userdata), fourth parameter was not a float");
return;
}
//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 };
free(pointTemp);
//set the type value
*type = (void *)point;
}
void ARC_ConfigType_FRectDestroyFn(ARC_Config *config, void *type){
free((ARC_FRect *)type);
}