Exemple #1
0
// Updates the positions of all objects 
void Physics::update(double update_time){
  int standard_iterations = 20.0;
  double update = update_time/(1.0*standard_iterations);
  
  //Numerical Integration
  for (int i = 0; i < standard_iterations; ++i){

    if (all_.size() > 0) {
      std::list<Physical *>::iterator it = all_.begin();
      while (it != all_.end()) {
        (*it)->acc_ = (*it)->external_forces()/(*it)->m_;
        (*it)->ang_acc_ = (*it)->external_torques()/(*it)->I_;
        ++it;
      }
    }

    collision_prevention();
    check_in_bounds();

    if (all_.size() > 0) {
      std::list<Physical *>::iterator it = all_.begin();
      while (it != all_.end()) {
        integrate_translational(update, *it); 
        if (!(*it)->rotates()) integrate_rotational(update, *it); 
        ++it;
      }
    }
  }
}
Exemple #2
0
/* A limited lookup that searches in a tree of height 2.
 * 
 * prerequisites:
 *   - a tree of height more than 1
 *
 * Decend in the tree using lock coupling with locks taken in
 * read-mode. Stop when you reach a leaf C. Mark the father as
 * F. Search for matches in C then continue into the
 * other children of F. 
 *
 */
static bool mini_lookup_b(
    struct Oc_wu *wu_p,
    Oc_xt_state *s_p,
    Oc_xt_op_lookup_range *lkr_p )    
{
    Oc_xt_node *father_p, *child_p, *hi_p = NULL;
    bool rc;
    
    oc_xt_trace_wu_lvl(
        3, OC_EV_XT_LOOKUP_RNG_MINI, wu_p, "range=[%s]",
        oc_xt_nd_string_of_2key (s_p, lkr_p->min_key_p, lkr_p->max_key_p));

    oc_xt_nd_get_for_read(wu_p, s_p, s_p->root_node_p->disk_addr);

    // 1. base case, this is the root node and the root is a leaf
    if (oc_xt_nd_is_leaf(s_p, s_p->root_node_p))
    {
        rc = search_in_leaf(wu_p, s_p, s_p->root_node_p, lkr_p);
        oc_xt_nd_release(wu_p, s_p, s_p->root_node_p);
        return rc;
    }

    father_p = s_p->root_node_p;

    // iteration
    while (1) {
        int loc_lo, loc_hi;
        uint64 addr;
        struct Oc_xt_key *dummy_key_p;
        
        oc_xt_trace_wu_lvl(3, OC_EV_XT_LOOKUP_RNG_MINI_ITER, wu_p, "");

        // compute the upper and lower bounds
        loc_lo = oc_xt_nd_index_lookup_le_key(wu_p, s_p, father_p, lkr_p->min_key_p);
        loc_hi = oc_xt_nd_index_lookup_ge_key(wu_p, s_p, father_p, lkr_p->min_key_p);
        oc_utl_assert(loc_lo != -1 ||
                      loc_hi != -1);
        if (-1 == loc_lo)
            loc_lo = loc_hi;
        if (-1 == loc_hi)
            loc_hi = loc_lo;

        // start by assuming that the lower-bound is the right direction
        oc_xt_nd_index_get_kth(s_p, father_p, loc_lo, &dummy_key_p, &addr);
        child_p = oc_xt_nd_get_for_read(wu_p, s_p, addr);

        /* If [child_p] contains [min_key_p] then don't bother with the 
         * high bound.
         */
        if (check_in_bounds(s_p, child_p, lkr_p->min_key_p))
            if (hi_p) {
                oc_xt_nd_release(wu_p, s_p, hi_p);
                hi_p = NULL;
            }
        
        if (loc_hi != loc_lo &&
            !check_in_bounds(s_p, child_p, lkr_p->min_key_p))
        {
            /* we are running the risk of missing some search hits.
             * Take a read-lock on the page with the high-bound.
             * Hold on to this page until further notice. 
             */
            oc_xt_trace_wu_lvl(3, OC_EV_XT_LOOKUP_RNG_MINI_SPLIT, wu_p, "");
            if (hi_p)
                oc_xt_nd_release(wu_p, s_p, hi_p);
            oc_xt_nd_index_get_kth(s_p, father_p, loc_hi, &dummy_key_p, &addr);
            hi_p = oc_xt_nd_get_for_read(wu_p, s_p, addr);
        }
        
        // continue descent with [child_p] only

        if (oc_xt_nd_is_leaf(s_p, child_p)) {
            // found a leaf with some keys
            rc = search_in_leaf(wu_p, s_p, child_p, lkr_p);
            oc_xt_nd_release(wu_p, s_p, father_p);
            oc_xt_nd_release(wu_p, s_p, child_p);
            break;
        }

        // release the father
        oc_xt_nd_release(wu_p, s_p, father_p);
        
        // switch places between father and son.
        father_p = child_p;
    }

    if (hi_p) {
        // We might have missed the search so we try the high bound as well.
        rc |= simple_descent_b(wu_p, s_p, hi_p, lkr_p);
    }
    
    return rc;
}