Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
sdl_interface.h
Go to the documentation of this file.
1#pragma once
2
3#include "SDL/ISdlResource.h"
4#include "SDL/TSdl.h"
6
7// Base types
12
13// Enum types
15
16// Owner types
19
20// Field types
37
38// Function types
40
41#include <type_traits>
42
63#define PH_DEFINE_SDL_CLASS(...)/* variadic args for template types that contain commas */\
64 \
65 using ClassType = std::remove_cv_t<__VA_ARGS__>;\
66 using OwnerType = std::remove_cv_t<typename ClassType::OwnerType>;\
67 \
68 /* A marker so we know the macro has been called. */\
69 using SdlClassDefinitionMarker = OwnerType;\
70 \
71 inline static const ClassType* getSdlClass()\
72 {\
73 static_assert(std::is_base_of_v<::ph::ISdlResource, OwnerType>,\
74 "PH_DEFINE_SDL_CLASS() can only be defined for SDL resource.");\
75 static_assert(std::is_base_of_v<::ph::SdlClass, ClassType>,\
76 "PH_DEFINE_SDL_CLASS() must return a class derived from SdlClass.");\
77 \
78 static const ClassType sdlClass = internal_sdl_class_impl();\
79 return &sdlClass;\
80 }\
81 \
82 inline const ::ph::SdlClass* getDynamicSdlClass() const override\
83 {\
84 return getSdlClass();\
85 }\
86 \
87 inline static ClassType internal_sdl_class_impl()
88
89#define PH_DEFINE_SDL_STRUCT(...)/* variadic args for template types that contain commas */\
90 \
91 using StructType = std::remove_cv_t<__VA_ARGS__>;\
92 using OwnerType = std::remove_cv_t<typename StructType::OwnerType>;\
93 \
94 /* A marker so we know the macro has been called. */\
95 using SdlStructDefinitionMarker = OwnerType;\
96 \
97 inline static const StructType* getSdlStruct()\
98 {\
99 static_assert(std::is_base_of_v<::ph::SdlStruct, StructType>,\
100 "PH_DEFINE_SDL_STRUCT() must return a struct derived from SdlStruct.");\
101 \
102 static const StructType sdlStruct = internal_sdl_struct_impl();\
103 return &sdlStruct;\
104 }\
105 \
106 inline static StructType internal_sdl_struct_impl()
107
108#define PH_DEFINE_SDL_FUNCTION(...)/* variadic args for template types that contain commas */\
109 \
110 using FunctionType = std::remove_cv_t<__VA_ARGS__>;\
111 using OwnerType = std::remove_cv_t<typename FunctionType::OwnerType>;\
112 \
113 /* A marker so we know the macro has been called. */\
114 using SdlFunctionDefinitionMarker = OwnerType;\
115 \
116 inline static const FunctionType* getSdlFunction()\
117 {\
118 static_assert(std::is_base_of_v<::ph::SdlFunction, FunctionType>,\
119 "PH_DEFINE_SDL_FUNCTION() must return a function derived from SdlFunction.");\
120 \
121 static const FunctionType sdlFunction = internal_sdl_function_impl();\
122 return &sdlFunction;\
123 }\
124 \
125 inline static FunctionType internal_sdl_function_impl()
126
142#define PH_DEFINE_SDL_ENUM(...)/* variadic args for template types that contain commas */\
143 template<>\
144 class TSdlEnum<std::remove_cv_t<typename __VA_ARGS__::EnumType>> final\
145 {\
146 public:\
147 \
148 using SdlEnumType = std::remove_cv_t<__VA_ARGS__>;\
149 using EnumType = std::remove_cv_t<typename SdlEnumType::EnumType>;\
150 \
151 static_assert(std::is_enum_v<EnumType>,\
152 "EnumType must be an enum. Currently it is not.");\
153 \
154 /* A marker so we know the macro has been called. */\
155 using SdlEnumDefinitionMarker = EnumType;\
156 \
157 public:\
158 inline EnumType operator [] (const std::string_view entryName) const\
159 {\
160 const ::ph::SdlEnum::TEntry<EnumType> entry = getSdlEnum()->getTypedEntry(entryName);\
161 return entry.value;\
162 }\
163 \
164 inline std::string_view operator [] (const EnumType entryValue) const\
165 {\
166 const ::ph::SdlEnum::TEntry<EnumType> entry = getSdlEnum()->getTypedEntry(entryValue);\
167 return entry.name;\
168 }\
169 \
170 inline static const SdlEnumType* getSdlEnum()\
171 {\
172 static_assert(std::is_base_of_v<::ph::SdlEnum, SdlEnumType>,\
173 "PH_DEFINE_SDL_ENUM() must return an enum derived from SdlEnum.");\
174 \
175 static const SdlEnumType sdlEnum = internal_sdl_enum_impl();\
176 return &sdlEnum;\
177 }\
178 \
179 private:\
180 static SdlEnumType internal_sdl_enum_impl();\
181 };\
182 \
183 /* In-header Implementations: */\
184 \
185 inline __VA_ARGS__ TSdlEnum<std::remove_cv_t<typename __VA_ARGS__::EnumType>>::internal_sdl_enum_impl()
SDL instance helpers.