CScanDisplay: Eliminate implicit sign conversions

Removes implicit sign conversions and also dehardcodes quite a bit of
sizes.
This commit is contained in:
Lioncash 2020-04-12 21:54:40 -04:00
parent 8000fb9e42
commit 0a01a30bf5
6 changed files with 70 additions and 48 deletions

View File

@ -12,6 +12,8 @@ class CScannableObjectInfo {
public:
enum class EPanelType {};
static constexpr size_t NumBuckets = 4;
struct SBucket {
CAssetId x0_texture;
float x4_appearanceRange = 0.f;
@ -29,14 +31,14 @@ private:
float x8_totalDownloadTime = 0.f;
u32 xc_category = 0;
bool x10_important = false;
rstl::reserved_vector<SBucket, 4> x14_buckets;
rstl::reserved_vector<SBucket, NumBuckets> x14_buckets;
public:
CScannableObjectInfo(CInputStream&, CAssetId);
CAssetId GetScannableObjectId() const { return x0_scannableObjectId; }
CAssetId GetStringTableId() const { return x4_stringId; }
float GetTotalDownloadTime() const { return x8_totalDownloadTime; }
const SBucket& GetBucket(s32 idx) const { return x14_buckets[idx]; }
const SBucket& GetBucket(size_t idx) const { return x14_buckets[idx]; }
u32 GetCategory() const { return xc_category; }
bool IsImportant() const { return x10_important; }
};

View File

@ -71,9 +71,10 @@ void CScanDisplay::CDataDot::SetDestPosition(const zeus::CVector2f& pos) {
CScanDisplay::CScanDisplay(const CGuiFrame& selHud) : xa0_selHud(selHud) {
x0_dataDot = g_SimplePool->GetObj("TXTR_DataDot");
for (int i = 0; i < 4; ++i)
for (size_t i = 0; i < xbc_dataDots.capacity(); ++i) {
xbc_dataDots.emplace_back(x0_dataDot);
x170_paneStates.resize(4);
}
x170_paneStates.resize(x170_paneStates.capacity());
}
void CScanDisplay::ProcessInput(const CFinalInput& input) {
@ -139,26 +140,34 @@ void CScanDisplay::ProcessInput(const CFinalInput& input) {
xb8_dash->SetColor(zeus::CColor(0.53f, 0.84f, 1.f, dashAlpha));
}
float CScanDisplay::GetDownloadStartTime(int idx) const {
if (!x14_scannableInfo)
float CScanDisplay::GetDownloadStartTime(size_t idx) const {
if (!x14_scannableInfo) {
return 0.f;
float nTime = x14_scannableInfo->GetBucket(idx).x4_appearanceRange;
}
const float nTime = x14_scannableInfo->GetBucket(idx).x4_appearanceRange;
float maxTime = 0.f;
for (int i = 0; i < 4; ++i) {
float iTime = x14_scannableInfo->GetBucket(i).x4_appearanceRange;
if (iTime < nTime)
for (size_t i = 0; i < CScannableObjectInfo::NumBuckets; ++i) {
const float iTime = x14_scannableInfo->GetBucket(i).x4_appearanceRange;
if (iTime < nTime) {
maxTime = std::max(iTime, maxTime);
}
}
return maxTime + g_tweakGui->GetScanAppearanceDuration();
}
float CScanDisplay::GetDownloadFraction(int idx, float scanningTime) const {
if (!x14_scannableInfo)
float CScanDisplay::GetDownloadFraction(size_t idx, float scanningTime) const {
if (!x14_scannableInfo) {
return 0.f;
float appearTime = GetDownloadStartTime(idx);
float appearRange = x14_scannableInfo->GetBucket(idx).x4_appearanceRange;
if (appearTime == appearRange)
}
const float appearTime = GetDownloadStartTime(idx);
const float appearRange = x14_scannableInfo->GetBucket(idx).x4_appearanceRange;
if (appearTime == appearRange) {
return 1.f;
}
return zeus::clamp(0.f, (scanningTime - appearTime) / (appearRange - appearTime), 1.f);
}
@ -182,26 +191,26 @@ void CScanDisplay::StartScan(TUniqueId id, const CScannableObjectInfo& scanInfo,
xa8_message->TextSupport().SetText(u"");
xac_scrollMessage->TextSupport().SetText(u"");
for (int i = 0; i < 20; ++i) {
CAuiImagePane* pane =
static_cast<CAuiImagePane*>(xa0_selHud.FindWidget(MP1::CPauseScreenBase::GetImagePaneName(i)));
for (size_t i = 0; i < 20; ++i) {
auto* pane = static_cast<CAuiImagePane*>(xa0_selHud.FindWidget(MP1::CPauseScreenBase::GetImagePaneName(i)));
zeus::CColor color = g_tweakGuiColors->GetScanDisplayImagePaneColor();
color.a() = 0.f;
pane->SetColor(color);
pane->SetTextureID0({}, g_SimplePool);
pane->SetAnimationParms(zeus::skZero2f, 0.f, 0.f);
int pos = -1;
for (int j = 0; j < 4; ++j) {
size_t pos = SIZE_MAX;
for (size_t j = 0; j < CScannableObjectInfo::NumBuckets; ++j) {
if (x14_scannableInfo->GetBucket(j).x8_imagePos == i) {
pos = j;
break;
}
}
if (pos >= 0)
if (pos != SIZE_MAX) {
x170_paneStates[pos].second = pane;
}
}
for (int i = 0; i < x170_paneStates.size(); ++i) {
for (size_t i = 0; i < x170_paneStates.size(); ++i) {
std::pair<float, CAuiImagePane*>& state = x170_paneStates[i];
if (state.second) {
const CScannableObjectInfo::SBucket& bucket = x14_scannableInfo->GetBucket(i);
@ -211,22 +220,25 @@ void CScanDisplay::StartScan(TUniqueId id, const CScannableObjectInfo& scanInfo,
}
state.second->SetTextureID0(bucket.x0_texture, g_SimplePool);
state.second->SetFlashFactor(0.f);
float startTime = GetDownloadStartTime(i);
if (scanTime >= startTime)
const float startTime = GetDownloadStartTime(i);
if (scanTime >= startTime) {
x170_paneStates[i].first = 0.f;
else
} else {
x170_paneStates[i].first = -1.f;
}
}
}
CAssetId strId = x14_scannableInfo->GetStringTableId();
if (strId.IsValid())
const CAssetId strId = x14_scannableInfo->GetStringTableId();
if (strId.IsValid()) {
x194_scanStr = g_SimplePool->GetObj({FOURCC('STRG'), strId});
}
for (int i = 0; i < 4; ++i) {
int pos = x14_scannableInfo->GetBucket(i).x8_imagePos;
for (size_t i = 0; i < CScannableObjectInfo::NumBuckets; ++i) {
const u32 pos = x14_scannableInfo->GetBucket(i).x8_imagePos;
CDataDot& dot = xbc_dataDots[i];
if (pos != -1) {
if (pos != UINT32_MAX) {
if (GetDownloadStartTime(i) - g_tweakGui->GetScanAppearanceDuration() < scanTime) {
dot.SetAlpha(0.f);
dot.SetDotState(CDataDot::EDotState::Done);
@ -243,12 +255,14 @@ void CScanDisplay::StartScan(TUniqueId id, const CScannableObjectInfo& scanInfo,
}
void CScanDisplay::StopScan() {
if (xc_state == EScanState::Done || xc_state == EScanState::Inactive)
if (xc_state == EScanState::Done || xc_state == EScanState::Inactive) {
return;
}
xc_state = EScanState::Done;
for (int i = 0; i < 4; ++i)
xbc_dataDots[i].SetDesiredAlpha(0.f);
for (auto& dataDot : xbc_dataDots) {
dataDot.SetDesiredAlpha(0.f);
}
}
void CScanDisplay::SetScanMessageTypeEffect(CGuiTextPane* pane, bool type) {
@ -310,25 +324,30 @@ void CScanDisplay::Update(float dt, float scanningTime) {
}
}
for (int i = 0; i < 4; ++i) {
if (x170_paneStates[i].second == nullptr)
for (size_t i = 0; i < x170_paneStates.size(); ++i) {
if (x170_paneStates[i].second == nullptr) {
continue;
}
if (x170_paneStates[i].first > 0.f) {
x170_paneStates[i].first = std::max(0.f, x170_paneStates[i].first - dt);
float tmp;
if (x170_paneStates[i].first > g_tweakGui->GetScanPaneFadeOutTime())
if (x170_paneStates[i].first > g_tweakGui->GetScanPaneFadeOutTime()) {
tmp = 1.f -
(x170_paneStates[i].first - g_tweakGui->GetScanPaneFadeOutTime()) / g_tweakGui->GetScanPaneFadeInTime();
else
} else {
tmp = x170_paneStates[i].first / g_tweakGui->GetScanPaneFadeOutTime();
}
x170_paneStates[i].second->SetFlashFactor(tmp * g_tweakGui->GetScanPaneFlashFactor() * x1a8_bodyAlpha);
}
float alphaMul =
const float alphaMul =
((xc_state == EScanState::Downloading) ? GetDownloadFraction(i, scanningTime) : 1.f) * x1a8_bodyAlpha;
zeus::CColor color = g_tweakGuiColors->GetScanDisplayImagePaneColor();
color.a() *= alphaMul;
x170_paneStates[i].second->SetColor(color);
x170_paneStates[i].second->SetDeResFactor(1.f - alphaMul);
if (GetDownloadStartTime(i) - g_tweakGui->GetScanAppearanceDuration() < scanningTime) {
CDataDot& dot = xbc_dataDots[i];
switch (dot.GetDotState()) {
@ -338,7 +357,7 @@ void CScanDisplay::Update(float dt, float scanningTime) {
dot.StartTransitionTo(zeus::skZero2f, g_tweakGui->GetScanAppearanceDuration());
break;
case CDataDot::EDotState::RevealPane: {
float tmp = dot.GetTransitionFactor();
const float tmp = dot.GetTransitionFactor();
if (tmp == 0.f) {
dot.SetDotState(CDataDot::EDotState::Done);
dot.SetDesiredAlpha(0.f);
@ -353,7 +372,7 @@ void CScanDisplay::Update(float dt, float scanningTime) {
}
}
for (int i = 0; i < 4; ++i) {
for (size_t i = 0; i < xbc_dataDots.size(); ++i) {
CDataDot& dot = xbc_dataDots[i];
switch (dot.GetDotState()) {
case CDataDot::EDotState::Hidden:

View File

@ -79,8 +79,8 @@ private:
float x1b0_aPulse = 1.f;
bool x1b4_scanComplete = false;
float GetDownloadStartTime(int idx) const;
float GetDownloadFraction(int idx, float scanningTime) const;
float GetDownloadStartTime(size_t idx) const;
float GetDownloadFraction(size_t idx, float scanningTime) const;
static void SetScanMessageTypeEffect(CGuiTextPane* pane, bool type);
public:

View File

@ -214,10 +214,11 @@ void CLogBookScreen::UpdateBodyImagesAndText() {
pane->SetAnimationParms(zeus::skZero2f, 0.f, 0.f);
}
for (int i = 0; i < 4; ++i) {
for (size_t i = 0; i < CScannableObjectInfo::NumBuckets; ++i) {
const CScannableObjectInfo::SBucket& bucket = scan->GetBucket(i);
if (bucket.x8_imagePos == UINT32_MAX)
if (bucket.x8_imagePos == UINT32_MAX) {
continue;
}
CAuiImagePane* pane = xf0_imagePanes[bucket.x8_imagePos];
if (bucket.x14_interval > 0.f) {
pane->SetAnimationParms(zeus::CVector2f(bucket.xc_size.x, bucket.xc_size.y), bucket.x14_interval,

View File

@ -536,7 +536,7 @@ void CPauseScreenBase::OnWidgetScroll(CGuiWidget* widget, const boo::SScrollDelt
}
}
std::string CPauseScreenBase::GetImagePaneName(u32 i) {
std::string CPauseScreenBase::GetImagePaneName(size_t i) {
static constexpr std::array PaneSuffixes{
"0", "1", "2", "3", "01", "12", "23", "012", "123", "0123",
"4", "5", "6", "7", "45", "56", "67", "456", "567", "4567",

View File

@ -102,7 +102,7 @@ protected:
void OnWidgetScroll(CGuiWidget* widget, const boo::SScrollDelta& delta, int accumX, int accumY);
public:
static std::string GetImagePaneName(u32 i);
static std::string GetImagePaneName(size_t i);
CPauseScreenBase(const CStateManager& mgr, CGuiFrame& frame, const CStringTable& pauseStrg, bool isLogBook = false);