Skip to content

Commit

Permalink
feat: hitbox bvh mesh cache initialization is now multi-threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan committed Feb 17, 2024
1 parent babe09d commit d23dfdb
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 146 deletions.
2 changes: 1 addition & 1 deletion build_scripts/scripts/external_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
get_submodule("networkmanager","https://github.com/Silverlan/networkmanager.git","68d2f5c")
get_submodule("panima","https://github.com/Silverlan/panima.git","9a32d345bdee87f5872e9d1b65de5772db996df3")
get_submodule("prosper","https://github.com/Silverlan/prosper.git","f405b5114f8abaf30ed5d92604e0b14854606cb1")
get_submodule("sharedutils","https://github.com/Silverlan/sharedutils.git","b308d6261cce0ebb9b8f44be17e72ab917992b3f")
get_submodule("sharedutils","https://github.com/Silverlan/sharedutils.git","9168116578a13b79faf24171322f3f8f9c23c931")
get_submodule("util_bsp","https://github.com/Silverlan/util_bsp.git","3c11053")
get_submodule("util_formatted_text","https://github.com/Silverlan/util_formatted_text.git","3bd9e2de37d0cb14bf8228fde5e25c97698e927b")
get_submodule("util_image","https://github.com/Silverlan/util_image.git","7a66f93")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "pragma/clientdefinitions.h"
#include <pragma/entities/components/base_bvh_component.hpp>
#include "pragma/entities/components/hitbox_mesh_bvh_builder.hpp"

class Model;
class ModelSubMesh;
Expand Down Expand Up @@ -40,14 +41,23 @@ namespace pragma {
std::unordered_map<Uuid, std::shared_ptr<MeshHitboxBvhCache>> meshCache;
};
struct DLLCLIENT ModelHitboxBvhCache {
std::shared_future<void> task;
std::atomic<bool> complete = false;

std::unordered_map<BoneId, std::shared_ptr<BoneHitboxBvhCache>> boneCache;
};
struct DLLCLIENT HitboxBvhCache {
using ModelName = std::string;
HitboxBvhCache(Game &game);
~HitboxBvhCache();
ModelHitboxBvhCache *GetModelCache(const ModelName &mdlName);
ModelHitboxBvhCache &AddModelCache(const ModelName &mdlName);
std::shared_future<void> GenerateModelCache(const ModelName &mdlName, Model &mdl);
private:
void PrepareModel(Model &mdl);
void InitializeModelHitboxBvhCache(Model &mdl, const HitboxMeshBvhBuildTask &buildTask, ModelHitboxBvhCache &mdlHbBvhCache);
std::unordered_map<ModelName, std::shared_ptr<ModelHitboxBvhCache>> m_modelBvhCache;
Game &m_game;
pragma::bvh::HitboxMeshBvhBuilder m_builder;
};
};
class DLLCLIENT CHitboxBvhComponent final : public BaseEntityComponent {
Expand All @@ -70,19 +80,19 @@ namespace pragma {
virtual void OnRemove() override;
virtual void OnEntitySpawn() override;
void InitializeBvh();
void UpdateTest();
bool IntersectionTest(const Vector3 &origin, const Vector3 &dir, float minDist, float maxDist, pragma::bvh::HitInfo &outHitInfo, const bvh::DebugDrawInfo *debugDrawInfo = nullptr);
void UpdateHitboxBvh();
void DebugDrawHitboxMeshes(BoneId boneId, float duration = 12.f) const;
bvh::HitboxBvhCache &GetGlobalBvhCache() const;
private:
void Reset();
void WaitForHitboxBvhUpdate();
void DebugDraw();
void OnModelChanged();
void InitializeHitboxBvh();
bool InitializeModel();
void InitializeHitboxMeshCache();
void InitializeHitboxMeshBvhs();
std::shared_future<void> m_hitboxMeshCacheTask;
std::unordered_map<BoneId, std::vector<std::shared_ptr<bvh::MeshHitboxBvhCache>>> m_hitboxMeshBvhCaches;
std::shared_ptr<ObbBvhTree> m_hitboxBvh;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace pragma::bvh {
struct MeshBvhTree;
class DLLCLIENT HitboxMeshBvhBuildTask {
public:
using BoneName = std::string;
struct DLLCLIENT BoneMeshInfo {
std::string meshUuid;
std::shared_ptr<ModelSubMesh> subMesh;
Expand All @@ -34,8 +35,8 @@ namespace pragma::bvh {

HitboxMeshBvhBuildTask(BS::thread_pool &threadPool);
bool Build(Model &mdl);
const std::unordered_map<BoneName, std::vector<std::shared_ptr<BoneMeshInfo>>> &GetResult() const { return m_boneMeshMap; }
private:
using BoneName = std::string;
bool Build(Model &mdl, BoneId boneId, const Hitbox &hitbox, const LODInfo &lodInfo);
void Serialize(Model &mdl);
void BuildHitboxMesh(Model &mdl, ModelSubMesh &subMesh);
Expand All @@ -48,7 +49,8 @@ namespace pragma::bvh {
class DLLCLIENT HitboxMeshBvhBuilder {
public:
HitboxMeshBvhBuilder();
void BuildModel(Model &mdl);
HitboxMeshBvhBuildTask BuildModel(Model &mdl);
BS::thread_pool &GetThreadPool() { return m_threadPool; }
private:
BS::thread_pool m_threadPool;
};
Expand Down
Loading

0 comments on commit d23dfdb

Please sign in to comment.