void AnimationGroup::changed(ConstFieldMaskArg whichField, 
                            UInt32            origin,
                            BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if((whichField & AnimationsFieldMask) || (whichField & OffsetFieldMask))
    {
        for(UInt32 i = 0; i < getMFAnimations()->size(); ++i)
        {
            getAnimations(i)->setOffset(getOffset());
            //commitChanges();
        }
    }
    if((whichField & AnimationsFieldMask) || (whichField & SpanFieldMask))
    {
        for(UInt32 i = 0; i < getMFAnimations()->size(); ++i)
        {
            getAnimations(i)->setSpan(getSpan());
            //commitChanges();
        }
    }
}
Exemple #2
0
bool FrTextSpans::iterateVA(FrTextSpanIterFunc *fn, va_list args) const
{
   bool success = (fn != 0) ;
   for (size_t i = 0 ; i < spanCount() && success ; i++)
      {
      FrSafeVAList(args) ;
      success = fn(getSpan(i),FrSafeVarArgs(args)) ;
      FrSafeVAListEnd(args) ;
      }
   return success ;
}
Exemple #3
0
FrList *FrTextSpans::wordList() const
{
   FrList *words = 0 ;
   FrList **end = &words ;
   for (size_t i = 0 ; i < spanCount() ; i++)
      {
      const FrTextSpan *span = getSpan(i) ;
      char *text = span->getText() ;
      words->pushlistend(new FrString(text,strlen(text),1,false),end) ;
      }
   *end = 0 ;				// properly terminate the list
   return words ;
}
Exemple #4
0
/*!\fn Real32 Animation::getCycleLength(void) const
 *
 * \brief Get the length, in seconds, of one cycle of the animation.
 *
 * This length takes into account the span and scale of the animation.
 *
 * @return The length, in seconds, of one cycle of the animation.
 */
Real32 Animation::getCycleLength(void) const
{
    Real32 UnclippedCycleLength;
    if(getSpan() > 0.0f)
    {
        UnclippedCycleLength = getSpan();
    }
    else
    {
        UnclippedCycleLength = getUnclippedCycleLength();
    }

    if(UnclippedCycleLength < 0.0f ||
       getScale() == 0.0f)
    {
        return -1.0f;
    }
    else
    {
        return UnclippedCycleLength / getScale();
    }
}
Exemple #5
0
void Driver::start(void)
{
    linked_pointer<Driver::callback> cb = callbacks;

    dbi::start();

    while(is(cb)) {
        cb->start();
        cb.next();
    }

#ifndef _MSWINDOWS_
    unsigned pos;
    Segment *seg;
    FILE *fp;

    remove(env("boards"));

    if(board_count) {
        fp = fopen(env("boards"), "w");
        pos = 0;
        while(fp && pos < board_count) {
            seg = getBoard(pos++);
            if(seg) {
                fprintf(fp, "%03d %04d %04d %s\n",
                    seg->getInstance(), seg->getFirst(), seg->getCount(), seg->getDescription());
            }
        }
        if(fp)
            fclose(fp);
    }

    remove(env("spans"));

    if(span_count) {
        fp = fopen(env("spans"), "w");
        pos = 0;
        while(fp && pos < span_count) {
            seg = getSpan(pos++);
            if(seg) {
                fprintf(fp, "%03d %04d %04d %s\n",
                    seg->getInstance(), seg->getFirst(), seg->getCount(), seg->getDescription());
            }
        }
        if(fp)
            fclose(fp);
    }

#endif
}
Exemple #6
0
FrList *FrTextSpans::printable() const
{
   FrList *result = 0 ;
   for (size_t i = 0 ; i < spanCount() ; i++)
      {
      pushlist(getSpan(i)->printable(),result) ;
      }
   FrList *meta_fields = m_metadata.fieldNames() ;
   if (meta_fields)
      {
      pushlist(m_metadata.deepcopy(),result) ;
      meta_fields->freeObject() ;
      }
   result = listreverse(result) ;
   pushlist(new FrString(originalString()),result) ;
   return result ;
}
Exemple #7
0
FrTextSpan *FrTextSpans::addSpan(const FrTextSpan *span, bool only_if_unique,
				 FrTextSpan_Operation score_op,
				 FrTextSpan_Operation weight_op)
{
   if (weight_op == FrTSOp_Default)
      weight_op = score_op ;
   if (only_if_unique || score_op != FrTSOp_None || weight_op != FrTSOp_None)
      {
      // check whether the span already exists
      for (size_t i = 0 ; i < spanCount() ; i++)
	 {
	 if (getSpan(i)->equal(span))
	    {
	    if (only_if_unique)
	       return 0 ;		// didn't add the span
	    else
	       {
	       m_spans[i].updateScore(span->score(),score_op) ;
	       m_spans[i].updateWeight(span->weight(),weight_op) ;
	       m_spans[i].updateMetaData(span->metaData()) ;
	       return &m_spans[i] ;
	       }
	    }
	 }
      }
   // adding the new span
   FrTextSpan *new_spans = FrNewR(FrTextSpan,m_spans,m_spancount+1) ;
   if (new_spans)
      {
      m_spans = new_spans ;
      FrTextSpan *newspan = &m_spans[m_spancount] ;
      m_spans[m_spancount].init(span,this) ;
      m_spans[m_spancount].updateMetaData(span->metaData()) ;
      m_spancount++ ;
      m_sorted = false ;
      return newspan ;
      }
   else
      return 0 ;
}
Exemple #8
0
bool FrTextSpans::removeMatchingSpansVA(FrTextSpanMatchFunc *fn,va_list args)
{
   bool removed = false ;
   if (fn)
      {
      size_t dest = 0 ;
      for (size_t i = 0 ; i < spanCount() ; i++)
	 {
	 FrTextSpan *span = getSpan(i) ;
	 FrSafeVAList(args) ;
	 if (fn(span,FrSafeVarArgs(args)))
	    {
	    m_spans[i].clear() ;
	    removed = true ;
	    }
	 else
	    m_spans[dest++] = m_spans[i] ;
	 FrSafeVAListEnd(args) ;
	 }
      m_spancount = dest ;
      }
   return removed ;
}
Exemple #9
0
/*!
 * \fn bool OSG::Animation::update(const Time& ElapsedTime)
 *
 * \brief Update the animation with the time since the last update
 *
 * The result of the animation will also be applied to the
 * object it is connected to.
 *
 * \param[in] ElapsedTime The time, in seconds, since the previous call to
 * update.
 */
