TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TransportMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 <G3D/Quat.h>
22 #include "Spline.h"
23 #include "DBCStores.h"
24 #include "DB2Stores.h"
25 #include "ObjectGuid.h"
26 
27 struct KeyFrame;
28 struct GameObjectTemplate;
29 struct TransportTemplate;
30 class Transport;
31 class Map;
32 
34 typedef std::vector<KeyFrame> KeyFrameVec;
35 typedef std::unordered_map<uint32, TransportTemplate> TransportTemplates;
36 typedef std::set<Transport*> TransportSet;
37 typedef std::unordered_map<uint32, TransportSet> TransportMap;
38 typedef std::unordered_map<uint32, std::set<uint32> > TransportInstanceMap;
39 
40 struct KeyFrame
41 {
42  explicit KeyFrame(TaxiPathNodeEntry const* node) : Index(0), Node(node), InitialOrientation(0.0f),
43  DistSinceStop(-1.0f), DistUntilStop(-1.0f), DistFromPrev(-1.0f), TimeFrom(0.0f), TimeTo(0.0f),
45  {
46  }
47 
53  float DistFromPrev;
54  float TimeFrom;
55  float TimeTo;
56  bool Teleport;
60 
61  // Data needed for next frame
64 
65  bool IsTeleportFrame() const { return Teleport; }
66  bool IsStopFrame() const { return (Node->Flags & TAXI_PATH_NODE_FLAG_STOP) != 0; }
67 };
68 
70 {
73 
74  std::set<uint32> mapsUsed;
75  bool inInstance;
78  float accelTime;
79  float accelDist;
81 };
82 
83 typedef std::map<uint32, TransportAnimationEntry const*> TransportPathContainer;
84 typedef std::map<uint32, TransportRotationEntry const*> TransportPathRotationContainer;
85 
87 {
88  TransportAnimation() : TotalTime(0) { }
89 
93 
94  TransportAnimationEntry const* GetAnimNode(uint32 time) const;
95  G3D::Quat GetAnimRotation(uint32 time) const;
96 };
97 
98 typedef std::map<uint32, TransportAnimation> TransportAnimationContainer;
99 
101 {
102  friend void DB2Manager::LoadStores(std::string const&, uint32);
103 
104  public:
105  static TransportMgr* instance();
106 
107  void Unload();
108 
109  void LoadTransportTemplates();
110 
111  // Creates a transport using given GameObject template entry
112  Transport* CreateTransport(uint32 entry, ObjectGuid::LowType guid = UI64LIT(0), Map* map = nullptr, uint32 phaseid = 0, uint32 phasegroup = 0);
113 
114  // Spawns all continent transports, used at core startup
115  void SpawnContinentTransports();
116 
117  // creates all transports for instance
118  void CreateInstanceTransports(Map* map);
119 
121  {
122  TransportTemplates::const_iterator itr = _transportTemplates.find(entry);
123  if (itr != _transportTemplates.end())
124  return &itr->second;
125  return NULL;
126  }
127 
129  {
130  TransportAnimationContainer::const_iterator itr = _transportAnimations.find(entry);
131  if (itr != _transportAnimations.end())
132  return &itr->second;
133 
134  return NULL;
135  }
136 
137  private:
138  TransportMgr();
139  ~TransportMgr();
140  TransportMgr(TransportMgr const&);
142 
143  // Generates and precaches a path for transport to avoid generation each time transport instance is created
144  void GeneratePath(GameObjectTemplate const* goInfo, TransportTemplate* transport);
145 
146  void AddPathNodeToTransport(uint32 transportEntry, uint32 timeSeg, TransportAnimationEntry const* node);
147 
148  void AddPathRotationToTransport(uint32 transportEntry, uint32 timeSeg, TransportRotationEntry const* node)
149  {
150  _transportAnimations[transportEntry].Rotations[timeSeg] = node;
151  }
152 
153  // Container storing transport templates
155 
156  // Container storing transport entries to create for instanced maps
158 
160 };
161 
162 #define sTransportMgr TransportMgr::instance()
163 
164 #endif // TRANSPORTMGR_H
uint32 DepartureTime
Definition: TransportMgr.h:58
float DistFromPrev
Definition: TransportMgr.h:53
std::vector< KeyFrame > KeyFrameVec
Definition: TransportMgr.h:34
bool IsStopFrame() const
Definition: TransportMgr.h:66
uint32 ArriveTime
Definition: TransportMgr.h:57
uint32 entry
Definition: TransportMgr.h:80
Definition: TransportMgr.h:86
Movement::Spline< double > TransportSpline
Definition: TransportMgr.h:31
void AddPathRotationToTransport(uint32 transportEntry, uint32 timeSeg, TransportRotationEntry const *node)
Definition: TransportMgr.h:148
Definition: TransportMgr.h:100
TransportAnimation const * GetTransportAnimInfo(uint32 entry) const
Definition: TransportMgr.h:128
#define UI64LIT(N)
Definition: Define.h:138
Definition: GameObject.h:34
float accelTime
Definition: TransportMgr.h:78
arena_t NULL
Definition: jemalloc_internal.h:624
float DistUntilStop
Definition: TransportMgr.h:52
#define false
Definition: CascPort.h:18
float TimeFrom
Definition: TransportMgr.h:54
Definition: Transport.h:28
TaxiPathNodeEntry const * Node
Definition: TransportMgr.h:49
Definition: DBCEnums.h:702
~TransportTemplate()
Definition: TransportMgr.cpp:23
std::map< uint32, TransportRotationEntry const * > TransportPathRotationContainer
Definition: TransportMgr.h:84
uint64 LowType
Definition: ObjectGuid.h:199
float InitialOrientation
Definition: TransportMgr.h:50
std::unordered_map< uint32, std::set< uint32 > > TransportInstanceMap
Definition: TransportMgr.h:38
std::set< uint32 > mapsUsed
Definition: TransportMgr.h:74
TransportSpline * Spline
Definition: TransportMgr.h:59
TransportTemplate const * GetTransportTemplate(uint32 entry) const
Definition: TransportMgr.h:120
TransportAnimation()
Definition: TransportMgr.h:88
KeyFrameVec keyFrames
Definition: TransportMgr.h:77
uint32 Flags
Definition: DB2Structure.h:1352
Definition: Quat.h:49
std::map< uint32, TransportAnimationEntry const * > TransportPathContainer
Definition: TransportMgr.h:83
float TimeTo
Definition: TransportMgr.h:55
KeyFrame(TaxiPathNodeEntry const *node)
Definition: TransportMgr.h:42
Vector2int16 & operator=(const Any &a)
Definition: DB2Structure.h:1375
uint32_t uint32
Definition: Define.h:150
float DistSinceStop
Definition: TransportMgr.h:51
std::unordered_map< uint32, TransportTemplate > TransportTemplates
Definition: TransportMgr.h:35
uint32 Index
Definition: TransportMgr.h:48
Definition: DB2Structure.h:1345
Definition: Map.h:259
Definition: DB2Structure.h:1384
bool Teleport
Definition: TransportMgr.h:56
bool inInstance
Definition: TransportMgr.h:75
uint32 NextArriveTime
Definition: TransportMgr.h:63
Definition: Spline.h:135
void LoadStores(std::string const &dataPath, uint32 defaultLocale)
Definition: DB2Stores.cpp:196
#define TC_GAME_API
Definition: Define.h:134
TransportPathContainer Path
Definition: TransportMgr.h:90
TransportInstanceMap _instanceTransports
Definition: TransportMgr.h:157
TransportTemplates _transportTemplates
Definition: TransportMgr.h:154
std::unordered_map< uint32, TransportSet > TransportMap
Definition: TransportMgr.h:37
TransportTemplate()
Definition: TransportMgr.h:71
Definition: TransportMgr.h:40
std::set< Transport * > TransportSet
Definition: TransportMgr.h:36
uint32 pathTime
Definition: TransportMgr.h:76
TransportAnimationContainer _transportAnimations
Definition: TransportMgr.h:159
TransportPathRotationContainer Rotations
Definition: TransportMgr.h:91
float NextDistFromPrev
Definition: TransportMgr.h:62
bool IsTeleportFrame() const
Definition: TransportMgr.h:65
std::map< uint32, TransportAnimation > TransportAnimationContainer
Definition: TransportMgr.h:98
Definition: TransportMgr.h:69
uint32 TotalTime
Definition: TransportMgr.h:92
float accelDist
Definition: TransportMgr.h:79