Skip to content

Commit

Permalink
switched to mingw and re-added glfw glew submodules, plus added glm s…
Browse files Browse the repository at this point in the history
…ubmodule
  • Loading branch information
TheGAzed committed Jul 17, 2024
1 parent 46dd422 commit 5bea264
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 28 deletions.
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
[submodule "external/nuklear"]
path = external/nuklear
url = git@github.com:Immediate-Mode-UI/Nuklear.git
[submodule "external/glfw"]
path = external/glfw
url = git@github.com:glfw/glfw.git
[submodule "external/glew"]
path = external/glew
url = git@github.com:Perlmint/glew-cmake.git
[submodule "external/glm"]
path = external/glm
url = git@github.com:g-truc/glm.git
11 changes: 4 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ project(SLNOSLAV
LANGUAGES C
)

if (WIN32)
add_compile_options(/W4)
else()
set(CMAKE_CXX_FLAGS "-std=c23 -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-g -pg")
set(CMAKE_CXX_FLAGS_RELEASE "-03")
endif()
set(CMAKE_CXX_FLAGS "-std=c17 -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-g -pg")
set(CMAKE_CXX_FLAGS_RELEASE "-03")

add_subdirectory(external)
add_subdirectory(program)

include(CTest)
enable_testing()
add_subdirectory(test)

9 changes: 9 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ target_include_directories(greatest INTERFACE greatest)

add_library(nuklear INTERFACE "")
target_include_directories(nuklear INTERFACE nuklear nuklear/demo/glfw_opengl3)

set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(glfw EXCLUDE_FROM_ALL)

add_definitions(-DGLEW_STATIC)
add_subdirectory(glew EXCLUDE_FROM_ALL)

add_subdirectory(glm)
1 change: 1 addition & 0 deletions external/glew
Submodule glew added at a5494d
1 change: 1 addition & 0 deletions external/glfw
Submodule glfw added at b35641
1 change: 1 addition & 0 deletions external/glm
Submodule glm added at 33b4a6
15 changes: 9 additions & 6 deletions program/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
find_package(OpenGL REQUIRED)
find_package(glfw3 3.3 REQUIRED)
find_package(GLEW REQUIRED)

add_executable(${PROJECT_NAME} main.c)

