Skip to content

Avoid allocations in NetworkedAnimator #12

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

Merged
merged 4 commits into from
Mar 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions MLAPI/MonoBehaviours/Prototyping/NetworkedAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class NetworkedAnimator : NetworkedBehaviour
[SerializeField] uint m_ParameterSendBits;
[SerializeField] float m_SendRate = 0.1f;

AnimatorControllerParameter[] m_AnimatorParameters;

// properties
public Animator animator
{
Expand Down Expand Up @@ -72,6 +74,7 @@ public void ResetParameterOptions()
{
Debug.Log("ResetParameterOptions");
m_ParameterSendBits = 0;
m_AnimatorParameters = null;
}

void FixedUpdate()
Expand Down Expand Up @@ -245,12 +248,13 @@ internal void HandleAnimTriggerMsg(int clientId, byte[] data)

void WriteParameters(BinaryWriter writer, bool autoSend)
{
for (int i = 0; i < m_Animator.parameters.Length; i++)
if (m_AnimatorParameters == null) m_AnimatorParameters = m_Animator.parameters;
for (int i = 0; i < m_AnimatorParameters.Length; i++)
{
if (autoSend && !GetParameterAutoSend(i))
continue;

AnimatorControllerParameter par = m_Animator.parameters[i];
AnimatorControllerParameter par = m_AnimatorParameters[i];
if (par.type == AnimatorControllerParameterType.Int)
{
writer.Write((uint)m_Animator.GetInteger(par.nameHash));
Expand All @@ -276,12 +280,13 @@ void WriteParameters(BinaryWriter writer, bool autoSend)

void ReadParameters(BinaryReader reader, bool autoSend)
{
for (int i = 0; i < m_Animator.parameters.Length; i++)
if (m_AnimatorParameters == null) m_AnimatorParameters = m_Animator.parameters;
for (int i = 0; i < m_AnimatorParameters.Length; i++)
{
if (autoSend && !GetParameterAutoSend(i))
continue;

AnimatorControllerParameter par = m_Animator.parameters[i];
AnimatorControllerParameter par = m_AnimatorParameters[i];
if (par.type == AnimatorControllerParameterType.Int)
{
int newValue = (int)reader.ReadUInt32();
Expand Down