Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental branch merge #79

Merged
merged 2 commits into from Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion BeatSaberMultiplayer/BeatSaberMultiplayer.csproj
Expand Up @@ -157,7 +157,10 @@
<Compile Include="Misc\SongDownloader.cs" />
<Compile Include="Misc\SongSeekBeatmapHandler.cs" />
<Compile Include="Misc\TableViewHelper.cs" />
<Compile Include="OnlineVRController.cs" />
<Compile Include="OverriddenClasses\OnlineAudioTimeController.cs" />
<Compile Include="OverriddenClasses\OnlineBeatmapCallbackController.cs" />
<Compile Include="OverriddenClasses\OnlineBeatmapSpawnController.cs" />
<Compile Include="OverriddenClasses\OnlineVRController.cs" />
<Compile Include="OnlinePlayerController.cs" />
<Compile Include="PlayerInfoDisplay.cs" />
<Compile Include="Plugin.cs" />
Expand Down
12 changes: 6 additions & 6 deletions BeatSaberMultiplayer/InGameOnlineController.cs
Expand Up @@ -175,14 +175,14 @@ private void PacketReceived(NetIncomingMessage msg)
if (player != null)
{
player.PlayerInfo = info;
player.avatarOffset = (index - localPlayerIndex) * (_currentScene == "GameCore" ? 3f : 0f);
player.avatarOffset = (index - localPlayerIndex) * (_currentScene == "GameCore" ? 5f : 0f);
}
else
{
player = new GameObject("OnlinePlayerController").AddComponent<OnlinePlayerController>();

player.PlayerInfo = info;
player.avatarOffset = (index - localPlayerIndex) * (_currentScene == "GameCore" ? 3f : 0f);
player.avatarOffset = (index - localPlayerIndex) * (_currentScene == "GameCore" ? 5f : 0f);

_players.Add(player);
}
Expand Down Expand Up @@ -430,16 +430,16 @@ public void UpdatePlayerInfo()
if (_vrPlatformHelper.vrPlatformSDK == VRPlatformHelper.VRPlatformSDK.Oculus)
{
Client.Instance.playerInfo.leftHandRot *= oculusTouchRotOffset;
Client.Instance.playerInfo.leftHandPos += oculusTouchPosOffset;
Client.Instance.playerInfo.leftHandPos += Client.Instance.playerInfo.leftHandRot * oculusTouchPosOffset;
Client.Instance.playerInfo.rightHandRot *= oculusTouchRotOffset;
Client.Instance.playerInfo.rightHandPos += oculusTouchPosOffset;
Client.Instance.playerInfo.rightHandPos += Client.Instance.playerInfo.rightHandRot * oculusTouchPosOffset;
}
else if (_vrPlatformHelper.vrPlatformSDK == VRPlatformHelper.VRPlatformSDK.OpenVR)
{
Client.Instance.playerInfo.leftHandRot *= openVrRotOffset;
Client.Instance.playerInfo.leftHandPos += openVrPosOffset;
Client.Instance.playerInfo.leftHandPos += Client.Instance.playerInfo.leftHandRot * openVrPosOffset;
Client.Instance.playerInfo.rightHandRot *= openVrRotOffset;
Client.Instance.playerInfo.rightHandPos += openVrPosOffset;
Client.Instance.playerInfo.rightHandPos += Client.Instance.playerInfo.rightHandRot * openVrPosOffset;
}

