Skip to content

Commit 2efe355

Browse files
committed
Changed Fonts to be assets
1 parent 385b1d1 commit 2efe355

21 files changed

Lines changed: 115 additions & 32 deletions

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ set(SOURCE_FILES
5555
src/RealEngine/Core/Logger.cpp
5656
src/RealEngine/Core/Assert.h
5757
src/RealEngine/Core/Profiler.h
58-
src/RealEngine/Core/Layer.h
59-
src/RealEngine/Core/Layer.cpp
60-
src/RealEngine/Core/LayerStack.h
61-
src/RealEngine/Core/LayerStack.cpp
58+
"src/RealEngine/Types/Layer.h"
59+
"src/RealEngine/Types/Layer.cpp"
60+
"src/RealEngine/Types/LayerStack.h"
61+
"src/RealEngine/Types/LayerStack.cpp"
6262
src/RealEngine/Core/Window.h
6363
src/RealEngine/Core/Window.cpp
6464
src/RealEngine/Core/KeyCodes.h
@@ -125,7 +125,7 @@ set(SOURCE_FILES
125125
vendor/ankerl/unordered_dense.h
126126
vendor/filewatch/FileWatch.h
127127

128-
"src/RealEngine/Types/RingBuffer.h" "src/RealEngine/Core/ImGuiLogSink.h" "src/RealEngine/Asset/AssetManager.h" "src/RealEngine/Asset/Asset.h" "src/RealEngine/Asset/AssetManager.cpp" "src/RealEngine/Asset/AssetMetadata.h" "src/RealEngine/Asset/AssetImporter.h" "src/RealEngine/Asset/AssetImporter.cpp" "src/RealEngine/Asset/TextureImporter.h" "src/RealEngine/Asset/TextureImporter.cpp" "src/RealEngine/Scripting/ScriptEngine.h" "src/RealEngine/Scripting/ScriptEngine.cpp" "src/RealEngine/Scripting/ScriptGlue.h" "src/RealEngine/Scripting/ScriptGlue.cpp" "src/RealEngine/Formatter/CoreFormatter.h" "src/RealEngine/Events/ProjectEvents.h" "src/RealEngine/Core/ProjectSerializer.h" "src/RealEngine/Core/ProjectSerializer.cpp" "src/RealEngine/Types/HashMap.h" "src/RealEngine/Scripting/ScriptInstance.h" "src/RealEngine/Scripting/ScriptInstance.cpp" "src/RealEngine/Types/Font.h" "src/RealEngine/Types/Font.cpp")
128+
"src/RealEngine/Types/RingBuffer.h" "src/RealEngine/Core/ImGuiLogSink.h" "src/RealEngine/Asset/AssetManager.h" "src/RealEngine/Asset/Asset.h" "src/RealEngine/Asset/AssetManager.cpp" "src/RealEngine/Asset/AssetMetadata.h" "src/RealEngine/Asset/AssetImporter.h" "src/RealEngine/Asset/AssetImporter.cpp" "src/RealEngine/Asset/TextureImporter.h" "src/RealEngine/Asset/TextureImporter.cpp" "src/RealEngine/Scripting/ScriptEngine.h" "src/RealEngine/Scripting/ScriptEngine.cpp" "src/RealEngine/Scripting/ScriptGlue.h" "src/RealEngine/Scripting/ScriptGlue.cpp" "src/RealEngine/Formatter/CoreFormatter.h" "src/RealEngine/Events/ProjectEvents.h" "src/RealEngine/Core/ProjectSerializer.h" "src/RealEngine/Core/ProjectSerializer.cpp" "src/RealEngine/Types/HashMap.h" "src/RealEngine/Scripting/ScriptInstance.h" "src/RealEngine/Scripting/ScriptInstance.cpp" "src/RealEngine/Types/Font.h" "src/RealEngine/Types/Font.cpp" "src/RealEngine/Asset/FontImporter.h" "src/RealEngine/Asset/FontImporter.cpp")
129129

130130
# Platform-specific files
131131
if(WIN32)

src/RealEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "RealEngine/Core/Dialogs.h"
1212
#include "RealEngine/Core/Input.h"
1313
#include "RealEngine/Core/KeyCodes.h"
14-
#include "RealEngine/Core/Layer.h"
1514
#include "RealEngine/Core/Logger.h"
1615
#include "RealEngine/Core/MouseCodes.h"
1716
#include "RealEngine/Core/Project.h"
@@ -59,6 +58,7 @@
5958
// ==============================
6059
// Types
6160
// ==============================
61+
#include "RealEngine/Types/Layer.h"
6262
#include "RealEngine/Types/RingBuffer.h"
6363
#include "RealEngine/Types/StringHash.h"
6464
#include "RealEngine/Types/UUID.h"

src/RealEngine/Asset/Asset.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22

33
#include "RealEngine/Types/StringHash.h"
44

