Skip to content

Commit

Permalink
fixed code for release
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGAzed committed Aug 4, 2024
1 parent 6d6124c commit bc165e7
Show file tree
Hide file tree
Showing 44 changed files with 142 additions and 103 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ cmake_minimum_required(VERSION 3.22.1)

project(SLNOSLAV
VERSION 0
DESCRIPTION "A C PROJECT FOR SOLVING KAKURO PUZZLES"
DESCRIPTION "A C PROJECT FOR SOLVING KAKURO PUZZLES"
LANGUAGES C
)

set(CMAKE_CXX_FLAGS "-std=c17 -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-g -pg")
set(CMAKE_CXX_FLAGS_RELEASE "-03")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

add_subdirectory(external)
add_subdirectory(program)
Expand Down
Binary file added assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/font/Roboto-Regular.ttf
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/icons/stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion program/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ add_library(program
source/structures/concrete/board.c
source/structures/concrete/state.c
source/slnoslav.c
include/style.h
)

target_include_directories(program PUBLIC include)
target_include_directories(program PUBLIC include assets)

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

Expand Down
Binary file removed program/assets/icons/stop.png
Binary file not shown.
2 changes: 1 addition & 1 deletion program/include/gui/default.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <structures/concrete/board.h>

#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500
#define WINDOW_HEIGHT 550

#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024
Expand Down
4 changes: 2 additions & 2 deletions program/include/instance/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ typedef struct settings {
bool is_reduce;

clock_t time_ms;
} Settings;
} settings_s;

Settings * get_settings_singleton(void);
settings_s * get_settings_singleton(void);

#endif /* INSTANCE_SETTINGS_H */
44 changes: 44 additions & 0 deletions program/include/style.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef STYLE_H
#define STYLE_H

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_KEYSTATE_BASED_INPUT
#include <nuklear.h>

enum theme {
DARK_MODE, LIGHT_MODE,
};

static inline void set_style(struct nk_context *ctx, enum theme theme) {
struct nk_color table[NK_COLOR_COUNT];

table[NK_COLOR_TEXT] = nk_rgba(0x1B, 0x1B, 0x1B, 0xFF);
table[NK_COLOR_WINDOW] = nk_rgba(0xD9, 0xD9, 0xD9, 0xFF);
table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_BORDER] = nk_rgba(0xD9, 0xD9, 0xD9, 255);
table[NK_COLOR_BUTTON] = nk_rgba(0xD9, 0xD9, 0xD9, 255);
table[NK_COLOR_BUTTON_HOVER] = nk_rgba(0xD9, 0xD9, 0xD9, 255);
table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(0xD9, 0xD9, 0xD9, 255);
table[NK_COLOR_SLIDER] = nk_rgba(0x82, 0x82, 0x82, 255);
table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(0x1B, 0x1B, 0x1B, 255);
table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(0x1B, 0x1B, 0x1B, 255);
table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(0x1B, 0x1B, 0x1B, 255);
table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255);
table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255);
table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255);
table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255);

nk_style_from_table(ctx, table);
}

#endif
12 changes: 5 additions & 7 deletions program/source/algorithms/backtrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <algorithms/backtrack.h>
#include <instance/settings.h>
#include <instance/statistics.h>
#include <instance/expect.h>

bool _backtrack_row_sum(board_s board, state_array_s current_state, size_t index);
bool _backtrack_col_sum(board_s board, state_array_s current_state, size_t index);
Expand Down Expand Up @@ -51,8 +50,8 @@ bool _backtrack_row_sum(board_s board, state_array_s current_state, size_t index
}

return
((filled_blocks == blocks) ? filled_sums != sums : false) ||
(filled_sums > sums) ||
((filled_blocks == blocks) ? filled_sums != sums : false) ||
(filled_sums > sums) ||
((blocks - filled_blocks) ? get_sums(blocks - filled_blocks, UPPER_EDGE_E) < (sums - filled_sums) : false) ||
((blocks - filled_blocks) ? get_sums(blocks - filled_blocks, LOWER_EDGE_E) > (sums - filled_sums) : false);
}
Expand All @@ -68,15 +67,14 @@ bool _backtrack_col_sum(board_s board, state_array_s current_state, size_t index
}

