Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History Rewritten #5

Merged
merged 28 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6c0a564
Don't print binds into F1 by default (fixes #4789)
def- Mar 6, 2022
95fe457
Auto font size
Jupeyy Mar 11, 2022
9d1844e
Merge #4786
bors[bot] Mar 11, 2022
3b93e65
Make hook collision line size adjustable
sjrc6 Mar 12, 2022
11c49ab
Add instructions for videorecorder being default (fixes #4804)
def- Mar 12, 2022
86bc885
Merge #4803
bors[bot] Mar 12, 2022
a0a0887
Merge #4805
bors[bot] Mar 12, 2022
f89142b
Merge #4790
bors[bot] Mar 12, 2022
5105141
Use newer ubuntu with higher clang-tidy version
def- Mar 12, 2022
fd533a4
Merge #4806
bors[bot] Mar 12, 2022
9277e3c
Fix laser clipping. Closes #2176
oy Oct 30, 2015
25ceea6
Write log to disk on assert
Jupeyy Mar 2, 2022
0ff8054
Allow more precise Destroy call to Job pool
Jupeyy Mar 12, 2022
f6df2ce
Merge #4773
bors[bot] Mar 12, 2022
420862d
Merge #4808
bors[bot] Mar 12, 2022
2d39456
Recurse ENGINE_SHARED
ChillerDragon Mar 12, 2022
4337bcf
Merge #4807
bors[bot] Mar 12, 2022
50eb249
fix bug that sneaked in during refactoring (in #4775)
C0D3D3V Mar 12, 2022
d140e05
Merge #4811
bors[bot] Mar 12, 2022
9518e44
Full size sound settings
def- Mar 12, 2022
a1668e0
Merge #4812
bors[bot] Mar 13, 2022
eab52b3
Don't mute for 0 seconds (fixes #4816)
def- Mar 13, 2022
e91a4d4
Merge #4817
bors[bot] Mar 13, 2022
cce42d4
Auto select search string on hot key
Jupeyy Mar 13, 2022
8ea73b7
Merge #4822
bors[bot] Mar 13, 2022
897ba58
Use system.h style for system.h
heinrich5991 Mar 13, 2022
5d5aa10
Merge #4823
bors[bot] Mar 13, 2022
b6bd8c8
Merge branch 'main' into upstream-ddnet
miguilimzero Mar 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
check-clang-tidy:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,9 @@ set_src(ENGINE_INTERFACE GLOB src/engine
uuid.h
warning.h
)
set_src(ENGINE_SHARED GLOB src/engine/shared
set_src(ENGINE_SHARED GLOB_RECURSE src/engine/shared
assertion_logger.cpp
assertion_logger.h
compression.cpp
compression.h
config.cpp
Expand Down
42 changes: 30 additions & 12 deletions src/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ IOHANDLE io_current_exe()
#endif
}

typedef struct
struct DBG_LOGGER_DATA
{
DBG_LOGGER logger;
DBG_LOGGER_FINISH finish;
DBG_LOGGER_ASSERTION on_assert = nullptr;
void *user;
} DBG_LOGGER_DATA;
};

static DBG_LOGGER_DATA loggers[16];
static int has_stdout_logger = 0;
Expand Down Expand Up @@ -181,11 +182,21 @@ static NETSOCKET_INTERNAL invalid_socket = {NETTYPE_INVALID, -1, -1, -1};

#define AF_WEBSOCKET_INET (0xee)

static void dbg_assert_notify_loggers()
{
for(int i = 0; i < num_loggers; i++)
{
if(loggers[i].on_assert)
loggers[i].on_assert(loggers[i].user);
}
}

void dbg_assert_imp(const char *filename, int line, int test, const char *msg)
{
if(!test)
{
dbg_msg("assert", "%s(%d): %s", filename, line, msg);
dbg_assert_notify_loggers();
dbg_break();
}
}
Expand Down Expand Up @@ -337,6 +348,13 @@ void dbg_logger(DBG_LOGGER logger, DBG_LOGGER_FINISH finish, void *user)
num_loggers++;
}

void dbg_logger_assertion(DBG_LOGGER logger, DBG_LOGGER_FINISH finish, DBG_LOGGER_ASSERTION on_assert, void *user)
{
dbg_logger(logger, finish, user);

loggers[num_loggers - 1].on_assert = on_assert;
}

void dbg_logger_stdout()
{
#if defined(CONF_FAMILY_WINDOWS)
Expand Down Expand Up @@ -4125,47 +4143,47 @@ int os_version_str(char *version, int length)

#if defined(CONF_EXCEPTION_HANDLING)
#if defined(CONF_FAMILY_WINDOWS)
static HMODULE gs_ExceptionHandlingModule = nullptr;
static HMODULE exception_handling_module = nullptr;
#endif

void init_exception_handler()
{
#if defined(CONF_FAMILY_WINDOWS)
gs_ExceptionHandlingModule = LoadLibraryA("exchndl.dll");
if(gs_ExceptionHandlingModule != nullptr)
exception_handling_module = LoadLibraryA("exchndl.dll");
if(exception_handling_module != nullptr)
{
// Intentional
#ifdef __MINGW32__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-function-type"
#endif
auto pfnExcHndlInit = (void APIENTRY (*)(void *))GetProcAddress(gs_ExceptionHandlingModule, "ExcHndlInit");
auto exc_hndl_init = (void APIENTRY (*)(void *))GetProcAddress(exception_handling_module, "ExcHndlInit");
#ifdef __MINGW32__
#pragma clang diagnostic pop
#endif
void *pExceptionHandlingOffset = (void *)GetModuleHandle(NULL);
pfnExcHndlInit(pExceptionHandlingOffset);
void *exception_handling_offset = (void *)GetModuleHandle(NULL);
exc_hndl_init(exception_handling_offset);
}
#else
#error exception handling not implemented
#endif
}

void set_exception_handler_log_file(const char *pLogFilePath)
void set_exception_handler_log_file(const char *log_file_path)
{
#if defined(CONF_FAMILY_WINDOWS)
if(gs_ExceptionHandlingModule != nullptr)
if(exception_handling_module != nullptr)
{
// Intentional
#ifdef __MINGW32__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-function-type"
#endif
auto pExceptionLogFilePathFunc = (BOOL APIENTRY(*)(const char *))(GetProcAddress(gs_ExceptionHandlingModule, "ExcHndlSetLogFileNameA"));
auto exception_log_file_path_func = (BOOL APIENTRY(*)(const char *))(GetProcAddress(exception_handling_module, "ExcHndlSetLogFileNameA"));
#ifdef __MINGW32__
#pragma clang diagnostic pop
#endif
pExceptionLogFilePathFunc(pLogFilePath);
exception_log_file_path_func(log_file_path);
}
#else
#error exception handling not implemented
Expand Down
5 changes: 4 additions & 1 deletion src/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,9 @@ typedef void (*DBG_LOGGER)(const char *line, void *user);
typedef void (*DBG_LOGGER_FINISH)(void *user);
void dbg_logger(DBG_LOGGER logger, DBG_LOGGER_FINISH finish, void *user);

typedef void (*DBG_LOGGER_ASSERTION)(void *user);
void dbg_logger_assertion(DBG_LOGGER logger, DBG_LOGGER_FINISH finish, DBG_LOGGER_ASSERTION on_assert, void *user);

void dbg_logger_stdout();
void dbg_logger_debugger();
void dbg_logger_file(const char *filename);
Expand Down Expand Up @@ -2361,7 +2364,7 @@ int os_version_str(char *version, int length);

#if defined(CONF_EXCEPTION_HANDLING)
void init_exception_handler();
void set_exception_handler_log_file(const char *pLogFilePath);
void set_exception_handler_log_file(const char *log_file_path);
#endif

#if defined(__cplusplus)
Expand Down
2 changes: 2 additions & 0 deletions src/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class IEngine : public IInterface
class CJobPool m_JobPool;

public:
virtual ~IEngine() = default;

virtual void Init() = 0;
virtual void InitLogfile() = 0;
virtual void AddJob(std::shared_ptr<IJob> pJob) = 0;
Expand Down
54 changes: 54 additions & 0 deletions src/engine/shared/assertion_logger.cpp
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);
}
36 changes: 36 additions & 0 deletions src/engine/shared/assertion_logger.h
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
1 change: 1 addition & 0 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ MACRO_CONFIG_INT(ClPredictFreeze, cl_predict_freeze, 1, 0, 2, CFGFLAG_CLIENT | C
MACRO_CONFIG_INT(ClShowNinja, cl_show_ninja, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show ninja skin")
MACRO_CONFIG_INT(ClShowHookCollOther, cl_show_hook_coll_other, 1, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show other players' hook collision line (2 to always show)")
MACRO_CONFIG_INT(ClShowHookCollOwn, cl_show_hook_coll_own, 1, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show own players' hook collision line (2 to always show)")
MACRO_CONFIG_INT(ClHookCollSize, cl_hook_coll_size, 0, 0, 20, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of hook collision line")

MACRO_CONFIG_COL(ClHookCollColorNoColl, cl_hook_coll_color_no_coll, 65407, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Specifies the color of a hookline that hits nothing.")
MACRO_CONFIG_COL(ClHookCollColorHookableColl, cl_hook_coll_color_hookable_coll, 6401973, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Specifies the color of a hookline that hits hookable tiles.")
Expand Down
22 changes: 19 additions & 3 deletions src/engine/shared/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <engine/shared/network.h>
#include <engine/storage.h>

#include <engine/shared/assertion_logger.h>

CHostLookup::CHostLookup() = default;

CHostLookup::CHostLookup(const char *pHostname, int Nettype)
Expand All @@ -29,6 +31,10 @@ class CEngine : public IEngine
IStorage *m_pStorage;
bool m_Logging;

CAssertionLogger m_AssertionLogger;

char m_aAppName[256];

static void Con_DbgLognetwork(IConsole::IResult *pResult, void *pUserData)
{
CEngine *pEngine = static_cast<CEngine *>(pUserData);
Expand All @@ -53,6 +59,7 @@ class CEngine : public IEngine

CEngine(bool Test, const char *pAppname, bool Silent, int Jobs)
{
str_copy(m_aAppName, pAppname, std::size(m_aAppName));
if(!Test)
{
if(!Silent)
Expand All @@ -79,25 +86,34 @@ class CEngine : public IEngine
m_Logging = false;
}

void Init()
~CEngine() override
{
m_JobPool.Destroy();
}

void Init() override
{
m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pStorage = Kernel()->RequestInterface<IStorage>();

if(!m_pConsole || !m_pStorage)
return;

char aFullPath[IO_MAX_PATH_LENGTH];
m_pStorage->GetCompletePath(IStorage::TYPE_SAVE, "dumps/", aFullPath, sizeof(aFullPath));
m_AssertionLogger.Init(aFullPath, m_aAppName);

m_pConsole->Register("dbg_lognetwork", "", CFGFLAG_SERVER | CFGFLAG_CLIENT, Con_DbgLognetwork, this, "Log the network");
}

void InitLogfile()
void InitLogfile() override
{
// open logfile if needed
if(g_Config.m_Logfile[0])
dbg_logger_file(g_Config.m_Logfile);
}

void AddJob(std::shared_ptr<IJob> pJob)
void AddJob(std::shared_ptr<IJob> pJob) override
{
if(g_Config.m_Debug)
dbg_msg("engine", "job added");
Expand Down
24 changes: 16 additions & 8 deletions src/engine/shared/jobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@ CJobPool::CJobPool()

CJobPool::~CJobPool()
{
m_Shutdown = true;
for(int i = 0; i < m_NumThreads; i++)
sphore_signal(&m_Semaphore);
for(int i = 0; i < m_NumThreads; i++)
if(!m_Shutdown)
{
if(m_apThreads[i])
thread_wait(m_apThreads[i]);
Destroy();
}
lock_destroy(m_Lock);
sphore_destroy(&m_Semaphore);
}

void CJobPool::WorkerThread(void *pUser)
Expand Down Expand Up @@ -86,6 +80,20 @@ void CJobPool::Init(int NumThreads)
m_apThreads[i] = thread_init(WorkerThread, this, "CJobPool worker");
}

void CJobPool::Destroy()
{
m_Shutdown = true;
for(int i = 0; i < m_NumThreads; i++)
sphore_signal(&m_Semaphore);
for(int i = 0; i < m_NumThreads; i++)
{
if(m_apThreads[i])
thread_wait(m_apThreads[i]);
}
lock_destroy(m_Lock);
sphore_destroy(&m_Semaphore);
}

void CJobPool::Add(std::shared_ptr<IJob> pJob)
{
lock_wait(m_Lock);
Expand Down
1 change: 1 addition & 0 deletions src/engine/shared/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CJobPool
~CJobPool();

void Init(int NumThreads);
void Destroy();
void Add(std::shared_ptr<IJob> pJob);
static void RunBlocking(IJob *pJob);
};
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/components/binds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void CBinds::Bind(int KeyID, const char *pStr, bool FreeOnly, int ModifierCombin
str_copy(m_aapKeyBindings[ModifierCombination][KeyID], pStr, Size);
str_format(aBuf, sizeof(aBuf), "bound %s%s (%d) = %s", GetKeyBindModifiersName(ModifierCombination), Input()->KeyName(KeyID), KeyID, m_aapKeyBindings[ModifierCombination][KeyID]);
}
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "binds", aBuf, gs_BindPrintColor);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "binds", aBuf, gs_BindPrintColor);
}

int CBinds::GetModifierMask(IInput *i)
Expand Down
Loading