Skip to content

Commit 77d12c6

Browse files
shift bundle size/diff calculations to cpp
related cleanup of vars and code luaside
1 parent e240076 commit 77d12c6

File tree

3 files changed

+24
-41
lines changed

3 files changed

+24
-41
lines changed

Themes/Til Death/BGAnimations/ScreenCoreBundleSelect underlay.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ local function makedoots(i)
9898
end,
9999
OnCommand=function(self)
100100
local bundle = DLMAN:GetCoreBundle(minidoots[i]:lower())
101-
local sumsize = 0
102-
for i=1,#bundle do
103-
sumsize = sumsize + bundle[i]:GetSize()
104-
end
105-
self:settextf("(%dmb)", sumsize/1024/1024)
101+
self:settextf("(%dmb)", bundle["TotalSize")
106102

107103
end
108104
}

Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/downloads.lua

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,9 @@ local iamspartacus = capWideScale(0,20)
732732
local noiamspartacus = capWideScale(20,40)
733733
local selectedbundle = false
734734

735-
local bundleinfo
736735
local bundlename
737736
local bundleindex
738737

739-
local bundlerating = 0
740-
local bundlesize = 0
741-
742738
local function makedoots(i)
743739
local packinfo
744740
local t = Def.ActorFrame{
@@ -754,23 +750,8 @@ local function makedoots(i)
754750
selectedbundle = true
755751
bundlename = minidoots[i]
756752
bundleindex = i
757-
758753
currentpage = 1
759754
packlist = DLMAN:GetCoreBundle(bundlename:lower())
760-
761-
-- these should prolly be shifted into the internal bundle object -mina
762-
local sumrating = 0
763-
local sumsize = 0
764-
if #packlist > 0 then
765-
for i=1,#packlist do
766-
sumsize = sumsize + packlist[i]:GetSize()
767-
sumrating = sumrating + packlist[i]:GetAvgDifficulty()
768-
end
769-
770-
bundlerating = sumrating/#packlist
771-
bundlesize = sumsize/1024/1024
772-
end
773-
774755
MESSAGEMAN:Broadcast("bundletime")
775756
MESSAGEMAN:Broadcast("UpdatePacks")
776757
end
@@ -803,21 +784,8 @@ local function makesuperdoots(i)
803784
selectedbundle = true
804785
bundlename = minidoots[i].."-Expanded"
805786
bundleindex = i
806-
807787
currentpage = 1
808788
packlist = DLMAN:GetCoreBundle(bundlename:lower())
809-
810-
local sumrating = 0
811-
local sumsize = 0
812-
if #packlist > 0 then
813-
for i=1,#packlist do
814-
sumsize = sumsize + packlist[i]:GetSize()
815-
sumrating = sumrating + packlist[i]:GetAvgDifficulty()
816-
end
817-
bundlerating = sumrating/#packlist
818-
bundlesize = sumsize/1024/1024
819-
end
820-
821789
MESSAGEMAN:Broadcast("bundletime")
822790
MESSAGEMAN:Broadcast("UpdatePacks")
823791
end
@@ -868,7 +836,7 @@ t[#t+1] = LoadFont("Common normal") .. {
868836
self:settext("Core Bundles (Expanded):")
869837
end,
870838
bundletimeMessageCommand=function(self)
871-
self:settextf("Total Size: %d(MB)", bundlesize)
839+
self:settextf("Total Size: %d(MB)", packlist["TotalSize"])
872840
end,
873841
MouseRightClickMessageCommand=function(self)
874842
if update then
@@ -882,8 +850,8 @@ t[#t+1] = LoadFont("Common normal") .. {
882850
self:xy(250+noiamspartacus,bundlegumbley - 36):zoom(0.5):halign(0):valign(0):visible(false)
883851
end,
884852
bundletimeMessageCommand=function(self)
885-
self:settextf("Avg: %5.2f", bundlerating)
886-
self:diffuse(byMSD(bundlerating))
853+
self:settextf("Avg: %5.2f", packlist["AveragePackDifficulty"])
854+
self:diffuse(byMSD(packlist["AveragePackDifficulty"]))
887855
self:visible(true)
888856
end,
889857
MouseRightClickMessageCommand=function(self)

src/DownloadManager.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,17 +1596,36 @@ class LunaDownloadManager : public Luna<DownloadManager>
15961596
}
15971597
static int GetCoreBundle(T* p, lua_State* L)
15981598
{
1599+
// this should probably return nil but only if we make it its own lua thing first -mina
15991600
auto bundle = DLMAN->GetCoreBundle(SArg(1));
16001601
lua_createtable(L, bundle.size(), 0);
16011602
for (size_t i = 0; i < bundle.size(); ++i) {
16021603
bundle[i]->PushSelf(L);
16031604
lua_rawseti(L, -2, i + 1);
16041605
}
1606+
1607+
size_t totalsize = 0;
1608+
float avgpackdiff = 0.f;
1609+
1610+
for (auto p : bundle) {
1611+
totalsize += p->size;
1612+
avgpackdiff += p->avgDifficulty;
1613+
}
1614+
1615+
if(!bundle.empty())
1616+
avgpackdiff /= bundle.size();
1617+
totalsize = totalsize / 1024 / 1024;
1618+
1619+
// this may be kind of unintuitive but lets roll with it for now -mina
1620+
lua_pushnumber(L, totalsize);
1621+
lua_setfield(L, -2, "TotalSize");
1622+
lua_pushnumber(L, avgpackdiff);
1623+
lua_setfield(L, -2, "AveragePackDifficulty");
1624+
16051625
return 1;
16061626
}
16071627
static int DownloadCoreBundle(T* p, lua_State* L)
16081628
{
1609-
// pass "novice", "expert" etc, should start a queue and download packs in sequence rather than concurrently to minimize time before can begin -mina
16101629
DLMAN->DownloadCoreBundle(SArg(1));
16111630
return 1;
16121631
}

0 commit comments

Comments
 (0)