Skip to content

Commit ad20cba

Browse files
committed
Network optimizations
1 parent 0f72998 commit ad20cba

File tree

9 files changed

+88
-23
lines changed

9 files changed

+88
-23
lines changed

BeatSaberOnline/Controllers/AvatarController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ void Update()
132132
{
133133
if (avatar != null && !forcePlayerInfo)
134134
{
135-
if (GameController.Tickrate < (1f / Time.smoothDeltaTime))
135+
if (GameController.TPS < (1f / Time.smoothDeltaTime))
136136
{
137-
interpolationProgress += Time.deltaTime * GameController.Tickrate;
137+
interpolationProgress += Time.deltaTime * GameController.TPS;
138138
}
139139
else
140140
{

BeatSaberOnline/Controllers/GameController.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
using BeatSaberOnline.Data;
2-
using BeatSaberOnline.Data.Steam;
32
using BeatSaberOnline.Utils;
43
using BeatSaberOnline.Views.Menus;
5-
using CustomAvatar;
6-
using CustomUI.Utilities;
7-
using Steamworks;
84
using System;
95
using System.Collections;
106
using System.Collections.Generic;
117
using System.Linq;
12-
using System.Text;
13-
using System.Threading.Tasks;
148
using UnityEngine;
159
using UnityEngine.SceneManagement;
16-
using UnityEngine.XR;
1710
using VRUI;
1811
using Logger = BeatSaberOnline.Data.Logger;
1912
using SteamAPI = BeatSaberOnline.Data.Steam.SteamAPI;
@@ -23,11 +16,38 @@ namespace BeatSaberOnline.Controllers
2316
class GameController : MonoBehaviour
2417
{
2518
public static GameController Instance;
26-
public static float TPS { get; } = 25f / 1000f;
27-
public static float Tickrate { get; } = 1000f / TPS;
19+
public static float TPS
20+
{
21+
get
22+
{
23+
float tps = 0;
24+
switch (Config.Instance.NetworkQuality)
25+
{
26+
case 0:
27+
tps = 5;
28+
break;
29+
case 1:
30+
tps = 10;
31+
break;
32+
case 2:
33+
tps = 15;
34+
break;
35+
case 3:
36+
tps = 20;
37+
break;
38+
case 4:
39+
tps = 25;
40+
break;
41+
case 5:
42+
tps = 30;
43+
break;
44+
}
45+
return 1f / tps;
46+
}
47+
}
2848
private ResultsViewController _resultsViewController;
2949
private string _currentScene;
30-
50+
3151
public static void Init(Scene to)
3252
{
3353
if (Instance != null)

BeatSaberOnline/Controllers/PlayerController.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void Awake()
5050

5151
}
5252
}
53-
private bool isBroadcasting = false;
53+
public bool isBroadcasting = false;
5454
public void StartBroadcasting()
5555
{
5656
if (isBroadcasting) { return; }
@@ -136,7 +136,7 @@ public void UpsertPlayer(PlayerInfo info)
136136
if (!_connectedPlayers.Keys.Contains(info.playerId))
137137
{
138138
_connectedPlayers.Add(info.playerId, info);
139-
if (Config.Instance.AvatarsInLobby)
139+
if ((Config.Instance.AvatarsInLobby && Plugin.instance.CurrentScene == "Menu") || (Config.Instance.AvatarsInGame && Plugin.instance.CurrentScene == "GameCore"))
140140
{
141141
AvatarController avatar = new GameObject("AvatarController").AddComponent<AvatarController>();
142142
avatar.SetPlayerInfo(info, new Vector3(0, 0, 0), info.playerId == _playerInfo.playerId);
@@ -154,7 +154,7 @@ public void UpsertPlayer(PlayerInfo info)
154154
Scoreboard.Instance.UpsertScoreboardEntry(info.playerId, info.playerName, (int)info.playerScore, (int)info.playerComboBlocks);
155155
MultiplayerLobby.RefreshScores();
156156
}
157-
if (Config.Instance.AvatarsInLobby)
157+
if (_connectedPlayerAvatars.ContainsKey(info.playerId) && (Config.Instance.AvatarsInLobby && Plugin.instance.CurrentScene == "Menu") || (Config.Instance.AvatarsInGame && Plugin.instance.CurrentScene == "GameCore"))
158158
{
159159
Vector3 offset = new Vector3(0, 0, 0);
160160
if (Plugin.instance.CurrentScene == "GameCore")
@@ -163,7 +163,7 @@ public void UpsertPlayer(PlayerInfo info)
163163
playerInfosByID[0] = _playerInfo.playerId;
164164
_connectedPlayers.Keys.ToList().CopyTo(playerInfosByID, 1);
165165
Array.Sort(playerInfosByID);
166-
offset = new Vector3((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 3f, 0, Math.Abs((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 3f));
166+
offset = new Vector3((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2.5f, 0, Math.Abs((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2f));
167167
}
168168

169169
_connectedPlayerAvatars[info.playerId].SetPlayerInfo(info, offset, info.playerId == _playerInfo.playerId);
@@ -212,6 +212,7 @@ void BroadcastPlayerInfo()
212212
{
213213
try
214214
{
215+
Data.Logger.Info("Broadcasting");
215216
UpdatePlayerInfo();
216217
SteamAPI.SendPlayerInfo(_playerInfo);
217218
if (_playerInfo.voip != null && _playerInfo.voip.Length > 0)

BeatSaberOnline/Data/Steam/SteamAPI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,13 @@ public static void Disconnect()
564564
Controllers.PlayerController.Instance.StopBroadcasting();
565565
_lobbyInfo.HostName = "";
566566
SendLobbyInfo(true);
567-
567+
568568
Connection = ConnectionState.DISCONNECTED;
569569
SteamMatchmaking.LeaveLobby(_lobbyInfo.LobbyID);
570570
Controllers.PlayerController.Instance.DestroyAvatars();
571+
WaitingMenu.firstInit = true;
571572
WaitingMenu.queuedSong = null;
572573
_lobbyInfo = new LobbyInfo();
573-
userID = 0;
574574
UpdateUserInfo();
575575
Scoreboard.Instance.RemoveAll();
576576
SongListUtils.InSong = false;

BeatSaberOnline/Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Plugin : IPlugin
1313
{
1414
public static Plugin instance;
1515
public string Name => "BeatSaberOnline";
16-
public string Version => "1.0.2";
16+
public string Version => "1.0.3";
1717
public string UpdatedVersion { get; set; }
1818
public string CurrentScene { get; set; }
1919

BeatSaberOnline/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.2")]
36-
[assembly: AssemblyFileVersion("1.0.2")]
35+
[assembly: AssemblyVersion("1.0.3")]
36+
[assembly: AssemblyFileVersion("1.0.3")]

BeatSaberOnline/Utils/Config.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class Config
1212
private bool _noFailMode;
1313
private bool _debugMode;
1414
private bool _avatarsInLobby;
15+
private bool _avatarsInGame;
16+
private int _networkQuality;
17+
1518
private static Config _instance;
1619

1720
private static FileInfo FileLocation { get; } = new FileInfo($"./UserData/{Plugin.instance.Name}.json");
@@ -135,6 +138,28 @@ public bool AvatarsInLobby
135138
}
136139

137140

141+
public bool AvatarsInGame
142+
{
143+
get { return _avatarsInGame; }
144+
set
145+
{
146+
_avatarsInGame = value;
147+
MarkDirty();
148+
}
149+
}
150+
151+
152+
public int NetworkQuality
153+
{
154+
get { return _networkQuality; }
155+
set
156+
{
157+
if (value > 5) { value = 5; }
158+
_networkQuality = value;
159+
MarkDirty();
160+
}
161+
}
162+
138163
Config()
139164
{
140165
_autoStartLobby = false;
@@ -143,6 +168,8 @@ public bool AvatarsInLobby
143168
_noFailMode = true;
144169
_debugMode = false;
145170
_avatarsInLobby = true;
171+
_avatarsInGame = true;
172+
_networkQuality = 3;
146173
IsDirty = true;
147174
}
148175

BeatSaberOnline/Views/Menus/MultiplayerLobby.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static void Init()
9191
Logger.Error(e);
9292
}
9393
});
94-
var t = middleViewController.CreateText("You can use Party in the Main Menu to choose songs for your lobby. \n\nYou can also control all the default Game Modifiers for the lobby through the Party Menu as well.", new Vector2(0, BASE.y - 10f));
94+
var t = middleViewController.CreateText("You can use Online Lobby in the Main Menu to choose songs for your lobby. \n\nYou can also control all the default Game Modifiers for the lobby through the Online Lobby Menu as well.", new Vector2(0, BASE.y - 10f));
9595
var tt = middleViewController.CreateText("If something goes wrong, click the disconnect button above and just reconnect to the lobby.", new Vector2(0, 0 - BASE.y));
9696
t.alignment = TMPro.TextAlignmentOptions.Center;
9797
tt.alignment = TMPro.TextAlignmentOptions.Center;

BeatSaberOnline/Views/PluginUI.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,27 @@ private void CreateSettingsMenu()
104104
Config.Instance.MaxLobbySize = value;
105105
};
106106

107-
var AvatarsInLobby = settingsMenu.AddBool("Enable Avatars");
107+
var AvatarsInLobby = settingsMenu.AddBool("Enable Avatars In Lobby");
108108
AvatarsInLobby.GetValue += delegate { return Config.Instance.AvatarsInLobby; };
109109
AvatarsInLobby.SetValue += delegate (bool value) { Config.Instance.AvatarsInLobby = value; };
110110

111+
var AvatarsInGame = settingsMenu.AddBool("Enable Avatars In Game");
112+
AvatarsInGame.GetValue += delegate { return Config.Instance.AvatarsInGame; };
113+
AvatarsInGame.SetValue += delegate (bool value) { Config.Instance.AvatarsInGame = value; };
114+
115+
116+
var NetworkQuality = settingsMenu.AddInt("Network Quality", 0, 5, 1);
117+
NetworkQuality.GetValue += delegate { return Config.Instance.NetworkQuality; };
118+
NetworkQuality.SetValue += delegate (int value) {
119+
Config.Instance.NetworkQuality = value;
120+
if (Controllers.PlayerController.Instance.isBroadcasting)
121+
{
122+
Controllers.PlayerController.Instance.StopBroadcasting();
123+
Controllers.PlayerController.Instance.StartBroadcasting();
124+
}
125+
};
126+
127+
111128
var DebugMode = settingsMenu.AddBool("Debug Mode");
112129
DebugMode.GetValue += delegate { return Config.Instance.DebugMode; };
113130
DebugMode.SetValue += delegate (bool value) { Config.Instance.DebugMode = value; };

0 commit comments

Comments
 (0)