diff --git a/README.md b/README.md index 9dfbc03..4dcdcef 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,4 @@ Make sure to link seika to whatever uses it with `target_link_libraries`. Example projects found [here](https://github.com/Chukobyte/seika-examples). -*Note: Using v0.0.x versions as pre-alpha, won't create full releases until minor version is incremented.* +*Warning: Using v0.0.x versions as pre-alpha, so expect naming inconsistencies and other holdovers from being a part of [crescent](https://github.com/Chukobyte/crescent) until v0.x.x. diff --git a/seika/data_structures/se_spatial_hash_map.c b/seika/data_structures/se_spatial_hash_map.c index 3a82095..882bca4 100644 --- a/seika/data_structures/se_spatial_hash_map.c +++ b/seika/data_structures/se_spatial_hash_map.c @@ -14,9 +14,9 @@ typedef struct PositionHashes { int32_t hashes[SE_SPATIAL_HASH_MAX_POSITION_HASH]; } PositionHashes; -void spatial_hash_map_update(SESpatialHashMap* hashMap, unsigned int entity, SESpatialHashMapGridSpacesHandle* handle, SERect2* collisionRect); -bool change_cell_size_if_needed(SESpatialHashMap* hashMap, SERect2* collisionRectToCheck); -int32_t spatial_hash(SESpatialHashMap* hashMap, SEVector2* position); +void spatial_hash_map_update(SESpatialHashMap* hashMap, unsigned int entity, SESpatialHashMapGridSpacesHandle* handle, SKARect2* collisionRect); +bool change_cell_size_if_needed(SESpatialHashMap* hashMap, SKARect2* collisionRectToCheck); +int32_t spatial_hash(SESpatialHashMap* hashMap, SKAVector2* position); void spatial_hash_map_destroy_node(SESpatialHashMap* hashMap); SESpatialHashMapGridSpace* get_or_create_grid_space(SESpatialHashMap* hashMap, int32_t positionHash); bool link_object_by_position_hash(SESpatialHashMap* hashMap, SESpatialHashMapGridSpacesHandle* object, unsigned int value, int32_t positionHash, PositionHashes* hashes); @@ -55,7 +55,7 @@ void se_spatial_hash_map_destroy(SESpatialHashMap* hashMap) { } // The purpose of this function is to make sure that 'cellSize' is twice as big as the largest object -bool change_cell_size_if_needed(SESpatialHashMap* hashMap, SERect2* collisionRectToCheck) { +bool change_cell_size_if_needed(SESpatialHashMap* hashMap, SKARect2* collisionRectToCheck) { const int objectMaxSize = collisionRectToCheck->h > collisionRectToCheck->w ? (int)collisionRectToCheck->h : (int)collisionRectToCheck->w; // Update largest object size of hashmap if applicable if (objectMaxSize > hashMap->largestObjectSize) { @@ -70,12 +70,12 @@ bool change_cell_size_if_needed(SESpatialHashMap* hashMap, SERect2* collisionRec return false; } -SESpatialHashMapGridSpacesHandle* se_spatial_hash_map_insert_or_update(SESpatialHashMap* hashMap, unsigned int entity, SERect2* collisionRect) { +SESpatialHashMapGridSpacesHandle* se_spatial_hash_map_insert_or_update(SESpatialHashMap* hashMap, unsigned int entity, SKARect2* collisionRect) { // Create new object handle if it doesn't exist if (!se_hash_map_has(hashMap->objectToGridMap, &entity)) { SESpatialHashMapGridSpacesHandle* newHandle = SE_MEM_ALLOCATE(SESpatialHashMapGridSpacesHandle); newHandle->gridSpaceCount = 0; - newHandle->collisionRect = (SERect2) { + newHandle->collisionRect = (SKARect2) { 0.0f, 0.0f, 0.0f, 0.0f }; se_hash_map_add(hashMap->objectToGridMap, &entity, &newHandle); @@ -98,8 +98,8 @@ SESpatialHashMapGridSpacesHandle* se_spatial_hash_map_insert_or_update(SESpatial return objectHandle; } -void spatial_hash_map_update(SESpatialHashMap* hashMap, unsigned int entity, SESpatialHashMapGridSpacesHandle* handle, SERect2* collisionRect) { - memcpy(&handle->collisionRect, collisionRect, sizeof(SERect2)); +void spatial_hash_map_update(SESpatialHashMap* hashMap, unsigned int entity, SESpatialHashMapGridSpacesHandle* handle, SKARect2* collisionRect) { + memcpy(&handle->collisionRect, collisionRect, sizeof(SKARect2)); // Unlink all previous spaces and objects unlink_all_objects_by_entity(hashMap, handle, entity); @@ -107,22 +107,22 @@ void spatial_hash_map_update(SESpatialHashMap* hashMap, unsigned int entity, SES // Add values to spaces and spaces to object handles (moving clockwise starting from top-left) PositionHashes hashes = { .hashCount = 0 }; // Top left - const int32_t topLeftHash = spatial_hash(hashMap, &(SEVector2) { + const int32_t topLeftHash = spatial_hash(hashMap, &(SKAVector2) { collisionRect->x, collisionRect->y }); link_object_by_position_hash(hashMap, handle, entity, topLeftHash, &hashes); // Top right - const int32_t topRightHash = spatial_hash(hashMap, &(SEVector2) { + const int32_t topRightHash = spatial_hash(hashMap, &(SKAVector2) { collisionRect->x + collisionRect->w, collisionRect->y }); link_object_by_position_hash(hashMap, handle, entity, topRightHash, &hashes); // Bottom Left - const int32_t bottomLeftHash = spatial_hash(hashMap, &(SEVector2) { + const int32_t bottomLeftHash = spatial_hash(hashMap, &(SKAVector2) { collisionRect->x, collisionRect->y + collisionRect->h }); link_object_by_position_hash(hashMap, handle, entity, bottomLeftHash, &hashes); // Bottom Right - const int32_t bottomRightHash = spatial_hash(hashMap, &(SEVector2) { + const int32_t bottomRightHash = spatial_hash(hashMap, &(SKAVector2) { collisionRect->x + collisionRect->w, collisionRect->y + collisionRect->h }); link_object_by_position_hash(hashMap, handle, entity, bottomRightHash, &hashes); @@ -190,7 +190,7 @@ SESpatialHashMapCollisionResult se_spatial_hash_map_compute_collision(SESpatialH } // Internal Functions -int32_t spatial_hash(SESpatialHashMap* hashMap, SEVector2* position) { +int32_t spatial_hash(SESpatialHashMap* hashMap, SKAVector2* position) { const int32_t x = (int32_t) position->x / hashMap->cellSize; const int32_t y = (int32_t) position->y / hashMap->cellSize; const int32_t hash = ((x * x) ^ (y * y)) % INT32_MAX; diff --git a/seika/data_structures/se_spatial_hash_map.h b/seika/data_structures/se_spatial_hash_map.h index a482c31..1cd0782 100644 --- a/seika/data_structures/se_spatial_hash_map.h +++ b/seika/data_structures/se_spatial_hash_map.h @@ -17,7 +17,7 @@ typedef struct SESpatialHashMapGridSpace { // Contains all grid spaces an object is assigned to typedef struct SESpatialHashMapGridSpacesHandle { size_t gridSpaceCount; - SERect2 collisionRect; + SKARect2 collisionRect; SESpatialHashMapGridSpace* gridSpaces[4]; } SESpatialHashMapGridSpacesHandle; @@ -37,7 +37,7 @@ typedef struct SESpatialHashMapCollisionResult { SESpatialHashMap* se_spatial_hash_map_create(int initialCellSize); void se_spatial_hash_map_destroy(SESpatialHashMap* hashMap); -SESpatialHashMapGridSpacesHandle* se_spatial_hash_map_insert_or_update(SESpatialHashMap* hashMap, unsigned int entity, SERect2* collisionRect); +SESpatialHashMapGridSpacesHandle* se_spatial_hash_map_insert_or_update(SESpatialHashMap* hashMap, unsigned int entity, SKARect2* collisionRect); void se_spatial_hash_map_remove(SESpatialHashMap* hashMap, unsigned int entity); SESpatialHashMapGridSpacesHandle* se_spatial_hash_map_get(SESpatialHashMap* hashMap, unsigned int entity); SESpatialHashMapCollisionResult se_spatial_hash_map_compute_collision(SESpatialHashMap* hashMap, unsigned int entity); diff --git a/seika/data_structures/se_tile_map.h b/seika/data_structures/se_tile_map.h index 4e6079e..669ed47 100644 --- a/seika/data_structures/se_tile_map.h +++ b/seika/data_structures/se_tile_map.h @@ -6,17 +6,17 @@ #define SE_TILE_MAP_MAX_TILES 36 typedef struct SETile { - SEVector2 position; + SKAVector2 position; } SETile; typedef struct SETileMap { SETexture* tileSpriteSheet; - SEVector2 tileSize; + SKAVector2 tileSize; SETile tiles[36]; } SETileMap; SETileMap* se_tile_map_create(SETexture* tileSpriteSheet); -void se_tile_map_add_tile(SETileMap* tileMap, SEVector2 position); -SETile* se_tile_map_get_tile(SETileMap* tileMap, SEVector2 position); -SETile* se_tile_map_has_tile(SETileMap* tileMap, SEVector2 position); +void se_tile_map_add_tile(SETileMap* tileMap, SKAVector2 position); +SETile* se_tile_map_get_tile(SETileMap* tileMap, SKAVector2 position); +SETile* se_tile_map_has_tile(SETileMap* tileMap, SKAVector2 position); void se_tile_map_destroy(SETileMap* tileMap); diff --git a/seika/input/input.c b/seika/input/input.c index 186b3a1..0888265 100644 --- a/seika/input/input.c +++ b/seika/input/input.c @@ -772,8 +772,8 @@ void input_gamepad_cleanup_flags() { void se_input_gamepad_start_vibration(int device, float weakMagnitude, float strongMagnitude, float durationSeconds) { for (int i = 0; i < activeGamepadCount; i++) { if (i == device) { - weakMagnitude = se_math_clamp_float(weakMagnitude, 0.0f, 1.0f); - strongMagnitude = se_math_clamp_float(strongMagnitude, 0.0f, 1.0f); + weakMagnitude = ska_math_clamp_float(weakMagnitude, 0.0f, 1.0f); + strongMagnitude = ska_math_clamp_float(strongMagnitude, 0.0f, 1.0f); const Uint16 weakMag = (Uint16)(weakMagnitude * 65535.0f + 0.5f); const Uint16 strongMag = (Uint16)(strongMagnitude * 65535.0f + 0.5f); const Uint32 durationMilliseconds = (Uint32)(durationSeconds * 1000.0f); diff --git a/seika/input/mouse.h b/seika/input/mouse.h index 45367b1..1222abc 100644 --- a/seika/input/mouse.h +++ b/seika/input/mouse.h @@ -3,7 +3,7 @@ #include "../math/se_math.h" typedef struct SEMouse { - SEVector2 position; + SKAVector2 position; } SEMouse; SEMouse* se_mouse_get(); diff --git a/seika/math/se_curve_float.c b/seika/math/se_curve_float.c index 6623059..e9cbf7e 100644 --- a/seika/math/se_curve_float.c +++ b/seika/math/se_curve_float.c @@ -48,7 +48,7 @@ void se_curve_float_add_control_points(SECurveFloat* curve, SECurveControlPoint bool se_curve_float_remove_control_point(SECurveFloat* curve, double x, double y) { for (size_t i = 0; i < curve->controlPointCount; i++) { SECurveControlPoint* point = &curve->controlPoints[i]; - if (se_math_is_almost_equal_double_default(x, point->x) && se_math_is_almost_equal_double_default(y, point->y)) { + if (ska_math_is_almost_equal_double_default(x, point->x) && ska_math_is_almost_equal_double_default(y, point->y)) { // We've found a matching point so set it's x to the highest value, sort it, then decrement the point count. point->x = DBL_MAX; selection_sort_curve_float(curve); diff --git a/seika/math/se_math.c b/seika/math/se_math.c index ab988c3..0bb0c5e 100644 --- a/seika/math/se_math.c +++ b/seika/math/se_math.c @@ -1,19 +1,19 @@ #include "se_math.h" // --- Vector2 --- // -bool se_math_vec2_equals(const SEVector2* v1, const SEVector2* v2) { +bool ska_math_vec2_equals(const SKAVector2* v1, const SKAVector2* v2) { return v1->x == v2->x && v1->y == v2->y; } -SEVector2 se_math_vec2_lerp(const SEVector2* v1, const SEVector2* v2, float t) { - return (SEVector2) { - .x = se_math_lerpf(v1->x, v2->x, t), - .y = se_math_lerpf(v1->y, v2->y, t) +SKAVector2 ska_math_vec2_lerp(const SKAVector2* v1, const SKAVector2* v2, float t) { + return (SKAVector2) { + .x = ska_math_lerpf(v1->x, v2->x, t), + .y = ska_math_lerpf(v1->y, v2->y, t) }; } // --- Rect2 --- // -bool se_rect2_does_rectangles_overlap(const SERect2* sourceRect, const SERect2* targetRect) { +bool se_rect2_does_rectangles_overlap(const SKARect2* sourceRect, const SKARect2* targetRect) { return (sourceRect->x + sourceRect->w >= targetRect->x) && (targetRect->x + targetRect->w >= sourceRect->x) && (sourceRect->y + sourceRect->h >= targetRect->y) && @@ -21,8 +21,8 @@ bool se_rect2_does_rectangles_overlap(const SERect2* sourceRect, const SERect2* } // --- Color --- // -SEColor se_color_get_normalized_color_default_alpha(unsigned int r, unsigned int g, unsigned int b) { - SEColor color = { +SKAColor ska_color_get_normalized_color_default_alpha(unsigned int r, unsigned int g, unsigned int b) { + SKAColor color = { .r = (float) r / 255.0f, .g = (float) g / 255.0f, .b = (float) b / 255.0f, @@ -31,8 +31,8 @@ SEColor se_color_get_normalized_color_default_alpha(unsigned int r, unsigned int return color; } -SEColor se_color_get_normalized_color(unsigned int r, unsigned int g, unsigned int b, unsigned int a) { - SEColor color = { +SKAColor ska_color_get_normalized_color(unsigned int r, unsigned int g, unsigned int b, unsigned int a) { + SKAColor color = { .r = (float) r / 255.0f, .g = (float) g / 255.0f, .b = (float) b / 255.0f, @@ -41,8 +41,8 @@ SEColor se_color_get_normalized_color(unsigned int r, unsigned int g, unsigned i return color; } -SEColor se_color_get_normalized_color_from_color(const SEColor* color) { - SEColor newColor = { +SKAColor ska_color_get_normalized_color_from_color(const SKAColor* color) { + SKAColor newColor = { .r = color->r / 255.0f, .g = color->g / 255.0f, .b = color->b / 255.0f, @@ -51,33 +51,33 @@ SEColor se_color_get_normalized_color_from_color(const SEColor* color) { return newColor; } -SEColor se_color_get_white() { - SEColor white = { 1.0f, 1.0f, 1.0f, 1.0f }; +SKAColor ska_color_get_white() { + SKAColor white = {1.0f, 1.0f, 1.0f, 1.0f }; return white; } // --- Misc --- // -float se_math_lerpf(float a, float b, float t) { +float ska_math_lerpf(float a, float b, float t) { return a + (b - a) * t; } -float se_math_map_to_range(float input, float inputMin, float inputMax, float outputMin, float outputMax) { +float ska_math_map_to_range(float input, float inputMin, float inputMax, float outputMin, float outputMax) { return (((input - inputMin) / (inputMax - inputMin)) * (outputMax - outputMin) + outputMin); } -float se_math_map_to_unit(float input, float inputMin, float inputMax) { - return se_math_map_to_range(input, inputMin, inputMax, 0.0f, 1.0f); +float ska_math_map_to_unit(float input, float inputMin, float inputMax) { + return ska_math_map_to_range(input, inputMin, inputMax, 0.0f, 1.0f); } -double se_math_map_to_range_double(double input, double inputMin, double inputMax, double outputMin, double outputMax) { +double ska_math_map_to_range_double(double input, double inputMin, double inputMax, double outputMin, double outputMax) { return (((input - inputMin) / (inputMax - inputMin)) * (outputMax - outputMin) + outputMin); } -double se_math_map_to_unit_double(double input, double inputMin, double inputMax) { - return se_math_map_to_range_double(input, inputMin, inputMax, 0.0, 1.0); +double ska_math_map_to_unit_double(double input, double inputMin, double inputMax) { + return ska_math_map_to_range_double(input, inputMin, inputMax, 0.0, 1.0); } -float se_math_signf(float value) { +float ska_math_signf(float value) { if (value > 0.0f) { return 1.0f; } else if(value < 0.0f) { @@ -86,36 +86,36 @@ float se_math_signf(float value) { return 0.0f; } -SEVector2 se_math_signvec2(SEVector2* value) { - SEVector2 sign_vec = { - .x = se_math_signf(value->x), - .y = se_math_signf(value->y) +SKAVector2 ska_math_signvec2(SKAVector2* value) { + SKAVector2 sign_vec = { + .x = ska_math_signf(value->x), + .y = ska_math_signf(value->y) }; return sign_vec; } -int se_math_clamp_int(int value, int min, int max) { +int ska_math_clamp_int(int value, int min, int max) { return value < min ? min : (value > max ? max : value); } -float se_math_clamp_float(float value, float min, float max) { +float ska_math_clamp_float(float value, float min, float max) { return value < min ? min : (value > max ? max : value); } -bool se_math_is_almost_equal_float(float v1, float v2, float epsilon) { +bool ska_math_is_almost_equal_float(float v1, float v2, float epsilon) { return fabsf(v1 - v2) <= epsilon; } -bool se_math_is_almost_equal_float_default(float v1, float v2) { +bool ska_math_is_almost_equal_float_default(float v1, float v2) { static const double epsilon = 0.001f; return fabsf(v1 - v2) <= epsilon; } -bool se_math_is_almost_equal_double(double v1, double v2, double epsilon) { +bool ska_math_is_almost_equal_double(double v1, double v2, double epsilon) { return fabs(v1 - v2) <= epsilon; } -bool se_math_is_almost_equal_double_default(double v1, double v2) { +bool ska_math_is_almost_equal_double_default(double v1, double v2) { static const double epsilon = 0.001; return fabs(v1 - v2) <= epsilon; } diff --git a/seika/math/se_math.h b/seika/math/se_math.h index 22443ff..ed72e46 100644 --- a/seika/math/se_math.h +++ b/seika/math/se_math.h @@ -10,104 +10,120 @@ extern "C" { #include -#define SE_PI 3.14159265358979323846f -#define SE_RAD_2_DEG (180.0f / SE_PI) +#define SKA_PI 3.14159265358979323846f +#define SKA_RAD_2_DEG (180.0f / SKA_PI) -// --- SEVector2 --- // -typedef struct SEVector2 { +// --- SKAVector2 --- // +typedef struct SKAVector2 { float x; float y; -} SEVector2; +} SKAVector2; -bool se_math_vec2_equals(const SEVector2* v1, const SEVector2* v2); -SEVector2 se_math_vec2_lerp(const SEVector2* v1, const SEVector2* v2, float t); +#define SKA_VECTOR2_ZERO (SEVector2){ 0.0f, 0.0f } +#define SKA_VECTOR2_LEFT (SEVector2){ -1.0f, 0.0f } +#define SKA_VECTOR2_RIGHT (SEVector2){ 1.0f, 0.0f } +#define SKA_VECTOR2_UP (SEVector2){ 0.0f, -1.0f } +#define SKA_VECTOR2_DOWN (SEVector2){ 0.0f, 1.0f } -// --- SEVector2i --- // -typedef struct SEVector2i { +bool ska_math_vec2_equals(const SKAVector2* v1, const SKAVector2* v2); +SKAVector2 ska_math_vec2_lerp(const SKAVector2* v1, const SKAVector2* v2, float t); + +// --- SKAVector2i --- // +typedef struct SKAVector2i { int x; int y; -} SEVector2i; +} SKAVector2i; -// --- SESize2D --- // -typedef struct SESize2D { +// --- SKASize2D --- // +typedef struct SKASize2D { float w; float h; -} SESize2D; +} SKASize2D; + +#define SKA_SIZE2D_ZERO (SESize2D){ 0.0f, 0.0f } -// --- SESize2Di --- // -typedef struct SESize2Di { +// --- SKASize2Di --- // +typedef struct SKASize2Di { int w; int h; -} SESize2Di; +} SKASize2Di; -// --- SERect2 --- // -typedef struct SERect2 { +// --- SKARect2 --- // +typedef struct SKARect2 { float x; float y; float w; float h; -} SERect2; +} SKARect2; -bool se_rect2_does_rectangles_overlap(const SERect2* sourceRect, const SERect2* targetRect); +#define SKA_RECT2D_ZERO (SESize2D){ 0.0f, 0.0f, 0.0f, 0.0f } -//--- SETransform2D ---// -typedef struct SETransform2D { - SEVector2 position; - SEVector2 scale; +bool se_rect2_does_rectangles_overlap(const SKARect2* sourceRect, const SKARect2* targetRect); + +//--- SKATransform2D ---// +typedef struct SKATransform2D { + SKAVector2 position; + SKAVector2 scale; float rotation; // degrees -} SETransform2D; +} SKATransform2D; -typedef struct SETransformModel2D { - SEVector2 position; - SEVector2 scale; +typedef struct SKATransformModel2D { + SKAVector2 position; + SKAVector2 scale; float rotation; // degrees int zIndex; - SEVector2 scaleSign; + SKAVector2 scaleSign; mat4 model; -} SETransformModel2D; +} SKATransformModel2D; -// --- SEVector3 --- // -typedef struct SEVector3 { +// --- SKAVector3 --- // +typedef struct SKAVector3 { float x; float y; float z; -} SEVector3; +} SKAVector3; -// --- SEVector4 --- // -typedef struct SEVector4 { +// --- SKAVector4 --- // +typedef struct SKAVector4 { float x; float y; float z; float w; -} SEVector4; +} SKAVector4; -// --- SEColor --- // -typedef struct SEColor { +// --- SKAColor --- // +typedef struct SKAColor { float r; float g; float b; float a; -} SEColor; +} SKAColor; + +#define SKA_COLOR_WHITE (SKAColor){ 1.0f, 1.0f, 1.0f, 1.0f } +#define SKA_COLOR_BLACK (SKAColor){ 0.0f, 0.0f, 0.0f, 1.0f } +#define SKA_COLOR_RED (SKAColor){ 1.0f, 0.0f, 0.0f, 1.0f } +#define SKA_COLOR_GREEN (SKAColor){ 0.0f, 1.0f, 0.0f, 1.0f } +#define SKA_COLOR_BLUE (SKAColor){ 0.0f, 0.0f, 1.0f, 1.0f } -SEColor se_color_get_normalized_color_default_alpha(unsigned int r, unsigned int g, unsigned int b); -SEColor se_color_get_normalized_color(unsigned int r, unsigned int g, unsigned int b, unsigned int a); -SEColor se_color_get_normalized_color_from_color(const SEColor* color); -SEColor se_color_get_white(); +SKAColor ska_color_get_normalized_color_default_alpha(unsigned int r, unsigned int g, unsigned int b); +SKAColor ska_color_get_normalized_color(unsigned int r, unsigned int g, unsigned int b, unsigned int a); +SKAColor ska_color_get_normalized_color_from_color(const SKAColor* color); +SKAColor ska_color_get_white(); // --- Misc --- // -float se_math_lerpf(float a, float b, float t); -float se_math_map_to_range(float input, float inputMin, float inputMax, float outputMin, float outputMax); -float se_math_map_to_unit(float input, float inputMin, float inputMax); -double se_math_map_to_range_double(double input, double inputMin, double inputMax, double outputMin, double outputMax); -double se_math_map_to_unit_double(double input, double inputMin, double inputMax); -float se_math_signf(float value); -SEVector2 se_math_signvec2(SEVector2* value); -int se_math_clamp_int(int value, int min, int max); -float se_math_clamp_float(float value, float min, float max); -bool se_math_is_almost_equal_float(float v1, float v2, float epsilon); -bool se_math_is_almost_equal_float_default(float v1, float v2); -bool se_math_is_almost_equal_double(double v1, double v2, double epsilon); -bool se_math_is_almost_equal_double_default(double v1, double v2); +float ska_math_lerpf(float a, float b, float t); +float ska_math_map_to_range(float input, float inputMin, float inputMax, float outputMin, float outputMax); +float ska_math_map_to_unit(float input, float inputMin, float inputMax); +double ska_math_map_to_range_double(double input, double inputMin, double inputMax, double outputMin, double outputMax); +double ska_math_map_to_unit_double(double input, double inputMin, double inputMax); +float ska_math_signf(float value); +SKAVector2 ska_math_signvec2(SKAVector2* value); +int ska_math_clamp_int(int value, int min, int max); +float ska_math_clamp_float(float value, float min, float max); +bool ska_math_is_almost_equal_float(float v1, float v2, float epsilon); +bool ska_math_is_almost_equal_float_default(float v1, float v2); +bool ska_math_is_almost_equal_double(double v1, double v2, double epsilon); +bool ska_math_is_almost_equal_double_default(double v1, double v2); #ifdef __cplusplus } diff --git a/seika/rendering/font.h b/seika/rendering/font.h index dc6af00..e06aff9 100644 --- a/seika/rendering/font.h +++ b/seika/rendering/font.h @@ -8,8 +8,8 @@ typedef struct SECharacter { GLuint textureId; - SEVector2 size; - SEVector2 bearing; + SKAVector2 size; + SKAVector2 bearing; unsigned int advance; } SECharacter; diff --git a/seika/rendering/frame_buffer.h b/seika/rendering/frame_buffer.h index 900c03c..9614014 100644 --- a/seika/rendering/frame_buffer.h +++ b/seika/rendering/frame_buffer.h @@ -22,8 +22,8 @@ void se_frame_buffer_set_screen_shader(struct SEShaderInstance* shaderInstance); void se_frame_buffer_reset_to_default_screen_shader(); typedef struct FrameBufferViewportData { - SEVector2i position; - SESize2Di size; + SKAVector2i position; + SKASize2Di size; } FrameBufferViewportData; FrameBufferViewportData se_frame_buffer_generate_viewport_data(int windowWidth, int windowHeight); diff --git a/seika/rendering/renderer.c b/seika/rendering/renderer.c index 16a8fa2..f43bf58 100644 --- a/seika/rendering/renderer.c +++ b/seika/rendering/renderer.c @@ -25,7 +25,7 @@ typedef struct TextureCoordinates { GLfloat tMax; } TextureCoordinates; -TextureCoordinates renderer_get_texture_coordinates(const SETexture* texture, const SERect2* drawSource, bool flipH, bool flipV); +TextureCoordinates renderer_get_texture_coordinates(const SETexture* texture, const SKARect2* drawSource, bool flipH, bool flipV); void renderer_set_shader_instance_params(SEShaderInstance* shaderInstance); void renderer_print_opengl_errors(); @@ -36,7 +36,7 @@ void sprite_renderer_update_resolution(); void font_renderer_initialize(); void font_renderer_finalize(); void font_renderer_update_resolution(); -void font_renderer_draw_text(const SEFont* font, const char* text, float x, float y, float scale, const SEColor* color); +void font_renderer_draw_text(const SEFont* font, const char* text, float x, float y, float scale, const SKAColor* color); static GLuint spriteQuadVAO; static GLuint spriteQuadVBO; @@ -59,12 +59,12 @@ static mat4 spriteProjection = { // Sprite Batching typedef struct SpriteBatchItem { SETexture* texture; - SERect2 sourceRect; - SESize2D destSize; - SEColor color; + SKARect2 sourceRect; + SKASize2D destSize; + SKAColor color; bool flipH; bool flipV; - SETransformModel2D* globalTransform; + SKATransformModel2D* globalTransform; SEShaderInstance* shaderInstance; } SpriteBatchItem; @@ -74,7 +74,7 @@ typedef struct FontBatchItem { float x; float y; float scale; - SEColor color; + SKAColor color; } FontBatchItem; void renderer_batching_draw_sprites(SpriteBatchItem items[], size_t spriteCount); @@ -138,8 +138,8 @@ void se_renderer_update_window_size(int windowWidth, int windowHeight) { const FrameBufferViewportData data = se_frame_buffer_generate_viewport_data(windowWidth, windowHeight); #else struct ViewportData { - SEVector2i position; - SESize2Di size; + SKAVector2i position; + SKASize2Di size; }; const struct ViewportData data = { .position = { .x = 0, .y = 0 }, .size = { .w = windowWidth, .h = windowHeight } }; #endif @@ -161,13 +161,13 @@ void update_active_render_layer_index(int zIndex) { } } -void se_renderer_queue_sprite_draw_call(SETexture* texture, SERect2 sourceRect, SESize2D destSize, SEColor color, bool flipH, bool flipV, SETransformModel2D* globalTransform, int zIndex, SEShaderInstance* shaderInstance) { +void se_renderer_queue_sprite_draw_call(SETexture* texture, SKARect2 sourceRect, SKASize2D destSize, SKAColor color, bool flipH, bool flipV, SKATransformModel2D* globalTransform, int zIndex, SEShaderInstance* shaderInstance) { if (texture == NULL) { se_logger_error("NULL texture, not submitting draw call!"); return; } SpriteBatchItem item = { .texture = texture, .sourceRect = sourceRect, .destSize = destSize, .color = color, .flipH = flipH, .flipV = flipV, .globalTransform = globalTransform, .shaderInstance = shaderInstance }; - const int arrayZIndex = se_math_clamp_int(zIndex + SE_RENDERER_MAX_Z_INDEX / 2, 0, SE_RENDERER_MAX_Z_INDEX - 1); + const int arrayZIndex = ska_math_clamp_int(zIndex + SE_RENDERER_MAX_Z_INDEX / 2, 0, SE_RENDERER_MAX_Z_INDEX - 1); // Get texture layer index for render texture size_t textureLayerIndex = render_layer_items[arrayZIndex].renderTextureLayerCount; for (size_t i = 0; i < render_layer_items[arrayZIndex].renderTextureLayerCount; i++) { @@ -186,14 +186,14 @@ void se_renderer_queue_sprite_draw_call(SETexture* texture, SERect2 sourceRect, update_active_render_layer_index(arrayZIndex); } -void se_renderer_queue_font_draw_call(SEFont* font, const char* text, float x, float y, float scale, SEColor color, int zIndex) { +void se_renderer_queue_font_draw_call(SEFont* font, const char* text, float x, float y, float scale, SKAColor color, int zIndex) { if (font == NULL) { se_logger_error("NULL font, not submitting draw call!"); return; } FontBatchItem item = { .font = font, .text = text, .x = x, .y = y, .scale = scale, .color = color }; - const int arrayZIndex = se_math_clamp_int(zIndex + SE_RENDERER_MAX_Z_INDEX / 2, 0, SE_RENDERER_MAX_Z_INDEX - 1); + const int arrayZIndex = ska_math_clamp_int(zIndex + SE_RENDERER_MAX_Z_INDEX / 2, 0, SE_RENDERER_MAX_Z_INDEX - 1); // Update font batch item on render layer render_layer_items[arrayZIndex].fontBatchItems[render_layer_items[arrayZIndex].fontBatchItemCount++] = item; // Update active render layer indices @@ -228,7 +228,7 @@ void se_renderer_flush_batches() { SE_STATIC_ARRAY_EMPTY(active_render_layer_items_indices); } -void se_renderer_process_and_flush_batches(const SEColor* backgroundColor) { +void se_renderer_process_and_flush_batches(const SKAColor* backgroundColor) { #ifdef SE_RENDER_TO_FRAMEBUFFER se_frame_buffer_bind(); #endif @@ -248,7 +248,7 @@ void se_renderer_process_and_flush_batches(const SEColor* backgroundColor) { se_frame_buffer_unbind(); // Clear screen texture background - static const SEColor screenBackgroundColor = { 0.0f, 0.0f, 0.0f, 1.0f }; + static const SKAColor screenBackgroundColor = {0.0f, 0.0f, 0.0f, 1.0f }; glClearColor(screenBackgroundColor.r, screenBackgroundColor.g, screenBackgroundColor.b, screenBackgroundColor.a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw screen texture from framebuffer @@ -267,7 +267,7 @@ void se_renderer_process_and_flush_batches(const SEColor* backgroundColor) { } #ifdef SE_RENDER_TO_FRAMEBUFFER -void se_renderer_process_and_flush_batches_just_framebuffer(const SEColor* backgroundColor) { +void se_renderer_process_and_flush_batches_just_framebuffer(const SKAColor* backgroundColor) { se_frame_buffer_bind(); // Clear framebuffer with background color @@ -444,8 +444,8 @@ void font_renderer_update_resolution() { se_shader_set_mat4_float(fontShader, "projection", &proj); } -void font_renderer_draw_text(const SEFont* font, const char* text, float x, float y, float scale, const SEColor* color) { - SEVector2 currentScale = { scale, scale }; +void font_renderer_draw_text(const SEFont* font, const char* text, float x, float y, float scale, const SKAColor* color) { + SKAVector2 currentScale = {scale, scale }; se_shader_use(fontShader); se_shader_set_vec4_float(fontShader, "textColor", color->r, color->g, color->b, color->a); glActiveTexture(GL_TEXTURE0); @@ -487,7 +487,7 @@ void font_renderer_draw_text(const SEFont* font, const char* text, float x, floa } // --- Misc --- // -TextureCoordinates renderer_get_texture_coordinates(const SETexture* texture, const SERect2* drawSource, bool flipH, bool flipV) { +TextureCoordinates renderer_get_texture_coordinates(const SETexture* texture, const SKARect2* drawSource, bool flipH, bool flipV) { GLfloat sMin = 0.0f; GLfloat sMax = 1.0f; GLfloat tMin = 0.0f; diff --git a/seika/rendering/renderer.h b/seika/rendering/renderer.h index d7e07c1..b16b1b3 100644 --- a/seika/rendering/renderer.h +++ b/seika/rendering/renderer.h @@ -17,10 +17,10 @@ void se_renderer_initialize(int inWindowWidth, int inWindowHeight, int inResolut void se_renderer_finalize(); void se_renderer_update_window_size(int windowWidth, int windowHeight); void se_renderer_set_sprite_shader_default_params(SEShader* shader); -void se_renderer_queue_sprite_draw_call(SETexture* texture, SERect2 sourceRect, SESize2D destSize, SEColor color, bool flipH, bool flipV, SETransformModel2D* globalTransform, int zIndex, SEShaderInstance* shaderInstance); -void se_renderer_queue_font_draw_call(SEFont* font, const char* text, float x, float y, float scale, SEColor color, int zIndex); -void se_renderer_process_and_flush_batches(const SEColor* backgroundColor); -void se_renderer_process_and_flush_batches_just_framebuffer(const SEColor* backgroundColor); +void se_renderer_queue_sprite_draw_call(SETexture* texture, SKARect2 sourceRect, SKASize2D destSize, SKAColor color, bool flipH, bool flipV, SKATransformModel2D* globalTransform, int zIndex, SEShaderInstance* shaderInstance); +void se_renderer_queue_font_draw_call(SEFont* font, const char* text, float x, float y, float scale, SKAColor color, int zIndex); +void se_renderer_process_and_flush_batches(const SKAColor* backgroundColor); +void se_renderer_process_and_flush_batches_just_framebuffer(const SKAColor* backgroundColor); // Shader params void se_renderer_set_global_shader_param_time(float timeValue); diff --git a/seika/rendering/shader/shader_file_parser.c b/seika/rendering/shader/shader_file_parser.c index 66f8d4f..a34973a 100644 --- a/seika/rendering/shader/shader_file_parser.c +++ b/seika/rendering/shader/shader_file_parser.c @@ -222,7 +222,7 @@ char* shader_file_parse_function_body(const char* functionSource) { } typedef struct ShaderFileParseVecParseResult { - SEVector4 vector; + SKAVector4 vector; char errorMessage[64]; } ShaderFileParseVecParseResult; @@ -371,17 +371,17 @@ SEShaderFileParseResult se_shader_file_parser_parse_shader(const char* shaderSou shaderUniform.value.floatValue = 0.0f; } else if (strcmp(shaderUniformTypeName, "vec2") == 0) { shaderUniform.type = SEShaderParamType_FLOAT2; - shaderUniform.value.float2Value = (SEVector2) { + shaderUniform.value.float2Value = (SKAVector2) { 0.0f, 0.0f }; } else if (strcmp(shaderUniformTypeName, "vec3") == 0) { shaderUniform.type = SEShaderParamType_FLOAT3; - shaderUniform.value.float3Value = (SEVector3) { + shaderUniform.value.float3Value = (SKAVector3) { 0.0f, 0.0f, 0.0f }; } else if (strcmp(shaderUniformTypeName, "vec4") == 0) { shaderUniform.type = SEShaderParamType_FLOAT4; - shaderUniform.value.float4Value = (SEVector4) { + shaderUniform.value.float4Value = (SKAVector4) { 0.0f, 0.0f, 0.0f, 0.0f }; } else { diff --git a/seika/rendering/shader/shader_instance.c b/seika/rendering/shader/shader_instance.c index 39f32b7..52c9a77 100644 --- a/seika/rendering/shader/shader_instance.c +++ b/seika/rendering/shader/shader_instance.c @@ -94,21 +94,21 @@ SEShaderParam* se_shader_instance_param_create_float(SEShaderInstance* shaderIns return (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); } -SEShaderParam* se_shader_instance_param_create_float2(SEShaderInstance* shaderInstance, const char* name, SEVector2 value) { +SEShaderParam* se_shader_instance_param_create_float2(SEShaderInstance* shaderInstance, const char* name, SKAVector2 value) { SEShaderParam params = { .name = se_strdup(name), .type = SEShaderParamType_FLOAT2 }; params.value.float2Value = value; se_string_hash_map_add(shaderInstance->paramMap, name, ¶ms, sizeof(SEShaderParam)); return (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); } -SEShaderParam* se_shader_instance_param_create_float3(SEShaderInstance* shaderInstance, const char* name, SEVector3 value) { +SEShaderParam* se_shader_instance_param_create_float3(SEShaderInstance* shaderInstance, const char* name, SKAVector3 value) { SEShaderParam params = { .name = se_strdup(name), .type = SEShaderParamType_FLOAT3 }; params.value.float3Value = value; se_string_hash_map_add(shaderInstance->paramMap, name, ¶ms, sizeof(SEShaderParam)); return (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); } -SEShaderParam* se_shader_instance_param_create_float4(SEShaderInstance* shaderInstance, const char* name, SEVector4 value) { +SEShaderParam* se_shader_instance_param_create_float4(SEShaderInstance* shaderInstance, const char* name, SKAVector4 value) { SEShaderParam params = { .name = se_strdup(name), .type = SEShaderParamType_FLOAT4 }; params.value.float4Value = value; se_string_hash_map_add(shaderInstance->paramMap, name, ¶ms, sizeof(SEShaderParam)); @@ -138,21 +138,21 @@ void se_shader_instance_param_update_float(SEShaderInstance* shaderInstance, con shaderInstance->paramsDirty = true; } -void se_shader_instance_param_update_float2(SEShaderInstance* shaderInstance, const char* name, SEVector2 value) { +void se_shader_instance_param_update_float2(SEShaderInstance* shaderInstance, const char* name, SKAVector2 value) { SEShaderParam* param = (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); SE_ASSERT(param->type == SEShaderParamType_FLOAT2); param->value.float2Value = value; shaderInstance->paramsDirty = true; } -void se_shader_instance_param_update_float3(SEShaderInstance* shaderInstance, const char* name, SEVector3 value) { +void se_shader_instance_param_update_float3(SEShaderInstance* shaderInstance, const char* name, SKAVector3 value) { SEShaderParam* param = (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); SE_ASSERT(param->type == SEShaderParamType_FLOAT3); param->value.float3Value = value; shaderInstance->paramsDirty = true; } -void se_shader_instance_param_update_float4(SEShaderInstance* shaderInstance, const char* name, SEVector4 value) { +void se_shader_instance_param_update_float4(SEShaderInstance* shaderInstance, const char* name, SKAVector4 value) { SEShaderParam* param = (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); SE_ASSERT(param->type == SEShaderParamType_FLOAT4); param->value.float4Value = value; @@ -178,19 +178,19 @@ float se_shader_instance_param_get_float(SEShaderInstance* shaderInstance, const return param->value.floatValue; } -SEVector2 se_shader_instance_param_get_float2(SEShaderInstance* shaderInstance, const char* name) { +SKAVector2 se_shader_instance_param_get_float2(SEShaderInstance* shaderInstance, const char* name) { SEShaderParam* param = (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); SE_ASSERT(param->type == SEShaderParamType_FLOAT2); return param->value.float2Value; } -SEVector3 se_shader_instance_param_get_float3(SEShaderInstance* shaderInstance, const char* name) { +SKAVector3 se_shader_instance_param_get_float3(SEShaderInstance* shaderInstance, const char* name) { SEShaderParam* param = (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); SE_ASSERT(param->type == SEShaderParamType_FLOAT3); return param->value.float3Value; } -SEVector4 se_shader_instance_param_get_float4(SEShaderInstance* shaderInstance, const char* name) { +SKAVector4 se_shader_instance_param_get_float4(SEShaderInstance* shaderInstance, const char* name) { SEShaderParam* param = (SEShaderParam*) se_string_hash_map_get(shaderInstance->paramMap, name); SE_ASSERT(param->type == SEShaderParamType_FLOAT4); return param->value.float4Value; diff --git a/seika/rendering/shader/shader_instance.h b/seika/rendering/shader/shader_instance.h index 66ca166..59f1aec 100644 --- a/seika/rendering/shader/shader_instance.h +++ b/seika/rendering/shader/shader_instance.h @@ -27,9 +27,9 @@ typedef struct SEShaderParam { bool boolValue; int intValue; float floatValue; - SEVector2 float2Value; - SEVector3 float3Value; - SEVector4 float4Value; + SKAVector2 float2Value; + SKAVector3 float3Value; + SKAVector4 float4Value; } value; } SEShaderParam; @@ -54,20 +54,20 @@ void se_shader_instance_param_create_from_copy(SEShaderInstance* shaderInstance, SEShaderParam* se_shader_instance_param_create_bool(SEShaderInstance* shaderInstance, const char* name, bool value); SEShaderParam* se_shader_instance_param_create_int(SEShaderInstance* shaderInstance, const char* name, int value); SEShaderParam* se_shader_instance_param_create_float(SEShaderInstance* shaderInstance, const char* name, float value); -SEShaderParam* se_shader_instance_param_create_float2(SEShaderInstance* shaderInstance, const char* name, SEVector2 value); -SEShaderParam* se_shader_instance_param_create_float3(SEShaderInstance* shaderInstance, const char* name, SEVector3 value); -SEShaderParam* se_shader_instance_param_create_float4(SEShaderInstance* shaderInstance, const char* name, SEVector4 value); +SEShaderParam* se_shader_instance_param_create_float2(SEShaderInstance* shaderInstance, const char* name, SKAVector2 value); +SEShaderParam* se_shader_instance_param_create_float3(SEShaderInstance* shaderInstance, const char* name, SKAVector3 value); +SEShaderParam* se_shader_instance_param_create_float4(SEShaderInstance* shaderInstance, const char* name, SKAVector4 value); void se_shader_instance_param_update_bool(SEShaderInstance* shaderInstance, const char* name, bool value); void se_shader_instance_param_update_int(SEShaderInstance* shaderInstance, const char* name, int value); void se_shader_instance_param_update_float(SEShaderInstance* shaderInstance, const char* name, float value); -void se_shader_instance_param_update_float2(SEShaderInstance* shaderInstance, const char* name, SEVector2 value); -void se_shader_instance_param_update_float3(SEShaderInstance* shaderInstance, const char* name, SEVector3 value); -void se_shader_instance_param_update_float4(SEShaderInstance* shaderInstance, const char* name, SEVector4 value); +void se_shader_instance_param_update_float2(SEShaderInstance* shaderInstance, const char* name, SKAVector2 value); +void se_shader_instance_param_update_float3(SEShaderInstance* shaderInstance, const char* name, SKAVector3 value); +void se_shader_instance_param_update_float4(SEShaderInstance* shaderInstance, const char* name, SKAVector4 value); bool se_shader_instance_param_get_bool(SEShaderInstance* shaderInstance, const char* name); int se_shader_instance_param_get_int(SEShaderInstance* shaderInstance, const char* name); float se_shader_instance_param_get_float(SEShaderInstance* shaderInstance, const char* name); -SEVector2 se_shader_instance_param_get_float2(SEShaderInstance* shaderInstance, const char* name); -SEVector3 se_shader_instance_param_get_float3(SEShaderInstance* shaderInstance, const char* name); -SEVector4 se_shader_instance_param_get_float4(SEShaderInstance* shaderInstance, const char* name); +SKAVector2 se_shader_instance_param_get_float2(SEShaderInstance* shaderInstance, const char* name); +SKAVector3 se_shader_instance_param_get_float3(SEShaderInstance* shaderInstance, const char* name); +SKAVector4 se_shader_instance_param_get_float4(SEShaderInstance* shaderInstance, const char* name); diff --git a/seika/seika.c b/seika/seika.c index 3e3a395..a07788f 100644 --- a/seika/seika.c +++ b/seika/seika.c @@ -161,7 +161,7 @@ void sf_process_inputs() { } void sf_render() { - static const SEColor backgroundColor = { 33.0f / 255.0f, 33.0f / 255.0f, 33.0f / 255.0f, 1.0f }; + static const SKAColor backgroundColor = {33.0f / 255.0f, 33.0f / 255.0f, 33.0f / 255.0f, 1.0f }; se_renderer_process_and_flush_batches(&backgroundColor); // TODO: Pass window to renderer and swap there? diff --git a/seika/utils/command_line_args_util.c b/seika/utils/command_line_args_util.c index 7b0df82..29f2834 100644 --- a/seika/utils/command_line_args_util.c +++ b/seika/utils/command_line_args_util.c @@ -6,31 +6,31 @@ #include "../data_structures/se_hash_map_string.h" -SEStringHashMap* sk_cmd_line_args_get_key_to_arg_def_map(SKCmdLineArgDef* argDefs) { +SEStringHashMap* sk_cmd_line_args_get_key_to_arg_def_map(SKACmdLineArgDef* argDefs) { SEStringHashMap* keyToArgDefMap = se_string_hash_map_create_default_capacity(); for (size_t i = 0; i < 999999999; i++) { if (argDefs[i].id == NULL) { break; } - SKCmdLineArgDef* argDef = &argDefs[i]; - for (size_t argIndex = 0; argIndex < SK_COMMAND_LINE_ARGS_KEY_LIMIT; argIndex++) { + SKACmdLineArgDef* argDef = &argDefs[i]; + for (size_t argIndex = 0; argIndex < SKA_COMMAND_LINE_ARGS_KEY_LIMIT; argIndex++) { const char* argKey = argDef->keys[argIndex]; if (!argKey) { break; } - se_string_hash_map_add(keyToArgDefMap, argKey, argDef, sizeof(SKCmdLineArgDef)); + se_string_hash_map_add(keyToArgDefMap, argKey, argDef, sizeof(SKACmdLineArgDef)); } } return keyToArgDefMap; } -SKCmdLineArgKeyResult* sk_cmd_line_args_util_find_or_add_key_result(const SKCmdLineArgDef* argDef, SKCmdLineArgResult* result) { +SKACmdLineArgKeyResult* sk_cmd_line_args_util_find_or_add_key_result(const SKACmdLineArgDef* argDef, SKACmdLineArgResult* result) { for (size_t i = 0; i < result->keyResultCount; i++) { - SKCmdLineArgKeyResult* keyResult = &result->keyResults[i]; - for (size_t j = 0; j < SK_COMMAND_LINE_ARGS_KEY_LIMIT; j++) { + SKACmdLineArgKeyResult* keyResult = &result->keyResults[i]; + for (size_t j = 0; j < SKA_COMMAND_LINE_ARGS_KEY_LIMIT; j++) { if (!argDef->keys[j]) { break; } @@ -42,21 +42,21 @@ SKCmdLineArgKeyResult* sk_cmd_line_args_util_find_or_add_key_result(const SKCmdL } // If here, we don't have a key result so add one - SKCmdLineArgKeyResult* keyResult = &result->keyResults[result->keyResultCount++]; + SKACmdLineArgKeyResult* keyResult = &result->keyResults[result->keyResultCount++]; keyResult->id = argDef->id; return keyResult; } -SKCmdLineArgResult sk_cmd_line_args_util_parse(int argv, char** args, SKCmdLineArgDef* argDefs) { - SKCmdLineArgResult result = (SKCmdLineArgResult){ .keyResults = {0}, .keyResultCount = 0 }; +SKACmdLineArgResult sk_cmd_line_args_util_parse(int argv, char** args, SKACmdLineArgDef* argDefs) { + SKACmdLineArgResult result = (SKACmdLineArgResult){ .keyResults = {0}, .keyResultCount = 0 }; SEStringHashMap* keyToArgDefMap = sk_cmd_line_args_get_key_to_arg_def_map(argDefs); for (int i = 0; i < argv; i++) { const char* arg = args[i]; - const SKCmdLineArgDef* argDef = (SKCmdLineArgDef*) se_string_hash_map_find(keyToArgDefMap, arg); + const SKACmdLineArgDef* argDef = (SKACmdLineArgDef*) se_string_hash_map_find(keyToArgDefMap, arg); if (argDef) { - SKCmdLineArgKeyResult* keyResult = sk_cmd_line_args_util_find_or_add_key_result(argDef, &result); + SKACmdLineArgKeyResult* keyResult = sk_cmd_line_args_util_find_or_add_key_result(argDef, &result); if (argDef->expectsValue) { const int nextArgIndex = i + 1; if (nextArgIndex < argv) { @@ -71,9 +71,9 @@ SKCmdLineArgResult sk_cmd_line_args_util_parse(int argv, char** args, SKCmdLineA return result; } -void sk_cmd_line_args_util_print_results(const SKCmdLineArgResult* result) { +void sk_cmd_line_args_util_print_results(const SKACmdLineArgResult* result) { for (size_t i = 0; i < result->keyResultCount; i++) { - const SKCmdLineArgKeyResult* keyResult = &result->keyResults[i]; + const SKACmdLineArgKeyResult* keyResult = &result->keyResults[i]; printf("---------------------------------------------------------------\n"); printf("Key Id: '%s'\n", keyResult->id); for (size_t valueIndex = 0; valueIndex < keyResult->valueCount; valueIndex++) { diff --git a/seika/utils/command_line_args_util.h b/seika/utils/command_line_args_util.h index d99683a..28211aa 100644 --- a/seika/utils/command_line_args_util.h +++ b/seika/utils/command_line_args_util.h @@ -3,27 +3,27 @@ #include #include -#define SK_COMMAND_LINE_ARGS_KEY_LIMIT 8 -#define SK_COMMAND_LINE_ARGS_RETURN_LIMIT 8 -#define SK_COMMAND_LINE_ARGS_RETURN_VALUES_LIMIT 8 +#define SKA_COMMAND_LINE_ARGS_KEY_LIMIT 8 +#define SKA_COMMAND_LINE_ARGS_RETURN_LIMIT 8 +#define SKA_COMMAND_LINE_ARGS_RETURN_VALUES_LIMIT 8 -typedef struct SKCmdLineArgDef { +typedef struct SKACmdLineArgDef { const char* id; const char* description; bool expectsValue; - const char* keys[SK_COMMAND_LINE_ARGS_KEY_LIMIT]; -} SKCmdLineArgDef; + const char* keys[SKA_COMMAND_LINE_ARGS_KEY_LIMIT]; +} SKACmdLineArgDef; -typedef struct SKCmdLineArgKeyResult { +typedef struct SKACmdLineArgKeyResult { const char* id; - const char* values[SK_COMMAND_LINE_ARGS_RETURN_VALUES_LIMIT]; + const char* values[SKA_COMMAND_LINE_ARGS_RETURN_VALUES_LIMIT]; size_t valueCount; -} SKCmdLineArgKeyResult; +} SKACmdLineArgKeyResult; -typedef struct SKCmdLineArgResult { - SKCmdLineArgKeyResult keyResults[SK_COMMAND_LINE_ARGS_RETURN_LIMIT]; +typedef struct SKACmdLineArgResult { + SKACmdLineArgKeyResult keyResults[SKA_COMMAND_LINE_ARGS_RETURN_LIMIT]; size_t keyResultCount; -} SKCmdLineArgResult; +} SKACmdLineArgResult; -SKCmdLineArgResult sk_cmd_line_args_util_parse(int argv, char** args, SKCmdLineArgDef* argDefs); -void sk_cmd_line_args_util_print_results(const SKCmdLineArgResult* result); +SKACmdLineArgResult sk_cmd_line_args_util_parse(int argv, char** args, SKACmdLineArgDef* argDefs); +void sk_cmd_line_args_util_print_results(const SKACmdLineArgResult* result); diff --git a/test/main.c b/test/main.c index ca77933..50e803b 100644 --- a/test/main.c +++ b/test/main.c @@ -90,20 +90,20 @@ void seika_spatial_hash_map_test(void) { // Create two entities and insert them into hash map const unsigned int entity = 1; - SESpatialHashMapGridSpacesHandle* handle = se_spatial_hash_map_insert_or_update(spatialHashMap, entity, &(SERect2) { + SESpatialHashMapGridSpacesHandle* handle = se_spatial_hash_map_insert_or_update(spatialHashMap, entity, &(SKARect2) { 0.0f, 0.0f, 32.0f, 32.0f }); TEST_ASSERT_EQUAL(handle, se_spatial_hash_map_get(spatialHashMap, entity)); const unsigned int entityTwo = 2; - SESpatialHashMapGridSpacesHandle* handleTwo = se_spatial_hash_map_insert_or_update(spatialHashMap, entityTwo, &(SERect2) { + SESpatialHashMapGridSpacesHandle* handleTwo = se_spatial_hash_map_insert_or_update(spatialHashMap, entityTwo, &(SKARect2) { 16.0f, 16.0f, 48.0f, 48.0f }); TEST_ASSERT_EQUAL(handleTwo, se_spatial_hash_map_get(spatialHashMap, entityTwo)); // An entity that should not be collided with const unsigned int entityNotCollided = 3; - se_spatial_hash_map_insert_or_update(spatialHashMap, entityNotCollided, &(SERect2) { + se_spatial_hash_map_insert_or_update(spatialHashMap, entityNotCollided, &(SKARect2) { 64.0f, 64.0f, 96.0f, 96.0f }); @@ -127,14 +127,14 @@ void seika_command_line_args_util_test(void) { #define SK_CMD_LINE_TEST_ARGV 5 const int argv = 5; char* args[SK_CMD_LINE_TEST_ARGV] = { "seika.exe", "--test", "true", "-l", "debug" }; - SKCmdLineArgDef defs[3] = { - (SKCmdLineArgDef){ .id = "working-dir-override", .description = "Overrides the current working dir", .expectsValue = true, .keys = { "-d", NULL } }, - (SKCmdLineArgDef){ .id = "log-level", .description = "Sets the log level for the engine runtime", .expectsValue = true, .keys = { "-l", NULL } }, - (SKCmdLineArgDef){ NULL } + SKACmdLineArgDef defs[3] = { + (SKACmdLineArgDef){ .id = "working-dir-override", .description = "Overrides the current working dir", .expectsValue = true, .keys = {"-d", NULL } }, + (SKACmdLineArgDef){ .id = "log-level", .description = "Sets the log level for the engine runtime", .expectsValue = true, .keys = {"-l", NULL } }, + (SKACmdLineArgDef){NULL } }; - const SKCmdLineArgResult result = sk_cmd_line_args_util_parse(SK_CMD_LINE_TEST_ARGV, args, defs); + const SKACmdLineArgResult result = sk_cmd_line_args_util_parse(SK_CMD_LINE_TEST_ARGV, args, defs); TEST_ASSERT_EQUAL_INT(1, result.keyResultCount); - const SKCmdLineArgKeyResult* keyResult = &result.keyResults[0]; + const SKACmdLineArgKeyResult* keyResult = &result.keyResults[0]; TEST_ASSERT_EQUAL_STRING("log-level", keyResult->id); TEST_ASSERT_EQUAL_INT(1, keyResult->valueCount); TEST_ASSERT_EQUAL_STRING("debug", keyResult->values[0]); diff --git a/vcpkg.json b/vcpkg.json index 4791d9f..cc00756 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "seika", - "version": "0.0.13", + "version": "0.0.14", "dependencies": [ { "name": "sdl2",