Skip to content

Commit

Permalink
Use command to clear all renders
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Aug 15, 2024
1 parent f27bfd7 commit d960a94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 35 deletions.
8 changes: 3 additions & 5 deletions RLBotCS/ManagerTools/Rendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ public void ClearClientRenders(int clientId)
_clientRenderTracker.Remove(clientId);
}

public void ClearAllRenders()
public void ClearAllRenders(MatchCommandSender matchCommandSender)
{
foreach (var clientRenders in _clientRenderTracker.Values)
foreach (int renderId in clientRenders.Keys)
foreach (ushort renderItem in clientRenders[renderId])
_RenderClearQueue.Enqueue(renderItem);
matchCommandSender.AddConsoleCommand("FlushPersistentDebugLines");
matchCommandSender.Send();

_clientRenderTracker.Clear();
}
Expand Down
37 changes: 7 additions & 30 deletions RLBotCS/Server/BridgeHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Threading.Channels;
using Bridge.Conversion;
using Bridge.State;
using Bridge.TCP;
using Microsoft.Extensions.Logging;
using RLBotCS.Server.FlatbuffersMessage;
Expand Down Expand Up @@ -52,11 +51,11 @@ private async Task HandleServer()
messenger.ResetByteCount();

float prevTime = _context.GameState.SecondsElapsed;
GameStateType prevGameStateType = _context.GameState.GameStateType;
_context.GameState = MessageHandler.CreateUpdatedState(
messageClump,
_context.GameState
);

float deltaTime = _context.GameState.SecondsElapsed - prevTime;
bool timeAdvanced = deltaTime > 0.001;

Expand All @@ -69,26 +68,18 @@ private async Task HandleServer()
var matchStarted = MessageHandler.ReceivedMatchInfo(messageClump);
if (matchStarted)
{
_context.RenderingMgmt.ClearAllRenders();
// _context.Logger.LogInformation("Map name: " + _context.GameState.MapName);
_context.RenderingMgmt.ClearAllRenders(_context.MatchCommandSender);
_context.MatchHasStarted = true;
_context.Writer.TryWrite(new MapSpawned());
}

bool matchEnded = _context.GameState.GameStateType == GameStateType.Inactive;
if (matchEnded)
if (_context.GameState.MatchEnded)
{
// reset everything
_context.QuickChat.ClearChats();
_context.PerfMonitor.ClearAll();
_context.RenderingMgmt.ClearAllRenders();

// don't close connections unless it was a true "match ended"
if (
prevGameStateType == GameStateType.Ended
&& !_context.MatchHasStarted
&& !matchStarted
)
_context.Writer.TryWrite(new StopMatch(false));
_context.RenderingMgmt.ClearAllRenders(_context.MatchCommandSender);
}
else if (
_context.GameState.GameStateType != GameStateType.Replay
Expand All @@ -100,10 +91,7 @@ private async Task HandleServer()
_context.QuickChat.RenderChats(_context.RenderingMgmt, _context.GameState);

// only render if we're not in a goal scored or ended state
if (
_context.GameState.GameStateType != GameStateType.GoalScored
&& _context.GameState.GameStateType != GameStateType.Ended
)
if (_context.GameState.GameStateType != GameStateType.GoalScored)
_context.PerfMonitor.RenderSummary(
_context.RenderingMgmt,
_context.GameState,
Expand Down Expand Up @@ -147,18 +135,7 @@ public void Cleanup()

try
{
_context.RenderingMgmt.ClearAllRenders();

// we can only clear so many renders each tick
// so we do this until we've cleared them all
// or rocket league has been closed
while (!_context.RenderingMgmt.SendRenderClears())
{
if (!messenger.WaitForAnyMessageAsync().Result)
break;

messenger.ResetByteCount();
}
_context.RenderingMgmt.ClearAllRenders(_context.MatchCommandSender);
}
catch (Exception e)
{
Expand Down

0 comments on commit d960a94

Please sign in to comment.