61 ~
Service() noexcept {
CE_ASSERT(mService ==
nullptr &&
"Service being destroyed while still initialized."); }
64 [[nodiscard]]
bool has() const noexcept {
return mService !=
nullptr; }
67 [[nodiscard]]
T&
get() const noexcept {
68 CE_ASSERT(mService !=
nullptr &&
"Trying to get an uninitialized service!");
73 [[nodiscard]]
T*
getPointer() const noexcept {
return mService.get(); }
81 template<
typename TT =
T,
typename... Args> TT&
create(Args&&... args) {
82 if constexpr(std::is_constructible_v<TT,
Engine&, Args...>) {
83 assign(ce_unique_new<TT>(*
this, std::forward<Args>(args)...));
84 }
else if constexpr(std::is_constructible_v<TT,
Engine*, Args...>) {
85 assign(ce_unique_new<TT>(
this, std::forward<Args>(args)...));
87 assign(ce_unique_new<TT>(std::forward<Args>(args)...));
89 return static_cast<TT&
>(get());
94 void destroy() noexcept { assign(
nullptr); }
98 void assign(
UPtr<T>&& service)
noexcept { mService = std::move(service); }
102 template<
typename TT> [[nodiscard]]
bool is() const noexcept {
return dynamic_cast<const TT*
>(mService.get()) !=
nullptr; }
105 [[nodiscard]]
explicit operator bool() const noexcept {
return has(); }
108 [[nodiscard]]
CE_EXPLICIT(
false) operator T&()
const {
return get(); }
111 [[nodiscard]]
CE_EXPLICIT(
false) operator T*()
const {
return getPointer(); }
118 CE_ASSERT(mService !=
nullptr &&
"Trying to get an uninitialized service!");
126 assign(std::forward<
decltype(service)>(service));
170 double lastSimulationTime = 0.0;
174 double lastRenderTime = 0.0;
#define CE_ASSERT(...)
Definition Macros.hpp:323
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
#define CE_EXPLICIT(EXPR)
Definition Macros.hpp:413
Definition AudioAPI.hpp:18
Service< RunLoop > mainRunLoop
The engine's main thread run loop.
Definition Engine.hpp:132
UPtr< ExecutionContext > backgroundQueue
A work queue that gets drained by several background threads.
Definition Engine.hpp:42
Definition RenderAPI.hpp:81
The CeresEngine renderer.
Definition Renderer.hpp:35
The ResourceManager is the main class responsible for managing and handling all resources in the engi...
Definition ResourceManager.hpp:47
A manager that references and manages mutliple scenes.
Definition Scene.hpp:230
An object that coordinates a group of related, network data transfer tasks.
Definition URLSession.hpp:399
Definition Application.hpp:19
std::unique_ptr< T, Deleter > UPtr
UPtr is a smart pointer that owns and manages another object through a pointer and disposes of that o...
Definition SmartPtr.hpp:28
std::uint64_t UInt64
Definition DataTypes.hpp:26
A wrapper class that stores and manages an engine Service.
Definition Engine.hpp:46
bool is() const noexcept
Definition Engine.hpp:102
T & operator*() const
Definition Engine.hpp:114
Service & operator=(UPtr< T > &&service) noexcept
Assigns a new service.
Definition Engine.hpp:125
void destroy() noexcept
Destroys a service.
Definition Engine.hpp:94
TT & create(Args &&... args)
Creates a new service.
Definition Engine.hpp:81
void assign(UPtr< T > &&service) noexcept
Assigns a new service.
Definition Engine.hpp:98
T & get() const noexcept
Definition Engine.hpp:67
Service() noexcept=default
Creates a new Service wrapper.
bool has() const noexcept
Definition Engine.hpp:64
T * getPointer() const noexcept
Definition Engine.hpp:73
T * operator->() const
Definition Engine.hpp:117