2017-03-03 20:04:23 +00:00
|
|
|
#ifndef DEFS_H
|
|
|
|
#define DEFS_H
|
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
|
2018-02-23 12:50:41 +00:00
|
|
|
enum class Error {
|
2017-03-03 20:04:23 +00:00
|
|
|
OK,
|
|
|
|
FAILED, ///< Generic fail error
|
|
|
|
ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
|
|
|
|
ERR_UNCONFIGURED, ///< The object being used hasnt been properly set up yet
|
|
|
|
ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
|
|
|
|
ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
|
|
|
|
ERR_OUT_OF_MEMORY, ///< Out of memory
|
|
|
|
ERR_FILE_NOT_FOUND,
|
|
|
|
ERR_FILE_BAD_DRIVE,
|
|
|
|
ERR_FILE_BAD_PATH,
|
2018-11-23 22:09:41 +00:00
|
|
|
ERR_FILE_NO_PERMISSION, // (10)
|
2017-03-03 20:04:23 +00:00
|
|
|
ERR_FILE_ALREADY_IN_USE,
|
|
|
|
ERR_FILE_CANT_OPEN,
|
|
|
|
ERR_FILE_CANT_WRITE,
|
|
|
|
ERR_FILE_CANT_READ,
|
|
|
|
ERR_FILE_UNRECOGNIZED, // (15)
|
|
|
|
ERR_FILE_CORRUPT,
|
|
|
|
ERR_FILE_MISSING_DEPENDENCIES,
|
|
|
|
ERR_FILE_EOF,
|
|
|
|
ERR_CANT_OPEN, ///< Can't open a resource/socket/file
|
2018-11-23 22:09:41 +00:00
|
|
|
ERR_CANT_CREATE, // (20)
|
2017-03-03 20:04:23 +00:00
|
|
|
ERR_QUERY_FAILED,
|
|
|
|
ERR_ALREADY_IN_USE,
|
|
|
|
ERR_LOCKED, ///< resource is locked
|
|
|
|
ERR_TIMEOUT,
|
2018-11-23 22:09:41 +00:00
|
|
|
ERR_CANT_CONNECT, // (25)
|
2017-03-03 20:04:23 +00:00
|
|
|
ERR_CANT_RESOLVE,
|
|
|
|
ERR_CONNECTION_ERROR,
|
|
|
|
ERR_CANT_AQUIRE_RESOURCE,
|
|
|
|
ERR_CANT_FORK,
|
|
|
|
ERR_INVALID_DATA, ///< Data passed is invalid (30)
|
|
|
|
ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
|
|
|
|
ERR_ALREADY_EXISTS, ///< When adding, item already exists
|
|
|
|
ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
|
|
|
|
ERR_DATABASE_CANT_READ, ///< database is full
|
|
|
|
ERR_DATABASE_CANT_WRITE, ///< database is full (35)
|
|
|
|
ERR_COMPILATION_FAILED,
|
|
|
|
ERR_METHOD_NOT_FOUND,
|
|
|
|
ERR_LINK_FAILED,
|
|
|
|
ERR_SCRIPT_FAILED,
|
2018-11-23 22:09:41 +00:00
|
|
|
ERR_CYCLIC_LINK, // (40)
|
2017-03-03 20:04:23 +00:00
|
|
|
ERR_INVALID_DECLARATION,
|
|
|
|
ERR_DUPLICATE_SYMBOL,
|
|
|
|
ERR_PARSE_ERROR,
|
|
|
|
ERR_BUSY,
|
2018-11-23 22:09:41 +00:00
|
|
|
ERR_SKIP, // (45)
|
2017-03-03 20:04:23 +00:00
|
|
|
ERR_HELP, ///< user requested help!!
|
|
|
|
ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
|
|
|
|
ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
|
|
|
|
ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
|
|
|
|
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
|
|
|
|
};
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
} // namespace godot
|
|
|
|
|
2019-05-15 10:07:46 +00:00
|
|
|
#include <GodotGlobal.hpp>
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2020-03-31 18:16:45 +00:00
|
|
|
// alloca() is non-standard. When using MSVC, it's in malloc.h.
|
2020-06-17 18:45:19 +00:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2020-03-31 18:16:45 +00:00
|
|
|
#include <alloca.h>
|
2020-06-17 18:45:19 +00:00
|
|
|
#else
|
|
|
|
#include <malloc.h>
|
2020-03-31 18:16:45 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-06 02:30:46 +00:00
|
|
|
typedef float real_t;
|
2017-03-03 20:04:23 +00:00
|
|
|
|
2020-12-08 20:47:42 +00:00
|
|
|
// This epsilon should match the one used by Godot for consistency.
|
|
|
|
// Using `f` when `real_t` is float.
|
|
|
|
#define CMP_EPSILON 0.00001f
|
2018-11-23 22:09:41 +00:00
|
|
|
#define CMP_EPSILON2 (CMP_EPSILON * CMP_EPSILON)
|
2020-12-08 20:47:42 +00:00
|
|
|
|
|
|
|
#define Math_PI 3.1415926535897932384626433833
|
2020-08-30 22:15:07 +00:00
|
|
|
#define Math_TAU 6.2831853071795864769252867666
|
2017-03-06 02:30:46 +00:00
|
|
|
|
|
|
|
#define _PLANE_EQ_DOT_EPSILON 0.999
|
|
|
|
#define _PLANE_EQ_D_EPSILON 0.0001
|
2017-03-04 02:04:16 +00:00
|
|
|
|
2019-05-15 10:07:46 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
#else
|
|
|
|
#define likely(x) x
|
|
|
|
#define unlikely(x) x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Don't use this directly; instead, use any of the CRASH_* macros
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define GENERATE_TRAP \
|
|
|
|
__debugbreak(); \
|
|
|
|
/* Avoid warning about control paths */ \
|
|
|
|
for (;;) { \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define GENERATE_TRAP __builtin_trap();
|
|
|
|
#endif
|
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
// ERR/WARN macros
|
|
|
|
#ifndef WARN_PRINT
|
2019-10-24 11:52:23 +00:00
|
|
|
#define WARN_PRINT(msg) godot::Godot::print_warning(msg, __func__, __FILE__, __LINE__)
|
2018-02-11 14:50:01 +00:00
|
|
|
#endif
|
2017-03-04 02:04:16 +00:00
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
#ifndef WARN_PRINTS
|
|
|
|
#define WARN_PRINTS(msg) WARN_PRINT((msg).utf8().get_data())
|
2017-03-04 02:04:16 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
#ifndef ERR_PRINT
|
2019-10-24 11:52:23 +00:00
|
|
|
#define ERR_PRINT(msg) godot::Godot::print_error(msg, __func__, __FILE__, __LINE__)
|
2018-02-11 14:50:01 +00:00
|
|
|
#endif
|
2017-03-04 02:04:16 +00:00
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
#ifndef ERR_PRINTS
|
|
|
|
#define ERR_PRINTS(msg) ERR_PRINT((msg).utf8().get_data())
|
2017-03-06 02:30:46 +00:00
|
|
|
#endif
|
|
|
|
|
2019-05-15 10:07:46 +00:00
|
|
|
#ifndef FATAL_PRINT
|
2019-10-24 11:52:23 +00:00
|
|
|
#define FATAL_PRINT(msg) ERR_PRINT(godot::String("FATAL: ") + (msg))
|
2017-03-06 02:30:46 +00:00
|
|
|
#endif
|
|
|
|
|
2019-05-15 10:07:46 +00:00
|
|
|
#ifndef ERR_MSG_INDEX
|
2019-10-24 11:52:23 +00:00
|
|
|
#define ERR_MSG_INDEX(index, size) (godot::String("Index ") + #index + "=" + godot::String::num_int64(index) + " out of size (" + #size + "=" + godot::String::num_int64(size) + ")")
|
2019-05-15 10:07:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_MSG_NULL
|
2019-10-24 11:52:23 +00:00
|
|
|
#define ERR_MSG_NULL(param) (godot::String("Parameter '") + #param + "' is null.")
|
2019-05-15 10:07:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_MSG_COND
|
2019-10-24 11:52:23 +00:00
|
|
|
#define ERR_MSG_COND(cond) (godot::String("Condition '") + #cond + "' is true.")
|
2019-05-15 10:07:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_FAIL_INDEX
|
|
|
|
#define ERR_FAIL_INDEX(index, size) \
|
|
|
|
do { \
|
|
|
|
if (unlikely((index) < 0 || (index) >= (size))) { \
|
|
|
|
ERR_PRINT(ERR_MSG_INDEX(index, size)); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_FAIL_INDEX_V
|
|
|
|
#define ERR_FAIL_INDEX_V(index, size, ret) \
|
|
|
|
do { \
|
|
|
|
if (unlikely((index) < 0 || (index) >= (size))) { \
|
|
|
|
ERR_PRINT(ERR_MSG_INDEX(index, size)); \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_FAIL_UNSIGNED_INDEX_V
|
|
|
|
#define ERR_FAIL_UNSIGNED_INDEX_V(index, size, ret) \
|
|
|
|
do { \
|
|
|
|
if (unlikely((index) >= (size))) { \
|
|
|
|
ERR_PRINT(ERR_MSG_INDEX(index, size)); \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CRASH_BAD_INDEX
|
|
|
|
#define CRASH_BAD_INDEX(index, size) \
|
|
|
|
do { \
|
|
|
|
if (unlikely((index) < 0 || (index) >= (size))) { \
|
|
|
|
FATAL_PRINT(ERR_MSG_INDEX(index, size)); \
|
|
|
|
GENERATE_TRAP; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_FAIL_NULL
|
|
|
|
#define ERR_FAIL_NULL(param) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!param)) { \
|
|
|
|
ERR_PRINT(ERR_MSG_NULL(param)); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_FAIL_NULL_V
|
|
|
|
#define ERR_FAIL_NULL_V(param, ret) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(!param)) { \
|
|
|
|
ERR_PRINT(ERR_MSG_NULL(param)); \
|
|
|
|
return ret; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2018-02-11 14:50:01 +00:00
|
|
|
#endif
|
2017-03-06 02:30:46 +00:00
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
#ifndef ERR_FAIL_COND
|
2019-05-15 10:07:46 +00:00
|
|
|
#define ERR_FAIL_COND(cond) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(cond)) { \
|
|
|
|
ERR_PRINT(ERR_MSG_COND(cond)); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CRASH_COND
|
|
|
|
#define CRASH_COND(cond) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(cond)) { \
|
|
|
|
FATAL_PRINT(ERR_MSG_COND(cond)); \
|
|
|
|
return; \
|
|
|
|
} \
|
2018-11-23 22:09:41 +00:00
|
|
|
} while (0)
|
2017-03-03 20:04:23 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
#ifndef ERR_FAIL_COND_V
|
2019-05-15 10:07:46 +00:00
|
|
|
#define ERR_FAIL_COND_V(cond, ret) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(cond)) { \
|
|
|
|
ERR_PRINT(ERR_MSG_COND(cond)); \
|
|
|
|
return ret; \
|
|
|
|
} \
|
2018-11-23 22:09:41 +00:00
|
|
|
} while (0)
|
2017-03-06 02:30:46 +00:00
|
|
|
#endif
|
|
|
|
|
2019-05-15 10:07:46 +00:00
|
|
|
#ifndef ERR_CONTINUE
|
|
|
|
#define ERR_CONTINUE(cond) \
|
|
|
|
{ \
|
|
|
|
if (unlikely(cond)) { \
|
|
|
|
ERR_PRINT(ERR_MSG_COND(cond)); \
|
|
|
|
continue; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_BREAK
|
|
|
|
#define ERR_BREAK(cond) \
|
|
|
|
{ \
|
|
|
|
if (unlikely(cond)) { \
|
|
|
|
ERR_PRINT(ERR_MSG_COND(cond)); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ERR_FAIL
|
|
|
|
#define ERR_FAIL() \
|
|
|
|
do { \
|
|
|
|
ERR_PRINT("Method/Function Failed."); \
|
|
|
|
return; \
|
2018-11-23 22:09:41 +00:00
|
|
|
} while (0)
|
2018-02-11 14:50:01 +00:00
|
|
|
#endif
|
2017-03-06 02:30:46 +00:00
|
|
|
|
2019-05-15 10:07:46 +00:00
|
|
|
#ifndef ERR_FAIL_V
|
|
|
|
#define ERR_FAIL_V(ret) \
|
|
|
|
do { \
|
|
|
|
ERR_PRINT("Method/Function Failed."); \
|
|
|
|
return ret; \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CRASH_NOW
|
|
|
|
#define CRASH_NOW() \
|
|
|
|
do { \
|
|
|
|
FATAL_PRINT("Method/Function Failed."); \
|
|
|
|
GENERATE_TRAP; \
|
2018-11-23 22:09:41 +00:00
|
|
|
} while (0)
|
2017-03-06 02:30:46 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-03 20:04:23 +00:00
|
|
|
#endif // DEFS_H
|