Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactor of seika #2

Merged
merged 55 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e89bb50
Starting to add new seika version test.
Chukobyte Oct 10, 2024
268c111
Updates.
Chukobyte Oct 10, 2024
f604290
Test out some stuff.
Chukobyte Oct 11, 2024
a1c583d
Updates.
Chukobyte Oct 11, 2024
55f8819
Updates.
Chukobyte Oct 11, 2024
722f45f
Forgot to add test file>
Chukobyte Oct 11, 2024
4ab7f28
Updates.
Chukobyte Oct 11, 2024
667109f
More seika1 tests.
Chukobyte Oct 14, 2024
3b2ee8e
More testing.
Chukobyte Oct 17, 2024
9428c63
Test.
Chukobyte Oct 17, 2024
1de543e
Updates.
Chukobyte Oct 17, 2024
738358c
More tests.
Chukobyte Oct 17, 2024
8354db4
Clean.
Chukobyte Oct 17, 2024
76f74bd
Clean.:
Chukobyte Oct 17, 2024
489b91b
Updates.
Chukobyte Oct 18, 2024
2b7b945
Clean.
Chukobyte Oct 18, 2024
5a288f2
Renaming seika to old seika.
Chukobyte Oct 18, 2024
2167d80
Renamed to new seika.
Chukobyte Oct 18, 2024
0b4f8dc
Updates.
Chukobyte Oct 18, 2024
1a1d428
Added input.
Chukobyte Oct 18, 2024
1f37cee
Clean.
Chukobyte Oct 18, 2024
cd71795
Clean.
Chukobyte Oct 18, 2024
cd047ed
Updates.
Chukobyte Oct 18, 2024
f720747
More.
Chukobyte Oct 18, 2024
7c51fdf
More.
Chukobyte Oct 18, 2024
753f6bd
Clean.
Chukobyte Oct 18, 2024
83b16c0
More tests.
Chukobyte Oct 18, 2024
4b24f86
Updates.
Chukobyte Oct 18, 2024
7014776
Updates.
Chukobyte Oct 18, 2024
2f0ac45
Updates.
Chukobyte Oct 20, 2024
ebb2ba0
Update.
Chukobyte Oct 20, 2024
237c177
Updates.
Chukobyte Oct 20, 2024
b284378
Clean.
Chukobyte Oct 20, 2024
b8c5e58
Clean.
Chukobyte Oct 20, 2024
4516793
Updates.
Chukobyte Oct 20, 2024
339ba70
Update.
Chukobyte Oct 20, 2024
3e54b2f
Clean.
Chukobyte Oct 20, 2024
b277390
Clean.
Chukobyte Oct 20, 2024
39e708f
Clean up.
Chukobyte Oct 20, 2024
60b93e3
Clean.
Chukobyte Oct 23, 2024
d83e004
Updates.
Chukobyte Oct 24, 2024
763b63a
Clean.
Chukobyte Oct 24, 2024
2dbce21
Clean.
Chukobyte Oct 24, 2024
980d6f0
Updates.
Chukobyte Oct 26, 2024
eb20b66
Clean.
Chukobyte Oct 26, 2024
c1b0fe1
Updates.
Chukobyte Oct 26, 2024
842ef61
Clean.
Chukobyte Oct 27, 2024
7dc34a4
Clean.
Chukobyte Oct 27, 2024
403e970
Clean.
Chukobyte Oct 27, 2024
84b366e
Update.
Chukobyte Oct 27, 2024
d45c9b6
Clean.
Chukobyte Oct 28, 2024
1563fbd
Clean.
Chukobyte Oct 29, 2024
66f0254
Clean.
Chukobyte Oct 29, 2024
49f311c
Update.
Chukobyte Oct 30, 2024
959e7e8
Clean.
Chukobyte Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 30 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,31 @@ cmake_minimum_required(VERSION 3.27.0)

set(CMAKE_C_STANDARD 11)

project(seika C)
project(seika-framework C)

option(IS_CI_BUILD "" OFF)
option(SEIKA_STATIC_LIB "Make seika and dependent libs static" OFF)

