Skip to content

Commit c42339e

Browse files
authored
Merge pull request #27 from starbounded-dev/feature/runtime-export
feature: export Runtime to Distribution
2 parents d6efc93 + cdedbf4 commit c42339e

320 files changed

Lines changed: 2570 additions & 8061 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
$editorItems = @(
8484
"imgui.ini",
8585
"App.lsettings",
86-
"SandboxProject",
86+
"LuxSampleProject",
8787
"Resources",
8888
"mono"
8989
)

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Intermediates/
1313
**.vcxproj.filters
1414
**.vcxproj.user
1515
**.csproj
16+
**.csproj.user
1617

1718
# Directories
1819
scripts/__pycache__
@@ -25,8 +26,11 @@ Sandbox/Resources/Cache
2526
Core/vendor/GLAD
2627
Core/vendor/NFD-Extended
2728
Core/vendor/tracy
28-
Editor/SandboxProject/Assets/Scripts/Binaries
29+
Editor/LuxSampleProject/Assets/Scripts/Binaries
2930
Editor/Resources/Cache
3031
Lux.slnx
31-
Editor/SandboxProject/Assets/Cache/Thumbnails
32-
Editor/SandboxProject/Assets/AssetRegistry.lzr
32+
Editor/LuxSampleProject/Assets/Cache/Thumbnails
33+
Editor/LuxSampleProject/Assets/AssetRegistry.lzr
34+
*.lap
35+
*.aps
36+
*.slnx

Core/Source/Lux/Asset/MeshSerializer.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#include "lpch.h"
22
#include "MeshSerializer.h"
33

4-
#include "AssimpMeshImporter.h"
54
#include "MeshRuntimeSerializer.h"
65

76
#include "Lux/Asset/AssetManager.h"
87
#include "Lux/Project/Project.h"
98
#include "Lux/Renderer/Mesh.h"
109

10+
#ifndef LUX_DIST
11+
#include "AssimpMeshImporter.h"
12+
#endif
13+
1114
#include <fstream>
1215
#include <sstream>
1316

@@ -148,6 +151,10 @@ namespace Lux
148151

149152
bool MeshSourceSerializer::TryLoadData(const AssetMetadata& metadata, Ref<Asset>& asset) const
150153
{
154+
#ifdef LUX_DIST
155+
LUX_CORE_ERROR("MeshSourceSerializer cannot import source meshes in Dist builds: {}", metadata.FilePath.string());
156+
return false;
157+
#else
151158
AssimpMeshImporter importer(Project::GetEditorAssetManager()->GetFileSystemPath(metadata));
152159
Ref<MeshSource> meshSource = importer.ImportToMeshSource();
153160
if (!meshSource)
@@ -156,6 +163,7 @@ namespace Lux
156163
meshSource->Handle = metadata.Handle;
157164
asset = meshSource;
158165
return true;
166+
#endif
159167
}
160168

161169
bool MeshSourceSerializer::SerializeToAssetPack(AssetHandle handle, FileStreamWriter& stream, AssetSerializationInfo& outInfo) const

Core/Source/Lux/Asset/TextureSerializer.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Lux/Renderer/SceneEnvironment.h"
77
#include "Lux/Serialization/TextureRuntimeSerializer.h"
88
#include "Lux/Project/Project.h"
9+
#include "Lux/Utilities/FileSystem.h"
910

1011
#include <filesystem>
1112

@@ -88,12 +89,17 @@ namespace Lux
8889

