Пример #1
0
QList<load_command_offset> MACHFile::getLoadCommands_offset()
{
    QList<load_command_offset> listResult;

    load_command_offset record;

    unsigned int nNumberOfCommands=getHeader_ncmds();

    if(nNumberOfCommands>0xFF)
    {
        nNumberOfCommands=0xFF;
    }

    unsigned int nOffset=getMachHeaderSize();

    for(int i=0; i<nNumberOfCommands; i++)
    {
        record.cmd=readDword(nOffset+offsetof(load_command,cmd),isReverse());
        record.cmdsize=readDword(nOffset+offsetof(load_command,cmdsize),isReverse());
        record.offset=nOffset;

        listResult.append(record);

        nOffset+=record.cmdsize;
    }



    return listResult;
}
Пример #2
0
QList<DYLIB_FULL> MACHFile::getLibs()
{
    QList<DYLIB_FULL> listResult;

    QList<load_command_offset> list=getLoadCommands_offset();

    for(int i=0; i<list.count(); i++)
    {
        if((list.at(i).cmd==LC_LOAD_DYLIB)||(list.at(i).cmd==LC_LOAD_WEAK_DYLIB)||(list.at(i).cmd==LC_ID_DYLIB))
        {
            unsigned int nOffset=list.at(i).offset;
            nOffset+=sizeof(load_command);

            DYLIB_FULL record;
            unsigned int nStringOffset=readDword(nOffset,isReverse());
            nOffset+=4;
            record.timestamp=readDword(nOffset,isReverse());
            nOffset+=4;
            record.current_version=readDword(nOffset,isReverse());
            nOffset+=4;
            record.compatibility_version=readDword(nOffset,isReverse());
            record.sVollName=getString(list.at(i).offset+nStringOffset,list.at(i).cmdsize-20);

            unsigned int nCount=record.sVollName.count("/");
            record.sShortName=record.sVollName.section("/",nCount,nCount);

            listResult.append(record);
        }
    }


    return listResult;
}
Пример #3
0
QList<segment_command_64> MACHFile::getSegmentsList64()
{
    QList<load_command_offset> list=getLoadCommands_offset();
    unsigned int nOffset=0;

    QList<segment_command_64> listResult;

    segment_command_64 record;

    for(int i=0; i<list.count(); i++)
    {
        if(list.at(i).cmd==LC_SEGMENT_64)
        {
            nOffset=list.at(i).offset;


            record.cmd=readDword(nOffset+offsetof(segment_command_64,cmd),isReverse());
            record.cmdsize=readDword(nOffset+offsetof(segment_command_64,cmdsize),isReverse());
            readArray(nOffset+offsetof(segment_command_64,segname),record.segname,16);
            record.vmaddr=readQword(nOffset+offsetof(segment_command_64,vmaddr),isReverse());
            record.vmsize=readQword(nOffset+offsetof(segment_command_64,vmsize),isReverse());
            record.fileoff=readQword(nOffset+offsetof(segment_command_64,fileoff),isReverse());
            record.filesize=readQword(nOffset+offsetof(segment_command_64,filesize),isReverse());
            record.maxprot=readDword(nOffset+offsetof(segment_command_64,maxprot),isReverse());
            record.initprot=readDword(nOffset+offsetof(segment_command_64,initprot),isReverse());
            record.nsects=readDword(nOffset+offsetof(segment_command_64,nsects),isReverse());
            record.flags=readDword(nOffset+offsetof(segment_command_64,flags),isReverse());

            listResult.append(record);
        }
    }

    return listResult;
}
Пример #4
0
unsigned long long MACHFile::getEntryPoint()
{
    unsigned long long nResult=0;

    unsigned int nNumberOfCommands=getHeader_ncmds();

    if(nNumberOfCommands>0xFF)
    {
        nNumberOfCommands=0xFF;
    }

    for(int i=0; i<nNumberOfCommands; i++)
    {
        if((getLoadCommand_type(i)==LC_THREAD)||(getLoadCommand_type(i)==LC_UNIXTHREAD))
        {
            unsigned int nOffset=getLoadCommand_offset(i);

            unsigned int nFlavor=readDword(nOffset+8,isReverse());

            if(nFlavor==x86_THREAD_STATE32)
            {
                nResult=readDword(nOffset+16+offsetof(F_STRUCT_X86_THREAD_STATE32,eip),isReverse());
            }
            else if(nFlavor==x86_THREAD_STATE64)
            {
                nResult=readQword(nOffset+16+offsetof(F_STRUCT_X86_THREAD_STATE64,rip),isReverse());
            }
        }
    }

    return nResult;
}
Пример #5
0
	OUTLINE::OUTLINE(PointS startpt, const vector<DIR>& new_steps)
		:start(startpt), stepcount(static_cast<int16_t>(new_steps.size())), steps(elem_num(stepcount)){
		PointS pos = start;
		box = RectS(pos, pos);
		auto lastdir = new_steps.back();
		auto prevdir = lastdir;
		int stepindex = 0;
		for (int srcindex = 0; srcindex < new_steps.size(); ++srcindex, ++stepindex){
			auto dir = new_steps[srcindex];
			set_step(stepindex, dir);
			pos += dir;
			box += pos;
			if (dir.isReverse(prevdir) && stepindex > 0){
				stepindex -= 2;
				prevdir = stepindex == -1 ? lastdir : step_dir(stepindex);
			}
			else{
				prevdir = dir;
			}
		}

		assert(pos.x == start.x&&pos.y == start.y);//ÂÖÀª±ØÐë·â±Õ
		int begin = 0;
		while (stepindex - 1 > begin && step_dir(begin).isReverse(step_dir(stepindex - 1))){
			start += step_dir(begin); //ÆðµãÏòÇ°ÒÆ
			++begin;
			--stepindex; //cancel there-and-back
		}
		for (int i = begin; i < stepindex; ++i){
			set_step(i - begin, step_dir(i));
		}
		stepcount = stepindex - begin;
		assert(stepcount >= 4);

	}
