QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Base.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <cstdint>
9#include <memory>
10#include <utility>
11
12#include <quasar/core/Log.h>
14
15#ifdef QUASAR_PLATFORM_LINUX
16#include <csignal>
17#endif
18
19namespace Quasar
20{
22 template <typename T>
23 using Scope = std::unique_ptr<T>;
24
26 template <typename T, typename... Args>
27 Scope<T> CreateScope(Args&&... args)
28 {
29 return std::make_unique<T>(std::forward<Args>(args)...);
30 }
31
33 template <typename T>
34 using Ref = std::shared_ptr<T>;
35
37 template <typename T, typename... Args>
38 Ref<T> CreateRef(Args&&... args)
39 {
40 return std::make_shared<T>(std::forward<Args>(args)...);
41 }
42}
43
46
49#ifdef QUASAR_PLATFORM_WINDOWS
50#define QUASAR_DEBUGBREAK() __debugbreak()
51#define QUASAR_FORCE_INLINE __forceinline
52#else
53#define QUASAR_DEBUGBREAK() static_cast<void>(std::raise(SIGTRAP))
54#define QUASAR_FORCE_INLINE [[gnu::always_inline]] inline
55#endif
56
58#define QUASAR_CONCAT_IMPL(a, b) a##b
59
64#define QUASAR_CONCAT(a, b) QUASAR_CONCAT_IMPL(a, b)
65
74#ifdef QUASAR_DEBUG
75#define QUASAR_ENGINE_ASSERT(condition, ...) \
76 do \
77 { \
78 if (!(condition)) \
79 { \
80 QUASAR_ENGINE_ERROR("Assertion '{}' failed at {}:{}", #condition, __FILE__, __LINE__); \
81 if constexpr (sizeof(#__VA_ARGS__) > 1) \
82 { \
83 QUASAR_ENGINE_ERROR("" __VA_ARGS__); \
84 } \
85 QUASAR_DEBUGBREAK(); \
86 } \
87 } while (false)
88#else
89#define QUASAR_ENGINE_ASSERT(condition, ...) ((void)[&] { return !(condition); })
90#endif
91
92namespace Quasar
93{
100 constexpr std::uint32_t Bit(std::uint32_t index)
101 {
102 QUASAR_ENGINE_ASSERT(index < 32, "Bit index {} is out of range", index);
103 return 1u << index;
104 }
105}
#define QUASAR_ENGINE_ASSERT(condition,...)
Checks a condition that must always be true in the engine code.
Definition Base.h:89
Engine and application loggers, and the macros to write to them.
Detects the platform and the build type at compile time.
Contains all the engine code.
Ref< T > CreateRef(Args &&... args)
Creates an object owned by a Ref. Same as std::make_shared.
Definition Base.h:38
constexpr std::uint32_t Bit(std::uint32_t index)
Returns a value where only the bit at the given index is set, for example Bit(3) is 8.
Definition Base.h:100
std::unique_ptr< T > Scope
Pointer with a single owner. Alias of std::unique_ptr.
Definition Base.h:23
Scope< T > CreateScope(Args &&... args)
Creates an object owned by a Scope. Same as std::make_unique.
Definition Base.h:27
std::shared_ptr< T > Ref
Pointer with shared ownership: the object is destroyed with its last Ref. Alias of std::shared_ptr.
Definition Base.h:34
@ T
T key.
Definition KeyCodes.h:63