lua版本
--按位与取反
--tbTeTile[layer]["Block"] &= ~(TB_BASE_TEX_INDEX[k])
function g_bitAndNot(a, b)
return bit._and(a, bit._not(b))
end
--按位或
--tbTeTile[layer]["Block"] |= TB_BASE_TEX_INDEX[k]
function g_bitOr(a, b)
return bit._or(a, b)
end
WOW服务器C++版本中的
//关于与取反的设置 技能相关 暴雪很多运算都与此相关
void Object::SetFlag(uint16 index, uint32 newFlag)
{
ASSERT(index < m_valuesCount || PrintIndexError(index, true));
uint32 oldval = m_uint32Values[index];
uint32 newval = oldval | newFlag;
if (oldval != newval)
{
m_uint32Values[index] = newval;
_changesMask.SetBit(index);
AddToObjectUpdateIfNeeded();
}
}
void Object::RemoveFlag(uint16 index, uint32 oldFlag)
{
ASSERT(index < m_valuesCount || PrintIndexError(index, true));
ASSERT(m_uint32Values);
uint32 oldval = m_uint32Values[index];
uint32 newval = oldval & ~oldFlag;
if (oldval != newval)
{
m_uint32Values[index] = newval;
_changesMask.SetBit(index);
AddToObjectUpdateIfNeeded();
}
}
void Object::ToggleFlag(uint16 index, uint32 flag)
{
if (HasFlag(index, flag))
{
RemoveFlag(index, flag);
}
else
{
SetFlag(index, flag);
}
}
[[nodiscard]] bool Object::HasFlag(uint16 index, uint32 flag) const
{
if (index >= m_valuesCount && !PrintIndexError(index, false))
{
return false;
}
return (m_uint32Values[index] & flag) != 0;
}
void Object::ApplyModFlag(uint16 index, uint32 flag, bool apply)
{
if (apply)
{
SetFlag(index, flag);
}
else
{
RemoveFlag(index, flag);
}
}
void Object::SetByteFlag(uint16 index, uint8 offset, uint8 newFlag)
{
ASSERT(index < m_valuesCount || PrintIndexError(index, true));
if (offset > 3)
{
LOG_ERROR("entities.object", "Object::SetByteFlag: wrong offset {}", offset);
return;
}
if (!(uint8(m_uint32Values[index] >> (offset * 8)) & newFlag))
{
m_uint32Values[index] |= uint32(uint32(newFlag) << (offset * 8));
_changesMask.SetBit(index);
AddToObjectUpdateIfNeeded();
}
}
void Object::RemoveByteFlag(uint16 index, uint8 offset, uint8 oldFlag)
{
ASSERT(index < m_valuesCount || PrintIndexError(index, true));
if (offset > 3)
{
LOG_ERROR("entities.object", "Object::RemoveByteFlag: wrong offset {}", offset);
return;
}
if (uint8(m_uint32Values[index] >> (offset * 8)) & oldFlag)
{
m_uint32Values[index] &= ~uint32(uint32(oldFlag) << (offset * 8));
_changesMask.SetBit(index);
AddToObjectUpdateIfNeeded();
}
}
[[nodiscard]] bool Object::HasByteFlag(uint16 index, uint8 offset, uint8 flag) const
{
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
ASSERT(offset < 4);
return (((uint8*) &m_uint32Values[index])[offset] & flag) != 0;
}
void Object::SetFlag64(uint16 index, uint64 newFlag)
{
uint64 oldval = GetUInt64Value(index);
uint64 newval = oldval | newFlag;
SetUInt64Value(index, newval);
}
void Object::RemoveFlag64(uint16 index, uint64 oldFlag)
{
uint64 oldval = GetUInt64Value(index);
uint64 newval = oldval & ~oldFlag;
SetUInt64Value(index, newval);
}
void Object::ToggleFlag64(uint16 index, uint64 flag)
{
if (HasFlag64(index, flag))
{
RemoveFlag64(index, flag);
}
else
{
SetFlag64(index, flag);
}
}
[[nodiscard]] bool Object::HasFlag64(uint16 index, uint64 flag) const
{
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
return (GetUInt64Value(index) & flag) != 0;
}
void Object::ApplyModFlag64(uint16 index, uint64 flag, bool apply)
{
if (apply)
{
SetFlag64(index, flag);
}
else
{
RemoveFlag64(index, flag);
}
}
网友评论