Skip to content

Commit

Permalink
Avoid CPU- and compiler-dependent part
Browse files Browse the repository at this point in the history
  • Loading branch information
Olion17 authored and billy1arm committed Aug 21, 2017
1 parent 22da350 commit 112a418
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
18 changes: 8 additions & 10 deletions src/game/Object/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
22 changes: 11 additions & 11 deletions src/game/Object/UpdateFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 112a418

Please sign in to comment.