Skip to content

Commit

Permalink
fix: Misc code smells (#269)
Browse files Browse the repository at this point in the history
* fix: code smell - casing

* fix: code smells - condensed if
  • Loading branch information
uweeby committed Jul 13, 2020
1 parent ce79591 commit 23dcca6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 36 deletions.
10 changes: 5 additions & 5 deletions Assets/Mirror/Cloud/ListServer/ListServerServerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ IEnumerator InternalAddServer(ServerJson server)
currentServer = server;

UnityWebRequest request = requestCreator.Post("servers", currentServer);
yield return requestCreator.SendRequestEnumerator(request, onSuccess, onFail);
yield return requestCreator.SendRequestEnumerator(request, OnSuccess, OnFail);
sending = false;

void onSuccess(string responseBody)
void OnSuccess(string responseBody)
{
CreatedIdJson created = JsonUtility.FromJson<CreatedIdJson>(responseBody);
serverId = created.id;

// Start ping to keep server alive
_pingCoroutine = runner.StartCoroutine(InternalPing());
}
void onFail(string responseBody)
void OnFail(string responseBody)
{
added = false;
}
Expand All @@ -158,10 +158,10 @@ IEnumerator InternalUpdateServer(PartialServerJson server)

sending = true;
UnityWebRequest request = requestCreator.Patch("servers/" + serverId, server);
yield return requestCreator.SendRequestEnumerator(request, onSuccess);
yield return requestCreator.SendRequestEnumerator(request, OnSuccess);
sending = false;

void onSuccess(string responseBody)
void OnSuccess(string responseBody)
{
skipNextPing = true;

Expand Down
23 changes: 8 additions & 15 deletions Assets/Mirror/Components/Experimental/NetworkTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,10 @@ public struct DataPoint
void FixedUpdate()
{
// if server then always sync to others.
if (IsServer)
// let the clients know that this has moved
if (IsServer && HasEitherMovedRotatedScaled())
{
// let the clients know that this has moved
if (HasEitherMovedRotatedScaled())
{
RpcMove(TargetTransform.localPosition, TargetTransform.localRotation, TargetTransform.localScale);
}
RpcMove(TargetTransform.localPosition, TargetTransform.localRotation, TargetTransform.localScale);
}

if (IsClient)
Expand All @@ -127,15 +124,12 @@ void FixedUpdate()
// -> only if connectionToServer has been initialized yet too
if (IsOwnerWithClientAuthority)
{
if (!IsServer)
if (!IsServer && HasEitherMovedRotatedScaled())
{
if (HasEitherMovedRotatedScaled())
{
// serialize
// local position/rotation for VR support
// send to server
CmdClientToServerSync(TargetTransform.localPosition, TargetTransform.localRotation, TargetTransform.localScale);
}
// serialize
// local position/rotation for VR support
// send to server
CmdClientToServerSync(TargetTransform.localPosition, TargetTransform.localRotation, TargetTransform.localScale);
}
}
else if (goal.IsValid)
Expand All @@ -157,7 +151,6 @@ void FixedUpdate()
InterpolateRotation(start, goal, TargetTransform.localRotation),
InterpolateScale(start, goal, TargetTransform.localScale));
}

}
}
}
Expand Down
5 changes: 2 additions & 3 deletions Assets/Mirror/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ void HandleAnimMsg(int stateHash, float normalizedTime, int layerId, NetworkRead
// usually transitions will be triggered by parameters, if not, play anims directly.
// NOTE: this plays "animations", not transitions, so any transitions will be skipped.
// NOTE: there is no API to play a transition(?)
if (stateHash != 0)
if (stateHash != 0 && Animator.enabled)
{
if (Animator.enabled)
Animator.Play(stateHash, layerId, normalizedTime);
}

Expand Down Expand Up @@ -554,4 +553,4 @@ void RpcOnAnimationResetTriggerClientMessage(int hash)

#endregion
}
}
}
9 changes: 3 additions & 6 deletions Assets/Mirror/Components/NetworkProximityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,10 @@ public override void OnRebuildObservers(HashSet<INetworkConnection> observers, b
// layers. but checking to every connection is fast.
foreach (INetworkConnection conn in Server.connections)
{
if (conn != null && conn.Identity != null)
// check distance
if (conn != null && conn.Identity != null && Vector3.Distance(conn.Identity.transform.position, position) < VisibilityRange)
{
// check distance
if (Vector3.Distance(conn.Identity.transform.position, position) < VisibilityRange)
{
observers.Add(conn);
}
observers.Add(conn);
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,17 +1015,14 @@ public void RebuildObservers(bool initialize)
{
// only add ready connections.
// otherwise the player might not be in the world yet or anymore
if (conn != null && conn.IsReady)
if (conn != null && conn.IsReady && initialize || !observers.Contains(conn))
{
if (initialize || !observers.Contains(conn))
{
// new observer
conn.AddToVisList(this);
// spawn identity for this conn
Server.ShowForConnection(this, conn);
if (logger.LogEnabled()) logger.Log("New Observer for " + gameObject + " " + conn);
changed = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void EnableHealth(bool value)

[UnityTest]
[Performance]
public IEnumerator Benchmark10k()
public IEnumerator Benchmark10K()
{
EnableHealth(true);

Expand All @@ -117,7 +117,7 @@ public IEnumerator Benchmark10k()

[UnityTest]
[Performance]
public IEnumerator Benchmark10kIdle()
public IEnumerator Benchmark10KIdle()
{
EnableHealth(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IEnumerator TearDown()

[UnityTest]
[Performance]
public IEnumerator Benchmark10kLight()
public IEnumerator Benchmark10KLight()
{
yield return Measure.Frames().MeasurementCount(120).WarmupCount(10).Run();
}
Expand Down

0 comments on commit 23dcca6

Please sign in to comment.