LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
libetm.h
1
/*
2
* libetm / libetm.h - Copyright (C) Emmanuel Thomas-Maurin 2008-2026
3
* <
[email protected]
>
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include <stdint.h>
20
21
#ifndef INC_LIBETM_H
22
#define INC_LIBETM_H
23
24
#define LIBETM_NAME "Libetm"
25
#define LIBETM_VERSION_NUM "0.6.0"
26
27
#ifndef _GNU_SOURCE
28
#define _GNU_SOURCE
29
#endif
30
#ifndef _ISOC11_SOURCE
31
#define _ISOC11_SOURCE
32
#endif
33
34
// === BIG CLEAN UP REQUIRED FROM HERE ===
35
36
/* TODO: Check/fix/spec this, quite confusing at the moment */
37
/*#if !defined(ANDROID_V) && !defined(LINUX_V) && !defined(WIN32_V)
38
# error No platform is defined
39
#endif*/
40
41
/*
42
* We should eventually define these in Makefile(s) or wherever
43
* (when compiling libetm and/or when linking against libetm)
44
* but definitely not here.
45
* Then only use INFO_OUT/ERR, VERBOSE_INFO_OUT/ERR, DEBUG_INFO_OUT
46
* in app code.
47
*/
48
/*#define LIBETM_VERBOSE_OUTPUT*/
49
/*#define LIBETM_DEBUG_OUTPUT*/
50
51
/* Is this one still relevant ? */
52
/*#define LIBETM_EXPERIMENTAL_STUFF*/
53
54
// === TO HERE ===
55
56
/*
57
* stdout and stderr on Linux and Android / text files on win32
58
* (see win32_specific.c)
59
*/
60
#ifdef WIN32_V
61
#define STD_OUT std_out
62
#define STD_ERR std_err
63
#else
64
#define STD_OUT stdout
65
#define STD_ERR stderr
66
#endif
67
/*
68
* === WARNING: Don't put a ';' at the end of theses INFO_whatever, or it will be a mess ===
69
*/
70
#if defined(LIBETM_VERBOSE_OUTPUT) || defined(LIBETM_DEBUG_OUTPUT)
71
#ifdef ANDROID_V
72
#define FILE_LINE_FUNC_STR "[%s: %d] %s(): ", basename2(__FILE__) , __LINE__, __func__
73
#else
74
#define FILE_LINE_FUNC_STR "[%s: %d] %s(): ", __FILE__ , __LINE__, __func__
75
#endif
76
#else
77
#define FILE_LINE_FUNC_STR ""
78
#endif
79
80
#ifndef ANDROID_V
81
#define INFO_OUT(...) \
82
{\
83
fprintf(STD_OUT, __VA_ARGS__);\
84
fflush(STD_OUT);\
85
}
86
#define INFO_ERR(...) \
87
{\
88
fprintf(STD_ERR, FILE_LINE_FUNC_STR);\
89
fprintf(STD_ERR, __VA_ARGS__);\
90
fflush(STD_ERR);\
91
}
92
#else
93
#ifndef ANDROID_NO_LOGGING
94
#include <android/log.h>
95
#define INFO_OUT(...) \
96
__android_log_print(ANDROID_LOG_INFO, "_android_out_", __VA_ARGS__);
97
#define INFO_ERR(...) \
98
__android_log_print(ANDROID_LOG_ERROR, "_android_err_", FILE_LINE_FUNC_STR); \
99
__android_log_print(ANDROID_LOG_ERROR, "_android_err_", __VA_ARGS__);
100
#else
101
#define INFO_OUT(...) {}
102
#define INFO_ERR(...) {}
103
#endif
104
#endif
105
106
/* TODO: Check this is still working with newly added Android stuff */
107
#ifdef LIBETM_VERBOSE_OUTPUT
108
#define VERBOSE_INFO_OUT(...) INFO_OUT(__VA_ARGS__)
109
#define VERBOSE_INFO_ERR(...) INFO_ERR(__VA_ARGS__)
110
#else
111
#define VERBOSE_INFO_OUT(...) {}
112
#define VERBOSE_INFO_ERR(...) {}
113
#endif
114
115
/* This is moved to LibGame: libgame.h -
116
#ifdef LIBETM_DEBUG_OUTPUT
117
#define DEBUG_INFO_OUT(...) \
118
{\
119
fprintf(STD_OUT, FILE_LINE_FUNC_STR);\
120
INFO_OUT(__VA_ARGS__)\
121
}
122
#else
123
#define DEBUG_INFO_OUT(...) \
124
{}
125
#endif*/
126
127
/* === TODO: Should we use mutex locks instead ? ===*/
128
#define N_SIMULTANEOUS_CALLS 64
129
#define N_SIMULTANEOUS_CALLS_MASK 63
130
131
/* Should zboolean type be sig_atomic_t ???? */
132
#undef TRUE
133
#undef FALSE
134
#define TRUE (1)
135
#define FALSE (0)
136
typedef
int32_t zboolean;
/* Couldn't find anything fancier at the moment */
137
138
/* (Previously)
139
typedef enum {
140
FALSE = (0), TRUE = (!FALSE)
141
} zboolean;
142
* Buggy because, if TRUE and FALSE are enum constants, the preprocessor
143
* will always replace them with zeros.
144
* See https://gcc.gnu.org/onlinedocs/cpp/If.html#If
145
*/
146
147
#define YES (1)
148
#define NO (0)
149
150
#include "str_mem.h"
151
#include "tcp_socket.h"
152
#include "error.h"
153
#include "misc.h"
154
/*#include "dllist.h"*/
155
#ifdef WIN32_V
156
#include "win32_specific.h"
157
#endif
158
#ifdef ANDROID_V
159
#include "android_specific.h"
160
#endif
161
162
#ifndef MAX
163
#define MAX(x,y) ((x) > (y) ? (x) : (y))
164
#endif
165
166
#ifndef MIN
167
#define MIN(x,y) ((x) < (y) ? (x) : (y))
168
#endif
169
170
#ifndef ABS
171
#define ABS(x) ((x) > 0 ? (x) : -(x))
172
#endif
173
174
/* Do more testing for the 2 following ones */
175
#ifndef SIGN
176
#define SIGN(x) ((x) != 0 ? ((x) > 0 ? 1 : -1) : 0)
177
#endif
178
179
/* DEPRECATED - use roundf instead which is always correct */
180
/* Only if f > 0 */
181
/*#ifndef APPROX
182
#define APPROX(f) (ABS(((f) - (int)(f)) > 0.5) ? (int)(f) + SIGN((f)) : (int)(f))
183
#endif*/
184
#endif
/* INC_LIBETM_H */
src
extra_libs
libetm-0.6.0
libetm.h
Generated by
1.9.8