Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138465 additions and 70987 deletions

View File

@@ -12,7 +12,7 @@
#include "cpu.h"
#include <chrono>
#include "3rdparty/fmt/format.h"
#include "core/format.hpp"
/* Debugging messages policy:
* These should be the severities used for direct Debug() calls
@@ -30,12 +30,12 @@
/**
* Ouptut a line of debugging information.
* @param name The category of debug information.
* @param category The category of debug information.
* @param level The maximum debug level this message should be shown at. When the debug level for this category is set lower, then the message will not be shown.
* @param format_string The formatting string of the message.
*/
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) DebugPrint(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
void DebugPrint(const char *level, const std::string &message);
#define Debug(category, level, format_string, ...) do { if ((level) == 0 || _debug_ ## category ## _level >= (level)) DebugPrint(#category, level, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)); } while (false)
void DebugPrint(const char *category, int level, const std::string &message);
extern int _debug_driver_level;
extern int _debug_grf_level;
@@ -56,71 +56,50 @@ extern int _debug_console_level;
extern int _debug_random_level;
#endif
char *DumpDebugFacilityNames(char *buf, char *last);
void SetDebugString(const char *s, void (*error_func)(const char *));
const char *GetDebugString();
void DumpDebugFacilityNames(std::back_insert_iterator<std::string> &output_iterator);
void SetDebugString(const char *s, void (*error_func)(const std::string &));
std::string GetDebugString();
/* Shorter form for passing filename and linenumber */
#define FILE_LINE __FILE__, __LINE__
/* Used for profiling
*
/** TicToc profiling.
* Usage:
* TIC();
* --Do your code--
* TOC("A name", 1);
*
* When you run the TIC() / TOC() multiple times, you can increase the '1'
* to only display average stats every N values. Some things to know:
*
* for (int i = 0; i < 5; i++) {
* TIC();
* --Do your code--
* TOC("A name", 5);
* }
*
* Is the correct usage for multiple TIC() / TOC() calls.
*
* TIC() / TOC() creates its own block, so make sure not the mangle
* it with another block.
*
* The output is counted in CPU cycles, and not comparable across
* machines. Mainly useful for local optimisations.
**/
#define TIC() {\
uint64 _xxx_ = ottd_rdtsc();\
static uint64 _sum_ = 0;\
static uint32 _i_ = 0;
* static TicToc::State state("A name", 1);
* TicToc tt(state);
* --Do your code--
*/
struct TicToc {
/** Persistent state for TicToc profiling. */
struct State {
const std::string_view name;
const uint32_t max_count;
uint32_t count = 0;
uint64_t chrono_sum = 0;
#define TOC(str, count)\
_sum_ += ottd_rdtsc() - _xxx_;\
if (++_i_ == count) {\
Debug(misc, 0, "[{}] {} [avg: {:.1f}]", str, _sum_, _sum_/(double)_i_);\
_i_ = 0;\
_sum_ = 0;\
}\
}
constexpr State(std::string_view name, uint32_t max_count) : name(name), max_count(max_count) { }
};
/* Chrono based version. The output is in microseconds. */
#define TICC() {\
auto _start_ = std::chrono::high_resolution_clock::now();\
static uint64 _sum_ = 0;\
static uint32 _i_ = 0;
State &state;
std::chrono::high_resolution_clock::time_point chrono_start; ///< real time count.
#define TOCC(str, _count_)\
_sum_ += (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - _start_)).count();\
if (++_i_ == _count_) {\
Debug(misc, 0, "[{}] {} us [avg: {:.1f} us]", str, _sum_, _sum_/(double)_i_);\
_i_ = 0;\
_sum_ = 0;\
}\
}
inline TicToc(State &state) : state(state), chrono_start(std::chrono::high_resolution_clock::now()) { }
inline ~TicToc()
{
this->state.chrono_sum += (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - this->chrono_start)).count();
if (++this->state.count == this->state.max_count) {
Debug(misc, 0, "[{}] {} us [avg: {:.1f} us]", this->state.name, this->state.chrono_sum, this->state.chrono_sum / static_cast<double>(this->state.count));
this->state.count = 0;
this->state.chrono_sum = 0;
}
}
};
void ShowInfo(const char *str);
void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
void ShowInfoI(const std::string &str);
#define ShowInfo(format_string, ...) ShowInfoI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
const char *GetLogPrefix();
std::string GetLogPrefix(bool force = false);
void DebugSendRemoteMessages();
void DebugReconsiderSendRemoteMessages();