From 112a4185534097b71bed5bff192f1a6c6fae88ac Mon Sep 17 00:00:00 2001 From: Olion Date: Sun, 20 Aug 2017 15:03:45 +0300 Subject: [PATCH] Avoid CPU- and compiler-dependent part --- src/game/Object/Unit.cpp | 18 ++++++++---------- src/game/Object/UpdateFields.h | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/game/Object/Unit.cpp b/src/game/Object/Unit.cpp index 5bae3d5c8..2d83836de 100644 --- a/src/game/Object/Unit.cpp +++ b/src/game/Object/Unit.cpp @@ -9969,23 +9969,21 @@ void Unit::DisableSpline() bool Unit::IsSchoolAllowed(SpellSchoolMask mask) const { uint32 now = WorldTimer::getMSTime(); - uint32 imask = mask; - while (int i = ffs(imask)) + for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) { - if (m_schoolAllowedSince[i - 1] > now) - return false; - imask &= ~(1 << (i - 1)); + if (mask & (1 << i)) + if (m_schoolAllowedSince[i] > now) + return false; } return true; } -void Unit::ProhibitSpellSchool(SpellSchoolMask idSchoolMask, uint32 unTimeMs) +void Unit::ProhibitSpellSchool(SpellSchoolMask mask, uint32 unTimeMs) { uint32 when = WorldTimer::getMSTime() + unTimeMs; - uint32 imask = idSchoolMask; - while (int i = ffs(imask)) + for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) { - m_schoolAllowedSince[i - 1] = when; - imask &= ~(1 << (i - 1)); + if (mask & (1 << i)) + m_schoolAllowedSince[i] = when; } } diff --git a/src/game/Object/UpdateFields.h b/src/game/Object/UpdateFields.h index 9ab34af84..09e5cc8a4 100644 --- a/src/game/Object/UpdateFields.h +++ b/src/game/Object/UpdateFields.h @@ -461,16 +461,16 @@ enum ECorpseFields }; // Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero -static inline uint32 ffs(const uint32 x) -{ -#ifdef WIN32 - unsigned long r = 0; - if (_BitScanForward(&r, x)) - return uint32(r + 1); - return 0; -#elif - return __builtin_ffs(x); -#endif -} +//static inline uint32 ffs(const uint32 x) +//{ +//#ifdef WIN32 +// unsigned long r = 0; +// if (_BitScanForward(&r, x)) +// return uint32(r + 1); +// return 0; +//#elif +// return __builtin_ffs(x); +//#endif +//} #endif