# Optional Modules
option(SEIKA_ECS "Will enable ecs" ON)
option(SEIKA_INPUT "Will enable input" ON)
option(SEIKA_RENDERING "Will enable rendering" ON)
option(SEIKA_AUDIO "Will enable audio" ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
list(APPEND flags "/W3" "/Zc:preprocessor")
elseif (APPLE)
list(APPEND flags "-Wfatal-errors" "-Wall" "-Wextra" "-Wno-write-strings" "-Wno-deprecated-declarations"
"-Wno-unused-variable" "-Wno-bad-function-cast" "-Wno-unused-parameter" "-Wno-missing-field-initializers")
else ()
list(APPEND flags "-std=c11" "-Wfatal-errors" "-Wall" "-Wextra" "-Wno-write-strings" "-Wno-deprecated-declarations"
"-Wno-unused-variable" "-Wno-cast-function-type" "-Wno-unused-parameter" "-Wno-missing-field-initializers")
endif ()

file(GLOB_RECURSE SEIKA_SRC seika/*.c seika/*.h)
add_library(${PROJECT_NAME} STATIC ${SEIKA_SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

#--- Dependencies ---#
include(Dependencies.cmake)

#--- Link ---#
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
target_link_libraries(${PROJECT_NAME} PUBLIC cglm glad stb_image zip miniaudio ${SDL3_LIBRARY} freetype Ws2_32)
elseif (WIN32)
target_link_libraries(${PROJECT_NAME} PUBLIC cglm glad stb_image zip miniaudio -lmingw32 -static-libgcc ${SDL3_LIBRARY} freetype -lws2_32)
elseif (APPLE)
target_link_libraries(${PROJECT_NAME} PUBLIC cglm glad stb_image zip miniaudio -Xlinker ${SDL3_LIBRARY} freetype m)
else ()
target_link_libraries(${PROJECT_NAME} PUBLIC cglm glad stb_image zip miniaudio -static-libgcc -Xlinker -export-dynamic ${SDL3_LIBRARY} freetype m)
endif ()

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

# Copy directories over that are needed to test
if (NOT IS_CI_BUILD)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/test
$<TARGET_FILE_DIR:${PROJECT_NAME}>/test
)
endif()
add_subdirectory(seika)
target_compile_definitions(seika
PUBLIC
SKA_ECS=$<IF:$<BOOL:${SEIKA_ECS}>,1,0>
SKA_INPUT=$<IF:$<BOOL:${SEIKA_INPUT}>,1,0>
SKA_RENDERING=$<IF:$<BOOL:${SEIKA_RENDERING}>,1,0>
SKA_AUDIO=$<IF:$<BOOL:${SEIKA_AUDIO}>,1,0>
)

if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(SK_IS_MAIN TRUE)
Expand All @@ -57,6 +36,19 @@ endif()

if (SK_IS_MAIN)
# Create seika test exe
add_executable(${PROJECT_NAME}_test test/test.c)
target_link_libraries(${PROJECT_NAME}_test ${PROJECT_NAME} unity)
add_executable(seika_test test/test.c)
target_link_libraries(seika_test seika unity)
if (NOT IS_CI_BUILD)
# Copy directories over that are needed to test
add_custom_command(TARGET seika_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/test
$<TARGET_FILE_DIR:seika_test>/test
)
if (SEIKA_INPUT OR SEIKA_RENDERING)
# Create test game executable
add_executable(seika_test_game test/game/src/main.c)
target_link_libraries(seika_test_game seika)
endif ()
endif()
endif()
116 changes: 61 additions & 55 deletions Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
include(FetchContent)

# https://github.com/libsdl-org/SDL
if (NOT TARGET SDL3::SDL3-static)
set(SDL_STATIC ${SEIKA_STATIC_LIB})
set(SDL_SHARED NOT ${SEIKA_STATIC_LIB})

FetchContent_Declare(
SDL_content
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG cacac6cc341d5856d1857bdcf7390551eed54865
)
FetchContent_MakeAvailable(SDL_content)

if (SEIKA_STATIC_LIB)
SET(SDL3_LIBRARY SDL3::SDL3-static)
else ()
SET(SDL3_LIBRARY SDL3::SDL3)
endif ()
endif ()

# https://github.com/Dav1dde/glad
if (NOT TARGET glad)
if (SEIKA_STATIC_LIB)
add_library(glad STATIC thirdparty/glad/glad.c)
else ()
add_library(glad thirdparty/glad/glad.c)
endif ()
target_include_directories(glad PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty")
endif()

# https://github.com/recp/cglm
if (NOT TARGET cglm)
set(CGLM_STATIC ${SEIKA_STATIC_LIB})
Expand All @@ -53,22 +24,6 @@ if (NOT TARGET kuba_zip)
FetchContent_MakeAvailable(kuba_zip_content)
endif()

# https://github.com/mackron/miniaudio
if (NOT TARGET miniaudio)
add_library(miniaudio INTERFACE thirdparty/miniaudio/miniaudio.h)
target_include_directories(miniaudio INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/miniaudio")
endif()

# https://github.com/nothings/stb
if (NOT TARGET stb_image)
if (SEIKA_STATIC_LIB)
add_library(stb_image STATIC thirdparty/stb_image/stb_image.c)
else ()
add_library(stb_image thirdparty/stb_image/stb_image.c)
endif ()
target_include_directories(stb_image PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty")
endif()

# https://github.com/ThrowTheSwitch/Unity
if (NOT TARGET unity)
add_definitions(-DUNITY_INCLUDE_DOUBLE)
Expand All @@ -81,16 +36,67 @@ if (NOT TARGET unity)
FetchContent_MakeAvailable(unity_content)
endif()

# https://github.com/freetype/freetype
if (NOT TARGET freetype)
if (NOT SEIKA_STATIC_LIB)
set(BUILD_SHARED_LIBS ON)
if (SEIKA_INPUT OR SEIKA_RENDERING)
# https://github.com/libsdl-org/SDL
if (NOT TARGET SDL3::SDL3-static)
set(SDL_STATIC ${SEIKA_STATIC_LIB})
set(SDL_SHARED NOT ${SEIKA_STATIC_LIB})

FetchContent_Declare(
SDL_content
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
GIT_TAG cacac6cc341d5856d1857bdcf7390551eed54865
)
FetchContent_MakeAvailable(SDL_content)

if (SEIKA_STATIC_LIB)
SET(SDL3_LIBRARY SDL3::SDL3-static)
else ()
SET(SDL3_LIBRARY SDL3::SDL3)
endif ()
endif ()
endif()

FetchContent_Declare(
freetype_content
GIT_REPOSITORY https://github.com/freetype/freetype.git
GIT_TAG VER-2-13-2
)
FetchContent_MakeAvailable(freetype_content)
if (SEIKA_RENDERING)
# https://github.com/Dav1dde/glad
if (NOT TARGET glad)
if (SEIKA_STATIC_LIB)
add_library(glad STATIC thirdparty/glad/glad.c)
else ()
add_library(glad thirdparty/glad/glad.c)
endif ()
target_include_directories(glad PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty")
endif()

# https://github.com/nothings/stb
if (NOT TARGET stb_image)
if (SEIKA_STATIC_LIB)
add_library(stb_image STATIC thirdparty/stb_image/stb_image.c)
else ()
add_library(stb_image thirdparty/stb_image/stb_image.c)
endif ()
target_include_directories(stb_image PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty")
endif()

# https://github.com/freetype/freetype
if (NOT TARGET freetype)
if (NOT SEIKA_STATIC_LIB)
set(BUILD_SHARED_LIBS ON)
endif ()

FetchContent_Declare(
freetype_content
GIT_REPOSITORY https://github.com/freetype/freetype.git
GIT_TAG VER-2-13-2
)
FetchContent_MakeAvailable(freetype_content)
endif()
endif()

if (SEIKA_AUDIO)
# https://github.com/mackron/miniaudio
if (NOT TARGET miniaudio)
add_library(miniaudio INTERFACE thirdparty/miniaudio/miniaudio.h)
target_include_directories(miniaudio INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/miniaudio")
endif()
endif()
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ A framework for windows, macOS, and linux that can be used to make games.
## How to include in a project

Seika uses cmake to build. To include in your project, add the following to your CMakeLists.txt:

```cmake
# Include seika framework as a dependency
# Include old_seika framework as a dependency
include(FetchContent)

FetchContent_Declare(
seika
GIT_REPOSITORY https://github.com/Chukobyte/seika.git
GIT_TAG v0.1.0
GIT_TAG v0.2.0
)

FetchContent_MakeAvailable(seika)
Expand All @@ -63,15 +64,23 @@ A simple example of creating a window and querying for inputs.
#include <seika/input/input.h>

int main(int argv, char** args) {
ska_init_all("Simple Window", 800, 600, 800, 600);

while (ska_is_running()) {
ska_window_initialize((SkaWindowProperties){
.title = "Simple Window",
.windowWidth = 800,
.windowHeight = 600,
.resolutionWidth = 800,
.resolutionHeight = 600,
.maintainAspectRatio = true,
});
ska_input_initialize();

while (true) {
// TODO: Need to update this
ska_update();

if (ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_ESCAPE, 0)) {
break;
}

if (ska_input_is_key_just_pressed(SkaInputKey_KEYBOARD_SPACE, 0)) {
printf("space just pressed\n");
}
Expand All @@ -82,10 +91,12 @@ int main(int argv, char** args) {
printf("space just released\n");
}

ska_window_render();
static SkaColor windowBackgroundColor = (SkaColor){ 0.2f, 0.2f, 0.2f, 1.0f };
ska_window_render(&windowBackgroundColor);
}

ska_shutdown_all();
ska_window_finalize();
ska_input_finalize();

return 0;
}
Expand Down
48 changes: 48 additions & 0 deletions seika/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.27.0)

set(CMAKE_C_STANDARD 11)

project(seika C)

if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
list(APPEND flags "/W3" "/Zc:preprocessor")
elseif (APPLE)
list(APPEND flags "-Wfatal-errors" "-Wall" "-Wextra" "-Wno-write-strings" "-Wno-deprecated-declarations"
"-Wno-unused-variable" "-Wno-bad-function-cast" "-Wno-unused-parameter" "-Wno-missing-field-initializers")
else ()
list(APPEND flags "-std=c11" "-Wfatal-errors" "-Wall" "-Wextra" "-Wno-write-strings" "-Wno-deprecated-declarations"
"-Wno-unused-variable" "-Wno-cast-function-type" "-Wno-unused-parameter" "-Wno-missing-field-initializers")
endif ()

file(GLOB_RECURSE SEIKA_SRC ./*.c ./*.h)
add_library(${PROJECT_NAME} STATIC ${SEIKA_SRC})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)

set(LIBS_TO_LINK "")

if (SEIKA_RENDERING)
list(APPEND LIBS_TO_LINK glad stb_image freetype)
endif()

if (SEIKA_AUDIO)
list(APPEND LIBS_TO_LINK miniaudio)
endif()

if (SEIKA_INPUT)
list(APPEND LIBS_TO_LINK ${SDL3_LIBRARY})
endif()

#--- Link ---#
if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
list(APPEND LIBS_TO_LINK Ws2_32)
elseif (WIN32)
list(APPEND LIBS_TO_LINK -lmingw32 -static-libgcc -lws2_32)
elseif (APPLE)
list(APPEND LIBS_TO_LINK m)
else ()
list(APPEND LIBS_TO_LINK -static-libgcc -Xlinker -export-dynamic m)
endif ()

target_link_libraries(${PROJECT_NAME} PUBLIC cglm zip ${LIBS_TO_LINK})

target_compile_options(${PROJECT_NAME} PUBLIC ${flags})
10 changes: 8 additions & 2 deletions seika/assert.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#include "seika/assert.h"

#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#include "seika/string.h"

void ska_print_assert_err(const char* fmt, ...) {
#define SKA_PRINT_BUFFER_SIZE 496
va_list args;
va_start(args, fmt);
va_start(args, fmt);
char str[SKA_PRINT_BUFFER_SIZE];
memset(str, 0, SKA_PRINT_BUFFER_SIZE);
ska_strncat(str, fmt, (sizeof(str) - strlen(str) - 1) );
ska_strncat(str, "\n", (sizeof(str) - strlen(str) - 1) );
vfprintf(stderr, str, args);
va_end(args);
va_end(args);
#undef SKA_PRINT_BUFFER_SIZE
}
10 changes: 5 additions & 5 deletions seika/assert.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif


#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#include "defines.h"
#include "platform.h"
#include "seika/string.h"
#include "seika/defines.h"
#include "seika/platform.h"

#define SKA_ASSERT_FAIL_EXIT_CODE (-1)

Expand Down
Loading
Loading