Merge branch 'master' into jgrpp

# Conflicts:
#	src/company_cmd.cpp
#	src/core/overflowsafe_type.hpp
#	src/economy.cpp
#	src/engine_base.h
#	src/ground_vehicle.cpp
#	src/group_gui.cpp
#	src/industry_cmd.cpp
#	src/industry_gui.cpp
#	src/newgrf_commons.cpp
#	src/newgrf_engine.cpp
#	src/newgrf_industries.cpp
#	src/newgrf_object.cpp
#	src/newgrf_roadstop.cpp
#	src/newgrf_station.cpp
#	src/rail_gui.cpp
#	src/road_cmd.h
#	src/road_gui.cpp
#	src/saveload/afterload.cpp
#	src/script/api/script_log.cpp
#	src/script/api/script_log.hpp
#	src/settings_gui.cpp
#	src/settingsgen/settingsgen.cpp
#	src/station_cmd.cpp
#	src/station_cmd.h
#	src/station_gui.cpp
#	src/strgen/strgen.cpp
#	src/string_func.h
#	src/string_type.h
#	src/table/settings/network_private_settings.ini
#	src/tests/math_func.cpp
#	src/textfile_gui.cpp
#	src/timetable_gui.cpp
#	src/town_cmd.cpp
#	src/vehicle.cpp
#	src/waypoint_cmd.cpp
#	src/waypoint_cmd.h
#	src/widgets/dropdown.cpp
This commit is contained in:
Jonathan G Rennison
2023-06-03 19:16:42 +01:00
101 changed files with 987 additions and 964 deletions

View File

@@ -8,6 +8,7 @@
/** @file script_log.cpp Implementation of ScriptLog. */
#include "../../stdafx.h"
#include "script_log_types.hpp"
#include "script_log.hpp"
#include "../../core/alloc_func.hpp"
#include "../../debug.h"
@@ -18,80 +19,50 @@
/* static */ void ScriptLog::Info(const char *message)
{
ScriptLog::Log(LOG_INFO, message);
ScriptLog::Log(ScriptLogTypes::LOG_INFO, message);
}
/* static */ void ScriptLog::Warning(const char *message)
{
ScriptLog::Log(LOG_WARNING, message);
ScriptLog::Log(ScriptLogTypes::LOG_WARNING, message);
}
/* static */ void ScriptLog::Error(const char *message)
{
ScriptLog::Log(LOG_ERROR, message);
ScriptLog::Log(ScriptLogTypes::LOG_ERROR, message);
}
/* static */ void ScriptLog::Log(ScriptLog::ScriptLogType level, const char *message)
/* static */ void ScriptLog::Log(ScriptLogTypes::ScriptLogType level, const char *message)
{
if (ScriptObject::GetLogPointer() == nullptr) {
ScriptObject::GetLogPointer() = new LogData();
LogData *log = (LogData *)ScriptObject::GetLogPointer();
ScriptLogTypes::LogData &logdata = ScriptObject::GetLogData();
log->lines = CallocT<char *>(400);
log->type = CallocT<ScriptLog::ScriptLogType>(400);
log->count = 400;
log->pos = log->count - 1;
log->used = 0;
}
LogData *log = (LogData *)ScriptObject::GetLogPointer();
/* Limit the log to 400 lines. */
if (logdata.size() >= 400U) logdata.pop_front();
/* Go to the next log-line */
log->pos = (log->pos + 1) % log->count;
if (log->used != log->count) log->used++;
/* Free last message, and write new message */
free(log->lines[log->pos]);
log->lines[log->pos] = stredup(message);
log->type[log->pos] = level;
auto &line = logdata.emplace_back();
line.type = level;
/* Cut string after first \n */
char *p;
while ((p = strchr(log->lines[log->pos], '\n')) != nullptr) {
*p = '\0';
break;
}
const char *newline = strchr(message, '\n');
line.text = std::string(message, 0, newline == nullptr ? strlen(message) : newline - message);
char logc;
switch (level) {
case LOG_SQ_ERROR: logc = 'S'; break;
case LOG_ERROR: logc = 'E'; break;
case LOG_SQ_INFO: logc = 'P'; break;
case LOG_WARNING: logc = 'W'; break;
case LOG_INFO: logc = 'I'; break;
default: logc = '?'; break;
case ScriptLogTypes::LOG_SQ_ERROR: logc = 'S'; break;
case ScriptLogTypes::LOG_ERROR: logc = 'E'; break;
case ScriptLogTypes::LOG_SQ_INFO: logc = 'P'; break;
case ScriptLogTypes::LOG_WARNING: logc = 'W'; break;
case ScriptLogTypes::LOG_INFO: logc = 'I'; break;
default: logc = '?'; break;
}
/* Also still print to debug window */
DEBUG(script, level, "[%d] [%c] %s", (uint)ScriptObject::GetRootCompany(), logc, log->lines[log->pos]);
DEBUG(script, level, "[%d] [%c] %s", (uint)ScriptObject::GetRootCompany(), logc, line.text.c_str());
InvalidateWindowData(WC_SCRIPT_DEBUG, 0, ScriptObject::GetRootCompany());
}
/* static */ void ScriptLog::FreeLogPointer()
{
LogData *log = (LogData *)ScriptObject::GetLogPointer();
for (int i = 0; i < log->count; i++) {
free(log->lines[i]);
}
free(log->lines);
free(log->type);
delete log;
}
/* static */ void ScriptLog::LogOnce(ScriptLog::ScriptLogType level, std::string &&message)
/* static */ void ScriptLog::LogOnce(ScriptLogTypes::ScriptLogType level, std::string &&message)
{
if (ScriptObject::IsNewUniqueLogMessage(message)) {
ScriptLog::Log(level, message.c_str());