-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
111 lines (101 loc) · 2.68 KB
/
Copy pathmain.c
File metadata and controls
111 lines (101 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "common.h"
#include <time.h>
/* ─── Global registry ──────────────────────────────────────────── */
t_algorithm g_algorithms[MAX_ALGORITHMS];
int g_algo_count = 0;
/* ─── Forward declarations ─────────────────────────────────────── */
void register_bubble_sort(void);
void register_selection_sort(void);
void register_insertion_sort(void);
void register_merge_sort(void);
void register_quick_sort(void);
void register_heap_sort(void);
void register_shell_sort(void);
void register_gnome_sort(void);
void register_cocktail_sort(void);
void register_algorithm(t_algorithm algo)
{
if (g_algo_count < MAX_ALGORITHMS)
g_algorithms[g_algo_count++] = algo;
}
static void init_font(void)
{
const char *font_paths[5];
Font loaded;
int i;
font_paths[0] = "/usr/share/fonts/TTF/OpenSans-SemiBold.ttf";
font_paths[1] = "/usr/share/fonts/TTF/OpenSans-Regular.ttf";
font_paths[2] = "/usr/share/fonts/TTF/DejaVuSans.ttf";
font_paths[3] = "/usr/share/fonts/liberation/LiberationSans-Regular.ttf";
font_paths[4] = NULL;
i = 0;
while (font_paths[i])
{
if (FileExists(font_paths[i]))
{
loaded = LoadFontEx(font_paths[i], 48, NULL, 0);
SetTextureFilter(loaded.texture, TEXTURE_FILTER_BILINEAR);
SetAppFont(loaded);
break ;
}
i++;
}
}
static void init_app(t_app_state *state)
{
memset(state, 0, sizeof(*state));
state->view_count = 1;
state->global_size = DEFAULT_SIZE;
state->global_speed = 4;
state->show_panel = true;
state->last_hl_val = -1;
InitAudioDevice();
InitSounds();
register_bubble_sort();
register_selection_sort();
register_insertion_sort();
register_merge_sort();
register_quick_sort();
register_heap_sort();
register_shell_sort();
register_gnome_sort();
register_cocktail_sort();
srand((unsigned)time(NULL));
set_view_count(state, 1);
}
static void game_loop(t_app_state *state)
{
float wheel;
while (!WindowShouldClose())
{
if (!state->paused)
{
update_sorts(state);
handle_sound(state);
}
wheel = GetMouseWheelMove();
if (wheel != 0)
state->panel_scroll -= (int)(wheel * 22);
if (state->panel_scroll < 0)
state->panel_scroll = 0;
handle_input(state);
BeginDrawing();
ClearBackground(COL_BG);
draw_frame(state);
EndDrawing();
}
}
int main(void)
{
t_app_state state;
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_MSAA_4X_HINT);
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "SortViz \xe2\x80\x94 Algorithm Visualizer");
SetTargetFPS(60);
init_font();
init_app(&state);
game_loop(&state);
UnloadSounds();
CloseAudioDevice();
CloseWindow();
return (0);
}