bool Animation::update(const Time& ElapsedTime)
{
    if(!_IsPlaying || _IsPaused)
    {
        return false;
    }

    //Increment the updated animations statistic
    StatIntElem *NAnimationsStatElem = StatCollector::getGlobalElem(statNAnimations);
    if(NAnimationsStatElem) { NAnimationsStatElem->inc(); }

    //Start the  animation update time statistic
    StatTimeElem *AnimUpdateTimeStatElem = StatCollector::getGlobalElem(statAnimUpdateTime);
    if(AnimUpdateTimeStatElem) { AnimUpdateTimeStatElem->start(); }

    _CurrentTime += getScale()*ElapsedTime;
    UInt32 PreUpdateCycleCount(getCycles());
    if(getCycling() < 0 || PreUpdateCycleCount < getCycling())
    {
        Real32 CycleLength(getCycleLength() * getScale());

        //Check if the Animation Time is past the end
        if(_CurrentTime >= CycleLength)
        {
            //Update the number of cycles completed
            setCycles( (CycleLength <= 0.0f) ? (0): (static_cast<UInt32>( osgFloor( _CurrentTime / CycleLength ) )) );
            //commitChanges();
        }
        Real32 t(_CurrentTime);

        if(getCycling() > 0 && getCycles() >= getCycling())
        {
            if(getSpan() > 0.0f)
            {
                t = getSpan();
            }
            t -= 0.0001f;
        }
        else
        {
            if(getSpan() > 0.0f)
            {
                t -= osgFloor(_CurrentTime/getSpan())*getSpan();
            }
        }
        t += getOffset();

        //Internal Update
        internalUpdate(t, _PrevTime);


        //If the number of cycles has changed
        if(getCycles() != PreUpdateCycleCount)
        {
            if(getCycling() > 0 && getCycles() >= getCycling())
            {
                //Animation has reached the end
                //Remove the Animation from it's update producer
                _UpdateEventConnection.disconnect();
                _IsPlaying = false;

                //Produce the Ended event
                produceAnimationEnded();
            }
            else
            {
                //Animation hasn't finished yet
                //Produce the Cycled event
                produceAnimationCycled();
            }
        }
    }

    _PrevTime = _CurrentTime;

    //Stp[ the  animation update time statistic
    if(AnimUpdateTimeStatElem) { AnimUpdateTimeStatElem->stop(); }

    //Return true if the animation has completed its number of cycles, false otherwise
    return (getCycling() > 0 && getCycles() >= getCycling());
}
bool AnimationGroup::update(const Time& ElapsedTime)
{
    if(!_IsPlaying || _IsPaused)
    {
        return false;
    }
    _CurrentTime += getScale()*ElapsedTime;

    UInt32 PreUpdateCycleCount(getCycles());
    if(getCycling() < 0 || PreUpdateCycleCount < getCycling())
    {
        Real32 CycleLength(getCycleLength() * getScale());
        
        //Check if the Animation Time is past the end
        if(_CurrentTime >= CycleLength)
        {
            //Update the number of cycles completed
            setCycles( (CycleLength <= 0.0f) ? (0): (static_cast<UInt32>( osgFloor( _CurrentTime / CycleLength ) )) );
            //commitChanges();
        }
        Real32 t(_CurrentTime);

        if(getCycling() > 0 && getCycles() >= getCycling())
        {
            if(getSpan() > 0.0f)
            {
                t = getSpan();
            }
            else
            {
                t = CycleLength;
            }
            t -= 0.0001f;
        }
        else
        {
            if(getSpan() > 0.0f)
            {
                t -= osgFloor(_CurrentTime/getSpan())*getSpan();
            }
        }
        t += getOffset();

        //Internal Update
        for(UInt32 i = 0; i < getMFAnimations()->size(); ++i)
        {
            getAnimations(i)->internalUpdate(t, _PrevTime);
        }

        //If the number of cycles has changed
        if(getCycles() != PreUpdateCycleCount)
        {
            if(getCycling() > 0 && getCycles() >= getCycling())
            {
                //Animation has reached the end
                //Remove the Animation from it's update producer
                _UpdateEventConnection.disconnect();
                _IsPlaying = false;

                //Produce the Ended event
                produceAnimationEnded();
            }
            else
            {
                //Animation hasn't finished yet
                //Produce the Cycled event
                produceAnimationCycled();
            }
        }
    }

    _PrevTime = _CurrentTime;

    //Return true if the animation has completed its number of cycles, false otherwise
    return (getCycling() > 0 && getCycles() >= getCycling());
}