return
((blocks == filled_blocks) ? filled_sums != sums : false) ||
(filled_sums > sums) ||
((blocks == filled_blocks) ? filled_sums != sums : false) ||
(filled_sums > sums) ||
((blocks - filled_blocks) ? get_sums(blocks - filled_blocks, UPPER_EDGE_E) < (sums - filled_sums) : false) ||
((blocks - filled_blocks) ? get_sums(blocks - filled_blocks, LOWER_EDGE_E) > (sums - filled_sums) : false);
}

bool _backtrack_valid_sums(board_s board, state_array_s current_state) {
error_mode = DEFAULT_E;
expect(is_end_state(current_state), return false, "current state is not an end state");
if (!is_end_state(current_state)) return false;

check_e * checks = calloc(board.game.empty_count, sizeof(check_e));

Expand Down
41 changes: 30 additions & 11 deletions program/source/gui/graphics.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <style.h>

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
Expand Down Expand Up @@ -71,9 +72,20 @@ void _glfw_initialize(GLFWwindow ** window, int * width, int * height) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

*window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SLNOSLAV", NULL, NULL);
glfwMakeContextCurrent(*window);
glfwGetWindowSize(*window, width, height);

GLFWimage favicon;

favicon.pixels = stbi_load("./assets/favicon.png", &favicon.width, &favicon.height, 0, 4);
error_mode = ASSERT_E;
expect(favicon.pixels, NO_ACTION, "[ERROR] Failed to load favicon image");

glfwSetWindowIcon(*window, 1, &favicon);
stbi_image_free(favicon.pixels);
}