5-
namespace RealEngine {
5+
namespace RealEngine {
66
using AssetHandle = StringHash;
77

88
enum class AssetType : uint16_t {
99
None = 0,
1010
Texture2D,
11-
Shader
11+
Shader,
12+
Font
1213
};
1314

15+
namespace Utils {
16+
static const char* GetAssetTypeString(AssetType type) {
17+
switch (type) {
18+
case AssetType::None: return "None";
19+
case AssetType::Texture2D: return "Texture2D";
20+
case AssetType::Shader: return "Shader";
21+
case AssetType::Font: return "Font";
22+
default: return "Unknown";
23+
}
24+
};
25+
}
26+
1427
class Asset {
1528
public:
1629
Asset() = default;

src/RealEngine/Asset/AssetImporter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "AssetImporter.h"
22

3+
34
namespace RealEngine {
45
using AssetImportFunction = std::function<Ref<Asset>(const AssetMetadata&)>;
56
static HashMap<AssetType, AssetImportFunction> s_AssetImportFunctions = {
67
{ AssetType::Texture2D, TextureImporter::ImportTexture2D },
8+
{ AssetType::Font, FontImporter::ImportFont },
79
};
810

911
Ref<Asset> AssetImporter::ImportAsset(const AssetMetadata& metadata) {

src/RealEngine/Asset/AssetImporter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "AssetMetadata.h"
44

55
#include "TextureImporter.h"
6+
#include "FontImporter.h"
67

78
namespace RealEngine {
89
class AssetImporter {

src/RealEngine/Asset/AssetManager.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace RealEngine {
1010
{ ".png", AssetType::Texture2D },
1111
{ ".jpg", AssetType::Texture2D },
1212
{ ".jpeg", AssetType::Texture2D },
13-
{ ".shader", AssetType::Shader }
13+
{ ".shader", AssetType::Shader },
14+
{ ".ttf", AssetType::Font }
1415
};
1516

1617
static AssetType GetAssetTypeFromFileExtension(const std::filesystem::path& extension) {
@@ -26,6 +27,8 @@ namespace RealEngine {
2627
switch (type) {
2728
case AssetType::Texture2D:
2829
return Texture2DMetadata{};
30+
case AssetType::Font:
31+
return {}; // No custom metadata for fonts yet
2932
default:
3033
RE_CORE_ASSERT(false, "AssetType {} is not supported for CustomMetadata", (uint16_t)type);
3134
return {};
@@ -181,7 +184,9 @@ namespace RealEngine {
181184
if (it->second.use_count() == 1) {
182185
AssetHandle handle = it->first;
183186
std::filesystem::path& path = m_AssetRegistry[handle].FilePath;
184-
RE_CORE_INFO("Unloading unused asset with filename: {}", path.filename());
187+
188+
AssetType type = m_AssetRegistry[handle].Type;
189+
RE_CORE_INFO("Unloading unused {} asset with filename: {}", Utils::GetAssetTypeString(type), path.filename());
185190

186191
it = m_LoadedAssets.erase(it);
187192
}

src/RealEngine/Asset/AssetManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ namespace RealEngine {
6262
Ref<T> LoadAsset(AssetHandle handle) {
6363
RE_PROFILE_FUNCTION();
6464
RE_CORE_ASSERT(IsAssetValid(handle), "Achivment unlocked how did we get here?");
65-
RE_CORE_INFO("Loading asset with handle: {}", (uint64_t)handle);
6665

67-
auto& assetMetaData = m_AssetRegistry.at(handle);
66+
AssetMetadata& assetMetaData = m_AssetRegistry.at(handle);
67+
RE_CORE_INFO("Loading {} asset with handle: {}", Utils::GetAssetTypeString(assetMetaData.Type), (uint64_t)handle);
68+
6869
Ref<Asset> asset = AssetImporter::ImportAsset(assetMetaData);
6970
asset->m_Handle = handle;
7071
m_LoadedAssets.emplace(handle, asset);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "FontImporter.h"
2+
3+
namespace RealEngine {
4+
Ref<Font> FontImporter::ImportFont(const AssetMetadata& metadata) {
5+
return CreateRef<Font>(metadata.FilePath);
6+
}
7+
}
8+
9+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#include "Asset.h"
3+
4+
#include "RealEngine/Types/Font.h"
5+
6+
namespace RealEngine {
7+
class FontImporter {
8+
public:
9+
static Ref<Font> ImportFont(const AssetMetadata& metadata);
10+
};
11+
}

src/RealEngine/Core/Application.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#pragma warning( disable : 4100 )
33

44
#include "RealEngine/Core/Assert.h"
5-
#include "RealEngine/Core/LayerStack.h"
65
#include "RealEngine/Core/Window.h"
76

7+
#include "RealEngine/Types/LayerStack.h"
8+
89
#include "RealEngine/Events/Event.h"
910
#include "RealEngine/Events/WindowEvents.h"
1011

0 commit comments

Comments
 (0)