void startBlock(Block *block) { // start block off with no neighbors and all vacant msg2vm(block, CMD_ADD_NCOUNT, block->localTime, 0); int i; for (i=0; i<NUM_PORTS; i++) msg2vm(block, CMD_ADD_VACANT, block->localTime, i); checkForNeighbors(block, NULL); }
void BalloonGoo::update(){ if (isSleeping()) emit checkForNeighbors(getPPosition()); this->moveToTarget(); if (active){ //apply the force to fly body->ApplyForceToCenter(force); body->SetAngularVelocity(0.0); body->SetTransform(body->GetPosition(),0.0); } }
// b: block to check // other: if set, then we only tell b about other's face void checkForNeighbors(Block* b, Block* other) { int i; for(i = 0; i < NUM_PORTS; ++i) { // see if we have a neighbor at port i Block* d = seeIfNeighborAt(b, i); if ((d != 0)&&((other==NULL)||(other==d))) { if (d->neighborhood[i] == NULL) { // we have a neighbor. tell them msg2vm(d, CMD_DEL_VACANT, b->localTime, i); msg2vm(d, CMD_ADD_NBR, b->localTime, b->id, i); if (other == NULL) checkForNeighbors(d, b); msg2vm(d, CMD_ADD_NCOUNT, b->localTime, countNeighbors(d)); d->neighborhood[i] = b; } assert(d->neighborhood[i] == b); } } }