AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
CinematicMgr Class Reference

#include "CinematicMgr.h"

Public Member Functions

 CinematicMgr (Player *playerref)
 
 ~CinematicMgr ()
 
uint32 GetActiveCinematicCamera () const
 
void SetActiveCinematicCamera (uint32 cinematicCameraId=0)
 
bool IsOnCinematic () const
 
void BeginCinematic ()
 
void EndCinematic ()
 
void UpdateCinematicLocation (uint32 diff)
 

Protected Attributes

uint32 m_cinematicDiff
 
uint32 m_lastCinematicCheck
 
uint32 m_activeCinematicCameraId
 
uint32 m_cinematicLength
 
std::vector< FlyByCamera > const * m_cinematicCamera
 
Position m_remoteSightPosition
 
TempSummonm_CinematicObject
 

Private Attributes

Playerplayer
 

Friends

class Player
 

Detailed Description

Constructor & Destructor Documentation

◆ CinematicMgr()

CinematicMgr::CinematicMgr ( Player playerref)
explicit
24{
25 player = playerref;
30 m_cinematicCamera = nullptr;
31 m_remoteSightPosition = Position(0.0f, 0.0f, 0.0f);
32 m_CinematicObject = nullptr;
33}
Definition: Position.h:27
Player * player
Definition: CinematicMgr.h:49
std::vector< FlyByCamera > const * m_cinematicCamera
Definition: CinematicMgr.h:56
uint32 m_cinematicDiff
Definition: CinematicMgr.h:52
uint32 m_lastCinematicCheck
Definition: CinematicMgr.h:53
uint32 m_cinematicLength
Definition: CinematicMgr.h:55
TempSummon * m_CinematicObject
Definition: CinematicMgr.h:58
uint32 m_activeCinematicCameraId
Definition: CinematicMgr.h:54
Position m_remoteSightPosition
Definition: CinematicMgr.h:57

References m_activeCinematicCameraId, m_cinematicCamera, m_cinematicDiff, m_cinematicLength, m_CinematicObject, m_lastCinematicCheck, m_remoteSightPosition, and player.

◆ ~CinematicMgr()

CinematicMgr::~CinematicMgr ( )
36{
39}
void EndCinematic()
Definition: CinematicMgr.cpp:74

References EndCinematic(), m_activeCinematicCameraId, and m_cinematicCamera.

Member Function Documentation

◆ BeginCinematic()

void CinematicMgr::BeginCinematic ( )
42{
43 // Sanity check for active camera set
45 return;
46
47 if (std::vector<FlyByCamera> const* flyByCameras = GetFlyByCameras(m_activeCinematicCameraId))
48 {
49 // Initialize diff, and set camera
51 m_cinematicCamera = flyByCameras;
52
53 auto camitr = m_cinematicCamera->begin();
54 if (camitr != m_cinematicCamera->end())
55 {
56 Position const& pos = camitr->locations;
57 if (!pos.IsPositionValid())
58 return;
59
63 {
66 }
67
68 // Get cinematic length
69 m_cinematicLength = flyByCameras->back().timeStamp;
70 }
71 }
72}
@ TEMPSUMMON_TIMED_DESPAWN
Definition: Object.h:48
std::vector< FlyByCamera > const * GetFlyByCameras(uint32 cinematicCameraId)
Definition: M2Stores.cpp:254
#define VISUAL_WAYPOINT
Definition: MotionMaster.h:34
Map * GetMap() const
Definition: Object.h:536
TempSummon * SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0, SummonPropertiesEntry const *properties=nullptr, bool visibleBySummonerOnly=false) const
Definition: Object.cpp:2366
void setActive(bool isActiveObject)
Definition: Object.cpp:1094
float m_positionZ
Definition: Position.h:57
float m_positionX
Definition: Position.h:55
float m_positionY
Definition: Position.h:56
bool IsPositionValid() const
Definition: Position.cpp:176
float GetPositionX() const
Definition: Position.h:116
float GetPositionY() const
Definition: Position.h:117
void SetViewpoint(WorldObject *target, bool apply)
Definition: Player.cpp:13204
void LoadGrid(float x, float y)
Definition: Map.cpp:495

