Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Game/Abilities/Essential/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Move : ActiveAbility

private int RepathRate
{
get { return FixedMath.Create(repathRate).Div(this.Speed).CeilToInt(); }
get { return FixedMath.Create(repathRate).Div(this.Speed > FixedMath.One ? this.Speed : FixedMath.One).CeilToInt(); }
}

private const int straightRepathRate = repathRate * 4;
Expand Down
1 change: 1 addition & 0 deletions Core/Game/Managers/LockstepManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ internal static void Visualize ()
AgentController.Visualize ();
ProjectileManager.Visualize ();
EffectManager.Visualize ();
CommandManager.Visualize();

}

Expand Down
2 changes: 1 addition & 1 deletion Core/Game/Managers/ReplayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static Frame[] Deserialize (Reader reader) {
bufferFrames.Clear();

int length = reader.ReadInt();
int lastSavedFrame = 0;
int lastSavedFrame = -1;
while (reader.Position < reader.Length) {

int frameCount = reader.ReadInt();
Expand Down
198 changes: 100 additions & 98 deletions Core/Game/Player/Commands/CommandManager.cs
Original file line number Diff line number Diff line change
@@ -1,99 +1,101 @@
using System;
using UnityEngine;
using System.Collections.Generic;
namespace Lockstep
{
public static class CommandManager
{

#region Recording


#endregion

static readonly FastList<byte> bufferedBytes = new FastList<byte>(256);

public static void Initialize()
{
}

public static void Simulate()
{
SendOut();
}

public static void ProcessPacket(byte[] packet)
{
processBytes.FastClear();
processBytes.AddRange(packet);
ProcessPacket(processBytes);
}

static FastList<byte> processBytes = new FastList<byte>();

public static void ProcessPacket(FastList<byte> packet)
{

if (packet == null || packet.Count < 4)
{
throw new System.Exception("Packet is null or not valid length");
}
int frameCount = BitConverter.ToInt32(packet.innerArray, 0);
int index = 4;

Frame frame = new Frame();

if (packet.Count > 4)
{
while (index < packet.Count)
{
Command com = new Command();
index += com.Reconstruct(packet.innerArray, index);
frame.AddCommand(com);
}
}
ProcessFrame(frameCount, frame);

}

public static void ProcessFrame(int frameCount, Frame frame)
{
if (FrameManager.HasFrame(frameCount) == false)
{
FrameManager.AddFrame(frameCount, frame);
}

}

/// <summary>
/// Sends out all Commands
/// </summary>
public static void SendOut()
{

if (bufferedBytes.Count > 0)
{
ClientManager.Distribute(bufferedBytes.ToArray());
bufferedBytes.FastClear();
}


}
//static FastList<Command> asdf = new FastList<Command>();
public static void SendCommand(Command com, bool immediate = false)
{
if (com == null)
{
return;
}

bufferedBytes.AddRange(com.Serialized);
if (immediate)
{

SendOut();
}
}
}

using System;
using UnityEngine;
using System.Collections.Generic;
namespace Lockstep
{
public static class CommandManager
{

#region Recording


#endregion

static readonly FastList<byte> bufferedBytes = new FastList<byte>(256);

public static void Initialize()
{
}

public static void Simulate()
{
SendOut();
}
public static void Visualize()
{
SendOut();
}

public static void ProcessPacket(byte[] packet)
{
processBytes.FastClear();
processBytes.AddRange(packet);
ProcessPacket(processBytes);
}

static FastList<byte> processBytes = new FastList<byte>();

public static void ProcessPacket(FastList<byte> packet)
{
if (ReplayManager.IsPlayingBack) return;
if (packet == null || packet.Count < 4)
{
throw new System.Exception("Packet is null or not valid length");
}
int frameCount = BitConverter.ToInt32(packet.innerArray, 0);

int index = 4;

Frame frame = new Frame();

if (packet.Count > 4)
{

while (index < packet.Count)
{
Command com = new Command();
index += com.Reconstruct(packet.innerArray, index);
frame.AddCommand(com);
}

}
ProcessFrame(frameCount, frame);
}

public static void ProcessFrame(int frameCount, Frame frame)
{
if (FrameManager.HasFrame(frameCount) == false)
{
FrameManager.AddFrame(frameCount, frame);
}

}

/// <summary>
/// Sends out all Commands
/// </summary>
public static void SendOut()
{

if (bufferedBytes.Count > 0)
{
ClientManager.Distribute(bufferedBytes.ToArray());
bufferedBytes.FastClear();
}


}
//static FastList<Command> asdf = new FastList<Command>();
public static void SendCommand(Command com)
{
if (com == null)
{
return;
}

bufferedBytes.AddRange(com.Serialized);

}
}

}
27 changes: 15 additions & 12 deletions Example/ExampleGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ void OnGUI ()
{
GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (2.5f, 2.5f, 1));

if (ReplayManager.CurrentReplay != null)
{
if (GUILayout.Button ("Stop")) {
ReplayManager.CurrentReplay = null;
ReplayManager.Stop ();
LSUtility.LoadLevel (SceneManager.GetActiveScene().name);
}

if (GUILayout.Button ("Rewind")) {
ReplayManager.Play (LastSave);
LSUtility.LoadLevel (SceneManager.GetActiveScene().name);
if (ReplayManager.IsPlayingBack) {
if (ReplayManager.CurrentReplay != null)
{
if (GUILayout.Button("Stop"))
{
ReplayManager.CurrentReplay = null;
ReplayManager.Stop();
LSUtility.LoadLevel(SceneManager.GetActiveScene().name);
}

if (GUILayout.Button("Rewind"))
{
ReplayManager.Play(LastSave);
LSUtility.LoadLevel(SceneManager.GetActiveScene().name);
}
}
}

if (ReplayManager.IsPlayingBack) {
} else {
if (GUILayout.Button ("Restart")) {
LSUtility.LoadLevel (SceneManager.GetActiveScene().name);
Expand Down
Loading