//------------------------------------------------------------------------------------- PyObject* Cellapp::__py_createEntity(PyObject* self, PyObject* args) { PyObject* params = NULL; char* entityType = NULL; SPACE_ID spaceID; PyObject* position, *direction; if(!PyArg_ParseTuple(args, "s|I|O|O|O", &entityType, &spaceID, &position, &direction, ¶ms)) { PyErr_Format(PyExc_TypeError, "KBEngine::createEntity: args is error! args[scriptName, spaceID, position, direction, states]."); PyErr_PrintEx(0); return 0; } if(entityType == NULL || strlen(entityType) == 0) { PyErr_Format(PyExc_TypeError, "KBEngine::createEntity: entityType is NULL."); PyErr_PrintEx(0); return 0; } Space* space = Spaces::findSpace(spaceID); if(space == NULL) { PyErr_Format(PyExc_TypeError, "KBEngine::createEntity: spaceID %ld not found.", spaceID); PyErr_PrintEx(0); return 0; } // 创建entity Entity* pEntity = Cellapp::getSingleton().createEntityCommon(entityType, params, false, 0); if(pEntity != NULL) { Py_INCREF(pEntity); pEntity->setSpaceID(space->getID()); pEntity->initializeEntity(params); pEntity->pySetPosition(position); pEntity->pySetDirection(direction); // 添加到space space->addEntityAndEnterWorld(pEntity); // 有可能在addEntityAndEnterWorld中被销毁了 // 是否能在创建过程中被销毁还需要考虑 if(pEntity->isDestroyed()) { Py_DECREF(pEntity); return NULL; } } //Py_XDECREF(params); return pEntity; }
//------------------------------------------------------------------------------------- void FMH_Baseapp_onEntityGetCellFrom_onCreateInNewSpaceFromBaseapp::process() { KBE_ASSERT(_e != NULL); Space* space = Spaces::findSpace(_spaceID); if(space == NULL) { ERROR_MSG(boost::format("FMH_Baseapp_onEntityGetCell::process: not found space(%1%), %2% %3%.\n") % _spaceID % _e->scriptName() % _e->id()); return; } _e->spaceID(space->id()); _e->initializeEntity(params_); Py_XDECREF(params_); // Ìí¼Óµ½space space->addEntityAndEnterWorld(_e); }
//------------------------------------------------------------------------------------- void FMH_Baseapp_onEntityGetCellFrom_onCreateInNewSpaceFromBaseapp::process() { KBE_ASSERT(_e != NULL); Space* space = Spaces::findSpace(_spaceID); if(space == NULL || !space->isGood()) { ERROR_MSG(fmt::format("FMH_Baseapp_onEntityGetCell::process: not found space({}), {} {}.\n", _spaceID, _e->scriptName(), _e->id())); return; } _e->spaceID(space->id()); _e->initializeEntity(params_); Py_XDECREF(params_); params_ = NULL; // Ìí¼Óµ½space space->addEntityAndEnterWorld(_e); }