Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
c43ca07a
E
et
项目概览
guo450212436
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
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,体验更适合开发者的 AI 搜索 >>
提交
c43ca07a
编写于
12月 07, 2017
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
消除TimerComponent每次udpate的gc
上级
67956cd7
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
107 addition
and
101 deletion
+107
-101
Client-Server.sln
Client-Server.sln
+1
-1
Server/Hotfix/Handler/G2G_LockRequestHandler.cs
Server/Hotfix/Handler/G2G_LockRequestHandler.cs
+1
-0
Server/Hotfix/System/NetOuterComponentSystem.cs
Server/Hotfix/System/NetOuterComponentSystem.cs
+2
-2
Server/Model/Component/ActorProxyComponent.cs
Server/Model/Component/ActorProxyComponent.cs
+17
-3
Server/Model/Component/BenchmarkComponent.cs
Server/Model/Component/BenchmarkComponent.cs
+2
-2
Server/Model/Entity/ActorProxy.cs
Server/Model/Entity/ActorProxy.cs
+35
-33
Unity/Assets/Scripts/Base/MultiMap.cs
Unity/Assets/Scripts/Base/MultiMap.cs
+16
-5
Unity/Assets/Scripts/Base/Network/AService.cs
Unity/Assets/Scripts/Base/Network/AService.cs
+0
-2
Unity/Assets/Scripts/Base/Network/KNet/KChannel.cs
Unity/Assets/Scripts/Base/Network/KNet/KChannel.cs
+0
-2
Unity/Assets/Scripts/Base/Network/KNet/KService.cs
Unity/Assets/Scripts/Base/Network/KNet/KService.cs
+11
-17
Unity/Assets/Scripts/Base/Network/TNet/TService.cs
Unity/Assets/Scripts/Base/Network/TNet/TService.cs
+1
-6
Unity/Assets/Scripts/Base/Network/UNet/UService.cs
Unity/Assets/Scripts/Base/Network/UNet/UService.cs
+0
-4
Unity/Assets/Scripts/Component/NetOuterComponent.cs
Unity/Assets/Scripts/Component/NetOuterComponent.cs
+1
-1
Unity/Assets/Scripts/Component/TimerComponent.cs
Unity/Assets/Scripts/Component/TimerComponent.cs
+12
-12
Unity/Unity.Editor.Plugins.csproj
Unity/Unity.Editor.Plugins.csproj
+1
-1
Unity/Unity.Editor.csproj
Unity/Unity.Editor.csproj
+1
-1
Unity/Unity.Plugins.csproj
Unity/Unity.Plugins.csproj
+1
-1
Unity/Unity.csproj
Unity/Unity.csproj
+5
-8
未找到文件。
Client-Server.sln
浏览文件 @
c43ca07a
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27
004.2009
VisualStudioVersion = 15.0.27
130.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Plugins", "Unity\Unity.Plugins.csproj", "{D1FDB199-0FB7-099D-3771-C6A942E4E326}"
EndProject
...
...
Server/Hotfix/Handler/G2G_LockRequestHandler.cs
浏览文件 @
c43ca07a
...
...
@@ -16,6 +16,7 @@ namespace Hotfix
{
response
.
Error
=
ErrorCode
.
ERR_NotFoundUnit
;
reply
(
response
);
return
;
}
await
unit
.
GetComponent
<
MasterComponent
>().
Lock
(
message
.
Address
);
...
...
Server/Hotfix/System/NetOuterComponentSystem.cs
浏览文件 @
c43ca07a
...
...
@@ -26,14 +26,14 @@ namespace Hotfix
{
public
static
void
Awake
(
this
NetOuterComponent
self
)
{
self
.
Awake
(
NetworkProtocol
.
T
CP
);
self
.
Awake
(
NetworkProtocol
.
K
CP
);
self
.
MessagePacker
=
new
ProtobufPacker
();
self
.
MessageDispatcher
=
new
OuterMessageDispatcher
();
}
public
static
void
Awake
(
this
NetOuterComponent
self
,
IPEndPoint
ipEndPoint
)
{
self
.
Awake
(
NetworkProtocol
.
T
CP
,
ipEndPoint
);
self
.
Awake
(
NetworkProtocol
.
K
CP
,
ipEndPoint
);
self
.
MessagePacker
=
new
ProtobufPacker
();
self
.
MessageDispatcher
=
new
OuterMessageDispatcher
();
}
...
...
Server/Model/Component/ActorProxyComponent.cs
浏览文件 @
c43ca07a
...
...
@@ -5,7 +5,7 @@ namespace Model
[
ObjectEvent
]
public
class
ActorProxyComponentEvent
:
ObjectEvent
<
ActorProxyComponent
>,
IStart
{
// 每
分钟扫描一次过期的actorproxy进行回收,过期时间是5
分钟
// 每
10s扫描一次过期的actorproxy进行回收,过期时间是1
分钟
public
async
void
Start
()
{
ActorProxyComponent
self
=
this
.
Get
();
...
...
@@ -14,7 +14,7 @@ namespace Model
while
(
true
)
{
await
Game
.
Scene
.
GetComponent
<
TimerComponent
>().
WaitAsync
(
60
000
);
await
Game
.
Scene
.
GetComponent
<
TimerComponent
>().
WaitAsync
(
1
000
);
if
(
self
.
Id
==
0
)
{
...
...
@@ -32,7 +32,7 @@ namespace Model
continue
;
}
if
(
timeNow
<
actorProxy
.
LastSendTime
+
5
*
6
0000
)
if
(
timeNow
<
actorProxy
.
LastSendTime
+
1
0000
)
{
continue
;
}
...
...
@@ -52,6 +52,20 @@ namespace Model
{
public
readonly
Dictionary
<
long
,
ActorProxy
>
ActorProxys
=
new
Dictionary
<
long
,
ActorProxy
>();
public
override
void
Dispose
()
{
if
(
this
.
Id
==
0
)
{
return
;
}
base
.
Dispose
();
foreach
(
ActorProxy
actorProxy
in
this
.
ActorProxys
.
Values
)
{
actorProxy
.
Dispose
();
}
this
.
ActorProxys
.
Clear
();
}
public
ActorProxy
Get
(
long
id
)
{
if
(
this
.
ActorProxys
.
TryGetValue
(
id
,
out
ActorProxy
actorProxy
))
...
...
Server/Model/Component/BenchmarkComponent.cs
浏览文件 @
c43ca07a
...
...
@@ -26,7 +26,7 @@ namespace Model
NetOuterComponent
networkComponent
=
Game
.
Scene
.
GetComponent
<
NetOuterComponent
>();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
await
Game
.
Scene
.
GetComponent
<
TimerComponent
>().
WaitAsync
(
100
0
);
await
Game
.
Scene
.
GetComponent
<
TimerComponent
>().
WaitAsync
(
100
);
this
.
TestAsync
(
networkComponent
,
ipEndPoint
,
i
);
}
}
...
...
@@ -43,7 +43,7 @@ namespace Model
using
(
Session
session
=
networkComponent
.
Create
(
ipEndPoint
))
{
int
i
=
0
;
while
(
i
<
100000000
0
)
while
(
i
<
100000000
)
{
++
i
;
await
this
.
Send
(
session
,
j
);
...
...
Server/Model/Entity/ActorProxy.cs
浏览文件 @
c43ca07a
...
...
@@ -123,16 +123,45 @@ namespace Model
this
.
tcs
=
null
;
this
.
CancellationTokenSource
=
new
CancellationTokenSource
();
}
public
void
Start
()
public
override
void
Dispose
()
{
if
(
this
.
Id
==
0
)
{
return
;
}
base
.
Dispose
();
this
.
LastSendTime
=
0
;
this
.
Address
=
null
;
this
.
RunningTasks
.
Clear
();
this
.
WaitingTasks
.
Clear
();
this
.
failTimes
=
0
;
var
t
=
this
.
tcs
;
this
.
tcs
=
null
;
t
?.
SetResult
(
null
);
}
public
async
void
Start
()
{
int
appId
=
await
Game
.
Scene
.
GetComponent
<
LocationProxyComponent
>().
Get
(
this
.
Id
);
this
.
Address
=
Game
.
Scene
.
GetComponent
<
StartConfigComponent
>().
Get
(
appId
).
GetComponent
<
InnerConfig
>().
Address
;
this
.
UpdateAsync
();
}
private
void
Add
(
ActorTask
task
)
{
if
(
this
.
Id
==
0
)
{
throw
new
Exception
(
"ActorProxy Disposed! dont hold actorproxy"
);
}
this
.
WaitingTasks
.
Enqueue
(
task
);
this
.
AllowGet
();
// failtimes > 0表示正在重试,这时候不能加到正在发送队列
if
(
this
.
failTimes
==
0
)
{
this
.
AllowGet
();
}
}
private
void
Remove
()
...
...
@@ -147,8 +176,7 @@ namespace Model
{
return
;
}
ActorTask
task
=
this
.
WaitingTasks
.
Dequeue
();
this
.
RunningTasks
.
Enqueue
(
task
);
...
...
@@ -172,18 +200,13 @@ namespace Model
private
async
void
UpdateAsync
()
{
if
(
this
.
Address
==
null
)
{
int
appId
=
await
Game
.
Scene
.
GetComponent
<
LocationProxyComponent
>().
Get
(
this
.
Id
);
this
.
Address
=
Game
.
Scene
.
GetComponent
<
StartConfigComponent
>().
Get
(
appId
).
GetComponent
<
InnerConfig
>().
Address
;
}
while
(
true
)
{
ActorTask
actorTask
=
await
this
.
GetAsync
();
if
(
this
.
Id
==
0
)
{
return
;
}
ActorTask
actorTask
=
await
this
.
GetAsync
();
if
(
actorTask
==
null
)
{
return
;
...
...
@@ -233,7 +256,6 @@ namespace Model
Game
.
Scene
.
GetComponent
<
ActorProxyComponent
>().
Remove
(
this
.
Id
);
return
;
}
// 等待一会再发送
await
Game
.
Scene
.
GetComponent
<
TimerComponent
>().
WaitAsync
(
this
.
failTimes
*
500
);
int
appId
=
await
Game
.
Scene
.
GetComponent
<
LocationProxyComponent
>().
Get
(
this
.
Id
);
...
...
@@ -244,6 +266,7 @@ namespace Model
}
// 发送成功
this
.
LastSendTime
=
TimeHelper
.
Now
();
this
.
failTimes
=
0
;
if
(
this
.
WindowSize
<
MaxWindowSize
)
{
...
...
@@ -259,14 +282,12 @@ namespace Model
public
void
Send
(
AMessage
message
)
{
this
.
LastSendTime
=
TimeHelper
.
Now
();
ActorMessageTask
task
=
new
ActorMessageTask
(
this
,
message
);
this
.
Add
(
task
);
}
public
Task
<
Response
>
Call
<
Response
>(
ARequest
request
)
where
Response
:
AResponse
{
this
.
LastSendTime
=
TimeHelper
.
Now
();
ActorRpcTask
<
Response
>
task
=
new
ActorRpcTask
<
Response
>(
this
,
request
);
this
.
Add
(
task
);
return
task
.
Tcs
.
Task
;
...
...
@@ -298,24 +319,5 @@ namespace Model
}
return
s
;
}
public
override
void
Dispose
()
{
if
(
this
.
Id
==
0
)
{
return
;
}
base
.
Dispose
();
this
.
LastSendTime
=
0
;
this
.
Address
=
""
;
this
.
RunningTasks
.
Clear
();
this
.
WaitingTasks
.
Clear
();
this
.
failTimes
=
0
;
var
t
=
this
.
tcs
;
this
.
tcs
=
null
;
t
?.
SetResult
(
null
);
}
}
}
\ No newline at end of file
Unity/Assets/Scripts/Base/MultiMap.cs
浏览文件 @
c43ca07a
using
System.Collections.Generic
;
using
System.Linq
;
namespace
Model
{
...
...
@@ -9,12 +10,9 @@ namespace Model
// 重用list
private
readonly
Queue
<
List
<
K
>>
queue
=
new
Queue
<
List
<
K
>>();
public
SortedDictionary
<
T
,
List
<
K
>>
.
KeyCollection
Keys
public
SortedDictionary
<
T
,
List
<
K
>>
GetDictionary
()
{
get
{
return
this
.
dictionary
.
Keys
;
}
return
this
.
dictionary
;
}
public
void
Add
(
T
t
,
K
k
)
...
...
@@ -29,6 +27,19 @@ namespace Model
this
.
dictionary
[
t
]
=
list
;
}
public
KeyValuePair
<
T
,
List
<
K
>>
First
()
{
return
this
.
dictionary
.
First
();
}
public
int
Count
{
get
{
return
this
.
dictionary
.
Count
;
}
}
private
List
<
K
>
FetchList
()
{
if
(
this
.
queue
.
Count
>
0
)
...
...
Unity/Assets/Scripts/Base/Network/AService.cs
浏览文件 @
c43ca07a
...
...
@@ -13,8 +13,6 @@ namespace Model
public
abstract
class
AService
:
IDisposable
{
public
abstract
void
Add
(
Action
action
);
public
abstract
AChannel
GetChannel
(
long
id
);
public
abstract
Task
<
AChannel
>
AcceptChannel
();
...
...
Unity/Assets/Scripts/Base/Network/KNet/KChannel.cs
浏览文件 @
c43ca07a
...
...
@@ -143,9 +143,7 @@ namespace Model
this
.
OnError
(
this
,
SocketError
.
Disconnecting
);
return
;
}
this
.
kcp
.
Update
(
timeNow
);
uint
nextUpdateTime
=
this
.
kcp
.
Check
(
timeNow
);
this
.
GetService
().
AddToNextTimeUpdate
(
nextUpdateTime
,
this
.
Id
);
}
...
...
Unity/Assets/Scripts/Base/Network/KNet/KService.cs
浏览文件 @
c43ca07a
...
...
@@ -33,7 +33,6 @@ namespace Model
// 下次时间更新的channel
private
readonly
MultiMap
<
long
,
long
>
timerMap
=
new
MultiMap
<
long
,
long
>();
private
readonly
Queue
<
long
>
timeoutTimer
=
new
Queue
<
long
>();
public
KService
(
IPEndPoint
ipEndPoint
)
{
...
...
@@ -211,11 +210,7 @@ namespace Model
{
this
.
timerMap
.
Add
(
time
,
id
);
}
public
override
void
Add
(
Action
action
)
{
}
public
override
AChannel
GetChannel
(
long
id
)
{
KChannel
channel
;
...
...
@@ -254,26 +249,25 @@ namespace Model
public
override
void
Update
()
{
this
.
TimeNow
=
(
uint
)
TimeHelper
.
Now
();
foreach
(
long
time
in
this
.
timerMap
.
Keys
)
while
(
true
)
{
if
(
t
ime
>
this
.
TimeNow
)
if
(
t
his
.
timerMap
.
Count
<=
0
)
{
break
;
}
this
.
timeoutTimer
.
Enqueue
(
time
);
}
while
(
this
.
timeoutTimer
.
Count
>
0
)
{
long
key
=
this
.
timeoutTimer
.
Dequeue
();
List
<
long
>
timeOutId
=
this
.
timerMap
[
key
]
;
var
kv
=
this
.
timerMap
.
First
(
);
if
(
kv
.
Key
>
TimeNow
)
{
break
;
}
List
<
long
>
timeOutId
=
kv
.
Value
;
foreach
(
long
id
in
timeOutId
)
{
this
.
updateChannels
.
Add
(
id
);
}
this
.
timerMap
.
Remove
(
key
);
this
.
timerMap
.
Remove
(
k
v
.
K
ey
);
}
foreach
(
long
id
in
updateChannels
)
{
KChannel
kChannel
;
...
...
Unity/Assets/Scripts/Base/Network/TNet/TService.cs
浏览文件 @
c43ca07a
...
...
@@ -43,12 +43,7 @@ namespace Model
this
.
acceptor
.
Stop
();
this
.
acceptor
=
null
;
}
public
override
void
Add
(
Action
action
)
{
this
.
actions
.
Enqueue
(
action
);
}
public
override
AChannel
GetChannel
(
long
id
)
{
TChannel
channel
=
null
;
...
...
Unity/Assets/Scripts/Base/Network/UNet/UService.cs
浏览文件 @
c43ca07a
...
...
@@ -60,10 +60,6 @@ namespace Model
return
channel
;
}
public
override
void
Add
(
Action
action
)
{
}
public
override
AChannel
GetChannel
(
long
id
)
{
UChannel
channel
=
null
;
...
...
Unity/Assets/Scripts/Component/NetOuterComponent.cs
浏览文件 @
c43ca07a
...
...
@@ -18,7 +18,7 @@
{
public
void
Awake
()
{
this
.
Awake
(
NetworkProtocol
.
T
CP
);
this
.
Awake
(
NetworkProtocol
.
K
CP
);
this
.
MessagePacker
=
new
ProtobufPacker
();
this
.
MessageDispatcher
=
new
ClientDispatcher
();
}
...
...
Unity/Assets/Scripts/Component/TimerComponent.cs
浏览文件 @
c43ca07a
...
...
@@ -20,7 +20,7 @@ namespace Model
}
}
public
class
TimerComponent
:
Component
public
class
TimerComponent
:
Component
{
private
readonly
Dictionary
<
long
,
Timer
>
timers
=
new
Dictionary
<
long
,
Timer
>();
...
...
@@ -29,24 +29,23 @@ namespace Model
/// </summary>
private
readonly
MultiMap
<
long
,
long
>
timeId
=
new
MultiMap
<
long
,
long
>();
private
readonly
EQueue
<
long
>
timeoutTimer
=
new
EQueue
<
long
>();
public
void
Update
()
{
long
timeNow
=
TimeHelper
.
Now
();
foreach
(
long
time
in
this
.
timeId
.
Keys
)
while
(
true
)
{
if
(
time
>
timeNow
)
if
(
this
.
timeId
.
Count
<=
0
)
{
return
;
}
var
kv
=
this
.
timeId
.
First
();
if
(
kv
.
Key
>
timeNow
)
{
break
;
}
this
.
timeoutTimer
.
Enqueue
(
time
);
}
while
(
this
.
timeoutTimer
.
Count
>
0
)
{
long
key
=
this
.
timeoutTimer
.
Dequeue
();
List
<
long
>
timeOutId
=
this
.
timeId
[
key
];
List
<
long
>
timeOutId
=
kv
.
Value
;
foreach
(
long
id
in
timeOutId
)
{
Timer
timer
;
...
...
@@ -56,7 +55,8 @@ namespace Model
}
timer
.
tcs
.
SetResult
(
true
);
}
this
.
timeId
.
Remove
(
key
);
this
.
timeId
.
Remove
(
kv
.
Key
);
}
}
...
...
Unity/Unity.Editor.Plugins.csproj
浏览文件 @
c43ca07a
...
...
@@ -7,7 +7,7 @@
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{81A6E58E-BFF2-F1C8-1C4E-6316985F642C}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AssemblyName>
Assembly-CSharp-Editor-firstpass
.dll
</AssemblyName>
<AssemblyName>
Assembly-CSharp-Editor-firstpass
</AssemblyName>
<FileAlignment>
512
</FileAlignment>
<ProjectTypeGuids>
{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<TargetFrameworkIdentifier>
.NETFramework
</TargetFrameworkIdentifier>
...
...
Unity/Unity.Editor.csproj
浏览文件 @
c43ca07a
...
...
@@ -7,7 +7,7 @@
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{C17F48D3-964E-E97C-3D2E-966F7A6C6D93}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AssemblyName>
Assembly-CSharp-Editor
.dll
</AssemblyName>
<AssemblyName>
Assembly-CSharp-Editor
</AssemblyName>
<FileAlignment>
512
</FileAlignment>
<ProjectTypeGuids>
{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<TargetFrameworkIdentifier>
.NETFramework
</TargetFrameworkIdentifier>
...
...
Unity/Unity.Plugins.csproj
浏览文件 @
c43ca07a
...
...
@@ -7,7 +7,7 @@
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{D1FDB199-0FB7-099D-3771-C6A942E4E326}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AssemblyName>
Assembly-CSharp-firstpass
.dll
</AssemblyName>
<AssemblyName>
Assembly-CSharp-firstpass
</AssemblyName>
<FileAlignment>
512
</FileAlignment>
<ProjectTypeGuids>
{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<TargetFrameworkIdentifier>
.NETFramework
</TargetFrameworkIdentifier>
...
...
Unity/Unity.csproj
浏览文件 @
c43ca07a
...
...
@@ -7,20 +7,17 @@
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{CF118143-7E37-744F-BE45-3F55345FEC40}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AssemblyName>
Assembly-CSharp
.dll
</AssemblyName>
<AssemblyName>
Assembly-CSharp
</AssemblyName>
<FileAlignment>
512
</FileAlignment>
<ProjectTypeGuids>
{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
</ProjectTypeGuids>
<TargetFrameworkIdentifier>
.NETFramework
</TargetFrameworkIdentifier>
<TargetFrameworkVersion>
v4.6
</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<TargetFrameworkProfile></TargetFrameworkProfile>
<CompilerResponseFile></CompilerResponseFile>
<UnityProjectType>
Game:1
</UnityProjectType>
<UnityBuildTarget>
iOS:9
</UnityBuildTarget>
<UnityVersion>
2017.1.1p4
</UnityVersion>
<RootNamespace>
</RootNamespace>
<RootNamespace></RootNamespace>
<LangVersion>
6
</LangVersion>
</PropertyGroup>
<PropertyGroup>
...
...
@@ -587,4 +584,4 @@
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"GenerateTargetFrameworkMonikerAttribute"
/>
</Project>
\ No newline at end of file
</Project>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录