Skip to content

Commit

Permalink
shift bundle size/diff calculations to cpp
Browse files Browse the repository at this point in the history
related cleanup of vars and code luaside
  • Loading branch information
MinaciousGrace committed Jul 20, 2018
1 parent e240076 commit 77d12c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ local function makedoots(i)
end,
OnCommand=function(self)
local bundle = DLMAN:GetCoreBundle(minidoots[i]:lower())
local sumsize = 0
for i=1,#bundle do
sumsize = sumsize + bundle[i]:GetSize()
end
self:settextf("(%dmb)", sumsize/1024/1024)
self:settextf("(%dmb)", bundle["TotalSize")

end
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,13 +732,9 @@ local iamspartacus = capWideScale(0,20)
local noiamspartacus = capWideScale(20,40)
local selectedbundle = false

local bundleinfo
local bundlename
local bundleindex

local bundlerating = 0
local bundlesize = 0

local function makedoots(i)
local packinfo
local t = Def.ActorFrame{
Expand All @@ -754,23 +750,8 @@ local function makedoots(i)
selectedbundle = true
bundlename = minidoots[i]
bundleindex = i

currentpage = 1
packlist = DLMAN:GetCoreBundle(bundlename:lower())

-- these should prolly be shifted into the internal bundle object -mina
local sumrating = 0
local sumsize = 0
if #packlist > 0 then
for i=1,#packlist do
sumsize = sumsize + packlist[i]:GetSize()
sumrating = sumrating + packlist[i]:GetAvgDifficulty()
end

bundlerating = sumrating/#packlist
bundlesize = sumsize/1024/1024
end

MESSAGEMAN:Broadcast("bundletime")
MESSAGEMAN:Broadcast("UpdatePacks")
end
Expand Down Expand Up @@ -803,21 +784,8 @@ local function makesuperdoots(i)
selectedbundle = true
bundlename = minidoots[i].."-Expanded"
bundleindex = i

currentpage = 1
packlist = DLMAN:GetCoreBundle(bundlename:lower())

local sumrating = 0
local sumsize = 0
if #packlist > 0 then
for i=1,#packlist do
sumsize = sumsize + packlist[i]:GetSize()
sumrating = sumrating + packlist[i]:GetAvgDifficulty()
end
bundlerating = sumrating/#packlist
bundlesize = sumsize/1024/1024
end

MESSAGEMAN:Broadcast("bundletime")
MESSAGEMAN:Broadcast("UpdatePacks")
end
Expand Down Expand Up @@ -868,7 +836,7 @@ t[#t+1] = LoadFont("Common normal") .. {
self:settext("Core Bundles (Expanded):")
end,
bundletimeMessageCommand=function(self)
self:settextf("Total Size: %d(MB)", bundlesize)
self:settextf("Total Size: %d(MB)", packlist["TotalSize"])
end,
MouseRightClickMessageCommand=function(self)
if update then
Expand All @@ -882,8 +850,8 @@ t[#t+1] = LoadFont("Common normal") .. {
self:xy(250+noiamspartacus,bundlegumbley - 36):zoom(0.5):halign(0):valign(0):visible(false)
end,
bundletimeMessageCommand=function(self)
self:settextf("Avg: %5.2f", bundlerating)
self:diffuse(byMSD(bundlerating))
self:settextf("Avg: %5.2f", packlist["AveragePackDifficulty"])
self:diffuse(byMSD(packlist["AveragePackDifficulty"]))
self:visible(true)
end,
MouseRightClickMessageCommand=function(self)
Expand Down
21 changes: 20 additions & 1 deletion src/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,17 +1596,36 @@ class LunaDownloadManager : public Luna<DownloadManager>
}
static int GetCoreBundle(T* p, lua_State* L)
{
// this should probably return nil but only if we make it its own lua thing first -mina
auto bundle = DLMAN->GetCoreBundle(SArg(1));
lua_createtable(L, bundle.size(), 0);
for (size_t i = 0; i < bundle.size(); ++i) {
bundle[i]->PushSelf(L);
lua_rawseti(L, -2, i + 1);
}

size_t totalsize = 0;
float avgpackdiff = 0.f;

for (auto p : bundle) {
totalsize += p->size;
avgpackdiff += p->avgDifficulty;
}

if(!bundle.empty())
avgpackdiff /= bundle.size();
totalsize = totalsize / 1024 / 1024;

// this may be kind of unintuitive but lets roll with it for now -mina
lua_pushnumber(L, totalsize);
lua_setfield(L, -2, "TotalSize");
lua_pushnumber(L, avgpackdiff);
lua_setfield(L, -2, "AveragePackDifficulty");

return 1;
}
static int DownloadCoreBundle(T* p, lua_State* L)
{
// pass "novice", "expert" etc, should start a queue and download packs in sequence rather than concurrently to minimize time before can begin -mina
DLMAN->DownloadCoreBundle(SArg(1));
return 1;
}
Expand Down

0 comments on commit 77d12c6

Please sign in to comment.