Skip to content

Commit

Permalink
Fixed a bunch of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Mar 26, 2024
1 parent 5a3604d commit 74d09cc
Show file tree
Hide file tree
Showing 34 changed files with 287 additions and 124 deletions.
4 changes: 2 additions & 2 deletions Engine/Scripts/Volt-ScriptCore.dll
Git LFS file not shown
4 changes: 2 additions & 2 deletions Engine/Scripts/Volt-ScriptCore.pdb
Git LFS file not shown
1 change: 1 addition & 0 deletions Engine/Volt-ScriptCore/Source/Volt/Amp/Amp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static void StopAllEvents()

public class AudioSourceComponent : Component
{
public override string GUID { get => "{06A69F94-BB09-4A3A-AF17-C9DA7D552BFE}"; }

#region Event
public uint PlayEvent(string aEventName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Volt
{
public class NetActorComponent : Component
{
public override string GUID { get => "{D5A9E480-C9D6-473C-B29E-9FE812320643}"; }

}
}
3 changes: 2 additions & 1 deletion Engine/Volt-ScriptCore/Source/Volt/Scene/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum VideoStatus : uint
public abstract class Component
{
public Entity entity { get; internal set; }
public virtual string GUID { get; set; }
// #TODO_Ivar: Create actual guid class instead and use to communicate components
public abstract string GUID { get; }
}

public class TransformComponent : Component
Expand Down
3 changes: 3 additions & 0 deletions Engine/Volt-ScriptCore/Source/Volt/Scene/LightComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public class SpotLightComponent : Component
{
public override string GUID { get => "{D35F915F-53E5-4E15-AE5B-769F4D79B6F8}"; }
public Vector3 color
{
get
Expand Down Expand Up @@ -33,6 +34,8 @@ public float intensity

public class PointLightComponent : Component
{
public override string GUID { get => "{A30A8848-A30B-41DD-80F9-4E163C01ABC2}"; }

public Vector3 color
{
get
Expand Down
106 changes: 55 additions & 51 deletions Volt/Navigation/src/Navigation/Core/NavigationSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,76 +37,80 @@ namespace Volt

bool NavigationSystem::OnAppUpdateEvent(Volt::AppUpdateEvent& e)
{
VT_PROFILE_FUNCTION()
if (myNavMesh && myActiveScene && myActiveScene->IsPlaying())
VT_PROFILE_FUNCTION();
if (myNavMesh && myActiveScene && myActiveScene->IsPlaying())
{
auto& crowd = myNavMesh->GetCrowd();
if (!crowd)
{
auto& crowd = myNavMesh->GetCrowd();
return false;
}

auto& agentMap = crowd->GetAgentMap();
auto& agentMap = crowd->GetAgentMap();
{
VT_PROFILE_SCOPE("Remove old agents");

for (auto [entityId, agentId] : agentMap)
{
VT_PROFILE_SCOPE("Remove old agents");
auto entity = myActiveScene->GetEntityFromUUID(entityId);

for (auto [entityId, agentId] : agentMap)
if (!entity || !entity.HasComponent<Volt::NavAgentComponent>())
{
auto entity = myActiveScene->GetEntityFromUUID(entityId);

if (!entity || !entity.HasComponent<Volt::NavAgentComponent>())
{
crowd->RemoveAgent(entity);
}
crowd->RemoveAgent(entity);
}

if (myEntityIdToTargetPosMap.contains(entityId))
{
myEntityIdToTargetPosMap.erase(entityId);
}
if (myEntityIdToTargetPosMap.contains(entityId))
{
myEntityIdToTargetPosMap.erase(entityId);
}
}
}

{
VT_PROFILE_SCOPE("Add new agents & disable movement on inactive agents");

auto& registry = myActiveScene->GetRegistry();

auto view = registry.view<const Volt::NavAgentComponent>();
view.each([&](const entt::entity id, const Volt::NavAgentComponent& comp)
{
VT_PROFILE_SCOPE("Add new agents & disable movement on inactive agents");
auto entity = Volt::Entity(id, myActiveScene);

auto& registry = myActiveScene->GetRegistry();
crowd->SetAgentPosition(entity, entity.GetPosition());

auto view = registry.view<const Volt::NavAgentComponent>();
view.each([&](const entt::entity id, const Volt::NavAgentComponent& comp)
if (!crowd->GetAgentMap().contains(entity.GetID()))
{
auto entity = Volt::Entity(id, myActiveScene);

crowd->SetAgentPosition(entity, entity.GetPosition());

if (!crowd->GetAgentMap().contains(entity.GetID()))
{
crowd->AddAgent(entity);
crowd->UpdateAgentParams(entity);
}
else if (!comp.active)
{
PauseAgent(entity, e.GetTimestep());
}
else if (comp.active)
{
UnpauseAgent(entity);
}
});
}
crowd->AddAgent(entity);
crowd->UpdateAgentParams(entity);
}
else if (!comp.active)
{
PauseAgent(entity, e.GetTimestep());
}
else if (comp.active)
{
UnpauseAgent(entity);
}
});
}

{
VT_PROFILE_SCOPE("Detour crowd update");
myNavMesh->Update(e.GetTimestep());
}
{
VT_PROFILE_SCOPE("Detour crowd update");
myNavMesh->Update(e.GetTimestep());
}

{
VT_PROFILE_SCOPE("Update agent positions");
for (auto [entityId, agentId] : agentMap)
{
VT_PROFILE_SCOPE("Update agent positions");
for (auto [entityId, agentId] : agentMap)
Volt::Entity entity = myActiveScene->GetEntityFromUUID(entityId);
if (entity.GetComponent<NavAgentComponent>().active)
{
Volt::Entity entity = myActiveScene->GetEntityFromUUID(entityId);
if (entity.GetComponent<NavAgentComponent>().active)
{
SyncDetourPosition(entity, e.GetTimestep());
}
SyncDetourPosition(entity, e.GetTimestep());
}
}
}
}

return false;
}
Expand Down Expand Up @@ -220,7 +224,7 @@ namespace Volt
VT_CORE_ERROR("Could not initialize agents because active scene is null");
return;
}

auto& registry = myActiveScene->GetRegistry();
auto view = registry.view<const Volt::NavAgentComponent>();
view.each([&](const entt::entity id, const Volt::NavAgentComponent& comp)
Expand Down
24 changes: 17 additions & 7 deletions Volt/Nexus/src/Nexus/Core/Packet/Packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ namespace Nexus
}

size_t i = packet.body.size();
packet.body.resize(packet.body.size() + data.size());
packet.body.resize(packet.body.size() + data.size() + sizeof(size_t));

memcpy(packet.body.data() + i, data.data(), data.size());

const size_t strSize = data.size();
memcpy(packet.body.data() + i + data.size(), &strSize, sizeof(size_t));
//packet << data.size();
return packet;
}
Expand All @@ -130,16 +134,22 @@ namespace Nexus
}
[[nodiscard]] std::string GetString(int len = 0)
{
if (len == 0) len = (int32_t)body.size();
std::string data;
if (len > body.size())

size_t strSize = 0;
memcpy_s(&strSize, sizeof(size_t), body.data() + body.size() - sizeof(size_t), sizeof(size_t));

if (body.size() < strSize)
{
// Log error
return data;
}
data.resize(len);
memcpy_s(data.data(), data.size(), body.data() + body.size() - len, len);
body.resize(body.size() - len);

body.resize(body.size() - sizeof(size_t));

data.resize(strSize);

memcpy_s(data.data(), data.size(), body.data() + body.size() - strSize, strSize);
body.resize(body.size() - strSize);
return data;
}
};
Expand Down
24 changes: 0 additions & 24 deletions Volt/Sandbox/src/Sandbox/AssetFileWatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ void Sandbox::CreateModifiedWatch()
break;
}
});