Пример #6
0
QList<section> MACHFile::getSectionsList32()
{
    QList<section> listResult;

    //    return listResult;
    QList<load_command_offset> list=getLoadCommands_offset();
    unsigned int nOffset=0;

    section record;

    unsigned int nNumberOfSections=0;

    for(int i=0; i<list.count(); i++)
    {
        if(list.at(i).cmd==LC_SEGMENT)
        {
            nOffset=list.at(i).offset;

            nNumberOfSections=readDword(nOffset+offsetof(segment_command,nsects),isReverse());

            nOffset+=sizeof(segment_command);

            for(int j=0; j<nNumberOfSections; j++)
            {
                readArray(nOffset+offsetof(section,sectname),record.sectname,16);
                readArray(nOffset+offsetof(section,segname),record.segname,16);
                record.addr=readDword(nOffset+offsetof(section,addr),isReverse());
                record.size=readDword(nOffset+offsetof(section,size),isReverse());
                record.offset=readDword(nOffset+offsetof(section,offset),isReverse());
                record.align=readDword(nOffset+offsetof(section,align),isReverse());
                record.reloff=readDword(nOffset+offsetof(section,reloff),isReverse());
                record.nreloc=readDword(nOffset+offsetof(section,nreloc),isReverse());
                record.flags=readDword(nOffset+offsetof(section,flags),isReverse());
                record.reserved1=readDword(nOffset+offsetof(section,reserved1),isReverse());
                record.reserved2=readDword(nOffset+offsetof(section,reserved2),isReverse());


                listResult.append(record);
                nOffset+=sizeof(section);
            }


        }
    }

    return listResult;
}
 void BaseTween::forceToStart()
 {
     currentTime = -delayStart;
     step = -1;
     isIterationStep = false;
     if (isReverse(0)) forceEndValues();
     else forceStartValues();
 }
 void BaseTween::forceToEnd(float time)
 {
     currentTime = time - getFullDuration();
     step = repeatCnt*2 + 1;
     isIterationStep = false;
     if (isReverse(repeatCnt*2)) forceStartValues();
     else forceEndValues();
 }
