comparison src/utils.h @ 30:f945bcc3571f

refactor
author Dennis C. M. <dennis@denniscm.com>
date Thu, 29 Jun 2023 17:48:36 +0100
parents dae463bbf5ca
children 61104b22a25d
comparison
equal deleted inserted replaced
29:dae463bbf5ca 30:f945bcc3571f
4 #include <stdio.h> 4 #include <stdio.h>
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <time.h> 6 #include <time.h>
7 #include <stdbool.h> 7 #include <stdbool.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 #include <GL/glut.h>
10 #include <pthread.h>
11 #include <ft2build.h>
12 #include <signal.h>
13 #include FT_FREETYPE_H
9 14
10 15
11 struct Element { 16 struct Element {
12 float value; 17 float value;
13 bool current; 18 bool current;
16 struct Algo { 21 struct Algo {
17 char name[50]; 22 char name[50];
18 void *(*function)(void *); 23 void *(*function)(void *);
19 }; 24 };
20 25
26 struct AlgoArgs {
27 struct Element *arr;
28 int arr_size;
29 int comparisons;
30 bool pause;
31 bool sequentially;
32 useconds_t delay;
33 };
34
35
36 struct ThreadState {
37 bool running;
38 pthread_t thread;
39 };
40
21 void create_array(struct Element *arr, int arr_size, int window_height, int vpadding); 41 void create_array(struct Element *arr, int arr_size, int window_height, int vpadding);
22 void swap_elements(int x, int y, struct Element *arr); 42 void swap_elements(int x, int y, struct Element *arr);
23 void randomize_array(struct Element *arr, int arr_size); 43 void randomize_array(struct Element *arr, int arr_size);
24 bool array_sorted(struct Element *arr, int arr_size); 44 bool array_sorted(struct Element *arr, int arr_size);
25 void algorithm_selector(struct Algo *algos, int direction, int *selected_algorithm); 45 void algorithm_selector(struct Algo *algos, int algos_size, int direction, int *selected_algo);
26 void delay_flow(useconds_t *delay, bool *pause); 46 void change_speed(struct AlgoArgs *algo_args, int change);
47 void control_flow(useconds_t delay, bool sequentially, bool *pause);
48 void reset_state(struct AlgoArgs *algo_args, struct ThreadState *thread_state);
49 void run(struct AlgoArgs *algo_args, struct Algo *algos, int selected_algo,
50 struct ThreadState *thread_state);
27 51
28 52
29 #endif // UTILS_H 53 #endif // UTILS_H