add_library(program

source/gui/graphics.c
source/gui/input.c
source/gui/draw.c
Expand All @@ -31,9 +28,15 @@ add_library(program
source/slnoslav.c
)

#target_compile_definitions(program PRIVATE ERROR_LOG_FILE_PATH=\"${CMAKE_BINARY_DIR}/debug_log.txt\")

target_include_directories(program PUBLIC include)

target_link_libraries(program PRIVATE glfw GLEW::GLEW OpenGL::GL m nuklear)
target_link_libraries(${PROJECT_NAME} PRIVATE program)
target_link_libraries(program
PRIVATE glfw
PRIVATE libglew_static
PRIVATE glm
nuklear
)

target_compile_definitions(${PROJECT_NAME} PRIVATE ERROR_LOG_FILE_PATH=\"${CMAKE_BINARY_DIR}/slnoslav-debug.txt\")
target_link_libraries(${PROJECT_NAME} PRIVATE program)
2 changes: 2 additions & 0 deletions program/include/instance/expect.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern FILE * error_log;
if (!(assertion)) { \
fprintf(error_log, __VA_ARGS__); \
fprintf(error_log, "\n"); \
fflush(error_log ? error_log : stderr); \
switch (error_mode) { \
case ABORT_E : { error_action; abort(); break; } \
case ASSERT_E : { error_action; assert(0 && (assertion)); break; } \
Expand All @@ -36,6 +37,7 @@ extern FILE * error_log;
if (!(assertion)) { \
fprintf(error_log ? error_log : stderr, __VA_ARGS__); \
fprintf(error_log ? error_log : stderr, "\n"); \
fflush(error_log ? error_log : stderr); \
switch (error_mode) { \
case ABORT_E : { error_action; abort(); break; } \
case ASSERT_E : { error_action; assert(0 && (assertion)); break;} \
Expand Down
4 changes: 3 additions & 1 deletion program/source/gui/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ void _glfw_initialize(GLFWwindow ** window, int * width, int * height) {
void _glew_initialize(void) {
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
glewExperimental = GL_TRUE;
GLenum error = glewInit();

error_mode = ASSERT_E;
expect(glewInit() == GLEW_OK, NO_ACTION, "[ERROR] Failed to setup GLEW");
expect(error == GLEW_OK, NO_ACTION, "[ERROR] Failed to setup GLEW: %s", glewGetErrorString(error));
}

struct nk_super _create_super(struct nk_glfw * glfw, GLFWwindow * window) {
Expand Down
4 changes: 2 additions & 2 deletions program/source/gui/interface/grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ void _multi_value(struct nk_context * context, struct nk_rect background, struct

void _draw_value(struct nk_context * context, struct nk_rect position, struct nk_color bg, struct nk_color fg, int value) {
char string_num[sizeof("-2147483647")] = { 0 };
sprintf(string_num, "%d", value);

float temp_height = context->style.font->height;
struct nk_user_font * font = context->style.font;

sprintf(string_num, "%d", value);
font->height = position.h;
position.x += (position.w / 2) - (font->width(font->userdata, font->height, string_num, strnlen(string_num, sizeof("-2147483647"))) / 2);
nk_draw_text(&context->current->buffer, position, string_num, strnlen(string_num, sizeof("-2147483647")), font, bg, fg);
Expand Down
17 changes: 9 additions & 8 deletions program/source/gui/interface/solver.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <gui/interface/solver.h>

#include <threads.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>

Expand All @@ -20,10 +20,10 @@
#ifdef WIN32
#include <io.h>
#include <fcntl.h>

int pipe(int pipefd[2]) { return _pipe(pipefd, 65536, _O_BINARY); }
int read(int __fd, const void * __buf, size_t __n) { return _read(__fd, __buf, __n); }
int write(int __fd, const void * __buf, size_t __n) { return _write(__fd, __buf, __n); }
//int read(int __fd, const void * __buf, size_t __n) { return _read(__fd, __buf, __n); }
//int write(int __fd, const void * __buf, size_t __n) { return _write(__fd, __buf, __n); }
#else
#include <unistd.h>
#endif
Expand All @@ -42,7 +42,7 @@ typedef enum pipe_type {

int pipefd[2];

thrd_start_t _solver(void * solution);
void * _solver(void * data);

void _create_ds(stack_s * prev, stack_s * next);
void _destroy_ds(stack_s * prev, stack_s * next);
Expand All @@ -65,8 +65,9 @@ player_s * get_player_singleton(void) {
}

void solve(struct nk_solver * data) {
thrd_t tid = { 0 };
thrd_create(&tid, (thrd_start_t)_solver, (void*)data);
pthread_t tid = { 0 };
pthread_create(&tid, NULL, &_solver, data);
//thrd_create(&tid, (thrd_start_t)_solver, (void*)data);
}

state_array_s state_provider(const ds_action_e action) {
Expand All @@ -90,7 +91,7 @@ state_array_s state_provider(const ds_action_e action) {
return (state_array_s) { 0 };
}

thrd_start_t _solver(void * data) {
void * _solver(void * data) {
get_player_singleton()->solve_state = SOLVE_RUNNING_E;

struct nk_solver * input = data;
Expand Down
2 changes: 0 additions & 2 deletions test/blackbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ target_link_libraries(BLACKBOX
program
)

target_compile_definitions(program PRIVATE ERROR_LOG_FILE_PATH=\"${CMAKE_BINARY_DIR}/blackbox-debug.txt\")

add_test(NAME BLACKBOX_TEST COMMAND BLACKBOX WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
2 changes: 0 additions & 2 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ target_link_libraries(UNITTESTS
program
)

target_compile_definitions(program PRIVATE ERROR_LOG_FILE_PATH=\"${CMAKE_BINARY_DIR}/blackbox-debug.txt\")

add_test(NAME UNIT_TEST COMMAND UNITTESTS WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")

0 comments on commit 5bea264

Please sign in to comment.