void Troop::kickOut(Pet* pet) { int index = pet->getIndex(); if (index >= cap) return; CCArray* vlink = (CCArray*)vlinks->objectAtIndex(pet->getVLink()); int v = vlink->indexOfObject(pet); vlink->removeObject(pet); while (vlink->count() > v) { Pet* p = (Pet*)vlink->lastObject(); p->setVLink(index + col); vlink->removeLastObject(); ((CCArray*)vlinks->objectAtIndex(index + col))->insertObject(p, 0); } CCArray* hlink = (CCArray*)hlinks->objectAtIndex(pet->getHLink()); int h = hlink->indexOfObject(pet); hlink->removeObject(pet); while (hlink->count() > h) { Pet* p = (Pet*)hlink->lastObject(); p->setHLink(index + 1); hlink->removeLastObject(); ((CCArray*)hlinks->objectAtIndex(index + 1))->insertObject(p, 0); } pets->replaceObjectAtIndex(index, Pet::createFakePet()); }
static void testPoolEfficiency(){ const int test_time = 1; vector<int> ops; int tot=0; for(int i=0;i<test_time;i++){ int op=0; if(tot){ if(rand()%2==0){ op=1; } } if(op) tot--; else tot++; ops.push_back(op); } { LifeCircleLogger logger("use system new"); CCArray *tmp = CCArray::array(); for(int i=0;i<test_time;i++){ if(ops[i]){ tmp->removeLastObject(); }else{ CCSprite *sp = CCSprite::node(); tmp->addObject(sp); } } }{ LifeCircleLogger logger("use MTPool"); CCArray *tmp = CCArray::array(); for(int i=0;i<test_time;i++){ if(ops[i]){ tmp->removeLastObject(); }else{ CCSprite *sp = MTPoolManager::sharedManager()->getObject(sp); tmp->addObject(sp); } } }{ LifeCircleLogger logger("use boost Pool"); CCArray *tmp = CCArray::array(); for(int i=0;i<test_time;i++){ if(ops[i]){ tmp->removeLastObject(); }else{ CCSprite *sp =spritePool.construct(); tmp->addObject(sp); } } } }