]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/util.h
ec63c1c356c0d035c9a9750b977302b4537a2c5e
[dragonblocks_alpha.git] / src / util.h
1 #ifndef _UTIL_H_
2 #define _UTIL_H_
3
4 #include <stdbool.h>
5 #include <arpa/inet.h>
6 #include <dragontype/number.h>
7
8 #define ever (;;)                                                                                                               // infinite for loop with style
9 #define INBRACES(str) str ? "(" : "", str ? str : "", str ? ")" : ""    // wrapper for printf to optionally add a message in braces if message is not NULL
10 #define CMPBOUNDS(x) x == 0 ? 0 : x > 0 ? 1 : -1                                                // resolves 1 if x > 0, 0 if x == 0 and -1 if x < 0
11 #define fallthrough __attribute__ ((fallthrough))                                               // prevent compiler warning about implicit fallthrough with style
12 #define unused __attribute__ ((unused))
13 #define U32(x) (((u32) 1 << 31) + x)
14
15 extern const char *program_name;        // this has to be set to program name on startup
16
17 void syscall_error(const char *err);                                                                                                                                                                            // print system call related error message and exit
18 void internal_error(const char *err);                                                                                                                                                                           // print general error message and exit
19 char *read_string(int fd, size_t bufsiz);                                                                                                                                                                       // read from fd until \0 or EOF terminator
20 char *address_string(struct sockaddr_in6 *addr);                                                                                                                                                        // convert IPv6 address to human readable, return allocated buffer
21 v3f32 html_to_v3f32(const char *html);                                                                                                                                                                          // convert #RRGGBB color to v3f32
22 void my_compress(const void *uncompressed, size_t uncompressed_size, char **compressed, size_t *compressed_size);                       // compress data using ZLib and store result(buffer allocated by malloc) in compressed
23 bool my_decompress(const char *compressed, size_t compressed_size, void *decompressed, size_t expected_decompressed_size);      // decompress data and put result into decompressed, return false if decompressed size does not match expected_decompressed_size
24 bool within_simulation_distance(v3f64 player_pos, v3s32 block_pos, u32 simulation_distance);                                                            // return true if a player is close enough to a block to access it
25
26 #endif