Skip to content

Commit 5affdb9

Browse files
committed
Some optimizations
1 parent 1b48106 commit 5affdb9

8 files changed

Lines changed: 97 additions & 90 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ else()
88
endif()
99
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
1010

11-
project(LevelInfo VERSION 1.5.3)
11+
project(LevelInfo VERSION 1.5.4)
1212

1313
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.cpp)
1414

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Version 1.5.4
2+
- Better iteration system for showing the LDM object count
3+
- More optimization
4+
15
# Version 1.5.3
26
- Fixed the informational text being displayed twice if the level was updated
37

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"geode": "5.3.0",
3-
"version": "v1.5.3",
3+
"version": "v1.5.4",
44
"gd": {
55
"win": "2.2081",
66
"android": "2.2081",

src/hooks/LevelInfoLayer.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#include <Geode/modify/LevelInfoLayer.hpp>
22
#include <cue/LoadingCircle.hpp> // This may be overkill
3+
#include <asp/iter.hpp>
34

45
#include "../managers/SettingsManager.h"
56
#include "../managers/SentCacheManager.h"
67
#include "../utils/Utils.h"
78

9+
using namespace geode::prelude;
10+
811
class $modify(MyLevelInfoLayer, LevelInfoLayer) {
912
struct Fields {
10-
cue::LoadingCircle *m_loadingCircle = cue::LoadingCircle::create();
11-
cocos2d::CCLabelBMFont *m_label;
13+
cue::LoadingCircle* m_loadingCircle = cue::LoadingCircle::create();
14+
CCLabelBMFont* m_label;
1215

13-
cocos2d::CCPoint m_position = {
14-
SettingsManager::Display.getWidth(),
15-
SettingsManager::Display.getHeight()
16-
};
16+
CCPoint const m_position = SettingsManager::Display.getPosition();
1717
std::string m_levelString;
1818

19-
geode::async::TaskHolder<geode::utils::web::WebResponse> m_listener;
19+
async::TaskHolder<utils::web::WebResponse> m_listener;
2020
};
2121

2222
bool init(GJGameLevel* level, bool challenge) {
@@ -40,7 +40,7 @@ class $modify(MyLevelInfoLayer, LevelInfoLayer) {
4040
};
4141

4242
// This will be called if the level just finished downloading
43-
void levelDownloadFinished(GJGameLevel *level) {
43+
void levelDownloadFinished(GJGameLevel* level) {
4444
LevelInfoLayer::levelDownloadFinished(level);
4545

4646
if (SettingsManager::Display.size > 0 && SettingsManager::Toggles.anyEnabled())
@@ -49,8 +49,8 @@ class $modify(MyLevelInfoLayer, LevelInfoLayer) {
4949

5050
// If the level is updated, avoid displaying the label twice by deleting the first
5151
// one and letting it create a new updated one
52-
void levelUpdateFinished(GJGameLevel *level, UpdateResponse response) {
53-
if (auto label = static_cast<cocos2d::CCLabelBMFont *>(this->getChildByIDRecursive("level-info-label"_spr)))
52+
void levelUpdateFinished(GJGameLevel* level, UpdateResponse response) {
53+
if (auto label = static_cast<CCLabelBMFont*>(this->getChildByIDRecursive("level-info-label"_spr)))
5454
label->removeFromParentAndCleanup(true);
5555

5656
return LevelInfoLayer::levelUpdateFinished(level, response);
@@ -75,7 +75,7 @@ class $modify(MyLevelInfoLayer, LevelInfoLayer) {
7575
switch (level->m_objectCount) {
7676
case 0:
7777
case 65535: {
78-
m_fields->m_levelString = cocos2d::ZipUtils::decompressString(
78+
m_fields->m_levelString = ZipUtils::decompressString(
7979
level->m_levelString, false, 0
8080
);
8181
labelContent << "Objects: ~" <<
@@ -92,37 +92,36 @@ class $modify(MyLevelInfoLayer, LevelInfoLayer) {
9292

9393
if (SettingsManager::Toggles.ldmObjectCount) {
9494
if (level->m_lowDetailMode) {
95-
std::string placeholder = "Objects (LDM): Loading...";
95+
std::string_view const placeholder = "Objects (LDM): Loading...";
9696
labelContent << placeholder << std::endl;
9797

9898
if (m_fields->m_levelString.empty())
99-
m_fields->m_levelString = cocos2d::ZipUtils::decompressString(
99+
m_fields->m_levelString = ZipUtils::decompressString(
100100
level->m_levelString, false, 0
101101
);
102102

103-
geode::async::spawn([self = geode::WeakRef<MyLevelInfoLayer>(this), placeholder] -> arc::Future<> {
103+
async::spawn([self = WeakRef<MyLevelInfoLayer>(this), placeholder] -> arc::Future<> {
104104
auto locked = self.lock();
105-
if (!locked || locked->m_fields->m_levelString.empty()) co_return;
106-
107-
std::stringstream ss(locked->m_fields->m_levelString);
108-
std::string object;
105+
if (!locked || locked->m_fields->m_levelString.empty())
106+
co_return;
109107

110108
size_t ldmObjectCount = 0;
111109

112110
// Before I forget what that corresponds to https://boomlings.dev/resources/client/level-components/level-string
113111
// {object};{object};{object};...
114-
while (std::getline(ss, object, ';')) {
115-
// {propertyKey},{propertyValue},{propertyKey},{propertyValue},...
116-
if (object.find(",103,1") == std::string::npos) // 103:1 = high detail object
117-
ldmObjectCount++;
118-
}
112+
asp::iter::split(locked->m_fields->m_levelString, ';')
113+
.forEach([&ldmObjectCount](std::string_view object) {
114+
if (object.find(",103,1") == std::string::npos) // 103:1 = high detail object
115+
ldmObjectCount++;
116+
}
117+
);
119118

120-
geode::queueInMainThread([locked, placeholder, ldmObjectCount] {
119+
queueInMainThread([locked, placeholder, ldmObjectCount] {
121120
if (!locked->m_fields->m_label)
122121
return;
123122

124123
std::string labelContent = locked->m_fields->m_label->getString();
125-
size_t pos = labelContent.find(placeholder);
124+
auto pos = labelContent.find(placeholder);
126125
if (pos != std::string::npos)
127126
labelContent.replace(
128127
pos,
@@ -169,18 +168,18 @@ class $modify(MyLevelInfoLayer, LevelInfoLayer) {
169168
labelContent << "Sent: " << (cached.value() ? "Yes" : "No")
170169
<< std::endl;
171170
} else {
172-
const std::string placeholder = "Sent: Loading...";
171+
std::string const placeholder = "Sent: Loading...";
173172
labelContent << placeholder << std::endl;
174173

175-
auto req = geode::utils::web::WebRequest();
174+
auto req = utils::web::WebRequest();
176175
auto levelID = static_cast<int>(level->m_levelID);
177176

178177
// This will call SendDB's API to know if the level was sent or
179178
// not. The actual sent field will be updated after the request
180179
// is completed
181180
m_fields->m_listener.spawn(
182181
req.get(fmt::format("https://api.senddb.dev/api/v1/level/{}", levelID)),
183-
[self = geode::WeakRef<MyLevelInfoLayer>(this), placeholder, levelID](geode::utils::web::WebResponse res) {
182+
[self = WeakRef<MyLevelInfoLayer>(this), placeholder, levelID](utils::web::WebResponse res) {
184183
auto locked = self.lock();
185184
if (!locked || !locked->m_fields->m_label) return;
186185

@@ -252,7 +251,7 @@ class $modify(MyLevelInfoLayer, LevelInfoLayer) {
252251
<< std::endl;
253252

254253
// Once we got all the values for the label, create it and set its settings
255-
m_fields->m_label = cocos2d::CCLabelBMFont::create(
254+
m_fields->m_label = CCLabelBMFont::create(
256255
labelContent.str().c_str(),
257256
"bigFont.fnt"
258257
);

src/managers/SettingsManager.cpp

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,113 @@
11
#include "SettingsManager.h"
22
#include "SentCacheManager.h"
33

4+
using namespace geode::prelude;
5+
46
// First initialize all the parameters
57
CustomStruct::DisplaySettings SettingsManager::Display = {
6-
static_cast<int>(geode::Mod::get()->getSettingValue<int64_t>("text-width-offset")),
7-
static_cast<int>(geode::Mod::get()->getSettingValue<int64_t>("text-height-offset")),
8-
static_cast<float>(geode::Mod::get()->getSettingValue<double>("text-size")),
9-
static_cast<int>(round(static_cast<double>(geode::Mod::get()->getSettingValue<int64_t>("text-opacity")) / 100 * 255)),
10-
geode::Mod::get()->getSettingValue<cocos2d::ccColor3B>("text-color"),
11-
geode::Mod::get()->getSettingValue<std::string>("number-separator")
8+
Mod::get()->getSettingValue<int>("text-width-offset"),
9+
Mod::get()->getSettingValue<int>("text-height-offset"),
10+
Mod::get()->getSettingValue<float>("text-size"),
11+
static_cast<int>(round(Mod::get()->getSettingValue<int>("text-opacity") / 100.f * 255)),
12+
Mod::get()->getSettingValue<ccColor3B>("text-color"),
13+
Mod::get()->getSettingValue<std::string>("number-separator")
1214
};
1315

1416
CustomStruct::ToggleSettings SettingsManager::Toggles = {
15-
geode::Mod::get()->getSettingValue<bool>("show-requested-stars"),
16-
geode::Mod::get()->getSettingValue<bool>("show-featured-rank"),
17-
geode::Mod::get()->getSettingValue<bool>("show-object-count"),
18-
geode::Mod::get()->getSettingValue<bool>("show-ldm-object-count"),
19-
geode::Mod::get()->getSettingValue<bool>("show-game-version"),
20-
geode::Mod::get()->getSettingValue<bool>("show-level-version"),
21-
geode::Mod::get()->getSettingValue<bool>("show-ldm-existence"),
22-
geode::Mod::get()->getSettingValue<bool>("show-sent"),
23-
geode::Mod::get()->getSettingValue<bool>("show-level-id"),
24-
geode::Mod::get()->getSettingValue<bool>("show-original-level-id"),
25-
geode::Mod::get()->getSettingValue<bool>("show-two-player-mode"),
26-
geode::Mod::get()->getSettingValue<bool>("show-editor-time"),
27-
geode::Mod::get()->getSettingValue<bool>("show-editor-time-copies"),
28-
geode::Mod::get()->getSettingValue<bool>("show-attempts"),
29-
geode::Mod::get()->getSettingValue<bool>("show-jumps"),
30-
geode::Mod::get()->getSettingValue<bool>("show-clicks"),
31-
geode::Mod::get()->getSettingValue<bool>("show-attempt-time")
17+
Mod::get()->getSettingValue<bool>("show-requested-stars"),
18+
Mod::get()->getSettingValue<bool>("show-featured-rank"),
19+
Mod::get()->getSettingValue<bool>("show-object-count"),
20+
Mod::get()->getSettingValue<bool>("show-ldm-object-count"),
21+
Mod::get()->getSettingValue<bool>("show-game-version"),
22+
Mod::get()->getSettingValue<bool>("show-level-version"),
23+
Mod::get()->getSettingValue<bool>("show-ldm-existence"),
24+
Mod::get()->getSettingValue<bool>("show-sent"),
25+
Mod::get()->getSettingValue<bool>("show-level-id"),
26+
Mod::get()->getSettingValue<bool>("show-original-level-id"),
27+
Mod::get()->getSettingValue<bool>("show-two-player-mode"),
28+
Mod::get()->getSettingValue<bool>("show-editor-time"),
29+
Mod::get()->getSettingValue<bool>("show-editor-time-copies"),
30+
Mod::get()->getSettingValue<bool>("show-attempts"),
31+
Mod::get()->getSettingValue<bool>("show-jumps"),
32+
Mod::get()->getSettingValue<bool>("show-clicks"),
33+
Mod::get()->getSettingValue<bool>("show-attempt-time")
3234
};
3335

3436
// There is DEFINETELY a better way to do this but if it works it works
3537
$execute {
3638
// Display Settings
37-
geode::listenForSettingChanges<int64_t>("text-width-offset", [](int64_t offset) {
38-
SettingsManager::Display.widthOffset = static_cast<int>(offset);
39+
listenForSettingChanges<int>("text-width-offset", [](int offset) {
40+
SettingsManager::Display.widthOffset = offset;
3941
});
40-
geode::listenForSettingChanges<int64_t>("text-height-offset", [](int64_t offset) {
41-
SettingsManager::Display.heightOffset = static_cast<int>(offset);
42+
listenForSettingChanges<int>("text-height-offset", [](int offset) {
43+
SettingsManager::Display.heightOffset = offset;
4244
});
43-
geode::listenForSettingChanges<double>("text-size", [](double size) {
44-
SettingsManager::Display.size = static_cast<float>(size);
45+
listenForSettingChanges<float>("text-size", [](float size) {
46+
SettingsManager::Display.size = size;
4547
});
46-
geode::listenForSettingChanges<int64_t>("text-opacity", [](int64_t opacity) {
48+
listenForSettingChanges<int>("text-opacity", [](int opacity) {
4749
SettingsManager::Display.opacity = static_cast<int>(round(opacity / 100.f * 255));
4850
});
49-
geode::listenForSettingChanges<cocos2d::ccColor3B>("text-color", [](cocos2d::ccColor3B color) {
51+
listenForSettingChanges<ccColor3B>("text-color", [](ccColor3B color) {
5052
SettingsManager::Display.color = color;
5153
});
52-
geode::listenForSettingChanges<std::string>("number-separator", [](std::string separator) {
54+
listenForSettingChanges<std::string>("number-separator", [](std::string_view separator) {
5355
SettingsManager::Display.separator = separator;
5456
});
5557

5658
// Toggles Settings
57-
geode::listenForSettingChanges<bool>("show-requested-stars", [](bool enabled) {
59+
listenForSettingChanges<bool>("show-requested-stars", [](bool enabled) {
5860
SettingsManager::Toggles.requestedStars = enabled;
5961
});
60-
geode::listenForSettingChanges<bool>("show-featured-rank", [](bool enabled) {
62+
listenForSettingChanges<bool>("show-featured-rank", [](bool enabled) {
6163
SettingsManager::Toggles.featuredRank = enabled;
6264
});
63-
geode::listenForSettingChanges<bool>("show-object-count", [](bool enabled) {
65+
listenForSettingChanges<bool>("show-object-count", [](bool enabled) {
6466
SettingsManager::Toggles.objectCount = enabled;
6567
});
66-
geode::listenForSettingChanges<bool>("show-ldm-object-count", [](bool enabled) {
68+
listenForSettingChanges<bool>("show-ldm-object-count", [](bool enabled) {
6769
SettingsManager::Toggles.ldmObjectCount = enabled;
6870
});
69-
geode::listenForSettingChanges<bool>("show-game-version", [](bool enabled) {
71+
listenForSettingChanges<bool>("show-game-version", [](bool enabled) {
7072
SettingsManager::Toggles.gameVersion = enabled;
7173
});
72-
geode::listenForSettingChanges<bool>("show-level-version", [](bool enabled) {
74+
listenForSettingChanges<bool>("show-level-version", [](bool enabled) {
7375
SettingsManager::Toggles.levelVersion = enabled;
7476
});
75-
geode::listenForSettingChanges<bool>("show-ldm-existence", [](bool enabled) {
77+
listenForSettingChanges<bool>("show-ldm-existence", [](bool enabled) {
7678
SettingsManager::Toggles.ldmExistence = enabled;
7779
});
78-
geode::listenForSettingChanges<bool>("show-sent", [](bool enabled) {
80+
listenForSettingChanges<bool>("show-sent", [](bool enabled) {
7981
if (!enabled)
8082
SentCacheManager::Clear();
8183

8284
SettingsManager::Toggles.sent = enabled;
8385
});
84-
geode::listenForSettingChanges<bool>("show-level-id", [](bool enabled) {
86+
listenForSettingChanges<bool>("show-level-id", [](bool enabled) {
8587
SettingsManager::Toggles.levelID = enabled;
8688
});
87-
geode::listenForSettingChanges<bool>("show-original-level-id", [](bool enabled) {
89+
listenForSettingChanges<bool>("show-original-level-id", [](bool enabled) {
8890
SettingsManager::Toggles.originalLevel = enabled;
8991
});
90-
geode::listenForSettingChanges<bool>("show-two-player-mode", [](bool enabled) {
92+
listenForSettingChanges<bool>("show-two-player-mode", [](bool enabled) {
9193
SettingsManager::Toggles.twoPlayerMode = enabled;
9294
});
93-
geode::listenForSettingChanges<bool>("show-editor-time", [](bool enabled) {
95+
listenForSettingChanges<bool>("show-editor-time", [](bool enabled) {
9496
SettingsManager::Toggles.editorTime = enabled;
9597
});
96-
geode::listenForSettingChanges<bool>("show-editor-time-copies", [](bool enabled) {
98+
listenForSettingChanges<bool>("show-editor-time-copies", [](bool enabled) {
9799
SettingsManager::Toggles.editorTimeCopies = enabled;
98100
});
99-
geode::listenForSettingChanges<bool>("show-attempts", [](bool enabled) {
101+
listenForSettingChanges<bool>("show-attempts", [](bool enabled) {
100102
SettingsManager::Toggles.attempts = enabled;
101103
});
102-
geode::listenForSettingChanges<bool>("show-jumps", [](bool enabled) {
104+
listenForSettingChanges<bool>("show-jumps", [](bool enabled) {
103105
SettingsManager::Toggles.jumps = enabled;
104106
});
105-
geode::listenForSettingChanges<bool>("show-clicks", [](bool enabled) {
107+
listenForSettingChanges<bool>("show-clicks", [](bool enabled) {
106108
SettingsManager::Toggles.clicks = enabled;
107109
});
108-
geode::listenForSettingChanges<bool>("show-attempt-time", [](bool enabled) {
110+
listenForSettingChanges<bool>("show-attempt-time", [](bool enabled) {
109111
SettingsManager::Toggles.attemptTime = enabled;
110112
});
111113
};

src/utils/CustomStruct.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ namespace CustomStruct {
99
cocos2d::ccColor3B color;
1010
std::string separator;
1111

12-
float getWidth() const {
13-
return cocos2d::CCDirector::get()->getWinSize().width * 0.2f + widthOffset;
14-
};
15-
float getHeight() const {
16-
return cocos2d::CCDirector::get()->getWinSize().height * 0.7f + heightOffset;
17-
};
12+
cocos2d::CCPoint getPosition() const {
13+
auto winSize = cocos2d::CCDirector::get()->getWinSize();
14+
15+
return {
16+
winSize.width * 0.2f + widthOffset,
17+
winSize.height * 0.7f + heightOffset
18+
};
19+
}
1820
};
1921

2022
struct ToggleSettings {

src/utils/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Utils.h"
22
#include "../managers/SettingsManager.h"
33

4-
std::unordered_map<int, std::string> Utils::GameVersions = {
4+
std::unordered_map<int, std::string_view> Utils::GameVersions = {
55
{ 22, "2.2" },
66
{ 21, "2.1" },
77
{ 20, "2.0" },
@@ -10,7 +10,7 @@ std::unordered_map<int, std::string> Utils::GameVersions = {
1010
{ 10, "1.7" }
1111
};
1212

13-
std::string Utils::GetGameVersion(int gameVersion) {
13+
std::string_view Utils::GetGameVersion(int gameVersion) {
1414
if (Utils::GameVersions.count(gameVersion))
1515
return Utils::GameVersions.at(gameVersion);
1616
return "Pre-1.7";

src/utils/Utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
class Utils {
44
private:
5-
static std::unordered_map<int, std::string> GameVersions;
5+
static std::unordered_map<int, std::string_view> GameVersions;
66

77
public:
8-
static std::string GetGameVersion(int gameVersion);
8+
static std::string_view GetGameVersion(int gameVersion);
99

1010
static std::string FormatNumber(int number);
1111
static std::string FormatTime(std::chrono::seconds seconds);

0 commit comments

Comments
 (0)