mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
Allow queuing Debug prints
This commit is contained in:
parent
7c1b15ecb8
commit
ac778db752
5 changed files with 80 additions and 27 deletions
|
@ -277,6 +277,7 @@ static void mriBindingInit() {
|
|||
{
|
||||
reopenWindowsStreams();
|
||||
configureWindowsStreams();
|
||||
Debug::stopQueueing();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -228,6 +228,11 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
#if __WIN32__
|
||||
if (conf.editor.debug)
|
||||
Debug::startQueueing();
|
||||
#endif
|
||||
|
||||
conf.readGameINI();
|
||||
|
||||
#ifdef MKXPZ_STEAM
|
||||
|
|
|
@ -146,6 +146,7 @@ main_source = files(
|
|||
'display/gl/tilequad.cpp',
|
||||
'display/gl/vertex.cpp',
|
||||
|
||||
'util/debugwriter.cpp',
|
||||
'util/iniconfig.cpp',
|
||||
'util/win-consoleutils.cpp',
|
||||
|
||||
|
|
45
src/util/debugwriter.cpp
Normal file
45
src/util/debugwriter.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "debugwriter.h"
|
||||
|
||||
std::stringstream Debug::queueBuf = std::stringstream();
|
||||
bool Debug::queue = false;
|
||||
|
||||
Debug::Debug()
|
||||
{
|
||||
getBuf() << std::boolalpha;
|
||||
}
|
||||
|
||||
Debug::~Debug()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "mkxp", buf.str().c_str());
|
||||
#else
|
||||
if (queue)
|
||||
getBuf() << std::endl;
|
||||
else
|
||||
std::cerr << buf.str() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::stringstream &Debug::getBuf()
|
||||
{
|
||||
return queue ? queueBuf : buf;
|
||||
}
|
||||
|
||||
void Debug::startQueueing()
|
||||
{
|
||||
queue = true;
|
||||
queueBuf.clear();
|
||||
queueBuf << std::boolalpha;
|
||||
}
|
||||
|
||||
void Debug::stopQueueing()
|
||||
{
|
||||
queue = false;
|
||||
const std::string str = queueBuf.str();
|
||||
|
||||
if (str.length() > 0) {
|
||||
std::cerr << str << std::endl;
|
||||
}
|
||||
|
||||
queueBuf.clear();
|
||||
}
|
|
@ -30,46 +30,47 @@
|
|||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* A cheap replacement for qDebug() */
|
||||
|
||||
class Debug
|
||||
{
|
||||
public:
|
||||
Debug()
|
||||
{
|
||||
buf << std::boolalpha;
|
||||
}
|
||||
Debug();
|
||||
~Debug();
|
||||
|
||||
template<typename T>
|
||||
Debug &operator<<(const T &t)
|
||||
{
|
||||
buf << t;
|
||||
buf << " ";
|
||||
|
||||
return *this;
|
||||
}
|
||||
Debug &operator<<(const T &t);
|
||||
|
||||
template<typename T>
|
||||
Debug &operator<<(const std::vector<T> &v)
|
||||
{
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
buf << v[i] << " ";
|
||||
Debug &operator<<(const std::vector<T> &v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Debug()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "mkxp", buf.str().c_str());
|
||||
#else
|
||||
std::cerr << buf.str() << std::endl;
|
||||
#endif
|
||||
}
|
||||
static void startQueueing();
|
||||
static void stopQueueing();
|
||||
|
||||
private:
|
||||
std::stringstream buf;
|
||||
static std::stringstream queueBuf;
|
||||
static bool queue;
|
||||
|
||||
std::stringstream &getBuf();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Debug &Debug::operator<<(const T &t)
|
||||
{
|
||||
getBuf() << t;
|
||||
getBuf() << " ";
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Debug &Debug::operator<<(const std::vector<T> &v)
|
||||
{
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
getBuf() << v[i] << " ";
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // DEBUGWRITER_H
|
||||
|
|
Loading…
Add table
Reference in a new issue