From 21a66f7fe6b7fc35d43bb35fb7d7549d22396fb5 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Mon, 7 Apr 2025 06:41:52 -0600 Subject: [PATCH] small fixes for config, entity, and some physics functions for vector2 --- include/arc/math/vector2.h | 24 ++++++++++++++++++++++++ include/arc/std/config.h | 12 +++++++++++- src/math/vector2.c | 14 +++++++++++++- src/std/config.c | 11 +++++++++++ src/std/entity.c | 2 +- 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/include/arc/math/vector2.h b/include/arc/math/vector2.h index ba98114..3207cda 100644 --- a/include/arc/math/vector2.h +++ b/include/arc/math/vector2.h @@ -28,6 +28,30 @@ void ARC_Vector2_Normalize(ARC_Vector2 *vector); */ void ARC_Vector2_RotateDegree(ARC_Vector2 *vector, float angle); +/** + * @brief + * + * @param vector1 + * @param vector2 +*/ +float ARC_Vector2_CrossProduct(ARC_Vector2 vector1, ARC_Vector2 vector2); + +/** + * @brief + * + * @param vector + * @param scalar +*/ +ARC_Vector2 ARC_Vector2_CrossProductScalar(ARC_Vector2 vector, float scalar); + +/** + * @brief + * + * @param scalar + * @param vector +*/ +ARC_Vector2 ARC_Vector2_ScalarCrossProduct(float scalar, ARC_Vector2 vector); + #ifdef __cplusplus } #endif diff --git a/include/arc/std/config.h b/include/arc/std/config.h index 92e0d80..afbf3d0 100644 --- a/include/arc/std/config.h +++ b/include/arc/std/config.h @@ -221,7 +221,17 @@ void ARC_Config_UnloadFromString(ARC_Config *config, ARC_String **string); * @breif config the config to unload the file from * @breif path the location of the .chemical file to unload */ -void ARC_Config_UnloadFromFile(ARC_Config *config, ARC_String *data); +void ARC_Config_UnloadFromFile(ARC_Config *config, ARC_String *path); + +/** + * @brief takes a given file path and unloads it into the config + * + * @note this path will be based on wherever the executable is run from + * + * @breif config the config to unload the file from + * @breif path the location of the .chemical file to unload +*/ +void ARC_Config_UnloadFromFileWithCStr(ARC_Config *config, const char *path); /** * @{ diff --git a/src/math/vector2.c b/src/math/vector2.c index a825903..aa80684 100644 --- a/src/math/vector2.c +++ b/src/math/vector2.c @@ -15,4 +15,16 @@ void ARC_Vector2_RotateDegree(ARC_Vector2 *vector, float angle){ ARC_Vector2 temp = *vector; vector->x = (temp.x * cos(angle)) - (temp.y * sin(angle)); vector->y = (temp.x * sin(angle)) + (temp.y * cos(angle)); -} \ No newline at end of file +} + +float ARC_Vector2_CrossProduct(ARC_Vector2 vector1, ARC_Vector2 vector2){ + return (vector1.x * vector2.y) - (vector1.y * vector2.x); +} + +ARC_Vector2 ARC_Vector2_CrossProductScalar(ARC_Vector2 vector, float scalar){ + return (ARC_Vector2){ scalar * vector.y, -scalar * vector.x }; +} + +ARC_Vector2 ARC_Vector2_ScalarCrossProduct(float scalar, ARC_Vector2 vector){ + return (ARC_Vector2){ -scalar * vector.y, scalar * vector.x }; +} diff --git a/src/std/config.c b/src/std/config.c index c32bafb..a8995e4 100644 --- a/src/std/config.c +++ b/src/std/config.c @@ -1046,6 +1046,17 @@ void ARC_Config_UnloadFromFile(ARC_Config *config, ARC_String *path){ ARC_Parser_ParseFile(config->parser, path); } +void ARC_Config_UnloadFromFileWithCStr(ARC_Config *config, const char *path){ + config->load = ARC_False; + + ARC_String *pathString; + ARC_String_CreateWithStrlen(&pathString, (char *)path); + + ARC_Parser_ParseFile(config->parser, pathString); + + ARC_String_Destroy(pathString); +} + void ARC_Config_InitStd(ARC_Config *config){ ARC_Config_RegisterTypeWithCStr(config, "bool" , (ARC_ConfigType){ sizeof(ARC_Bool) , ARC_ConfigType_BoolCopyFn , ARC_ConfigType_BoolDestroyFn , NULL }); ARC_Config_RegisterTypeWithCStr(config, "int8" , (ARC_ConfigType){ sizeof(int8_t) , ARC_ConfigType_Int8CopyFn , ARC_ConfigType_Int8DestroyFn , NULL }); diff --git a/src/std/entity.c b/src/std/entity.c index 72f72d5..d83a4bd 100644 --- a/src/std/entity.c +++ b/src/std/entity.c @@ -78,7 +78,7 @@ uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint 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); + totalSize = *(uint32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, offsetEndIndex - 1); } //if the new component size would overflow, throw an error