mirror of https://github.com/AxioDL/metaforce.git
CGameOptions: Make use of std::string_view where applicable
Enforces the use of valid strings in the interface. Also reduces c_str() noise a little bit.
This commit is contained in:
parent
df4487bae8
commit
659b8a43d3
|
@ -31,12 +31,12 @@ CGameHintInfo::SHintLocation::SHintLocation(CInputStream& in, s32)
|
||||||
, x8_areaId(in.readUint32Big())
|
, x8_areaId(in.readUint32Big())
|
||||||
, xc_stringId(in.readUint32Big()) {}
|
, xc_stringId(in.readUint32Big()) {}
|
||||||
|
|
||||||
int CGameHintInfo::FindHintIndex(const char* str) {
|
int CGameHintInfo::FindHintIndex(std::string_view str) {
|
||||||
const std::vector<CGameHint>& gameHints = g_MemoryCardSys->GetHints();
|
const std::vector<CGameHint>& gameHints = g_MemoryCardSys->GetHints();
|
||||||
const auto& it = std::find_if(gameHints.begin(), gameHints.end(),
|
const auto it =
|
||||||
[&str](const CGameHint& gh) -> bool { return gh.GetName() == str; });
|
std::find_if(gameHints.cbegin(), gameHints.cend(), [&str](const CGameHint& gh) { return gh.GetName() == str; });
|
||||||
|
|
||||||
return (it != gameHints.end() ? it - gameHints.begin() : -1);
|
return it != gameHints.cend() ? it - gameHints.cbegin() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer, CObjectReference*) {
|
CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer, CObjectReference*) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ private:
|
||||||
public:
|
public:
|
||||||
CGameHintInfo(CInputStream&, s32);
|
CGameHintInfo(CInputStream&, s32);
|
||||||
const std::vector<CGameHint>& GetHints() const { return x0_hints; }
|
const std::vector<CGameHint>& GetHints() const { return x0_hints; }
|
||||||
static int FindHintIndex(const char* str);
|
static int FindHintIndex(std::string_view str);
|
||||||
};
|
};
|
||||||
|
|
||||||
CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream&, const CVParamTransfer, CObjectReference*);
|
CFactoryFnReturn FHintFactory(const SObjectTag&, CInputStream&, const CVParamTransfer, CObjectReference*);
|
||||||
|
|
|
@ -578,43 +578,51 @@ const CHintOptions::SHintState* CHintOptions::GetCurrentDisplayedHint() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHintOptions::DelayHint(const char* name) {
|
void CHintOptions::DelayHint(std::string_view name) {
|
||||||
int idx = CGameHintInfo::FindHintIndex(name);
|
const int idx = CGameHintInfo::FindHintIndex(name);
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (x10_nextHintIdx == idx)
|
if (x10_nextHintIdx == idx) {
|
||||||
for (SHintState& state : x0_hintStates)
|
for (SHintState& state : x0_hintStates) {
|
||||||
state.x4_time += 60.f;
|
state.x4_time += 60.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
x0_hintStates[idx].x0_state = EHintState::Delayed;
|
x0_hintStates[idx].x0_state = EHintState::Delayed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHintOptions::ActivateImmediateHintTimer(const char* name) {
|
void CHintOptions::ActivateImmediateHintTimer(std::string_view name) {
|
||||||
int idx = CGameHintInfo::FindHintIndex(name);
|
const int idx = CGameHintInfo::FindHintIndex(name);
|
||||||
if (idx == -1)
|
if (idx == -1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SHintState& hintState = x0_hintStates[idx];
|
SHintState& hintState = x0_hintStates[idx];
|
||||||
const CGameHintInfo::CGameHint& hint = g_MemoryCardSys->GetHints()[idx];
|
const CGameHintInfo::CGameHint& hint = g_MemoryCardSys->GetHints()[idx];
|
||||||
if (hintState.x0_state != EHintState::Zero)
|
if (hintState.x0_state != EHintState::Zero) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hintState.x0_state = EHintState::Waiting;
|
hintState.x0_state = EHintState::Waiting;
|
||||||
hintState.x4_time = hint.GetImmediateTime();
|
hintState.x4_time = hint.GetImmediateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHintOptions::ActivateContinueDelayHintTimer(const char* name) {
|
void CHintOptions::ActivateContinueDelayHintTimer(std::string_view name) {
|
||||||
int idx = x10_nextHintIdx;
|
int idx = x10_nextHintIdx;
|
||||||
if (idx != 0)
|
if (idx != 0) {
|
||||||
idx = CGameHintInfo::FindHintIndex(name);
|
idx = CGameHintInfo::FindHintIndex(name);
|
||||||
if (idx == -1)
|
}
|
||||||
|
if (idx == -1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SHintState& hintState = x0_hintStates[idx];
|
SHintState& hintState = x0_hintStates[idx];
|
||||||
const CGameHintInfo::CGameHint& hint = g_MemoryCardSys->GetHints()[idx];
|
const CGameHintInfo::CGameHint& hint = g_MemoryCardSys->GetHints()[idx];
|
||||||
if (hintState.x0_state != EHintState::Displaying)
|
if (hintState.x0_state != EHintState::Displaying) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hintState.x4_time = hint.GetTextTime();
|
hintState.x4_time = hint.GetTextTime();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Runtime/CSaveWorld.hpp"
|
#include "Runtime/CSaveWorld.hpp"
|
||||||
|
@ -205,9 +206,9 @@ public:
|
||||||
void SetNextHintTime();
|
void SetNextHintTime();
|
||||||
void InitializeMemoryState();
|
void InitializeMemoryState();
|
||||||
const SHintState* GetCurrentDisplayedHint() const;
|
const SHintState* GetCurrentDisplayedHint() const;
|
||||||
void DelayHint(const char* name);
|
void DelayHint(std::string_view name);
|
||||||
void ActivateImmediateHintTimer(const char* name);
|
void ActivateImmediateHintTimer(std::string_view name);
|
||||||
void ActivateContinueDelayHintTimer(const char* name);
|
void ActivateContinueDelayHintTimer(std::string_view name);
|
||||||
void DismissDisplayedHint();
|
void DismissDisplayedHint();
|
||||||
u32 GetNextHintIdx() const;
|
u32 GetNextHintIdx() const;
|
||||||
const std::vector<SHintState>& GetHintStates() const { return x0_hintStates; }
|
const std::vector<SHintState>& GetHintStates() const { return x0_hintStates; }
|
||||||
|
|
|
@ -396,12 +396,13 @@ void CScriptSpecialFunction::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
|
||||||
}
|
}
|
||||||
case ESpecialFunction::RedundantHintSystem: {
|
case ESpecialFunction::RedundantHintSystem: {
|
||||||
CHintOptions& hintOptions = g_GameState->HintOptions();
|
CHintOptions& hintOptions = g_GameState->HintOptions();
|
||||||
if (msg == EScriptObjectMessage::Action)
|
if (msg == EScriptObjectMessage::Action) {
|
||||||
hintOptions.ActivateContinueDelayHintTimer(xec_locatorName.c_str());
|
hintOptions.ActivateContinueDelayHintTimer(xec_locatorName);
|
||||||
else if (msg == EScriptObjectMessage::Increment)
|
} else if (msg == EScriptObjectMessage::Increment) {
|
||||||
hintOptions.ActivateImmediateHintTimer(xec_locatorName.c_str());
|
hintOptions.ActivateImmediateHintTimer(xec_locatorName);
|
||||||
else if (msg == EScriptObjectMessage::Decrement)
|
} else if (msg == EScriptObjectMessage::Decrement) {
|
||||||
hintOptions.DelayHint(xec_locatorName.c_str());
|
hintOptions.DelayHint(xec_locatorName);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESpecialFunction::Billboard: {
|
case ESpecialFunction::Billboard: {
|
||||||
|
|
Loading…
Reference in New Issue