-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdm_algorithm.h
120 lines (108 loc) · 4.13 KB
/
dm_algorithm.h
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
112
113
114
115
116
117
118
119
120
#ifndef DM_ALGORITHM
#define DM_ALGORITHM
#include "dm_defines.h"
// SHADOWCASTING
bool dm_sc_is_leakageblocked(int x, int y, int ax, int ay, bool (*is_blocked)(int, int));
void dm_shadowcast_r(
int x, int y,
int xmax, int ymax,
unsigned int radius,
bool (*is_blocked)(int, int),
void (*on_visible)(int, int, double),
bool allow_leakage,
int octant, int row, double start_slope, double end_slope,
int xx, int xy, int yx, int yy,
int *history
);
void dm_shadowcast(int x, int y, int xmax, int ymax, unsigned int radius, bool (*is_blocked)(int, int), void (*on_visible)(int, int, double), bool allow_leakage);
// SPIRAL
struct dm_spiral {
int x, y;
int leg, layer, maxlayers;
};
struct dm_spiral dm_spiral(int maxlayers);
bool dm_spiralnext(struct dm_spiral*);
// BRESENHAM LINE
void dm_bresenham(int x1, int y1, int x2, int y2, bool (*is_blocked)(int, int), void (*on_visible)(int, int));
// FLOODFILL
void dm_floodfill(int x, int y, bool (*is_blocked)(int, int, int), void (*on_flood)(int, int, int));
void dm_floodfill_r(int x, int y, bool (*is_blocked)(int, int, int), void (*on_flood)(int, int, int), int depth);
int dm_floodfill_id();
// RANDOM
void dm_seed(unsigned long seed);
double dm_randf();
int dm_randi();
int dm_randii(int a, int b);
bool dm_chance(int in, int outof);
// MATH
int dm_maxi(int a, int b);
double dm_maxf(double a, double b);
int dm_mini(int a, int b);
double dm_minf(double a, double b);
int dm_disti(int x1, int y1, int x2, int y2);
double dm_distf(double x1, double y1, double x2, double y2);
void dm_direction(double x1, double y1, double x2, double y2, double *xref, double *yref);
void dm_normalize(double x, double y, double *xref, double *yref);
double dm_round(double val);
double dm_ceil_out(double val);
// STRING
void dm_splitstr(char *text, char splitter, int m, int n, char words[m][n], int *wordlen);
void dm_lines(int m, int n, char words[m][n], int sentence_size, int o, int p, char lines[o][p], int *linelen);
void dm_wordwrap(char *text, int size, void (*on_line)(char *line));
// ASTAR
struct dm_astarnode {
unsigned int astar_id;
int astar_x;
int astar_y;
bool astar_closed;
bool astar_opened;
int astar_fcost;
int astar_gcost;
int astar_hcost;
struct dm_astarnode* astar_parent;
struct dm_astarnode* astar_child;
// helper pointer to something we can reference in the parent world in the getters below
void *owner;
// getters for parent world to let me update my astar x and y
int (*get_x)(struct dm_astarnode*);
int (*get_y)(struct dm_astarnode*);
};
struct dm_astarlist {
unsigned int index;
unsigned int length;
unsigned int capacity;
struct dm_astarnode **list;
};
struct dm_astarnode* dm_astar_newnode();
void dm_astar_reset(struct dm_astarnode* node);
void dm_astar_clean(struct dm_astarnode* node, unsigned int astar_id);
bool dm_astar_equals(struct dm_astarnode* node_a, struct dm_astarnode* node_b);
void dm_astarlist_push(struct dm_astarlist *list, struct dm_astarnode *node);
void dm_astarlist_remove(struct dm_astarlist *list, struct dm_astarnode *node);
void dm_astarlist_free(struct dm_astarlist *list);
void dm_astar(
struct dm_astarnode *start_node,
struct dm_astarnode *end_node,
bool (*is_blocked)(struct dm_astarnode*, struct dm_astarnode*),
struct dm_astarnode* (*get_node)(int, int),
void (*on_path)(struct dm_astarnode*),
bool is_cardinal_only,
bool is_manhattan
);
void dm_astar_check(
struct dm_astarnode *current_node,
struct dm_astarnode *end_node,
int neighbor_x,
int neighbor_y,
struct dm_astarlist *open_list,
bool (*is_blocked)(struct dm_astarnode*, struct dm_astarnode*),
struct dm_astarnode* (*get_node)(int, int),
bool is_manhattan
);
// CELLULAR AUTOMATA
int dm_cella_count_alive_neighbors(int *map, int x, int y, int width, int height);
void dm_cella_simulate(int *map, int width, int height, int deathLimit, int birthLimit);
void dm_cella_init(int *map, int width, int height, double chanceToStartAlive);
void dm_cellular_automata(int width, int height, void (*on_solid)(int, int), void (*on_open)(int, int));
void dm_cellular_automata_detail(int width, int height, void (*on_solid)(int, int), void (*on_open)(int, int), double alive_chance, int death_max, int birth_max, int steps);
#endif