-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.h
92 lines (70 loc) · 2.31 KB
/
common.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
#ifndef _HAS_COMMON_H
#define _HAS_COMMON_H
#include <stdint.h>
struct ulong_ptr {
unsigned long i;
void *ptr;
};
struct double_ptr {
double i;
void *ptr;
};
struct ptr_num {
void* ptr;
size_t num;
};
enum msg {
MSG_PAUSE = 1,
MSG_CONT = 2,
MSG_WALL = 4,
MSG_TERM = 8,
MSG_RM = 16
};
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define die(FMT, ...) \
do { \
printf("yastg: panic in %s:%d: " FMT "\n", __FILE__, __LINE__, __VA_ARGS__); \
log_printfn(LOG_PANIC, "in %s:%d: " FMT "\n", __FILE__, __LINE__, __VA_ARGS__); \
exit(EXIT_FAILURE); \
} while(0)
#define bug(FMT, ...) \
do { \
printf("yastg: Oops! YASTG has encountered an internal bug in %s:%d and is crashing: " FMT "\n", __FILE__, __LINE__, __VA_ARGS__); \
log_printfn(LOG_PANIC, "Oops! YASTG has encountered an internal bug in %s:%d and is crashing: " FMT "\n", __FILE__, __LINE__, __VA_ARGS__); \
exit(EXIT_FAILURE); \
} while(0)
#define XYTORAD(x, y) \
(unsigned long)sqrt((double)x*x+y*y)
#define XYTOPHI(x, y) \
(atan2((double)y, (double)x))
#define POLTOX(phi, rad) \
(unsigned long)(rad*cos(phi))
#define POLTOY(phi, rad) \
(unsigned long)(rad*sin(phi))
#define MAX(x, y) \
((x > y) ? x : y)
#define MIN(x, y) \
((x < y) ? x : y)
void chomp(char *s);
int limit_long_to_int(const long l);
unsigned int limit_long_to_uint(const long l);
int str_to_long(const char * const str, long *out);
/* Greek alphabet */
#define GREEK_N 24
#define GREEK_LEN 7
extern const char* greek[GREEK_N];
/* Roman numerals */
#define ROMAN_N 24
#define ROMAN_LEN 5
extern const char* roman[ROMAN_N];
/* Astronomical constants */
#define GM_PER_AU 150 /* gigameters per astronomical unit */
#define AU_PER_LY 63241 /* Astronomical units per light year */
#define GM_PER_LY (GM_PER_AU * AU_PER_LY)
#define TICK_PER_LY 10000 /* Resolution of all coordinates (1/TICK_PER_LY lightyears) */
/* The "real" values here should be habitable zone from 0.95 to 1.37 AU and snow line (i.e. the upper limit
* for rocky planetary formation) at 2.7 AU in a sol like system.
* For simplicity, we assume habend == snowline and change the values somewhat. */
#define HAB_ZONE_START 0.95 /* Start of habitable zone in a sol like system, in AU */
#define HAB_ZONE_END 1.50 /* End of habitable zone in a sol like system, in AU */
#endif