void _glew_initialize(void) {
Expand All @@ -82,15 +94,22 @@ void _glew_initialize(void) {
GLenum error = glewInit();

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

struct nk_super _create_super(struct nk_glfw * glfw, GLFWwindow * window) {
struct nk_context * context = nk_glfw3_init(glfw, window, NK_GLFW3_INSTALL_CALLBACKS);
struct nk_font_atlas atlas;
struct nk_font_atlas * atlas_ptr = &atlas;
nk_glfw3_font_stash_begin(glfw, &atlas_ptr);
struct nk_font_config cfg = nk_font_config(0);
cfg.oversample_h = 3;
cfg.oversample_v = 2;
struct nk_font_atlas * atlas;

nk_glfw3_font_stash_begin(glfw, &atlas);
struct nk_font * roboto = nk_font_atlas_add_from_file(atlas, "./assets/font/Roboto-Regular.ttf", 20.0f, &cfg);
nk_glfw3_font_stash_end(glfw);
nk_init_default(context, &roboto->handle);

set_style(context, LIGHT_MODE);

FILE * fp = fopen(get_settings_singleton()->filepath, "rb");
expect(fp, NO_ACTION, "[ERROR] File pointer variable (fp) is NULL (%p): %s", (void*)fp, strerror(errno));
Expand All @@ -116,13 +135,13 @@ struct nk_media _create_media(void) {
glEnable(GL_TEXTURE_2D);

struct nk_media media = { 0 };
media.play = icon_load("./program/assets/icons/forwards.png");
media.pause = icon_load("./program/assets/icons/stop.png");
media.begin = icon_load("./program/assets/icons/start.png");
media.end = icon_load("./program/assets/icons/end.png");
media.reverse = icon_load("./program/assets/icons/backwards.png");
media.next = icon_load("./program/assets/icons/next.png");
media.previous = icon_load("./program/assets/icons/previous.png");
media.play = icon_load("./assets/icons/forwards.png");
media.pause = icon_load("./assets/icons/stop.png");
media.begin = icon_load("./assets/icons/start.png");
media.end = icon_load("./assets/icons/end.png");
media.reverse = icon_load("./assets/icons/backwards.png");
media.next = icon_load("./assets/icons/next.png");
media.previous = icon_load("./assets/icons/previous.png");

return media;
}
Expand Down
60 changes: 11 additions & 49 deletions program/source/gui/interface/grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define RGB_WHITE (nk_rgb(255, 255, 255))
#define RGB_BLACK (nk_rgb(0, 0, 0))
#define RGB_DARK_GRAY (nk_rgb(64, 64, 64))
#define RGB_LIGHT_GRAY (nk_rgb(192, 192, 192))
#define RGB_WHITE (nk_rgb(0xD9, 0xD9, 0xD9))
#define RGB_BLACK (nk_rgb(0x1B, 0x1B, 0x1B))
#define RGB_GRAY (nk_rgb(0x82, 0x82, 0x82))
#define RGB_GRAY (nk_rgb(192, 192, 192))

#define SUM_SQUARE(block_size) { \
.x = 0.15 * ((block_size) / 2), .y = 0.15 * ((block_size) / 2), \
Expand All @@ -33,9 +33,6 @@ struct nk_rect _background(struct nk_context * context, board_s board);
void _lines(struct nk_context * context, board_s board, struct nk_rect background);

void _unset_blocks(struct nk_context * context, board_s board, struct nk_rect background);
void _sum_triangles(struct nk_context * context, board_s board, struct nk_rect background);
void _upper_sum_triangle(struct nk_context * context, struct nk_rect background, ulookup_t row, ulookup_t col, float block_size);
void _lower_sum_triangle(struct nk_context * context, struct nk_rect background, ulookup_t row, ulookup_t col, float block_size);
void _sum_values(struct nk_context * context, board_s board, struct nk_rect background);
void _upper_sum_value(struct nk_context * context, struct nk_rect background, struct nk_rect sum_square, ulookup_t row, ulookup_t col, float block_size, lookup_t value);
void _lower_sum_value(struct nk_context * context, struct nk_rect background, struct nk_rect sum_square, ulookup_t row, ulookup_t col, float block_size, lookup_t value);
Expand All @@ -50,7 +47,7 @@ void grid(struct nk_context * context, board_s board) {
struct nk_rect background = _background(context, board);
_lines(context, board, background);
_unset_blocks(context, board, background);
_sum_triangles(context, board, background);
//_sum_triangles(context, board, background);
_sum_values(context, board, background);
_empty_values(context, board, background);
}
Expand All @@ -74,15 +71,15 @@ void _lines(struct nk_context * context, board_s board, struct nk_rect backgroun
ulookup_t row_size = board.game.size[ROW_E], col_size = board.game.size[COLUMN_E];
float block_size = background.w / board.game.size[COLUMN_E];

for(ulookup_t i = 1; i < col_size; i++) {
for(ulookup_t i = 0; i <= col_size; i++) {
float x0 = background.x + (block_size * i), y0 = background.y;
float x1 = background.x + (block_size * i), y1 = background.y + background.h;
nk_stroke_line(&context->current->buffer, x0, y0, x1, y1, 0.5f, RGB_DARK_GRAY);
nk_stroke_line(&context->current->buffer, x0, y0, x1, y1, 0.5f, RGB_GRAY);
}
for(ulookup_t j = 1; j < row_size; j++) {
for(ulookup_t j = 0; j <= row_size; j++) {
float x0 = background.x, y0 = background.y + (block_size * j);
float x1 = background.x + background.w, y1 = background.y + (block_size * j);
nk_stroke_line(&context->current->buffer, x0, y0, x1, y1, 0.5f, RGB_DARK_GRAY);
nk_stroke_line(&context->current->buffer, x0, y0, x1, y1, 0.5f, RGB_GRAY);
}
}

Expand All @@ -102,41 +99,6 @@ void _unset_blocks(struct nk_context * context, board_s board, struct nk_rect ba
destroy_max_overlap_rectangles(&array);
}

void _sum_triangles(struct nk_context * context, board_s board, struct nk_rect background) {
ulookup_t row_size = board.game.size[ROW_E];
ulookup_t col_size = board.game.size[COLUMN_E];
float block_size = (background.w / col_size);

for (ulookup_t r = 0; r < row_size; r++) {
for (ulookup_t c = 0; c < col_size; c++) {
if (board.game.grids[ROW_E][r][c] > 0) _upper_sum_triangle(context, background, r, c, block_size);
if (board.game.grids[COLUMN_E][r][c] > 0) _lower_sum_triangle(context, background, r, c, block_size);
}
}
}

void _upper_sum_triangle(struct nk_context * context, struct nk_rect background, ulookup_t row, ulookup_t col, float block_size) {
float x0 = background.x + (col * block_size), y0 = background.y + (row * block_size);
float x1 = x0 + block_size, y1 = y0;
float x2 = x0 + block_size, y2 = y0 + block_size;

nk_fill_triangle(&context->current->buffer, x0, y0, x1, y1, x2, y2, RGB_DARK_GRAY);
nk_stroke_line(&context->current->buffer, x0, y0, x1, y1, 0.5f, RGB_LIGHT_GRAY);
nk_stroke_line(&context->current->buffer, x0, y0, x2, y2, 0.5f, RGB_LIGHT_GRAY);
nk_stroke_line(&context->current->buffer, x1, y1, x2, y2, 0.5f, RGB_LIGHT_GRAY);
}

void _lower_sum_triangle(struct nk_context * context, struct nk_rect background, ulookup_t row, ulookup_t col, float block_size) {
float x0 = background.x + (col * block_size), y0 = background.y + (row * block_size);
float x1 = x0, y1 = y0 + block_size;
float x2 = x0 + block_size, y2 = y0 + block_size;

nk_fill_triangle(&context->current->buffer, x0, y0, x1, y1, x2, y2, RGB_DARK_GRAY);
nk_stroke_line(&context->current->buffer, x0, y0, x1, y1, 0.5f, RGB_LIGHT_GRAY);
nk_stroke_line(&context->current->buffer, x0, y0, x2, y2, 0.5f, RGB_LIGHT_GRAY);
nk_stroke_line(&context->current->buffer, x1, y1, x2, y2, 0.5f, RGB_LIGHT_GRAY);
}

void _sum_values(struct nk_context * context, board_s board, struct nk_rect background) {
ulookup_t row_size = board.game.size[ROW_E];
ulookup_t col_size = board.game.size[COLUMN_E];
Expand All @@ -162,7 +124,7 @@ void _upper_sum_value(struct nk_context * context, struct nk_rect background, st
.h = sum_square.h,
};

_draw_value(context, upper_sum, RGB_DARK_GRAY, RGB_WHITE, value);
_draw_value(context, upper_sum, RGB_GRAY, RGB_WHITE, value);
}

void _lower_sum_value(struct nk_context * context, struct nk_rect background, struct nk_rect sum_square, ulookup_t row, ulookup_t col, float block_size, lookup_t value) {
Expand All @@ -173,7 +135,7 @@ void _lower_sum_value(struct nk_context * context, struct nk_rect background, st
.h = sum_square.h,
};

_draw_value(context, lower_sum, RGB_DARK_GRAY, RGB_WHITE, value);
_draw_value(context, lower_sum, RGB_GRAY, RGB_WHITE, value);
}

void _empty_values(struct nk_context * context, board_s board, struct nk_rect background) {
Expand Down
1 change: 1 addition & 0 deletions program/source/gui/interface/solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void * _solver(void * data) {
state_array_s guess = pop_stack(&stack);
{
state_array_s temp = copy_state_array(guess);
error_mode = ASSERT_E;
expect(-1 != write(pipefd[WRITE_PIPE_E], &temp, sizeof(state_array_s)),
NO_ACTION, "[ERROR] Write to pipe failed: %s", strerror(errno));
}
Expand Down
4 changes: 1 addition & 3 deletions program/source/instance/argument.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ void setup_program(int argc, char **argv) {
// call to settings setup to set program settings
_setup_settings(argument);
}


}

Hash _get_hash(char * string) {
Expand Down Expand Up @@ -294,7 +292,7 @@ void _setup_help(char * value) {
printf("\t--information,-i show information about SLNOSLAV\n");

printf("\nProgram settings:\n");
printf("\t--filepath,-fp <filepath> filepath to .kkr file [\"program/0.kkr\"]\n");
printf("\t--filepath,-fp <filepath> filepath to .kkr file [\"puzzles/0.kkr\"]\n");
printf("\t--backtrack,-bt enable backtracking [disabled]\n");
printf("\t--forward-check,-fch enable forward checking [disabled]\n");
printf("\t--arc-consistency,-ac enable arc-consistency [disabled]\n");
Expand Down
6 changes: 3 additions & 3 deletions program/source/instance/settings.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <instance/settings.h>

Settings * get_settings_singleton(void) {
static Settings setup = {
.filepath = "program/0.kkr",
settings_s * get_settings_singleton(void) {
static settings_s setup = {
.filepath = "assets/puzzles/0.kkr",
.is_backtrack = false,
.is_forward_check = false,
.is_arc_consistency = false,
Expand Down
Loading

0 comments on commit bc165e7

Please sign in to comment.