References GetFlyByCameras(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), Position::IsPositionValid(), Map::LoadGrid(), m_activeCinematicCameraId, m_cinematicCamera, m_cinematicDiff, m_cinematicLength, m_CinematicObject, Position::m_positionX, Position::m_positionY, Position::m_positionZ, player, WorldObject::setActive(), Player::SetViewpoint(), WorldObject::SummonCreature(), TEMPSUMMON_TIMED_DESPAWN, and VISUAL_WAYPOINT.

Referenced by WorldSession::HandleNextCinematicCamera().

◆ EndCinematic()

void CinematicMgr::EndCinematic ( )
75{
77 return;
78
80 m_cinematicCamera = nullptr;
83 {
84 if (WorldObject* vpObject = player->GetViewpoint())
85 if (vpObject == m_CinematicObject)
87
89 }
90}
Definition: Object.h:410
void AddObjectToRemoveList()
Definition: Object.cpp:2160
WorldObject * GetViewpoint() const
Definition: Player.cpp:13247

References WorldObject::AddObjectToRemoveList(), Player::GetViewpoint(), m_activeCinematicCameraId, m_cinematicCamera, m_cinematicDiff, m_CinematicObject, player, and Player::SetViewpoint().

Referenced by WorldSession::HandleCompleteCinematic(), UpdateCinematicLocation(), and ~CinematicMgr().

◆ GetActiveCinematicCamera()

uint32 CinematicMgr::GetActiveCinematicCamera ( ) const
inline

◆ IsOnCinematic()

bool CinematicMgr::IsOnCinematic ( ) const
inline
42{ return (m_cinematicCamera != nullptr); }

◆ SetActiveCinematicCamera()

void CinematicMgr::SetActiveCinematicCamera ( uint32  cinematicCameraId = 0)
inline
41{ m_activeCinematicCameraId = cinematicCameraId; }

Referenced by Player::SendCinematicStart().

◆ UpdateCinematicLocation()

