Skip to content

Commit

Permalink
Updated src
Browse files Browse the repository at this point in the history
  • Loading branch information
expired6978 committed Jul 21, 2021
1 parent c8cf9cb commit 76768ff
Show file tree
Hide file tree
Showing 10 changed files with 922 additions and 88 deletions.
16 changes: 7 additions & 9 deletions f4ee/BodyMorphInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void F4EEBodyGenUpdate::Run()
{
if(equipData[s])
{
for(UInt32 i = 0; i < 31; ++i)
for(UInt32 i = 0; i < 32; ++i)
{
NiPointer<NiAVObject> slotNode(equipData[s]->slots[i].node);
if(slotNode && g_bodyMorphInterface.IsNodeMorphable(slotNode))
Expand Down Expand Up @@ -606,6 +606,8 @@ bool BodyMorphInterface::ApplyMorphsToShape(Actor * actor, const MorphableShapeP
MorphApplicator morpher(geometry, newBlock, newBlock, [&](std::vector<Morpher::Vector3> & verts)
{
SimpleLocker locker(&m_morphLock);

actorMorphs->Lock();
for(auto & actorMorph : *actorMorphs)
{
float effectiveValue = actorMorph.second->GetEffectiveValue();
Expand All @@ -621,6 +623,7 @@ bool BodyMorphInterface::ApplyMorphsToShape(Actor * actor, const MorphableShapeP
_WARNING("%s - Shape: %s Morph: %s contained out of bounds vertices\t[%s]", __FUNCTION__, morphableShape->shapeName.c_str(), actorMorph.first->c_str(), morphableShape->morphPath.c_str());
}
}
actorMorphs->Unlock();
});

if(geomData) {
Expand Down Expand Up @@ -742,7 +745,8 @@ void BodyMorphInterface::GetMorphs(Actor * actor, bool isFemale, std::vector<BSF
auto it = m_morphMap[isFemale ? 1 : 0].find(actor ? actor->formID : 0);
if(it != m_morphMap[isFemale ? 1 : 0].end()) {
for(auto & morph : *it->second) {
morphs.push_back(morph.first->c_str());
if(morph.first)
morphs.push_back(morph.first->c_str());
}
}
}
Expand Down Expand Up @@ -816,7 +820,6 @@ float BodyMorphInterface::GetMorph(Actor * actor, bool isFemale, const BSFixedSt

float UserValues::GetValue(BGSKeyword * keyword)
{
SimpleLocker locker(&m_morphLock);
auto it = find(keyword ? keyword->formID : 0);
if(it != end()) {
return it->second;
Expand All @@ -827,8 +830,6 @@ float UserValues::GetValue(BGSKeyword * keyword)

void UserValues::SetValue(BGSKeyword * keyword, float value)
{
SimpleLocker locker(&m_morphLock);

UInt32 formId = keyword ? keyword->formID : 0;

// Erase the value if it is present and we are putting zero in
Expand All @@ -844,7 +845,6 @@ void UserValues::SetValue(BGSKeyword * keyword, float value)

void UserValues::RemoveKeyword(BGSKeyword * keyword)
{
SimpleLocker locker(&m_morphLock);
auto it = find(keyword ? keyword->formID : 0);
if(it != end()) {
erase(it);
Expand All @@ -853,9 +853,7 @@ void UserValues::RemoveKeyword(BGSKeyword * keyword)

float UserValues::GetEffectiveValue()
{
SimpleLocker locker(&m_morphLock);

auto maxIt = std::max_element(begin(), end());
auto maxIt = std::max_element(begin(), end(), [](const std::pair<UInt32,float>& a, const std::pair<UInt32, float>& b) { return a.second < b.second; });
if(maxIt != end()) {
return maxIt->second;
}
Expand Down
11 changes: 4 additions & 7 deletions f4ee/BodyMorphInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,8 @@ class UserValues : public std::unordered_map<UInt32, float>

void Revert()
{
SimpleLocker locker(&m_morphLock);
clear();
}

protected:
SimpleLock m_morphLock;
};
typedef std::shared_ptr<UserValues> UserValuesPtr;

Expand All @@ -137,6 +133,9 @@ class MorphValueMap : public std::unordered_map<StringTableItem, UserValuesPtr>
void RemoveMorphsByName(const BSFixedString & morph);
void RemoveMorphsByKeyword(BGSKeyword * keyword);

void Lock() { m_morphLock.Lock(); }
void Unlock() { m_morphLock.Release(); }

void Revert()
{
SimpleLocker locker(&m_morphLock);
Expand Down Expand Up @@ -199,9 +198,7 @@ class BodyMorphProcessor : public BSModelDB::BSModelProcessor
BSModelDB::BSModelProcessor * m_oldProcessor;
};

class BodyMorphInterface : public BSTEventSink<TESObjectLoadedEvent>,
public BSTEventSink<TESLoadGameEvent>,
public BSTEventSink<TESInitScriptEvent>
class BodyMorphInterface
{
public:
BodyMorphInterface() : m_totalMemory(0), m_memoryLimit(0x80000000LL) { } // 2GB
Expand Down
13 changes: 7 additions & 6 deletions f4ee/CharGenInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ DWORD CharGenInterface::LoadPreset(const std::string & filePath)
npc->morphSetValue = new tArray<float>();
if(npc->morphSetValue) {
npc->morphSetValue->Clear();
npc->morphSetValue->Allocate(fValues.size());
for(int i = 0; i < fValues.size(); i++)
npc->morphSetValue->Allocate(5);
size_t elements = (std::min<size_t>)(5, fValues.size());
for(size_t i = 0; i < elements; i++)
{
(*npc->morphSetValue)[i] = fValues.at(i);
}
Expand Down Expand Up @@ -1075,7 +1076,7 @@ void CharGenInterface::UnlockHeadParts()
});
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
_MESSAGE("Completed head part unlock of %d parts in %f seconds", total, elapsed_seconds.count());
_MESSAGE("Completed head part unlock of %d parts in %f seconds", total.load(), elapsed_seconds.count());
}

void CharGenInterface::UnlockTints()
Expand Down Expand Up @@ -1111,7 +1112,7 @@ void CharGenInterface::UnlockTints()
});
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
_MESSAGE("Completed tint unlock of %d tints in %f seconds", total, elapsed_seconds.count());
_MESSAGE("Completed tint unlock of %d tints in %f seconds", total.load(), elapsed_seconds.count());
}

void CharGenInterface::ProcessHairColor(NiAVObject * node, BGSColorForm * colorForm, BSLightingShaderMaterialBase * shaderMaterial)
Expand Down Expand Up @@ -1252,8 +1253,8 @@ bool CharGenInterface::LoadHairColorData(const std::string & filePath, const Mod
{
UInt32 formId = 0;
sscanf_s(value.asCString(), "%X", &formId);
UInt32 modIndex = modInfo->modIndex;
formId |= modIndex << 24;

formId |= modInfo->GetPartialIndex() << (modInfo->IsLight() ? 16 : 24);

TESForm * form = LookupFormByID(formId);
if(!form) {
Expand Down
18 changes: 9 additions & 9 deletions f4ee/Morpher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "half.hpp"
#include "f4se/BSGeometry.h"

float round(float num)
float round_v(float num)
{
return (num > 0.0) ? floor(num + 0.5) : ceil(num - 0.5);
}
Expand Down Expand Up @@ -100,19 +100,19 @@ MorphApplicator::MorphApplicator(BSTriShape * _geometry, UInt8 * srcBlock, UInt8

if(vertexDesc & BSTriShape::kFlag_Normals)
{
*(SInt8*)vBegin = (UInt8)round((((rawNormals[i].x + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round((((rawNormals[i].y + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round((((rawNormals[i].z + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawNormals[i].x + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawNormals[i].y + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawNormals[i].z + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;

*(SInt8*)vBegin = (UInt8)round((((rawBitangents[i].y + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawBitangents[i].y + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;

if(vertexDesc & BSTriShape::kFlag_Tangents)
{
*(SInt8*)vBegin = (UInt8)round((((rawTangents[i].x + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round((((rawTangents[i].y + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round((((rawTangents[i].z + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawTangents[i].x + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawTangents[i].y + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawTangents[i].z + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;

*(SInt8*)vBegin = (UInt8)round((((rawBitangents[i].z + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
*(SInt8*)vBegin = (UInt8)round_v((((rawBitangents[i].z + 1.0f) / 2.0f) * 255.0f)); vBegin += 1;
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions f4ee/ScaleformNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,24 +582,24 @@ void F4EEScaleform_GetEquippedItems::Invoke(Args * args)
if(characterCreation) {
Actor * actor = characterCreation->actor;

static std::unordered_map<TESForm*, std::pair<SInt32, UInt8>> stackList;
std::unordered_map<TESForm*, std::pair<SInt32, UInt8>> stackList;
auto inventory = actor->inventoryList;
if(inventory)
{
inventory->inventoryLock.Lock();
inventory->inventoryLock.LockForRead();
for(UInt32 i = 0; i < inventory->items.count; i++)
{
SInt32 s = 0;
inventory->items[i].stack->Visit([&](BGSInventoryItem::Stack * stack)
{
if(stack->flags & BGSInventoryItem::Stack::kFlagEquipped) {
stackList.emplace(inventory->items[i].form, std::make_pair(s, stack->flags & 0xF));
stackList.emplace(inventory->items[i].form, std::make_pair(s, stack->flags & 0x7));
}
s++;
return true;
});
}
inventory->inventoryLock.Release();
inventory->inventoryLock.UnlockRead();
}
if(!stackList.empty())
{
Expand Down Expand Up @@ -627,7 +627,7 @@ void F4EEScaleform_UnequipItems::Invoke(Args * args)
Actor * actor = characterCreation->actor;

// Convert the GFX data to a stack mapping
static std::unordered_map<TESForm*, std::pair<SInt32, UInt8>> stackList;
std::unordered_map<TESForm*, std::pair<SInt32, UInt8>> stackList;
UInt32 numItems = args->args[0].GetArraySize();
for (UInt32 i = 0; i < numItems; i++) {
GFxValue element, formId, stackIndex, flags;
Expand All @@ -648,7 +648,7 @@ void F4EEScaleform_UnequipItems::Invoke(Args * args)
auto inventory = actor->inventoryList;
if(inventory)
{
inventory->inventoryLock.Lock();
inventory->inventoryLock.LockForWrite();

for(UInt32 i = 0; i < inventory->items.count; i++)
{
Expand All @@ -659,7 +659,7 @@ void F4EEScaleform_UnequipItems::Invoke(Args * args)
inventory->items[i].stack->Visit([&](BGSInventoryItem::Stack * stack)
{
if(it->second.first == s) {
stack->flags &= ~0xF;
stack->flags &= ~0x7;
return false;
}

Expand All @@ -669,7 +669,7 @@ void F4EEScaleform_UnequipItems::Invoke(Args * args)
}
}

inventory->inventoryLock.Release();
inventory->inventoryLock.UnlockWrite();
}

if(!stackList.empty()) {
Expand All @@ -685,7 +685,7 @@ void F4EEScaleform_UnequipItems::Invoke(Args * args)
args->result->PushBack(&equippedItem);
}

g_task->AddTask(new F4EEBodyGenUpdate(actor, false));
g_task->AddTask(new F4EEBodyGenUpdate(actor, false));
}
else
args->result->SetNull();
Expand All @@ -699,7 +699,7 @@ void F4EEScaleform_EquipItems::Invoke(Args * args)
Actor * actor = characterCreation->actor;

// Convert the GFX data
static std::unordered_map<TESForm*, std::pair<SInt32, UInt8>> stackList;
std::unordered_map<TESForm*, std::pair<SInt32, UInt8>> stackList;
UInt32 numItems = args->args[0].GetArraySize();
for (UInt32 i = 0; i < numItems; i++) {
GFxValue element, formId, stackIndex, flags;
Expand All @@ -720,7 +720,7 @@ void F4EEScaleform_EquipItems::Invoke(Args * args)
auto inventory = actor->inventoryList;
if(inventory)
{
inventory->inventoryLock.Lock();
inventory->inventoryLock.LockForWrite();

for(UInt32 i = 0; i < inventory->items.count; i++)
{
Expand All @@ -731,7 +731,7 @@ void F4EEScaleform_EquipItems::Invoke(Args * args)
inventory->items[i].stack->Visit([&](BGSInventoryItem::Stack * stack)
{
if(it->second.first == s) {
stack->flags |= it->second.second & 0xF;
stack->flags |= it->second.second & 0x7;
return false;
}

Expand All @@ -741,7 +741,7 @@ void F4EEScaleform_EquipItems::Invoke(Args * args)
}
}

inventory->inventoryLock.Release();
inventory->inventoryLock.UnlockWrite();
}

if(!stackList.empty()) {
Expand Down

0 comments on commit 76768ff

Please sign in to comment.