Skip to content

Commit 0129172

Browse files
committed
feat(core): adds glm with abstractions and tracy as a profiler
1 parent 5102dad commit 0129172

5 files changed

Lines changed: 177 additions & 3 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright RavenStormStudio 2026 All Rights Reserved Copyright
2+
3+
#pragma once
4+
5+
// []==================================================[]
6+
// This file contains math types and functions that wrap
7+
// glm. This might be a temporary solution, as I plan to
8+
// implement a custom math library for this engine.
9+
// For now the glm wrapper is in place.
10+
//
11+
// IMPORTANT: DON'T USE GLM DIRECTLY. Only use the
12+
// provided types of this file. If something is missing,
13+
// please add it here.
14+
// []==================================================[]
15+
16+
#include <numbers>
17+
18+
#include <glm/glm.hpp>
19+
#include <glm/gtc/matrix_transform.hpp>
20+
#include <glm/gtc/quaternion.hpp>
21+
22+
#include "CoreTypes.hpp"
23+
24+
template <typename TScalar>
25+
concept CScalar = std::is_floating_point_v<TScalar> && !std::is_same_v<TScalar, bool8>;
26+
27+
using FVector2 = glm::vec2;
28+
using FVector3 = glm::vec3;
29+
using FVector4 = glm::vec4;
30+
31+
using FQuaternion = glm::quat;
32+
33+
using FMatrix4 = glm::mat4;
34+
35+
static_assert(sizeof(FVector2) == 8 && std::is_trivially_copyable_v<FVector2>);
36+
static_assert(sizeof(FVector3) == 12 && std::is_trivially_copyable_v<FVector3>);
37+
static_assert(sizeof(FVector4) == 16 && std::is_trivially_copyable_v<FVector4>);
38+
39+
static_assert(sizeof(FQuaternion) == 16 && std::is_trivially_copyable_v<FQuaternion>);
40+
static_assert(sizeof(FMatrix4) == 64 && std::is_trivially_copyable_v<FMatrix4>);
41+
42+
namespace Math
43+
{
44+
template <CScalar TScalar>
45+
inline constexpr TScalar KindaSmallNumber = TScalar(1e-4);
46+
47+
template <CScalar TScalar>
48+
[[nodiscard]] constexpr TScalar IsNearlyEqual(const TScalar A, const TScalar B, const TScalar Tolerance = KindaSmallNumber<TScalar>)
49+
{
50+
return Abs(A - B) <= Tolerance;
51+
}
52+
53+
template <CScalar TScalar>
54+
[[nodiscard]] constexpr TScalar IsNearlyZero(const TScalar Value, const TScalar Tolerance = KindaSmallNumber<TScalar>)
55+
{
56+
return Abs(Value) <= Tolerance;
57+
}
58+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright RavenStormStudio 2026 All Rights Reserved Copyright
2+
3+
#pragma once
4+
5+
#include "CoreMacros.hpp"
6+
#include "CoreTypes.hpp"
7+
8+
#include "Memory/Containers/String.hpp"
9+
10+
#if RAVEN_PROFILER_ENABLED
11+
# include <tracy/Tracy.hpp>
12+
#endif
13+
14+
namespace Profiler
15+
{
16+
struct FZone
17+
{
18+
const TChar* Name;
19+
uint32 Color;
20+
};
21+
22+
namespace Colors
23+
{
24+
inline constexpr uint32 White = 0xFFFFFFFF;
25+
inline constexpr uint32 Black = 0x00000000;
26+
inline constexpr uint32 Red = 0xFF0000FF;
27+
inline constexpr uint32 Green = 0xFF00FF00;
28+
inline constexpr uint32 Blue = 0xFFFF0000;
29+
inline constexpr uint32 Yellow = 0xFFFFFF00;
30+
inline constexpr uint32 Magenta = 0xFFFF00FF;
31+
inline constexpr uint32 Cyan = 0xFF00FFFF;
32+
inline constexpr uint32 Gray = 0xFF808080;
33+
inline constexpr uint32 Orange = 0xFFFFA500;
34+
inline constexpr uint32 Purple = 0xFF800080;
35+
inline constexpr uint32 Brown = 0xFFA52A2A;
36+
inline constexpr uint32 Pink = 0xFFFFC0CB;
37+
38+
constexpr uint32 CreateColor(const uint8 R, const uint8 G, const uint8 B)
39+
{
40+
return (static_cast<uint32>(R) << 24) | (static_cast<uint32>(G) << 16) | (static_cast<uint32>(B) << 8);
41+
}
42+
}
43+
}
44+
45+
#if RAVEN_PROFILER_ENABLED
46+
47+
# define RAVEN_DEFINE_PROFILER_ZONE(Name, Color) inline constexpr Profiler::FZone CONCAT(Name, Zone) = { (#Name), (Color) }
48+
49+
# define RAVEN_PROFILE_SRCLOC(Definition) \
50+
static constexpr tracy::SourceLocationData CONCAT(RavenProfilerSrcLoc, __LINE__) = { (Definition.Name), __FUNCTION__, __FILE__, static_cast<uint32>(__LINE__), (Definition).Color }
51+
52+
# define RAVEN_PROFILE_FUNCTION(ColorValue) \
53+
static constexpr tracy::SourceLocationData CONCAT(RavenProfilerSrcLoc, __LINE__) = { nullptr, __FUNCTION__, __FILE__, static_cast<uint32>(__LINE__), (ColorValue) }; \
54+
tracy::ScopedZone CONCAT(RavenProfilerZone, __LINE__) = { &CONCAT(RavenProfilerSrcLoc, __LINE__), true }
55+
56+
# define RAVEN_PROFILE_ZONE(Definition) \
57+
RAVEN_PROFILE_SRCLOC(Definition); \
58+
tracy::ScopedZone CONCAT(RavenProfilerZone, __LINE__) = { &CONCAT(RavenProfilerSrcLoc, __LINE__), true }
59+
60+
# define RAVEN_PROFILE_ZONE_DYNAMIC(Definition, SuffixText, SuffixLength) \
61+
RAVEN_PROFILE_ZONE(Definition); \
62+
CONCAT(RavenProfilerZone, __LINE__).Name((SuffixText), (SuffixLength))
63+
64+
# define RAVEN_PROFILE_ZONE_TEXT(Definition, Text, TextLength) \
65+
RAVEN_PROFILE_ZONE(Definition); \
66+
CONCAT(RavenProfilerZone, __LINE__).Text((Text), (TextLength))
67+
68+
# define RAVEN_PROFILE_FRAME_MARK() FrameMark
69+
# define RAVEN_PROFILE_FRAME_MARK_NAMED(Name) FrameMarkNamed((Name))
70+
# define RAVEN_PROFILE_THREAD(Name) tracy::SetThreadName((Name))
71+
# define RAVEN_PROFILE_PLOT(Name, Value) TracyPlot((Name), (Value))
72+
73+
#else
74+
# define RAVEN_DEFINE_PROFILER_ZONE(...)
75+
# define RAVEN_PROFILE_SRCLOC(Definition)
76+
# define RAVEN_PROFILE_FUNCTION(...) ((void)0)
77+
# define RAVEN_PROFILE_ZONE(...) ((void)0)
78+
# define RAVEN_PROFILE_ZONE_DYNAMIC(...) ((void)0)
79+
# define RAVEN_PROFILE_ZONE_TEXT(...) ((void)0)
80+
# define RAVEN_PROFILE_FRAME_MARK(...) ((void)0)
81+
# define RAVEN_PROFILE_FRAME_MARK_NAMED(...) ((void)0)
82+
# define RAVEN_PROFILE_THREAD(...) ((void)0)
83+
# define RAVEN_PROFILE_PLOT(...) ((void)0)
84+
#endif

Engine/Source/Runtime/Core/xmake.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ local target_name = 'Core'
22

33
raven_engine_target(target_name)
44
add_packages('mimalloc')
5+
add_packages('glm', 'tracy', { public = true })
6+
7+
add_defines('GLM_FORCE_DEPTH_ZERO_TO_ONE=', 'GLM_FORCE_XYZW_ONLY=', 'GLM_FORCE_EXPLICIT_CTOR=', { public = true })
58
raven_end_target()
69

710
raven_test_target(target_name .. '_Tests')

Engine/Source/Runtime/Launch/Private/Launch.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Copyright RavenStormStudio 2026 All Rights Reserved Copyright
22

33
#include <iostream>
4+
#include <Windows.h>
45

56
#include "Error/Result.hpp"
67

78
#include "Memory/Memory.hpp"
89

10+
#include "Profiling/Profiling.hpp"
11+
912
struct FTexture
1013
{
1114
uint32 Width = 0;
@@ -28,10 +31,34 @@ TResult<int> LoadTexture()
2831
return Texture.Width * Texture.Height;
2932
}
3033

34+
35+
RAVEN_DEFINE_PROFILER_ZONE(Setup, Profiler::Colors::Cyan);
36+
RAVEN_DEFINE_PROFILER_ZONE(Test1, Profiler::Colors::Green);
37+
RAVEN_DEFINE_PROFILER_ZONE(Test2, Profiler::Colors::Red);
38+
3139
int main()
3240
{
41+
RAVEN_PROFILE_ZONE(SetupZone);
42+
RAVEN_PROFILE_FUNCTION(Profiler::Colors::Red);
3343
Memory::Initialize();
3444

45+
float32 Value = 0;
46+
while (!(GetAsyncKeyState(VK_END) & 0x8000))
47+
{
48+
RAVEN_PROFILE_FRAME_MARK();
49+
if constexpr (true)
50+
{
51+
RAVEN_PROFILE_ZONE(Test1Zone);
52+
53+
if constexpr (true)
54+
{
55+
RAVEN_PROFILE_ZONE(Test2Zone);
56+
}
57+
}
58+
RAVEN_PROFILE_PLOT("Test", Value);
59+
Value++;
60+
}
61+
3562
TResult<int> Result = LoadTexture();
3663
if (!Result)
3764
{

xmake.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if is_mode('debug') then
3232
add_defines('RAVEN_BUILD_MODULAR')
3333
add_defines('RAVEN_MODE_DEBUG', 'RAVEN_MODE="Debug"')
3434

35-
add_defines('RAVEN_ENABLE_ASSERTS=1')
35+
add_defines('RAVEN_ENABLE_ASSERTS=1', 'RAVEN_PROFILER_ENABLED=1', 'TRACY_ENABLE')
3636
elseif is_mode('development') then
3737
set_symbols('debug')
3838
set_optimize('fastest')
@@ -41,7 +41,7 @@ elseif is_mode('development') then
4141
add_defines('RAVEN_BUILD_MODULAR')
4242
add_defines('RAVEN_MODE_DEVELOPMENT', 'RAVEN_MODE="Development"')
4343

44-
add_defines('RAVEN_ENABLE_ASSERTS=0')
44+
add_defines('RAVEN_ENABLE_ASSERTS=0', 'RAVEN_PROFILER_ENABLED=1', 'TRACY_ENABLE')
4545
elseif is_mode('shipping') then
4646
set_symbols('debug')
4747
set_optimize('aggressive')
@@ -50,7 +50,7 @@ elseif is_mode('shipping') then
5050
add_defines('RAVEN_BUILD_MONOLITHIC')
5151
add_defines('RAVEN_MODE_SHIPPING', 'RAVEN_MODE="Shipping"')
5252

53-
add_defines('RAVEN_ENABLE_ASSERTS=0')
53+
add_defines('RAVEN_ENABLE_ASSERTS=0', 'RAVEN_PROFILER_ENABLED=0')
5454
end
5555

5656
if is_plat('windows') then
@@ -73,6 +73,8 @@ rule_end()
7373
add_requires("snitch 1.3.2")
7474
add_requires('glfw 3.4')
7575
add_requires('mimalloc 3.3.2', { configs = { cxx = true } })
76+
add_requires('glm 1.0.3', { configs = { cxx_standard = '20' } })
77+
add_requires('tracy 0.13.0')
7678

7779
-- Helper Functions
7880
includes('Engine/Build/targets.lua')

0 commit comments

Comments
 (0)