void CinematicMgr::UpdateCinematicLocation ( uint32  diff)
93{
95 return;
96
97 Position lastPosition;
98 uint32 lastTimestamp = 0;
99 Position nextPosition;
100 uint32 nextTimestamp = 0;
101
102 // Obtain direction of travel
103 for (FlyByCamera cam : *m_cinematicCamera)
104 {
105 if (cam.timeStamp > m_cinematicDiff)
106 {
107 nextPosition.Relocate(cam.locations);
108 nextTimestamp = cam.timeStamp;
109 break;
110 }
111 lastPosition.Relocate(cam.locations);
112 lastTimestamp = cam.timeStamp;
113 }
114 float angle = lastPosition.GetAbsoluteAngle(&nextPosition);
115 angle -= lastPosition.GetOrientation();
116 if (angle < 0)
117 angle += 2 * float(M_PI);
118
119 // Look for position around 2 second ahead of us.
120 int32 workDiff = m_cinematicDiff;
121
122 // Modify result based on camera direction (Humans for example, have the camera point behind)
123 workDiff += static_cast<int32>(float(CINEMATIC_LOOKAHEAD) * cos(angle));
124
125 // Get an iterator to the last entry in the cameras, to make sure we don't go beyond the end
126 auto endItr = m_cinematicCamera->rbegin();
127 if (endItr != m_cinematicCamera->rend() && workDiff > static_cast<int32>(endItr->timeStamp))
128 workDiff = endItr->timeStamp;
129
130 // Never try to go back in time before the start of cinematic!
131 if (workDiff < 0)
132 workDiff = m_cinematicDiff;
133
134 // Obtain the previous and next waypoint based on timestamp
135 for (FlyByCamera cam : *m_cinematicCamera)
136 {
137 if (static_cast<int32>(cam.timeStamp) >= workDiff)
138 {
139 nextPosition.Relocate(cam.locations);
140 nextTimestamp = cam.timeStamp;
141 break;
142 }
143 lastPosition.Relocate(cam.locations);
144 lastTimestamp = cam.timeStamp;
145 }
146
147 // Never try to go beyond the end of the cinematic
148 if (workDiff > static_cast<int32>(nextTimestamp))
149 workDiff = static_cast<int32>(nextTimestamp);
150
151 // Interpolate the position for this moment in time (or the adjusted moment in time)
152 uint32 timeDiff = nextTimestamp - lastTimestamp;
153 uint32 interDiff = workDiff - lastTimestamp;
154 float xDiff = nextPosition.m_positionX - lastPosition.m_positionX;
155 float yDiff = nextPosition.m_positionY - lastPosition.m_positionY;
156 float zDiff = nextPosition.m_positionZ - lastPosition.m_positionZ;
157 Position interPosition(lastPosition.m_positionX + (xDiff * (float(interDiff) / float(timeDiff))), lastPosition.m_positionY +
158 (yDiff * (float(interDiff) / float(timeDiff))), lastPosition.m_positionZ + (zDiff * (float(interDiff) / float(timeDiff))));
159
160 // Advance (at speed) to this position. The remote sight object is used
161 // to send update information to player in cinematic
162 if (m_CinematicObject && interPosition.IsPositionValid())
163 m_CinematicObject->MonsterMoveWithSpeed(interPosition.m_positionX, interPosition.m_positionY, interPosition.m_positionZ, 500.0f);
164
165 // If we never received an end packet 10 seconds after the final timestamp then force an end
167 EndCinematic();
168}
constexpr auto IN_MILLISECONDS
Definition: Common.h:53
std::int32_t int32
Definition: Define.h:103
std::uint32_t uint32
Definition: Define.h:107
constexpr auto CINEMATIC_LOOKAHEAD
Definition: CinematicMgr.h:27
Definition: M2Stores.h:26
float GetOrientation() const
Definition: Position.h:119
float GetAbsoluteAngle(float x, float y) const
Definition: Position.h:186
void Relocate(float x, float y)
Definition: Position.h:72
void MonsterMoveWithSpeed(float x, float y, float z, float speed)
Definition: Unit.cpp:529

References CINEMATIC_LOOKAHEAD, EndCinematic(), Position::GetAbsoluteAngle(), Position::GetOrientation(), IN_MILLISECONDS, Position::IsPositionValid(), m_activeCinematicCameraId, m_cinematicCamera, m_cinematicDiff, m_cinematicLength, m_CinematicObject, Position::m_positionX, Position::m_positionY, Position::m_positionZ, Unit::MonsterMoveWithSpeed(), and Position::Relocate().

Referenced by Player::Update().

Friends And Related Function Documentation

◆ Player

friend class Player
friend

Member Data Documentation

◆ m_activeCinematicCameraId

uint32 CinematicMgr::m_activeCinematicCameraId
protected

◆ m_cinematicCamera

std::vector<FlyByCamera> const* CinematicMgr::m_cinematicCamera
protected

◆ m_cinematicDiff

uint32 CinematicMgr::m_cinematicDiff
protected

◆ m_cinematicLength

uint32 CinematicMgr::m_cinematicLength
protected

◆ m_CinematicObject

TempSummon* CinematicMgr::m_CinematicObject
protected

◆ m_lastCinematicCheck

uint32 CinematicMgr::m_lastCinematicCheck
protected

Referenced by CinematicMgr(), and Player::Update().

◆ m_remoteSightPosition

Position CinematicMgr::m_remoteSightPosition
protected

Referenced by CinematicMgr().

◆ player

Player* CinematicMgr::player
private