// updateData // update data void CWayPoint::updateData( CSerializable* pObj ) { pObj->nextRecord(); CZone* pZone = (CZone*) getParent(); // next waypoint long id = pObj->readLong(); CGameObject *p = pZone->searchObject( id ); if ( id != -1 && p ) { if ( p && p->getObjectType() == CGameObject::WaypointObject ) { ((CWayPoint*)p)->setBack( this ); setNext( (CWayPoint*)p ); } } else { if ( m_next ) m_next->setBack( NULL ); setNext(NULL); } // prev waypoint id = pObj->readLong(); p = pZone->searchObject( id ); if ( id != -1 && p ) { if ( p && p->getObjectType() == CGameObject::WaypointObject ) { ((CWayPoint*)p)->setNext( this ); setBack( (CWayPoint*)p ); } } else { if ( m_back ) m_back->setNext( NULL ); setBack(NULL); } // wait time m_timeWait = pObj->readLong(); CGameObject::updateData( pObj ); }
CPlayerComponent::~CPlayerComponent() { // unregister collide obj CGameObject *zone = (CGameObject*)m_gameObject->getParent(); if ( zone && zone->getObjectType() == CGameObject::ZoneObject ) ((CZone*)zone)->unRegisterCollideObj( m_gameObject); // unregister event getIView()->unRegisterEvent( this ); }
// init // run when init object void CPlayerComponent::initComponent() { m_collada = (CColladaMeshComponent*)m_gameObject->getComponent( IObjectComponent::ColladaMesh ); // load model by character id CGameConfig::SCharacterInfo *charInfo = CGameConfig::getInstance()->getCharacterInfo(m_charID); // load model m_collada->loadScene(charInfo->model.c_str() ); // load animation CColladaAnimationFactory* animFactory = CColladaAnimationFactory::getInstance(); m_animationPackage = animFactory->getAnimation( charInfo->name.c_str() ); if ( m_animationPackage == NULL ) m_animationPackage = animFactory->loadAnimation( charInfo->name.c_str(), getIView()->getPath(charInfo->anim)); m_collada->setAnimationPackage( m_animationPackage ); // apply lod for (int i = 0, n = (int)charInfo->lods.size(); i < n; i++) m_collada->addLodData( charInfo->lods[i].distance, charInfo->lods[i].node.c_str() ); init(m_gameObject); // register event getIView()->registerEvent("CPlayerComponent", this); // init lua player component char luaObjName[64]; sprintf(luaObjName, "CPlayerComp_%ld", m_gameObject->getID()); m_luaObjName = luaObjName; // init collision ISceneManager *smgr = getIView()->getSceneMgr(); ITriangleSelector *selector = smgr->createTriangleSelectorFromBoundingBox(m_gameObject->getSceneNode()); m_gameObject->getSceneNode()->setTriangleSelector(selector); selector->drop(); CGameObject *zone = (CGameObject*)m_gameObject->getParent(); if ( zone && zone->getObjectType() == CGameObject::ZoneObject ) ((CZone*)zone)->registerCollideObj( m_gameObject); }
bool CHistoryManager::doCreate( SAction* action, bool redo ) { IDoc *pDoc = getIView()->getDocument(); CSerializable *pObject = &action->object1; pObject->setCursorRecord(0); if ( redo == false ) { SSerializableRec *pObjectID = pObject->getProperty("objectID"); if ( pObjectID == NULL ) return false; long objID = -1; sscanf( pObjectID->data, "%ld", &objID ); CGameObject* pObj = pDoc->searchObject( objID ); if ( pObj == NULL ) return false; CZone *pZone = (CZone*) pObj->getParent(); pZone->removeObject( pObj ); } else { SSerializableRec *pParentID = pObject->getProperty("parentID"); SSerializableRec *pObjectTemplate = pObject->getProperty("objectTemplate"); SSerializableRec *pObjectType = pObject->getProperty("objectType"); if ( pParentID == NULL ) return false; long parentID = -1; sscanf( pParentID->data, "%ld", &parentID ); CGameObject* pParent = pDoc->searchObject( parentID ); if ( pParent == NULL ) return false; if ( pParent->getObjectType() != CGameObject::ZoneObject ) return false; CZone *pZone = (CZone*) pParent; wchar_t objTemplate[1024]; uiString::convertUTF8ToUnicode(pObjectTemplate->data, objTemplate); CGameObject *pObj = NULL; if ( strcmp( pObjectType->data, strOfObjType( CGameObject::GameObject ) ) == 0 ) pObj = pZone->createObject( objTemplate ); else if ( strcmp( pObjectType->data, strOfObjType( CGameObject::CameraObject ) ) == 0 ) pObj = pZone->createCamera(); else if ( strcmp( pObjectType->data, strOfObjType( CGameObject::WaypointObject ) ) == 0 ) pObj = pZone->createWaypoint(); else if ( strcmp( pObjectType->data, strOfObjType( CGameObject::TriggerObject ) ) == 0 ) pObj = pZone->createTrigger(); else if ( strcmp( pObjectType->data, strOfObjType( CGameObject::LightObject ) ) == 0 ) pObj = pZone->createLight(); if ( pObj ) { pObj->updateData( pObject ); pZone->setSortObject( true ); } } return true; }