Compare commits
10 commits
3b1972eb67
...
5fba766695
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fba766695 | ||
|
|
788147b8f2 | ||
|
|
55f2d46af1 | ||
|
|
a829b656f3 | ||
|
|
d89c95688e | ||
|
|
d01d78972e | ||
|
|
21a66f7fe6 | ||
|
|
017629872f | ||
|
|
5a9d7ca07d | ||
|
|
4b8b1a98c0 |
30 changed files with 670 additions and 387 deletions
|
|
@ -11,12 +11,13 @@ function(print var)
|
|||
message("${var} = ${${var}}")
|
||||
endfunction()
|
||||
|
||||
#TODO: Might want to remove this
|
||||
# ~ DEFAULT TO DEBUG IF TYPE NOT SET ~ #
|
||||
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"
|
||||
"$<$<CONFIG:DEBUG>:-O0;-g3;-ggdb;-DARC_DEBUG;>"
|
||||
|
|
|
|||
|
|
@ -1 +1,87 @@
|
|||
\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 =
|
||||
"<variable> -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>\n"
|
||||
"<variableName> -> <variableChar> <variableName> | LAMBDA\n"
|
||||
"<variableChar> -> 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, "<variable>")){
|
||||
return ARC_TEST_TAG_VARIABLE;
|
||||
}
|
||||
if(ARC_String_EqualsCStringWithStrlen(string, "<variableName>")){
|
||||
return ARC_TEST_TAG_VARIABLE_NAME;
|
||||
}
|
||||
if(ARC_String_EqualsCStringWithStrlen(string, "<variableChar>")){
|
||||
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);
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -5,22 +5,21 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @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 library you are using
|
||||
* @note ARC_RendererType is determined by which window backend 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
|
||||
*/
|
||||
|
|
@ -43,12 +42,63 @@ void ARC_Renderer_Clear(ARC_Renderer *renderer);
|
|||
/**
|
||||
* @brief renders the renderer
|
||||
*
|
||||
* @note the renderer will most likely be drawn to from ARC_EngineData
|
||||
*
|
||||
* @param renderer the renderer to render
|
||||
* @param renderer renders all buffers and current renderer to window
|
||||
*/
|
||||
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
|
||||
|
|
|
|||
|
|
@ -9,18 +9,43 @@ 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
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ typedef struct ARC_DCircle {
|
|||
double r;
|
||||
} ARC_DCircle;
|
||||
|
||||
void TEMP_Circle_Placeholder(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* @{
|
||||
|
|
@ -325,7 +335,9 @@ void ARC_Config_UnloadFromFile(ARC_Config *config, ARC_String *data);
|
|||
*/
|
||||
|
||||
/**
|
||||
* @brief TODO: write this
|
||||
* @brief inits a config type with the standard config settings
|
||||
*
|
||||
* @param config the config to init
|
||||
*/
|
||||
void ARC_Config_InitStd(ARC_Config *config);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ extern "C" {
|
|||
typedef struct ARC_EntitySystem ARC_EntitySystem;
|
||||
|
||||
/**
|
||||
* @brief an entity component system type
|
||||
* @brief an entity type (just an id)
|
||||
*/
|
||||
typedef uint32_t ARC_Entity;
|
||||
|
||||
/**
|
||||
* @brief an entity component system type
|
||||
* @brief flags to define an entities current state
|
||||
*/
|
||||
typedef enum ARC_EntityFlags {
|
||||
ARC_ENTITY_DEAD = 0,
|
||||
|
|
@ -33,12 +33,16 @@ typedef enum ARC_EntityFlags {
|
|||
typedef uint32_t ARC_EntityComponent;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @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
|
||||
*/
|
||||
typedef void (* ARC_EntityCoponent_CreateEmptyFn)(void **type);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @brief creates an empty entity system, use ARC_EntitySystem_RegisterComponent to add compenents to the entity system
|
||||
*
|
||||
* @parm[out] entitySystem an empty entity system
|
||||
*/
|
||||
void ARC_EntitySystem_Create(ARC_EntitySystem **entitySystem);
|
||||
|
||||
|
|
@ -57,37 +61,68 @@ 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 an id for for the component
|
||||
* @return a uint32_t id for for the component
|
||||
*/
|
||||
uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint32_t componentSize);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @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
|
||||
*/
|
||||
ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @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
|
||||
*/
|
||||
void ARC_EntitySystem_ReleaseEntity(ARC_EntitySystem *entitySystem, ARC_Entity entity);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @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 *
|
||||
*/
|
||||
void ARC_EntitySystem_AddComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component, void *data);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @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
|
||||
*/
|
||||
ARC_Bool ARC_EntitySystem_HasComponent(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @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
|
||||
*/
|
||||
void *ARC_EntitySystem_GetComponentData(ARC_EntitySystem *entitySystem, ARC_Entity entity, ARC_EntityComponent component);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @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
|
||||
*/
|
||||
ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, ARC_Array components);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ extern int32_t arc_errno;
|
|||
extern FILE *arc_errno_log_file;
|
||||
|
||||
#ifndef ARC_DEBUG_LOG_STREAM_OVERRIDE
|
||||
//this functin will be called on start, handy to set the log file to stdout if it is not overrided
|
||||
//this function 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
|
||||
|
|
|
|||
|
|
@ -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 vector
|
||||
* @brief gets size of elements stored in the handler
|
||||
*
|
||||
* @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_
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderLine((SDL_Renderer *)renderer, point1.x, point1.y, point2.x, point2.y);
|
||||
SDL_SetRenderDrawColor(renderer->renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderLine(renderer->renderer, point1.x, point1.y, point2.x, point2.y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderRect((SDL_Renderer *)renderer, (SDL_FRect *)&rect);
|
||||
SDL_SetRenderDrawColor(renderer->renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderRect(renderer->renderer, (SDL_FRect *)&rect);
|
||||
}
|
||||
|
||||
void ARC_FRect_RenderFill(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderFillRect((SDL_Renderer *)renderer, (SDL_FRect *)&rect);
|
||||
SDL_SetRenderDrawColor(renderer->renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderFillRect(renderer->renderer, (SDL_FRect *)&rect);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,22 @@
|
|||
#include <stdlib.h>
|
||||
#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;
|
||||
|
|
@ -14,26 +28,109 @@ void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *
|
|||
return;
|
||||
}
|
||||
|
||||
*renderer = (ARC_Renderer *)SDL_CreateRenderer((SDL_Window *)(data->window), NULL);
|
||||
*renderer = (ARC_Renderer *)malloc(sizeof(ARC_Renderer));
|
||||
|
||||
if(!*renderer){
|
||||
/* ~ Renderer ~ */
|
||||
(*renderer)->renderer = SDL_CreateRenderer((SDL_Window *)(data->window), NULL);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawBlendMode((SDL_Renderer *)*renderer, SDL_BLENDMODE_BLEND);
|
||||
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 };
|
||||
}
|
||||
|
||||
void ARC_Renderer_Destroy(ARC_Renderer *renderer){
|
||||
SDL_DestroyRenderer((SDL_Renderer *) renderer);
|
||||
ARC_Hashtable_Destroy(renderer->buffers);
|
||||
SDL_DestroyRenderer(renderer->renderer);
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
void ARC_Renderer_Clear(ARC_Renderer *renderer){
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x1c, 0x2c, 0x3c, 0xff);
|
||||
SDL_RenderClear((SDL_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){
|
||||
SDL_RenderPresent((SDL_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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
#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 <SDL3/SDL.h>
|
||||
|
||||
typedef SDL_Renderer ARC_RendererType;
|
||||
typedef struct ARC_RendererType {
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
ARC_Hashtable *buffers;
|
||||
|
||||
ARC_Color clearColor;
|
||||
} ARC_RendererType;
|
||||
|
||||
#endif // !ARC_SDL_RENDERER_H_
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "arc/graphics/sprite.h"
|
||||
|
||||
#include "renderer.h"
|
||||
#include "spritesheet.h"
|
||||
#include "arc/math/point.h"
|
||||
#include "arc/math/rectangle.h"
|
||||
|
|
@ -41,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((SDL_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){
|
||||
|
|
@ -64,7 +65,7 @@ void ARC_Sprite_RenderAt(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_FPoint
|
|||
flip |= SDL_FLIP_VERTICAL;
|
||||
}
|
||||
|
||||
SDL_RenderTextureRotated((SDL_Renderer *)renderer, sprite->spritesheet->texture, (SDL_FRect *)&sourceRect, (SDL_FRect *)&destinationRect, sprite->angle, (SDL_FPoint *)&(sprite->origin), flip);
|
||||
SDL_RenderTextureRotated(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){
|
||||
|
|
|
|||
|
|
@ -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((SDL_Renderer *)renderer, surface);
|
||||
(*spritesheet)->texture = SDL_CreateTextureFromSurface(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((SDL_Renderer *)renderer, spritesheet->texture, NULL, (SDL_FRect *)&renderBounds);
|
||||
SDL_RenderTexture(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((SDL_Renderer *)renderer, spritesheet->texture, (SDL_FRect *)&bounds, (SDL_FRect *)&renderBounds);
|
||||
SDL_RenderTexture(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((SDL_Renderer *)renderer, spritesheet->texture, (SDL_FRect *)&sheetBounds, (SDL_FRect *)&renderBounds);
|
||||
SDL_RenderTexture(renderer->renderer, spritesheet->texture, (SDL_FRect *)&sheetBounds, (SDL_FRect *)&renderBounds);
|
||||
}
|
||||
|
||||
ARC_Point ARC_Spritesheet_GetSize(ARC_Spritesheet *spritesheet){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "arc/graphics/text.h"
|
||||
|
||||
#include "text.h"
|
||||
#include "renderer.h"
|
||||
#include "arc/graphics/color.h"
|
||||
#include "arc/math/point.h"
|
||||
#include "arc/math/rectangle.h"
|
||||
|
|
@ -12,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) {
|
||||
|
|
@ -26,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);
|
||||
|
|
@ -42,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((SDL_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((SDL_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){
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#include "arc/graphics/view.h"
|
||||
|
||||
#include "arc/std/errno.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void ARC_View_Create(ARC_View **view, ARC_Renderer *renderer, ARC_Rect bounds){
|
||||
|
|
@ -15,19 +15,19 @@ 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(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_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;
|
||||
// }
|
||||
}
|
||||
|
||||
ARC_Rect ARC_View_GetBounds(ARC_View *view){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
#include "arc/math/circle.h"
|
||||
|
||||
void TEMP_Circle_Placeholder(void){
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -16,3 +16,15 @@ void ARC_Vector2_RotateDegree(ARC_Vector2 *vector, float angle){
|
|||
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 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
@ -1417,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;
|
||||
|
|
@ -1425,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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
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){
|
||||
|
|
@ -121,7 +124,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);
|
||||
|
|
@ -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){
|
||||
|
|
@ -179,7 +183,7 @@ ARC_Array ARC_EntitySystem_QueryComponentsData(ARC_EntitySystem *entitySystem, A
|
|||
componentsMask |= (1 << ((ARC_EntityComponent *)components.data)[index]);
|
||||
}
|
||||
|
||||
//setup teh components data and get a return size
|
||||
//setup the 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
|
||||
|
|
|
|||
|
|
@ -2,268 +2,129 @@
|
|||
#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 <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//TODO: rewrite these tests. ARC_Config does use both the parser and lexer so for now (very temporary) its tests function for these ones
|
||||
//TODO: add more tests
|
||||
const char *languageCString =
|
||||
"<variable> -> ALPHA_UPPER_CHAR <variableName> | ALPHA_LOWER_CHAR <variableName> | UNDERSCORE <variableName>\n"
|
||||
"<variableName> -> <variableChar> <variableName> | LAMBDA\n"
|
||||
"<variableChar> -> ALPHA_UPPER_CHAR | ALPHA_LOWER_CHAR | UNDERSCORE | NUMBER\n";
|
||||
|
||||
//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, "<alphaChar>")){
|
||||
// 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, "<alphaChar> -> 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);
|
||||
//}
|
||||
#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, "<variable>")){
|
||||
return ARC_TEST_TAG_VARIABLE;
|
||||
}
|
||||
if(ARC_String_EqualsCStringWithStrlen(string, "<variableName>")){
|
||||
return ARC_TEST_TAG_VARIABLE_NAME;
|
||||
}
|
||||
if(ARC_String_EqualsCStringWithStrlen(string, "<variableChar>")){
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue