Avoid some unnecessary string operations when not recording history, cleanup, debug crash in `fullName` kaetemi/ryzomclassic#152

ryzomclassic-develop
kaetemi 4 years ago
parent 4a7a153a3e
commit ccb141672f

@ -23,36 +23,37 @@ private:
typedef std::deque<std::string> THistoryContainer;
public:
explicit CDebugHistory()
: _Recording(false)
: m_Recording(false)
{
}
virtual ~CDebugHistory() { }
void addHistory(std::string const& txt)
{
if (_Recording)
_History.push_back(txt);
if (m_Recording)
m_History.push_back(txt);
}
void addHistory(char const* txt)
{
if (_Recording)
if (m_Recording)
addHistory(NLMISC::toString(txt));
}
template <class A>
void addHistory(char const* txt, A a) { if (_Recording) addHistory(NLMISC::toString(txt, a)); }
void addHistory(char const* txt, A a) { if (m_Recording) addHistory(NLMISC::toString(txt, a)); }
template <class A, class B>
void addHistory(char const* txt, A a, B b) { if (_Recording) addHistory(NLMISC::toString(txt, a, b)); }
void addHistory(char const* txt, A a, B b) { if (m_Recording) addHistory(NLMISC::toString(txt, a, b)); }
template <class A, class B, class C>
void addHistory(char const* txt, A a, B b, C c) { if (_Recording) addHistory(NLMISC::toString(txt, a, b, c)); }
void addHistory(char const* txt, A a, B b, C c) { if (m_Recording) addHistory(NLMISC::toString(txt, a, b, c)); }
template <class A, class B, class C, class D>
void addHistory(char const* txt, A a, B b, C c, D d) { if (_Recording) addHistory(NLMISC::toString(txt, a, b, c, d)); }
void addHistory(char const* txt, A a, B b, C c, D d) { if (m_Recording) addHistory(NLMISC::toString(txt, a, b, c, d)); }
void setRecording(bool val) { _Recording = val; }
void setRecording(bool val) { m_Recording = val; }
inline bool isRecording() { return m_Recording; }
void writeAsInfo()
{
int j = 0;
FOREACH(itHistory, THistoryContainer, _History)
FOREACH(itHistory, THistoryContainer, m_History)
{
nlinfo("HIST %3i: %s", j, itHistory->c_str());
++j;
@ -60,8 +61,8 @@ public:
}
private:
bool _Recording;
THistoryContainer _History;
bool m_Recording;
THistoryContainer m_History;
};
#endif

@ -503,18 +503,23 @@ void CStateInstance::processStateEvent(CAIEvent const& stateEvent, CAIState cons
if (!reaction.testCompatibility(this,state))
continue;
if (getDebugHistory()->isRecording())
{
getDebugHistory()->addHistory("STATE: '%s' EVENT: '%s' REACTION: '%s'", state->getAliasNode()->fullName().c_str(),
stateEvent.getName().c_str(), reaction.getAliasNode()->fullName().c_str());
}
foundReaction=true;
if (!reaction.getAction())
{
nldebug("Failed to find action for event");
nlwarning("Failed to find action for event: %s",reaction.getAliasNode()->fullName().c_str());
continue;
}
if (!reaction.getAction()->executeAction(this, NULL))
{
nldebug("Failed to execute action for event");
nlwarning("Failed to execute action for event '%s': for stateInstance:'%s' in state:'%s'", stateEvent.getName().c_str(),
aliasTreeOwner()->getAliasNode()->fullName().c_str(), state->getAliasNode()->fullName().c_str());
continue;
@ -522,10 +527,13 @@ void CStateInstance::processStateEvent(CAIEvent const& stateEvent, CAIState cons
}
if (!foundReaction)
{
if (getDebugHistory()->isRecording())
{
getDebugHistory()->addHistory("STATE: '%s' EVENT: '%s' NO REACTION", state->getAliasNode()->fullName().c_str(),
stateEvent.getName().c_str());
}
}
}

Loading…
Cancel
Save