myFileChangeQueue.emplace_back([&]()
{
auto assetBrowser = EditorLibrary::Get<AssetBrowserPanel>();
assetBrowser->Reload();
});
});
}

Expand All @@ -135,12 +129,6 @@ void Sandbox::CreateDeleteWatch()
}
}
});

myFileChangeQueue.emplace_back([&]()
{
auto assetBrowser = EditorLibrary::Get<AssetBrowserPanel>();
assetBrowser->Reload();
});
});
}

Expand All @@ -149,12 +137,6 @@ void Sandbox::CreateAddWatch()
myFileWatcher->AddCallback(efsw::Actions::Add, [&](const std::filesystem::path newPath, const std::filesystem::path oldPath)
{
std::scoped_lock lock(myFileWatcherMutex);

myFileChangeQueue.emplace_back([&]()
{
auto assetBrowser = EditorLibrary::Get<AssetBrowserPanel>();
assetBrowser->Reload();
});
});
}

Expand All @@ -174,11 +156,5 @@ void Sandbox::CreateMovedWatch()
Volt::AssetManager::Get().MoveAssetInRegistry(oldPath, newPath);
}
});

myFileChangeQueue.emplace_back([&]()
{
auto assetBrowser = EditorLibrary::Get<AssetBrowserPanel>();
//assetBrowser->Reload();
});
});
}
21 changes: 8 additions & 13 deletions Volt/Sandbox/src/Sandbox/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ void Sandbox::OnAttach()
void Sandbox::CreateWatches()
{
myFileWatcher->AddWatch(Volt::ProjectManager::GetEngineDirectory());
myFileWatcher->AddWatch(Volt::ProjectManager::GetProjectDirectory());
myFileWatcher->AddWatch(Volt::ProjectManager::GetAssetsDirectory());
myFileWatcher->AddWatch(Volt::ProjectManager::GetMonoBinariesDirectory());

CreateModifiedWatch();
CreateDeleteWatch();
Expand Down Expand Up @@ -465,18 +466,7 @@ void Sandbox::OnEvent(Volt::Event& e)
return;
}

