diff --git a/include/vstd/CLoggerBase.h b/include/vstd/CLoggerBase.h index 546b3d352..a1cf6edba 100644 --- a/include/vstd/CLoggerBase.h +++ b/include/vstd/CLoggerBase.h @@ -193,5 +193,6 @@ extern DLL_LINKAGE vstd::CLoggerBase * logNetwork; extern DLL_LINKAGE vstd::CLoggerBase * logAi; extern DLL_LINKAGE vstd::CLoggerBase * logAnim; extern DLL_LINKAGE vstd::CLoggerBase * logMod; +extern DLL_LINKAGE vstd::CLoggerBase * logRng; VCMI_LIB_NAMESPACE_END diff --git a/lib/CRandomGenerator.cpp b/lib/CRandomGenerator.cpp index 3a7ac2320..0cec4fa31 100644 --- a/lib/CRandomGenerator.cpp +++ b/lib/CRandomGenerator.cpp @@ -15,21 +15,25 @@ VCMI_LIB_NAMESPACE_BEGIN CRandomGenerator::CRandomGenerator() { + logRng->trace("CRandomGenerator constructed"); resetSeed(); } CRandomGenerator::CRandomGenerator(int seed) { + logRng->trace("CRandomGenerator constructed (%d)", seed); setSeed(seed); } void CRandomGenerator::setSeed(int seed) { + logRng->trace("CRandomGenerator::setSeed (%d)", seed); rand.seed(seed); } void CRandomGenerator::resetSeed() { + logRng->trace("CRandomGenerator::resetSeed"); boost::hash stringHash; auto threadIdHash = stringHash(boost::lexical_cast(boost::this_thread::get_id())); setSeed(static_cast(threadIdHash * std::time(nullptr))); @@ -37,16 +41,20 @@ void CRandomGenerator::resetSeed() int CRandomGenerator::nextInt(int upper) { + logRng->trace("CRandomGenerator::nextInt (%d)", upper); return nextInt(0, upper); } int64_t CRandomGenerator::nextInt64(int64_t upper) { + logRng->trace("CRandomGenerator::nextInt64 (%d)", upper); return nextInt64(0, upper); } int CRandomGenerator::nextInt(int lower, int upper) { + logRng->trace("CRandomGenerator::nextInt64 (%d, %d)", lower, upper); + if (lower > upper) throw std::runtime_error("Invalid range provided: " + std::to_string(lower) + " ... " + std::to_string(upper)); @@ -55,17 +63,20 @@ int CRandomGenerator::nextInt(int lower, int upper) int CRandomGenerator::nextInt() { + logRng->trace("CRandomGenerator::nextInt64"); return TIntDist()(rand); } int CRandomGenerator::nextBinomialInt(int coinsCount, double coinChance) { + logRng->trace("CRandomGenerator::nextBinomialInt (%d, %f)", coinsCount, coinChance); std::binomial_distribution<> distribution(coinsCount, coinChance); return distribution(rand); } int64_t CRandomGenerator::nextInt64(int64_t lower, int64_t upper) { + logRng->trace("CRandomGenerator::nextInt64 (%d, %d)", lower, upper); if (lower > upper) throw std::runtime_error("Invalid range provided: " + std::to_string(lower) + " ... " + std::to_string(upper)); @@ -74,11 +85,13 @@ int64_t CRandomGenerator::nextInt64(int64_t lower, int64_t upper) double CRandomGenerator::nextDouble(double upper) { + logRng->trace("CRandomGenerator::nextDouble (%f)", upper); return nextDouble(0, upper); } double CRandomGenerator::nextDouble(double lower, double upper) { + logRng->trace("CRandomGenerator::nextDouble (%f, %f)", lower, upper); if(lower > upper) throw std::runtime_error("Invalid range provided: " + std::to_string(lower) + " ... " + std::to_string(upper)); diff --git a/lib/logging/CLogger.cpp b/lib/logging/CLogger.cpp index 6d7c43ed3..e33c6425e 100644 --- a/lib/logging/CLogger.cpp +++ b/lib/logging/CLogger.cpp @@ -96,6 +96,7 @@ DLL_LINKAGE vstd::CLoggerBase * logNetwork = CLogger::getLogger(CLoggerDomain("n DLL_LINKAGE vstd::CLoggerBase * logAi = CLogger::getLogger(CLoggerDomain("ai")); DLL_LINKAGE vstd::CLoggerBase * logAnim = CLogger::getLogger(CLoggerDomain("animation")); DLL_LINKAGE vstd::CLoggerBase * logMod = CLogger::getLogger(CLoggerDomain("mod")); +DLL_LINKAGE vstd::CLoggerBase * logRng = CLogger::getLogger(CLoggerDomain("rng")); CLogger * CLogger::getLogger(const CLoggerDomain & domain) {