Example #1
0
void PosUpdateScan::executePlanOperation() {
  auto c_pc = checked_pointer_cast<const PointerCalculator>(input.getTable(0));
  auto c_store = checked_pointer_cast<const storage::Store>(c_pc->getActualTable());

  // Cast the constness away
  auto store = std::const_pointer_cast<storage::Store>(c_store);

  // Get the current maximum size
  const auto& beforSize = store->size();

  // Get the offset for inserts into the delta and the size of the delta that
  // we need to increase by the positions we are inserting
  auto writeArea = store->appendToDelta(c_pc->getPositions()->size());

  // Get the modification record for the current transaction
  auto& txmgr = tx::TransactionManager::getInstance();
  auto& modRecord = txmgr[_txContext.tid];

  // Functor we use for updating the data
  set_json_value_functor fun(store->getDeltaTable());
  storage::type_switch<hyrise_basic_types> ts;

  size_t counter = 0;
  for(const auto& p : *(c_pc->getPositions())) {
    // First delete the old record
    bool deleteOk = store->markForDeletion(p, _txContext.tid) == hyrise::tx::TX_CODE::TX_OK;
    if(!deleteOk) {
      txmgr.rollbackTransaction(_txContext);
      throw std::runtime_error("Aborted TX because TID of other TX found");
    }
    modRecord.deletePos(store, p);
    //store->setTid(p, _txContext.tid);

    // Copy the old row from the main
    store->copyRowToDelta(store, p, writeArea.first+counter, _txContext.tid);
    // Update all the necessary values
    for(const auto& kv : _raw_data) {
      const auto& fld = store->numberOfColumn(kv.first);
      fun.set(fld, writeArea.first+counter, kv.second);
      ts(store->typeOfColumn(fld), fun);
    }

    // Insert the new one
    modRecord.insertPos(store, beforSize+counter);
    ++counter;
  }

  // Update affected rows
  auto rsp = getResponseTask();
  if (rsp != nullptr)
    rsp->incAffectedRows(counter);

  addResult(c_store);
}
void GameObject::updateAbsorptionByPlayer()
{
	if (m_state != OBJECT_ABSORBING) return;
	
	float dE = PLAYER_GAMEOBJECT_ENERGY_ABSORPTION_RATE * m_absorbTimer.time();
	
	//transfer energy to player
	removeEnergy(dE);
	Player::Instance()->giveEnergy(dE);
	if (m_state == OBJECT_ABSORBED)
	{
		markForDeletion();
	}
	
	m_absorbTimer.start();
	return;
}
Example #3
0
void Gibs::rts_update()
{
    life -= ODT;
    if (state < 2)
    {
        angle += angleSpeed * ODT;
        position += Vector2(velocity) * ODT;
        yOffset += velocity.z * ODT;
        velocity.z += 8.f * ODT;
        if (yOffset >= 0.f)
        {
            ++state;
            yOffset = -yOffset * .3f;
            velocity *= .3f;
            velocity.z = -velocity.z;
            angleSpeed *= .5f;
            Globals::pMap->spawnDecal(eFX((int)eFX::FX_DECAL_BLOOD_A + onut::randi(3)), position, 0, .75f);
        }
    }
    if (life < 0) markForDeletion();
}
/**
 * read a set of slice contours from a file
 */
