diff --git a/CMakeLists.txt b/CMakeLists.txt index da7aeaf..3c2e1bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,13 +11,12 @@ function(print var) message("${var} = ${${var}}") endfunction() -# ~ DEFAULT TO DEBUG IF TYPE NOT SET ~ # +#TODO: Might want to remove this if(NOT CMAKE_BUILD_TYPE) message("[Archeus] Build Type not set, defaulting to Debug") set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default to Debug" FORCE) endif() -# ~ COMPILER OPTIONS ~ # add_compile_options( "-Wall" "-Werror" "-fexceptions" "$<$:-O0;-g3;-ggdb;-DARC_DEBUG;>" diff --git a/doc/pages/standard/parser.md b/doc/pages/standard/parser.md index 3a79163..9e52d44 100644 --- a/doc/pages/standard/parser.md +++ b/doc/pages/standard/parser.md @@ -1,87 +1 @@ \page standard-parser ARC_Parser - -# Basic Overview - -The ::ARC_Parser type is a generic parsing type. To create the type it is recommeded you use ARC_Parser_CreateFromString( - -# Basic Example - -```c -const char *languageCString = - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE \n" - " -> | LAMBDA\n" - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n"; - -#define ARC_DOC_UNDERSCORE 1 -#define ARC_DOC_NUMBER 2 -#define ARC_DOC_ALPHA_UPPER_CHAR 3 -#define ARC_DOC_ALPHA_LOWER_CHAR 4 -#define ARC_DOC_VARIABLE 5 -#define ARC_DOC_VARIABLE_NAME 6 -#define ARC_DOC_VARIABLE_CHAR 7 - -void ARC_TEST_InitLexerRulesFn(ARC_Lexer *lexer){ - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_TEST_TAG_UNDERSCORE, '_' )); - - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_TEST_TAG_NUMBER , '0', '9')); - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_TEST_TAG_ALPHA_LOWER_CHAR, 'a', 'z')); - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_TEST_TAG_ALPHA_UPPER_CHAR, 'A', 'Z')); -} - -uint32_t ARC_TEST_GetStringIdFn(ARC_String *string){ - if(ARC_String_EqualsCStringWithStrlen(string, "LAMBDA")){ - return ARC_PARSER_TAG_LAMBDA; - } - - if(ARC_String_EqualsCStringWithStrlen(string, "UNDERSCORE")){ - return ARC_TEST_TAG_UNDERSCORE; - } - - if(ARC_String_EqualsCStringWithStrlen(string, "NUMBER")){ - return ARC_TEST_TAG_NUMBER; - } - if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_UPPER_CHAR")){ - return ARC_TEST_TAG_ALPHA_UPPER_CHAR; - } - if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_LOWER_CHAR")){ - return ARC_TEST_TAG_ALPHA_LOWER_CHAR; - } - - if(ARC_String_EqualsCStringWithStrlen(string, "")){ - return ARC_TEST_TAG_VARIABLE; - } - if(ARC_String_EqualsCStringWithStrlen(string, "")){ - return ARC_TEST_TAG_VARIABLE_NAME; - } - if(ARC_String_EqualsCStringWithStrlen(string, "")){ - return ARC_TEST_TAG_VARIABLE_CHAR; - } - - return ~(uint32_t)0; -} - -void ARC_TESTData_CreateFn(void **data, ARC_ParserTagToken *parsedData, void *userData){ -} - -void ARC_TESTData_DestroyFn(void *data, ARC_Bool clear, void *userData){ -} - -int main(){ - ARC_String *languageString; - ARC_String_CreateWithStrlen(&languageString, (char *)languageCString); - - ARC_Parser *parser; - ARC_ParserData_CreateFn createCharFn = ARC_TESTData_CreateFn; - ARC_ParserData_DestroyFn destroyCharFn = ARC_TESTData_DestroyFn; - ARC_Parser_CreateFromString(&parser, languageString, ARC_TEST_InitLexerRulesFn, ARC_TEST_GetStringIdFn, &createCharFn, &destroyCharFn, NULL); - ARC_String_Destroy(languageString); - - //this destroys string, so no need for cleanup - ARC_String *tempString; - ARC_String_CreateWithStrlen(&tempString, "variable123"); - ARC_Parser_Parse(parser, &tempString); - - // cleanup - ARC_Parser_Destroy(parser); -} -``` diff --git a/include/arc/graphics/renderer.h b/include/arc/graphics/renderer.h index 0d7e925..e5f7ab4 100644 --- a/include/arc/graphics/renderer.h +++ b/include/arc/graphics/renderer.h @@ -5,21 +5,22 @@ extern "C" { #endif -#include - /** * @brief predefien ARC_EngineData so as not to get circular reference */ typedef struct ARC_EngineData ARC_EngineData; /** - * @note ARC_RendererType is determined by which window backend you are using + * @note ARC_RendererType is determined by which window library you are using */ typedef struct ARC_RendererType ARC_Renderer; /** * @brief creates ARC_Renderer type with ARC_EngineData * + * @note the parameter data is determined by which graphics library you are using + * please refer to the graphics library section to see what needs to be passed + * * @param renderer ARC_Renderer to initialize * @param data the engine data to create from */ @@ -42,63 +43,12 @@ void ARC_Renderer_Clear(ARC_Renderer *renderer); /** * @brief renders the renderer * - * @param renderer renders all buffers and current renderer to window + * @note the renderer will most likely be drawn to from ARC_EngineData + * + * @param renderer the renderer to render */ void ARC_Renderer_Render(ARC_Renderer *renderer); -/** - * @brief - * - * @param renderer - * @param zIndex -*/ -void ARC_Renderer_InitBuffer(ARC_Renderer *renderer, uint32_t zIndex); - -/** - * @brief - * - * @param renderer - * @param 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 - * - * @param renderer -*/ -void ARC_Renderer_ClearBuffers(ARC_Renderer *renderer); - -/** - * @brief - * - * @param renderer - * @param zIndex -*/ -void ARC_Renderer_SetCurrentBuffer(ARC_Renderer *renderer, uint32_t zIndex); - -/** - * @brief - * - * @param renderer -*/ -void ARC_Renderer_UnsetBuffer(ARC_Renderer *renderer); - #ifdef __cplusplus } #endif diff --git a/include/arc/graphics/text.h b/include/arc/graphics/text.h index 9f6bcd2..3838fd7 100644 --- a/include/arc/graphics/text.h +++ b/include/arc/graphics/text.h @@ -9,47 +9,22 @@ 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_String *name; +typedef struct ARC_Text ARC_Text; - 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); -/** - * @brief -*/ -void ARC_Text_Destroy(ARC_Text *text); +void ARC_Text_Destroy(ARC_Text *font); -/** - * @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_ \ No newline at end of file diff --git a/include/arc/math/circle.h b/include/arc/math/circle.h index b93f406..60d9acb 100644 --- a/include/arc/math/circle.h +++ b/include/arc/math/circle.h @@ -25,8 +25,6 @@ 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 8194524..2af564b 100644 --- a/include/arc/math/point.h +++ b/include/arc/math/point.h @@ -27,27 +27,8 @@ 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 05b4210..577bf16 100644 --- a/include/arc/math/rectangle.h +++ b/include/arc/math/rectangle.h @@ -47,22 +47,6 @@ 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/include/arc/math/vector2.h b/include/arc/math/vector2.h index 3207cda..ba98114 100644 --- a/include/arc/math/vector2.h +++ b/include/arc/math/vector2.h @@ -28,30 +28,6 @@ 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 dae3309..92e0d80 100644 --- a/include/arc/std/config.h +++ b/include/arc/std/config.h @@ -221,17 +221,7 @@ 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 *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); +void ARC_Config_UnloadFromFile(ARC_Config *config, ARC_String *data); /** * @{ @@ -335,9 +325,7 @@ void ARC_Config_UnloadFromFileWithCStr(ARC_Config *config, const char *path); */ /** - * @brief inits a config type with the standard config settings - * - * @param config the config to init + * @brief TODO: write this */ void ARC_Config_InitStd(ARC_Config *config); diff --git a/include/arc/std/entity.h b/include/arc/std/entity.h index 59da830..10d9112 100644 --- a/include/arc/std/entity.h +++ b/include/arc/std/entity.h @@ -15,12 +15,12 @@ extern "C" { typedef struct ARC_EntitySystem ARC_EntitySystem; /** - * @brief an entity type (just an id) + * @brief an entity component system type */ typedef uint32_t ARC_Entity; /** - * @brief flags to define an entities current state + * @brief an entity component system type */ typedef enum ARC_EntityFlags { ARC_ENTITY_DEAD = 0, @@ -33,16 +33,12 @@ typedef enum ARC_EntityFlags { typedef uint32_t ARC_EntityComponent; /** - * @brief a callback function for components attached to an entity to create an empty type when a new entity is created - * - * @param[out] type, the place to create an empty type + * @brief */ typedef void (* ARC_EntityCoponent_CreateEmptyFn)(void **type); /** - * @brief creates an empty entity system, use ARC_EntitySystem_RegisterComponent to add compenents to the entity system - * - * @parm[out] entitySystem an empty entity system + * @brief */ void ARC_EntitySystem_Create(ARC_EntitySystem **entitySystem); @@ -61,68 +57,37 @@ void ARC_EntitySystem_Destroy(ARC_EntitySystem *entitySystem); * @param[in] entitySystem the entity system to register the component to * @param[in] componentSize the size of the component to register * - * @return a uint32_t id for for the component + * @return an id for for the component */ uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint32_t componentSize); /** - * @brief inits an empty entity, usually use ARC_EntitySystem_AddComponent to add compenets to the entity this function creates - * - * @param[in] entitySystem the entitySystem to init a new entity in - * - * @return an ARC_Entity that holds the id of the newly inited slot + * @brief */ ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem); /** - * @brief releases an entity from a given entity system - * - * @param[in] entitySystem the entity system to remove the entity from - * @param[in] entity the entity to remove + * @brief */ void ARC_EntitySystem_ReleaseEntity(ARC_EntitySystem *entitySystem, ARC_Entity entity); /** - * @brief adds a component to a given entity within an entity system - * - * @note data will be copied, so if data was created elsewere it needs to be freed elsewhere - * - * @param[in] entitySystem the entity system that holds the entity which is being modified - * @param[in] entity the entity as an id which a component is being added to - * @param[in] component the id of the compenent for the entity system - * @param[in] data the components data as a void * + * @brief */ void ARC_EntitySystem_AddComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component, void *data); /** - * @brief checks if an entity has a component within an entity system - * - * @param[in] entitySystem the entity system that holds the entity which is being checked - * @param[in] entity the entity as an id - * @param[in] component the id of the compenent for the entity system - * - * @return ARC_True if the entity has the given component, otherwise ARC_False + * @brief */ ARC_Bool ARC_EntitySystem_HasComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component); /** - * @brief retrieves a components data for a specific entity - * - * @param[in] entitySystem the entity system that holds the entity which is being retrieved - * - * @param[in] entity the entity as an id - * @param[in] component the id of the compenent for the entity system - * @return the components data as a void * on success, otherwise NULL + * @brief */ void *ARC_EntitySystem_GetComponentData(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component); /** - * @brief retrieves all entities which have the given components - * - * @note this function will not check for exact matches, it just returns the entitys which have all the components (the entity might have more components than what is given) - * - * @param[in] entitySystem the entity system to query entities from - * @param[in] components the components a entity has to have to match + * @brief */ ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, ARC_Array components); diff --git a/include/arc/std/errno.h b/include/arc/std/errno.h index d969b24..79fb015 100644 --- a/include/arc/std/errno.h +++ b/include/arc/std/errno.h @@ -23,7 +23,7 @@ extern int32_t arc_errno; extern FILE *arc_errno_log_file; #ifndef ARC_DEBUG_LOG_STREAM_OVERRIDE - //this function will be called on start, handy to set the log file to stdout if it is not overrided + //this functin will be called on start, handy to set the log file to stdout if it is not overrided void __attribute__ ((constructor)) ARC_Errno_SetDefaultStream(void); #endif // !ARC_DEBUG_LOG_STREAM_OVERRIDE #endif // !ARC_DEBUG diff --git a/include/arc/std/handler.h b/include/arc/std/handler.h index b5c7fe8..a48ce31 100644 --- a/include/arc/std/handler.h +++ b/include/arc/std/handler.h @@ -10,14 +10,14 @@ extern "C" { /** * @brief a handler type -*/ + */ typedef struct ARC_Handler ARC_Handler; /** * @brief a function that will take iterated data * * @param data iterated data from ARC_Handler_Iterate -*/ + */ typedef void (* ARC_Handler_DataFn)(void *data); /** @@ -25,14 +25,14 @@ typedef void (* ARC_Handler_DataFn)(void *data); * * @param config ARC_Handler to initialize * @param destroyDataFn function to clean data in handler, can be null -*/ + */ void ARC_Handler_Create(ARC_Handler **handler, ARC_Vector_DestroyDataFn *destroyDataFn); /** * @brief destroyes ARC_Handler type * * @param handler ARC_Handler to destory -*/ + */ void ARC_Handler_Destroy(ARC_Handler *handler); /** @@ -40,7 +40,7 @@ void ARC_Handler_Destroy(ARC_Handler *handler); * * @param handler ARC_Handler to add to * @param data data that is being added -*/ + */ void ARC_Handler_Add(ARC_Handler *handler, void *data); /** @@ -52,7 +52,7 @@ void ARC_Handler_Add(ARC_Handler *handler, void *data); * * @param handler ARC_Handler to remove from * @param index index of data that is being removed -*/ + */ void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index); /** @@ -60,14 +60,14 @@ void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index); * * @param handler ARC_Handler to iterate through * @param datafn function that will be called on each element of data -*/ + */ void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn); /** * @brief clears all data from handler and puts it in trash vector * * @param handler ARC_Handler to clear data from -*/ + */ void ARC_Handler_Clear(ARC_Handler *handler); /** @@ -76,18 +76,18 @@ void ARC_Handler_Clear(ARC_Handler *handler); * @note cleanfn's main purpose is to help manage memory * * @param handler ARC_Handler to remove trash from -*/ + */ void ARC_Handler_Clean(ARC_Handler *handler); /** - * @brief gets size of elements stored in the handler + * @brief gets size of vector * * @param handler ARC_handler to get size from -*/ + */ uint32_t ARC_Handler_GetSize(ARC_Handler *handler); #ifdef __cplusplus } #endif -#endif // !ARC_STD_HANDLER_H_ +#endif //ARC_STD_HANDLER_H_ diff --git a/packages/graphics/sdl3/config.c b/packages/graphics/sdl3/config.c index 082ac80..7d6a911 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", (void *)sprite); + sprintf(pointerCString, "%p", 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", (void *)sprite); + sprintf(pointerCString, "%p", sprite); /* ~ spritesheet ~ */ //create a name based on the type and the sprite pointer to have a unique name for cleanup on remove @@ -206,9 +206,8 @@ 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 @@ -216,9 +215,8 @@ 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/line.c b/packages/graphics/sdl3/line.c index 12ea67e..6035a4c 100644 --- a/packages/graphics/sdl3/line.c +++ b/packages/graphics/sdl3/line.c @@ -2,6 +2,6 @@ #include "renderer.h" void ARC_Line_Render(ARC_Point point1, ARC_Point point2, ARC_Renderer *renderer, ARC_Color color){ - SDL_SetRenderDrawColor(renderer->renderer, color.r, color.g, color.b, color.a); - SDL_RenderLine(renderer->renderer, point1.x, point1.y, point2.x, point2.y); + SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a); + SDL_RenderLine((SDL_Renderer *)renderer, point1.x, point1.y, point2.x, point2.y); } diff --git a/packages/graphics/sdl3/rectangle.c b/packages/graphics/sdl3/rectangle.c index 2837483..cc51480 100644 --- a/packages/graphics/sdl3/rectangle.c +++ b/packages/graphics/sdl3/rectangle.c @@ -13,11 +13,11 @@ void ARC_Rect_RenderFill(ARC_Rect rect, ARC_Renderer *renderer, ARC_Color color) } void ARC_FRect_Render(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color){ - SDL_SetRenderDrawColor(renderer->renderer, color.r, color.g, color.b, color.a); - SDL_RenderRect(renderer->renderer, (SDL_FRect *)&rect); + SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a); + SDL_RenderRect((SDL_Renderer *)renderer, (SDL_FRect *)&rect); } void ARC_FRect_RenderFill(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color){ - SDL_SetRenderDrawColor(renderer->renderer, color.r, color.g, color.b, color.a); - SDL_RenderFillRect(renderer->renderer, (SDL_FRect *)&rect); + SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a); + SDL_RenderFillRect((SDL_Renderer *)renderer, (SDL_FRect *)&rect); } diff --git a/packages/graphics/sdl3/renderer.c b/packages/graphics/sdl3/renderer.c index 939b62e..a4d6e2c 100644 --- a/packages/graphics/sdl3/renderer.c +++ b/packages/graphics/sdl3/renderer.c @@ -5,22 +5,8 @@ #include #include "arc/engine/engine.h" #include "arc/graphics/window.h" -#include "arc/std/bool.h" #include "arc/std/errno.h" -uint32_t ARC_Renderer_BuffersHashtableHashFn(void *key){ - return *(uint32_t *)key; -} - -ARC_Bool ARC_Renderer_BuffersHashtableKeyCompareFn(void *key1, void *key2){ - return (ARC_Bool)(*(uint32_t *)key1 == *(uint32_t *)key2); -} - -void ARC_Renderer_BuffersHashtableDestroy(void *key, void *value){ - free((uint32_t *)key); - SDL_DestroyTexture(value); -} - void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *data){ if(!data){ arc_errno = ARC_ERRNO_NULL; @@ -28,109 +14,26 @@ void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData * return; } - *renderer = (ARC_Renderer *)malloc(sizeof(ARC_Renderer)); + *renderer = (ARC_Renderer *)SDL_CreateRenderer((SDL_Window *)(data->window), NULL); - /* ~ Renderer ~ */ - (*renderer)->renderer = SDL_CreateRenderer((SDL_Window *)(data->window), NULL); - - if((*renderer)->renderer == NULL){ + if(!*renderer){ arc_errno = ARC_ERRNO_NULL; - ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("SDL_CreateRenderer(%p, NULL);", (void *)data->window); + ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("SDL_CreateRenderer(%p, NULL);", data->window); free(renderer); - return; } - SDL_SetRenderDrawBlendMode((*renderer)->renderer, SDL_BLENDMODE_BLEND); - - /* ~ Buffers ~ */ - ARC_Hashtable_HashFn hashFn = ARC_Renderer_BuffersHashtableHashFn; - ARC_Hashtable_KeyCompareFn keyCompareFn = ARC_Renderer_BuffersHashtableKeyCompareFn; - ARC_Hashtable_DestroyKeyValueFn destroyKeyValueFn = ARC_Renderer_BuffersHashtableDestroy; - ARC_Hashtable_Create(&((*renderer)->buffers), &hashFn, &keyCompareFn, &destroyKeyValueFn); - - /* ~ Clear Color ~ */ - (*renderer)->clearColor = (ARC_Color){ 0x1c, 0x2c, 0x3c, 0xff }; + SDL_SetRenderDrawBlendMode((SDL_Renderer *)*renderer, SDL_BLENDMODE_BLEND); } void ARC_Renderer_Destroy(ARC_Renderer *renderer){ - ARC_Hashtable_Destroy(renderer->buffers); - SDL_DestroyRenderer(renderer->renderer); - free(renderer); + SDL_DestroyRenderer((SDL_Renderer *) renderer); } 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); + SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x1c, 0x2c, 0x3c, 0xff); + SDL_RenderClear((SDL_Renderer *)renderer); } void ARC_Renderer_Render(ARC_Renderer *renderer){ - SDL_RenderPresent(renderer->renderer); -} - -void ARC_Renderer_InitBuffer(ARC_Renderer *renderer, uint32_t zIndex){ - SDL_Texture *buffer = (SDL_Texture *)ARC_Hashtable_Get(renderer->buffers, &zIndex); - if(buffer != NULL){ - //buffer was already created, do nothing - return; - } - - SDL_Rect viewPort = { 0, 0, 0, 0 }; - - SDL_GetRenderViewport(renderer->renderer, &viewPort); - - buffer = SDL_CreateTexture(renderer->renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, viewPort.w - viewPort.x, viewPort.h - viewPort.y); - - uint32_t *index = (uint32_t *)malloc(sizeof(uint32_t)); - *index = zIndex; - ARC_Hashtable_Add(renderer->buffers, index, buffer); -} - -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; - - SDL_Texture *buffer = (SDL_Texture *)value; - - SDL_SetRenderTarget(renderer->renderer, buffer); - SDL_SetRenderDrawColor(renderer->renderer, 0x00, 0x00, 0x00, 0x00); - SDL_RenderClear(renderer->renderer); -} - -void ARC_Renderer_ClearBuffers(ARC_Renderer *renderer){ - ARC_Hashtable_RunIteration(renderer->buffers, ARC_Renderer_BuffersHashtableClearIteratorFn, (void *)renderer); -} - -void ARC_Renderer_SetCurrentBuffer(ARC_Renderer *renderer, uint32_t zIndex){ - SDL_Texture *buffer = (SDL_Texture *)ARC_Hashtable_Get(renderer->buffers, &zIndex); - SDL_SetRenderTarget(renderer->renderer, buffer); - - if(buffer != NULL){ - //TODO: probs throw an error - return; - } -} - -void ARC_Renderer_UnsetBuffer(ARC_Renderer *renderer){ - SDL_SetRenderTarget(renderer->renderer, NULL); + SDL_RenderPresent((SDL_Renderer *)renderer); } diff --git a/packages/graphics/sdl3/renderer.h b/packages/graphics/sdl3/renderer.h index 423f931..2609e6b 100644 --- a/packages/graphics/sdl3/renderer.h +++ b/packages/graphics/sdl3/renderer.h @@ -1,18 +1,10 @@ #ifndef ARC_SDL_RENDERER_H_ #define ARC_SDL_RENDERER_H_ -#include "arc/graphics/color.h" #include "arc/graphics/renderer.h" #include "arc/graphics/window.h" -#include "arc/std/hashtable.h" #include -typedef struct ARC_RendererType { - SDL_Renderer *renderer; - - ARC_Hashtable *buffers; - - ARC_Color clearColor; -} ARC_RendererType; +typedef SDL_Renderer ARC_RendererType; #endif // !ARC_SDL_RENDERER_H_ diff --git a/packages/graphics/sdl3/sprite.c b/packages/graphics/sdl3/sprite.c index 6809bfd..397de3a 100644 --- a/packages/graphics/sdl3/sprite.c +++ b/packages/graphics/sdl3/sprite.c @@ -1,6 +1,5 @@ #include "arc/graphics/sprite.h" -#include "renderer.h" #include "spritesheet.h" #include "arc/math/point.h" #include "arc/math/rectangle.h" @@ -42,7 +41,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((SDL_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){ @@ -65,7 +64,7 @@ void ARC_Sprite_RenderAt(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_FPoint flip |= SDL_FLIP_VERTICAL; } - SDL_RenderTextureRotated(renderer->renderer, sprite->spritesheet->texture, (SDL_FRect *)&sourceRect, (SDL_FRect *)&destinationRect, sprite->angle, (SDL_FPoint *)&(sprite->origin), flip); + SDL_RenderTextureRotated((SDL_Renderer *)renderer, sprite->spritesheet->texture, (SDL_FRect *)&sourceRect, (SDL_FRect *)&destinationRect, sprite->angle, (SDL_FPoint *)&(sprite->origin), flip); } void ARC_Sprite_IterateFrame(ARC_Sprite *sprite){ diff --git a/packages/graphics/sdl3/spritesheet.c b/packages/graphics/sdl3/spritesheet.c index 82e005e..6bca7ac 100644 --- a/packages/graphics/sdl3/spritesheet.c +++ b/packages/graphics/sdl3/spritesheet.c @@ -28,7 +28,7 @@ void ARC_Spritesheet_CreateFromFile(ARC_Spritesheet **spritesheet, ARC_Renderer //set the texture SDL_BlendMode tempMode; SDL_GetSurfaceBlendMode(surface, &tempMode); - (*spritesheet)->texture = SDL_CreateTextureFromSurface(renderer->renderer, surface); + (*spritesheet)->texture = SDL_CreateTextureFromSurface((SDL_Renderer *)renderer, surface); SDL_SetTextureBlendMode((*spritesheet)->texture, tempMode); SDL_SetTextureScaleMode((*spritesheet)->texture, SDL_SCALEMODE_NEAREST); @@ -45,12 +45,12 @@ void ARC_Spritesheet_Destroy(ARC_Spritesheet *spritesheet){ } void ARC_Spritesheet_Render(ARC_Spritesheet *spritesheet, ARC_Renderer *renderer, ARC_FRect renderBounds){ - SDL_RenderTexture(renderer->renderer, spritesheet->texture, NULL, (SDL_FRect *)&renderBounds); + SDL_RenderTexture((SDL_Renderer *)renderer, spritesheet->texture, NULL, (SDL_FRect *)&renderBounds); } void ARC_Spritesheet_RenderArea(ARC_Spritesheet *spritesheet, ARC_Rect sheetBounds, ARC_Renderer *renderer, ARC_FRect renderBounds){ ARC_FRect bounds = ARC_Rect_CastToFRect(sheetBounds); - SDL_RenderTexture(renderer->renderer, spritesheet->texture, (SDL_FRect *)&bounds, (SDL_FRect *)&renderBounds); + SDL_RenderTexture((SDL_Renderer *)renderer, spritesheet->texture, (SDL_FRect *)&bounds, (SDL_FRect *)&renderBounds); } void ARC_Spritesheet_RenderTile(ARC_Spritesheet *spritesheet, ARC_Point tilePosition, ARC_Renderer *renderer, ARC_FRect renderBounds){ @@ -70,7 +70,7 @@ void ARC_Spritesheet_RenderTile(ARC_Spritesheet *spritesheet, ARC_Point tilePosi }; //render the bounds - SDL_RenderTexture(renderer->renderer, spritesheet->texture, (SDL_FRect *)&sheetBounds, (SDL_FRect *)&renderBounds); + SDL_RenderTexture((SDL_Renderer *)renderer, spritesheet->texture, (SDL_FRect *)&sheetBounds, (SDL_FRect *)&renderBounds); } ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet){ diff --git a/packages/graphics/sdl3/text.c b/packages/graphics/sdl3/text.c index 50c2d76..d87ed08 100644 --- a/packages/graphics/sdl3/text.c +++ b/packages/graphics/sdl3/text.c @@ -1,6 +1,6 @@ #include "arc/graphics/text.h" -#include "renderer.h" +#include "text.h" #include "arc/graphics/color.h" #include "arc/math/point.h" #include "arc/math/rectangle.h" @@ -12,13 +12,11 @@ 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)->fontSize = size; - (*text)->bounds = (ARC_FRect){ 0.0f, 0.0f, 0.0f, 0.0f }; - (*text)->color = color; - (*text)->backendData = NULL; + (*text)->size = size; + (*text)->color = color; + (*text)->texture = NULL; + (*text)->bounds = (ARC_Rect){ 0, 0, 0, 0 }; //TODO: fix this if(TTF_Init() == false) { @@ -28,16 +26,15 @@ void ARC_Text_Create(ARC_Text **text, ARC_String *path, int32_t size, ARC_Color } void ARC_Text_Destroy(ARC_Text *font){ - if(font->backendData != NULL){ - SDL_DestroyTexture((SDL_Texture *)font->backendData); + if(font->texture != NULL){ + SDL_DestroyTexture(font->texture); } - 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->fontSize); + TTF_Font *ttfont = TTF_OpenFont(text->name->data, text->size); 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); @@ -45,22 +42,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->backendData != NULL){ - SDL_DestroyTexture((SDL_Texture *)text->backendData); + if(text->texture){ + SDL_DestroyTexture(text->texture); } - text->backendData = (void *)SDL_CreateTextureFromSurface(renderer->renderer, surface); + text->texture = SDL_CreateTextureFromSurface((SDL_Renderer *)renderer, surface); SDL_DestroySurface(surface); TTF_CloseFont(ttfont); } void ARC_Text_Render(ARC_Text *text, ARC_Renderer *renderer){ - if(text->backendData == NULL){ + if(text->texture == NULL){ return; } SDL_FRect bounds = (SDL_FRect){ text->bounds.x, text->bounds.y, text->bounds.w, text->bounds.h }; - SDL_RenderTexture(renderer->renderer, (SDL_Texture *)(text->backendData), NULL, &bounds); + SDL_RenderTexture((SDL_Renderer *)renderer, text->texture, 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 new file mode 100644 index 0000000..4c561ba --- /dev/null +++ b/packages/graphics/sdl3/text.h @@ -0,0 +1,20 @@ +#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/packages/graphics/sdl3/view.c b/packages/graphics/sdl3/view.c index 135b125..b581e10 100644 --- a/packages/graphics/sdl3/view.c +++ b/packages/graphics/sdl3/view.c @@ -1,7 +1,7 @@ #include "arc/graphics/view.h" #include "arc/std/errno.h" -#include +#include #include void ARC_View_Create(ARC_View **view, ARC_Renderer *renderer, ARC_Rect bounds){ @@ -15,21 +15,21 @@ void ARC_View_Destroy(ARC_View *view){ } void ARC_View_Render(ARC_View *view, ARC_View_RenderFn renderFn, void *data){ -// int err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, (const SDL_Rect *)&(view->bounds)); -// if(err){ -// ARC_DEBUG_LOG_ERROR(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, renderFn), SDL_RenderSetViewport(...) returned: %d", err); -// return; -// } -// -// renderFn(data); -// -// err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, NULL); -// if(err){ -// ARC_DEBUG_LOG(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, NULL), SDL_RenderSetViewport(...) returned: %d", err); -// return; -// } + int err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, (const SDL_Rect *)&(view->bounds)); + if(err){ + ARC_DEBUG_LOG(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, renderFn), SDL_RenderSetViewport(...) returned: %d", err); + return; + } + + renderFn(data); + + err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, NULL); + if(err){ + ARC_DEBUG_LOG(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, NULL), SDL_RenderSetViewport(...) returned: %d", err); + return; + } } ARC_Rect ARC_View_GetBounds(ARC_View *view){ return view->bounds; -} +} \ No newline at end of file diff --git a/src/math/circle.c b/src/math/circle.c index 9a5e8d1..e69de29 100644 --- a/src/math/circle.c +++ b/src/math/circle.c @@ -1,4 +0,0 @@ -#include "arc/math/circle.h" - -void TEMP_Circle_Placeholder(void){ -} diff --git a/src/math/config.c b/src/math/config.c index 6cfe34a..cec1f8f 100644 --- a/src/math/config.c +++ b/src/math/config.c @@ -358,10 +358,7 @@ 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->x = pointX; - point->y = pointY; - point->w = pointW; - point->h = *pointTemp; + *point = (ARC_FRect){ pointX, pointY, pointW, *pointTemp }; free(pointTemp); //set the type value diff --git a/src/math/point.c b/src/math/point.c index 042aff4..7e1767c 100644 --- a/src/math/point.c +++ b/src/math/point.c @@ -1,26 +1,8 @@ #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 - }; -} - - +} \ No newline at end of file diff --git a/src/math/rectangle.c b/src/math/rectangle.c index de2d90a..994ce91 100644 --- a/src/math/rectangle.c +++ b/src/math/rectangle.c @@ -1,6 +1,9 @@ #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); @@ -11,16 +14,6 @@ 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/math/vector2.c b/src/math/vector2.c index aa80684..a825903 100644 --- a/src/math/vector2.c +++ b/src/math/vector2.c @@ -15,16 +15,4 @@ 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)); -} - -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 }; -} +} \ No newline at end of file diff --git a/src/std/config.c b/src/std/config.c index 6e1d2e3..c32bafb 100644 --- a/src/std/config.c +++ b/src/std/config.c @@ -1046,17 +1046,6 @@ 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 }); @@ -1428,8 +1417,7 @@ void ARC_ConfigType_DoubleDestroyFn(ARC_Config *config, void *type){ } void ARC_ConfigType_StringCopyFn(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_STRING){ + if(parsedData->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; @@ -1437,8 +1425,7 @@ 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(childTagToken->tagTokens, 1); - ARC_String_Create((ARC_String **)type, NULL, 0); + ARC_ParserTagToken *stringCharsTagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 1); ARC_ParserData_HelperRecurseStringAdd((ARC_String **)type, stringCharsTagToken); } diff --git a/src/std/entity.c b/src/std/entity.c index 2e89603..72f72d5 100644 --- a/src/std/entity.c +++ b/src/std/entity.c @@ -42,10 +42,6 @@ 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){ @@ -80,7 +76,10 @@ 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 = *(uint32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, offsetEndIndex - 1); + uint32_t totalSize = 0; + if(ARC_VectorInline_GetSize(entitySystem->offsetVector) != 0){ + totalSize = *(uint32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, offsetEndIndex); + } //if the new component size would overflow, throw an error if(totalSize > (~(uint32_t)0) - componentSize){ @@ -89,18 +88,16 @@ 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->sizeVector) - 1; + return ARC_VectorInline_GetSize(entitySystem->offsetVector) - 1; } ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem){ @@ -124,7 +121,7 @@ ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem){ //get the next free entity ARC_Entity entity = (ARC_Entity)ARC_VectorInline_GetSize(entitySystem->data); - + //TODO: check if this works ARC_VectorInline_Add(entitySystem->data, NULL); ARC_VectorInline_Add(entitySystem->flagVector, NULL); ARC_VectorInline_Add(entitySystem->maskVector, NULL); @@ -172,8 +169,7 @@ 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); - int32_t temp = *(int32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, (uint32_t)component); - return data + temp; + return data + *(int32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, (uint32_t)component); } ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, ARC_Array components){ @@ -183,7 +179,7 @@ ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, A componentsMask |= (1 << ((ARC_EntityComponent *)components.data)[index]); } - //setup the components data and get a return size + //setup teh components data and get a return size uint32_t maxEntitySize = ARC_VectorInline_GetSize(entitySystem->data) - ARC_VectorInline_GetSize(entitySystem->freeEntities); //clear the query if it already exists diff --git a/tests/std/parser.c b/tests/std/parser.c index d790613..54ef244 100644 --- a/tests/std/parser.c +++ b/tests/std/parser.c @@ -2,129 +2,268 @@ #include "arc/std/bool.h" #include "arc/std/errno.h" #include "arc/std/parser.h" +#include "arc/std/parser/helpers.h" #include "arc/std/lexer.h" +#include "arc/std/vector.h" #include #include -//TODO: add more tests -const char *languageCString = - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE \n" - " -> | LAMBDA\n" - " -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n"; +//TODO: rewrite these tests. ARC_Config does use both the parser and lexer so for now (very temporary) its tests function for these ones -#define ARC_TEST_TAG_UNDERSCORE 1 -#define ARC_TEST_TAG_NUMBER 2 -#define ARC_TEST_TAG_ALPHA_UPPER_CHAR 3 -#define ARC_TEST_TAG_ALPHA_LOWER_CHAR 4 -#define ARC_TEST_TAG_VARIABLE 5 -#define ARC_TEST_TAG_VARIABLE_NAME 6 -#define ARC_TEST_TAG_VARIABLE_CHAR 7 - -void ARC_TEST_InitLexerRulesFn(ARC_Lexer *lexer){ - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_TEST_TAG_UNDERSCORE, '_' )); - - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_TEST_TAG_NUMBER , '0', '9')); - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_TEST_TAG_ALPHA_LOWER_CHAR, 'a', 'z')); - ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(ARC_TEST_TAG_ALPHA_UPPER_CHAR, 'A', 'Z')); -} - -uint32_t ARC_TEST_GetStringIdFn(ARC_String *string){ - if(ARC_String_EqualsCStringWithStrlen(string, "LAMBDA")){ - return ARC_PARSER_TAG_LAMBDA; - } - - if(ARC_String_EqualsCStringWithStrlen(string, "UNDERSCORE")){ - return ARC_TEST_TAG_UNDERSCORE; - } - - if(ARC_String_EqualsCStringWithStrlen(string, "NUMBER")){ - return ARC_TEST_TAG_NUMBER; - } - if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_UPPER_CHAR")){ - return ARC_TEST_TAG_ALPHA_UPPER_CHAR; - } - if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_LOWER_CHAR")){ - return ARC_TEST_TAG_ALPHA_LOWER_CHAR; - } - - if(ARC_String_EqualsCStringWithStrlen(string, "")){ - return ARC_TEST_TAG_VARIABLE; - } - if(ARC_String_EqualsCStringWithStrlen(string, "")){ - return ARC_TEST_TAG_VARIABLE_NAME; - } - if(ARC_String_EqualsCStringWithStrlen(string, "")){ - return ARC_TEST_TAG_VARIABLE_CHAR; - } - - return ~(uint32_t)0; -} - -void ARC_TESTData_CreateFn(void **data, ARC_ParserTagToken *parsedData, void *userData){ -} - -void ARC_TESTData_DestroyFn(void *data, ARC_Bool clear, void *userData){ -} - -ARC_TEST(Parser_Init){ - ARC_String *languageString; - ARC_String_CreateWithStrlen(&languageString, (char *)languageCString); - - ARC_Parser *parser; - ARC_ParserData_CreateFn createCharFn = ARC_TESTData_CreateFn; - ARC_ParserData_DestroyFn destroyCharFn = ARC_TESTData_DestroyFn; - ARC_Parser_CreateFromString(&parser, languageString, ARC_TEST_InitLexerRulesFn, ARC_TEST_GetStringIdFn, &createCharFn, &destroyCharFn, NULL); - ARC_String_Destroy(languageString); - - ARC_Parser_Destroy(parser); - - ARC_CHECK(arc_errno == 0); -} - -ARC_TEST(Parser_Basic_Parse){ - ARC_String *languageString; - ARC_String_CreateWithStrlen(&languageString, (char *)languageCString); - - ARC_Parser *parser; - ARC_ParserData_CreateFn createCharFn = ARC_TESTData_CreateFn; - ARC_ParserData_DestroyFn destroyCharFn = ARC_TESTData_DestroyFn; - ARC_Parser_CreateFromString(&parser, languageString, ARC_TEST_InitLexerRulesFn, ARC_TEST_GetStringIdFn, &createCharFn, &destroyCharFn, NULL); - ARC_String_Destroy(languageString); - - /* ~ first test ~ */ - ARC_String *tempString; - ARC_String_CreateWithStrlen(&tempString, "myvar1"); - - //this destroys string, so no need for cleanup - ARC_Parser_Parse(parser, &tempString); - - ARC_CHECK(arc_errno == 0); - - /* ~ second test ~ */ - ARC_String_CreateWithStrlen(&tempString, "z1xwvq"); - - //this destroys string, so no need for cleanup - ARC_Parser_Parse(parser, &tempString); - - ARC_CHECK(arc_errno == 0); - - /* ~ third test ~ */ - ARC_String_CreateWithStrlen(&tempString, "z1234"); - - //this destroys string, so no need for cleanup - ARC_Parser_Parse(parser, &tempString); - - ARC_CHECK(arc_errno == 0); - - /* ~ fourth test ~ */ - ARC_String_CreateWithStrlen(&tempString, "aaaaa"); - - - //this destroys string, so no need for cleanup - ARC_Parser_Parse(parser, &tempString); - - ARC_CHECK(arc_errno == 0); - - /* ~ cleanup ~ */ - ARC_Parser_Destroy(parser); -} +//ARC_TEST(Parser_Init){ +// ARC_Parser *parser; +// ARC_Parser_Create(&parser, &languageArray, TEST_Parser_InitLexerRulesFn, NULL, NULL, NULL); +// +// ARC_Parser_Destroy(parser); +// +// ARC_CHECK(arc_errno == 0); +//} +// +//ARC_TEST(Parser_Basic_Parse){ +// ARC_Parser *parser; +// ARC_Parser_Create(&parser, &languageArray, TEST_Parser_InitLexerRulesFn, NULL, NULL, NULL); +// +// ARC_String *tempString; +// +// +// /* ~ first test ~ */ +// ARC_String_CreateWithStrlen(&tempString, "myvar1"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == 0); +// +// +// /* ~ second test ~ */ +// ARC_String_CreateWithStrlen(&tempString, "z1xwvq"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == 0); +// +// +// /* ~ third test ~ */ +// ARC_String_CreateWithStrlen(&tempString, "z1234"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == 0); +// +// +// /* ~ fourth test ~ */ +// ARC_String_CreateWithStrlen(&tempString, "aaaaa"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == 0); +// +// +// /* ~ cleanup ~ */ +// ARC_Parser_Destroy(parser); +//} +// +//ARC_TEST(Parser_Basic_ParseError){ +// ARC_Parser *parser; +// ARC_Parser_Create(&parser, &languageArray, TEST_Parser_InitLexerRulesFn, NULL, NULL, NULL); +// +// ARC_String *tempString; +// +// +// /* ~ first test ~ */ +// ARC_String_CreateWithStrlen(&tempString, "!myVar1"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == ARC_ERRNO_DATA); +// +// +// /* ~ second test ~ */ +// //check again with moved character +// arc_errno = 0; +// ARC_String_CreateWithStrlen(&tempString, "my!Var1"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == ARC_ERRNO_DATA); +// +// +// /* ~ third test ~ */ +// //check again with moved character +// arc_errno = 0; +// ARC_String_CreateWithStrlen(&tempString, "myVar1!"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == ARC_ERRNO_DATA); +// +// +// /* ~ cleanup ~ */ +// ARC_Parser_Destroy(parser); +// +// //reset for next test +// arc_errno = 0; +//} +// +//ARC_TEST(Parser_Basic_GetParsedValue){ +// ARC_Parser *parser; +// +// ARC_ParserData_CreateFn createStringFn = TEST_ParserData_CreateStringFn; +// ARC_ParserData_DestroyFn destroyStringFn = TEST_ParserData_DestroyStringFn; +// +// ARC_Parser_Create(&parser, &languageArray, TEST_Parser_InitLexerRulesFn, &createStringFn, &destroyStringFn, NULL); +// +// ARC_String *tempString; +// +// +// /* ~ first test ~ */ +// ARC_String_CreateWithStrlen(&tempString, "myvar1"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// ARC_CHECK(arc_errno == 0); +// +// ARC_String *checkValue = (ARC_String *)ARC_Parser_GetData(parser); +// ARC_CHECK(ARC_String_EqualsCStringWithStrlen(checkValue, "myvar1")); +// +// +// /* ~ cleanup ~ */ +// ARC_Parser_Destroy(parser); +//} +// +//ARC_TEST(Parser_ParserLang_BasicVector){ +// ARC_Vector *testLanguage; +// ARC_Vector_Create(&testLanguage, NULL, NULL); +// +// ARC_Vector_Add(testLanguage, testTags + 0); +// ARC_Vector_Add(testLanguage, testTags + 1); +// ARC_Vector_Add(testLanguage, testTags + 2); +// +// ARC_Parser *parser; +// ARC_Parser_CreateFromVector(&parser, testLanguage, TEST_Parser_InitLexerRulesFn, NULL, NULL, NULL); +// +// ARC_String *tempString; +// ARC_String_CreateWithStrlen(&tempString, "variablename"); +// +// //this destroys string, so no need for cleanup +// ARC_Parser_Parse(parser, &tempString); +// +// //cleanup +// ARC_Parser_Destroy(parser); +// ARC_Vector_Destroy(testLanguage); +// +// ARC_CHECK(arc_errno == 0); +//} +// +///* ~ parser tests ~ */ +//void TEST_Parser_InitBasicLexerTokenRules(ARC_Lexer *lexer){ +// //null +// ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharRule(ARC_PARSER_TAG_LAMBDA, 0)); +// +// //alpha char +// ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(TEST_PARSER_ALPHA_LOWER_CHAR, 'a', 'z')); +// ARC_Lexer_RegisterTokenRule(lexer, ARC_LexerTokenRule_CreateAndReturnMatchCharOrBetween(TEST_PARSER_ALPHA_UPPER_CHAR, 'A', 'Z')); +//} +// +//uint32_t TEST_Parser_GetStringIdFn(ARC_String *string){ +// if(ARC_String_EqualsCStringWithStrlen(string, "")){ +// return TEST_PARSER_ALPHA_CHAR; +// } +// +// if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_LOWER_CHAR")){ +// return TEST_PARSER_ALPHA_LOWER_CHAR; +// } +// +// if(ARC_String_EqualsCStringWithStrlen(string, "ALPHA_UPPER_CHAR")){ +// return TEST_PARSER_ALPHA_UPPER_CHAR; +// } +// +// return ~(uint32_t)0; +//} +// +//void TEST_ParserData_CreateCharFn(void **data, ARC_ParserTagToken *parsedData, void *userData){ +// if(parsedData == NULL){ +// *data = NULL; +// return; +// } +// +// char *alphaChar = (char *)malloc(sizeof(char)); +// +// ARC_ParserTagToken *tagToken = (ARC_ParserTagToken *)ARC_Vector_Get(parsedData->tagTokens, 0); +// *alphaChar = tagToken->token->data->data[0]; +// +// *data = (void *)alphaChar; +//} +// +//void TEST_ParserData_DestroyCharFn(void *data, ARC_Bool clear, void *userData){ +// if(data == NULL){ +// return; +// } +// +// free((char *)data); +//} +// +//ARC_TEST(Parser_Parser_BasicCreateWithStringTest){ +// ARC_Parser *parser; +// +// /* ~ create the language ~ */ +// ARC_String *languageString; +// ARC_String_CreateWithStrlen(&languageString, " -> ALPHA_LOWER_CHAR | ALPHA_UPPER_CHAR\n"); +// +// ARC_ParserData_CreateFn createCharFn = TEST_ParserData_CreateCharFn; +// ARC_ParserData_DestroyFn destroyCharFn = TEST_ParserData_DestroyCharFn; +// ARC_Parser_CreateFromString(&parser, languageString, TEST_Parser_InitBasicLexerTokenRules, TEST_Parser_GetStringIdFn, &createCharFn, &destroyCharFn, NULL); +// +// ARC_String_Destroy(languageString); +// +// ARC_CHECK(arc_errno == 0); +// +// +// /* ~ check if a can be parsed ~ */ +// ARC_String *tempString; +// ARC_String_CreateWithStrlen(&tempString, "a"); +// +// ARC_Parser_Parse(parser, &tempString); +// +// char *data = (char *)ARC_Parser_GetData(parser); +// +// ARC_CHECK(*data == 'a'); +// +// ARC_Parser_ClearData(parser); +// +// +// /* ~ check if Z can be parsed ~ */ +// ARC_String_CreateWithStrlen(&tempString, "Z"); +// +// ARC_Parser_Parse(parser, &tempString); +// +// data = (char *)ARC_Parser_GetData(parser); +// +// ARC_CHECK(*data == 'Z'); +// +// ARC_Parser_ClearData(parser); +// +// +// /* ~ check if 8 errors ~ */ +// ARC_String_CreateWithStrlen(&tempString, "8"); +// +// ARC_Parser_Parse(parser, &tempString); +// +// data = (char *)ARC_Parser_GetData(parser); +// +// ARC_CHECK(arc_errno == ARC_ERRNO_DATA); +// arc_errno = 0; +// +// ARC_Parser_ClearData(parser); +// +// +// //cleanup +// ARC_Parser_Destroy(parser); +//}