Debian Codegraph @

prboom2/src/dsda/utility.h

raw
1 //
2 // Copyright(C) 2022 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Utility
16 //
17
18 #ifndef __DSDA_UTILITY__
19 #define __DSDA_UTILITY__
20
21 #include <string.h>
22
23 #include "d_ticcmd.h"
24 #include "tables.h"
25
26 #if !defined(__GNUC__) && !defined(__clang__)
27 #define __attribute__(x)
28 #endif
29
30 #define FIXED_STRING_LENGTH 16
31 #define COMMAND_MOVEMENT_STRING_LENGTH 18
32
33 #define ZERO_DATA(item) memset(&item, 0, sizeof(item))
34
35 typedef struct {
36 dboolean negative;
37 int base;
38 int frac;
39 } dsda_fixed_t;
40
41 typedef struct {
42 int base;
43 int frac;
44 } dsda_angle_t;
45
46 typedef struct {
47 byte bytes[16];
48 char string[33];
49 } dsda_cksum_t;
50
51 typedef struct {
52 char* string;
53 size_t size;
54 } dsda_string_t;
55
56 void dsda_InitString(dsda_string_t* dest, const char* value);
57 void dsda_FreeString(dsda_string_t* dest);
58 void dsda_StringCat(dsda_string_t* dest, const char* source);
59 void dsda_StringCatF(dsda_string_t* dest, const char* format, ...) __attribute__((format(printf,2,3)));
60 void dsda_StringPrintF(dsda_string_t* dest, const char* format, ...) __attribute__((format(printf,2,3)));
61 void dsda_TranslateCheckSum(dsda_cksum_t* cksum);
62 dboolean dsda_HasFileExt(const char* file, const char* ext);
63 char** dsda_SplitString(char* str, const char* delimiter);
64 void dsda_UppercaseString(char* str);
65 void dsda_FixedToString(char* str, fixed_t x);
66 dsda_fixed_t dsda_SplitFixed(fixed_t x);
67 dsda_angle_t dsda_SplitAngle(angle_t x);
68 void dsda_PrintCommandMovement(char* str, ticcmd_t* cmd);
69 char* dsda_ConcatDir(const char* a, const char* b);
70 void dsda_CutExtension(char* str);
71 const char* dsda_BaseName(const char* str);
72 const char* dsda_FileExtension(const char* str);
73 double dsda_DistancePointToLine(fixed_t line_x1, fixed_t line_y1,
74 fixed_t line_x2, fixed_t line_y2,
75 fixed_t point_x, fixed_t point_y);
76 fixed_t dsda_FixedDistancePointToLine(fixed_t line_x1, fixed_t line_y1,
77 fixed_t line_x2, fixed_t line_y2,
78 fixed_t point_x, fixed_t point_y,
79 fixed_t *closest_x, fixed_t *closest_y);
80 fixed_t dsda_FloatToFixed(float x);
81 fixed_t dsda_StringToFixed(const char* x);
82 byte dsda_FloatToPercent(float x);
83 int dsda_IntToFixed(int x);
84 angle_t dsda_DegreesToAngle(float x);
85
86 #define DO_ONCE { static int do_once = true; if (do_once) {
87 #define END_ONCE do_once = false; } }
88
89 #endif