Skip to content

Commit 2b1193b

Browse files
committed
调整mailbox概念, 改名为entityCall
kbengine/kbengine#546
1 parent 38e8367 commit 2b1193b

File tree

5 files changed

+112
-112
lines changed

5 files changed

+112
-112
lines changed

DataTypes.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public override bool isSameType(object v)
487487
}
488488
}
489489

490-
public class KBEDATATYPE_MAILBOX : KBEDATATYPE_BASE
490+
public class KBEDATATYPE_ENTITYCALL : KBEDATATYPE_BASE
491491
{
492492
public override object createFromStream(MemoryStream stream)
493493
{

Entity.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class Entity
2626

2727
public object renderObj = null;
2828

29-
public Mailbox baseMailbox = null;
30-
public Mailbox cellMailbox = null;
29+
public EntityCall baseEntityCall = null;
30+
public EntityCall cellEntityCall = null;
3131

3232
// enterworld之后设置为true
3333
public bool inWorld = false;
@@ -194,16 +194,16 @@ public void baseCall(string methodname, params object[] arguments)
194194
return;
195195
}
196196

197-
baseMailbox.newMail();
198-
baseMailbox.bundle.writeUint16(methodID);
197+
baseEntityCall.newCall();
198+
baseEntityCall.bundle.writeUint16(methodID);
199199

200200
try
201201
{
202202
for(var i=0; i<method.args.Count; i++)
203203
{
204204
if(method.args[i].isSameType(arguments[i]))
205205
{
206-
method.args[i].addToStream(baseMailbox.bundle, arguments[i]);
206+
method.args[i].addToStream(baseEntityCall.bundle, arguments[i]);
207207
}
208208
else
209209
{
@@ -214,11 +214,11 @@ public void baseCall(string methodname, params object[] arguments)
214214
catch(Exception e)
215215
{
216216
Dbg.ERROR_MSG(className + "::baseCall(method=" + methodname + "): args is error(" + e.Message + ")!");
217-
baseMailbox.bundle = null;
217+
baseEntityCall.bundle = null;
218218
return;
219219
}
220220

221-
baseMailbox.postMail(null);
221+
baseEntityCall.sendCall(null);
222222
}
223223

224224
public void cellCall(string methodname, params object[] arguments)
@@ -251,22 +251,22 @@ public void cellCall(string methodname, params object[] arguments)
251251
return;
252252
}
253253

254-
if(cellMailbox == null)
254+
if(cellEntityCall == null)
255255
{
256256
Dbg.ERROR_MSG(className + "::cellCall(" + methodname + "): no cell!");
257257
return;
258258
}
259259

260-
cellMailbox.newMail();
261-
cellMailbox.bundle.writeUint16(methodID);
260+
cellEntityCall.newCall();
261+
cellEntityCall.bundle.writeUint16(methodID);
262262

263263
try
264264
{
265265
for(var i=0; i<method.args.Count; i++)
266266
{
267267
if(method.args[i].isSameType(arguments[i]))
268268
{
269-
method.args[i].addToStream(cellMailbox.bundle, arguments[i]);
269+
method.args[i].addToStream(cellEntityCall.bundle, arguments[i]);
270270
}
271271
else
272272
{
@@ -277,11 +277,11 @@ public void cellCall(string methodname, params object[] arguments)
277277
catch(Exception e)
278278
{
279279
Dbg.ERROR_MSG(className + "::cellCall(" + methodname + "): args is error(" + e.Message + ")!");
280-
cellMailbox.bundle = null;
280+
cellEntityCall.bundle = null;
281281
return;
282282
}
283283

284-
cellMailbox.postMail(null);
284+
cellEntityCall.sendCall(null);
285285
}
286286

287287
public void enterWorld()

Mailbox.cs EntityCall.cs

+82-82
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
namespace KBEngine
2-
{
3-
using UnityEngine;
4-
using System;
5-
using System.Collections;
6-
using System.Collections.Generic;
7-
8-
/*
9-
实体的Mailbox
10-
关于Mailbox请参考API手册中对它的描述
11-
https://github.com/kbengine/kbengine/tree/master/docs/api
12-
*/
13-
public class Mailbox
14-
{
15-
// Mailbox的类别
16-
public enum MAILBOX_TYPE
17-
{
18-
MAILBOX_TYPE_CELL = 0, // CELL_MAILBOX
19-
MAILBOX_TYPE_BASE = 1 // BASE_MAILBOX
20-
}
21-
22-
public Int32 id = 0;
23-
public string className = "";
24-
public MAILBOX_TYPE type = MAILBOX_TYPE.MAILBOX_TYPE_CELL;
25-
26-
private NetworkInterface networkInterface_;
27-
28-
public Bundle bundle = null;
29-
30-
public Mailbox()
31-
{
32-
networkInterface_ = KBEngineApp.app.networkInterface();
33-
}
34-
35-
public virtual void __init__()
36-
{
37-
}
38-
39-
bool isBase()
40-
{
41-
return type == MAILBOX_TYPE.MAILBOX_TYPE_BASE;
42-
}
43-
44-
bool isCell()
45-
{
46-
return type == MAILBOX_TYPE.MAILBOX_TYPE_CELL;
47-
}
48-
49-
/*
50-
创建新的mail
51-
*/
52-
public Bundle newMail()
53-
{
54-
if(bundle == null)
55-
bundle = Bundle.createObject();
56-
57-
if(type == Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL)
58-
bundle.newMessage(Message.messages["Baseapp_onRemoteCallCellMethodFromClient"]);
59-
else
60-
bundle.newMessage(Message.messages["Base_onRemoteMethodCall"]);
61-
62-
bundle.writeInt32(this.id);
63-
64-
return bundle;
65-
}
66-
67-
/*
68-
向服务端发送这个mail
69-
*/
70-
public void postMail(Bundle inbundle)
71-
{
72-
if(inbundle == null)
73-
inbundle = bundle;
74-
75-
inbundle.send(networkInterface_);
76-
77-
if(inbundle == bundle)
78-
bundle = null;
79-
}
80-
}
81-
82-
}
1+
namespace KBEngine
2+
{
3+
using UnityEngine;
4+
using System;
5+
using System.Collections;
6+
using System.Collections.Generic;
7+
8+
/*
9+
实体的EntityCall
10+
关于EntityCall请参考API手册中对它的描述
11+
https://github.com/kbengine/kbengine/tree/master/docs/api
12+
*/
13+
public class EntityCall
14+
{
15+
// EntityCall的类别
16+
public enum ENTITYCALL_TYPE
17+
{
18+
ENTITYCALL_TYPE_CELL = 0, // CELL_ENTITYCALL
19+
ENTITYCALL_TYPE_BASE = 1 // BASE_ENTITYCALL
20+
}
21+
22+
public Int32 id = 0;
23+
public string className = "";
24+
public ENTITYCALL_TYPE type = ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL;
25+
26+
private NetworkInterface networkInterface_;
27+
28+
public Bundle bundle = null;
29+
30+
public EntityCall()
31+
{
32+
networkInterface_ = KBEngineApp.app.networkInterface();
33+
}
34+
35+
public virtual void __init__()
36+
{
37+
}
38+
39+
bool isBase()
40+
{
41+
return type == ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE;
42+
}
43+
44+
bool isCell()
45+
{
46+
return type == ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL;
47+
}
48+
49+
/*
50+
创建新的call
51+
*/
52+
public Bundle newCall()
53+
{
54+
if(bundle == null)
55+
bundle = Bundle.createObject();
56+
57+
if(type == EntityCall.ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL)
58+
bundle.newMessage(Message.messages["Baseapp_onRemoteCallCellMethodFromClient"]);
59+
else
60+
bundle.newMessage(Message.messages["Base_onRemoteMethodCall"]);
61+
62+
bundle.writeInt32(this.id);
63+
64+
return bundle;
65+
}
66+
67+
/*
68+
向服务端发送这个call
69+
*/
70+
public void sendCall(Bundle inbundle)
71+
{
72+
if(inbundle == null)
73+
inbundle = bundle;
74+
75+
inbundle.send(networkInterface_);
76+
77+
if(inbundle == bundle)
78+
bundle = null;
79+
}
80+
}
81+
82+
}

EntityDef.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static void initDataType()
6161
datatypes["VECTOR4"] = new KBEDATATYPE_VECTOR4();
6262
datatypes["PYTHON"] = new KBEDATATYPE_PYTHON();
6363
datatypes["UNICODE"] = new KBEDATATYPE_UNICODE();
64-
datatypes["MAILBOX"] = new KBEDATATYPE_MAILBOX();
64+
datatypes["ENTITYCALL"] = new KBEDATATYPE_ENTITYCALL();
6565
datatypes["BLOB"] = new KBEDATATYPE_BLOB();
6666
}
6767

@@ -80,7 +80,7 @@ public static void bindMessageDataType()
8080
datatype2id["DATATYPE"] = 2;
8181
datatype2id["CHAR"] = 2;
8282
datatype2id["DETAIL_TYPE"] = 2;
83-
datatype2id["MAIL_TYPE"] = 2;
83+
datatype2id["ENTITYCALL_TYPE"] = 2;
8484

8585
id2datatypes[2] = datatypes["UINT8"];
8686

@@ -137,7 +137,7 @@ public static void bindMessageDataType()
137137
datatype2id["PY_DICT"] = 10;
138138
datatype2id["PY_TUPLE"] = 10;
139139
datatype2id["PY_LIST"] = 10;
140-
datatype2id["MAILBOX"] = 10;
140+
datatype2id["ENTITYCALL"] = 10;
141141

142142
id2datatypes[10] = datatypes["PYTHON"];
143143

KBEngine.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1442,10 +1442,10 @@ public void Client_onCreatedProxies(UInt64 rndUUID, Int32 eid, string entityType
14421442
entity.id = eid;
14431443
entity.className = entityType;
14441444

1445-
entity.baseMailbox = new Mailbox();
1446-
entity.baseMailbox.id = eid;
1447-
entity.baseMailbox.className = entityType;
1448-
entity.baseMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_BASE;
1445+
entity.baseEntityCall = new EntityCall();
1446+
entity.baseEntityCall.id = eid;
1447+
entity.baseEntityCall.className = entityType;
1448+
entity.baseEntityCall.type = EntityCall.ENTITYCALL_TYPE.ENTITYCALL_TYPE_BASE;
14491449

14501450
entities[eid] = entity;
14511451

@@ -1713,10 +1713,10 @@ public void Client_onEntityEnterWorld(MemoryStream stream)
17131713
entity.id = eid;
17141714
entity.className = entityType;
17151715

1716-
entity.cellMailbox = new Mailbox();
1717-
entity.cellMailbox.id = eid;
1718-
entity.cellMailbox.className = entityType;
1719-
entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL;
1716+
entity.cellEntityCall = new EntityCall();
1717+
entity.cellEntityCall.id = eid;
1718+
entity.cellEntityCall.className = entityType;
1719+
entity.cellEntityCall.type = EntityCall.ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL;
17201720

17211721
entities[eid] = entity;
17221722

@@ -1747,10 +1747,10 @@ public void Client_onEntityEnterWorld(MemoryStream stream)
17471747
clearEntities(false);
17481748
entities[entity.id] = entity;
17491749

1750-
entity.cellMailbox = new Mailbox();
1751-
entity.cellMailbox.id = eid;
1752-
entity.cellMailbox.className = entityType;
1753-
entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL;
1750+
entity.cellEntityCall = new EntityCall();
1751+
entity.cellEntityCall.id = eid;
1752+
entity.cellEntityCall.className = entityType;
1753+
entity.cellEntityCall.type = EntityCall.ENTITYCALL_TYPE.ENTITYCALL_TYPE_CELL;
17541754

17551755
entity.set_direction(entity.getDefinedProperty("direction"));
17561756
entity.set_position(entity.getDefinedProperty("position"));
@@ -1794,7 +1794,7 @@ public void Client_onEntityLeaveWorld(Int32 eid)
17941794
if(entity_id == eid)
17951795
{
17961796
clearSpace(false);
1797-
entity.cellMailbox = null;
1797+
entity.cellEntityCall = null;
17981798
}
17991799
else
18001800
{

0 commit comments

Comments
 (0)