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
/* === TODO: Should we use mutex locks instead ? ===*/
116
#define N_SIMULTANEOUS_CALLS 64
117
#define N_SIMULTANEOUS_CALLS_MASK 63
118
119
/* Should zboolean type be sig_atomic_t ???? */
120
#undef TRUE
121
#undef FALSE
122
#define TRUE (1)
123
#define FALSE (0)
124
125
typedef
int32_t zboolean32;
126
typedef
int16_t zboolean16;
127
typedef
int8_t zboolean8;
128
129
/* Couldn't find anything fancier at the moment */
130
typedef
zboolean32 zboolean;
131
132
/* (Previously)
133
typedef enum {
134
FALSE = (0), TRUE = (!FALSE)
135
} zboolean;
136
* Buggy because, if TRUE and FALSE are enum constants, the preprocessor
137
* will always replace them with zeros.
138
* See https://gcc.gnu.org/onlinedocs/cpp/If.html#If
139
*/
140
141
#define YES (1)
142
#define NO (0)
143
144
#include "str_mem.h"
145
#include "tcp_socket.h"
146
#include "error.h"
147
#include "misc.h"
148
/*#include "dllist.h"*/
149
#ifdef WIN32_V
150
#include "win32_specific.h"
151
#endif
152
#ifdef ANDROID_V
153
#include "android_specific.h"
154
#endif
155
156
#ifndef MAX
157
#define MAX(x,y) ((x) > (y) ? (x) : (y))
158
#endif
159
160
#ifndef MIN
161
#define MIN(x,y) ((x) < (y) ? (x) : (y))
162
#endif
163
164
#ifndef ABS
165
#define ABS(x) ((x) > 0 ? (x) : -(x))
166
#endif
167
168
/* Do more testing for the 2 following ones */
169
#ifndef SIGN
170
#define SIGN(x) ((x) != 0 ? ((x) > 0 ? 1 : -1) : 0)
171
#endif
172
173
/* DEPRECATED - use roundf instead which is always correct */
174
/* Only if f > 0 */
175
/*#ifndef APPROX
176
#define APPROX(f) (ABS(((f) - (int)(f)) > 0.5) ? (int)(f) + SIGN((f)) : (int)(f))
177
#endif*/
178
#endif
/* INC_LIBETM_H */
src
extra_libs
libetm-0.6.0
libetm.h
Generated by
1.9.8