mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-22 06:02: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();
|
reopenWindowsStreams();
|
||||||
configureWindowsStreams();
|
configureWindowsStreams();
|
||||||
|
Debug::stopQueueing();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -228,6 +228,11 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __WIN32__
|
||||||
|
if (conf.editor.debug)
|
||||||
|
Debug::startQueueing();
|
||||||
|
#endif
|
||||||
|
|
||||||
conf.readGameINI();
|
conf.readGameINI();
|
||||||
|
|
||||||
#ifdef MKXPZ_STEAM
|
#ifdef MKXPZ_STEAM
|
||||||
|
|
|
@ -146,6 +146,7 @@ main_source = files(
|
||||||
'display/gl/tilequad.cpp',
|
'display/gl/tilequad.cpp',
|
||||||
'display/gl/vertex.cpp',
|
'display/gl/vertex.cpp',
|
||||||
|
|
||||||
|
'util/debugwriter.cpp',
|
||||||
'util/iniconfig.cpp',
|
'util/iniconfig.cpp',
|
||||||
'util/win-consoleutils.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>
|
#include <android/log.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* A cheap replacement for qDebug() */
|
/* A cheap replacement for qDebug() */
|
||||||
|
|
||||||
class Debug
|
class Debug
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Debug()
|
Debug();
|
||||||
{
|
~Debug();
|
||||||
buf << std::boolalpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Debug &operator<<(const T &t)
|
Debug &operator<<(const T &t);
|
||||||
{
|
|
||||||
buf << t;
|
|
||||||
buf << " ";
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Debug &operator<<(const std::vector<T> &v)
|
Debug &operator<<(const std::vector<T> &v);
|
||||||
{
|
|
||||||
for (size_t i = 0; i < v.size(); ++i)
|
|
||||||
buf << v[i] << " ";
|
|
||||||
|
|
||||||
return *this;
|
static void startQueueing();
|
||||||
}
|
static void stopQueueing();
|
||||||
|
|
||||||
~Debug()
|
|
||||||
{
|
|
||||||
#ifdef __ANDROID__
|
|
||||||
__android_log_write(ANDROID_LOG_DEBUG, "mkxp", buf.str().c_str());
|
|
||||||
#else
|
|
||||||
std::cerr << buf.str() << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::stringstream buf;
|
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
|
#endif // DEBUGWRITER_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue