Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Sep 3, 2023
1 parent c82b184 commit 0aa3b5c
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 41 deletions.
12 changes: 10 additions & 2 deletions lib/Red/Utils/Resources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ inline void WaitForResource(const R& aResource, const W& aTimeout)
});

cv.wait_for(lock, aTimeout);
mutex.unlock();

if (!lock.owns_lock())
{
mutex.unlock();
}
}
}

Expand All @@ -103,7 +107,11 @@ inline void WaitForResources(const V<R, A...>& aResources, const W& aTimeout)
});

cv.wait_for(lock, aTimeout);
mutex.unlock();

if (!lock.owns_lock())
{
mutex.unlock();
}
}
}
}
15 changes: 15 additions & 0 deletions src/App/Extensions/GarmentOverride/Dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@ bool App::DynamicAppearanceController::IsDynamicValue(const std::string_view& aV
return aValue.starts_with(DynamicValueMarker);
}

bool App::DynamicAppearanceController::IsDynamicValue(const Red::StringView& aValue) const
{
return aValue.size > 0 && IsDynamicValue(aValue.data);
}

bool App::DynamicAppearanceController::IsDynamicValue(Red::CName aValue) const
{
return IsDynamicValue(aValue.ToString());
}

void App::DynamicAppearanceController::RegisterPath(Red::ResourcePath aPath, const char* aPathStr)
{
m_paths.insert_or_assign(aPath, aPathStr);
Expand All @@ -585,6 +595,11 @@ void App::DynamicAppearanceController::RegisterPath(Red::ResourcePath aPath, con
m_paths.insert_or_assign(aPath, aPathStr);
}

void App::DynamicAppearanceController::RegisterPath(Red::ResourcePath aPath, const Red::StringView& aPathStr)
{
m_paths.insert_or_assign(aPath, std::string(aPathStr.data, aPathStr.size));
}

const std::string& App::DynamicAppearanceController::GetPathStr(Red::ResourcePath aPath) const
{
if (!aPath)
Expand Down
4 changes: 4 additions & 0 deletions src/App/Extensions/GarmentOverride/Dynamic.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Red/EntityTemplate.hpp"
#include "Red/ResourcePath.hpp"

namespace App
{
Expand Down Expand Up @@ -57,10 +58,13 @@ class DynamicAppearanceController
[[nodiscard]] bool IsDynamicValue(const char* aValue) const;
[[nodiscard]] bool IsDynamicValue(const std::string& aValue) const;
[[nodiscard]] bool IsDynamicValue(const std::string_view& aValue) const;
[[nodiscard]] bool IsDynamicValue(const Red::StringView& aValue) const;
[[nodiscard]] bool IsDynamicValue(Red::CName aValue) const;

void RegisterPath(Red::ResourcePath aPath, const char* aPathStr);
void RegisterPath(Red::ResourcePath aPath, const std::string& aPathStr);
void RegisterPath(Red::ResourcePath aPath, const std::string_view& aPathStr);
void RegisterPath(Red::ResourcePath aPath, const Red::StringView& aPathStr);

bool SupportsDynamicAppearance(const Red::EntityTemplate* aTemplate);
void MarkDynamicAppearanceName(Red::CName& aAppearanceName, Red::Entity* aEntity);
Expand Down
10 changes: 6 additions & 4 deletions src/App/Extensions/GarmentOverride/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ constexpr auto EmptyAppearanceTags = {
std::pair(Red::CName("EmptyAppearance:Male"), "&Male"),
std::pair(Red::CName("EmptyAppearance:Female"), "&Female"),
};

const Red::ClassLocator<Red::CMesh> s_meshResourceType;
}

std::string_view App::GarmentOverrideModule::GetName()
Expand Down Expand Up @@ -550,7 +552,7 @@ void App::GarmentOverrideModule::OnReassembleAppearance(Red::Entity* aEntity, ui
}
}

void App::GarmentOverrideModule::OnCreateResourcePath(Red::ResourcePath* aPath, const std::string_view* aPathStr)
void App::GarmentOverrideModule::OnCreateResourcePath(Red::ResourcePath* aPath, const Red::StringView* aPathStr)
{
if (aPathStr && s_dynamicAppearance->IsDynamicValue(*aPathStr))
{
Expand Down Expand Up @@ -663,21 +665,21 @@ void App::GarmentOverrideModule::SelectDynamicAppearance(Core::SharedPtr<App::En
Red::EntityTemplate* aResource,
Red::TemplateAppearance*& aAppearance)
{
aEntityState->SelectTemplateAppearance(aSelector, aResource, aAppearance);
aEntityState->SelectDynamicAppearance(aSelector, aResource, aAppearance);
}

void App::GarmentOverrideModule::SelectDynamicAppearance(Core::SharedPtr<EntityState>& aEntityState,
DynamicAppearanceName& aSelector,
Red::AppearanceResource* aResource,
Red::Handle<Red::AppearanceDefinition>& aDefinition)
{
aEntityState->SelectConditionalAppearance(aSelector, aResource, aDefinition);
aEntityState->SelectDynamicAppearance(aSelector, aResource, aDefinition);
}

void App::GarmentOverrideModule::ApplyDynamicAppearance(Core::SharedPtr<EntityState>& aEntityState,
Red::DynArray<Red::Handle<Red::IComponent>>& aComponents)
{
aEntityState->ProcessConditionalComponents(aComponents);
aEntityState->ToggleConditionalComponents(aComponents);

for (auto& component : aComponents)
{
Expand Down
2 changes: 1 addition & 1 deletion src/App/Extensions/GarmentOverride/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GarmentOverrideModule : public ConfigurableUnitModule<GarmentOverrideUnit>
static void OnChangeItem(uintptr_t, Red::WeakHandle<Red::Entity>&, Red::GarmentItemChangeRequest&);
static void OnChangeCustomItem(uintptr_t, Red::WeakHandle<Red::Entity>&, Red::GarmentItemChangeCustomRequest&);
static void OnRemoveItem(uintptr_t, Red::WeakHandle<Red::Entity>&, Red::GarmentItemRemoveRequest&);
static void OnCreateResourcePath(Red::ResourcePath* aPath, const std::string_view* aPathStr);
static void OnCreateResourcePath(Red::ResourcePath* aPath, const Red::StringView* aPathStr);
static void OnRegisterPart(uintptr_t, Red::Handle<Red::EntityTemplate>& aPart,
Red::Handle<Red::ComponentsStorage>& aComponents,
Red::Handle<Red::AppearanceDefinition>& aAppearance);
Expand Down
21 changes: 10 additions & 11 deletions src/App/Extensions/GarmentOverride/States.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "States.hpp"
#include "Red/Entity.hpp"
#include "Red/Mesh.hpp"

namespace
{
Expand Down Expand Up @@ -392,8 +393,8 @@ void App::EntityState::UpdateDynamicAttributes()
m_dynamicAppearance->UpdateState(m_entity);
}

bool App::EntityState::SelectTemplateAppearance(App::DynamicAppearanceName& aSelector, Red::EntityTemplate* aResource,
Red::TemplateAppearance*& aAppearance)
bool App::EntityState::SelectDynamicAppearance(App::DynamicAppearanceName& aSelector, Red::EntityTemplate* aResource,
Red::TemplateAppearance*& aAppearance)
{
if (!aAppearance)
{
Expand Down Expand Up @@ -426,8 +427,8 @@ bool App::EntityState::SelectTemplateAppearance(App::DynamicAppearanceName& aSel
return true;
}

bool App::EntityState::SelectConditionalAppearance(DynamicAppearanceName& aSelector, Red::AppearanceResource* aResource,
Red::Handle<Red::AppearanceDefinition>& aDefinition)
bool App::EntityState::SelectDynamicAppearance(DynamicAppearanceName& aSelector, Red::AppearanceResource* aResource,
Red::Handle<Red::AppearanceDefinition>& aDefinition)
{
int8_t maxWeight = -1;
int8_t numCandidates = 0;
Expand Down Expand Up @@ -497,7 +498,7 @@ bool App::EntityState::SelectConditionalAppearance(DynamicAppearanceName& aSelec
return false;
}

void App::EntityState::ProcessConditionalComponents(Red::DynArray<Red::Handle<Red::IComponent>>& aComponents)
void App::EntityState::ToggleConditionalComponents(Red::DynArray<Red::Handle<Red::IComponent>>& aComponents)
{
Core::Map<Red::CName, WeightedComponentGroup> groups;

Expand Down Expand Up @@ -602,18 +603,16 @@ bool App::EntityState::ApplyDynamicAppearance(Red::Handle<Red::IComponent>& aCom
if (finalResource != originalResource && finalResource != componentWrapper.GetResource())
{
componentWrapper.SetResource(finalResource);
// componentWrapper.LoadResource();
}

if (aSetAppearance)
{
const auto originalAppearance = GetOriginalAppearance(componentWrapper);
const auto finalAppearance = m_dynamicAppearance->ResolveName(m_entity, aVariant, originalAppearance);

if (finalAppearance != originalAppearance && finalAppearance != componentWrapper.GetAppearance())
if (finalAppearance != originalAppearance && finalAppearance != componentWrapper.GetAppearanceName())
{
componentWrapper.SetAppearance(finalAppearance);
// componentWrapper.LoadAppearance();
componentWrapper.SetAppearanceName(finalAppearance);
}
}
}
Expand Down Expand Up @@ -658,7 +657,7 @@ bool App::EntityState::ApplyAppearanceOverride(Red::Handle<Red::IComponent>& aCo
const auto& activeVariant = resourceState->GetActiveVariantParts();
finalAppearance = m_dynamicAppearance->ResolveName(m_entity, activeVariant, finalAppearance);

return finalAppearance && component.SetAppearance(finalAppearance) && component.LoadAppearance();
return finalAppearance && component.SetAppearanceName(finalAppearance) && component.LoadAppearance();
}

bool App::EntityState::ApplyChunkMaskOverride(Red::Handle<Red::IComponent>& aComponent)
Expand Down Expand Up @@ -736,7 +735,7 @@ Red::CName App::EntityState::GetOriginalAppearance(ComponentWrapper& aComponent)
auto it = m_originalAppearances.find(componentId);

if (it == m_originalAppearances.end())
it = m_originalAppearances.emplace(componentId, aComponent.GetAppearance()).first;
it = m_originalAppearances.emplace(componentId, aComponent.GetAppearanceName()).first;

return it.value();
}
Expand Down
8 changes: 4 additions & 4 deletions src/App/Extensions/GarmentOverride/States.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ class EntityState
void AddOffsetOverride(uint64_t aHash, Red::ResourcePath aResourcePath, int32_t aOffset);
void RemoveOffsetOverrides(uint64_t aHash);

bool SelectTemplateAppearance(DynamicAppearanceName& aSelector, Red::EntityTemplate* aResource,
bool SelectDynamicAppearance(DynamicAppearanceName& aSelector, Red::EntityTemplate* aResource,
Red::TemplateAppearance*& aAppearance);
bool SelectConditionalAppearance(DynamicAppearanceName& aSelector, Red::AppearanceResource* aResource,
Red::Handle<Red::AppearanceDefinition>& aDefinition);
void ProcessConditionalComponents(Red::DynArray<Red::Handle<Red::IComponent>>& aComponents);
bool SelectDynamicAppearance(DynamicAppearanceName& aSelector, Red::AppearanceResource* aResource,
Red::Handle<Red::AppearanceDefinition>& aDefinition);
void ToggleConditionalComponents(Red::DynArray<Red::Handle<Red::IComponent>>& aComponents);
bool ApplyDynamicAppearance(Red::Handle<Red::IComponent>& aComponent);
bool ApplyDynamicAppearance(Red::Handle<Red::IComponent>& aComponent, Red::ResourcePath aResource);
void LinkComponentToPart(Red::Handle<Red::IComponent>& aComponent, Red::ResourcePath aResource);
Expand Down
20 changes: 10 additions & 10 deletions src/App/Extensions/GarmentOverride/Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ inline bool SetMorphComponentMeshPath(T* aComponent, Red::ResourcePath aPath)
}

template<class T>
inline Red::CName GetComponentAppearance(T* aComponent)
inline Red::CName GetComponentAppearanceName(T* aComponent)
{
return aComponent->meshAppearance;
}
Expand Down Expand Up @@ -206,26 +206,26 @@ Red::SharedPtr<Red::ResourceToken<Red::CMesh>> App::ComponentWrapper::LoadResour
return meshRef.token;
}

Red::CName App::ComponentWrapper::GetAppearance() const
Red::CName App::ComponentWrapper::GetAppearanceName() const
{
switch (m_type)
{
case ComponentType::MeshComponent:
return GetComponentAppearance(m_component.GetPtr<Red::ent::MeshComponent>());
return GetComponentAppearanceName(m_component.GetPtr<Red::ent::MeshComponent>());
case ComponentType::SkinnedMeshComponent:
return GetComponentAppearance(m_component.GetPtr<Red::ent::SkinnedMeshComponent>());
return GetComponentAppearanceName(m_component.GetPtr<Red::ent::SkinnedMeshComponent>());
case ComponentType::SkinnedClothComponent:
return GetComponentAppearance(m_component.GetPtr<Red::ent::SkinnedClothComponent>());
return GetComponentAppearanceName(m_component.GetPtr<Red::ent::SkinnedClothComponent>());
case ComponentType::MorphTargetSkinnedMeshComponent:
return GetComponentAppearance(m_component.GetPtr<Red::ent::MorphTargetSkinnedMeshComponent>());
return GetComponentAppearanceName(m_component.GetPtr<Red::ent::MorphTargetSkinnedMeshComponent>());
case ComponentType::Unknown:
break;
}

return {};
}

bool App::ComponentWrapper::SetAppearance(Red::CName aAppearance) const
bool App::ComponentWrapper::SetAppearanceName(Red::CName aAppearance) const
{
switch (m_type)
{
Expand Down Expand Up @@ -253,19 +253,19 @@ bool App::ComponentWrapper::LoadAppearance() const
{
case ComponentType::MeshComponent:
meshRef = GetComponentMesh(m_component.GetPtr<Red::ent::MeshComponent>());
meshAppName = GetComponentAppearance(m_component.GetPtr<Red::ent::MeshComponent>());
meshAppName = GetComponentAppearanceName(m_component.GetPtr<Red::ent::MeshComponent>());
break;
case ComponentType::SkinnedMeshComponent:
meshRef = GetComponentMesh(m_component.GetPtr<Red::ent::SkinnedMeshComponent>());
meshAppName = GetComponentAppearance(m_component.GetPtr<Red::ent::SkinnedMeshComponent>());
meshAppName = GetComponentAppearanceName(m_component.GetPtr<Red::ent::SkinnedMeshComponent>());
break;
case ComponentType::SkinnedClothComponent:
// meshRef = GetClothComponentMesh(m_component.GetPtr<Red::ent::SkinnedClothComponent>());
// meshAppName = GetComponentAppearance(m_component.GetPtr<Red::ent::SkinnedClothComponent>());
break;
case ComponentType::MorphTargetSkinnedMeshComponent:
meshRef = GetMorphComponentMesh(m_component.GetPtr<Red::ent::MorphTargetSkinnedMeshComponent>());
meshAppName = GetComponentAppearance(m_component.GetPtr<Red::ent::MorphTargetSkinnedMeshComponent>());
meshAppName = GetComponentAppearanceName(m_component.GetPtr<Red::ent::MorphTargetSkinnedMeshComponent>());
break;
case ComponentType::Unknown:
break;
Expand Down
4 changes: 2 additions & 2 deletions src/App/Extensions/GarmentOverride/Wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ComponentWrapper
bool SetResource(Red::ResourcePath aPath) const;
[[nodiscard]] Red::SharedPtr<Red::ResourceToken<Red::CMesh>> LoadResource(bool aWait = false) const;

[[nodiscard]] Red::CName GetAppearance() const;
bool SetAppearance(Red::CName aAppearance) const;
[[nodiscard]] Red::CName GetAppearanceName() const;
bool SetAppearanceName(Red::CName aAppearance) const;
bool LoadAppearance() const;

[[nodiscard]] uint64_t GetChunkMask() const;
Expand Down
2 changes: 1 addition & 1 deletion src/App/Project.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ constexpr auto Author = "psiberx";
constexpr auto NameW = L"ArchiveXL";
constexpr auto AuthorW = L"psiberx";

constexpr auto Version = semver::from_string_noexcept("1.5.10").value();
constexpr auto Version = semver::from_string_noexcept("1.5.11").value();
}
8 changes: 4 additions & 4 deletions src/App/Version.rc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#define VER_PRODUCTVERSION 1,5,10,0
#define VER_FILEVERSION 1,5,10,2308171907
#define VER_PRODUCTVERSION 1,5,11,0
#define VER_FILEVERSION 1,5,11,2309031253

#define VER_PRODUCTNAME_STR "ArchiveXL\0"
#define VER_PRODUCTVERSION_STR "1.5.10\0"
#define VER_FILEVERSION_STR "1.5.10.2308171907\0"
#define VER_PRODUCTVERSION_STR "1.5.11\0"
#define VER_FILEVERSION_STR "1.5.11.2309031253\0"

1 VERSIONINFO
FILEVERSION VER_FILEVERSION
Expand Down
11 changes: 10 additions & 1 deletion src/Red/ResourcePath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
#include "Core/Raw.hpp"
#include "Red/Addresses.hpp"

namespace Red
{
struct StringView
{
const char* data;
uint32_t size;
};
}

namespace Raw::ResourcePath
{
constexpr auto Create = Core::RawFunc<
/* addr = */ Red::Addresses::ResourcePath_Create,
/* type = */ Red::ResourcePath* (*)(Red::ResourcePath* aOut, const std::string_view* aPath)>();
/* type = */ Red::ResourcePath* (*)(Red::ResourcePath* aOut, const Red::StringView* aPath)>();
}
1 change: 1 addition & 0 deletions src/pch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <RED4ext/Scripting/Natives/Generated/IRenderResourceBlob.hpp>
#include <RED4ext/Scripting/Natives/Generated/ITexture.hpp>
#include <RED4ext/Scripting/Natives/Generated/JsonResource.hpp>
#include <RED4ext/Scripting/Natives/Generated/MaterialParameterInstance.hpp>
#include <RED4ext/Scripting/Natives/Generated/MorphTargetMesh.hpp>
#include <RED4ext/Scripting/Natives/Generated/anim/LipsyncMapping.hpp>
#include <RED4ext/Scripting/Natives/Generated/appearance/AppearanceDefinition.hpp>
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set_xmakever("2.5.9")

set_project("ArchiveXL")
set_version("1.5.10", {build = "%y%m%d%H%M"})
set_version("1.5.11", {build = "%y%m%d%H%M"})

set_arch("x64")
set_languages("cxx20", "cxx2a")
Expand Down

0 comments on commit 0aa3b5c

Please sign in to comment.