Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core/Movement: Add new SplineChainMovementGenerator that allows accur…
…ate replication of sniffed waypoints in static sequences, along with DB facilities that allow loading of waypoints from DB. (cherry picked from commit 6d00d3f) Merge remote-tracking branch 'Treeston/3.3.5-splinechains' into 3.3.5 (PR #17946) (cherry picked from commit 20f4839) Core/Movement: Add a convenience default ctor to SplineChainResumeInfo, and fix PCH build in some configurations (zzz why do we even keep Appveyor and Travis around). (cherry picked from commit 4fa646c) PCH build fix. Again. (( Alright, you made me waste 20 minutes of my life on a full nonPCH rebuild of the core now. )) (( I hope you're happy. )) (cherry picked from commit 4a1a460)
- Loading branch information
1 parent
9aa4b6d
commit 59d48ce
Showing
12 changed files
with
401 additions
and
21 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
sql/updates/world/master/2017_03_01_07_world_2016_09_20_00_world.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- add tables for spline chain DB storage | ||
DROP TABLE IF EXISTS `script_spline_chain_meta`; | ||
CREATE TABLE `script_spline_chain_meta` ( | ||
`entry` INT UNSIGNED NOT NULL, | ||
`chainId` TINYINT UNSIGNED NOT NULL, | ||
`splineId` TINYINT UNSIGNED NOT NULL, | ||
`expectedDuration` INT UNSIGNED NOT NULL, | ||
`msUntilNext` INT UNSIGNED NOT NULL, | ||
PRIMARY KEY USING BTREE (`entry`,`chainId`,`splineId`) | ||
); | ||
DROP TABLE IF EXISTS `script_spline_chain_waypoints`; | ||
CREATE TABLE `script_spline_chain_waypoints` ( | ||
`entry` INT UNSIGNED NOT NULL, | ||
`chainId` TINYINT UNSIGNED NOT NULL, | ||
`splineId` TINYINT UNSIGNED NOT NULL, | ||
`wpId` TINYINT UNSIGNED NOT NULL, | ||
`x` FLOAT NOT NULL, | ||
`y` FLOAT NOT NULL, | ||
`z` FLOAT NOT NULL, | ||
PRIMARY KEY USING BTREE (`entry`,`chainId`,`splineId`,`wpId`) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/server/game/Movement/MovementGenerators/SplineChainMovementGenerator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "SplineChainMovementGenerator.h" | ||
#include "Creature.h" | ||
#include "CreatureAI.h" | ||
#include "MoveSplineInit.h" | ||
#include "MoveSpline.h" | ||
#include "Log.h" | ||
|
||
uint32 SplineChainMovementGenerator::SendPathSpline(Unit* me, Movement::PointsArray const& wp) const | ||
{ | ||
uint32 numWp = wp.size(); | ||
ASSERT(numWp > 1 && "Every path must have source & destination"); | ||
Movement::MoveSplineInit init(me); | ||
if (numWp > 2) | ||
init.MovebyPath(wp); | ||
else | ||
init.MoveTo(wp[1], false, true); | ||
init.SetWalk(_walk); | ||
return init.Launch(); | ||
} | ||
|
||
void SplineChainMovementGenerator::SendSplineFor(Unit* me, uint32 index, uint32& toNext) | ||
{ | ||
ASSERT(index < _chainSize); | ||
TC_LOG_DEBUG("movement.splinechain", "%s: Sending spline for %u.", me->GetGUID().ToString().c_str(), index); | ||
|
||
SplineChainLink const& thisLink = _chain[index]; | ||
uint32 actualDuration = SendPathSpline(me, thisLink.Points); | ||
if (actualDuration != thisLink.ExpectedDuration) | ||
{ | ||
TC_LOG_DEBUG("movement.splinechain", "%s: Sent spline for %u, duration is %u ms. Expected was %u ms (delta %d ms). Adjusting.", me->GetGUID().ToString().c_str(), index, actualDuration, thisLink.ExpectedDuration, int32(actualDuration) - int32(thisLink.ExpectedDuration)); | ||
toNext = uint32(double(actualDuration)/double(thisLink.ExpectedDuration) * toNext); | ||
} | ||
else | ||
{ | ||
TC_LOG_DEBUG("movement.splinechain", "%s: Sent spline for %u, duration is %u ms.", me->GetGUID().ToString().c_str(), index, actualDuration); | ||
} | ||
} | ||
|
||
void SplineChainMovementGenerator::Initialize(Unit* me) | ||
{ | ||
if (_chainSize) | ||
{ | ||
if (_nextFirstWP) // this is a resumed movegen that has to start with a partial spline | ||
{ | ||
if (finished) | ||
return; | ||
SplineChainLink const& thisLink = _chain[_nextIndex]; | ||
if (_nextFirstWP >= thisLink.Points.size()) | ||
{ | ||
TC_LOG_ERROR("movement.splinechain", "%s: Attempted to resume spline chain from invalid resume state (%u, %u).", me->GetGUID().ToString().c_str(), _nextIndex, _nextFirstWP); | ||
_nextFirstWP = thisLink.Points.size()-1; | ||
} | ||
Movement::PointsArray partial(thisLink.Points.begin() + (_nextFirstWP-1), thisLink.Points.end()); | ||
SendPathSpline(me, partial); | ||
TC_LOG_DEBUG("movement.splinechain", "%s: Resumed spline chain generator from resume state.", me->GetGUID().ToString().c_str()); | ||
++_nextIndex; | ||
if (!_msToNext) | ||
_msToNext = 1; | ||
_nextFirstWP = 0; | ||
} | ||
else | ||
{ | ||
_msToNext = std::max(_chain[_nextIndex].TimeToNext, 1u); | ||
SendSplineFor(me, _nextIndex, _msToNext); | ||
++_nextIndex; | ||
if (_nextIndex >= _chainSize) | ||
_msToNext = 0; | ||
} | ||
} | ||
else | ||
{ | ||
TC_LOG_ERROR("movement", "SplineChainMovementGenerator::Initialize - empty spline chain passed for %s.", me->GetGUID().ToString().c_str()); | ||
} | ||
} | ||
|
||
void SplineChainMovementGenerator::Finalize(Unit* me) | ||
{ | ||
if (!finished) | ||
return; | ||
Creature* cMe = me->ToCreature(); | ||
if (cMe && cMe->IsAIEnabled) | ||
cMe->AI()->MovementInform(SPLINE_CHAIN_MOTION_TYPE, _id); | ||
} | ||
|
||
bool SplineChainMovementGenerator::Update(Unit* me, uint32 diff) | ||
{ | ||
if (finished) | ||
return false; | ||
|
||
// _msToNext being zero here means we're on the final spline | ||
if (!_msToNext) | ||
{ | ||
finished = me->movespline->Finalized(); | ||
return !finished; | ||
} | ||
|
||
if (_msToNext <= diff) | ||
{ | ||
// Send next spline | ||
TC_LOG_DEBUG("movement.splinechain", "%s: Should send spline %u (%u ms late).", me->GetGUID().ToString().c_str(), _nextIndex, diff - _msToNext); | ||
_msToNext = std::max(_chain[_nextIndex].TimeToNext, 1u); | ||
SendSplineFor(me, _nextIndex, _msToNext); | ||
++_nextIndex; | ||
if (_nextIndex >= _chainSize) | ||
{ | ||
// We have reached the final spline, once it finalizes we should also finalize the movegen (start checking on next update) | ||
_msToNext = 0; | ||
return true; | ||
} | ||
} | ||
else | ||
_msToNext -= diff; | ||
return true; | ||
} | ||
|
||
SplineChainResumeInfo SplineChainMovementGenerator::GetResumeInfo(Unit const* me) const | ||
{ | ||
if (!_nextIndex) | ||
return SplineChainResumeInfo(_id, &_chain, _walk, 0, 0, _msToNext); | ||
if (me->movespline->Finalized()) | ||
return SplineChainResumeInfo(_id, &_chain, _walk, _nextIndex, 0, 1u); | ||
return SplineChainResumeInfo(_id, &_chain, _walk, uint8(_nextIndex - 1), uint8(me->movespline->_currentSplineIdx()), _msToNext); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/server/game/Movement/MovementGenerators/SplineChainMovementGenerator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef TRINITY_SPLINECHAINMOVEMENTGENERATOR_H | ||
#define TRINITY_SPLINECHAINMOVEMENTGENERATOR_H | ||
|
||
#include "SplineChain.h" | ||
#include "MovementGenerator.h" | ||
|
||
class TC_GAME_API SplineChainMovementGenerator : public MovementGenerator | ||
{ | ||
public: | ||
explicit SplineChainMovementGenerator(uint32 id, SplineChain const& chain, bool walk = false) : _id(id), _chain(chain), _chainSize(chain.size()), _walk(walk), finished(false), _nextIndex(0), _nextFirstWP(0), _msToNext(0) { } | ||
explicit SplineChainMovementGenerator(SplineChainResumeInfo const& info) : _id(info.PointID), _chain(*info.Chain), _chainSize(info.Chain->size()), _walk(info.IsWalkMode), finished(info.SplineIndex >= info.Chain->size()), _nextIndex(info.SplineIndex), _nextFirstWP(info.PointIndex), _msToNext(info.TimeToNext) { } | ||
void Initialize(Unit* me) override; | ||
void Finalize(Unit* me) override; | ||
void Reset(Unit* /*me*/) override { }; | ||
bool Update(Unit* me, uint32 diff) override; | ||
MovementGeneratorType GetMovementGeneratorType() const override { return SPLINE_CHAIN_MOTION_TYPE; } | ||
// Builds info that can later be used to resume this spline chain movement at the current position | ||
SplineChainResumeInfo GetResumeInfo(Unit const* me) const; | ||
|
||
private: | ||
void SendSplineFor(Unit* me, uint32 index, uint32& toNext); | ||
uint32 SendPathSpline(Unit* me, Movement::PointsArray const& wp) const; | ||
uint32 const _id; | ||
SplineChain const& _chain; | ||
uint8 const _chainSize; | ||
bool const _walk; | ||
bool finished; | ||
uint8 _nextIndex; | ||
uint8 _nextFirstWP; // only used for resuming | ||
uint32 _msToNext; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef TRINITY_SPLINECHAIN_H | ||
#define TRINITY_SPLINECHAIN_H | ||
|
||
#include "MoveSplineInitArgs.h" | ||
|
||
struct TC_GAME_API SplineChainLink | ||
{ | ||
SplineChainLink(Movement::PointsArray const& points, uint32 expectedDuration, uint32 msToNext) : Points(points), ExpectedDuration(expectedDuration), TimeToNext(msToNext) { } | ||
template <typename iteratorType> SplineChainLink(iteratorType begin, iteratorType end, uint32 expectedDuration, uint32 msToNext) : Points(begin, end), ExpectedDuration(expectedDuration), TimeToNext(msToNext) { } | ||
SplineChainLink(uint32 expectedDuration, uint32 msToNext) : Points(), ExpectedDuration(expectedDuration), TimeToNext(msToNext) { } | ||
Movement::PointsArray Points; | ||
uint32 ExpectedDuration; | ||
uint32 TimeToNext; | ||
}; | ||
typedef std::vector<SplineChainLink> SplineChain; | ||
|
||
struct TC_GAME_API SplineChainResumeInfo | ||
{ | ||
SplineChainResumeInfo() : PointID(0), Chain(nullptr), IsWalkMode(false), SplineIndex(0), PointIndex(0), TimeToNext(0) { } | ||
SplineChainResumeInfo(uint32 id, SplineChain const* chain, bool walk, uint8 splineIndex, uint8 wpIndex, uint32 msToNext) : | ||
PointID(id), Chain(chain), IsWalkMode(walk), SplineIndex(splineIndex), PointIndex(wpIndex), TimeToNext(msToNext) { } | ||
uint32 PointID; | ||
SplineChain const* Chain; | ||
bool IsWalkMode; | ||
uint8 SplineIndex; | ||
uint8 PointIndex; | ||
uint32 TimeToNext; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
59d48ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any description what is this?
i know that it's the 4th wp system...
59d48ce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check #17946