NoJobEngine 2.0.7
Loading...
Searching...
No Matches
Components.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <glm/glm.hpp>
9#include <glm/gtc/matrix_transform.hpp>
10
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <vector>
15#include <unordered_map>
16
17namespace NoJob
18{
19 class Mesh;
20 class Material;
21 class AnimationAsset;
22
24 {
25 std::uint64_t ID = 0;
26 };
27
29 {
30 std::string Tag;
31 };
32
33 // ---------------------------------------------------------
34 // Global Entity Layers
35 // ---------------------------------------------------------
36
37 using LayerMask = std::uint32_t;
38
39 using LayerMask = std::uint32_t;
40
41 namespace EntityLayers
42 {
43 constexpr std::uint32_t Default = 0;
44 constexpr std::uint32_t Player = 1;
45 constexpr std::uint32_t Enemy = 2;
46 constexpr std::uint32_t Environment = 3;
47 constexpr std::uint32_t Interactable = 4;
48
49 constexpr std::uint32_t MaxLayers = 32;
50
51 constexpr LayerMask All = 0xFFFFFFFFu;
52 constexpr LayerMask None = 0u;
53
54 constexpr LayerMask Bit(std::uint32_t layer)
55 {
56 return layer < MaxLayers
57 ? (LayerMask{ 1 } << layer)
58 : None;
59 }
60 }
61
63 {
65 };
66
67
69 {
70 glm::vec3 Position{ 0.0f, 0.0f, 0.0f };
71 glm::vec3 Rotation{ 0.0f, 0.0f, 0.0f };
72 glm::vec3 Scale{ 1.0f, 1.0f, 1.0f };
73
74 glm::mat4 GetTransform() const
75 {
76 const glm::mat4 rotation =
77 glm::rotate(
78 glm::mat4(1.0f),
79 Rotation.z,
80 { 0.0f, 0.0f, 1.0f }) *
81 glm::rotate(
82 glm::mat4(1.0f),
83 Rotation.y,
84 { 0.0f, 1.0f, 0.0f }) *
85 glm::rotate(
86 glm::mat4(1.0f),
87 Rotation.x,
88 { 1.0f, 0.0f, 0.0f });
89
90 return glm::translate(
91 glm::mat4(1.0f), Position)
92 * rotation
93 * glm::scale(
94 glm::mat4(1.0f), Scale);
95 }
96 };
97
99 {
100 std::uint32_t Parent = 0;
101 std::vector<std::uint32_t> Children;
102 };
103
104
110
112 {
114 bool Primary = true;
115 float PerspectiveFOV = 45.0f;
116 float PerspectiveNear = 0.1f;
117 float PerspectiveFar = 1000.0f;
118 float OrthographicSize = 10.0f;
119 float OrthographicNear = -1.0f;
120 float OrthographicFar = 1000.0f;
121
122 glm::mat4 GetProjection(float aspectRatio) const
123 {
124 aspectRatio = aspectRatio > 0.0001f ? aspectRatio : 1.0f;
126 return glm::perspective(
127 glm::radians(PerspectiveFOV),
128 aspectRatio,
131
132 const float halfHeight = OrthographicSize * 0.5f;
133 const float halfWidth = halfHeight * aspectRatio;
134 return glm::ortho(
135 -halfWidth, halfWidth,
136 -halfHeight, halfHeight,
138 }
139 };
140
142 {
143 std::string ClipPath;
144 bool PlayOnAwake = true;
145 bool Loop = false;
146 float Volume = 1.0f;
147 float Pitch = 1.0f;
148
149 // V1.6 Block 2 spatial audio. SpatialBlend is intentionally Unity-like:
150 // 0 = fully 2D, 1 = fully 3D, intermediate values crossfade between both.
151 float SpatialBlend = 0.0f;
152 float MinDistance = 1.0f;
153 float MaxDistance = 50.0f;
154 float DopplerFactor = 1.0f;
155 };
156
158 {
159 bool Enabled = true;
160 };
161
162
163 enum class ParticleShape : std::uint8_t { Point = 0, Sphere = 1, Cone = 2 };
164 enum class ParticleBlendMode : std::uint8_t { Alpha = 0, Additive = 1 };
165
167 {
168 bool Playing = true;
169 bool Loop = true;
170 float Duration = 5.0f;
171 float StartLifetime = 2.0f;
172 float LifetimeRandom = 0.0f;
173 float StartSpeed = 2.0f;
174 float SpeedRandom = 0.0f;
175 float StartSize = 0.2f;
176 float SizeRandom = 0.0f;
177 glm::vec4 StartColor{ 1.0f, 0.65f, 0.15f, 1.0f };
178 glm::vec4 EndColor{ 1.0f, 0.15f, 0.02f, 0.0f };
179 float EndSizeMultiplier = 0.25f;
180 float EmissionRate = 20.0f;
181 std::uint32_t MaxParticles = 500;
182 glm::vec3 Direction{ 0.0f, 1.0f, 0.0f };
183 glm::vec3 Gravity{ 0.0f, -1.0f, 0.0f };
184
186 float ShapeRadius = 0.5f;
187 float ConeAngle = 25.0f;
188
190 std::string TexturePath;
191 };
192
194 {
195 glm::vec3 Color{ 1.0f, 1.0f, 1.0f };
196 float Intensity = 1.0f;
197 bool CastShadows = true;
198 float ShadowBias = 0.002f;
199 };
200
202 {
203 glm::vec3 Color{ 1.0f, 1.0f, 1.0f };
204 float Intensity = 1.0f;
205 float Range = 10.0f;
206 bool CastShadows = true;
207 float ShadowBias = 0.02f;
208 };
209
211 {
212 glm::vec3 Color{ 1.0f, 1.0f, 1.0f };
213 float Intensity = 1.0f;
214 float Range = 10.0f;
215 float InnerAngle = 20.0f;
216 float OuterAngle = 30.0f;
217 bool CastShadows = true;
218 float ShadowBias = 0.002f;
219 };
220
221
222 enum class RigidbodyType
223 {
227 };
228
236 {
237 bool Enabled = true;
238
239 float Speed = 3.5f;
240 float StoppingDistance = 0.1f;
241
242 glm::vec3 Destination{ 0.0f };
243
244 bool HasDestination = false;
245
246 float RepathInterval = 0.5f;
247 };
249 {
250 bool Enabled = true;
252
253 float DetectionRadius = 10.0f;
254 float FieldOfView = 120.0f;
255 // Vertical offset of the observer's eyes
256 // relative to the entity's world position.
257 float EyeHeight = 1.6f;
258
259 float MemoryDuration = 3.0f;
260
261
262 float UpdateInterval = 0.1f;
263
264 bool DebugDraw = true;
265
266
267 };
268
270 {
271 float Friction = 0.5f;
272 float Bounciness = 0.0f;
273 };
274
276 {
277 glm::vec3 Size{ 1.0f, 1.0f, 1.0f };
278 bool IsTrigger = false;
280 };
281
283 {
284 float Radius = 0.5f;
285 bool IsTrigger = false;
287 };
288
290 {
291 float Radius = 0.5f;
292 float Height = 2.0f;
293 bool IsTrigger = false;
295 };
296
297 enum class ScriptFieldType { Float = 0, Int, Bool, Vec3, String };
298
300 {
302 float Float = 0.0f;
303 int Int = 0;
304 bool Bool = false;
305 std::string String;
306 glm::vec3 Vec3{ 0.0f };
307
308 static ScriptFieldValue MakeFloat(float value) { ScriptFieldValue v; v.Type=ScriptFieldType::Float; v.Float=value; return v; }
309 static ScriptFieldValue MakeInt(int value) { ScriptFieldValue v; v.Type=ScriptFieldType::Int; v.Int=value; return v; }
310 static ScriptFieldValue MakeBool(bool value) { ScriptFieldValue v; v.Type=ScriptFieldType::Bool; v.Bool=value; return v; }
311 static ScriptFieldValue MakeString(std::string value) { ScriptFieldValue v; v.Type=ScriptFieldType::String; v.String=std::move(value); return v; }
312 static ScriptFieldValue MakeVec3(glm::vec3 value) { ScriptFieldValue v; v.Type=ScriptFieldType::Vec3; v.Vec3=value; return v; }
313 };
314
316 {
317 bool Enabled = true;
318 std::string ScriptName = "Rotator";
319 std::unordered_map<std::string, ScriptFieldValue> Fields;
320 };
321
322
324 {
325 std::shared_ptr<AnimationAsset> Animation;
326 int ClipIndex = 0;
327 float TimeSeconds = 0.0f;
328 float Speed = 1.0f;
329 bool Playing = true;
330 bool Loop = true;
331 };
332
334 {
335 std::string SourcePath;
336 bool IsRoot = true;
337 };
338
340 {
341 std::shared_ptr<Mesh> MeshAsset;
342 };
343
345 {
346 std::shared_ptr<Material> MaterialAsset;
347 std::vector<std::shared_ptr<Material>> Materials;
348
349 std::shared_ptr<Material> GetMaterial(std::size_t index) const
350 {
351 if(index<Materials.size() && Materials[index]) return Materials[index];
352 return index==0 ? MaterialAsset : nullptr;
353 }
354 void SetMaterials(std::vector<std::shared_ptr<Material>> materials)
355 {
356 Materials=std::move(materials);
357 MaterialAsset=Materials.empty()?nullptr:Materials.front();
358 }
359 };
360}
constexpr std::uint32_t Default
Definition Components.h:43
constexpr std::uint32_t MaxLayers
Definition Components.h:49
constexpr std::uint32_t Enemy
Definition Components.h:45
constexpr LayerMask Bit(std::uint32_t layer)
Definition Components.h:54
constexpr LayerMask None
Definition Components.h:52
constexpr std::uint32_t Environment
Definition Components.h:46
constexpr std::uint32_t Interactable
Definition Components.h:47
constexpr LayerMask All
Definition Components.h:51
constexpr std::uint32_t Player
Definition Components.h:44
ParticleBlendMode
Definition Components.h:164
std::uint32_t LayerMask
Definition Components.h:37
CameraProjectionType
Definition Components.h:106
RigidbodyType
Definition Components.h:223
ParticleShape
Definition Components.h:163
ScriptFieldType
Definition Components.h:297
std::shared_ptr< AnimationAsset > Animation
Definition Components.h:325
glm::mat4 GetProjection(float aspectRatio) const
Definition Components.h:122
CameraProjectionType ProjectionType
Definition Components.h:113
std::uint64_t ID
Definition Components.h:25
std::uint32_t Layer
Definition Components.h:64
std::shared_ptr< Mesh > MeshAsset
Definition Components.h:341
std::shared_ptr< Material > GetMaterial(std::size_t index) const
Definition Components.h:349
std::shared_ptr< Material > MaterialAsset
Definition Components.h:346
void SetMaterials(std::vector< std::shared_ptr< Material > > materials)
Definition Components.h:354
std::vector< std::shared_ptr< Material > > Materials
Definition Components.h:347
std::unordered_map< std::string, ScriptFieldValue > Fields
Definition Components.h:319
ParticleBlendMode BlendMode
Definition Components.h:189
std::vector< std::uint32_t > Children
Definition Components.h:101
static ScriptFieldValue MakeInt(int value)
Definition Components.h:309
static ScriptFieldValue MakeBool(bool value)
Definition Components.h:310
static ScriptFieldValue MakeFloat(float value)
Definition Components.h:308
ScriptFieldType Type
Definition Components.h:301
static ScriptFieldValue MakeString(std::string value)
Definition Components.h:311
static ScriptFieldValue MakeVec3(glm::vec3 value)
Definition Components.h:312
std::string Tag
Definition Components.h:30
glm::mat4 GetTransform() const
Definition Components.h:74