+/*
+ Packet counter
+*/
+
+class PacketCounter
+{
+public:
+ PacketCounter()
+ {
+ }
+
+ void add(u16 command)
+ {
+ core::map<u16, u16>::Node *n = m_packets.find(command);
+ if(n == NULL)
+ {
+ m_packets[command] = 1;
+ }
+ else
+ {
+ n->setValue(n->getValue()+1);
+ }
+ }
+
+ void clear()
+ {
+ for(core::map<u16, u16>::Iterator
+ i = m_packets.getIterator();
+ i.atEnd() == false; i++)
+ {
+ i.getNode()->setValue(0);
+ }
+ }
+
+ void print(std::ostream &o)
+ {
+ for(core::map<u16, u16>::Iterator
+ i = m_packets.getIterator();
+ i.atEnd() == false; i++)
+ {
+ o<<"cmd "<<i.getNode()->getKey()
+ <<" count "<<i.getNode()->getValue()
+ <<std::endl;
+ }
+ }
+
+private:
+ // command, count
+ core::map<u16, u16> m_packets;
+};
+
+/*
+ These should be put into every thread
+*/
+
+#if CATCH_UNHANDLED_EXCEPTIONS == 1
+ #define BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER try{
+ #define END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)\
+ }catch(std::exception &e){\
+ logstream<<"ERROR: An unhandled exception occurred: "\
+ <<e.what()<<std::endl;\
+ assert(0);\
+ }
+ #ifdef _WIN32 // Windows
+ #ifdef _MSC_VER // MSVC
+void se_trans_func(unsigned int, EXCEPTION_POINTERS*);
+
+class FatalSystemException : public BaseException
+{
+public:
+ FatalSystemException(const char *s):
+ BaseException(s)
+ {}
+};
+ #define BEGIN_DEBUG_EXCEPTION_HANDLER \
+ BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER\
+ _set_se_translator(se_trans_func);
+
+ #define END_DEBUG_EXCEPTION_HANDLER(logstream) \
+ END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
+ #else // Probably mingw
+ #define BEGIN_DEBUG_EXCEPTION_HANDLER\
+ BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER
+ #define END_DEBUG_EXCEPTION_HANDLER(logstream)\
+ END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
+ #endif
+ #else // Posix
+ #define BEGIN_DEBUG_EXCEPTION_HANDLER\
+ BEGIN_PORTABLE_DEBUG_EXCEPTION_HANDLER
+ #define END_DEBUG_EXCEPTION_HANDLER(logstream)\
+ END_PORTABLE_DEBUG_EXCEPTION_HANDLER(logstream)
+ #endif
+#else
+ // Dummy ones
+ #define BEGIN_DEBUG_EXCEPTION_HANDLER
+ #define END_DEBUG_EXCEPTION_HANDLER(logstream)