Пример #9
0
QList<segment_command> MACHFile::getSegmentsList32()
{
    QList<load_command_offset> list=getLoadCommands_offset();
    unsigned int nOffset=0;

    QList<segment_command> listResult;

    segment_command record;

    for(int i=0; i<list.count(); i++)
    {
        if(list.at(i).cmd==LC_SEGMENT)
        {
            nOffset=list.at(i).offset;

            //            uint32_t cmd;
            //            uint32_t cmdsize;
            //            char segname[16];
            //            uint32_t vmaddr;
            //            uint32_t vmsize;
            //            uint32_t fileoff;
            //            uint32_t filesize;
            //            vm_prot_t maxprot;
            //            vm_prot_t initprot;
            //            uint32_t nsects;
            //            uint32_t flags;


            record.cmd=readDword(nOffset+offsetof(segment_command,cmd),isReverse());
            record.cmdsize=readDword(nOffset+offsetof(segment_command,cmdsize),isReverse());
            readArray(nOffset+offsetof(segment_command,segname),record.segname,16);
            record.vmaddr=readDword(nOffset+offsetof(segment_command,vmaddr),isReverse());
            record.vmsize=readDword(nOffset+offsetof(segment_command,vmsize),isReverse());
            record.fileoff=readDword(nOffset+offsetof(segment_command,fileoff),isReverse());
            record.filesize=readDword(nOffset+offsetof(segment_command,filesize),isReverse());
            record.maxprot=readDword(nOffset+offsetof(segment_command,maxprot),isReverse());
            record.initprot=readDword(nOffset+offsetof(segment_command,initprot),isReverse());
            record.nsects=readDword(nOffset+offsetof(segment_command,nsects),isReverse());
            record.flags=readDword(nOffset+offsetof(segment_command,flags),isReverse());

            listResult.append(record);
        }
    }

    return listResult;
}
Пример #10
0
void MACHFile::setHeader_magic(unsigned int nValue)
{
    writeDword(offsetof(mach_header,magic),nValue,isReverse());

    if((nValue==MH_CIGAM)||(nValue==MH_CIGAM_64))
    {
        nIsReverse=1;
    }
    else
    {
        nIsReverse=0;
    }
}
Пример #11
0
void PatternHourGlass::apply(Color* stripColors)
{
	//	Need to handle HourGlass Transition animation, 
	//	from indicator color i to indicator color (i+1)
	//	...code
	
	// The pattern has two states, inTransition and normal
	// everytime when the indicaotr reach the highest point, a transitional pattern
	// will show up for certain seconds, after the transitional pattern is animated
	// the pattern will change back to the normal state.
	
	if(inTransition){
		// if the transitional animation is finised, change to render the pattern of normal state
		if(isTransitionExpired()){
			inTransition = false;
			setTransitionExpired(false);
			
			// reset the frozen indicator to it's current value
			indicator = actualValueBeingStored % (maxValueCanBePresentedOnHourGlass/indicatorUnit);
			indicator *= indicatorUnit;
		}
		
	 	transitionUpdate();
		transitionApply(stripColors);

				
	} else {
		// Normal State
		if(isReverse())
		{
			for(byte i = STRIP_LENGTH-1; i > (STRIP_LENGTH-1)-indicator; i--){
				float scale = calculateScale(i);
				stripColors[i].add(colors[currentColorIndex].scaled(scale));	
			}
			for(byte i = (STRIP_LENGTH-1) - indicator; i >= 0; i--){
				float scale = calculateScale(i);
				stripColors[i].add(bgColor.scaled(scale));
			}
		} else {
			for(byte i = 0; i < indicator; i++){
				float scale = calculateScale(i);
				stripColors[i].add(colors[currentColorIndex].scaled(scale));
			}
			for(byte i = indicator; i < STRIP_LENGTH; i++ ){
				float scale = calculateScale(i);
				stripColors[i].add(bgColor.scaled(scale));
			}
		}
	}// End Normal State
}
Пример #12
0
 bool Motor::onReverse() {
   if(_bidirectional) {
     if(isReverse()) {
       if(!_has_been_reverse) {
         return _has_been_reverse = true;
       }
       // else
       return false;
     }
     // else
     return _has_been_reverse = false;
   }
   // else
   return false;
 }
