Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/User/Core/UserLeaderboards.cpp
1163 views
1
#include "RSDK/Core/RetroEngine.hpp"
2
#include <string>
3
4
// ====================
5
// API Cores
6
// ====================
7
8
namespace RSDK
9
{
10
namespace SKU
11
{
12
// Dummy API
13
#if RETRO_USERCORE_DUMMY
14
#include "RSDK/User/Dummy/DummyLeaderboards.cpp"
15
#endif
16
17
// Steam API
18
#if RETRO_USERCORE_STEAM
19
#include "RSDK/User/Steam/SteamLeaderboards.cpp"
20
#endif
21
22
// Epic Games API
23
#if RETRO_USERCORE_EOS
24
#include "RSDK/User/EOS/EOSLeaderboards.cpp"
25
#endif
26
27
// Switch API
28
#if RETRO_USERCORE_NX
29
#include "RSDK/User/NX/NXLeaderboards.cpp"
30
#endif
31
32
} // namespace SKU
33
} // namespace RSDK
34
35
using namespace RSDK;
36
37
#if RETRO_REV02
38
SKU::UserLeaderboards *RSDK::SKU::leaderboards = NULL;
39
40
RSDK::SKU::LeaderboardLoadInfo *RSDK::SKU::LeaderboardLoadList::InitLoadInfo()
41
{
42
LeaderboardLoadInfo *info = NULL;
43
AllocateStorage((void **)&info, sizeof(LeaderboardLoadInfo), DATASET_TMP, true);
44
memset(info, 0, sizeof(LeaderboardLoadInfo));
45
info->parent = this;
46
return info;
47
}
48
49
void RSDK::SKU::LeaderboardLoadList::Clear()
50
{
51
while (true) {
52
LeaderboardLoadInfo *current = this->next;
53
if (!current)
54
break;
55
56
LeaderboardLoadInfo *next = current->next;
57
if (next)
58
next->prev = NULL;
59
this->next = next;
60
61
if (current == this->prev)
62
this->prev = NULL;
63
64
--this->count;
65
66
RemoveStorageEntry((void **)&current);
67
}
68
69
this->prev = NULL;
70
this->next = NULL;
71
this->last = NULL;
72
this->count = 0;
73
this->unused = 0;
74
}
75
76
void RSDK::SKU::LeaderboardLoadList::AddLoadInfoPrev(LeaderboardLoadInfo *info)
77
{
78
LeaderboardLoadInfo *next = this->next;
79
if (next) {
80
if (this->count != 10) {
81
next->prev = info;
82
info->next = next;
83
++this->count;
84
this->next = info;
85
}
86
}
87
else {
88
Clear();
89
90
this->count = 1;
91
this->prev = info;
92
this->next = info;
93
this->last = info;
94
if (info->avail.start == 1)
95
info->disableLoadPrev = true;
96
}
97
}
98
99
void RSDK::SKU::LeaderboardLoadList::AddLoadInfoNext(LeaderboardLoadInfo *info)
100
{
101
LeaderboardLoadInfo *last = this->last;
102
if (last) {
103
if (this->count != 10) {
104
last->next = info;
105
info->prev = last;
106
++this->count;
107
this->last = info;
108
}
109
}
110
else {
111
Clear();
112
113
this->count = 1;
114
this->prev = info;
115
this->next = info;
116
this->last = info;
117
118
if (info->avail.start == 1)
119
info->disableLoadPrev = true;
120
}
121
}
122
123
void RSDK::SKU::LeaderboardLoadList::RemoveLoadInfoPrev()
124
{
125
LeaderboardLoadInfo *last = this->last;
126
127
if (this->last) {
128
LeaderboardLoadInfo *current = last->prev;
129
if (current)
130
current->next = NULL;
131
132
this->last = current;
133
134
if (last == this->prev)
135
this->prev = NULL;
136
137
--this->count;
138
}
139
}
140
void RSDK::SKU::LeaderboardLoadList::RemoveLoadInfoNext()
141
{
142
LeaderboardLoadInfo *next = this->next;
143
144
if (next) {
145
LeaderboardLoadInfo *current = next->next;
146
if (current)
147
current->prev = NULL;
148
this->next = current;
149
150
if (next == this->prev)
151
this->prev = NULL;
152
153
--this->count;
154
}
155
}
156
157
void RSDK::SKU::LeaderboardEntryInfo::Setup()
158
{
159
this->viewSize.start = 0;
160
this->viewSize.length = 0;
161
memset(this->entries, 0, sizeof(this->entries));
162
163
LeaderboardLoadInfo *info = this->loadList->next;
164
int32 count = 0;
165
if (info) {
166
this->viewSize.start = info->avail.start;
167
168
while (info) {
169
LeaderboardEntry **entryList = &entries[count];
170
LeaderboardEntry *entry = info->entries;
171
172
for (int32 e = 0; e < info->avail.length; ++e) {
173
*entryList++ = &entry[e];
174
++count;
175
}
176
177
info = info->next;
178
}
179
}
180
181
this->viewSize.length = count;
182
}
183
184
void RSDK::SKU::LeaderboardEntryInfo::HandleTimers()
185
{
186
UserLeaderboards *leaderboards = this->parent;
187
if (leaderboards->currentLeaderboard && this->loadType) {
188
LeaderboardLoadInfo *next = this->loadList->next;
189
LeaderboardLoadInfo *last = this->loadList->last;
190
191
if (next && last) {
192
switch (this->loadType) {
193
default:
194
case LEADERBOARD_LOAD_INIT:
195
case LEADERBOARD_LOAD_NEXT:
196
if ((this->loadSize.start + this->loadSize.length) != (last->avail.start + last->avail.length) && !next->disableLoadNext
197
&& last->status == STATUS_OK) {
198
if (this->loadList->count == 10) {
199
this->loadList->RemoveLoadInfoNext();
200
RemoveStorageEntry((void **)&next);
201
}
202
LeaderboardLoadInfo *info = this->loadList->InitLoadInfo();
203
info->avail.start = last->avail.length + last->avail.start;
204
info->avail.length = 20;
205
this->loadList->AddLoadInfoNext(info);
206
leaderboards->LoadLeaderboards(info);
207
Setup();
208
}
209
break;
210
211
case LEADERBOARD_LOAD_PREV:
212
if (next->avail.start != this->loadSize.start && !next->disableLoadPrev && next->status == STATUS_OK) {
213
if (this->loadList->count == 10) {
214
this->loadList->RemoveLoadInfoPrev();
215
RemoveStorageEntry((void **)&last);
216
}
217
LeaderboardLoadInfo *info = this->loadList->InitLoadInfo();
218
219
info->avail.start = next->avail.start;
220
if (info->avail.start > 20)
221
info->avail.start -= 20;
222
else
223
info->avail.start = 1;
224
225
info->avail.length = next->avail.start - info->avail.start;
226
227
if (info->avail.start == 1)
228
info->disableLoadPrev = true;
229
230
this->loadList->AddLoadInfoPrev(info);
231
leaderboards->LoadLeaderboards(info);
232
Setup();
233
}
234
break;
235
}
236
}
237
}
238
}
239
240
void RSDK::SKU::LeaderboardEntryInfo::LoadLeaderboardEntries(int32 start, uint32 length, int32 type)
241
{
242
switch (type) {
243
default:
244
case LEADERBOARD_LOAD_INIT:
245
loadType = (LeaderboardLoadTypes)type;
246
247
loadSize.start = start;
248
loadSize.length = length;
249
break;
250
251
case LEADERBOARD_LOAD_PREV:
252
loadType = (LeaderboardLoadTypes)type;
253
254
loadSize.start = MAX(start, 1);
255
loadSize.length = MIN(length, 200);
256
break;
257
258
case LEADERBOARD_LOAD_NEXT: {
259
loadType = (LeaderboardLoadTypes)type;
260
261
int32 startPos = start;
262
int32 endPos = start + length;
263
if (length - start < 200)
264
startPos = endPos - 200;
265
266
loadSize.start = startPos;
267
loadSize.length = endPos - startPos;
268
break;
269
}
270
}
271
}
272
273
void RSDK::SKU::ResetLeaderboardInfo()
274
{
275
leaderboards->status = STATUS_NONE;
276
leaderboards->currentLeaderboard = NULL;
277
278
leaderboards->loadList.Clear();
279
leaderboards->entryInfo.Setup();
280
}
281
282
SKU::LeaderboardEntry *RSDK::SKU::ReadLeaderboardEntry(int32 entryID)
283
{
284
if (entryID >= leaderboards->entryInfo.viewSize.start
285
&& entryID < leaderboards->entryInfo.viewSize.start + leaderboards->entryInfo.viewSize.length)
286
return leaderboards->entryInfo.entries[entryID - leaderboards->entryInfo.viewSize.start];
287
288
return NULL;
289
}
290
#endif
291
292