Commit 51459582 authored by Dino Bollinger's avatar Dino Bollinger
Browse files

More WIP work on the Voidwrap Workshop Integration

Poll workshop stuff once per second on the main menu only.
Add debug messages to check if stuff works correctly.
Will be rebased once everything is clean.
parent 5dba3383
......@@ -215,6 +215,7 @@ void communityapiSetRichPresence(char const * key, char const * str)
if (nullptr == Voidwrap_Steam_SetRichPresence)
return;
DLOG_F(INFO, "Voidwrap: attempt to set rich presence");
Voidwrap_Steam_SetRichPresence(key, str);
#else
UNREFERENCED_PARAMETER(str);
......@@ -230,6 +231,7 @@ void communityapiClearRichPresence(void)
if (nullptr == Voidwrap_Steam_ClearRichPresence)
return;
DLOG_F(INFO, "Voidwrap: attempt to clear rich presence");
Voidwrap_Steam_ClearRichPresence();
#endif
}
......@@ -243,6 +245,7 @@ void communityapiQuerySubscribedItems(void)
if (nullptr == Voidwrap_Steam_QuerySubscribedItems)
return;
DLOG_F(INFO, "Voidwrap: query subscribed items");
Voidwrap_Steam_QuerySubscribedItems();
#endif
}
......@@ -255,6 +258,7 @@ bool communityapiIsRunningQuery(void)
if (nullptr == Voidwrap_Steam_IsRunningQuery)
return false;
DLOG_F(INFO, "Voidwrap: check if is running query");
return Voidwrap_Steam_IsRunningQuery();
#else
return false;
......@@ -269,6 +273,7 @@ bool communityapiRetrieveSubscribedItems(uint64_t** subscribedItems, uint32_t* n
if (nullptr == Voidwrap_Steam_RetrieveSubscribedItems)
return false;
DLOG_F(INFO, "Voidwrap: attempt to retrieve subscribed items");
return Voidwrap_Steam_RetrieveSubscribedItems(subscribedItems, numSubscribed);
#else
UNREFERENCED_PARAMETER(subscribedItems);
......@@ -286,6 +291,7 @@ void communityapiDownloadWorkshopItem(uint64_t fileId)
if (nullptr == Voidwrap_Steam_DownloadWorkshopItem)
return;
DLOG_F(INFO, "Voidwrap: attempt to download workshop item: %llx", fileId);
Voidwrap_Steam_DownloadWorkshopItem(fileId);
#else
UNREFERENCED_PARAMETER(fileId);
......@@ -300,6 +306,7 @@ bool communityapiIsDownloading(void)
if (nullptr == Voidwrap_Steam_IsDownloading)
return false;
DLOG_F(INFO, "Voidwrap: attempt to retrieve global download state");
return Voidwrap_Steam_IsDownloading();
#else
return false;
......@@ -314,6 +321,7 @@ void communityapiGetBytesDownloaded(uint64_t* bytesDownloaded, uint64_t* bytesTo
if (nullptr == Voidwrap_Steam_GetBytesDownloaded)
return;
DLOG_F(INFO, "Voidwrap: attempt to retrieve download bytes");
Voidwrap_Steam_GetBytesDownloaded(bytesDownloaded, bytesTotal);
#else
UNREFERENCED_PARAMETER(bytesDownloaded);
......@@ -330,6 +338,7 @@ bool communityapiItemIsInstalled(uint64_t fileId)
if (nullptr == Voidwrap_Steam_ItemIsInstalled)
return 0;
DLOG_F(INFO, "Voidwrap: attempt to retrieve installed state for item: %llx", fileId);
return Voidwrap_Steam_ItemIsInstalled(fileId);
#else
UNREFERENCED_PARAMETER(fileId);
......@@ -346,6 +355,7 @@ bool communityapiItemIsSubscribed(uint64_t fileId)
if (nullptr == Voidwrap_Steam_ItemIsSubscribed)
return 0;
DLOG_F(INFO, "Voidwrap: attempt to retrieve subscribed state for item: %llx", fileId);
return Voidwrap_Steam_ItemIsSubscribed(fileId);
#else
UNREFERENCED_PARAMETER(fileId);
......@@ -362,6 +372,7 @@ bool communityapiItemNeedsUpdate(uint64_t fileId)
if (nullptr == Voidwrap_Steam_ItemNeedsUpdate)
return 0;
DLOG_F(INFO, "Voidwrap: attempt to retrieve update state for item: %llx", fileId);
return Voidwrap_Steam_ItemNeedsUpdate(fileId);
#else
UNREFERENCED_PARAMETER(fileId);
......@@ -378,6 +389,7 @@ bool communityapiItemIsDownloading(uint64_t fileId)
if (nullptr == Voidwrap_Steam_ItemIsDownloading)
return 0;
DLOG_F(INFO, "Voidwrap: attempt to retrieve download state for item: %llx", fileId);
return Voidwrap_Steam_ItemIsDownloading(fileId);
#else
UNREFERENCED_PARAMETER(fileId);
......@@ -394,6 +406,7 @@ bool communityapiGetItemInstallInfo(uint64_t fileId, char* folderPath, uint32_t
if (nullptr == Voidwrap_Steam_GetItemInstallInfo)
return false;
DLOG_F(INFO, "Voidwrap: attempt to retrieve item install info for item: %llx", fileId);
return Voidwrap_Steam_GetItemInstallInfo(fileId, folderPath, folderBufSize);
#else
UNREFERENCED_PARAMETER(fileId);
......
......@@ -1274,7 +1274,7 @@ static void AddonJson_ReadWorkshopItems(sjson_context *ctx)
if (!g_currentWorkshopItems || !g_numWorkshopItems)
return;
for (uint i = 0; i < g_numWorkshopItems; i++)
for (unsigned int i = 0; i < g_numWorkshopItems; i++)
{
uint64_t fileId = g_currentWorkshopItems[i];
......@@ -1459,4 +1459,4 @@ void Addon_FreeUserMods(void)
g_addoncount_mods = 0;
}
#endif
\ No newline at end of file
#endif
......@@ -1266,6 +1266,14 @@ static MenuEntry_t **MEL_SAVE;
// -------------------------------------------
// Addon Menu - Definitions and Variables
// check once per second
#define WORKSHOP_POLLDELAY 120
static bool m_workshop_disable_addons_menu = false;
static bool m_active_workshop_query = false;
static uint32_t m_workshop_last_polltime = 0;
static char m_workshop_download_msg[32] = {};
int32_t cvar_addonmenu_strict = 1;
// total addon count combined
......@@ -2521,7 +2529,7 @@ static void Menu_Addon_RefreshTextBuffers(const useraddon_t* addonPtr)
Bsprintf(tempbuf, "\n^%dAdding user content:^%d\n", abt_headerpal, abt_textpal);
Bstrcat(m_addonbodytext, tempbuf);
if (true || communityapiEnabled())
if (communityapiEnabled())
{
Bstrcat(m_addonbodytext, "- Open the Workshop in Steam, and subscribe to the items you wish to download.\n"
"- Go back to the main menu and wait for the download to finish.\n"
......@@ -4212,73 +4220,77 @@ static void Menu_PreDraw(MenuID_t cm, MenuEntry_t* entry, const vec2_t origin)
#ifdef ADDONS_MENU
if (cm == MENU_MAIN)
{
bool displayedMessage = false;
if (communityapiEnabled())
{
uint64_t* subscribedItems; uint32_t numSubscribedItems;
if (communityapiRetrieveSubscribedItems(&subscribedItems, &numSubscribedItems))
if (timer120() - m_workshop_last_polltime > WORKSHOP_POLLDELAY)
{
DO_FREE_AND_NULL(g_currentWorkshopItems);
g_currentWorkshopItems = subscribedItems;
g_numWorkshopItems = numSubscribedItems;
uint64_t* subscribedItems; uint32_t numSubscribedItems;
if (m_active_workshop_query && communityapiRetrieveSubscribedItems(&subscribedItems, &numSubscribedItems))
{
DLOG_F(INFO, "Voidwrap: successfully retrieved %d items", numSubscribedItems);
DO_FREE_AND_NULL(g_currentWorkshopItems);
g_currentWorkshopItems = subscribedItems;
g_numWorkshopItems = numSubscribedItems;
// remove items in download stack first, if any remain
while (g_workshopDownloadStack)
// remove items in download stack first, if any remain
while (g_workshopDownloadStack)
{
workshopitem_t* tempws = g_workshopDownloadStack->next;
Xfree(g_workshopDownloadStack);
g_workshopDownloadStack = tempws;
}
for (int i = 0; i < g_numWorkshopItems; i++)
{
const uint64_t fileid = g_currentWorkshopItems[i];
Bassert(communityapiItemIsSubscribed(fileid));
if (!communityapiItemIsInstalled(fileid) || communityapiItemNeedsUpdate(fileid))
{
workshopitem_t* wsitem = (workshopitem_t*)Xcalloc(1, sizeof(workshopitem_t));
wsitem->fileid = fileid;
wsitem->next = g_workshopDownloadStack;
g_workshopDownloadStack = wsitem;
}
}
}
bool isDownloading = communityapiIsDownloading();
if (!isDownloading && g_workshopDownloadStack)
{
workshopitem_t* tempws = g_workshopDownloadStack->next;
communityapiDownloadWorkshopItem(g_workshopDownloadStack->fileid);
Xfree(g_workshopDownloadStack);
g_workshopDownloadStack = tempws;
isDownloading = true;
}
for (int i = 0; i < g_numWorkshopItems; i++)
m_workshop_download_msg[0] = '\0';
if (isDownloading)
{
const uint64_t fileid = g_currentWorkshopItems[i];
Bassert(communityapiItemIsSubscribed(fileid));
if (!communityapiItemIsInstalled(fileid) || communityapiItemNeedsUpdate(fileid))
{
workshopitem_t* wsitem = (workshopitem_t*) Xcalloc(1, sizeof(workshopitem_t));
wsitem->fileid = fileid;
wsitem->next = g_workshopDownloadStack;
g_workshopDownloadStack = wsitem;
}
}
}
bool isDownloading = communityapiIsDownloading();
if (!isDownloading && g_workshopDownloadStack)
{
workshopitem_t* tempws = g_workshopDownloadStack->next;
communityapiDownloadWorkshopItem(g_workshopDownloadStack->fileid);
Xfree(g_workshopDownloadStack);
g_workshopDownloadStack = tempws;
isDownloading = true;
}
if (!displayedMessage && isDownloading)
{
uint64_t bytesDL, bytesTotal;
communityapiGetBytesDownloaded(&bytesDL, &bytesTotal);
uint64_t bytesDL, bytesTotal;
communityapiGetBytesDownloaded(&bytesDL, &bytesTotal);
const char* msg = "Download Pending...";
if (bytesTotal > 0)
{
char dlbuf[32];
Bsprintf(dlbuf, "Download Progress: %ld%%", bytesDL/bytesTotal);
msg = dlbuf;
if (bytesTotal > 0)
Bsprintf(m_workshop_download_msg, "Download Progress: %ld%%", bytesDL / bytesTotal);
else
Bstrcpy(m_workshop_download_msg, "Download Pending...");
}
Menu_Main_DisplayMessage(origin, msg, MENUTEXTPAL_GREEN, 6-MENU_GLOWSHADE);
displayedMessage = true;
m_workshop_disable_addons_menu = communityapiIsRunningQuery() || isDownloading;
m_workshop_last_polltime = timer120();
}
}
// disable the addon menu if a workshop item is downloading, or shareware is active
MenuEntry_DisableOnCondition(&ME_MAIN_ADDONS, g_Shareware || communityapiIsRunningQuery() || communityapiIsDownloading());
MenuEntry_DisableOnCondition(&ME_MAIN_ADDONS, g_Shareware || m_workshop_disable_addons_menu);
if (!displayedMessage && g_addon_failedboot)
if (m_workshop_download_msg[0])
{
Menu_Main_DisplayMessage(origin, m_workshop_download_msg, MENUTEXTPAL_GREEN, 6 - MENU_GLOWSHADE);
}
else if (g_addon_failedboot)
{
const char* msg = FURY ? "Failed to launch user content!" : "Failed to launch addons!";
Menu_Main_DisplayMessage(origin, msg, MENUTEXTPAL_RED, 6-MENU_GLOWSHADE);
displayedMessage = true;
}
}
#endif
......@@ -6598,7 +6610,11 @@ static void Menu_AboutToStartDisplaying(Menu_t * m)
if (communityapiEnabled())
{
if (!communityapiIsRunningQuery() && !communityapiIsDownloading())
{
DLOG_F(INFO, "Voidwrap: send query for subscribed items");
communityapiQuerySubscribedItems();
m_active_workshop_query = true;
}
}
if (FURY)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment