Skip to content

Commit

Permalink
load time for level string for non-saved levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Sep 15, 2023
1 parent 6da5622 commit f88bfc5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 62 deletions.
32 changes: 19 additions & 13 deletions src/hooks/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@ class $modify(LevelInfoLayer) {
auto cache = BetterInfoCache::sharedState();
cache->storeDatesForLevel(this->m_level);

auto label = typeinfo_cast<CCLabelBMFont*>(getChildByID("length-label"));
if(label) {
auto bmFont = CCLabelBMFont::create("Loading", "bigFont.fnt");
bmFont->setID("bi-exact-time");
bmFont->setPosition({label->getPositionX() + 1, label->getPositionY() - 2.f}); //193 - 185
bmFont->setAnchorPoint({0,1});
bmFont->setScale(0.325f);
addChild(bmFont);
label->setPositionY(label->getPositionY() + 6.f);
}

return true;
}

void updateLabelValues() {
LevelInfoLayer::updateLabelValues();
std::thread([this](){
auto wt = ExtendedLevelInfo::workingTime(std::round(BetterInfo::timeForLevelString(m_level->m_levelString)));
Loader::get()->queueInMainThread([this, wt]() {
auto label = typeinfo_cast<CCLabelBMFont*>(getChildByID("length-label"));
if(label) {
auto bmFont = typeinfo_cast<CCLabelBMFont*>(getChildByID("bi-exact-time"));
if(label && bmFont) {
bmFont->setString(fmt::format("{}", wt).c_str());
//label->setString(fmt::format("{} ({})", label->getString(), wt).c_str());
auto bmFont = CCLabelBMFont::create(fmt::format("{}", wt).c_str(), "bigFont.fnt");
bmFont->setID("bi-exact-time");
bmFont->setPosition({label->getPositionX() + 1, label->getPositionY() - 2.f}); //todo: position properly
label->setPositionY(label->getPositionY() + 6.f);

//193 - 185
bmFont->setAnchorPoint({0,1});
bmFont->setScale(0.325f);
addChild(bmFont);
}
});
}).detach();


return true;
}

void onViewProfile(CCObject* sender) {
Expand Down
103 changes: 54 additions & 49 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,59 +526,64 @@ inline uint64_t timeInMs() {
}

float BetterInfo::timeForLevelString(const std::string& levelString) {
//todo: checked portals
auto a = timeInMs();

auto decompressString = decodeBase64Gzip(levelString);
auto c = timeInMs();
std::stringstream responseStream(decompressString);
std::string currentObject;
std::string currentKey;
std::string keyID;

std::stringstream objectStream;
float prevPortalX = 0;
int prevPortalId = 0;

float timeFull = 0;

float maxPos = 0;
while(getline(responseStream, currentObject, ';')){
size_t i = 0;
int objID = 0;
float xPos = 0;

objectStream.clear();
objectStream << currentObject;
objectStream.seekp(0);
objectStream.seekg(0);
//std::stringstream objectStream(currentObject);
while(getline(objectStream, currentKey, ',')) {


if(i % 2 == 0) keyID = currentKey;
else {
if(keyID == "1") objID = std::stoi(currentKey);
else if(keyID == "2") xPos = std::stof(currentKey);
else if(keyID == "kA4") prevPortalId = speedToPortalId(std::stoi(currentKey));
try {
//todo: checked portals
auto a = timeInMs();

auto decompressString = decodeBase64Gzip(levelString);
auto c = timeInMs();
std::stringstream responseStream(decompressString);
std::string currentObject;
std::string currentKey;
std::string keyID;

std::stringstream objectStream;
float prevPortalX = 0;
int prevPortalId = 0;

float timeFull = 0;

float maxPos = 0;
while(getline(responseStream, currentObject, ';')){
size_t i = 0;
int objID = 0;
float xPos = 0;

objectStream.clear();
objectStream << currentObject;
objectStream.seekp(0);
objectStream.seekg(0);
//std::stringstream objectStream(currentObject);
while(getline(objectStream, currentKey, ',')) {


if(i % 2 == 0) keyID = currentKey;
else {
if(keyID == "1") objID = std::stoi(currentKey);
else if(keyID == "2") xPos = std::stof(currentKey);
else if(keyID == "kA4") prevPortalId = speedToPortalId(std::stoi(currentKey));
}
i++;

if(xPos != 0 && objID != 0) break;
}
i++;

if(xPos != 0 && objID != 0) break;
}
if(maxPos < xPos) maxPos = xPos;
if(!objectIDIsSpeedPortal(objID)) continue;

if(maxPos < xPos) maxPos = xPos;
if(!objectIDIsSpeedPortal(objID)) continue;
timeFull += (xPos - prevPortalX) / travelForPortalId(prevPortalId);
prevPortalId = objID;
prevPortalX = xPos;
}

timeFull += (xPos - prevPortalX) / travelForPortalId(prevPortalId);
prevPortalId = objID;
prevPortalX = xPos;
timeFull += (maxPos - prevPortalX) / travelForPortalId(prevPortalId);
auto b = timeInMs() - a;
log::info("time spent decompressing: {}", c - a);
log::info("time spent: {}", b);
return timeFull;
} catch(std::exception e) {
log::error("An exception has occured while calculating time for levelString: {}", e.what());
return 0;
}

timeFull += (maxPos - prevPortalX) / travelForPortalId(prevPortalId);
auto b = timeInMs() - a;
log::info("time spent decompressing: {}", c - a);
log::info("time spent: {}", b);
return timeFull;

}

0 comments on commit f88bfc5

Please sign in to comment.