if (_currentScene == "GameCore" && loaded)
Expand Down
78 changes: 73 additions & 5 deletions BeatSaberMultiplayer/OnlinePlayerController.cs
@@ -1,15 +1,18 @@
using BeatSaberMultiplayer.Data;
using BeatSaberMultiplayer.Data;
using BeatSaberMultiplayer.OverriddenClasses;
using BS_Utils.Gameplay;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace BeatSaberMultiplayer
{
class OnlinePlayerController : MonoBehaviour
public class OnlinePlayerController : PlayerController
{
public PlayerInfo PlayerInfo {

Expand Down Expand Up @@ -42,6 +45,10 @@ class OnlinePlayerController : MonoBehaviour

public AvatarController avatar;

public OnlineBeatmapCallbackController beatmapCallbackController;
public OnlineBeatmapSpawnController beatmapSpawnController;
public OnlineAudioTimeController audioTimeController;

public float avatarOffset;
public bool noInterpolation = false;
public bool destroyed = false;
Expand All @@ -63,15 +70,60 @@ public void Start()
avatar = new GameObject("AvatarController").AddComponent<AvatarController>();
syncStartInfo = _info;
syncEndInfo = _info;

Misc.Logger.Info("Scene name: " + SceneManager.GetActiveScene().name);
if (SceneManager.GetActiveScene().name != "Menu" && !Client.Instance.playerInfo.Equals(PlayerInfo))
{
SpawnBeatmapControllers();
SpawnSabers();
}
}
}

public void Update()
void SpawnBeatmapControllers()
{
Misc.Logger.Info("Creating beatmap controllers...");

beatmapCallbackController = new GameObject("OnlineBeatmapCallbackController").AddComponent<OnlineBeatmapCallbackController>();
Misc.Logger.Info("Created beatmap callback controller!");
beatmapCallbackController.Init(this);
Misc.Logger.Info("Initialized beatmap callback controller!");

audioTimeController = new GameObject("OnlineAudioTimeController").AddComponent<OnlineAudioTimeController>();
Misc.Logger.Info("Created audio time controller!");
audioTimeController.Init(this);
Misc.Logger.Info("Initialized audio time controller!");

beatmapSpawnController = new GameObject("OnlineBeatmapSpawnController").AddComponent<OnlineBeatmapSpawnController>();
Misc.Logger.Info("Created beatmap spawn controller!");
beatmapSpawnController.Init(this, beatmapCallbackController, audioTimeController);
Misc.Logger.Info("Initialized beatmap spawn controller!");
}

void SpawnSabers()
{
Misc.Logger.Info("Spawning left saber...");
_leftSaber = Instantiate(Resources.FindObjectsOfTypeAll<Saber>().First(x => x.name == "LeftSaber"), transform, false);
var leftController = _leftSaber.gameObject.AddComponent<OnlineVRController>();
leftController.owner = this;

Misc.Logger.Info("Spawning right saber...");
_rightSaber = Instantiate(Resources.FindObjectsOfTypeAll<Saber>().First(x => x.name == "RightSaber"), transform, false);
var rightController = _rightSaber.gameObject.AddComponent<OnlineVRController>();
rightController.owner = this;

Misc.Logger.Info("Sabers spawned!");
}

public override void Update()
{
if (avatar != null)
{
avatar.SetPlayerInfo(_info, avatarOffset, Client.Instance.playerInfo.Equals(_info));
}
if(_info != null)
_info.playerProgress += Time.deltaTime;

}

public void FixedUpdate()
Expand All @@ -86,11 +138,15 @@ public void FixedUpdate()
_info.leftHandPos = Vector3.Lerp(syncStartInfo.leftHandPos, syncEndInfo.leftHandPos, lerpProgress);
_info.rightHandPos = Vector3.Lerp(syncStartInfo.rightHandPos, syncEndInfo.rightHandPos, lerpProgress);

_overrideHeadPos = true;
_overriddenHeadPos = _info.headPos;
_headPos = _info.headPos + Vector3.right * avatarOffset;
transform.position = _headPos;

_info.headRot = Quaternion.Lerp(syncStartInfo.headRot, syncEndInfo.headRot, lerpProgress);
_info.leftHandRot = Quaternion.Lerp(syncStartInfo.leftHandRot, syncEndInfo.leftHandRot, lerpProgress);
_info.rightHandRot = Quaternion.Lerp(syncStartInfo.rightHandRot, syncEndInfo.rightHandRot, lerpProgress);

_info.playerProgress = Mathf.Lerp(syncStartInfo.playerProgress, syncEndInfo.playerProgress, lerpProgress);
}
}

Expand All @@ -100,7 +156,17 @@ public void OnDestroy()
Misc.Logger.Info("Destroying player controller");
#endif
destroyed = true;
Destroy(avatar.gameObject);

if (avatar != null)
{
Destroy(avatar.gameObject);
}

if (beatmapCallbackController != null && beatmapSpawnController != null)
{
Destroy(beatmapCallbackController.gameObject);
Destroy(beatmapSpawnController.gameObject);
}
}

public void UpdatePrevPosRot(PlayerInfo newPlayerInfo)
Expand All @@ -114,6 +180,8 @@ public void UpdatePrevPosRot(PlayerInfo newPlayerInfo)

syncStartInfo = _info;
syncEndInfo = newPlayerInfo;

_info.playerProgress = syncEndInfo.playerProgress;
}
}
}
104 changes: 0 additions & 104 deletions BeatSaberMultiplayer/OnlineVRController.cs

This file was deleted.

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace BeatSaberMultiplayer.OverriddenClasses
{
public class OnlineAudioTimeController : AudioTimeSyncController
{
public OnlinePlayerController owner;

public void Init(OnlinePlayerController newOwner)
{
owner = newOwner;

_songTime = owner.PlayerInfo.playerProgress;
}

public override void Update()
{
if(owner != null)
_songTime = owner.PlayerInfo.playerProgress;
}

public override void Awake()
{
}

}
}