Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老鱼er
et
提交
268135c1
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,体验更适合开发者的 AI 搜索 >>
提交
268135c1
编写于
9月 05, 2018
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
客户端为了0GC需要消息池,服务端消息需要跨协程不能有消息池
上级
9beff5f6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
81 addition
and
51 deletion
+81
-51
Server/Model/Server.Model.csproj
Server/Model/Server.Model.csproj
+6
-2
Unity/Assets/Scripts/Module/Message/MessagePool.cs
Unity/Assets/Scripts/Module/Message/MessagePool.cs
+46
-34
Unity/Assets/Scripts/Module/Message/OpcodeTypeComponent.cs
Unity/Assets/Scripts/Module/Message/OpcodeTypeComponent.cs
+5
-0
Unity/Hotfix/Module/Message/MessagePool.cs
Unity/Hotfix/Module/Message/MessagePool.cs
+24
-15
未找到文件。
Server/Model/Server.Model.csproj
浏览文件 @
268135c1
...
...
@@ -17,6 +17,12 @@
</PropertyGroup>
<ItemGroup>
<Compile Remove="Libs\**" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessagePool.cs">
<Link>Module\Message\MessagePool\ETModel\MessagePool.cs</Link>
</Compile>
<Compile Include="..\..\Unity\Hotfix\Module\Message\MessagePool.cs">
<Link>Module\Message\MessagePool\ETHotfix\MessagePool.cs</Link>
</Compile>
<EmbeddedResource Remove="Libs\**" />
<None Remove="Libs\**" />
</ItemGroup>
...
...
@@ -87,7 +93,6 @@
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessageAttribute.cs" Link="Module\Message\MessageAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessageHandlerAttribute.cs" Link="Module\Message\MessageHandlerAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessageInfo.cs" Link="Module\Message\MessageInfo.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessagePool.cs" Link="Module\Message\MessagePool.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\NetworkComponent.cs" Link="Module\Message\NetworkComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\Network\AChannel.cs" Link="Module\Message\Network\AChannel.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\Network\AService.cs" Link="Module\Message\Network\AService.cs" />
...
...
@@ -116,7 +121,6 @@
<Compile Include="..\..\Unity\Assets\Scripts\Other\AppType.cs" Link="Other\AppType.cs" />
<Compile Include="..\..\Unity\Hotfix\Module\Message\HotfixMessage.cs" Link="Module\Message\HotfixMessage.cs" />
<Compile Include="..\..\Unity\Hotfix\Module\Message\HotfixOpcode.cs" Link="Module\Message\HotfixOpcode.cs" />
<Compile Include="..\..\Unity\Hotfix\Module\Message\MessagePool.cs" Link="Module\Message\MessagePool\MessagePool.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.2.1" />
...
...
Unity/Assets/Scripts/Module/Message/MessagePool.cs
浏览文件 @
268135c1
...
...
@@ -3,48 +3,60 @@ using System.Collections.Generic;
namespace
ETModel
{
public
class
MessagePool
{
public
static
MessagePool
Instance
{
get
;
}
=
new
MessagePool
();
private
readonly
Dictionary
<
Type
,
Queue
<
object
>>
dictionary
=
new
Dictionary
<
Type
,
Queue
<
object
>>();
public
object
Fetch
(
Type
type
)
{
Queue
<
object
>
queue
;
if
(!
this
.
dictionary
.
TryGetValue
(
type
,
out
queue
))
{
queue
=
new
Queue
<
object
>();
this
.
dictionary
.
Add
(
type
,
queue
);
}
object
obj
;
// 客户端为了0GC需要消息池,服务端消息需要跨协程不需要消息池
public
class
MessagePool
{
public
static
MessagePool
Instance
{
get
;
}
=
new
MessagePool
();
#if !SERVER
private
readonly
Dictionary
<
Type
,
Queue
<
object
>>
dictionary
=
new
Dictionary
<
Type
,
Queue
<
object
>>();
#endif
public
object
Fetch
(
Type
type
)
{
#if !SERVER
Queue
<
object
>
queue
;
if
(!
this
.
dictionary
.
TryGetValue
(
type
,
out
queue
))
{
queue
=
new
Queue
<
object
>();
this
.
dictionary
.
Add
(
type
,
queue
);
}
object
obj
;
if
(
queue
.
Count
>
0
)
{
{
obj
=
queue
.
Dequeue
();
}
}
else
{
obj
=
Activator
.
CreateInstance
(
type
);
obj
=
Activator
.
CreateInstance
(
type
);
}
return
obj
;
}
public
T
Fetch
<
T
>()
where
T
:
class
return
obj
;
#else
return
Activator
.
CreateInstance
(
type
);
#endif
}
public
T
Fetch
<
T
>()
where
T
:
class
{
T
t
=
(
T
)
this
.
Fetch
(
typeof
(
T
));
T
t
=
(
T
)
this
.
Fetch
(
typeof
(
T
));
return
t
;
}
public
void
Recycle
(
object
obj
)
{
Type
type
=
obj
.
GetType
();
Queue
<
object
>
queue
;
if
(!
this
.
dictionary
.
TryGetValue
(
type
,
out
queue
))
{
queue
=
new
Queue
<
object
>();
public
void
Recycle
(
object
obj
)
{
#if !SERVER
Type
type
=
obj
.
GetType
();
Queue
<
object
>
queue
;
if
(!
this
.
dictionary
.
TryGetValue
(
type
,
out
queue
))
{
queue
=
new
Queue
<
object
>();
this
.
dictionary
.
Add
(
type
,
queue
);
}
queue
.
Enqueue
(
obj
);
}
}
}
queue
.
Enqueue
(
obj
);
#endif
}
}
}
\ No newline at end of file
Unity/Assets/Scripts/Module/Message/OpcodeTypeComponent.cs
浏览文件 @
268135c1
...
...
@@ -62,8 +62,13 @@ namespace ETModel
return
this
.
opcodeTypes
.
GetValueByKey
(
opcode
);
}
// 客户端为了0GC需要消息池,服务端消息需要跨协程不需要消息池
public
object
GetInstance
(
ushort
opcode
)
{
#if SERVER
Type
type
=
this
.
GetType
(
opcode
);
return
Activator
.
CreateInstance
(
type
);
#endif
return
this
.
typeMessages
[
opcode
];
}
...
...
Unity/Hotfix/Module/Message/MessagePool.cs
浏览文件 @
268135c1
...
...
@@ -3,30 +3,37 @@ using System.Collections.Generic;
namespace
ETHotfix
{
// 客户端为了0GC需要消息池,服务端消息需要跨协程不需要消息池
public
class
MessagePool
{
public
static
MessagePool
Instance
{
get
;
}
=
new
MessagePool
();
#if !SERVER
private
readonly
Dictionary
<
Type
,
Queue
<
object
>>
dictionary
=
new
Dictionary
<
Type
,
Queue
<
object
>>();
#endif
public
object
Fetch
(
Type
type
)
{
#if !SERVER
Queue
<
object
>
queue
;
if
(!
this
.
dictionary
.
TryGetValue
(
type
,
out
queue
))
{
queue
=
new
Queue
<
object
>();
this
.
dictionary
.
Add
(
type
,
queue
);
}
if
(!
this
.
dictionary
.
TryGetValue
(
type
,
out
queue
))
{
queue
=
new
Queue
<
object
>();
this
.
dictionary
.
Add
(
type
,
queue
);
}
object
obj
;
if
(
queue
.
Count
>
0
)
{
obj
=
queue
.
Dequeue
();
}
else
{
obj
=
Activator
.
CreateInstance
(
type
);
}
return
obj
;
if
(
queue
.
Count
>
0
)
{
obj
=
queue
.
Dequeue
();
}
else
{
obj
=
Activator
.
CreateInstance
(
type
);
}
return
obj
;
#else
return
Activator
.
CreateInstance
(
type
);
#endif
}
public
T
Fetch
<
T
>()
where
T
:
class
...
...
@@ -37,6 +44,7 @@ namespace ETHotfix
public
void
Recycle
(
object
obj
)
{
#if !SERVER
Type
type
=
obj
.
GetType
();
Queue
<
object
>
queue
;
if
(!
this
.
dictionary
.
TryGetValue
(
type
,
out
queue
))
...
...
@@ -45,6 +53,7 @@ namespace ETHotfix
this
.
dictionary
.
Add
(
type
,
queue
);
}
queue
.
Enqueue
(
obj
);
#endif
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录