list *readSliceContours(char *filename) {
  list *slices, *slice, *nextSlice;
  contour *cont;
  listNode *sliceNode, *contNode, *adjNode, *lnAdj;
  intNode *in;
  vertex *v;
  char str[10*SR_MAX_STR_LEN];
  double sliceZ;
  int adjIndex;

  /* open the file */
  FILE *fp = fopen(filename,"r");

  /* validate */
  if(fp == NULL) {
    fprintf(stderr,"error: surfIO.c couldn't open the slice contour file %s for reading\n", filename);
    return NULL;
  }

  skipComments(fp,'#');

  /* create the slices */
  slices = newList(LIST);

  /* read the first string */
  fscanf(fp, "slice ");

  /* read the file */
  while(!feof(fp)) {
    /* read the z coordinate */
    fscanf(fp, "%lf", &sliceZ);

    slice = newList(LIST);
    enqueue(slices,slice);

    /* read the next string and test for new slice */
    fscanf(fp, "%s ", str);
    while(!strcmp(str,"contour")) { /* while we are still reading contours */
      cont = createContour();
      enqueue(slice,cont);

      /* read closure state */
      fscanf(fp, "%s", str);
      if(!strcmp(str,"closed")) {
        cont->closed = CLOSED;
      }

      /* read the first string on the next line, test for "adjacent" */
      fscanf(fp, "%s", str);

      while(strcmp(str,"adjacent")) {
        /* create and read this vertex */
        v = createVertex();
        v->x = atof(str);
        fscanf(fp, "%lf", &v->y);
        v->z = sliceZ;

        enqueue(cont->vertices,v);

        fscanf(fp, "%s", str);
      }

      /* read the adjacent contours as ints, convert to pointers later */
      fscanf(fp, "%d", &adjIndex);
      while(adjIndex != -1) {
        /* add this index to the list */
        in = (intNode*) malloc(sizeof(intNode));
        in->val = adjIndex;

        enqueue(cont->adjacentContours,in);

        fscanf(fp, "%d", &adjIndex);
      }

      fscanf(fp, "%s ", str);
    }
  }

  /* resolve the links from the ajacent contour indices */
  for(sliceNode = getListNode(slices,0);
      listSize(slices) > 1 &&((listNode*)sliceNode)->next;
      sliceNode = (listNode*) sliceNode->next) {

    /* get links to this slice list and the next, for searching */
    slice = (list*) sliceNode->data;
    nextSlice = (list*) ((listNode*) ((listNode*)sliceNode)->next)->data;

    /* iterate over the contours in this slice */
    for(contNode = getListNode(slice,0); contNode;
        contNode = (listNode*) contNode->next) {
      cont = (contour*) contNode->data;

      /* iterate over the adjacent contour indices */
      for(adjNode = getListNode(cont->adjacentContours,0); adjNode;
          adjNode = (listNode*) adjNode->next) {

        /* get the index, replace it with a link, or NULL */
        in = (intNode*) adjNode->data;
        lnAdj = getListNode(nextSlice,in->val);
        free(in);

        if(lnAdj == NULL) {
          markForDeletion(adjNode);
        }
        else {
          setListNodeData(adjNode, (void*) lnAdj->data);
        }
      }

      deleteMarkedNodes(cont->adjacentContours);
    }
  }

  fclose(fp);

  return slices;
}
bool DARTCollisionDetector::detectCollision(bool /*_checkAllCollisions*/,
                                            bool /*_calculateContactPoints*/) {
  clearAllContacts();

  // Set all the body nodes are not in colliding
  for (size_t i = 0; i < mCollisionNodes.size(); i++)
    mCollisionNodes[i]->getBodyNode()->setColliding(false);

  std::vector<Contact> contacts;

  for (size_t i = 0; i < mCollisionNodes.size(); i++) {
    for (size_t j = i + 1; j < mCollisionNodes.size(); j++) {
      CollisionNode* collNode1 = mCollisionNodes[i];
      CollisionNode* collNode2 = mCollisionNodes[j];
      dynamics::BodyNode* BodyNode1 = collNode1->getBodyNode();
      dynamics::BodyNode* BodyNode2 = collNode2->getBodyNode();

      if (!isCollidable(collNode1, collNode2))
        continue;

      for (size_t k = 0; k < BodyNode1->getNumCollisionShapes(); k++) {
        for (size_t l = 0; l < BodyNode2->getNumCollisionShapes(); l++) {
          int currContactNum = mContacts.size();

          contacts.clear();
          collide(BodyNode1->getCollisionShape(k),
                  BodyNode1->getTransform()
                  * BodyNode1->getCollisionShape(k)->getLocalTransform(),
                  BodyNode2->getCollisionShape(l),
                  BodyNode2->getTransform()
                  * BodyNode2->getCollisionShape(l)->getLocalTransform(),
                  &contacts);

          size_t numContacts = contacts.size();

          for (unsigned int m = 0; m < numContacts; ++m) {
            Contact contactPair;
            contactPair = contacts[m];
            contactPair.bodyNode1 = BodyNode1;
            contactPair.bodyNode2 = BodyNode2;
            assert(contactPair.bodyNode1 != NULL);
            assert(contactPair.bodyNode2 != NULL);

            mContacts.push_back(contactPair);
          }

          std::vector<bool> markForDeletion(numContacts, false);
          for (size_t m = 0; m < numContacts; m++) {
            for (size_t n = m + 1; n < numContacts; n++) {
              Eigen::Vector3d diff =
                  mContacts[currContactNum + m].point -
                  mContacts[currContactNum + n].point;
              if (diff.dot(diff) < 1e-6) {
                markForDeletion[m] = true;
                break;
              }
            }
          }

          for (int m = numContacts - 1; m >= 0; m--)
          {
            if (markForDeletion[m])
              mContacts.erase(mContacts.begin() + currContactNum + m);
          }
        }
      }
    }
  }

  for (size_t i = 0; i < mContacts.size(); ++i)
  {
    // Set these two bodies are in colliding
    mContacts[i].bodyNode1->setColliding(true);
    mContacts[i].bodyNode2->setColliding(true);
  }

  return !mContacts.empty();
}