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; typedef std::deque<std::string> THistoryContainer;
public: public:
explicit CDebugHistory() explicit CDebugHistory()
: _Recording(false) : m_Recording(false)
{ {
} }
virtual ~CDebugHistory() { } virtual ~CDebugHistory() { }
void addHistory(std::string const& txt) void addHistory(std::string const& txt)
{ {
if (_Recording) if (m_Recording)
_History.push_back(txt); m_History.push_back(txt);
} }
void addHistory(char const* txt) void addHistory(char const* txt)
{ {
if (_Recording) if (m_Recording)
addHistory(NLMISC::toString(txt)); addHistory(NLMISC::toString(txt));
} }
template <class A> 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> 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> 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> 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() void writeAsInfo()
{ {
int j = 0; int j = 0;
FOREACH(itHistory, THistoryContainer, _History) FOREACH(itHistory, THistoryContainer, m_History)
{ {
nlinfo("HIST %3i: %s", j, itHistory->c_str()); nlinfo("HIST %3i: %s", j, itHistory->c_str());
++j; ++j;
@ -60,8 +61,8 @@ public:
} }
private: private:
bool _Recording; bool m_Recording;
THistoryContainer _History; THistoryContainer m_History;
}; };
#endif #endif

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

Loading…
Cancel
Save