Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
waypoints.cpp
Go to the documentation of this file.
1
#include "
waypoints.h
"
2
#include "
Viewscreen.h
"
3
#include "
../MathUtilities.h
"
4
#include "
../Dialogs/WaypointDialog.h
"
5
6
waypoints::waypoints
(
GameClass
* prmGameClass)
7
{
8
gameclass
= prmGameClass;
9
ResetSession
();
10
}
11
12
void
waypoints::ResetSession
()
13
{
14
download
= {};
15
CancelPendingSelection
();
16
gameclass
->
bus
->
waypoint
.clear();
17
gameclass
->
bus
->
waypoint
.emplace_back(
Swaypoint
{});
18
gameclass
->
bus
->
WPtargetC
= 0;
19
if
(
DialogBase::dialogs
[
D_WAYPOINTMANAGER
])
20
static_cast<
WaypointDialog
*
>
(
DialogBase::dialogs
[
D_WAYPOINTMANAGER
])->InvalidateWaypoints();
21
}
22
23
void
waypoints::UpdateMaster
(
Swaypoint
waypoint)
const
24
{
25
auto
masterIndex =
Find
(waypoint.
id
);
26
if
(masterIndex == -1)
27
return
;
28
gameclass
->
bus
->
waypoint
.at(masterIndex) = waypoint;
29
}
30
31
void
waypoints::RequestWaypointData
()
32
{
33
// Device recreation repeats the loading stages within the same connection.
34
// Keep its records, temporary waypoint and selection, even during a download.
35
if
(
download
.
Begin
())
36
gameclass
->
logger
->
Log
(
"Waypoint download scheduled; waiting for server login completion"
);
37
}
38
39
void
waypoints::FrameMove
(
float
elapsedSeconds)
40
{
41
if
(!
download
.
TryRequest
(
g_bGotConclusion
, elapsedSeconds))
42
return
;
43
44
char
msg[160];
45
sprintf_s(msg,
sizeof
msg,
"Requesting waypoint snapshot after login completion (attempt %u, retaining %zu records)"
,
46
download
.
Attempts
(),
gameclass
->
bus
->
waypoint
.size());
47
gameclass
->
logger
->
Log
(msg);
48
SClientPacket
outpacket = {};
49
outpacket.
type
= 37;
// waypoint management
50
outpacket.
f_x
= 2.0f;
// request all data
51
outpacket.
f_y
= 0.0f;
// no specific waypoint ID
52
outpacket.
f_z
= 0.0f;
// NULL
53
outpacket.
f_w
= 0.0f;
// NULL
54
gameclass
->
networking
->
SendToServer
(&outpacket,
sizeof
(
SClientPacket
),
true
);
55
}
56
57
void
waypoints::CancelPendingSelection
()
58
{
59
pendingSelection
.
Clear
();
60
}
61
62
bool
waypoints::ResolvePendingSelection
()
63
{
64
const
int
id
=
pendingSelection
.
Id
();
65
if
(!
pendingSelection
.
TryResolve
(
gameclass
->
bus
->
waypoint
,
gameclass
->
bus
->
WPtargetC
))
66
return
false
;
67
68
char
msg[160];
69
sprintf_s(msg,
sizeof
msg,
"Applied server waypoint ID %i at index %i"
,
id
,
gameclass
->
bus
->
WPtargetC
);
70
gameclass
->
logger
->
Log
(msg);
71
// The dialog uses a filtered, sorted row index, not the master collection index.
72
static_cast<
WaypointDialog
*
>
(
DialogBase::dialogs
[
D_WAYPOINTMANAGER
])->ActiveTab();
73
return
true
;
74
}
75
76
void
waypoints::SetCurrentFromServer
(
int
id
)
77
{
78
if
(
download
.
Complete
())
79
{
80
char
msg[160];
81
sprintf_s(msg,
sizeof
msg,
"Waypoint snapshot selection received (ID %i, %zu records, attempt %u)"
,
82
id
,
gameclass
->
bus
->
waypoint
.size(),
download
.
Attempts
());
83
gameclass
->
logger
->
Log
(msg);
84
}
85
pendingSelection
.
Set
(
id
);
86
if
(!
ResolvePendingSelection
())
87
{
88
char
msg[160];
89
sprintf_s(msg,
sizeof
msg,
"Waiting for server waypoint ID %i; retaining current index %i"
,
id
,
gameclass
->
bus
->
WPtargetC
);
90
gameclass
->
logger
->
Log
(msg);
91
}
92
}
93
94
void
waypoints::Delete
(
int
index)
95
{
96
CancelPendingSelection
();
97
if
(index == 0)
98
ZeroMemory(&
gameclass
->
bus
->
waypoint
.at(0),
sizeof
Swaypoint
);
99
else
// delete from list
100
{
101
SClientPacket
outpacket;
102
outpacket.
type
= 37;
// Waypoint management
103
outpacket.
f_x
= 1.0f;
// delete
104
outpacket.
f_y
=
static_cast<
float
>
(
gameclass
->
bus
->
waypoint
.at(index).
id
);
105
outpacket.
f_z
= 0.0f;
106
outpacket.
f_w
= 0.0f;
107
gameclass
->
networking
->
SendToServer
(&outpacket,
sizeof
(
SClientPacket
),
true
);
108
109
gameclass
->
bus
->
waypoint
.erase(
gameclass
->
bus
->
waypoint
.begin() + index);
110
111
if
(index ==
gameclass
->
bus
->
WPtargetC
)
112
gameclass
->
bus
->
WPtargetC
= 0;
113
else
114
gameclass
->
bus
->
WPtargetC
--;
115
if
(
gameclass
->
bus
->
WPtargetC
< 0)
116
gameclass
->
bus
->
WPtargetC
= 0;
117
118
outpacket =
WaypointProtocol::Select
(
gameclass
->
bus
->
waypoint
.at(
gameclass
->
bus
->
WPtargetC
).id,
119
gameclass
->
bus
->
streetViewConfigured
&&
playerships
[0].
groundvehicle
);
120
gameclass
->
bus
->
ClearTurnByTurn
();
121
gameclass
->
networking
->
SendToServer
(&outpacket,
sizeof
(
SClientPacket
),
true
);
122
}
123
}
124
125
void
waypoints::AddOrUpdate
(
Swaypoint
tempwaypoint)
126
{
127
auto
* waypointDialog =
static_cast<
WaypointDialog
*
>
(
DialogBase::dialogs
[
D_WAYPOINTMANAGER
]);
128
const
short
tab = waypointDialog->
TabForGroup
(tempwaypoint.
group
);
129
if
(tab < 0)
130
{
131
gameclass
->
logger
->
Log
(
"Received waypoint with invalid folder group"
,
Logger::Level::Warn
);
132
return
;
133
}
134
download
.
ReceivedRecord
();
135
tempwaypoint.
text
[_countof(tempwaypoint.
text
) - 1] = L
'\0'
;
136
tempwaypoint.
elevationKm
=
RiseMath::Vec3Length
(&tempwaypoint.
location
) -
radiusC
;
137
138
tempwaypoint.
latlng
=
CalculateLatLng
(tempwaypoint.
location
);
139
140
if
(waypointDialog->tabs <= tab)
141
{
142
char
msg[99];
143
sprintf_s(msg,
sizeof
msg,
"Received waypoint for tab %i that does not exist... adding!"
, tab);
144
gameclass
->
logger
->
Log
(msg);
145
146
for
(
int
t = waypointDialog->tabs; t <= tab; t++)
147
{
148
DialogBase::dialogs
[
D_WAYPOINTMANAGER
]->
tabusedefaultlang
[t] = 0;
149
DialogBase::dialogs
[
D_WAYPOINTMANAGER
]->
tabstr
[t][0] = 0;
150
}
151
waypointDialog->tabs =
static_cast<
short
>
(tab + 1);
152
}
153
154
for
(
unsigned
t = 1; t <
gameclass
->
bus
->
waypoint
.size(); t++)
155
{
156
if
(
gameclass
->
bus
->
waypoint
.at(t).id == tempwaypoint.
id
)
157
{
158
char
msg[99];
159
sprintf_s(msg,
sizeof
msg,
"Found received waypoint at %i, updating (%i)!"
, t, tempwaypoint.
id
);
160
gameclass
->
logger
->
Log
(msg);
161
gameclass
->
bus
->
waypoint
.at(t) = tempwaypoint;
162
static_cast<
WaypointDialog
*
>
(
DialogBase::dialogs
[
D_WAYPOINTMANAGER
])->InvalidateWaypoints();
163
ResolvePendingSelection
();
164
return
;
165
}
166
}
167
168
char
msg[99];
169
sprintf_s(msg,
sizeof
msg,
"Could not find received waypoint, adding (%i)!"
, tempwaypoint.
id
);
170
gameclass
->
logger
->
Log
(msg);
171
gameclass
->
bus
->
waypoint
.emplace_back(tempwaypoint);
172
static_cast<
WaypointDialog
*
>
(
DialogBase::dialogs
[
D_WAYPOINTMANAGER
])->InvalidateWaypoints();
173
ResolvePendingSelection
();
174
}
175
176
short
waypoints::Find
(
int
id
)
const
177
{
178
for
(
size_t
t = 0; t <
gameclass
->
bus
->
waypoint
.size(); t++)
179
{
180
if
(
gameclass
->
bus
->
waypoint
.at(t).id ==
id
)
181
return
static_cast<
short
>
(t);
182
}
183
return
-1;
184
}
185
186
short
waypoints::FindByUniqueId
(
int
uniqueId)
const
187
{
189
for
(
unsigned
t = 1; t <
gameclass
->
bus
->
waypoint
.size(); t++)
190
{
191
if
(
gameclass
->
bus
->
waypoint
.at(t).uniqueid == uniqueId)
192
return
t;
193
}
194
return
0;
195
}
196
197
std::vector<Swaypoint>
waypoints::GetGroup
(
short
group)
const
198
{
199
std::vector<Swaypoint> newwaypoints;
200
for
(
unsigned
t = 0; t <
gameclass
->
bus
->
waypoint
.size(); t++)
201
{
202
// waypoint.at(t).id = t;
203
if
(
gameclass
->
bus
->
waypoint
.at(t).group == group)
204
newwaypoints.emplace_back(
gameclass
->
bus
->
waypoint
.at(t));
205
}
206
return
newwaypoints;
207
}
208
209
void
waypoints::Upload
(
Swaypoint
swaypoint)
const
210
{
211
SPacketHuge
hugePacket;
212
hugePacket.
type
= 18;
// waypoint data upstream
213
hugePacket.waypoint = swaypoint;
214
gameclass
->
networking
->
SendToServer
(&hugePacket,
sizeof
SPacketHuge
,
true
);
215
}
D_WAYPOINTMANAGER
@ D_WAYPOINTMANAGER
Definition
DialogBase.h:6
MathUtilities.h
CalculateLatLng
RiseMath::Vector2 CalculateLatLng(RiseMath::Vector3 position)
Definition
MathUtilities.h:21
Viewscreen.h
WaypointDialog.h
Bus::ClearTurnByTurn
void ClearTurnByTurn()
Definition
Bus.h:517
Bus::streetViewConfigured
bool streetViewConfigured
Definition
Bus.h:510
Bus::waypoint
std::vector< Swaypoint > waypoint
Definition
Bus.h:500
Bus::WPtargetC
int WPtargetC
Definition
Bus.h:499
DialogBase::dialogs
static DialogBase * dialogs[D_ENUMERATION]
Definition
DialogBase.h:41
DialogBase::tabstr
WCHAR tabstr[MAX_TAB][MAX_TAB_CHARS]
Definition
DialogBase.h:65
DialogBase::tabusedefaultlang
short tabusedefaultlang[MAX_TAB]
Definition
DialogBase.h:52
GameClass
Definition
GameClass.h:44
GameClass::bus
std::unique_ptr< Bus > bus
Definition
GameClass.h:108
GameClass::networking
std::unique_ptr< Networking > networking
Definition
GameClass.h:103
GameClass::logger
std::unique_ptr< Logger > logger
Definition
GameClass.h:109
Logger::Log
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition
Logger.cpp:283
Logger::Warn
@ Warn
Definition
Logger.h:26
Networking::SendToServer
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
Definition
Networking.cpp:160
WaypointDialog
Definition
WaypointDialog.h:10
WaypointDialog::TabForGroup
short TabForGroup(unsigned char group) const
Definition
WaypointDialog.cpp:517
WaypointProtocol::DownloadState::Complete
bool Complete()
Definition
WaypointProtocol.h:122
WaypointProtocol::DownloadState::Attempts
unsigned Attempts() const
Definition
WaypointProtocol.h:129
WaypointProtocol::DownloadState::Begin
bool Begin()
Definition
WaypointProtocol.h:101
WaypointProtocol::DownloadState::ReceivedRecord
void ReceivedRecord()
Definition
WaypointProtocol.h:118
WaypointProtocol::DownloadState::TryRequest
bool TryRequest(bool loginComplete, float elapsedSeconds)
Definition
WaypointProtocol.h:108
WaypointProtocol::PendingSelection::TryResolve
bool TryResolve(const std::vector< Swaypoint > &waypoints, int ¤tIndex)
Definition
WaypointProtocol.h:157
WaypointProtocol::PendingSelection::Clear
void Clear()
Definition
WaypointProtocol.h:154
WaypointProtocol::PendingSelection::Set
void Set(int id)
Definition
WaypointProtocol.h:153
WaypointProtocol::PendingSelection::Id
int Id() const
Definition
WaypointProtocol.h:155
waypoints::CancelPendingSelection
void CancelPendingSelection()
Definition
waypoints.cpp:57
waypoints::SetCurrentFromServer
void SetCurrentFromServer(int id)
Definition
waypoints.cpp:76
waypoints::Upload
void Upload(Swaypoint swaypoint) const
Definition
waypoints.cpp:209
waypoints::Find
short Find(int id) const
Definition
waypoints.cpp:176
waypoints::pendingSelection
WaypointProtocol::PendingSelection pendingSelection
Definition
waypoints.h:28
waypoints::GetGroup
std::vector< Swaypoint > GetGroup(short group) const
Definition
waypoints.cpp:197
waypoints::download
WaypointProtocol::DownloadState download
Definition
waypoints.h:27
waypoints::AddOrUpdate
void AddOrUpdate(Swaypoint tempwaypoint)
Definition
waypoints.cpp:125
waypoints::Delete
void Delete(int index)
Definition
waypoints.cpp:94
waypoints::ResetSession
void ResetSession()
Definition
waypoints.cpp:12
waypoints::FindByUniqueId
short FindByUniqueId(int uniqueid) const
Definition
waypoints.cpp:186
waypoints::FrameMove
void FrameMove(float elapsedSeconds)
Definition
waypoints.cpp:39
waypoints::UpdateMaster
void UpdateMaster(Swaypoint waypoint) const
Definition
waypoints.cpp:23
waypoints::RequestWaypointData
void RequestWaypointData()
Definition
waypoints.cpp:31
waypoints::waypoints
waypoints(GameClass *prmGameClass)
Definition
waypoints.cpp:6
waypoints::gameclass
GameClass * gameclass
Definition
waypoints.h:26
waypoints::ResolvePendingSelection
bool ResolvePendingSelection()
Definition
waypoints.cpp:62
playerships
s_network_objects playerships[MAX_SCAN]
Definition
globals.cpp:112
g_bGotConclusion
bool g_bGotConclusion
Definition
globals.cpp:97
radiusC
#define radiusC
Definition
globals.h:87
RiseMath::Vec3Length
float Vec3Length(const Vector3 *a)
Definition
ClientMath.h:95
WaypointProtocol::Select
SClientPacket Select(int waypointId, bool streetViewConfigured)
Definition
WaypointProtocol.h:138
SClientPacket
Definition
ServerTypes.h:580
SClientPacket::f_x
float f_x
Definition
ServerTypes.h:583
SClientPacket::f_z
float f_z
Definition
ServerTypes.h:583
SClientPacket::type
unsigned char type
Definition
ServerTypes.h:581
SClientPacket::f_w
float f_w
Definition
ServerTypes.h:583
SClientPacket::f_y
float f_y
Definition
ServerTypes.h:583
SPacketHuge
Definition
ServerTypes.h:934
SPacketHuge::type
unsigned char type
Definition
ServerTypes.h:946
Swaypoint
Definition
ServerTypes.h:891
Swaypoint::elevationKm
float elevationKm
Definition
ServerTypes.h:899
Swaypoint::latlng
RiseMath::Vector2 latlng
Definition
ServerTypes.h:898
Swaypoint::group
unsigned char group
Definition
ServerTypes.h:893
Swaypoint::location
RiseMath::Vector3 location
Definition
ServerTypes.h:897
Swaypoint::id
long id
Definition
ServerTypes.h:900
Swaypoint::text
WCHAR text[64]
Definition
ServerTypes.h:892
s_network_objects::groundvehicle
bool groundvehicle
Definition
globals.h:555
waypoints.h
Viewscreen
waypoints.cpp
Generated on
for Rise by
1.18.0