Skip to content

Commit

Permalink
Fixes #568
Browse files Browse the repository at this point in the history
  • Loading branch information
DudeMcDude authored and Yanti Parazi committed Mar 18, 2022
1 parent ffcc8cc commit c0fe23b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions TemplePlus/critter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,8 @@ std::string LegacyCritterSystem::GetHairStyleFile(HairStyle style, const char *
// Originally @ 1007E9D0
void LegacyCritterSystem::UpdateModelEquipment(objHndl obj)
{
if (mSuspendModelUpdate)
return;

UpdateAddMeshes(obj);
auto raceOffset = GetModelRaceOffset(obj, false);
Expand Down Expand Up @@ -1263,6 +1265,11 @@ void LegacyCritterSystem::UpdateModelEquipment(objHndl obj)
}
}

void LegacyCritterSystem::SuspendModelUpdate(bool state)
{
mSuspendModelUpdate = state;
}

void LegacyCritterSystem::AddNpcAddMeshes(objHndl obj)
{

Expand Down
3 changes: 3 additions & 0 deletions TemplePlus/critter.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ struct LegacyCritterSystem : temple::AddressTable
gfx::EncodedAnimId GetAnimId(objHndl critter, gfx::WeaponAnim anim);

void UpdateModelEquipment(objHndl obj);
void SuspendModelUpdate(bool state);

/**
* This is called initially when the model is loaded for an object
Expand Down Expand Up @@ -380,6 +381,8 @@ struct LegacyCritterSystem : temple::AddressTable
std::unordered_map<int, std::vector<std::string>> mAddMeshes;

const std::vector<std::string>& GetAddMeshes(int matIdx, int raceOffset);

bool mSuspendModelUpdate = false;
};

extern LegacyCritterSystem critterSys;
Expand Down
4 changes: 4 additions & 0 deletions TemplePlus/gamesystems/gamesystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ void GameSystems::AdvanceTime() {

for (auto system : mTimeAwareSystems) {
system->AdvanceTime(now);
/*if (timeGetTime() - now > 200) {
auto asdf = 1;
logger->debug("{} taking longer", system->GetName());
}*/
}

}
Expand Down
7 changes: 5 additions & 2 deletions TemplePlus/gamesystems/timeevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "graphics/mapterrain.h"
#include "objfade.h"
#include "ui/ui_dialog.h"
#include <tig/tig_timer.h>

/*
Internal system specification used by the time event system
Expand Down Expand Up @@ -1112,7 +1113,7 @@ void TimeEventSystem::AdvanceTime(uint32_t newTimeMs) {

// Expire event
auto sysSpec = GetTimeEventTypeSpec(node->evt.system);

auto now = TigGetSystemTime();
if (node->IsValid(0)) {
lastValid = *node;
sysSpec.expiredCallback(&node->evt);
Expand All @@ -1121,7 +1122,9 @@ void TimeEventSystem::AdvanceTime(uint32_t newTimeMs) {
if (sysSpec.removedCallback) {
sysSpec.removedCallback(&node->evt);
}

/*if (TigElapsedSystemTime(now) > 100) {
logger->trace("Slow callback detected on system {}",(int) node->evt.system);
}*/
auto evtSystemId = node->evt.system;
free(node);

Expand Down
4 changes: 4 additions & 0 deletions TemplePlus/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,9 +1606,13 @@ obj_f InventorySystem::GetInventoryNumField(objHndl objHnd)

void InventorySystem::WieldBestAll(objHndl critter, objHndl tgt){

critterSys.SuspendModelUpdate(true); // added to improve perf
for (auto invIdx = INVENTORY_WORN_IDX_START; invIdx < INVENTORY_WORN_IDX_END; invIdx++){
WieldBest(critter, invIdx, tgt);
}
critterSys.SuspendModelUpdate(false);

critterSys.UpdateModelEquipment(critter);
}

void InventorySystem::ForceRemove(objHndl item, objHndl parent){
Expand Down
4 changes: 2 additions & 2 deletions TemplePlus/tig/tig_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <timeapi.h>

/* 0x101E3500 */
uint32_t TigGetSystemTime() {
inline uint32_t TigGetSystemTime() {
return timeGetTime();
}

/* 0x101E3510 */
int TigElapsedSystemTime(int refTime) {
inline int TigElapsedSystemTime(int refTime) {
return timeGetTime() - refTime;
}

0 comments on commit c0fe23b

Please sign in to comment.