Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
885936f7
E
et
项目概览
老鱼er
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
885936f7
编写于
2月 28, 2015
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加IRunner接口,World的Componet实现该接口会每帧调用Run方法
上级
28af0327
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
118 addition
and
72 deletion
+118
-72
CSharp/CSharp.sln
CSharp/CSharp.sln
+0
-3
CSharp/Game/Controller/Factory/UnitFactory.cs
CSharp/Game/Controller/Factory/UnitFactory.cs
+1
-1
CSharp/Game/Model/Component/ActorComponent.cs
CSharp/Game/Model/Component/ActorComponent.cs
+8
-3
CSharp/Game/Model/Component/NetworkComponent.cs
CSharp/Game/Model/Component/NetworkComponent.cs
+5
-2
CSharp/Game/Model/Component/TimerComponent.cs
CSharp/Game/Model/Component/TimerComponent.cs
+2
-2
CSharp/Game/Model/IAssemblyLoader.cs
CSharp/Game/Model/IAssemblyLoader.cs
+3
-0
CSharp/Game/Model/IRunner.cs
CSharp/Game/Model/IRunner.cs
+10
-0
CSharp/Game/Model/Model.csproj
CSharp/Game/Model/Model.csproj
+1
-0
CSharp/Game/Model/World.cs
CSharp/Game/Model/World.cs
+35
-6
CSharp/Platform/Common/Network/IService.cs
CSharp/Platform/Common/Network/IService.cs
+1
-5
CSharp/Platform/ENet/ENet.vcxproj
CSharp/Platform/ENet/ENet.vcxproj
+3
-2
CSharp/Platform/TNet/IPoller.cs
CSharp/Platform/TNet/IPoller.cs
+1
-1
CSharp/Platform/TNet/TPoller.cs
CSharp/Platform/TNet/TPoller.cs
+1
-1
CSharp/Platform/TNet/TService.cs
CSharp/Platform/TNet/TService.cs
+5
-21
CSharp/Platform/UNet/UService.cs
CSharp/Platform/UNet/UService.cs
+2
-17
CSharp/Test/TNetTest/TServiceTest.cs
CSharp/Test/TNetTest/TServiceTest.cs
+20
-4
CSharp/Test/UNetTest/UServiceTest.cs
CSharp/Test/UNetTest/UServiceTest.cs
+20
-4
未找到文件。
CSharp/CSharp.sln
浏览文件 @
885936f7
...
...
@@ -136,7 +136,4 @@ Global
{1888D319-0495-43F3-BA8D-163EC20D9437} = {F13D0B3D-5B4F-452A-9378-0FD39555371D}
{47A7404D-F501-43C5-8183-4B4E9E8C24B2} = {F13D0B3D-5B4F-452A-9378-0FD39555371D}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
CSharp/Game/Controller/Factory/UnitFactory.cs
浏览文件 @
885936f7
...
...
@@ -9,7 +9,7 @@ namespace Controller
{
Unit
player
=
new
Unit
(
configId
);
player
.
AddComponent
<
BuffComponent
>();
player
.
AddComponent
<
ActorComponent
>()
.
Run
()
;
player
.
AddComponent
<
ActorComponent
>();
World
.
Instance
.
GetComponent
<
UnitComponent
>().
Add
(
player
);
return
player
;
}
...
...
CSharp/Game/Model/Component/ActorComponent.cs
浏览文件 @
885936f7
...
...
@@ -11,11 +11,16 @@ namespace Model
{
private
readonly
Queue
<
Env
>
msgEnvQueue
=
new
Queue
<
Env
>();
p
ublic
Action
msgAction
=
()
=>
{};
p
rivate
Action
msgAction
=
()
=>
{};
p
ublic
Env
Env
{
get
;
private
set
;
}
p
rivate
Env
Env
{
get
;
set
;
}
public
async
void
Run
()
public
ActorComponent
()
{
Start
();
}
private
async
void
Start
()
{
while
(
true
)
{
...
...
CSharp/Game/Model/Component/NetworkComponent.cs
浏览文件 @
885936f7
...
...
@@ -7,7 +7,7 @@ using UNet;
namespace
Model
{
public
class
NetworkComponent
:
Component
<
World
>
public
class
NetworkComponent
:
Component
<
World
>
,
IRunner
{
private
IService
service
;
...
...
@@ -26,8 +26,11 @@ namespace Model
}
this
.
service
.
Add
(
this
.
AcceptChannel
);
}
this
.
service
.
Start
();
public
void
Run
()
{
this
.
service
.
Run
();
}
/// <summary>
...
...
CSharp/Game/Model/Component/TimerComponent.cs
浏览文件 @
885936f7
...
...
@@ -6,7 +6,7 @@ using MongoDB.Bson;
namespace
Model
{
public
class
TimerComponent
:
Component
<
World
>
public
class
TimerComponent
:
Component
<
World
>,
IRunner
{
private
class
Timer
{
...
...
@@ -49,7 +49,7 @@ namespace Model
this
.
timeId
.
Remove
(
timer
.
Time
,
timer
.
Id
);
}
public
void
Update
()
public
void
Run
()
{
long
timeNow
=
TimeHelper
.
Now
();
foreach
(
long
time
in
this
.
timeId
.
Keys
)
...
...
CSharp/Game/Model/IAssemblyLoader.cs
浏览文件 @
885936f7
...
...
@@ -2,6 +2,9 @@
namespace
Model
{
/// <summary>
/// World的Componet实现该接口,World.Load会调用Load方法
/// </summary>
public
interface
IAssemblyLoader
{
void
Load
(
Assembly
assembly
);
...
...
CSharp/Game/Model/IRunner.cs
0 → 100644
浏览文件 @
885936f7
namespace
Model
{
/// <summary>
/// 实现了该接口的World Componet会每帧刷新
/// </summary>
public
interface
IRunner
{
void
Run
();
}
}
CSharp/Game/Model/Model.csproj
浏览文件 @
885936f7
...
...
@@ -67,6 +67,7 @@
<Compile
Include=
"FactoryAttribute.cs"
/>
<Compile
Include=
"IAssemblyLoader.cs"
/>
<Compile
Include=
"IFactory.cs"
/>
<Compile
Include=
"IRunner.cs"
/>
<Compile
Include=
"MessageAttribute.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Unit.cs"
/>
...
...
CSharp/Game/Model/World.cs
浏览文件 @
885936f7
using
System.IO
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Reflection
;
using
System.Threading
;
using
Common.Base
;
namespace
Model
...
...
@@ -8,7 +10,7 @@ namespace Model
{
private
static
readonly
World
instance
=
new
World
();
p
ublic
Assembly
Assembly
{
get
;
set
;
}
p
rivate
Assembly
assembly
;
public
static
World
Instance
{
...
...
@@ -18,23 +20,50 @@ namespace Model
}
}
private
List
<
IRunner
>
iRunners
;
private
bool
isStop
;
private
World
()
{
}
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
())
{
IAssemblyLoader
assemblyLoader
=
component
as
IAssemblyLoader
;
if
(
assemblyLoader
==
null
)
if
(
assemblyLoader
!=
null
)
{
assemblyLoader
.
Load
(
this
.
assembly
);
}
IRunner
runner
=
component
as
IRunner
;
if
(
runner
!=
null
)
{
this
.
iRunners
.
Add
(
runner
);
}
}
}
public
void
Start
()
{
while
(!
isStop
)
{
Thread
.
Sleep
(
1
);
foreach
(
IRunner
runner
in
this
.
iRunners
)
{
continue
;
runner
.
Run
()
;
}
assemblyLoader
.
Load
(
this
.
Assembly
);
}
}
public
void
Stop
()
{
isStop
=
true
;
}
}
}
\ No newline at end of file
CSharp/Platform/Common/Network/IService.cs
浏览文件 @
885936f7
...
...
@@ -26,10 +26,6 @@ namespace Common.Network
void
Remove
(
AChannel
channel
);
void
RunOnce
(
int
timeout
);
void
Start
();
void
Stop
();
void
Run
();
}
}
\ No newline at end of file
CSharp/Platform/ENet/ENet.vcxproj
浏览文件 @
885936f7
...
...
@@ -73,8 +73,8 @@
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<LinkIncremental>
true
</LinkIncremental>
<IncludePath>
$(SolutionDir)\Platform\;$(IncludePath)
</IncludePath>
<OutDir>
$(SolutionDir)\Bin\
Debug
\
</OutDir>
<IntDir>
$(SolutionDir)\Temp\
Debug
\
</IntDir>
<OutDir>
$(SolutionDir)\Bin\
$(Configuration)
\
</OutDir>
<IntDir>
$(SolutionDir)\Temp\
$(Configuration)
\
</IntDir>
<TargetExt>
.dll
</TargetExt>
<TargetName>
$(ProjectName)
</TargetName>
</PropertyGroup>
...
...
@@ -84,6 +84,7 @@
<LinkIncremental>
true
</LinkIncremental>
<IncludePath>
$(SolutionDir)\Platform\;$(IncludePath)
</IncludePath>
<OutDir>
$(SolutionDir)\Bin\$(Configuration)\
</OutDir>
<IntDir>
$(SolutionDir)\Temp\$(Configuration)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<LinkIncremental>
false
</LinkIncremental>
...
...
CSharp/Platform/TNet/IPoller.cs
浏览文件 @
885936f7
...
...
@@ -6,6 +6,6 @@ namespace TNet
{
void
Add
(
Action
action
);
void
Run
(
int
timeout
);
void
Run
();
}
}
\ No newline at end of file
CSharp/Platform/TNet/TPoller.cs
浏览文件 @
885936f7
...
...
@@ -16,7 +16,7 @@ namespace TNet
this
.
concurrentQueue
.
Enqueue
(
action
);
}
public
void
Run
(
int
timeout
)
public
void
Run
()
{
while
(
true
)
{
...
...
CSharp/Platform/TNet/TService.cs
浏览文件 @
885936f7
...
...
@@ -8,7 +8,7 @@ using MongoDB.Bson;
namespace
TNet
{
public
class
TService
:
IService
public
sealed
class
TService
:
IService
{
private
readonly
IPoller
poller
=
new
TPoller
();
private
TSocket
acceptor
;
...
...
@@ -19,8 +19,6 @@ namespace TNet
private
readonly
TimerManager
timerManager
=
new
TimerManager
();
private
bool
isStop
;
/// <summary>
/// 即可做client也可做server
/// </summary>
...
...
@@ -40,7 +38,7 @@ namespace TNet
{
}
pr
otected
virtual
void
Dispose
(
bool
disposing
)
pr
ivate
void
Dispose
(
bool
disposing
)
{
if
(
this
.
acceptor
==
null
)
{
...
...
@@ -57,7 +55,6 @@ namespace TNet
this
.
acceptor
.
Dispose
();
}
isStop
=
true
;
this
.
acceptor
=
null
;
}
...
...
@@ -130,23 +127,10 @@ namespace TNet
return
await
this
.
ConnectAsync
(
host
,
port
);
}
public
void
RunOnce
(
int
timeout
)
{
this
.
poller
.
Run
(
timeout
);
}
public
void
Start
()
{
while
(!
isStop
)
{
this
.
RunOnce
(
0
);
this
.
timerManager
.
Refresh
();
}
}
public
void
Stop
()
public
void
Run
()
{
this
.
isStop
=
true
;
this
.
poller
.
Run
();
this
.
timerManager
.
Refresh
();
}
internal
TimerManager
Timer
...
...
CSharp/Platform/UNet/UService.cs
浏览文件 @
885936f7
...
...
@@ -15,8 +15,6 @@ namespace UNet
private
readonly
Dictionary
<
ObjectId
,
UChannel
>
idChannels
=
new
Dictionary
<
ObjectId
,
UChannel
>();
private
bool
isStop
;
/// <summary>
/// 即可做client也可做server
/// </summary>
...
...
@@ -117,22 +115,9 @@ namespace UNet
this
.
channels
.
Remove
(
channel
.
RemoteAddress
);
}
public
void
RunOnce
(
int
timeout
)
{
this
.
poller
.
RunOnce
(
timeout
);
}
public
void
Start
()
{
while
(!
isStop
)
{
this
.
poller
.
RunOnce
();
}
}
public
void
Stop
()
public
void
Run
()
{
this
.
isStop
=
true
;
this
.
poller
.
RunOnce
()
;
}
}
}
\ No newline at end of file
CSharp/Test/TNetTest/TServiceTest.cs
浏览文件 @
885936f7
...
...
@@ -14,6 +14,9 @@ namespace TNetTest
private
const
int
echoTimes
=
10000
;
private
readonly
Barrier
barrier
=
new
Barrier
(
3
);
private
bool
isClientStop
;
private
bool
isServerStop
;
private
async
void
ClientEvent
(
IService
service
,
string
hostName
,
ushort
port
)
{
AChannel
channel
=
await
service
.
GetChannel
(
hostName
,
port
);
...
...
@@ -49,8 +52,21 @@ namespace TNetTest
using
(
IService
clientService
=
new
TService
())
using
(
IService
serverService
=
new
TService
(
hostName
,
8889
))
{
Task
task1
=
Task
.
Factory
.
StartNew
(()
=>
clientService
.
Start
(),
TaskCreationOptions
.
LongRunning
);
Task
task2
=
Task
.
Factory
.
StartNew
(()
=>
serverService
.
Start
(),
TaskCreationOptions
.
LongRunning
);
Task
task1
=
Task
.
Factory
.
StartNew
(()
=>
{
while
(!
isClientStop
)
{
clientService
.
Run
();
}
},
TaskCreationOptions
.
LongRunning
);
Task
task2
=
Task
.
Factory
.
StartNew
(()
=>
{
while
(!
isServerStop
)
{
serverService
.
Run
();
}
},
TaskCreationOptions
.
LongRunning
);
// 往server host线程增加事件,accept
serverService
.
Add
(()
=>
this
.
ServerEvent
(
serverService
));
...
...
@@ -62,8 +78,8 @@ namespace TNetTest
this
.
barrier
.
SignalAndWait
();
serverService
.
Add
(
serverService
.
Stop
);
clientService
.
Add
(
clientService
.
Stop
);
serverService
.
Add
(
()
=>
{
isServerStop
=
true
;
}
);
clientService
.
Add
(
()
=>
{
isClientStop
=
true
;
}
);
Task
.
WaitAll
(
task1
,
task2
);
}
}
...
...
CSharp/Test/UNetTest/UServiceTest.cs
浏览文件 @
885936f7
...
...
@@ -15,6 +15,9 @@ namespace UNetTest
private
const
int
echoTimes
=
10000
;
private
readonly
Barrier
barrier
=
new
Barrier
(
2
);
private
bool
isClientStop
;
private
bool
isServerStop
;
private
async
void
ClientEvent
(
IService
clientService
,
string
hostName
,
ushort
port
)
{
AChannel
channel
=
await
clientService
.
GetChannel
(
hostName
,
port
);
...
...
@@ -48,8 +51,21 @@ namespace UNetTest
using
(
IService
clientService
=
new
UService
(
hostName
,
8888
))
using
(
IService
serverService
=
new
UService
(
hostName
,
8889
))
{
Task
task1
=
Task
.
Factory
.
StartNew
(()
=>
clientService
.
Start
(),
TaskCreationOptions
.
LongRunning
);
Task
task2
=
Task
.
Factory
.
StartNew
(()
=>
serverService
.
Start
(),
TaskCreationOptions
.
LongRunning
);
Task
task1
=
Task
.
Factory
.
StartNew
(()
=>
{
while
(!
isClientStop
)
{
clientService
.
Run
();
}
},
TaskCreationOptions
.
LongRunning
);
Task
task2
=
Task
.
Factory
.
StartNew
(()
=>
{
while
(!
isServerStop
)
{
serverService
.
Run
();
}
},
TaskCreationOptions
.
LongRunning
);
// 往server host线程增加事件,accept
serverService
.
Add
(()
=>
this
.
ServerEvent
(
serverService
));
...
...
@@ -60,8 +76,8 @@ namespace UNetTest
clientService
.
Add
(()
=>
this
.
ClientEvent
(
clientService
,
hostName
,
port
));
barrier
.
SignalAndWait
();
serverService
.
Add
(
serverService
.
Stop
);
clientService
.
Add
(
clientService
.
Stop
);
serverService
.
Add
(
()
=>
{
isServerStop
=
true
;
}
);
clientService
.
Add
(
()
=>
{
isClientStop
=
true
;
}
);
Task
.
WaitAll
(
task1
,
task2
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录