2023-01-10 15:14:30 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* defs.hpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2022-10-09 06:47:07 +00:00
|
|
|
#ifndef GODOT_DEFS_HPP
|
|
|
|
#define GODOT_DEFS_HPP
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2022-08-19 07:30:06 +00:00
|
|
|
#include <cstring>
|
2021-08-18 14:03:52 +00:00
|
|
|
|
2024-10-07 12:51:51 +00:00
|
|
|
namespace godot {
|
|
|
|
|
2022-12-07 13:11:44 +00:00
|
|
|
#if !defined(GDE_EXPORT)
|
2022-06-18 12:23:28 +00:00
|
|
|
#if defined(_WIN32)
|
2022-12-07 13:11:44 +00:00
|
|
|
#define GDE_EXPORT __declspec(dllexport)
|
2022-06-18 12:23:28 +00:00
|
|
|
#elif defined(__GNUC__)
|
2022-12-07 13:11:44 +00:00
|
|
|
#define GDE_EXPORT __attribute__((visibility("default")))
|
2021-08-18 14:03:52 +00:00
|
|
|
#else
|
2022-12-07 13:11:44 +00:00
|
|
|
#define GDE_EXPORT
|
2021-08-18 14:03:52 +00:00
|
|
|
#endif
|
2022-06-18 12:23:28 +00:00
|
|
|
#endif
|
2021-08-18 14:03:52 +00:00
|
|
|
|
|
|
|
// Turn argument to string constant:
|
|
|
|
// https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html#Stringizing
|
|
|
|
#ifndef _STR
|
|
|
|
#define _STR(m_x) #m_x
|
|
|
|
#define _MKSTR(m_x) _STR(m_x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Should always inline no matter what.
|
|
|
|
#ifndef _ALWAYS_INLINE_
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define _ALWAYS_INLINE_ __attribute__((always_inline)) inline
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#define _ALWAYS_INLINE_ __forceinline
|
|
|
|
#else
|
|
|
|
#define _ALWAYS_INLINE_ inline
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Should always inline, except in debug builds because it makes debugging harder.
|
|
|
|
#ifndef _FORCE_INLINE_
|
|
|
|
#ifdef DISABLE_FORCED_INLINE
|
|
|
|
#define _FORCE_INLINE_ inline
|
|
|
|
#else
|
|
|
|
#define _FORCE_INLINE_ _ALWAYS_INLINE_
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-10-05 06:03:52 +00:00
|
|
|
#ifndef _NO_DISCARD_
|
|
|
|
#define _NO_DISCARD_ [[nodiscard]]
|
|
|
|
#endif
|
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
// Windows badly defines a lot of stuff we'll never use. Undefine it.
|
|
|
|
#ifdef _WIN32
|
|
|
|
#undef min // override standard definition
|
|
|
|
#undef max // override standard definition
|
|
|
|
#undef ERROR // override (really stupid) wingdi.h standard definition
|
|
|
|
#undef DELETE // override (another really stupid) winnt.h standard definition
|
|
|
|
#undef MessageBox // override winuser.h standard definition
|
|
|
|
#undef MIN // override standard definition
|
|
|
|
#undef MAX // override standard definition
|
|
|
|
#undef CLAMP // override standard definition
|
|
|
|
#undef Error
|
|
|
|
#undef OK
|
|
|
|
#undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__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
|
|
|
|
|
2021-09-01 03:11:10 +00:00
|
|
|
#ifdef REAL_T_IS_DOUBLE
|
|
|
|
typedef double real_t;
|
|
|
|
#else
|
|
|
|
typedef float real_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Generic swap template.
|
|
|
|
#ifndef SWAP
|
|
|
|
#define SWAP(m_x, m_y) __swap_tmpl((m_x), (m_y))
|
2024-03-10 21:02:43 +00:00
|
|
|
template <typename T>
|
2021-09-01 03:11:10 +00:00
|
|
|
inline void __swap_tmpl(T &x, T &y) {
|
|
|
|
T aux = x;
|
|
|
|
x = y;
|
|
|
|
y = aux;
|
|
|
|
}
|
|
|
|
#endif // SWAP
|
|
|
|
|
2021-08-18 14:03:52 +00:00
|
|
|
// Home-made index sequence trick, so it can be used everywhere without the costly include of std::tuple.
|
|
|
|
// https://stackoverflow.com/questions/15014096/c-index-of-type-during-variadic-template-expansion
|
|
|
|
template <size_t... Is>
|
|
|
|
struct IndexSequence {};
|
|
|
|
|
|
|
|
template <size_t N, size_t... Is>
|
|
|
|
struct BuildIndexSequence : BuildIndexSequence<N - 1, N - 1, Is...> {};
|
|
|
|
|
|
|
|
template <size_t... Is>
|
|
|
|
struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {};
|
|
|
|
|
2024-10-07 12:51:51 +00:00
|
|
|
} //namespace godot
|
|
|
|
|
|
|
|
// To maintain compatibility an alias is defined outside the namespace.
|
|
|
|
// Consider it deprecated.
|
|
|
|
using real_t = godot::real_t;
|
|
|
|
|
2022-10-09 06:47:07 +00:00
|
|
|
#endif // GODOT_DEFS_HPP
|