Skip to content

Commit

Permalink
Prevent loading same replay twice
Browse files Browse the repository at this point in the history
  • Loading branch information
crashfort committed May 4, 2024
1 parent ecf6079 commit 442243e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/rv_main.inc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void RV_StartPlayback()
public void RV_StopPlayback()
{
RV_StopPlaybackBots();
RV_StopMenuLoadRestriction();
}

public void RV_ResetPlayback()
Expand Down
29 changes: 28 additions & 1 deletion src/rv_menu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public void RV_StartMenus()
// Download map info immediately.
// This will call into Net_MapInfoDownloadReceived or Net_MapInfoDownloadFailed in rv_net_callbacks.inc.
Net_DownloadMapInfo();

rv_loaded_streams = CreateTrie();
}

// Called on map end.
Expand All @@ -109,6 +111,7 @@ public void RV_StopMenus()

delete rv_zone_list_menu;
delete rv_main_menu;
delete rv_loaded_streams;
}

public int RV_HandleSelectZoneMenu(Menu menu, MenuAction action, int param1, int param2)
Expand Down Expand Up @@ -218,6 +221,10 @@ public int RV_HandleSelectReplayMenu(Menu menu, MenuAction action, int param1, i
RV_LoadStreamSpawnBot(replay_id);
}

// Set so this cannot be loaded again.
// This will not allow you to retry to download if it fails, which is bad but we don't really handle that case.
SetTrieValue(rv_loaded_streams, replay_id, 1);

DisplayMenu(menu, param1, MENU_TIME_FOREVER);
}

Expand All @@ -233,6 +240,21 @@ public int RV_HandleSelectReplayMenu(Menu menu, MenuAction action, int param1, i
{
}

else if (action == MenuAction_DrawItem)
{
int dummy;

char replay_id[RV_REPLAY_ID_SIZE];
GetMenuItem(menu, param2, replay_id, sizeof(replay_id));

if (GetTrieValue(rv_loaded_streams, replay_id, dummy))
{
return ITEMDRAW_DISABLED; // This is already loaded, disable item.
}

return ITEMDRAW_DEFAULT;
}

return 0;
}

Expand All @@ -250,7 +272,7 @@ public void RV_CreateNewReplayListMenu(int response_handle)
char menu_title[128];
Format(menu_title, sizeof(menu_title), "%s (%d replays)", zone_title, num_replays);

Menu menu = CreateMenu(RV_HandleSelectReplayMenu);
Menu menu = CreateMenu(RV_HandleSelectReplayMenu, MENU_ACTIONS_DEFAULT | MenuAction_DrawItem);
SetMenuTitle(menu, menu_title);
SetMenuExitBackButton(menu, true);

Expand All @@ -276,3 +298,8 @@ public void RV_CreateNewReplayListMenu(int response_handle)

DisplayMenu(menu, user_id, MENU_TIME_FOREVER);
}

public void RV_StopMenuLoadRestriction()
{
ClearTrie(rv_loaded_streams);
}
6 changes: 5 additions & 1 deletion src/rv_priv.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ char rv_cur_map[128];

// Downloaded replay listings for a zone.
// These are created on demand and reused, meaning that new requests are not made for existing ones.
StringMap rv_replay_listings; // Array of RVReplayListing.
StringMap rv_replay_listings; // Value is RVReplayListing.

// Main menu.
// This is created once after map start.
Expand All @@ -123,3 +123,7 @@ Menu rv_zone_list_menu;
// Menus for replay selection in a zone.
// These are created on demand and reused, meaning that new requests are not made for existing ones.
Menu rv_zone_menus[NET_ZONES_MAX];

// Currently playing streams.
// Used to guard against duplication during playback in the replay selection menu.
StringMap rv_loaded_streams; // Value is int.

0 comments on commit 442243e

Please sign in to comment.