Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
core.hpp
Go to the documentation of this file.
1#pragma once
2
3// Platform-specific API macros
4#ifdef HELIOS_PLATFORM_WINDOWS
5#ifdef HELIOS_BUILD_SHARED
6#define HELIOS_API __declspec(dllexport)
7#else
8#define HELIOS_API __declspec(dllimport)
9#endif
10#elifdef HELIOS_PLATFORM_LINUX
11#ifdef HELIOS_BUILD_SHARED
12#define HELIOS_API __attribute__((visibility("default")))
13#else
14#define HELIOS_API
15#endif
16#else
17#define HELIOS_API
18#endif
19
20#ifdef HELIOS_PLATFORM_WINDOWS
21#define HELIOS_EXPORT __declspec(dllexport)
22#elifdef HELIOS_PLATFORM_LINUX
23#define HELIOS_EXPORT __attribute__((visibility("default")))
24#else
25#define HELIOS_EXPORT
26#endif
27
28// Debug break functionality
29#ifdef HELIOS_ENABLE_ASSERTS
30
31// TODO: Replace with std::breakpoint() from <debugging> in C++26
32// https://en.cppreference.com/w/cpp/utility/breakpoint.html
33
34// MSVC: Use the intrinsic which maps to the appropriate inlined assembly
35#if defined(_MSC_VER) && (_MSC_VER >= 1300)
36#define HELIOS_DEBUG_BREAK() __debugbreak()
37
38// ARM64 on Apple: Use signal-based break (better debugger integration)
39#elif defined(__arm64__) && defined(__APPLE__)
40#include <unistd.h>
41#include <csignal>
42#define HELIOS_DEBUG_BREAK() ::kill(::getpid(), SIGINT)
43
44// ARM64 with GCC/Clang: Use brk instruction
45#elif defined(__arm64__) && (defined(__GNUC__) || defined(__clang__))
46#define HELIOS_DEBUG_BREAK() __asm__("brk 0")
47
48// ARM (32-bit) on Apple: Use trap instruction
49#elif defined(__arm__) && defined(__APPLE__)
50#define HELIOS_DEBUG_BREAK() __asm__("trap")
51
52// ARM (32-bit) with GCC/Clang: Use bkpt instruction
53#elif defined(__arm__) && (defined(__GNUC__) || defined(__clang__))
54#define HELIOS_DEBUG_BREAK() __asm__("bkpt 0")
55
56// ARM with Arm Compiler: Use breakpoint intrinsic
57#elif defined(__arm__) && defined(__ARMCC_VERSION)
58#define HELIOS_DEBUG_BREAK() __breakpoint(0)
59
60// x86/x86_64 with Clang/GCC: Use int3 instruction (AT&T syntax)
61#elif (defined(__x86_64__) || defined(__i386__)) && (defined(__GNUC__) || defined(__clang__))
62#define HELIOS_DEBUG_BREAK() __asm__("int3")
63
64// x86/x86_64 with MSVC: Use int3 instruction (Intel syntax)
65#elif (defined(_M_X64) || defined(_M_IX86)) && defined(_MSC_VER)
66#define HELIOS_DEBUG_BREAK() __asm int 3
67
68// PowerPC: Trigger exception via opcode 0x00000000
69#elif defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC)
70#define HELIOS_DEBUG_BREAK() __asm__(".long 0")
71
72// WebAssembly: No breakpoint support, use unreachable
73#elif defined(__wasm__)
74#define HELIOS_DEBUG_BREAK() __asm__("unreachable")
75
76// Fallback: Use compiler builtin trap (works on most modern compilers)
77#elif defined(__has_builtin) && __has_builtin(__builtin_trap)
78#define HELIOS_DEBUG_BREAK() __builtin_trap()
79
80// Last resort: Use signal-based approach
81#else
82#include <csignal>
83#define HELIOS_DEBUG_BREAK() ::std::raise(SIGTRAP)
84
85#endif
86
87#else
88// Debug break disabled in release builds
89#define HELIOS_DEBUG_BREAK()
90#endif
91
92#include <utility>
93#define HELIOS_UNREACHABLE() std::unreachable()
94
95// Release mode unreachable
96#ifndef HELIOS_DEBUG_MODE
97#define HELIOS_RELEASE_UNREACHABLE() HELIOS_UNREACHABLE()
98#else
99#define HELIOS_RELEASE_UNREACHABLE()
100#endif
101
102// Utility macros
103#define HELIOS_BIT(x) (1 << (x))
104
105// Stringify macros
106#define HELIOS_STRINGIFY_IMPL(x) #x
107#define HELIOS_STRINGIFY(x) HELIOS_STRINGIFY_IMPL(x)
108
109// Concatenation macros
110#define HELIOS_CONCAT_IMPL(a, b) a##b
111#define HELIOS_CONCAT(a, b) HELIOS_CONCAT_IMPL(a, b)
112
113// Anonymous variable generation
114#define HELIOS_ANONYMOUS_VAR(prefix) HELIOS_CONCAT(prefix, __LINE__)
115
116// Force inline macros
117#ifdef _MSC_VER
118#define HELIOS_FORCE_INLINE __forceinline
119#elif defined(__GNUC__) || defined(__clang__)
120#define HELIOS_FORCE_INLINE __attribute__((always_inline)) inline
121#else
122#define HELIOS_FORCE_INLINE inline
123#endif
124
125// No inline macros
126#ifdef _MSC_VER
127#define HELIOS_NO_INLINE __declspec(noinline)
128#elif defined(__GNUC__) || defined(__clang__)
129#define HELIOS_NO_INLINE __attribute__((noinline))
130#else
131#define HELIOS_NO_INLINE
132#endif
133
134// Compiler-specific branch prediction hints (fallback)
135#if defined(__GNUC__) || defined(__clang__)
136#define HELIOS_EXPECT_TRUE(x) __builtin_expect(!!(x), 1)
137#define HELIOS_EXPECT_FALSE(x) __builtin_expect(!!(x), 0)
138#else
139#define HELIOS_EXPECT_TRUE(x) (x)
140#define HELIOS_EXPECT_FALSE(x) (x)
141#endif
142
143#if defined(__cpp_lib_move_only_function) && __cpp_lib_move_only_function >= 202110L
144#define HELIOS_MOVEONLY_FUNCTION_AVALIABLE
145#endif
146
147#if defined(__cpp_lib_containers_ranges) && __cpp_lib_containers_ranges >= 202202L
148#define HELIOS_CONTAINERS_RANGES_AVALIABLE
149#endif