-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from teeframe/upstream-ddnet
Rebase from DDNet
- Loading branch information
Showing
28 changed files
with
443 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "assertion_logger.h" | ||
|
||
#include <base/system.h> | ||
#include <mutex> | ||
|
||
void CAssertionLogger::DbgLogger(const char *pLine, void *pUser) | ||
{ | ||
((CAssertionLogger *)pUser)->DbgLogger(pLine); | ||
} | ||
|
||
void CAssertionLogger::DbgLoggerAssertion(void *pUser) | ||
{ | ||
((CAssertionLogger *)pUser)->DbgLoggerAssertion(); | ||
} | ||
|
||
void CAssertionLogger::DbgLogger(const char *pLine) | ||
{ | ||
std::unique_lock<std::mutex> Lock(m_DbgMessageMutex); | ||
|
||
SDebugMessageItem *pMsgItem = (SDebugMessageItem *)m_DbgMessages.Allocate(sizeof(SDebugMessageItem)); | ||
str_copy(pMsgItem->m_aMessage, pLine, std::size(pMsgItem->m_aMessage)); | ||
} | ||
|
||
void CAssertionLogger::DbgLoggerAssertion() | ||
{ | ||
char aAssertLogFile[IO_MAX_PATH_LENGTH]; | ||
char aDate[64]; | ||
str_timestamp(aDate, sizeof(aDate)); | ||
str_format(aAssertLogFile, std::size(aAssertLogFile), "%s%s_assert_log_%d_%s.txt", m_aAssertLogPath, m_aGameName, pid(), aDate); | ||
std::unique_lock<std::mutex> Lock(m_DbgMessageMutex); | ||
IOHANDLE FileHandle = io_open(aAssertLogFile, IOFLAG_WRITE); | ||
if(FileHandle) | ||
{ | ||
auto *pIt = m_DbgMessages.First(); | ||
while(pIt) | ||
{ | ||
io_write(FileHandle, pIt->m_aMessage, str_length(pIt->m_aMessage)); | ||
io_write(FileHandle, "\n", 1); | ||
|
||
pIt = m_DbgMessages.Next(pIt); | ||
} | ||
|
||
io_sync(FileHandle); | ||
io_close(FileHandle); | ||
} | ||
} | ||
|
||
void CAssertionLogger::Init(const char *pAssertLogPath, const char *pGameName) | ||
{ | ||
str_copy(m_aAssertLogPath, pAssertLogPath, std::size(m_aAssertLogPath)); | ||
str_copy(m_aGameName, pGameName, std::size(m_aGameName)); | ||
|
||
dbg_logger_assertion(DbgLogger, nullptr, DbgLoggerAssertion, this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef ENGINE_SHARED_ASSERTION_LOGGER_H | ||
#define ENGINE_SHARED_ASSERTION_LOGGER_H | ||
|
||
#include <base/system.h> | ||
|
||
#include <cstddef> | ||
#include <mutex> | ||
|
||
#include <engine/shared/ringbuffer.h> | ||
|
||
class CAssertionLogger | ||
{ | ||
static void DbgLogger(const char *pLine, void *pUser); | ||
static void DbgLoggerAssertion(void *pUser); | ||
|
||
static constexpr size_t s_MaxDbgMessageCount = 64; | ||
|
||
void DbgLogger(const char *pLine); | ||
void DbgLoggerAssertion(); | ||
|
||
struct SDebugMessageItem | ||
{ | ||
char m_aMessage[1024]; | ||
}; | ||
|
||
std::mutex m_DbgMessageMutex; | ||
CStaticRingBuffer<SDebugMessageItem, sizeof(SDebugMessageItem) * s_MaxDbgMessageCount, CRingBufferBase::FLAG_RECYCLE> m_DbgMessages; | ||
|
||
char m_aAssertLogPath[IO_MAX_PATH_LENGTH]; | ||
char m_aGameName[256]; | ||
|
||
public: | ||
void Init(const char *pAssertLogPath, const char *pGameName); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.