Skip to content

Commit 57c3561

Browse files
committed
实体组件属性修改后的标脏机制
kbengine#630 实体组件方法的real调用机制 kbengine#629
1 parent 0732b73 commit 57c3561

File tree

6 files changed

+67
-34
lines changed

6 files changed

+67
-34
lines changed

kbe/src/lib/client_lib/entity_component.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ SCRIPT_GET_DECLARE("base", pyGetBaseEntityCall, 0, 0)
2121
SCRIPT_GETSET_DECLARE_END()
2222
BASE_SCRIPT_INIT(EntityComponent, 0, 0, 0, 0, 0)
2323

24+
//-------------------------------------------------------------------------------------
25+
PyObject* EntityComponent::onScriptGetAttribute(PyObject* attr)
26+
{
27+
return ScriptObject::onScriptGetAttribute(attr);
28+
}
29+
2430
}

kbe/src/lib/entitydef/entity_component.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -396,40 +396,6 @@ void EntityComponent::onInstallScript(PyObject* mod)
396396
*/
397397
}
398398

399-
//-------------------------------------------------------------------------------------
400-
PyObject* EntityComponent::onScriptGetAttribute(PyObject* attr)
401-
{
402-
wchar_t* PyUnicode_AsWideCharStringRet0 = PyUnicode_AsWideCharString(attr, NULL);
403-
char* ccattr = strutil::wchar2char(PyUnicode_AsWideCharStringRet0);
404-
PyMem_Free(PyUnicode_AsWideCharStringRet0);
405-
406-
/*
407-
// 如果是ghost调用def方法则需要rpc调用。
408-
if (!isReal())
409-
{
410-
MethodDescription* pMethodDescription = const_cast<ScriptDefModule*>(pScriptModule())->findCellMethodDescription(ccattr);
411-
412-
if (pMethodDescription)
413-
{
414-
free(ccattr);
415-
return new RealEntityMethod(pMethodDescription, this);
416-
}
417-
}
418-
else
419-
{
420-
// 如果访问了def持久化类容器属性
421-
// 由于没有很好的监测容器类属性内部的变化,这里使用一个折中的办法进行标脏
422-
PropertyDescription* pPropertyDescription = const_cast<ScriptDefModule*>(pScriptModule())->findPersistentPropertyDescription(ccattr);
423-
if (pPropertyDescription && (pPropertyDescription->getFlags() & ENTITY_CELL_DATA_FLAGS) > 0)
424-
{
425-
setDirty();
426-
}
427-
}
428-
*/
429-
free(ccattr);
430-
return ScriptObject::onScriptGetAttribute(attr);
431-
}
432-
433399
//-------------------------------------------------------------------------------------
434400
int EntityComponent::onScriptSetAttribute(PyObject* attr, PyObject* value)
435401
{

kbe/src/server/baseapp/entity_component.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ SCRIPT_GET_DECLARE("client", pyGetClientEntityCall, 0, 0)
2121
SCRIPT_GETSET_DECLARE_END()
2222
BASE_SCRIPT_INIT(EntityComponent, 0, 0, 0, 0, 0)
2323

24+
//-------------------------------------------------------------------------------------
25+
PyObject* EntityComponent::onScriptGetAttribute(PyObject* attr)
26+
{
27+
return ScriptObject::onScriptGetAttribute(attr);
28+
}
29+
2430
}

kbe/src/server/cellapp/entity_component.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
#include "entitydef/entity_component.h"
5+
#include "entity.h"
6+
#include "real_entity_method.h"
57

68
namespace KBEngine{
79

@@ -24,4 +26,45 @@ SCRIPT_GET_DECLARE("otherClients", pyGetOtherClients, 0, 0)
2426
SCRIPT_GETSET_DECLARE_END()
2527
BASE_SCRIPT_INIT(EntityComponent, 0, 0, 0, 0, 0)
2628

29+
//-------------------------------------------------------------------------------------
30+
PyObject* EntityComponent::onScriptGetAttribute(PyObject* attr)
31+
{
32+
wchar_t* PyUnicode_AsWideCharStringRet0 = PyUnicode_AsWideCharString(attr, NULL);
33+
char* ccattr = strutil::wchar2char(PyUnicode_AsWideCharStringRet0);
34+
PyMem_Free(PyUnicode_AsWideCharStringRet0);
35+
36+
if (ownerID_ > 0)
37+
{
38+
Entity* pOwner = static_cast<Entity*>(owner());
39+
40+
if (pOwner)
41+
{
42+
// 如果是ghost调用def方法则需要rpc调用。
43+
if (!pOwner->isReal())
44+
{
45+
MethodDescription* pMethodDescription = const_cast<ScriptDefModule*>(pComponentDescrs_)->findCellMethodDescription(ccattr);
46+
47+
if (pMethodDescription)
48+
{
49+
free(ccattr);
50+
return new RealEntityMethod(pPropertyDescription_, pMethodDescription, pOwner);
51+
}
52+
}
53+
else
54+
{
55+
// 如果访问了def持久化类容器属性
56+
// 由于没有很好的监测容器类属性内部的变化,这里使用一个折中的办法进行标脏
57+
PropertyDescription* pPropertyDescription = const_cast<ScriptDefModule*>(pComponentDescrs_)->findPersistentPropertyDescription(ccattr);
58+
if (pPropertyDescription && (pPropertyDescription->getFlags() & ENTITY_CELL_DATA_FLAGS) > 0)
59+
{
60+
pOwner->setDirty();
61+
}
62+
}
63+
}
64+
}
65+
66+
free(ccattr);
67+
return ScriptObject::onScriptGetAttribute(attr);
68+
}
69+
2770
}

kbe/src/server/dbmgr/entity_component.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ SCRIPT_GET_DECLARE("isDestroyed", pyIsDestroyed, 0, 0)
1313
SCRIPT_GETSET_DECLARE_END()
1414
BASE_SCRIPT_INIT(EntityComponent, 0, 0, 0, 0, 0)
1515

16+
//-------------------------------------------------------------------------------------
17+
PyObject* EntityComponent::onScriptGetAttribute(PyObject* attr)
18+
{
19+
return ScriptObject::onScriptGetAttribute(attr);
20+
}
21+
1622
}

kbe/src/server/tools/kbcmd/entity_component.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ SCRIPT_GET_DECLARE("isDestroyed", pyIsDestroyed, 0, 0)
1313
SCRIPT_GETSET_DECLARE_END()
1414
BASE_SCRIPT_INIT(EntityComponent, 0, 0, 0, 0, 0)
1515

16+
//-------------------------------------------------------------------------------------
17+
PyObject* EntityComponent::onScriptGetAttribute(PyObject* attr)
18+
{
19+
return ScriptObject::onScriptGetAttribute(attr);
20+
}
21+
1622
}

0 commit comments

Comments
 (0)