Skip to content

Commit 1373b8c

Browse files
author
Caerind
committed
Update AssetsPath detection to find examples folder + minor fixes
1 parent 6cdbd9f commit 1373b8c

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

examples/inputs.data

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<Buttons type="std::vector<en::EventSystem::EventButton>" hash="616188669">
3+
<size>0</size>
4+
</Buttons>
5+
<Axes type="std::vector<en::EventSystem::EventAxis>" hash="1399036478">
6+
<size>0</size>
7+
</Axes>

examples/resources.data

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<Resources type="std::vector<en::ResourceInfo>" hash="1530161136">
3+
<size>0</size>
4+
</Resources>

examples/worlds.data

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<Worlds type="std::vector<std::string>" hash="1731526995">
3+
<size>0</size>
4+
</Worlds>

src/Enlivengine/Core/ComponentFactory.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ bool ComponentFactory::Register()
6060
{
6161
if constexpr (Traits::IsEmpty<T>::value)
6262
{
63+
ENLIVE_UNUSED(entity);
6364
if (objectEditor.BeginClass(TypeInfo<T>::GetName(), TypeInfo<T>::GetName(), TypeInfo<T>::GetHash()))
6465
{
6566
objectEditor.EndClass();
@@ -92,6 +93,7 @@ bool ComponentFactory::Register()
9293
{
9394
if constexpr (Traits::IsEmpty<T>::value)
9495
{
96+
ENLIVE_UNUSED(entity);
9597
if (serializer.BeginClass(TypeInfo<T>::GetName(), TypeInfo<T>::GetName(), TypeInfo<T>::GetHash()))
9698
{
9799
return serializer.EndClass();

src/Enlivengine/Resources/PathManager.cpp

+28-10
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ const std::string& PathManager::GetExecutablePath()
4141

4242
bool PathManager::AutoDetectAssetsPath()
4343
{
44-
for (U32 i = 0; i < 5; ++i)
44+
constexpr U32 kScanDepth = 5;
45+
46+
std::string backfolder = "";
47+
for (U32 i = 0; i < kScanDepth; ++i)
4548
{
46-
std::string backfolder = "";
47-
for (U32 j = 0; j < i; ++j)
49+
if (i > 0)
4850
{
4951
backfolder += "../";
5052
}
@@ -56,15 +58,31 @@ bool PathManager::AutoDetectAssetsPath()
5658
return true;
5759
}
5860
}
59-
60-
#if defined(ENLIVE_RELEASE)
61-
std::filesystem::path tempAssetsPath = std::filesystem::path(GetCurrentPath() + "Assets");
62-
if (std::filesystem::exists(tempAssetsPath))
61+
62+
#if defined(ENLIVE_TOOL)
63+
// Start backward to get the examples at the root instead of the one in the build folder
64+
for (I32 i = static_cast<I32>(kScanDepth); i > 0; --i)
6365
{
64-
SetAssetsPath(tempAssetsPath.generic_string() + "/");
65-
return true;
66+
if (i < 5)
67+
{
68+
backfolder.resize(backfolder.size() - 3);
69+
}
70+
71+
std::filesystem::path tempCurrentExamplesPath = std::filesystem::path(GetCurrentPath() + backfolder + "examples").lexically_normal();
72+
if (std::filesystem::exists(tempCurrentExamplesPath))
73+
{
74+
SetAssetsPath(tempCurrentExamplesPath.generic_string() + "/");
75+
return true;
76+
}
77+
78+
std::filesystem::path tempExecutableExamplesPath = std::filesystem::path(GetExecutablePath() + backfolder + "examples").lexically_normal();
79+
if (std::filesystem::exists(tempExecutableExamplesPath))
80+
{
81+
SetAssetsPath(tempExecutableExamplesPath.generic_string() + "/");
82+
return true;
83+
}
6684
}
67-
#endif // ENLIVE_RELEASE
85+
#endif // ENLIVE_TOOL
6886

6987
return false;
7088
}

src/Enlivengine/Utils/Hash.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class Hash
2020
{
2121
if (str != nullptr)
2222
{
23-
U32 h = 89;
23+
U32 h = 5381;
2424
while (*str != 0)
2525
{
26-
h = h * 33 + (*str++);
26+
h = h * 5 + (*str++);
2727
}
2828
return h;
2929
}

0 commit comments

Comments
 (0)