8990
if (AssetManager::GetAssetType(handle) == AssetType::EnvMap)
9091
{
91-
Ref<Environment> environment = AssetManager::GetAsset<Environment>(handle);
92-
if (!environment || !environment->RadianceMap || !environment->IrradianceMap)
92+
auto assetManager = Project::GetEditorAssetManager();
93+
if (!assetManager)
9394
return false;
9495

95-
TextureRuntimeSerializer::SerializeToFile(environment->RadianceMap, stream);
96-
TextureRuntimeSerializer::SerializeToFile(environment->IrradianceMap, stream);
96+
const AssetMetadata metadata = assetManager->GetMetadata(handle);
97+
Buffer sourceBuffer = FileSystem::ReadBytes(assetManager->GetFileSystemPath(metadata));
98+
if (!sourceBuffer)
99+
return false;
100+
101+
stream.WriteBuffer(sourceBuffer);
102+
sourceBuffer.Release();
97103
outInfo.Size = stream.GetStreamPosition() - outInfo.Offset;
98104
return true;
99105
}
@@ -113,8 +119,24 @@ namespace Lux
113119
const AssetType assetType = (AssetType)assetInfo.Type;
114120
if (assetType == AssetType::EnvMap)
115121
{
116-
Ref<TextureCube> radiance = TextureRuntimeSerializer::DeserializeTextureCube(stream);
117-
Ref<TextureCube> irradiance = TextureRuntimeSerializer::DeserializeTextureCube(stream);
122+
Buffer sourceBuffer;
123+
stream.ReadBuffer(sourceBuffer);
124+
if (!sourceBuffer)
125+
return nullptr;
126+
127+
TextureSpecification equirectSpec;
128+
equirectSpec.DebugName = "PackedEnvEquirect";
129+
equirectSpec.FlipVertically = false;
130+
equirectSpec.Width = (uint32_t)sourceBuffer.Size;
131+
equirectSpec.Height = 0;
132+
133+
Ref<Texture2D> equirectTexture = Texture2D::Create(equirectSpec, sourceBuffer);
134+
sourceBuffer.Release();
135+
136+
if (!equirectTexture || !equirectTexture->Loaded())
137+
return nullptr;
138+
139+
auto [radiance, irradiance] = Renderer::CreateEnvironmentMap(equirectTexture);
118140
if (!radiance || !irradiance)
119141
return nullptr;
120142

Core/Source/Lux/Core/Application.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ namespace Lux {
8888
else
8989
m_Window->CenterWindow();
9090
m_Window->SetResizable(specification.Resizable);
91+
m_Window->Show();
9192

9293
if (m_Specification.EnableImGui)
9394
{

Core/Source/Lux/Core/Window.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ namespace Lux {
513513
glfwSetWindowPos(m_WindowHandle, x, y);
514514
}
515515

516+
void Window::Show()
517+
{
518+
glfwShowWindow(m_WindowHandle);
519+
}
520+
516521
void Window::SetTitle(const std::string& title)
517522
{
518523
m_Data.Title = title;

Core/Source/Lux/Core/Window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace Lux {
5757

5858
virtual void Maximize();
5959
virtual void CenterWindow();
60+
virtual void Show();
6061

6162
virtual const std::string& GetTitle() const { return m_Data.Title; }
6263
virtual void SetTitle(const std::string& title);

Core/Source/Lux/Project/Project.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@
88

99
namespace Lux
1010
{
11+
const char* RuntimeExportTargetToString(RuntimeExportTarget target)
12+
{
13+
switch (target)
14+
{
15+
case RuntimeExportTarget::Debug: return "Debug";
16+
case RuntimeExportTarget::Release: return "Release";
17+
case RuntimeExportTarget::Dist: return "Dist";
18+
}
19+
20+
return "Release";
21+
}
22+
23+
RuntimeExportTarget RuntimeExportTargetFromString(std::string_view value)
24+
{
25+
if (value == "Debug" || value == "0")
26+
return RuntimeExportTarget::Debug;
27+
if (value == "Dist" || value == "2")
28+
return RuntimeExportTarget::Dist;
29+
return RuntimeExportTarget::Release;
30+
}
31+
1132
std::filesystem::path Project::GetAssetAbsolutePath(const std::filesystem::path& path) const
1233
{
1334
return GetAssetDirectory() / path;
@@ -50,6 +71,15 @@ namespace Lux
5071
s_ActiveProject->m_Config.StartScene = startSceneMetadata.FilePath.generic_string();
5172
}
5273

74+
if (!s_ActiveProject->m_Config.RuntimeExport.IconPath.empty())
75+
s_ActiveProject->m_Config.RuntimeExport.IconHandle = GetEditorAssetManager()->GetAssetHandleFromFilePath(s_ActiveProject->m_Config.RuntimeExport.IconPath);
76+
else if (s_ActiveProject->m_Config.RuntimeExport.IconHandle)
77+
{
78+
AssetMetadata iconMetadata = GetEditorAssetManager()->GetMetadata(s_ActiveProject->m_Config.RuntimeExport.IconHandle);
79+
if (iconMetadata.IsValid())
80+
s_ActiveProject->m_Config.RuntimeExport.IconPath = iconMetadata.FilePath.generic_string();
81+
}
82+
5383
if (!AudioEngine::HasInitializedEngine())
5484
{
5585
AudioEngine::Init();
@@ -66,13 +96,31 @@ namespace Lux
6696
}
6797

6898
s_ActiveProject = project;
99+
if (AudioEngine::HasInitializedEngine())
100+
{
101+
AudioEngine::Shutdown();
102+
AudioEngine::SetInitalizedEngine(false);
103+
}
104+
69105
if (!s_ActiveProject)
70106
return;
71107

108+
if (s_ActiveProject->m_ProjectDirectory.empty())
109+
s_ActiveProject->m_ProjectDirectory = s_ActiveProject->m_Config.ProjectDirectory;
110+
if (s_ActiveProject->m_ProjectFilePath.empty() && !s_ActiveProject->m_ProjectDirectory.empty())
111+
s_ActiveProject->m_ProjectFilePath = s_ActiveProject->m_ProjectDirectory / s_ActiveProject->m_Config.ProjectFileName;
112+
72113
s_ActiveProject->m_Config.ProjectDirectory = s_ActiveProject->m_ProjectDirectory;
73114
s_ActiveProject->m_Config.ProjectFileName = s_ActiveProject->m_ProjectFilePath.filename().string();
115+
74116
s_AssetManager = Ref<RuntimeAssetManager>::Create();
75117
GetRuntimeAssetManager()->SetAssetPack(assetPack);
118+
119+
if (!AudioEngine::HasInitializedEngine())
120+
{
121+
AudioEngine::Init();
122+
AudioEngine::SetInitalizedEngine(true);
123+
}
76124
}
77125

78126
Ref<Project> Project::New()
@@ -83,6 +131,23 @@ namespace Lux
83131
return s_ActiveProject;
84132
}
85133

134+
Ref<Project> Project::LoadRuntime(const std::filesystem::path& path, Ref<AssetPack> assetPack)
135+
{
136+
Ref<Project> project = Ref<Project>::Create();
137+
138+
ProjectSerializer serializer(project);
139+
if (!serializer.DeserializeRuntime(path))
140+
return nullptr;
141+
142+
project->m_ProjectFilePath = path.lexically_normal();
143+
project->m_ProjectDirectory = path.parent_path();
144+
project->m_Config.ProjectDirectory = project->m_ProjectDirectory;
145+
project->m_Config.ProjectFileName = project->m_ProjectFilePath.filename().string();
146+
147+
SetActiveRuntime(project, assetPack);
148+
return s_ActiveProject;
149+
}
150+
86151
Ref<Project> Project::Load(const std::filesystem::path& path)
87152
{
88153
Ref<Project> project = Ref<Project>::Create();
@@ -106,6 +171,9 @@ namespace Lux
106171
if (!s_ActiveProject->m_Config.StartScene.empty() && GetEditorAssetManager())
107172
s_ActiveProject->m_Config.StartSceneHandle = GetEditorAssetManager()->GetAssetHandleFromFilePath(s_ActiveProject->m_Config.StartScene);
108173

174+
if (!s_ActiveProject->m_Config.RuntimeExport.IconPath.empty() && GetEditorAssetManager())
175+
s_ActiveProject->m_Config.RuntimeExport.IconHandle = GetEditorAssetManager()->GetAssetHandleFromFilePath(s_ActiveProject->m_Config.RuntimeExport.IconPath);
176+
109177
if (s_ActiveProject->m_Config.DefaultNamespace.empty())
110178
s_ActiveProject->m_Config.DefaultNamespace = s_ActiveProject->m_Config.Name;
111179

@@ -132,5 +200,8 @@ namespace Lux
132200

133201
if (m_Config.ScriptModulePath.empty())
134202
m_Config.ScriptModulePath = std::filesystem::path("Scripts/Binaries") / (m_Config.Name + ".dll");
203+
204+
if (m_Config.RuntimeExport.GameName.empty())
205+
m_Config.RuntimeExport.GameName = m_Config.Name;
135206
}
136207
}

Core/Source/Lux/Project/Project.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ namespace Lux
2626
CaptureToFile = 1
2727
};
2828

29+
enum class RuntimeExportTarget : uint8_t
30+
{
31+
Debug = 0,
32+
Release = 1,
33+
Dist = 2
34+
};
35+
36+
const char* RuntimeExportTargetToString(RuntimeExportTarget target);
37+
RuntimeExportTarget RuntimeExportTargetFromString(std::string_view value);
38+
2939
struct ProjectAudioSettings
3040
{
3141
double FileStreamingDurationThreshold = 1.0;
@@ -110,6 +120,18 @@ namespace Lux
110120
float SSRDepthTolerance = 0.8f;
111121
};
112122

123+
struct ProjectRuntimeExportSettings
124+
{
125+
std::string GameName;
126+
uint32_t WindowWidth = 1920;
127+
uint32_t WindowHeight = 1080;
128+
bool Fullscreen = false;
129+
bool VSync = true;
130+
std::filesystem::path IconPath;
131+
AssetHandle IconHandle = 0;
132+
RuntimeExportTarget TargetConfig = RuntimeExportTarget::Release;
133+
};
134+
113135
struct ProjectConfig
114136
{
115137
std::string Name = "Untitled";
@@ -137,6 +159,7 @@ namespace Lux
137159
ProjectAudioSettings Audio;
138160
ProjectPhysicsSettings Physics;
139161
ProjectSceneRendererSettings SceneRenderer;
162+
ProjectRuntimeExportSettings RuntimeExport;
140163
};
141164

142165
class Project : public RefCounted
@@ -291,6 +314,7 @@ namespace Lux
291314

292315
static Ref<Project> New();
293316
static Ref<Project> Load(const std::filesystem::path& path);
317+
static Ref<Project> LoadRuntime(const std::filesystem::path& path, Ref<AssetPack> assetPack);
294318
static bool SaveActive(const std::filesystem::path& path);
295319

296320
private:

Core/Source/Lux/Project/ProjectRuntimeFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Lux
1111
struct FileHeader
1212
{
1313
char Header[4] = { 'L', 'P', 'R', 'J' };
14-
uint32_t Version = 8;
14+
uint32_t Version = 9;
1515
};
1616

1717
struct Audio

0 commit comments

Comments
 (0)