TrinityCore
Loading...
Searching...
No Matches
TransportMgr.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRANSPORTMGR_H
19#define TRANSPORTMGR_H
20
21#include "DBCStores.h"
22#include "ObjectGuid.h"
23#include <memory>
24
25struct KeyFrame;
28class Transport;
29class Map;
30
31namespace Movement
32{
33 template <typename length_type> class Spline;
34}
35
37typedef std::vector<KeyFrame> KeyFrameVec;
38typedef std::unordered_map<uint32, TransportTemplate> TransportTemplates;
39typedef std::set<Transport*> TransportSet;
40typedef std::unordered_map<uint32, TransportSet> TransportMap;
41typedef std::unordered_map<uint32, std::set<uint32> > TransportInstanceMap;
42
44{
45 explicit KeyFrame(TaxiPathNodeEntry const* node) : Index(0), Node(node), InitialOrientation(0.0f),
46 DistSinceStop(-1.0f), DistUntilStop(-1.0f), DistFromPrev(-1.0f), TimeFrom(0.0f), TimeTo(0.0f),
47 Teleport(false), ArriveTime(0), DepartureTime(0), Spline(nullptr), NextDistFromPrev(0.0f), NextArriveTime(0)
48 {
49 }
50
57 float TimeFrom;
58 float TimeTo;
62 std::shared_ptr<TransportSpline> Spline;
63
64 // Data needed for next frame
67
68 bool IsTeleportFrame() const { return Teleport; }
69 bool IsStopFrame() const { return Node->Flags == 2; }
70};
71
85
86typedef std::map<uint32, TransportAnimationEntry const*> TransportPathContainer;
87typedef std::map<uint32, TransportRotationEntry const*> TransportPathRotationContainer;
88
90{
91 TransportAnimation() : TotalTime(0) { }
92
96
97 TransportAnimationEntry const* GetAnimNode(uint32 time) const;
98 TransportRotationEntry const* GetAnimRotation(uint32 time) const;
99};
100
101typedef std::map<uint32, TransportAnimation> TransportAnimationContainer;
102
104{
105 public:
106 static TransportMgr* instance();
107
108 void Unload();
109
110 void LoadTransportTemplates();
111
112 void LoadTransportAnimationAndRotation();
113
114 // Creates a transport using given GameObject template entry
115 Transport* CreateTransport(uint32 entry, ObjectGuid::LowType guid = 0, Map* map = nullptr);
116
117 // Spawns all continent transports, used at core startup
118 void SpawnContinentTransports();
119
120 // creates all transports for instance
121 void CreateInstanceTransports(Map* map);
122
124 {
125 TransportTemplates::const_iterator itr = _transportTemplates.find(entry);
126 if (itr != _transportTemplates.end())
127 return &itr->second;
128 return nullptr;
129 }
130
132 {
133 TransportAnimationContainer::const_iterator itr = _transportAnimations.find(entry);
134 if (itr != _transportAnimations.end())
135 return &itr->second;
136
137 return nullptr;
138 }
139
140 private:
141 TransportMgr();
143 TransportMgr(TransportMgr const&) = delete;
145
146 // Generates and precaches a path for transport to avoid generation each time transport instance is created
147 void GeneratePath(GameObjectTemplate const* goInfo, TransportTemplate* transport);
148
149 void AddPathNodeToTransport(uint32 transportEntry, uint32 timeSeg, TransportAnimationEntry const* node);
150
151 void AddPathRotationToTransport(uint32 transportEntry, uint32 timeSeg, TransportRotationEntry const* node)
152 {
153 _transportAnimations[transportEntry].Rotations[timeSeg] = node;
154 }
155
156 // Container storing transport templates
158
159 // Container storing transport entries to create for instanced maps
161
163};
164
165#define sTransportMgr TransportMgr::instance()
166
167#endif // TRANSPORTMGR_H
#define TC_GAME_API
Definition Define.h:114
uint32_t uint32
Definition Define.h:133
Movement::Spline< double > TransportSpline
std::unordered_map< uint32, TransportSet > TransportMap
std::map< uint32, TransportRotationEntry const * > TransportPathRotationContainer
std::unordered_map< uint32, std::set< uint32 > > TransportInstanceMap
std::map< uint32, TransportAnimation > TransportAnimationContainer
std::map< uint32, TransportAnimationEntry const * > TransportPathContainer
std::vector< KeyFrame > KeyFrameVec
std::set< Transport * > TransportSet
std::unordered_map< uint32, TransportTemplate > TransportTemplates
Definition Map.h:281
uint32 LowType
Definition ObjectGuid.h:142
TransportTemplates _transportTemplates
TransportAnimation const * GetTransportAnimInfo(uint32 entry) const
TransportAnimationContainer _transportAnimations
TransportTemplate const * GetTransportTemplate(uint32 entry) const
TransportInstanceMap _instanceTransports
TransportMgr(TransportMgr const &)=delete
void AddPathRotationToTransport(uint32 transportEntry, uint32 timeSeg, TransportRotationEntry const *node)
TransportMgr & operator=(TransportMgr const &)=delete
float DistUntilStop
uint32 Index
float NextDistFromPrev
KeyFrame(TaxiPathNodeEntry const *node)
bool IsTeleportFrame() const
float DistFromPrev
uint32 NextArriveTime
bool IsStopFrame() const
float DistSinceStop
std::shared_ptr< TransportSpline > Spline
float InitialOrientation
uint32 DepartureTime
TaxiPathNodeEntry const * Node
bool Teleport
float TimeFrom
float TimeTo
uint32 ArriveTime
TransportPathRotationContainer Rotations
TransportPathContainer Path
std::set< uint32 > mapsUsed
KeyFrameVec keyFrames