Skip to content

Commit

Permalink
Updating macro used to check for valid coords in array2d.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Apr 8, 2024
1 parent b789d4e commit bcd6c2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
19 changes: 3 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ set(CMAKE_C_STANDARD 11)

project(seika C)

if (NOT DEFINED SEIKA_STATIC_LIB)
set(SEIKA_STATIC_LIB "Make seika and dependent libs static" ON)
endif ()
option(IS_CI_BUILD "" OFF)
option(SEIKA_STATIC_LIB "Make seika and dependent libs static" OFF)

if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
list(APPEND flags "/W3" "/Zc:preprocessor")
Expand Down Expand Up @@ -38,20 +37,8 @@ endif ()

target_compile_options(${PROJECT_NAME} PUBLIC ${flags})

if (NOT SEIKA_STATIC_LIB)
# SDL
file(GLOB SDL3_DLLS "${CMAKE_BINARY_DIR}/_deps/sdl_content-build/*.dll")
install(FILES ${SDL3_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
# Freetype
file(GLOB FREETYPE_DLLS "${CMAKE_BINARY_DIR}/_deps/freetype_content-build/*.dll")
install(FILES ${FREETYPE_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
endif ()

# Copy directories over that are needed to test
if (NOT DEFINED IS_CI_BUILD)
set(IS_CI_BUILD "false")
endif()
if (IS_CI_BUILD STREQUAL "false")
if (NOT IS_CI_BUILD)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/test
Expand Down
6 changes: 3 additions & 3 deletions seika/data_structures/array2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "seika/memory.h"
#include "seika/assert.h"

#define SKA_ARRAY2D_IS_VALID_COORD(ARRAY2D, ROW, COL) (!((int32)ROW >= ARRAY2D->size.w || (int32)COL >= ARRAY2D->size.h))
#define SKA_ARRAY2D_IS_COORD_INVALID(ARRAY2D, ROW, COL) ((int32)ROW >= ARRAY2D->size.w || (int32)COL >= ARRAY2D->size.h)

SkaArray2D* ska_array2d_create(usize rows, usize cols, usize elementSize) {
SkaArray2D* newArray = SKA_MEM_ALLOCATE(SkaArray2D);
Expand All @@ -27,14 +27,14 @@ void ska_array2d_destroy(SkaArray2D* array2d) {
}

void* ska_array2d_get(SkaArray2D* array2d, usize x, usize y) {
if (!SKA_ARRAY2D_IS_VALID_COORD(array2d, x, y)) {
if (SKA_ARRAY2D_IS_COORD_INVALID(array2d, x, y)) {
return NULL;
}
return (void*)((char*)array2d->data[y] + x * array2d->elementSize);
}

bool ska_array2d_set(SkaArray2D* array2d, usize x, usize y, void* newValue) {
if (!SKA_ARRAY2D_IS_VALID_COORD(array2d, x, y)) {
if (SKA_ARRAY2D_IS_COORD_INVALID(array2d, x, y)) {
return false;
}
memcpy((void*)((char*)array2d->data[y] + x * array2d->elementSize), newValue, array2d->elementSize);
Expand Down
2 changes: 1 addition & 1 deletion seika/version_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

#define SKA_VERSION_MAJOR 0
#define SKA_VERSION_MINOR 1
#define SKA_VERSION_PATCH 2
#define SKA_VERSION_PATCH 3

#define SKA_VERSION (SKA_MACRO_TO_STRING(SKA_VERSION_MAJOR) "." SKA_MACRO_TO_STRING(SKA_VERSION_MINOR) "." SKA_MACRO_TO_STRING(SKA_VERSION_PATCH))

0 comments on commit bcd6c2e

Please sign in to comment.