Example #1
0
dstrlist* dsplit(const dstring* text, const dstring* on, size_t max) {
	dstrlist* result = dlist_new();
	int slen = on->len;
	unsigned int i, j, k = 0;

	if (max == 1) {
		dlist_add(result, text);
		return result;
	} else if (max <= 0) {
		max = text->len;
	}

	j = 0;
	i = dpos(text, on, 0);
	while(i != -1) {
		dlist_push(result, dsub(text, j, i - j));
		k++;
		j = i + slen;
		if (k + 1 == max) {
			dlist_push(result, dsub(text, j, text->len - j));
			return result;
		}
		i = dpos(text, on, j);
	}
	dlist_push(result, dsub(text, j, text->len - j));

	return result;
}
Example #2
0
void ai::Herd::calculateV(v2<float> &velocity, Object *sheep, const int leader, const float distance) {
	bool was_stopped = velocity.is0();
	velocity.clear();
	
	std::set<const Object *> o_set;
	World->enumerate_objects(o_set, sheep, distance, NULL);
	int n = 0;
	for(std::set<const Object *>::iterator i = o_set.begin(); i != o_set.end(); ++i) {
		const Object *o = *i;
		if (o->impassability == 0 || (leader && o->get_summoner() != leader)) 
			continue;
		int cd = getComfortDistance(o);
		if (cd == -1)
			continue;
			
		v2<float> pos = sheep->get_relative_position(o);
		float r = pos.length();
		if (r < 0.001) r = 0.001;
		if (pos.quick_length() < cd * cd)
			velocity -= pos / r;
		else 
			velocity += pos / r;
		
		++n;
	}
	const v2<int> tile_size = Map->getPathTileSize();
	v2<int> pos = sheep->get_center_position().convert<int>() / tile_size;
	
	const Matrix<int> &hint = Map->getAreaMatrix(sheep->registered_name);

	GET_CONFIG_VALUE("objects.ai.hint-gravity", float, hgc, 10.0f);
	v2<int> size = v2<int>((int)distance, (int)distance * 4 / 3) / tile_size / 2;
	for(int y = -size.y; y <= size.y; ++y) 
		for(int x = -size.x; x < size.x; ++x) {
			if (hint.get(pos.y + y, pos.x + x)) {
				v2<float> dpos(x, y);
				//LOG_DEBUG(("%d:%s %g %g, %g", sheep->get_id(), sheep->registered_name.c_str(), dpos.x, dpos.y, dpos.length()));
				float r = dpos.normalize();
				velocity += dpos * hgc / r;
			}
		}
		
	const Object * o = leader?World->getObjectByID(leader): NULL;
	if (o != NULL && !ZBox::sameBox(o->get_z(), sheep->get_z())) 
		o = NULL;
	
	if (o != NULL) {
		//LOG_DEBUG(("leader: %p", o));
		v2<float> pos = sheep->get_relative_position(o);
		int cd = getComfortDistance(NULL);
		if (pos.quick_length() < cd * cd)
			velocity -= pos;
		else 
			velocity += pos * n;
	}
	float v = velocity.normalize();

	if (v < (was_stopped?0.5:0.0001)) 
		velocity.clear();
}
// Configure
bool UIMirrorOverlay::configure(hwc_context_t *ctx, hwc_layer_1_t *layer)
{
    if (LIKELY(ctx->mOverlay[HWC_DISPLAY_EXTERNAL])) {
        overlay::Overlay& ov = *(ctx->mOverlay[HWC_DISPLAY_EXTERNAL]);
        // Set overlay state
        ov.setState(sState);
        private_handle_t *hnd = (private_handle_t *)layer->handle;
        if (!hnd) {
            ALOGE("%s:NULL private handle for layer!", __FUNCTION__);
            return false;
        }
        ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);
        // Determine the RGB pipe for UI depending on the state
        ovutils::eDest dest = ovutils::OV_PIPE0;

        ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
        if(ctx->mSecureMode) {
            ovutils::setMdpFlags(mdpFlags,
                    ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
        }

        ovutils::PipeArgs parg(mdpFlags,
                info,
                ovutils::ZORDER_0,
                ovutils::IS_FG_OFF,
                ovutils::ROT_FLAG_DISABLED);
        ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
        ov.setSource(pargs, dest);

        hwc_rect_t sourceCrop = layer->sourceCrop;
        // x,y,w,h
        ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
                sourceCrop.right - sourceCrop.left,
                sourceCrop.bottom - sourceCrop.top);
        ov.setCrop(dcrop, dest);

        int transform = layer->transform;
        ovutils::eTransform orient =
                static_cast<ovutils::eTransform>(transform);
        ov.setTransform(orient, dest);

        hwc_rect_t displayFrame = layer->displayFrame;
        ovutils::Dim dpos(displayFrame.left,
                displayFrame.top,
                displayFrame.right - displayFrame.left,
                displayFrame.bottom - displayFrame.top);
        ov.setPosition(dpos, dest);

        if (!ov.commit(dest)) {
            ALOGE("%s: commit fails", __FUNCTION__);
            sIsUiMirroringOn = false;
            return false;
        }
        sIsUiMirroringOn = true;
    }
    return sIsUiMirroringOn;
}
inline object_info_ptr create_rocket_flare(kernel::system* csys, create_msg const& msg)
{
    decart_position dpos(msg.pos,msg.orien);
    geo_position gp(dpos, get_base());

    rocket_flare::settings_t vs;

    return rocket_flare::create(dynamic_cast<objects_factory*>(csys),vs,gp);
}
Example #5
0
GP<DjVuFile>
lt_XMLParser::Impl::get_file(const GURL &url,GUTF8String id)
{
  GP<DjVuFile> dfile;
  GP<DjVuDocument> doc;
  GCriticalSectionLock lock(&xmlparser_lock);
  {
    GPosition pos=m_docs.contains(url.get_string());
    if(pos)
    {
      doc=m_docs[pos];
    }else
    {
      doc=DjVuDocument::create_wait(url);
      if(! doc->wait_for_complete_init())
      {
        G_THROW(( ERR_MSG("XMLAnno.fail_init") "\t")+url.get_string() );
      }
      m_docs[url.get_string()]=doc;
    }
    if(id.is_int())
    {
      const int xpage=id.toInt(); //atoi((char const *)page); 
      if(xpage>0)
        id=doc->page_to_id(xpage-1);
    }else if(!id.length())
    { 
      id=doc->page_to_id(0);
    }
  }
  const GURL fileurl(doc->id_to_url(id));
  GPosition dpos(m_files.contains(fileurl.get_string()));
  if(!dpos)
  {
    if(!doc->get_id_list().contains(id))
    {
      G_THROW( ERR_MSG("XMLAnno.bad_page") );
    }
    dfile=doc->get_djvu_file(id,false);
    if(!dfile)
    {
      G_THROW( ERR_MSG("XMLAnno.bad_page") );
    }
    m_files[fileurl.get_string()]=dfile;
  }else
  {
    dfile=m_files[dpos];
  }
  return dfile;
}
Example #6
0
bool GNC::GCS::Widgets::WRule::HitTest(float x, float y, const GNC::GCS::Vector& rel)
{
        bool hits = false;

        GNC::GCS::Vector dpos(x,y);
        if ( m_Vertices[0].DistanciaEuclideaCuadrado(m_Vertices[1]) / 4.0f > dpos.DistanciaEuclideaCuadrado(m_Vertices[0].PuntoMedio(m_Vertices[1]))) {

                GNC::GCS::Vector vdir = m_Vertices[1] - m_Vertices[0];
                GNC::GCS::Vector orto = (vdir / rel).VectorOrtogonal() * rel;

                GNC::GCS::Vector inter = GNC::GCS::Vector::InterseccionEntreRectas(dpos, dpos + orto, m_Vertices[0], m_Vertices[1]);
                GNC::GCS::Vector diff = (inter - dpos).ValorAbsoluto();
                if ( (diff / rel).Norma2Cuadrado() < (m_Vertices[0].m_Size * m_Vertices[0].m_Size) ) {
                        hits = true;
                }
        }
        return hits;
}
Example #7
0
void MolDraw2DSVG::addMoleculeMetadata(const ROMol &mol, int confId) const {
  PRECONDITION(d_os, "no output stream");
  d_os << "<metadata>" << std::endl;
  d_os << "<rdkit:mol"
       << " xmlns:rdkit = \"http://www.rdkit.org/xml\""
       << " version=\"" << RDKIT_SVG_VERSION << "\""
       << ">" << std::endl;
  for (const auto atom : mol.atoms()) {
    d_os << "<rdkit:atom idx=\"" << atom->getIdx() + 1 << "\"";
    bool doKekule = false, allHsExplicit = true, isomericSmiles = true;
    d_os << " atom-smiles=\""
         << SmilesWrite::GetAtomSmiles(atom, doKekule, nullptr, allHsExplicit,
                                       isomericSmiles)
         << "\"";
    auto tag = boost::str(boost::format("_atomdrawpos_%d") % confId);

    const Conformer &conf = mol.getConformer(confId);
    RDGeom::Point3D pos = conf.getAtomPos(atom->getIdx());

    Point2D dpos(pos.x, pos.y);
    if (atom->hasProp(tag))
      dpos = atom->getProp<Point2D>(tag);
    else
      dpos = getDrawCoords(dpos);
    d_os << " drawing-x=\"" << dpos.x << "\""
         << " drawing-y=\"" << dpos.y << "\"";
    d_os << " x=\"" << pos.x << "\""
         << " y=\"" << pos.y << "\""
         << " z=\"" << pos.z << "\"";

    d_os << " />" << std::endl;
  }
  for (const auto bond : mol.bonds()) {
    d_os << "<rdkit:bond idx=\"" << bond->getIdx() + 1 << "\"";
    d_os << " begin-atom-idx=\"" << bond->getBeginAtomIdx() + 1 << "\"";
    d_os << " end-atom-idx=\"" << bond->getEndAtomIdx() + 1 << "\"";
    bool doKekule = false, allBondsExplicit = true;
    d_os << " bond-smiles=\""
         << SmilesWrite::GetBondSmiles(bond, -1, doKekule, allBondsExplicit)
         << "\"";
    d_os << " />" << std::endl;
  }
  d_os << "</rdkit:mol></metadata>" << std::endl;
}
void scene_view::set_focus(std::string group, int idx)
{
    object *o = 0;
    if (group == "objects" && idx < m_objects.size())
        o = &m_objects[idx];
    else if (group == "player spawn")
        o = &m_player;

    if (!o)
        return;

    nya_math::vec2 dpos(0.0f, 100.0f);
    dpos.rotate(m_camera_yaw);

    m_camera_pos = o->pos + nya_math::vec3(dpos.x, o->y + 50.0, dpos.y);
    m_camera_pitch = 30;

    update();
}
/// Smearing function
StatusCode GaussSmearVertex::smearVertex(HepMC::GenEvent& theEvent) {

  double dx = m_gaussDist() * sqrt(m_xsig) + m_xmean;
  double dy = m_gaussDist() * sqrt(m_ysig) + m_ymean;
  double dz = m_gaussDist() * sqrt(m_zsig) + m_zmean;
  double dt = m_gaussDist() * sqrt(m_tsig) + m_tmean;

  Gaudi::LorentzVector dpos(dx, dy, dz, dt);

  debug() << "Smearing vertices by " << dpos << endmsg;

  for (auto vit = theEvent.vertices_begin(); vit != theEvent.vertices_end(); ++vit) {
    Gaudi::LorentzVector pos((*vit)->position());
    pos += dpos;
    (*vit)->set_position(HepMC::FourVector(pos.x(), pos.y(), pos.z(), pos.t()));
  }

  return StatusCode::SUCCESS;
}
Example #10
0
//=============================================================================
// Smearing function
//=============================================================================
StatusCode FlatSmearVertex::smearVertex( HepMC::GenEvent * theEvent ) {
  double dx , dy , dz , dt ;
  
  dx = m_xmin + m_flatDist( ) * ( m_xmax - m_xmin ) ;
  dy = m_ymin + m_flatDist( ) * ( m_ymax - m_ymin ) ;
  dz = m_zmin + m_flatDist( ) * ( m_zmax - m_zmin ) ;
  dt = m_zDir * dz/Gaudi::Units::c_light ;

  Gaudi::LorentzVector dpos( dx , dy , dz , dt ) ;
  
  debug() << "Smearing vertices by " << dpos << endmsg;

  for (auto vit = theEvent->vertices_begin(); vit != theEvent->vertices_end(); ++vit ) {
    Gaudi::LorentzVector pos ( (*vit) -> position() ) ;
    pos += dpos ;
    (*vit)->set_position( HepMC::FourVector(pos.x(), pos.y(), pos.z(), pos.t() ) ) ;
  }

  return StatusCode::SUCCESS ;      
}
Example #11
0
void PltWin::mousePressEvent(QMouseEvent * event)
{
  DVector dpos(2), ubat;
  IVector at;
  FILE *f;
  double mindsq, dsq, xworld, yworld, ubmin, ubmax;
  int x, y, n, apick, nat, i;
  bool ok;

  if (event->button() == Qt::LeftButton && clickAtoms) {
    if (NInit == 0) return;
    x = event->x();
    y = event->y();
    apick = 0;
    mindsq = 1e20;
    for (n=1; n<=NInit; n++) {
      if (!zLayerSel(zLayer(n))) continue;
      dsq = pow(atomScreen(n,1)-x,2) + pow(atomScreen(n,2)-y,2);
      if (dsq < mindsq) {
	apick = n;
	mindsq = dsq;
      }
    }
    napicked++;
    apicked(napicked) = apick;
    repaint();

    if (napicked==2 && doAfterMouseClicks == CALC_DPOS_PEIERLSNABARRO)
      emit signalDPosPeierlsNabarro_interm();
  }

  if (event->button() == Qt::RightButton && clickAtoms) {
    if (napicked > 0) {
      apicked(napicked) = 0;
      napicked--;
      repaint();
    }
  }
}
void vsx_widget_profiler_thread::draw_tags()
{
  font.color.r = 1.0;
  font.color.g = 1.0;
  font.color.b = 1.0;
  font.color.a = 1.0;

  for (size_t i = 0; i < tag_draw_chunks.size(); i++)
  {
    float chunk_depth = (float)(tag_draw_chunks[i]->depth + 1);
    vsx_vector3<> dpos(
          tag_draw_chunks[i]->time_start * time_scale::get_instance()->time_scale_x + time_scale::get_instance()->time_offset,
          -chunk_depth * chunk_height - 0.005
    );
    //vsx_vector3_helper::dump<float>(dpos);
    font.print( dpos, tag_draw_chunks[i]->tag, 0.005 );
    dpos.y -= 0.005;
    font.print( dpos, vsx_string_helper::i2s(tag_draw_chunks[i]->cycles_end-tag_draw_chunks[i]->cycles_start) + " CPU cycles", 0.005 );
    dpos.y -= 0.005;
    font.print( dpos, vsx_string_helper::f2s(tag_draw_chunks[i]->time_end - tag_draw_chunks[i]->time_start) + " seconds", 0.005 );
  }
  profiler->sub_end();
}
Example #13
0
void SimplexDemo::displayCallback()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glDisable(GL_LIGHTING);

    GL_ShapeDrawer::drawCoordSystem();

    btScalar m[16];
    int i;

    btVector3 worldBoundsMin(-1000,-1000,-1000);
    btVector3 worldBoundsMax(1000,1000,1000);

    for (i=0; i<numObjects; i++)
    {
        btTransform transA;
        transA.setIdentity();
        btVector3	dpos(0.f,5.f,0.f);
        transA.setOrigin( dpos );
        btQuaternion orn;
        orn.setEuler(yaw,pitch,roll);
        transA.setRotation(orn);
        transA.getOpenGLMatrix( m );

        /// draw the simplex
        m_shapeDrawer.drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode(),worldBoundsMin,worldBoundsMax);

        /// calculate closest point from simplex to the origin, and draw this vector
        simplex.calcClosest(m);

    }
    pitch += 0.005f;
    yaw += 0.01f;

    glFlush();
    glutSwapBuffers();
}
static void onMouseMove(GLFWwindow* window, double xpos, double ypos)
{
	// AntTweakBar event
	if (TwEventMousePosGLFW(int(xpos), int(ypos)))
		return;

	glm::vec2 dpos(xpos - s_prevXPos, s_prevYPos - ypos);

	// Drag mesh
	if (g_drag){
		g_drag->second += 0.01f * glm::vec3(dpos, 0);
	}

	// Camera control
	if (s_camera.getMode() == CameraMode::ARC){
		s_camera.rotate(dpos);
	}
	else if (s_camera.getMode() == CameraMode::PAN){
		s_camera.pan(dpos);
	}	

	s_prevXPos = xpos;
	s_prevYPos = ypos;
}
Example #15
0
void simulateGeometry(size_t frameRate,
                      double minRadius, // in mm
                      double maxRadius, // in mm
                      double simDuration, // in seconds
                      size_t numBubbles, // over lifetime of simulation
                      const std::string &outputDir) {
 
  std::vector<FakeBubbleStats> bubbleStats(numBubbles);
  std::vector<Bubble *> bubbles(numBubbles);
  
  size_t numFrames = ceil(frameRate * simDuration);
  double dt = 1.0 / double(frameRate);
  
  // initialize random bubble stats
  for (size_t i = 0; i < numBubbles; i++) {
    bubbleStats[i].bubbleBirthtime = random_double(0.02, simDuration * 0.95);
    bubbleStats[i].bubbleRadius = random_double(minRadius, maxRadius);
    std::cout << "bubbleRadius: " << bubbleStats[i].bubbleRadius << std::endl;
    
    bubbleStats[i].isBubbleBorn = false;
    bubbleStats[i].isBubbleDead = false;
  }
  
  // initialize bubble objects
  for (size_t i = 0; i < numBubbles; i++) {
    bubbles[i] = new Bubble();
    TriangleMesh *currBubble = new TriangleMesh;
    
    // yep, for now a different copy of each
    currBubble->read(baseDir + "bubble_lr.obj", MFF_OBJ);
    
    // constant is here because starting size of bubbles is 5mm radius
    double ds = bubbleStats[i].bubbleRadius / 5.0;
    
    currBubble->scale(Vector3d(ds, ds, ds));
    
    double dx = random_double(-0.05, +0.05);
    double dz = random_double(-0.05, +0.05);
    Vector3d dpos(dx,0,dz);
    //currBubble->translate(dpos);  // TODO: uncomment this line to randomizing starting position
    
    bubbles[i]->setBubbleMesh(currBubble);
    
  }
  
  std::string solidPrefix = "solid_";
  std::string airPrefix = "air_";
  std::string bubblePrefix = "bubble_";
  
  for (size_t f = 0; f < numFrames; f++) {
    
    double currTime = f * dt;
    
    std::string zeropadFrameNum = ZeroPadNumber(f, 6);

    // add a bit of random vertical motion to the fluid surface
    //airMesh->jitter(Vector3d(0,0.0005,0));
    
    solidMesh->write(outputDir + solidPrefix + zeropadFrameNum + ".obj", MFF_OBJ);
    airMesh->write(outputDir + airPrefix + zeropadFrameNum + ".obj", MFF_OBJ);
    
    // advect all the bubbles for each timestep
    for (size_t b = 0; b < numBubbles; b++) {
      
      if (bubbleStats[b].bubbleBirthtime <= currTime) {
        bubbleStats[b].isBubbleBorn = true;
      }
      
      
      // check whether bubble has peeked above the surface
      if (bubbleStats[b].isBubbleBorn && !bubbleStats[b].isBubbleDead) {
        BoundingBox airbbox, bubbbox;
        airMesh->getBoundingBox(airbbox);
        bubbles[b]->getBubbleMesh()->getBoundingBox(bubbbox);
        
        // rough crappy rule of thumb
        if (bubbbox.GetBoxmax().y() > airbbox.GetBoxmax().y()) {
          // KILL THE BUBBLE!
          bubbleStats[b].isBubbleDead = true;
        }
      }
      
      
      if (bubbleStats[b].isBubbleBorn && !bubbleStats[b].isBubbleDead) {
        
        std::string zeropadBubbleNum = ZeroPadNumber(b, 6);
        bubbles[b]->getBubbleMesh()->write(outputDir + bubblePrefix + zeropadBubbleNum + "_" + zeropadFrameNum + ".obj", MFF_OBJ);
        bubbles[b]->timestep(dt);
      }
      
      
    }
    
    
    
  }
}
Example #16
0
void AppWin::calcDPosPeierlsNabarro_interm()
{
  int icurr = tabWidget->currentIndex();
  PltWin *pwthis = plotWidget[icurr];
  PltWin *pw;
  FILE *f;
  DVector ubat, dpos(2);
  IVector at;
  double ubmin, ubmax;
  int i, istart, iend, nat, j;
  bool ok;

  //  if (pwthis->nchain==0) {
  //    f = fopen("ub_pos.dat", "w+");
  //    fclose(f);
  //  }

  if (pwthis->applyHow==0)
    istart = iend = icurr;
  else {
    istart = 0;
    iend = tabWidget->count()-1;
  }

  at.Allocate(30); at.EnlargeStep(10);
  ubat.Allocate(30); ubat.EnlargeStep(10);  

  for (i=istart; i<=iend; i++) {
    pw = plotWidget[i];
    if (!pw->isSelected) continue;

    if (i != icurr) {
      pw->applyHow = pwthis->applyHow;
      pw->napicked = pwthis->napicked;
      pw->apicked = pwthis->apicked;
    }

    ok = findDPosPeierlsNabarro(pw, dpos, nat, at, ubat, ubmin, ubmax);
    if (!ok) {
      msgError(err_DPosPeierlsNabarro);
      at.Free();
      ubat.Free();
      pw->napicked = 0;
      pwthis->repaint();
      return;
    }

    if (pw->nchain == 0) {
      pw->dposchain.Allocate(6,2); pw->dposchain.EnlargeStep(2,0);
      pw->nachain.Allocate(6); pw->nachain.EnlargeStep(2);
      pw->achain.Allocate(6,30); pw->achain.EnlargeStep(2,10);
      pw->ubchain.Allocate(6,30); pw->ubchain.EnlargeStep(2,10);
      pw->ubchain_min.Allocate(6); pw->ubchain_min.EnlargeStep(2);
      pw->ubchain_max.Allocate(6); pw->ubchain_max.EnlargeStep(2);
    }

    pw->nchain++;
    pw->dposchain(pw->nchain,1) = dpos(1);
    pw->dposchain(pw->nchain,2) = dpos(2);
    pw->nachain(pw->nchain) = nat;
    pw->ubchain_min(pw->nchain) = ubmin;
    pw->ubchain_max(pw->nchain) = ubmax;
    for (j=1; j<=nat; j++) {
      pw->achain(pw->nchain,j) = at(j);
      pw->ubchain(pw->nchain,j) = ubat(j);
    }

    pw->napicked = 0;
  }

  at.Free();
  ubat.Free();
  pwthis->repaint();
}
Example #17
0
int main(int argc, char* argv[]) {
	dstring *s1, *s2, *s3, *s4, *s5, *s6;
	
	/* dstring* dnew(); */
	test_start("dnew()");
	s1 = dnew();
	test_assert(s1 != NULL);
	test_assert(s1->data != NULL);
	test_assert(s1->size > 0);
	test_assert(s1->len == 0);
	test_assert(s1->data[0] == 0);
	test_end();
	
	/* dstring* dnewcopy(const dstring* str); */
	test_start("dnewcopy()");
	s2 = dnewcopy(s1);
	test_assert(s2 != NULL);
	test_assert(s2->data != NULL);
	test_assert(s2->size > 0);
	test_assert(s2->len == 0);
	test_assert(s2->data[0] == 0);
	s1->data[0] = 'A';
	s1->data[1] = 0;
	s1->len = 1;
	dfree(s2);
	s2 = dnewcopy(s1);
	test_assert(s2->len == 1);
	test_assert(strcmp(s1->data, s2->data) == 0);
	test_end();
	
	/* void dfree(dstring* str); */
	test_start("dfree()");
	dfree(s1);
	dfree(s2);
	test_assert(1);
	test_end();
	
	/* dstring* dfromc(int chr); */
	test_start("dfromc()");
	s1 = dfromc('X');
	test_assert(s1 != NULL);
	test_assert(s1->len == 1);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "X") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dfromcs(const char* str); */
	test_start("dfromcs()");
	s1 = dfromcs("Hello World!");
	test_assert(s1 != NULL);
	test_assert(s1->len == 12);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dfrommem(const void* mem, size_t size); */
	test_start("dfrommem()");
	s1 = dfrommem("Hello World!", 12);
	test_assert(s1 != NULL);
	test_assert(s1->len == 12);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dcpy(dstring* dst, const dstring* src); */
	test_start("dcpy()");
	s1 = dfromcs("Hello ");
	s2 = dfromcs("World!!!");
	s3 = dcpy(s1, s2);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 8);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "World!!!") == 0);
	dfree(s1);
	dfree(s2);
	test_end();
	
	/* dstring* dcpyc(dstring* dst, int src); */
	test_start("dcpyc()");
	s1 = dfromcs("Hello");
	s2 = dcpyc(s1, '!');
	
	test_assert(s2 == s1);
	test_assert(s1->len == 1);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "!") == 0);
	dfree(s1);
	test_end();

	/* dstring* dcpycs(dstring* dst, const char* src); */
	test_start("dcpycs");
	s1 = dfromcs("Hello");
	s2 = dcpycs(s1, "Hola!");
	
	test_assert(s2 == s1);
	test_assert(s1->len == 5);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Hola!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dcpymem(dstring* dst, const void* mem, size_t size); */
	test_start("dcpymem");
	s1 = dfromcs("Hello");
	s2 = dcpymem(s1, "Foo!", 4);
	
	test_assert(s2 == s1);
	test_assert(s1->len == 4);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Foo!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dncpy(dstring* dst, const dstring* src, dstrlen_t n); */
	test_start("dncpy");
	s1 = dfromcs("Hello");
	s2 = dfromcs("World!");
	s1 = dncpy(s1, s2, 5);
	
	test_assert(s1->len == 5);
	test_assert(strcmp(s1->data, "World") == 0);
	
	s1 = dncpy(s1, s2, 20);
	test_assert(s1->len == 6);
	test_assert(strcmp(s1->data, "World!") == 0);
	
	dfree(s1);
	dfree(s2);
	test_end();
	
	/* dstring* dncpycs(dstring* dst, const char* src, dstrlen_t n); */
	test_start("dncpycs");
	s1 = dfromcs("Hello");
	s1 = dncpycs(s1, "World!", 5);
	
	test_assert(s1->len == 5);
	test_assert(strcmp(s1->data, "World") == 0);
	
	s1 = dncpycs(s1, "World!", 20);
	test_assert(s1->len == 6);
	test_assert(strcmp(s1->data, "World!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dcat(dstring* dst, const dstring* src); */
	test_start("dcat");
	s1 = dfromcs("Hello ");
	s2 = dfromcs("World!");
	s3 = dcat(s1, s2);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 12);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	
	dfree(s1);
	dfree(s2);
	test_end();
	
	/* dstring* dcatc(dstring* dst, int src); */
	test_start("dcatc");
	s1 = dfromcs("Hello");
	s3 = dcatc(s1, '!');
	
	test_assert(s1 == s3);
	test_assert(s1->len == 6);
	test_assert(strcmp(s1->data, "Hello!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dcatcs(dstring* dst, const char* src); */
	test_start("dcatcs");
	s1 = dfromcs("Hello ");
	s3 = dcatcs(s1, "World!");
	
	test_assert(s1 == s3);
	test_assert(s1->len == 12);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dcatmem(dstring* dst, const void* src, size_t size); */
	test_start("dcatmem");
	s1 = dfromcs("Hello ");
	s3 = dcatmem(s1, "Guys!", 5);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 11);
	test_assert(strcmp(s1->data, "Hello Guys!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dncat(dstring* dst, const dstring* src, dstrlen_t n); */
	test_start("dncat");
	s2 = dfromcs("Guys!");
	s1 = dfromcs("Hello ");
	s3 = dncat(s1, s2, 4);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 10);
	test_assert(strcmp(s1->data, "Hello Guys") == 0);
	dfree(s1);
	
	s1 = dfromcs("Hello ");
	s3 = dncat(s1, s2, 8);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 11);
	test_assert(strcmp(s1->data, "Hello Guys!") == 0);
	dfree(s1);
	
	dfree(s2);
	test_end();
	
	/* dstring* dncatcs(dstring* dst, const char* src, dstrlen_t n); */
	test_start("dncatcs");
	s1 = dfromcs("Hello ");
	s3 = dncatcs(s1, "Guys!", 4);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 10);
	test_assert(strcmp(s1->data, "Hello Guys") == 0);
	dfree(s1);
	
	s1 = dfromcs("Hello ");
	s3 = dncatcs(s1, "Guys!", 8);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 11);
	test_assert(strcmp(s1->data, "Hello Guys!") == 0);
	dfree(s1);
	test_end();
	
	/* int dcmp(const dstring* a, const dstring* b); */
	test_start("dcmp");
	s1 = dfromcs("ddd");
	s2 = dfromcs("aaa");
	s3 = dfromcs("zzz");
	s4 = dfromcs("bo");
	s5 = dfromcs("aaaa");
	s6 = dfromcs("ddd");
	
	test_assert(dcmp(s1, s2) != 0);
	test_assert(dcmp(s1, s3) != 0);
	test_assert(dcmp(s1, s4) != 0);
	test_assert(dcmp(s1, s5) != 0);
	test_assert(dcmp(s1, s6) == 0);
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	dfree(s4);
	dfree(s5);
	dfree(s6);
	test_end();
	
	/* int dcmpc(const dstring* a, int b); */
	test_start("dcmpc");
	s1 = dfromc('X');
	test_assert(dcmpc(s1, 'a') != 0);
	test_assert(dcmpc(s1, 'x') != 0);
	test_assert(dcmpc(s1, 'X') == 0);
	dfree(s1);
	test_end();
	
	/* int dcmpcs(const dstring* a, const char* b); */
	test_start("dcmpcs");
	s1 = dfromcs("Foo");
	test_assert(dcmpcs(s1, "FO") != 0);
	test_assert(dcmpcs(s1, "barr") != 0);
	test_assert(dcmpcs(s1, "Foo") == 0);
	dfree(s1);
	test_end();
	
	/* int dcmpmem(const dstring* a, const void* b, size_t size); */
	test_start("dcmpmem");
	s1 = dfromcs("Foo");
	test_assert(dcmpmem(s1, "FO", 2) != 0);
	test_assert(dcmpmem(s1, "barr", 4) != 0);
	test_assert(dcmpmem(s1, "Foo", 3) == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dsub(const dstring* a, dstrlen_t start, dstrlen_t length); */
	test_start("dsub");
	s1 = dfromcs("hello world!");
	s2 = dsub(s1, 0, 5);
	s3 = dsub(s1, 6, 6);
	s4 = dsub(s1, 6, 12);
	s5 = dsub(s1, 20, 10);
	
	test_assert(dcmpcs(s2, "hello") == 0);
	test_assert(dcmpcs(s3, "world!") == 0);
	test_assert(dcmpcs(s4, "world!") == 0);
	test_assert(dcmpcs(s5, "") == 0);
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	dfree(s4);
	dfree(s5);
	test_end();
	
	/* int dstartswith(const dstring* a, const dstring* b); */
	test_start("dstartswith");
	s1 = dfromcs("Is this ok?");
	s2 = dfromcs("Is");
	s3 = dfromcs("bla");
	
	test_assert(dstartswith(s1, s2));
	test_assert(!dstartswith(s1, s3));
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	test_end();
	
	/* int dstartswithc(const dstring* a, int b); */
	test_start("dstartswithc");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dstartswithc(s1, 'I'));
	test_assert(!dstartswithc(s1, 'O'));
	
	dfree(s1);
	test_end();
	
	/* int dstartswithcs(const dstring* a, const char* b); */
	test_start("dstartswithcs");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dstartswithcs(s1, "Is"));
	test_assert(!dstartswithcs(s1, "is"));
	
	dfree(s1);
	test_end();
	
	/* int dendswith(const dstring* a, const dstring* b); */
	test_start("dendswith");
	s1 = dfromcs("Is this ok?");
	s2 = dfromcs("ok?");
	s3 = dfromcs("Ok?");
	
	test_assert(dendswith(s1, s2));
	test_assert(!dendswith(s1, s3));
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	test_end();
	
	/* int dendswithc(const dstring* a, int b); */
	test_start("dendswithc");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dendswithc(s1, '?'));
	test_assert(!dendswithc(s1, '!'));
	
	dfree(s1);
	test_end();
	
	/* int dendswithcs(const dstring* a, const char* b); */
	test_start("dendswithcs");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dendswithcs(s1, "ok?"));
	test_assert(!dendswithcs(s1, "ok!"));
	
	dfree(s1);
	test_end();
	
	/* int dpos(const dstring* a, const dstring* b, dstrlen_t start); */
	test_start("dpos");
	s1 = dfromcs("this is a good place");
	s2 = dfromcs("is");
	s3 = dfromcs("bla");
	
	test_assert(dpos(s1, s2, 0) == 2);
	test_assert(dpos(s1, s2, 4) == 5);
	test_assert(dpos(s1, s2, 7) == -1);
	test_assert(dpos(s1, s3, 44) == -1);
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	test_end();
	
	/* int dposc(const dstring* a, int b, dstrlen_t start); */
	test_start("dposc");
	s1 = dfromcs("this is a good place");
	
	test_assert(dposc(s1, 'i', 0) == 2);
	test_assert(dposc(s1, 'i', 4) == 5);
	test_assert(dposc(s1, 'j', 7) == -1);
	test_assert(dposc(s1, 'x', 44) == -1);
	
	dfree(s1);
	test_end();
	
	/* int dposcs(const dstring* a, const char* b, dstrlen_t start); */
	test_start("dposcs");
	s1 = dfromcs("this is a good place");
	
	test_assert(dposcs(s1, "is", 0) == 2);
	test_assert(dposcs(s1, "is", 4) == 5);
	test_assert(dposcs(s1, "is", 7) == -1);
	test_assert(dposcs(s1, "bla", 44) == -1);
	
	dfree(s1);
	test_end();
	
	
	return 0;
}
Example #18
0
bool APathFollower::Interpolate ()
{
	DVector3 dpos(0, 0, 0);
	FLinkContext ctx;

	if ((args[2] & 8) && Time > 0.f)
	{
		dpos = Pos();
	}

	if (CurrNode->Next==NULL) return false;

	UnlinkFromWorld (&ctx);
	DVector3 newpos;
	if (args[2] & 1)
	{	// linear
		newpos.X = Lerp(CurrNode->X(), CurrNode->Next->X());
		newpos.Y = Lerp(CurrNode->Y(), CurrNode->Next->Y());
		newpos.Z = Lerp(CurrNode->Z(), CurrNode->Next->Z());
	}
	else
	{	// spline
		if (CurrNode->Next->Next==NULL) return false;

		newpos.X = Splerp(PrevNode->X(), CurrNode->X(), CurrNode->Next->X(), CurrNode->Next->Next->X());
		newpos.Y = Splerp(PrevNode->Y(), CurrNode->Y(), CurrNode->Next->Y(), CurrNode->Next->Next->Y());
		newpos.Z = Splerp(PrevNode->Z(), CurrNode->Z(), CurrNode->Next->Z(), CurrNode->Next->Next->Z());
	}
	SetXYZ(newpos);
	LinkToWorld (&ctx);

	if (args[2] & 6)
	{
		if (args[2] & 8)
		{
			if (args[2] & 1)
			{ // linear
				dpos.X = CurrNode->Next->X() - CurrNode->X();
				dpos.Y = CurrNode->Next->Y() - CurrNode->Y();
				dpos.Z = CurrNode->Next->Z() - CurrNode->Z();
			}
			else if (Time > 0.f)
			{ // spline
				dpos = newpos - dpos;
			}
			else
			{
				int realarg = args[2];
				args[2] &= ~(2|4|8);
				Time += 0.1f;
				dpos = newpos;
				Interpolate ();
				Time -= 0.1f;
				args[2] = realarg;
				dpos = newpos - dpos;
				newpos -= dpos;
				SetXYZ(newpos);
			}
			if (args[2] & 2)
			{ // adjust yaw
				Angles.Yaw = dpos.Angle();
			}
			if (args[2] & 4)
			{ // adjust pitch; use floats for precision
				double dist = dpos.XY().Length();
				Angles.Pitch = dist != 0.f ? VecToAngle(dist, -dpos.Z) : 0.;
			}
		}
		else
		{
			if (args[2] & 2)
			{ // interpolate angle
				DAngle angle1 = CurrNode->Angles.Yaw.Normalized180();
				DAngle angle2 = angle1 + deltaangle(angle1, CurrNode->Next->Angles.Yaw);
				Angles.Yaw = Lerp(angle1.Degrees, angle2.Degrees);
			}
			if (args[2] & 1)
			{ // linear
				if (args[2] & 4)
				{ // interpolate pitch
					Angles.Pitch = Lerp(CurrNode->Angles.Pitch.Degrees, CurrNode->Next->Angles.Pitch.Degrees);
				}
			}
			else
			{ // spline
				if (args[2] & 4)
				{ // interpolate pitch
					Angles.Pitch = Splerp(PrevNode->Angles.Pitch.Degrees, CurrNode->Angles.Pitch.Degrees,
						CurrNode->Next->Angles.Pitch.Degrees, CurrNode->Next->Next->Angles.Pitch.Degrees);
				}
			}
		}
	}

	return true;
}
void scene_view::mouseMoveEvent(QMouseEvent *event)
{
    int x = event->localPos().x();
    int y = event->localPos().y();

    const bool shift = event->modifiers().testFlag(Qt::ShiftModifier);
    const bool alt = event->modifiers().testFlag(Qt::AltModifier);

    bool lock_mouse = false;

    auto btns = event->buttons();
    if (btns.testFlag(Qt::RightButton))
    {
        if (shift)
        {
            m_camera_yaw += x - m_mouse_x;
            m_camera_pitch += y - m_mouse_y;
            m_camera_yaw.normalize();
            m_camera_pitch.clamp(-90, 90);
        }
        else if (alt)
        {
            m_camera_pos.y -= (y - m_mouse_y) * 10.0f;
            m_camera_pos.y = nya_math::clamp(m_camera_pos.y, 20.0f, 5000.0f);
        }
        else
        {
            nya_math::vec2 dpos(x - m_mouse_x, y - m_mouse_y);
            dpos.rotate(m_camera_yaw);
            dpos *= m_camera_pos.y / 30.0f;
            m_camera_pos.x += dpos.x, m_camera_pos.z += dpos.y;
            m_camera_pos.x = nya_math::clamp(m_camera_pos.x, -location_size, location_size);
            m_camera_pos.z = nya_math::clamp(m_camera_pos.z, -location_size, location_size);
        }
    }
    else if (btns.testFlag(Qt::LeftButton))
    {
        nya_math::vec2 dpos(x - m_mouse_x, y - m_mouse_y);
        dpos.rotate(m_camera_yaw);
        dpos *= m_camera_pos.y / 300.0f;
        if (shift)
            dpos *= 10.0f;

        if (m_mode == mode_edit)
        {
            for (auto &o: m_selection["objects"])
            {
                if (o >= m_objects.size())
                    continue;

                auto &obj = m_objects[o];
                obj.pos.x += dpos.x, obj.pos.z += dpos.y;
                obj.pos.y = m_location_phys.get_height(obj.pos.x, obj.pos.z, true);
            }

            for (auto &o: m_selection["paths"])
            {
                if (o >= m_paths.size())
                    continue;

                auto &pth = m_paths[o];
                for (auto &p: pth.points)
                {
                    p.x += dpos.x, p.z += dpos.y;
                    p.y = m_location_phys.get_height(p.x, p.z, true);
                }
            }

            if (!m_selection["player spawn"].empty())
            {
                m_player.pos.x += dpos.x, m_player.pos.z += dpos.y;
                m_player.pos.y = m_location_phys.get_height(m_player.pos.x, m_player.pos.z, true);
            }
        }
    }
    else if (alt)
    {
        const float add = -(y - m_mouse_y) * (shift ? 10.0f : 1.0f);
        lock_mouse = true;

        if (m_mode == mode_add || m_mode == mode_path)
            m_selected_add.y = nya_math::clamp(m_selected_add.y + add, 0.0f, 10000.0f);

        if (m_mode == mode_zone)
            m_zone_add.radius = nya_math::clamp(m_zone_add.radius + add, 1.0f, 10000.0f);

        if (m_mode == mode_edit)
        {
            for (auto &o: m_selection["objects"])
            {
                if (o < m_objects.size())
                    m_objects[o].y = nya_math::clamp(m_objects[o].y + add, 0.0f, 10000.0f);
            }

            if (!m_selection["player spawn"].empty())
                m_player.y = nya_math::clamp(m_player.y + add, 0.0f, 10000.0f);
        }
    }
    else if (shift)
    {
        const nya_math::angle_deg add = (y - m_mouse_y) * 4.0f;
        lock_mouse = true;

        if (m_mode == mode_add)
            m_selected_add.yaw = (m_selected_add.yaw + add).normalize();

        if (m_mode == mode_edit)
        {
            const float far_dist = 100000.0f;
            nya_math::vec3 vmin(far_dist, far_dist, far_dist), vmax(-far_dist, -far_dist, -far_dist);

            for (auto &o: m_selection["objects"])
            {
                if (o >= m_objects.size())
                    continue;

                m_objects[o].yaw = (m_objects[o].yaw + add).normalize();
                vmin = nya_math::vec3::min(vmin, m_objects[o].pos);
                vmax = nya_math::vec3::max(vmax, m_objects[o].pos);
            }

            for (auto &o: m_selection["paths"])
            {
                if (o >= m_paths.size())
                    continue;

                for (auto &p: m_paths[o].points)
                {
                    vmin = nya_math::vec3::min(vmin, p.xyz());
                    vmax = nya_math::vec3::max(vmax, p.xyz());
                }
            }

            if (!m_selection["player spawn"].empty())
            {
                m_player.yaw = (m_player.yaw + add).normalize();
                vmin = nya_math::vec3::min(vmin, m_player.pos);
                vmax = nya_math::vec3::max(vmax, m_player.pos);
            }

            auto c = vmin + (vmax - vmin) * 0.5;

            const nya_math::quat rot(nya_math::angle_deg(), add, 0);

            for (auto &o: m_selection["objects"])
            {
                if (o >= m_objects.size())
                    continue;

                m_objects[o].pos = c + rot.rotate(m_objects[o].pos - c);
            }

            for (auto &o: m_selection["paths"])
            {
                if (o >= m_paths.size())
                    continue;

                for (auto &p: m_paths[o].points)
                    p.xyz() = c + rot.rotate(p.xyz() - c);
            }

            if (!m_selection["player spawn"].empty())
                m_player.pos = c + rot.rotate(m_player.pos - c);
        }
    }

    if (lock_mouse)
    {
        QPoint glob = mapToGlobal(QPoint(m_mouse_x, m_mouse_y));
        clearFocus();
        QCursor::setPos(glob);
        setFocus();
    }
    else
        m_mouse_x = x, m_mouse_y = y;

    update();
}
// Configure
bool FBUpdateLowRes::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
                               int fbZorder) {
    bool ret = false;
    hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
    if (LIKELY(ctx->mOverlay)) {
        int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
        // ext only layer present..
        if(extOnlyLayerIndex != -1) {
            layer = &list->hwLayers[extOnlyLayerIndex];
            layer->compositionType = HWC_OVERLAY;
        }
        overlay::Overlay& ov = *(ctx->mOverlay);
        private_handle_t *hnd = (private_handle_t *)layer->handle;
        ovutils::Whf info(getWidth(hnd), getHeight(hnd),
                          ovutils::getMdpFormat(hnd->format), hnd->size);

        //Request an RGB pipe
        ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy);
        if(dest == ovutils::OV_INVALID) { //None available
            ALOGE("%s: No pipes available to configure framebuffer",
                __FUNCTION__);
            return false;
        }

        mDest = dest;

        ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
        ovutils::eIsFg isFg = ovutils::IS_FG_OFF;
        ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);

        hwc_rect_t sourceCrop = layer->sourceCrop;
        hwc_rect_t displayFrame = layer->displayFrame;
        int transform = layer->transform;
        int fbWidth  = ctx->dpyAttr[mDpy].xres;
        int fbHeight = ctx->dpyAttr[mDpy].yres;
        int rotFlags = ovutils::ROT_FLAGS_NONE;

        ovutils::eTransform orient =
                    static_cast<ovutils::eTransform>(transform);
        if(mDpy && ctx->mExtOrientation) {
            // If there is a external orientation set, use that
            transform = ctx->mExtOrientation;
            orient = static_cast<ovutils::eTransform >(ctx->mExtOrientation);
        }

        // Dont do wormhole calculation when extorientation is set on External
        if((!mDpy || (mDpy && !ctx->mExtOrientation))
                               && extOnlyLayerIndex == -1) {
            getNonWormholeRegion(list, sourceCrop);
            displayFrame = sourceCrop;
        }
        ovutils::Dim dpos(displayFrame.left,
                          displayFrame.top,
                          displayFrame.right - displayFrame.left,
                          displayFrame.bottom - displayFrame.top);

        if(mDpy) {
            // Get Aspect Ratio for external
            getAspectRatioPosition(ctx, mDpy, ctx->mExtOrientation, dpos.x,
                                    dpos.y, dpos.w, dpos.h);
            // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
            getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
            // Convert dim to hwc_rect_t
            displayFrame.left = dpos.x;
            displayFrame.top = dpos.y;
            displayFrame.right = dpos.w + displayFrame.left;
            displayFrame.bottom = dpos.h + displayFrame.top;
        }
        setMdpFlags(layer, mdpFlags, 0);
        // For External use rotator if there is a rotation value set
        if(mDpy && (ctx->mExtOrientation & HWC_TRANSFORM_ROT_90)) {
            mRot = ctx->mRotMgr->getNext();
            if(mRot == NULL) return -1;
            //Configure rotator for pre-rotation
            if(configRotator(mRot, info, mdpFlags, orient, 0) < 0) {
                ALOGE("%s: configRotator Failed!", __FUNCTION__);
                mRot = NULL;
                return -1;
            }
            info.format = (mRot)->getDstFormat();
            updateSource(orient, info, sourceCrop);
            rotFlags |= ovutils::ROT_PREROTATED;
        }
        //For the mdp, since either we are pre-rotating or MDP does flips
        orient = ovutils::OVERLAY_TRANSFORM_0;
        transform = 0;

        //XXX: FB layer plane alpha is currently sent as zero from
        //surfaceflinger
        ovutils::PipeArgs parg(mdpFlags,
                info,
                zOrder,
                isFg,
                static_cast<ovutils::eRotFlags>(rotFlags),
                ovutils::DEFAULT_PLANE_ALPHA,
                (ovutils::eBlending) getBlending(layer->blending));

        ret = true;
        if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
                    NULL, mDest) < 0) {
            ALOGE("%s: ConfigMdp failed for low res", __FUNCTION__);
            ret = false;
        }
    }
    return ret;
}
/* Helpers */
bool configPrimVid(hwc_context_t *ctx, hwc_layer_1_t *layer) {
    overlay::Overlay& ov = *(ctx->mOverlay);
    private_handle_t *hnd = (private_handle_t *)layer->handle;
    ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);

    ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
    if (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) {
        ovutils::setMdpFlags(mdpFlags,
                ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
    }
    if(layer->blending == HWC_BLENDING_PREMULT) {
        ovutils::setMdpFlags(mdpFlags,
                ovutils::OV_MDP_BLEND_FG_PREMULT);
    }

    ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF;
    if (ctx->numHwLayers == 1) {
        isFgFlag = ovutils::IS_FG_SET;
    }

    ovutils::PipeArgs parg(mdpFlags,
            info,
            ovutils::ZORDER_0,
            isFgFlag,
            ovutils::ROT_FLAG_DISABLED);
    ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
    ov.setSource(pargs, ovutils::OV_PIPE0);

    hwc_rect_t sourceCrop = layer->sourceCrop;
    hwc_rect_t displayFrame = layer->displayFrame;

    //Calculate the rect for primary based on whether the supplied position
    //is within or outside bounds.
    const int fbWidth =
            ovutils::FrameBufferInfo::getInstance()->getWidth();
    const int fbHeight =
            ovutils::FrameBufferInfo::getInstance()->getHeight();

    if( displayFrame.left < 0 ||
            displayFrame.top < 0 ||
            displayFrame.right > fbWidth ||
            displayFrame.bottom > fbHeight) {
        calculate_crop_rects(sourceCrop, displayFrame, fbWidth, fbHeight);
    }

    // source crop x,y,w,h
    ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
            sourceCrop.right - sourceCrop.left,
            sourceCrop.bottom - sourceCrop.top);
    //Only for Primary
    ov.setCrop(dcrop, ovutils::OV_PIPE0);

    ovutils::eTransform orient =
            static_cast<ovutils::eTransform>(layer->transform);
    ov.setTransform(orient, ovutils::OV_PIPE0);

    // position x,y,w,h
    ovutils::Dim dpos(displayFrame.left,
            displayFrame.top,
            displayFrame.right - displayFrame.left,
            displayFrame.bottom - displayFrame.top);
    ov.setPosition(dpos, ovutils::OV_PIPE0);

    if (!ov.commit(ovutils::OV_PIPE0)) {
        ALOGE("%s: commit fails", __FUNCTION__);
        return false;
    }
    return true;
}
bool configExtVid(hwc_context_t *ctx, hwc_layer_1_t *layer) {
    overlay::Overlay& ov = *(ctx->mOverlay[HWC_DISPLAY_EXTERNAL]);
    private_handle_t *hnd = (private_handle_t *)layer->handle;
    ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size);

    ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE;
    if (isSecureBuffer(hnd)) {
        ovutils::setMdpFlags(mdpFlags,
                ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
    }

    if(layer->blending == HWC_BLENDING_PREMULT) {
        ovutils::setMdpFlags(mdpFlags,
                ovutils::OV_MDP_BLEND_FG_PREMULT);
    }

    ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF;
    if (ctx->listStats[HWC_DISPLAY_EXTERNAL].numAppLayers == 1) {
        isFgFlag = ovutils::IS_FG_SET;
    }

    ovutils::PipeArgs parg(mdpFlags,
            info,
            ovutils::ZORDER_1,
            isFgFlag,
            ovutils::ROT_FLAG_DISABLED);
    ovutils::PipeArgs pargs[ovutils::MAX_PIPES] = { parg, parg, parg };
    ov.setSource(pargs, ovutils::OV_PIPE1);

    int transform = layer->transform;
    ovutils::eTransform orient =
            static_cast<ovutils::eTransform>(transform);

    hwc_rect_t sourceCrop = layer->sourceCrop;
    hwc_rect_t displayFrame = layer->displayFrame;

    //Calculate the rect for primary based on whether the supplied position
    //is within or outside bounds.
    const int fbWidth = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].xres;
    const int fbHeight = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].yres;

    if( displayFrame.left < 0 ||
            displayFrame.top < 0 ||
            displayFrame.right > fbWidth ||
            displayFrame.bottom > fbHeight) {
        calculate_crop_rects(sourceCrop, displayFrame, fbWidth, fbHeight,
                transform);
    }

    // x,y,w,h
    ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top,
            sourceCrop.right - sourceCrop.left,
            sourceCrop.bottom - sourceCrop.top);
    //Only for External
    ov.setCrop(dcrop, ovutils::OV_PIPE1);

    ov.setTransform(orient, ovutils::OV_PIPE1);

    ovutils::Dim dpos(displayFrame.left,
            displayFrame.top,
            (displayFrame.right - displayFrame.left),
            (displayFrame.bottom - displayFrame.top));

    //Only for External
    ov.setPosition(dpos, ovutils::OV_PIPE1);

    if (!ov.commit(ovutils::OV_PIPE1)) {
        ALOGE("%s: commit fails", __FUNCTION__);
        return false;
    }
    return true;
}