Skip to content

Commit 9afa327

Browse files
committed
Update py_entitydef.cpp
kbengine#612
1 parent 3e3d0c4 commit 9afa327

File tree

1 file changed

+69
-16
lines changed

1 file changed

+69
-16
lines changed

kbe/src/lib/entitydef/py_entitydef.cpp

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,63 @@ static bool loadAllScriptForComponentType(COMPONENT_TYPE loadComponentType)
12541254
}
12551255

12561256
//-------------------------------------------------------------------------------------
1257+
class Entity : public script::ScriptObject
1258+
{
1259+
BASE_SCRIPT_HREADER(Entity, ScriptObject)
1260+
public:
1261+
Entity(PyTypeObject* pyType = getScriptType(), bool isInitialised = true):
1262+
ScriptObject(pyType, isInitialised) {}
1263+
~Entity() {}
1264+
};
1265+
1266+
SCRIPT_METHOD_DECLARE_BEGIN(Entity)
1267+
SCRIPT_METHOD_DECLARE_END()
1268+
1269+
SCRIPT_MEMBER_DECLARE_BEGIN(Entity)
1270+
SCRIPT_MEMBER_DECLARE_END()
1271+
1272+
SCRIPT_GETSET_DECLARE_BEGIN(Entity)
1273+
SCRIPT_GETSET_DECLARE_END()
1274+
BASE_SCRIPT_INIT(Entity, 0, 0, 0, 0, 0)
1275+
1276+
class Proxy : public script::ScriptObject
1277+
{
1278+
BASE_SCRIPT_HREADER(Proxy, ScriptObject)
1279+
public:
1280+
Proxy(PyTypeObject* pyType = getScriptType(), bool isInitialised = true) :
1281+
ScriptObject(pyType, isInitialised) {}
1282+
~Proxy() {}
1283+
};
1284+
1285+
SCRIPT_METHOD_DECLARE_BEGIN(Proxy)
1286+
SCRIPT_METHOD_DECLARE_END()
1287+
1288+
SCRIPT_MEMBER_DECLARE_BEGIN(Proxy)
1289+
SCRIPT_MEMBER_DECLARE_END()
1290+
1291+
SCRIPT_GETSET_DECLARE_BEGIN(Proxy)
1292+
SCRIPT_GETSET_DECLARE_END()
1293+
BASE_SCRIPT_INIT(Proxy, 0, 0, 0, 0, 0)
1294+
1295+
class EntityComponent : public script::ScriptObject
1296+
{
1297+
BASE_SCRIPT_HREADER(EntityComponent, ScriptObject)
1298+
public:
1299+
EntityComponent(PyTypeObject* pyType = getScriptType(), bool isInitialised = true) :
1300+
ScriptObject(pyType, isInitialised) {}
1301+
~EntityComponent() {}
1302+
};
1303+
1304+
SCRIPT_METHOD_DECLARE_BEGIN(EntityComponent)
1305+
SCRIPT_METHOD_DECLARE_END()
1306+
1307+
SCRIPT_MEMBER_DECLARE_BEGIN(EntityComponent)
1308+
SCRIPT_MEMBER_DECLARE_END()
1309+
1310+
SCRIPT_GETSET_DECLARE_BEGIN(EntityComponent)
1311+
SCRIPT_GETSET_DECLARE_END()
1312+
BASE_SCRIPT_INIT(EntityComponent, 0, 0, 0, 0, 0)
1313+
12571314
static bool execPython(COMPONENT_TYPE componentType)
12581315
{
12591316
std::pair<std::wstring, std::wstring> pyPaths = getComponentPythonPaths(componentType);
@@ -1265,18 +1322,8 @@ static bool execPython(COMPONENT_TYPE componentType)
12651322

12661323
APPEND_PYSYSPATH(pyPaths.second);
12671324

1268-
PyObject* kbeModuleOld = PyImport_AddModule("KBEngine");
1269-
if (kbeModuleOld == NULL)
1270-
{
1271-
KBE_ASSERT(false);
1272-
return false;
1273-
}
1274-
12751325
PyObject* modulesOld = PySys_GetObject("modules");
12761326

1277-
PyObjectPtr entityType(PyObject_GetAttrString(kbeModuleOld, "Entity"), PyObjectPtr::STEAL_REF);
1278-
PyObjectPtr entityComponentType(PyObject_GetAttrString(kbeModuleOld, "EntityComponent"), PyObjectPtr::STEAL_REF);
1279-
12801327
PyThreadState* pCurInterpreter = PyThreadState_Get();
12811328
PyThreadState* pNewInterpreter = Py_NewInterpreter();
12821329

@@ -1330,6 +1377,12 @@ static bool execPython(COMPONENT_TYPE componentType)
13301377
PyObject* kbeModule = PyImport_AddModule("KBEngine");
13311378
KBE_ASSERT(kbeModule);
13321379

1380+
Entity::installScript(kbeModule);
1381+
EntityComponent::installScript(kbeModule);
1382+
1383+
if (componentType == BASEAPP_TYPE)
1384+
Proxy::installScript(kbeModule);
1385+
13331386
const char* componentName = COMPONENT_NAME_EX(componentType);
13341387
if (PyModule_AddStringConstant(kbeModule, "component", componentName))
13351388
{
@@ -1342,12 +1395,6 @@ static bool execPython(COMPONENT_TYPE componentType)
13421395
// 将模块对象加入main
13431396
PyObject_SetAttrString(m, "KBEngine", kbeModule);
13441397

1345-
PyModule_AddObject(kbeModule, "EntityComponent", entityComponentType.get());
1346-
PyModule_AddObject(kbeModule, "Entity", entityType.get());
1347-
1348-
if(componentType == BASEAPP_TYPE)
1349-
PyModule_AddObject(kbeModule, "Proxy", entityType.get());
1350-
13511398
if (pNewInterpreter != PyThreadState_Swap(pCurInterpreter))
13521399
{
13531400
KBE_ASSERT(false);
@@ -1358,6 +1405,12 @@ static bool execPython(COMPONENT_TYPE componentType)
13581405

13591406
bool otherPartSuccess = loadAllScriptForComponentType(componentType);
13601407

1408+
Entity::uninstallScript();
1409+
EntityComponent::uninstallScript();
1410+
1411+
if (componentType == BASEAPP_TYPE)
1412+
Proxy::uninstallScript();
1413+
13611414
if (pNewInterpreter != PyThreadState_Swap(pCurInterpreter))
13621415
{
13631416
KBE_ASSERT(false);

0 commit comments

Comments
 (0)