aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorccrs <ccrs@users.noreply.github.com>2019-04-16 23:29:04 +0200
committerccrs <ccrs@users.noreply.github.com>2019-04-16 23:29:04 +0200
commit11de6b5f866e087307a719b931be8c51b984c54e (patch)
tree85a38751df910e22102ec15981e3bc87754d06c7 /src
parent8e286f91b91a73203ee47e859f0ddf3f55ab6bd5 (diff)
Core/Movement: implement and use new remove method in MotionMaster
All erases within MotionMaster are now done by itr. Previous impl used value erase which uses the custom comparator which does not identify elements uniquely --> wrong values were deleted ref #23187#discussion_r275791179
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Movement/MotionMaster.cpp42
-rw-r--r--src/server/game/Movement/MotionMaster.h3
2 files changed, 17 insertions, 28 deletions
diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp
index 50ab36fba84..b89a5aad293 100644
--- a/src/server/game/Movement/MotionMaster.cpp
+++ b/src/server/game/Movement/MotionMaster.cpp
@@ -363,12 +363,7 @@ void MotionMaster::Remove(MovementGenerator* movement, MovementSlot slot/* = MOT
{
auto itr = _generators.find(movement);
if (itr != _generators.end())
- {
- MovementGenerator* pointer = *itr;
- bool const top = GetCurrentMovementGenerator() == pointer;
- _generators.erase(pointer);
- Delete(pointer, top, false);
- }
+ Remove(itr, GetCurrentMovementGenerator() == *itr, false);
}
break;
default:
@@ -409,12 +404,7 @@ void MotionMaster::Remove(MovementGeneratorType type, MovementSlot slot/* = MOTI
});
if (itr != _generators.end())
- {
- MovementGenerator* pointer = *itr;
- bool const top = GetCurrentMovementGenerator() == pointer;
- _generators.erase(pointer);
- Delete(pointer, top, false);
- }
+ Remove(itr, GetCurrentMovementGenerator() == *itr, false);
}
break;
default:
@@ -1024,13 +1014,18 @@ void MotionMaster::LaunchMoveSpline(Movement::MoveSplineInit&& init, uint32 id/*
/******************** Private methods ********************/
-void MotionMaster::Pop(bool active, bool movementInform)
+void MotionMaster::Remove(MotionMasterContainer::iterator iterator, bool active, bool movementInform)
{
- MovementGenerator* pointer = *_generators.begin();
- _generators.erase(pointer);
+ MovementGenerator* pointer = *iterator;
+ _generators.erase(iterator);
Delete(pointer, active, movementInform);
}
+void MotionMaster::Pop(bool active, bool movementInform)
+{
+ Remove(_generators.begin(), active, movementInform);
+}
+
void MotionMaster::DirectInitialize()
{
// Clear ALL movement generators (including default)
@@ -1125,14 +1120,11 @@ void MotionMaster::DirectAdd(MovementGenerator* movement, MovementSlot slot/* =
{
if (movement->Priority >= (*_generators.begin())->Priority)
{
- MovementGenerator* pointer = *_generators.begin();
- if (movement->Priority == pointer->Priority)
- {
- _generators.erase(pointer);
- Delete(pointer, true, false);
- }
+ auto itr = _generators.begin();
+ if (movement->Priority == (*itr)->Priority)
+ Remove(itr, true, false);
else
- pointer->Deactivate(_owner);
+ (*itr)->Deactivate(_owner);
}
else
{
@@ -1142,11 +1134,7 @@ void MotionMaster::DirectAdd(MovementGenerator* movement, MovementSlot slot/* =
});
if (itr != _generators.end())
- {
- MovementGenerator* pointer = *itr;
- _generators.erase(pointer);
- Delete(pointer, false, false);
- }
+ Remove(itr, false, false);
}
}
else
diff --git a/src/server/game/Movement/MotionMaster.h b/src/server/game/Movement/MotionMaster.h
index 5f89f2304da..e8aaf8f86b7 100644
--- a/src/server/game/Movement/MotionMaster.h
+++ b/src/server/game/Movement/MotionMaster.h
@@ -122,7 +122,7 @@ class TC_GAME_API MotionMaster
// Removes first found movement
// NOTE: MOTION_SLOT_DEFAULT will be autofilled with IDLE_MOTION_TYPE
void Remove(MovementGeneratorType type, MovementSlot slot = MOTION_SLOT_ACTIVE);
- // NOTE: NOTE: MOTION_SLOT_DEFAULT wont be affected
+ // NOTE: MOTION_SLOT_DEFAULT wont be affected
void Clear();
// Removes all movements for the given MovementSlot
// NOTE: MOTION_SLOT_DEFAULT will be autofilled with IDLE_MOTION_TYPE
@@ -188,6 +188,7 @@ class TC_GAME_API MotionMaster
bool HasFlag(uint8 const flag) const { return (_flags & flag) != 0; }
void RemoveFlag(uint8 const flag) { _flags &= ~flag; }
+ void Remove(MotionMasterContainer::iterator iterator, bool active, bool movementInform);
void Pop(bool active, bool movementInform);
void DirectInitialize();
void DirectClear();