Пример #13
0
unsigned int MACHFile::getLoadCommand_offset(unsigned int nLoadCommand)
{
    if(isLoadCommandPresent(nLoadCommand))
    {
        unsigned int nOffset=getMachHeaderSize();

        for(int i=0; i<nLoadCommand; i++)
        {
            nOffset+=readDword(nOffset+offsetof(load_command,cmdsize),isReverse());
        }

        return nOffset;
    }

    return 0;
}
Пример #14
0
void RenderParams::update(ConstCDLOpDataRcPtr & cdl)
{
    double slope[4], offset[4], power[4];
    cdl->getSlopeParams().getRGBA(slope);
    cdl->getOffsetParams().getRGBA(offset);
    cdl->getPowerParams().getRGBA(power);

    const float saturation = (float)cdl->getSaturation();
    const CDLOpData::Style style = cdl->getStyle();

    m_isReverse
        = (style == CDLOpData::CDL_V1_2_REV)
        || (style == CDLOpData::CDL_NO_CLAMP_REV);

    m_isNoClamp
        = (style == CDLOpData::CDL_NO_CLAMP_FWD)
        || (style == CDLOpData::CDL_NO_CLAMP_REV);

    if (isReverse())
    {
        // Reverse render parameters
        setSlope(Reciprocal((float)slope[0]),
                 Reciprocal((float)slope[1]),
                 Reciprocal((float)slope[2]),
                 Reciprocal((float)slope[3]));
   
        setOffset((float)-offset[0], (float)-offset[1], (float)-offset[2], (float)-offset[3]);
   
        setPower(Reciprocal((float)power[0]),
                 Reciprocal((float)power[1]),
                 Reciprocal((float)power[2]),
                 Reciprocal((float)power[3]));
       
        setSaturation(Reciprocal(saturation));
    }
    else
    {
        // Forward render parameters
        setSlope((float)slope[0], (float)slope[1], (float)slope[2], (float)slope[3]);
        setOffset((float)offset[0], (float)offset[1], (float)offset[2], (float)offset[3]);
        setPower((float)power[0], (float)power[1], (float)power[2], (float)power[3]);
        setSaturation(saturation);
    }
}
Пример #15
0
void CEnemy::Update()
{
    CEntity::Update(); // animation and movement stuff
    
    // handling new movement in different states
    if (!_moving && _state == EnemyStateScatter)
    {
        Move(chooseDirection(_scatterX, _scatterY)); // try to move to our scatter corner
    }
    else if (!_moving && _state == EnemyStateChase)
    {
        Move(chooseDirection(_chaseX, _chaseY)); // try to move to our chase position (different for every ghost)
    }
    else if (!_moving && _state == EnemyStateFrighten)
    {
        while (true) { // just move in random direction
            int direction = rand() % 4;
            if (!isReverse((Direction)direction)) {
                Move((Direction)direction);
                if (_moving) {
                    break;
                }
            }
        }
    }
    else if (!_moving && _state == EnemyStateEyes)
    {
        if (getXposition() == _startX && getYposition() == _startY) {
            Reset(); // reset our states when home reached
            
            _state = EnemyStateChase;
            Update(); // start chase over
        }
        else {
            Move(chooseDirection(_startX, _startY)); // go home
        }
    }
}
void PatternBarPlotToBarPlot::apply(Color* stripColors)
{
	if(isReverse())
	{
		for(byte i = STRIP_LENGTH-1; i > (STRIP_LENGTH-1)-currentPosition; i--){
			float scale = calculateScale(i);
			stripColors[i].add(barColor.scaled(scale));	
		}
		for(byte i = (STRIP_LENGTH-1) - currentPosition; i >= 0; i--){
			float scale = calculateScale(i);
			stripColors[i].add(bgColor.scaled(scale));
		}
	} else {
		for(byte i = 0; i < currentPosition; i++){
			float scale = calculateScale(i);
			stripColors[i].add(barColor.scaled(scale));
		}
		for(byte i = currentPosition; i < STRIP_LENGTH; i++ ){
			float scale = calculateScale(i);
			stripColors[i].add(bgColor.scaled(scale));
		}
	}
}
Пример #17
0
void PatternHourGlass::transitionApply(Color* stripColors)
{
	if(isReverse())
	{
		for(byte i = STRIP_LENGTH-1; i > (STRIP_LENGTH-1)-transitionCurrentPosition; i--){
			float scale = calculateScale(i);
			stripColors[i].add(colors[transitionColorIndex].scaled(scale));	
		}
		for(byte i = (STRIP_LENGTH-1) - transitionCurrentPosition; i >= 0; i--){
			float scale = calculateScale(i);
			stripColors[i].add(bgColor.scaled(scale));
		}
	} else {
		for(byte i = 0; i < transitionCurrentPosition; i++){
			float scale = calculateScale(i);
			stripColors[i].add(colors[transitionColorIndex].scaled(scale));
		}
		for(byte i = transitionCurrentPosition; i < STRIP_LENGTH; i++ ){
			float scale = calculateScale(i);
			stripColors[i].add(bgColor.scaled(scale));
		}
	}
	
}
Пример #18
0
unsigned int MACHFile::getHeader_filetype()
{
    return readDword(offsetof(mach_header,filetype),isReverse());
}
Пример #19
0
unsigned int MACHFile::getSegment_nsects32(unsigned int nSegment)
{
    return readDword(getSegmentHeaderOffset(nSegment)+offsetof(segment_command,nsects),isReverse());
}
Пример #20
0
void
InsertSizes::accumulateLibraryStats(Unitig *utg) {

  for (uint32 fi=0; fi<utg->ufpath.size(); fi++) {
    ufNode  *frag = &utg->ufpath[fi];

    if (FI->mateIID(frag->ident) == 0)
      //  Unmated fragment.
      continue;

    if (utg->id() != utg->fragIn(FI->mateIID(frag->ident)))
      //  Mate in a different unitig.
      continue;

    uint32        mi   = utg->pathPosition(FI->mateIID(frag->ident));
    ufNode *mate = &utg->ufpath[mi];

    if (frag->ident < mate->ident)
      //  Only do this once for each mate pair.
      continue;

#warning assumes innie mate pairs
    if (isReverse(frag->position) == isReverse(mate->position))
      //  Same orient mates, not a good mate pair.
      continue;

    //  Compute the insert size.

    int32  insertSize = 0;

    if (isReverse(frag->position)) {
      if (frag->position.end <= mate->position.bgn)
        //  Misordered, not a good mate pair.  NOTE: this is specifically allowing mates that
        //  overlap, i.e., insert size is less than the sum of fragment lengths.
        continue;

      //  We must have, at least, the following picture, where the relationship on the left is
      //  strict.  'frag' is allowed to move to the right, and 'mate' is allowed to move to the
      //  left, but moving either in the other direction turns this into an outtie relationship.
      //
      //  (end)  <----- (bgn)  frag
      //  (bgn) ----->  (end) mate
      //
      assert(mate->position.bgn < frag->position.end);

      //  However, we aren't guaranteed that the right side is ordered properly (i.e., misordered by
      //  one fragment contained in the other fragment).  We hope this doesn't happen, but if it
      //  does, we'll catch it.  The insertSize defaults to zero, which is then ignored below.
      //
      if (mate->position.bgn < frag->position.bgn)
        insertSize = frag->position.bgn - mate->position.bgn;

    } else {
      //  (See comments above)
      if (mate->position.end <= frag->position.bgn)
        continue;

      assert(frag->position.bgn < mate->position.end);

      if (frag->position.bgn < mate->position.bgn)
        insertSize = mate->position.bgn - frag->position.bgn;
    }

    assert(insertSize > 0);

    uint32 di = FI->libraryIID(frag->ident);

    if (_distMax[di] <= _distLen[di]) {
      _distMax[di] *= 2;
      int32 *d = new int32 [_distMax[di]];
      memcpy(d, _dist[di], sizeof(int32) * _distLen[di]);
      delete [] _dist[di];
      _dist[di] = d;
    }

    _dist[di][_distLen[di]++] = insertSize;
  }
}
Пример #21
0
void
MateLocation::buildHappinessGraphs(UnitigVector &unitigs) {

  //  First entry is always zero.  Needed for the getById() accessor.

  assert(_table[0].mleFrgID1 == 0);
  assert(_table[0].mleFrgID2 == 0);

  assert(IS != NULL);

  for (uint32 mleidx=1; mleidx<_table.size(); mleidx++) {
    MateLocationEntry &loc = _table[mleidx];

    //  We MUST have mleFrgID1 defined.  If mleFrgID2 is not defined, then the mate is external.
    assert(loc.mleFrgID1 != 0);

    //  Well, this bit of ugly is here to fill out the location of the mate (when it is in a
    //  different unitig, the location for this fragment is not set)....EXCEPT that the mate might
    //  not even be placed in a unitig yet (if it is a contain, and we're called before contains are
    //  placed).
    //
    //  This is currently only used for logging -- AND statistics on mate happiness.  Later we
    //  should use it to determine if the mate is buried in the other unitig, which would make the
    //  fragment in this unitig bad.
    //
    if (loc.mleFrgID2 == 0) {
      assert(loc.mleUtgID2 == 0);
      loc.mleFrgID2 = FI->mateIID(loc.mleFrgID1);
      loc.mleUtgID2 = _tig->fragIn(loc.mleFrgID2);

      if (loc.mleUtgID2 != 0) {
        Unitig  *mt = unitigs[loc.mleUtgID2];
        uint32   fi = _tig->pathPosition(loc.mleFrgID2);
        loc.mlePos2 = mt->ufpath[fi].position;
      }
    }

    uint32 lib =  FI->libraryIID(loc.mleFrgID1);

    if (lib == 0)
      //  Shouldn't occur, but just in case, ignore fragments in the legacy library.
      continue;

    if (IS->valid(lib) == false)
      // Don't check libs that we didn't generate good stats for
      continue;

    int32 badMaxInter = static_cast<int32>(IS->mean(lib) + BADMATE_INTER_STDDEV * IS->stddev(lib));
    int32 badMinInter = static_cast<int32>(IS->mean(lib) - BADMATE_INTER_STDDEV * IS->stddev(lib));

    int32 badMaxIntra = static_cast<int32>(IS->mean(lib) + BADMATE_INTRA_STDDEV * IS->stddev(lib));
    int32 badMinIntra = static_cast<int32>(IS->mean(lib) - BADMATE_INTRA_STDDEV * IS->stddev(lib));

    //  To keep the results the same as the previous version (1.89)
    badMaxIntra = badMaxInter;
    badMinIntra = badMinInter;

    int32 dist = 0;
    int32 bgn  = 0;
    int32 end  = 0;

    //  Bgn and End MUST be signed.

    int32 matBgn = loc.mlePos2.bgn;
    int32 matEnd = loc.mlePos2.end;
    int32 matLen = (matBgn < matEnd) ? (matEnd - matBgn) : (matBgn - matEnd);

    int32 frgBgn = loc.mlePos1.bgn;
    int32 frgEnd = loc.mlePos1.end;
    int32 frgLen = (frgBgn < frgEnd) ? (frgEnd - frgBgn) : (frgBgn - frgEnd);

    int32 nContained  = 0;

    if (OG->getBestContainer(loc.mleFrgID1)->isContained == true)
      nContained++;

    if (OG->getBestContainer(loc.mleFrgID2)->isContained == true)
      nContained++;

    if ((matLen >= MIN(badMaxInter, badMaxIntra)) ||
        (frgLen >= MIN(badMaxInter, badMaxIntra)))
      //  Yikes, fragment longer than insert size!
      continue;


    //  Until reset, assume this is a bad mate pair.
    loc.isGrumpy = true;

    int32 ULEN1 = 0;  //unitigs[loc.mleUtgID1]->getLength()
    int32 ULEN2 = 0;  //unitigs[loc.mleUtgID2]->getLength()


    //  If the mate is in another unitig, mark bad only if there is enough space to fit the mate in
    //  this unitig.
    //
    //  TODO: OR if there isn't enough space on the end of the OTHER unitig
    //
    if (loc.mleUtgID1 != loc.mleUtgID2) {
      if ((isReverse(loc.mlePos1) == true)  && (badMaxInter < frgBgn)) {
        incrRange(badExternalRev, -1, frgBgn - badMaxInter, frgEnd);
        incrRange(badExternalRev, -1, frgBgn, frgEnd);
        nbadExternalRev[nContained]++;
        if (logFileFlagSet(LOG_HAPPINESS))
          writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad external reverse\n",
                  loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                  loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
        goto markBad;
      }

      if ((isReverse(loc.mlePos1) == false) && (badMaxInter < _tigLen - frgBgn)) {
        incrRange(badExternalFwd, -1, frgEnd, frgBgn + badMaxInter);
        incrRange(badExternalFwd, -1, frgEnd, frgBgn);
        nbadExternalFwd[nContained]++;
        if (logFileFlagSet(LOG_HAPPINESS))
          writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad external forward\n",
                  loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                  loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
        goto markBad;
      }

      //  Not enough space.  Not a grumpy mate pair.
      loc.isGrumpy = false;

      if (isReverse(loc.mlePos1) == true)
        ngoodExternalRev[nContained]++;
      else
        ngoodExternalFwd[nContained]++;

      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- not bad, not enough space\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      continue;
    }


    //  Both mates are in this unitig.


    //  Same orientation?
    if ((isReverse(loc.mlePos1) == false) &&
        (isReverse(loc.mlePos2) == false)) {
      incrRange(badNormal, -1, MIN(frgBgn, matBgn), MAX(frgEnd, matEnd));
      nbadNormal[nContained]++;
      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad normal\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      goto markBad;
    }

    if ((isReverse(loc.mlePos1) == true) &&
        (isReverse(loc.mlePos2) == true)) {
      incrRange(badAnti, -1, MIN(frgEnd, matEnd), MAX(frgBgn, matBgn));
      nbadAnti[nContained]++;
      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad anti\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      goto markBad;
    }


    //  Check a special case for a circular unitig, outtie mates, but close enough to the end to
    //  plausibly be linking the ends together.
    //
    //   <---              --->
    //  ========unitig==========
    //
    if ((isReverse(loc.mlePos1) == true) &&
        (badMinIntra               <= frgBgn + _tigLen - matBgn) &&
        (frgBgn + _tigLen - matBgn <= badMaxIntra)) {
      loc.isGrumpy = false;  //  IT'S GOOD, kind of.
      ngood[nContained]++;
      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- good because circular\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      continue;
    }


    //  Outties?  True if pos1.end < pos2.bgn.  (For the second case, swap pos1 and pos2)
    //
    //  (pos1.end) <------   (pos1.bgn)
    //  (pos2.bgn)  -------> (pos2.end)
    //
    if ((isReverse(loc.mlePos1) == true)  && (loc.mlePos1.end < loc.mlePos2.bgn)) {
      incrRange(badOuttie, -1, MIN(frgBgn, frgEnd), MAX(matBgn, matEnd));
      nbadOuttie[nContained]++;
      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad outtie (case 1)\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      goto markBad;
    }
    if ((isReverse(loc.mlePos1) == false) && (loc.mlePos2.end < loc.mlePos1.bgn)) {
      incrRange(badOuttie, -1, MIN(frgBgn, frgEnd), MAX(matBgn, matEnd));
      nbadOuttie[nContained]++;
      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad outtie (case 2)\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      goto markBad;
    }

    //  So, now not NORMAL or ANTI or OUTTIE.  We must be left with innies.

    if (isReverse(loc.mlePos1) == false)
      //  First fragment is on the left, second is on the right.
      dist = loc.mlePos2.bgn - loc.mlePos1.bgn;
    else
      //  First fragment is on the right, second is on the left.
      dist = loc.mlePos1.bgn - loc.mlePos2.bgn;

    assert(dist >= 0);

    if (dist < badMinIntra) {
      incrRange(badCompressed, -1, MIN(frgBgn, matBgn), MAX(frgBgn, matBgn));
      nbadCompressed[nContained]++;
      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad compressed\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      goto markBad;
    }

    if (badMaxIntra < dist) {
      incrRange(badStretched, -1, MIN(frgBgn, matBgn), MAX(frgBgn, matBgn));
      nbadStretched[nContained]++;
      if (logFileFlagSet(LOG_HAPPINESS))
        writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- bad stretched\n",
                loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
                loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
      goto markBad;
    }

    assert(badMinIntra <= dist);
    assert(dist        <= badMaxIntra);

    incrRange(good, 1, MIN(frgBgn, matBgn), MAX(frgBgn, matBgn));
    loc.isGrumpy = false;  //  IT'S GOOD!
    ngood[nContained]++;
    if (logFileFlagSet(LOG_HAPPINESS))
      writeLog("buildHappinessGraph()--  unitig %d (len %d) frag %d pos %d,%d (len %d) and unitig %d (len %d) frag %d pos %d,%d (len %d) -- GOOD!\n",
              loc.mleUtgID1, ULEN1, loc.mleFrgID1, frgBgn, frgEnd, frgLen,
              loc.mleUtgID2, ULEN2, loc.mleFrgID2, matBgn, matEnd, matLen);
    continue;

  markBad:

    //  Mark bad from the 3' end of the fragment till the upper limit where the mate should go.

    if (loc.mleUtgID1 == _tig->id()) {
      assert(loc.mleFrgID1 != 0);
      if (isReverse(loc.mlePos1) == false) {
        //  Mark bad for forward fagment 1
        assert(frgBgn < frgEnd);
        bgn = frgEnd;
        end = frgBgn + badMaxIntra;
        incrRange(badFwd, -1, bgn, end);
      } else {
        //  Mark bad for reverse fragment 1
        assert(frgEnd < frgBgn);
        bgn = frgBgn - badMaxIntra;
        end = frgEnd;
        incrRange(badRev, -1, bgn, end);
      }
    }

    if (loc.mleUtgID2 == _tig->id()) {
      assert(loc.mleFrgID2 != 0);
      if (isReverse(loc.mlePos2) == false) {
        //  Mark bad for forward fragment 2
        assert(matBgn < matEnd);
        bgn = matEnd;
        end = matBgn + badMaxIntra;
        incrRange(badFwd, -1, bgn, end);
      } else {
        //  Mark bad for reverse fragment 2
        assert(matEnd < matBgn);
        bgn = matBgn - badMaxIntra;
        end = matEnd;
        incrRange(badRev, -1, bgn, end);
      }
    }
  }  //  Over all MateLocationEntries in the table
}  //  buildHappinessGraph()
Пример #22
0
unsigned long long MACHFile::getSegment_filesize64(unsigned int nSegment)
{
    return readQword(getSegmentHeaderOffset(nSegment)+offsetof(segment_command_64,filesize),isReverse());
}
Пример #23
0
	void Tween::updateOverride(int step, int lastStep, bool isIterationStep, float delta)
    {
		if (equation == NULL) return;
        
		// Case iteration end has been reached
        
		if (!isIterationStep && step > lastStep)
        {
            (*accessor)(tweenTarget, type, TweenCMD::SET, isReverse(lastStep) ? startValues : targetValues);
			return;
		}
        
		if (!isIterationStep && step < lastStep)
        {
            (*accessor)(tweenTarget, type, TweenCMD::SET, isReverse(lastStep) ? targetValues : startValues);
			return;
		}
        
		// Validation
        
		assert(isIterationStep);
		assert(getCurrentTime() >= 0);
		assert(getCurrentTime() <= duration);
        
		// Case duration equals zero
        
		if (duration < 0.00000000001f && delta > -0.00000000001f)
        {
            (*accessor)(tweenTarget, type, TweenCMD::SET, isReverse(step) ? targetValues : startValues);
			return;
		}
        
        if (duration < 0.00000000001f && delta < 0.00000000001f) {
            (*accessor)(tweenTarget, type, TweenCMD::SET, isReverse(step) ? startValues : targetValues);
			return;
		}
        
		// Normal behavior
        
		float time = isReverse(step) ? duration - getCurrentTime() : getCurrentTime();
		float t = equation->compute(time/duration);
        
		if (waypointsCnt == 0 || pathAlgorithm == NULL)
        {
			for (int i=0; i<combinedAttrsCnt; i++)
            {
				accessorBuffer[i] = startValues[i] + t * (targetValues[i] - startValues[i]);
			}
            
		}
        else
        {
			for (int i=0; i<combinedAttrsCnt; i++)
            {
				pathBuffer[0] = startValues[i];
				pathBuffer[1+waypointsCnt] = targetValues[i];
				for (int ii=0; ii<waypointsCnt; ii++)
                {
					pathBuffer[ii+1] = waypoints[ii*combinedAttrsCnt+i];
				}
                
				accessorBuffer[i] = pathAlgorithm->compute(t, pathBuffer, waypointsCnt+2);
			}
		}
        
        (*accessor)(tweenTarget, type, TweenCMD::SET, accessorBuffer);
	}
