提交 6d169497 编写于 作者: T tanghai

1.增加一个nuget命令行解析库

2.World componet增加一个IStart接口,在World Start时调用
3.Runner改成Update
上级 885936f7
<Properties StartupItem="Exe\Profile\Profile.csproj"> <Properties StartupItem="Exe\Profile\Profile.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.Workbench ActiveDocument="Exe\Profile\Program.cs"> <MonoDevelop.Ide.Workbench />
<Files>
<File FileName="Exe\Profile\App.config" Line="1" Column="1" />
<File FileName="Exe\Profile\Program.cs" Line="3" Column="3" />
</Files>
<Pads>
<Pad Id="MonoDevelop.NUnit.TestPad">
<State expanded="True" selected="True" />
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore /> <BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints> </MonoDevelop.Ide.DebuggingService.Breakpoints>
......
...@@ -7,11 +7,11 @@ using UNet; ...@@ -7,11 +7,11 @@ using UNet;
namespace Model namespace Model
{ {
public class NetworkComponent: Component<World>, IRunner public class NetworkComponent: Component<World>, IUpdate, IStart
{ {
private IService service; private IService service;
public void Run(string host, int port, NetworkProtocol protocol = NetworkProtocol.TCP) private void Accept(string host, int port, NetworkProtocol protocol = NetworkProtocol.TCP)
{ {
switch (protocol) switch (protocol)
{ {
...@@ -25,12 +25,17 @@ namespace Model ...@@ -25,12 +25,17 @@ namespace Model
throw new ArgumentOutOfRangeException("protocol"); throw new ArgumentOutOfRangeException("protocol");
} }
this.service.Add(this.AcceptChannel); this.AcceptChannel();
} }
public void Run() public void Start()
{ {
this.service.Run(); this.Accept(World.Instance.Options.Host, World.Instance.Options.Port, World.Instance.Options.Protocol);
}
public void Update()
{
this.service.Update();
} }
/// <summary> /// <summary>
......
...@@ -6,7 +6,7 @@ using MongoDB.Bson; ...@@ -6,7 +6,7 @@ using MongoDB.Bson;
namespace Model namespace Model
{ {
public class TimerComponent : Component<World>, IRunner public class TimerComponent : Component<World>, IUpdate
{ {
private class Timer private class Timer
{ {
...@@ -49,7 +49,7 @@ namespace Model ...@@ -49,7 +49,7 @@ namespace Model
this.timeId.Remove(timer.Time, timer.Id); this.timeId.Remove(timer.Time, timer.Id);
} }
public void Run() public void Update()
{ {
long timeNow = TimeHelper.Now(); long timeNow = TimeHelper.Now();
foreach (long time in this.timeId.Keys) foreach (long time in this.timeId.Keys)
......
namespace Model
{
/// <summary>
/// World的Componet实现该接口后,会在World.Start时调用该Start方法
/// </summary>
interface IStart
{
void Start();
}
}
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
/// <summary> /// <summary>
/// 实现了该接口的World Componet会每帧刷新 /// 实现了该接口的World Componet会每帧刷新
/// </summary> /// </summary>
public interface IRunner public interface IUpdate
{ {
void Run(); void Update();
} }
} }
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="CommandLine">
<HintPath>..\..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson"> <Reference Include="MongoDB.Bson">
<HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc1\lib\net35\MongoDB.Bson.dll</HintPath> <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc1\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference> </Reference>
...@@ -67,8 +70,10 @@ ...@@ -67,8 +70,10 @@
<Compile Include="FactoryAttribute.cs" /> <Compile Include="FactoryAttribute.cs" />
<Compile Include="IAssemblyLoader.cs" /> <Compile Include="IAssemblyLoader.cs" />
<Compile Include="IFactory.cs" /> <Compile Include="IFactory.cs" />
<Compile Include="IRunner.cs" /> <Compile Include="IStart.cs" />
<Compile Include="IUpdate.cs" />
<Compile Include="MessageAttribute.cs" /> <Compile Include="MessageAttribute.cs" />
<Compile Include="Options.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Unit.cs" /> <Compile Include="Unit.cs" />
<Compile Include="UnitType.cs" /> <Compile Include="UnitType.cs" />
......
using System.Text;
using CommandLine;
using Common.Network;
namespace Common.Base
{
public class Options
{
[Option('h', "host", Required = true, HelpText = "Host.")]
public string Host { get; set; }
[Option('p', "port", Required = true, HelpText = "Port.")]
public int Port { get; set; }
[Option("protocol", Required = true, HelpText = "Protocol, tcp or udp.")]
public NetworkProtocol Protocol { get; set; }
[Option('v', null, HelpText = "Print details during execution.")]
public bool Verbose { get; set; }
[HelpOption]
public string GetUsage()
{
// this without using CommandLine.Text
StringBuilder usage = new StringBuilder();
usage.AppendLine("Quickstart Application 1.0");
usage.AppendLine("Read user manual for usage instructions...");
return usage.ToString();
}
}
}
...@@ -20,7 +20,9 @@ namespace Model ...@@ -20,7 +20,9 @@ namespace Model
} }
} }
private List<IRunner> iRunners; public Options Options { get; set; }
private readonly List<IUpdate> iUpdates = new List<IUpdate>();
private bool isStop; private bool isStop;
...@@ -31,7 +33,6 @@ namespace Model ...@@ -31,7 +33,6 @@ namespace Model
public void Load() public void Load()
{ {
this.assembly = Assembly.Load(File.ReadAllBytes(@"./Controller.dll")); this.assembly = Assembly.Load(File.ReadAllBytes(@"./Controller.dll"));
this.iRunners = new List<IRunner>();
foreach (Component<World> component in this.GetComponents()) foreach (Component<World> component in this.GetComponents())
{ {
...@@ -40,23 +41,35 @@ namespace Model ...@@ -40,23 +41,35 @@ namespace Model
{ {
assemblyLoader.Load(this.assembly); assemblyLoader.Load(this.assembly);
} }
IRunner runner = component as IRunner;
if (runner != null)
{
this.iRunners.Add(runner);
}
} }
} }
public void Start() public void Start()
{ {
Load();
foreach (Component<World> component in this.GetComponents())
{
IUpdate update = component as IUpdate;
if (update != null)
{
this.iUpdates.Add(update);
}
IStart start = component as IStart;
if (start != null)
{
start.Start();
}
}
// loop
while (!isStop) while (!isStop)
{ {
Thread.Sleep(1); Thread.Sleep(1);
foreach (IRunner runner in this.iRunners) foreach (IUpdate update in this.iUpdates)
{ {
runner.Run(); update.Update();
} }
} }
} }
......
...@@ -31,19 +31,6 @@ namespace Common.Base ...@@ -31,19 +31,6 @@ namespace Common.Base
return timer.Id; return timer.Id;
} }
public void Update(ObjectId id, long time)
{
Timer timer;
if (!this.timers.TryGetValue(id, out timer))
{
return;
}
this.timeGuid.Remove(timer.Time, timer.Id);
timer.Time = time;
this.timeGuid.Add(timer.Time, timer.Id);
}
public void Remove(ObjectId id) public void Remove(ObjectId id)
{ {
Timer timer; Timer timer;
......
...@@ -26,6 +26,6 @@ namespace Common.Network ...@@ -26,6 +26,6 @@ namespace Common.Network
void Remove(AChannel channel); void Remove(AChannel channel);
void Run(); void Update();
} }
} }
\ No newline at end of file
...@@ -6,6 +6,6 @@ namespace TNet ...@@ -6,6 +6,6 @@ namespace TNet
{ {
void Add(Action action); void Add(Action action);
void Run(); void Update();
} }
} }
\ No newline at end of file
...@@ -32,7 +32,7 @@ namespace TNet ...@@ -32,7 +32,7 @@ namespace TNet
this.StartRecv(); this.StartRecv();
} }
protected virtual void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (this.socket == null) if (this.socket == null)
{ {
......
...@@ -16,7 +16,7 @@ namespace TNet ...@@ -16,7 +16,7 @@ namespace TNet
this.concurrentQueue.Enqueue(action); this.concurrentQueue.Enqueue(action);
} }
public void Run() public void Update()
{ {
while (true) while (true)
{ {
......
...@@ -127,9 +127,9 @@ namespace TNet ...@@ -127,9 +127,9 @@ namespace TNet
return await this.ConnectAsync(host, port); return await this.ConnectAsync(host, port);
} }
public void Run() public void Update()
{ {
this.poller.Run(); this.poller.Update();
this.timerManager.Refresh(); this.timerManager.Refresh();
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{ {
public static void Initialize() public static void Initialize()
{ {
int ret = NativeMethods.EnetInitialize(); int ret = NativeMethods.ENetInitialize();
if (ret < 0) if (ret < 0)
{ {
throw new UException(string.Format("Initialization failed, ret: {0}", ret)); throw new UException(string.Format("Initialization failed, ret: {0}", ret));
...@@ -13,18 +13,18 @@ ...@@ -13,18 +13,18 @@
public static void Deinitialize() public static void Deinitialize()
{ {
NativeMethods.EnetDeinitialize(); NativeMethods.ENetDeinitialize();
} }
public static uint Time public static uint Time
{ {
get get
{ {
return NativeMethods.EnetTimeGet(); return NativeMethods.ENetTimeGet();
} }
set set
{ {
NativeMethods.EnetTimeSet(value); NativeMethods.ENetTimeSet(value);
} }
} }
} }
......
...@@ -20,102 +20,102 @@ namespace UNet ...@@ -20,102 +20,102 @@ namespace UNet
public const uint ENET_HOST_BROADCAST = 0xffffffff; public const uint ENET_HOST_BROADCAST = 0xffffffff;
[DllImport(LIB, EntryPoint = "enet_address_set_host")] [DllImport(LIB, EntryPoint = "enet_address_set_host")]
internal static extern int EnetAddressSetHost(ref ENetAddress address, string hostName); internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);
[DllImport(LIB, EntryPoint = "enet_address_get_host")] [DllImport(LIB, EntryPoint = "enet_address_get_host")]
internal static extern int EnetAddressGetHost( internal static extern int ENetAddressGetHost(
ref ENetAddress address, StringBuilder hostName, uint nameLength); ref ENetAddress address, StringBuilder hostName, uint nameLength);
[DllImport(LIB, EntryPoint = "enet_address_get_host_ip")] [DllImport(LIB, EntryPoint = "enet_address_get_host_ip")]
internal static extern int EnetAddressGetHostIp( internal static extern int ENetAddressGetHostIp(
ref ENetAddress address, StringBuilder hostIp, uint ipLength); ref ENetAddress address, StringBuilder hostIp, uint ipLength);
[DllImport(LIB, EntryPoint = "enet_deinitialize")] [DllImport(LIB, EntryPoint = "enet_deinitialize")]
internal static extern void EnetDeinitialize(); internal static extern void ENetDeinitialize();
[DllImport(LIB, EntryPoint = "enet_initialize")] [DllImport(LIB, EntryPoint = "enet_initialize")]
internal static extern int EnetInitialize(); internal static extern int ENetInitialize();
[DllImport(LIB, EntryPoint = "enet_host_create")] [DllImport(LIB, EntryPoint = "enet_host_create")]
internal static extern IntPtr EnetHostCreate( internal static extern IntPtr ENetHostCreate(
ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
uint outgoingBandwidth); uint outgoingBandwidth);
[DllImport(LIB, EntryPoint = "enet_host_create")] [DllImport(LIB, EntryPoint = "enet_host_create")]
internal static extern IntPtr EnetHostCreate( internal static extern IntPtr ENetHostCreate(
IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
uint outgoingBandwidth); uint outgoingBandwidth);
[DllImport(LIB, EntryPoint = "enet_host_destroy")] [DllImport(LIB, EntryPoint = "enet_host_destroy")]
internal static extern void EnetHostDestroy(IntPtr host); internal static extern void ENetHostDestroy(IntPtr host);
[DllImport(LIB, EntryPoint = "enet_host_connect")] [DllImport(LIB, EntryPoint = "enet_host_connect")]
internal static extern IntPtr EnetHostConnect( internal static extern IntPtr ENetHostConnect(
IntPtr host, ref ENetAddress address, uint channelCount, uint data); IntPtr host, ref ENetAddress address, uint channelCount, uint data);
[DllImport(LIB, EntryPoint = "enet_host_broadcast")] [DllImport(LIB, EntryPoint = "enet_host_broadcast")]
internal static extern void EnetHostBroadcast(IntPtr host, byte channelID, IntPtr packet); internal static extern void ENetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
[DllImport(LIB, EntryPoint = "enet_host_compress")] [DllImport(LIB, EntryPoint = "enet_host_compress")]
internal static extern void EnetHostCompress(IntPtr host, IntPtr compressor); internal static extern void ENetHostCompress(IntPtr host, IntPtr compressor);
[DllImport(LIB, EntryPoint = "enet_host_compress_with_range_coder")] [DllImport(LIB, EntryPoint = "enet_host_compress_with_range_coder")]
internal static extern int EnetHostCompressWithRangeCoder(IntPtr host); internal static extern int ENetHostCompressWithRangeCoder(IntPtr host);
[DllImport(LIB, EntryPoint = "enet_host_channel_limit")] [DllImport(LIB, EntryPoint = "enet_host_channel_limit")]
internal static extern void EnetHostChannelLimit(IntPtr host, uint channelLimit); internal static extern void ENetHostChannelLimit(IntPtr host, uint channelLimit);
[DllImport(LIB, EntryPoint = "enet_host_bandwidth_limit")] [DllImport(LIB, EntryPoint = "enet_host_bandwidth_limit")]
internal static extern void EnetHostBandwidthLimit( internal static extern void ENetHostBandwidthLimit(
IntPtr host, uint incomingBandwidth, uint outgoingBandwidth); IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
[DllImport(LIB, EntryPoint = "enet_host_flush")] [DllImport(LIB, EntryPoint = "enet_host_flush")]
internal static extern void EnetHostFlush(IntPtr host); internal static extern void ENetHostFlush(IntPtr host);
[DllImport(LIB, EntryPoint = "enet_host_check_events")] [DllImport(LIB, EntryPoint = "enet_host_check_events")]
internal static extern int EnetHostCheckEvents(IntPtr host, ENetEvent ev); internal static extern int ENetHostCheckEvents(IntPtr host, ENetEvent ev);
[DllImport(LIB, EntryPoint = "enet_host_service")] [DllImport(LIB, EntryPoint = "enet_host_service")]
internal static extern int EnetHostService(IntPtr host, ENetEvent ev, uint timeout); internal static extern int ENetHostService(IntPtr host, ENetEvent ev, uint timeout);
[DllImport(LIB, EntryPoint = "enet_time_get")] [DllImport(LIB, EntryPoint = "enet_time_get")]
internal static extern uint EnetTimeGet(); internal static extern uint ENetTimeGet();
[DllImport(LIB, EntryPoint = "enet_time_set")] [DllImport(LIB, EntryPoint = "enet_time_set")]
internal static extern void EnetTimeSet(uint newTimeBase); internal static extern void ENetTimeSet(uint newTimeBase);
[DllImport(LIB, EntryPoint = "enet_packet_create")] [DllImport(LIB, EntryPoint = "enet_packet_create")]
internal static extern IntPtr EnetPacketCreate(byte[] data, uint dataLength, PacketFlags flags); internal static extern IntPtr ENetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
[DllImport(LIB, EntryPoint = "enet_packet_destroy")] [DllImport(LIB, EntryPoint = "enet_packet_destroy")]
internal static extern void EnetPacketDestroy(IntPtr packet); internal static extern void ENetPacketDestroy(IntPtr packet);
[DllImport(LIB, EntryPoint = "enet_packet_resize")] [DllImport(LIB, EntryPoint = "enet_packet_resize")]
internal static extern int EnetPacketResize(IntPtr packet, uint dataLength); internal static extern int ENetPacketResize(IntPtr packet, uint dataLength);
[DllImport(LIB, EntryPoint = "enet_peer_throttle_configure")] [DllImport(LIB, EntryPoint = "enet_peer_throttle_configure")]
internal static extern void EnetPeerThrottleConfigure( internal static extern void ENetPeerThrottleConfigure(
IntPtr peer, uint interval, uint acceleration, uint deceleration); IntPtr peer, uint interval, uint acceleration, uint deceleration);
[DllImport(LIB, EntryPoint = "enet_peer_send")] [DllImport(LIB, EntryPoint = "enet_peer_send")]
internal static extern int EnetPeerSend(IntPtr peer, byte channelID, IntPtr packet); internal static extern int ENetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
[DllImport(LIB, EntryPoint = "enet_peer_receive")] [DllImport(LIB, EntryPoint = "enet_peer_receive")]
internal static extern IntPtr EnetPeerReceive(IntPtr peer, out byte channelID); internal static extern IntPtr ENetPeerReceive(IntPtr peer, out byte channelID);
[DllImport(LIB, EntryPoint = "enet_peer_reset")] [DllImport(LIB, EntryPoint = "enet_peer_reset")]
internal static extern void EnetPeerReset(IntPtr peer); internal static extern void ENetPeerReset(IntPtr peer);
[DllImport(LIB, EntryPoint = "enet_peer_ping")] [DllImport(LIB, EntryPoint = "enet_peer_ping")]
internal static extern void EnetPeerPing(IntPtr peer); internal static extern void ENetPeerPing(IntPtr peer);
[DllImport(LIB, EntryPoint = "enet_peer_disconnect_now")] [DllImport(LIB, EntryPoint = "enet_peer_disconnect_now")]
internal static extern void EnetPeerDisconnectNow(IntPtr peer, uint data); internal static extern void ENetPeerDisconnectNow(IntPtr peer, uint data);
[DllImport(LIB, EntryPoint = "enet_peer_disconnect")] [DllImport(LIB, EntryPoint = "enet_peer_disconnect")]
internal static extern void EnetPeerDisconnect(IntPtr peer, uint data); internal static extern void ENetPeerDisconnect(IntPtr peer, uint data);
[DllImport(LIB, EntryPoint = "enet_peer_disconnect_later")] [DllImport(LIB, EntryPoint = "enet_peer_disconnect_later")]
internal static extern void EnetPeerDisconnectLater(IntPtr peer, uint data); internal static extern void ENetPeerDisconnectLater(IntPtr peer, uint data);
} }
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ namespace UNet ...@@ -17,7 +17,7 @@ namespace UNet
this.remoteAddress = this.socket.RemoteAddress; this.remoteAddress = this.socket.RemoteAddress;
} }
protected void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (this.socket == null) if (this.socket == null)
{ {
......
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Common.Logger;
using Common.Network; using Common.Network;
namespace UNet namespace UNet
...@@ -20,7 +19,7 @@ namespace UNet ...@@ -20,7 +19,7 @@ namespace UNet
{ {
throw new ArgumentNullException("data"); throw new ArgumentNullException("data");
} }
this.packet = NativeMethods.EnetPacketCreate(data, (uint) data.Length, flags); this.packet = NativeMethods.ENetPacketCreate(data, (uint) data.Length, flags);
if (this.packet == IntPtr.Zero) if (this.packet == IntPtr.Zero)
{ {
throw new UException("Packet creation call failed"); throw new UException("Packet creation call failed");
...@@ -45,7 +44,7 @@ namespace UNet ...@@ -45,7 +44,7 @@ namespace UNet
return; return;
} }
NativeMethods.EnetPacketDestroy(this.packet); NativeMethods.ENetPacketDestroy(this.packet);
this.packet = IntPtr.Zero; this.packet = IntPtr.Zero;
} }
......
...@@ -33,7 +33,7 @@ namespace UNet ...@@ -33,7 +33,7 @@ namespace UNet
{ {
UAddress address = new UAddress(hostName, port); UAddress address = new UAddress(hostName, port);
ENetAddress nativeAddress = address.Struct; ENetAddress nativeAddress = address.Struct;
this.host = NativeMethods.EnetHostCreate( this.host = NativeMethods.ENetHostCreate(
ref nativeAddress, NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0); ref nativeAddress, NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);
if (this.host == IntPtr.Zero) if (this.host == IntPtr.Zero)
...@@ -41,12 +41,12 @@ namespace UNet ...@@ -41,12 +41,12 @@ namespace UNet
throw new UException("Host creation call failed."); throw new UException("Host creation call failed.");
} }
NativeMethods.EnetHostCompressWithRangeCoder(this.host); NativeMethods.ENetHostCompressWithRangeCoder(this.host);
} }
public UPoller() public UPoller()
{ {
this.host = NativeMethods.EnetHostCreate( this.host = NativeMethods.ENetHostCreate(
IntPtr.Zero, NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0); IntPtr.Zero, NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);
if (this.host == IntPtr.Zero) if (this.host == IntPtr.Zero)
...@@ -73,7 +73,7 @@ namespace UNet ...@@ -73,7 +73,7 @@ namespace UNet
return; return;
} }
NativeMethods.EnetHostDestroy(this.host); NativeMethods.ENetHostDestroy(this.host);
this.host = IntPtr.Zero; this.host = IntPtr.Zero;
} }
...@@ -122,7 +122,7 @@ namespace UNet ...@@ -122,7 +122,7 @@ namespace UNet
UAddress address = new UAddress(hostName, port); UAddress address = new UAddress(hostName, port);
ENetAddress nativeAddress = address.Struct; ENetAddress nativeAddress = address.Struct;
IntPtr ptr = NativeMethods.EnetHostConnect(this.host, ref nativeAddress, IntPtr ptr = NativeMethods.ENetHostConnect(this.host, ref nativeAddress,
NativeMethods.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, 0); NativeMethods.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, 0);
USocket socket = new USocket(ptr); USocket socket = new USocket(ptr);
if (socket.PeerPtr == IntPtr.Zero) if (socket.PeerPtr == IntPtr.Zero)
...@@ -147,7 +147,7 @@ namespace UNet ...@@ -147,7 +147,7 @@ namespace UNet
{ {
this.eNetEventCache = new ENetEvent(); this.eNetEventCache = new ENetEvent();
} }
if (NativeMethods.EnetHostCheckEvents(this.host, this.eNetEventCache) <= 0) if (NativeMethods.ENetHostCheckEvents(this.host, this.eNetEventCache) <= 0)
{ {
return null; return null;
} }
...@@ -158,7 +158,7 @@ namespace UNet ...@@ -158,7 +158,7 @@ namespace UNet
public void Flush() public void Flush()
{ {
NativeMethods.EnetHostFlush(this.host); NativeMethods.ENetHostFlush(this.host);
} }
public void Add(Action action) public void Add(Action action)
...@@ -187,17 +187,12 @@ namespace UNet ...@@ -187,17 +187,12 @@ namespace UNet
private int Service() private int Service()
{ {
int ret = NativeMethods.EnetHostService(this.host, null, 0); int ret = NativeMethods.ENetHostService(this.host, null, 0);
return ret; return ret;
} }
public void RunOnce(int timeout = 0) public void Update()
{ {
if (timeout < 0)
{
throw new ArgumentOutOfRangeException(string.Format("timeout: {0}", timeout));
}
this.OnEvents(); this.OnEvents();
if (this.Service() < 0) if (this.Service() < 0)
......
...@@ -115,9 +115,9 @@ namespace UNet ...@@ -115,9 +115,9 @@ namespace UNet
this.channels.Remove(channel.RemoteAddress); this.channels.Remove(channel.RemoteAddress);
} }
public void Run() public void Update()
{ {
this.poller.RunOnce(); this.poller.Update();
} }
} }
} }
\ No newline at end of file
...@@ -14,7 +14,6 @@ namespace UNet ...@@ -14,7 +14,6 @@ namespace UNet
public Action<ENetEvent> Connected { get; set; } public Action<ENetEvent> Connected { get; set; }
public Action<ENetEvent> Received { get; private set; } public Action<ENetEvent> Received { get; private set; }
public Action<ENetEvent> Disconnect { get; private set; } public Action<ENetEvent> Disconnect { get; private set; }
public Action<int> Error { get; set; }
private void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
...@@ -23,7 +22,7 @@ namespace UNet ...@@ -23,7 +22,7 @@ namespace UNet
return; return;
} }
NativeMethods.EnetPeerReset(this.peerPtr); NativeMethods.ENetPeerReset(this.peerPtr);
this.peerPtr = IntPtr.Zero; this.peerPtr = IntPtr.Zero;
} }
...@@ -79,18 +78,18 @@ namespace UNet ...@@ -79,18 +78,18 @@ namespace UNet
public void Ping() public void Ping()
{ {
NativeMethods.EnetPeerPing(this.peerPtr); NativeMethods.ENetPeerPing(this.peerPtr);
} }
public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration) public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration)
{ {
NativeMethods.EnetPeerThrottleConfigure(this.peerPtr, interval, acceleration, deceleration); NativeMethods.ENetPeerThrottleConfigure(this.peerPtr, interval, acceleration, deceleration);
} }
public void SendAsync(byte[] data, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable) public void SendAsync(byte[] data, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
{ {
UPacket packet = new UPacket(data, flags); UPacket packet = new UPacket(data, flags);
NativeMethods.EnetPeerSend(this.peerPtr, channelID, packet.PacketPtr); NativeMethods.ENetPeerSend(this.peerPtr, channelID, packet.PacketPtr);
// enet_peer_send函数会自动删除packet,设置为0,防止Dispose或者析构函数再次删除 // enet_peer_send函数会自动删除packet,设置为0,防止Dispose或者析构函数再次删除
packet.PacketPtr = IntPtr.Zero; packet.PacketPtr = IntPtr.Zero;
} }
...@@ -127,7 +126,7 @@ namespace UNet ...@@ -127,7 +126,7 @@ namespace UNet
public Task<bool> DisconnectAsync(uint data = 0) public Task<bool> DisconnectAsync(uint data = 0)
{ {
NativeMethods.EnetPeerDisconnect(this.peerPtr, data); NativeMethods.ENetPeerDisconnect(this.peerPtr, data);
// EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose // EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose
this.peerPtr = IntPtr.Zero; this.peerPtr = IntPtr.Zero;
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
...@@ -137,7 +136,7 @@ namespace UNet ...@@ -137,7 +136,7 @@ namespace UNet
public Task<bool> DisconnectLaterAsync(uint data = 0) public Task<bool> DisconnectLaterAsync(uint data = 0)
{ {
NativeMethods.EnetPeerDisconnectLater(this.peerPtr, data); NativeMethods.ENetPeerDisconnectLater(this.peerPtr, data);
// EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose // EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose
this.peerPtr = IntPtr.Zero; this.peerPtr = IntPtr.Zero;
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
...@@ -147,7 +146,7 @@ namespace UNet ...@@ -147,7 +146,7 @@ namespace UNet
public void DisconnectNow(uint data) public void DisconnectNow(uint data)
{ {
NativeMethods.EnetPeerDisconnectNow(this.peerPtr, data); NativeMethods.ENetPeerDisconnectNow(this.peerPtr, data);
// EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose // EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose
this.peerPtr = IntPtr.Zero; this.peerPtr = IntPtr.Zero;
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc1\lib\net35\MongoDB.Bson.dll</HintPath> <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc1\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference> </Reference>
<Reference Include="MongoDB.Driver"> <Reference Include="MongoDB.Driver">
<HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc1\lib\net35\MongoDB.Driver.dll</HintPath> <HintPath>..\..\packages\mongocsharpdriver.1.10.0\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference> </Reference>
<Reference Include="nunit.framework"> <Reference Include="nunit.framework">
<HintPath>..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> <HintPath>..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
......
...@@ -29,6 +29,7 @@ namespace MongoDBTest ...@@ -29,6 +29,7 @@ namespace MongoDBTest
world.AddComponent<UnitComponent>(); world.AddComponent<UnitComponent>();
world.AddComponent<FactoryComponent<Unit>>(); world.AddComponent<FactoryComponent<Unit>>();
world.AddComponent<BehaviorTreeComponent>(); world.AddComponent<BehaviorTreeComponent>();
world.AddComponent<NetworkComponent>();
world.Load(); world.Load();
Unit player1 = world.GetComponent<FactoryComponent<Unit>>().Create(UnitType.GatePlayer, 1); Unit player1 = world.GetComponent<FactoryComponent<Unit>>().Create(UnitType.GatePlayer, 1);
......
...@@ -56,7 +56,7 @@ namespace TNetTest ...@@ -56,7 +56,7 @@ namespace TNetTest
{ {
while (!isClientStop) while (!isClientStop)
{ {
clientService.Run(); clientService.Update();
} }
}, TaskCreationOptions.LongRunning); }, TaskCreationOptions.LongRunning);
...@@ -64,7 +64,7 @@ namespace TNetTest ...@@ -64,7 +64,7 @@ namespace TNetTest
{ {
while (!isServerStop) while (!isServerStop)
{ {
serverService.Run(); serverService.Update();
} }
}, TaskCreationOptions.LongRunning); }, TaskCreationOptions.LongRunning);
......
...@@ -55,7 +55,7 @@ namespace UNetTest ...@@ -55,7 +55,7 @@ namespace UNetTest
{ {
while (!isClientStop) while (!isClientStop)
{ {
clientService.Run(); clientService.Update();
} }
}, TaskCreationOptions.LongRunning); }, TaskCreationOptions.LongRunning);
...@@ -63,7 +63,7 @@ namespace UNetTest ...@@ -63,7 +63,7 @@ namespace UNetTest
{ {
while (!isServerStop) while (!isServerStop)
{ {
serverService.Run(); serverService.Update();
} }
}, TaskCreationOptions.LongRunning); }, TaskCreationOptions.LongRunning);
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="CommandLine">
<HintPath>..\..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.Prism.Composition"> <Reference Include="Microsoft.Practices.Prism.Composition">
<HintPath>..\..\packages\Prism.Composition.5.0.0\lib\NET45\Microsoft.Practices.Prism.Composition.dll</HintPath> <HintPath>..\..\packages\Prism.Composition.5.0.0\lib\NET45\Microsoft.Practices.Prism.Composition.dll</HintPath>
</Reference> </Reference>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="CommandLineParser" version="1.9.71" targetFramework="net45" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net45" /> <package id="CommonServiceLocator" version="1.3" targetFramework="net45" />
<package id="mongocsharpdriver" version="1.10.0" targetFramework="net45" /> <package id="mongocsharpdriver" version="1.10.0" targetFramework="net45" />
<package id="NLog" version="3.2.0.0" targetFramework="net45" /> <package id="NLog" version="3.2.0.0" targetFramework="net45" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册