@@ -1254,6 +1254,63 @@ static bool loadAllScriptForComponentType(COMPONENT_TYPE loadComponentType)
1254
1254
}
1255
1255
1256
1256
// -------------------------------------------------------------------------------------
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
+
1257
1314
static bool execPython (COMPONENT_TYPE componentType)
1258
1315
{
1259
1316
std::pair<std::wstring, std::wstring> pyPaths = getComponentPythonPaths (componentType);
@@ -1265,18 +1322,8 @@ static bool execPython(COMPONENT_TYPE componentType)
1265
1322
1266
1323
APPEND_PYSYSPATH (pyPaths.second );
1267
1324
1268
- PyObject* kbeModuleOld = PyImport_AddModule (" KBEngine" );
1269
- if (kbeModuleOld == NULL )
1270
- {
1271
- KBE_ASSERT (false );
1272
- return false ;
1273
- }
1274
-
1275
1325
PyObject* modulesOld = PySys_GetObject (" modules" );
1276
1326
1277
- PyObjectPtr entityType (PyObject_GetAttrString (kbeModuleOld, " Entity" ), PyObjectPtr::STEAL_REF);
1278
- PyObjectPtr entityComponentType (PyObject_GetAttrString (kbeModuleOld, " EntityComponent" ), PyObjectPtr::STEAL_REF);
1279
-
1280
1327
PyThreadState* pCurInterpreter = PyThreadState_Get ();
1281
1328
PyThreadState* pNewInterpreter = Py_NewInterpreter ();
1282
1329
@@ -1330,6 +1377,12 @@ static bool execPython(COMPONENT_TYPE componentType)
1330
1377
PyObject* kbeModule = PyImport_AddModule (" KBEngine" );
1331
1378
KBE_ASSERT (kbeModule);
1332
1379
1380
+ Entity::installScript (kbeModule);
1381
+ EntityComponent::installScript (kbeModule);
1382
+
1383
+ if (componentType == BASEAPP_TYPE)
1384
+ Proxy::installScript (kbeModule);
1385
+
1333
1386
const char * componentName = COMPONENT_NAME_EX (componentType);
1334
1387
if (PyModule_AddStringConstant (kbeModule, " component" , componentName))
1335
1388
{
@@ -1342,12 +1395,6 @@ static bool execPython(COMPONENT_TYPE componentType)
1342
1395
// 将模块对象加入main
1343
1396
PyObject_SetAttrString (m, " KBEngine" , kbeModule);
1344
1397
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
-
1351
1398
if (pNewInterpreter != PyThreadState_Swap (pCurInterpreter))
1352
1399
{
1353
1400
KBE_ASSERT (false );
@@ -1358,6 +1405,12 @@ static bool execPython(COMPONENT_TYPE componentType)
1358
1405
1359
1406
bool otherPartSuccess = loadAllScriptForComponentType (componentType);
1360
1407
1408
+ Entity::uninstallScript ();
1409
+ EntityComponent::uninstallScript ();
1410
+
1411
+ if (componentType == BASEAPP_TYPE)
1412
+ Proxy::uninstallScript ();
1413
+
1361
1414
if (pNewInterpreter != PyThreadState_Swap (pCurInterpreter))
1362
1415
{
1363
1416
KBE_ASSERT (false );
0 commit comments