Пример #24
0
unsigned int MACHFile::getSegment_flags64(unsigned int nSegment)
{
    return readDword(getSegmentHeaderOffset(nSegment)+offsetof(segment_command_64,flags),isReverse());
}
 void BaseTween::updateStep()
 {
     while (isValid(step))
     {
         if (!isIterationStep && currentTime+deltaTime <= 0)
         {
             isIterationStep = true;
             step -= 1;
             
             float delta = 0-currentTime;
             deltaTime -= delta;
             currentTime = duration;
             
             if (isReverse(step)) forceStartValues();
             else forceEndValues();
             callCallback(TweenCallback::BACK_START);
             updateOverride(step, step+1, isIterationStep, delta);
             
         }
         else if (!isIterationStep && currentTime+deltaTime >= repeatDelay)
         {
             isIterationStep = true;
             step += 1;
             
             float delta = repeatDelay-currentTime;
             deltaTime -= delta;
             currentTime = 0;
             
             if (isReverse(step)) forceEndValues(); else forceStartValues();
             callCallback(TweenCallback::START);
             updateOverride(step, step-1, isIterationStep, delta);
             
         }
         else if (isIterationStep && currentTime+deltaTime < 0)
         {
             isIterationStep = false;
             step -= 1;
             
             float delta = 0-currentTime;
             deltaTime -= delta;
             currentTime = 0;
             
             updateOverride(step, step+1, isIterationStep, delta);
             callCallback(TweenCallback::BACK_END);
             
             if (step < 0 && repeatCnt >= 0) callCallback(TweenCallback::BACK_COMPLETE);
             else currentTime = repeatDelay;
             
         }
         else if (isIterationStep && currentTime+deltaTime > duration)
         {
             isIterationStep = false;
             step += 1;
             
             float delta = duration-currentTime;
             deltaTime -= delta;
             currentTime = duration;
             
             updateOverride(step, step-1, isIterationStep, delta);
             callCallback(TweenCallback::END);
             
             if (step > repeatCnt*2 && repeatCnt >= 0) callCallback(TweenCallback::COMPLETE);
             currentTime = 0;
             
         }
         else if (isIterationStep)
         {
             float delta = deltaTime;
             deltaTime -= delta;
             currentTime += delta;
             updateOverride(step, step, isIterationStep, delta);
             break;
             
         }
         else
         {
             float delta = deltaTime;
             deltaTime -= delta;
             currentTime += delta;
             break;
         }
     }
 }
Пример #26
0
unsigned int MACHFile::getSection_nreloc32(unsigned int nSection)
{
    return readDword(getSectionHeaderOffset(nSection)+offsetof(section,nreloc),isReverse());
}
Пример #27
0
unsigned long long MACHFile::getSection_size64(unsigned int nSection)
{
    return readQword(getSectionHeaderOffset(nSection)+offsetof(section_64,size),isReverse());
}
Пример #28
0
unsigned int MACHFile::getHeader_ncmds()
{
    return readDword(offsetof(mach_header,ncmds),isReverse());
}
Пример #29
0
unsigned int MACHFile::getSection_flags64(unsigned int nSection)
{
    return readDword(getSectionHeaderOffset(nSection)+offsetof(section_64,flags),isReverse());
}
Пример #30
0
unsigned int MACHFile::getHeader_magic()
{
    return readDword(offsetof(mach_header,magic),isReverse());
}