tidy ReplayConnection
This commit is contained in:
@@ -10,35 +10,26 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace OpenRA.Network
|
namespace OpenRA.Network
|
||||||
{
|
{
|
||||||
public class ReplayConnection : IConnection
|
public class ReplayConnection : IConnection
|
||||||
{
|
{
|
||||||
//uint nextFrame = 1;
|
|
||||||
FileStream replayStream;
|
FileStream replayStream;
|
||||||
|
List<byte[]> sync = new List<byte[]>();
|
||||||
|
|
||||||
public ReplayConnection( string replayFilename )
|
public ReplayConnection( string replayFilename ) { replayStream = File.OpenRead( replayFilename ); }
|
||||||
{
|
|
||||||
replayStream = File.OpenRead( replayFilename );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int LocalClientId
|
public int LocalClientId { get { return 0; } }
|
||||||
{
|
public ConnectionState ConnectionState { get { return ConnectionState.Connected; } }
|
||||||
get { return 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConnectionState ConnectionState
|
|
||||||
{
|
|
||||||
get { return ConnectionState.Connected; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// do nothing; ignore locally generated orders
|
// do nothing; ignore locally generated orders
|
||||||
public void Send( int frame, List<byte[]> orders ) { }
|
public void Send( int frame, List<byte[]> orders ) { }
|
||||||
public void SendImmediate( List<byte[]> orders ) { }
|
public void SendImmediate( List<byte[]> orders ) { }
|
||||||
|
|
||||||
public void SendSync( int frame, byte[] syncData )
|
public void SendSync( int frame, byte[] syncData )
|
||||||
{
|
{
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
@@ -47,8 +38,6 @@ namespace OpenRA.Network
|
|||||||
sync.Add( ms.ToArray() );
|
sync.Add( ms.ToArray() );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<byte[]> sync = new List<byte[]>();
|
|
||||||
|
|
||||||
public void Receive( Action<int, byte[]> packetFn )
|
public void Receive( Action<int, byte[]> packetFn )
|
||||||
{
|
{
|
||||||
while( sync.Count != 0 )
|
while( sync.Count != 0 )
|
||||||
@@ -56,9 +45,11 @@ namespace OpenRA.Network
|
|||||||
packetFn( LocalClientId, sync[ 0 ] );
|
packetFn( LocalClientId, sync[ 0 ] );
|
||||||
sync.RemoveAt( 0 );
|
sync.RemoveAt( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( replayStream == null ) return;
|
if( replayStream == null ) return;
|
||||||
|
|
||||||
var reader = new BinaryReader( replayStream );
|
var reader = new BinaryReader( replayStream );
|
||||||
|
|
||||||
while( replayStream.Position < replayStream.Length )
|
while( replayStream.Position < replayStream.Length )
|
||||||
{
|
{
|
||||||
var client = reader.ReadInt32();
|
var client = reader.ReadInt32();
|
||||||
@@ -66,6 +57,7 @@ namespace OpenRA.Network
|
|||||||
var packet = reader.ReadBytes( packetLen );
|
var packet = reader.ReadBytes( packetLen );
|
||||||
packetFn( client, packet );
|
packetFn( client, packet );
|
||||||
}
|
}
|
||||||
|
|
||||||
replayStream = null;
|
replayStream = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace OpenRA.Network
|
namespace OpenRA.Network
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user