switch (mySceneState)
{
case SceneState::Edit:
break;
case SceneState::Play:
myRuntimeScene->OnEvent(e);
break;
case SceneState::Pause:
break;
case SceneState::Simulating:
break;
}
myRuntimeScene->OnEvent(e);
}

void Sandbox::OnScenePlay()
Expand Down Expand Up @@ -814,6 +804,11 @@ bool Sandbox::OnUpdateEvent(Volt::AppUpdateEvent& e)
f();
}

if (!myFileChangeQueue.empty())
{
EditorLibrary::Get<AssetBrowserPanel>()->Reload();
}

myFileChangeQueue.clear();

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void ComponentPropertyUtility::Initialize()
RegisterMonoPropertyType<glm::vec2>(s_monoPropertyFunctions);
RegisterMonoPropertyType<glm::vec3>(s_monoPropertyFunctions);
RegisterMonoPropertyType<glm::vec4>(s_monoPropertyFunctions);
RegisterMonoPropertyType<glm::quat>(s_monoPropertyFunctions);

RegisterMonoPropertyType<std::string>(s_monoPropertyFunctions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref<AssetBrowser::DirectoryItem> AssetDirectoryProcessor::ProcessDirectories(con
Ref<AssetBrowser::DirectoryItem> dirData = CreateRef<AssetBrowser::DirectoryItem>(m_selectionManager.Get(), relPath);
directoryItems[relPath] = dirData;
directoryItems[relPath.parent_path()]->subDirectories.emplace_back(dirData);
dirData->parentDirectory = directoryItems[relPath.parent_path()].get();
}
else
{
Expand Down
9 changes: 8 additions & 1 deletion Volt/Sandbox/src/Sandbox/Window/SceneViewPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,14 @@ void SceneViewPanel::DrawEntity(Volt::Entity entity, const std::string& filter)
{
for (const auto& child : children)
{
DrawEntity(m_scene->GetEntityFromUUID(child), filter);
auto childEnt = m_scene->GetEntityFromUUID(child);
if (!childEnt)
{
// #TODO_Ivar: Maybe display invalid entity somehow?
continue;
}

DrawEntity(childEnt, filter);
}

ImGui::TreePop();
Expand Down
Loading

0 comments on commit 74d09cc

Please sign in to comment.