Ejemplo n.º 1
0
RealTime RealTime::operator +(const RealTime &t) const {
	if (GetUsec() + t.GetUsec() >= ONE_MILLION) {
		return RealTime(GetSec() + t.GetSec() + 1, GetUsec() + t.GetUsec()
				- ONE_MILLION);
	} else {
		return RealTime(GetSec() + t.GetSec(), GetUsec() + t.GetUsec());
	}
}
Ejemplo n.º 2
0
RealTime RealTime::operator +(int msec) const {
	int usec = GetUsec() + msec * 1000;
	if (usec >= ONE_MILLION) {
		return RealTime(GetSec() + usec / ONE_MILLION, usec % ONE_MILLION);
	} else {
		return RealTime(GetSec(), usec);
	}
}
Ejemplo n.º 3
0
RealTime RealTime::operator -(int msec) const {
	int usec = GetUsec() - msec * 1000;
	if (usec < 0) {
		usec = -usec;
		return RealTime(GetSec() - usec / ONE_MILLION - 1, ONE_MILLION - usec
				% ONE_MILLION);
	} else {
		return RealTime(GetSec(), usec);
	}
}
Ejemplo n.º 4
0
void
PluginHostAdapter::convertFeatures(VampFeatureList *features,
                                   FeatureSet &fs)
{
    if (!features) return;

    unsigned int outputs = m_descriptor->getOutputCount(m_handle);

    for (unsigned int i = 0; i < outputs; ++i) {
        
        VampFeatureList &list = features[i];

        if (list.featureCount > 0) {

            Feature feature;
            feature.values.reserve(list.features[0].v1.valueCount);

            for (unsigned int j = 0; j < list.featureCount; ++j) {

                feature.hasTimestamp = list.features[j].v1.hasTimestamp;
                feature.timestamp = RealTime(list.features[j].v1.sec,
                                             list.features[j].v1.nsec);
                feature.hasDuration = false;

                if (m_descriptor->vampApiVersion >= 2) {
                    unsigned int j2 = j + list.featureCount;
                    feature.hasDuration = list.features[j2].v2.hasDuration;
                    feature.duration = RealTime(list.features[j2].v2.durationSec,
                                                list.features[j2].v2.durationNsec);
                }

                for (unsigned int k = 0; k < list.features[j].v1.valueCount; ++k) {
                    feature.values.push_back(list.features[j].v1.values[k]);
                }

                if (list.features[j].v1.label) {
                    feature.label = list.features[j].v1.label;
                }

                fs[i].push_back(feature);

                if (list.features[j].v1.valueCount > 0) {
                    feature.values.clear();
                }

                if (list.features[j].v1.label) {
                    feature.label = "";
                }
            }
        }
    }
}
Ejemplo n.º 5
0
void
BTimeSource::DirectRemoveMe(const media_node &node)
{
	// XXX this code has race conditions and is pretty dumb, and it
	// XXX won't detect nodes that crash and don't remove themself.

	CALLED();
	ASSERT(fSlaveNodes != NULL);
	BAutolock lock(fSlaveNodes->locker);

	if (fSlaveNodes->count == 0) {
		ERROR("BTimeSource::DirectRemoveMe no slots used\n");
		return;
	}
	for (int i = 0; i < SLAVE_NODES_COUNT; i++) {
		if (fSlaveNodes->node_id[i] == node.node && fSlaveNodes->node_port[i] == node.port) {
			fSlaveNodes->node_id[i] = 0;
			fSlaveNodes->node_port[i] = 0;
			fSlaveNodes->count -= 1;
			if (fSlaveNodes->count == 0) {
				// stop the time source
				time_source_op_info msg;
				msg.op = B_TIMESOURCE_STOP_IMMEDIATELY;
				msg.real_time = RealTime();
				TRACE_TIMESOURCE("stopping time source %" B_PRId32 "\n", ID());
				write_port(fControlPort, TIMESOURCE_OP, &msg, sizeof(msg));
			}
			return;
		}
	}
	ERROR("BTimeSource::DirectRemoveMe failed\n");
}
Ejemplo n.º 6
0
inline double StopWatch::UserTime()
{
#if (MFEM_TIMER_TYPE == 0)
   std::clock_t utime = user_time;
   if (Running)
      utime += (std::clock() - start_utime);
   return (double)(utime) / CLOCKS_PER_SEC;
#elif (MFEM_TIMER_TYPE == 1)
   clock_t curr_rtime, curr_utime, curr_stime;
   clock_t utime = user_time;
   if (Running)
   {
      Current(&curr_rtime, &curr_utime, &curr_stime);
      utime += (curr_utime - start_utime);
   }
   return (double)(utime) / my_CLK_TCK;
#elif (MFEM_TIMER_TYPE == 2)
   if (Running)
   {
      struct timespec curr_utime;
      GetUserTime(curr_utime);
      return ((user_time.tv_sec + (curr_utime.tv_sec - start_utime.tv_sec)) +
              1e-9*(user_time.tv_nsec +
                    (curr_utime.tv_nsec - start_utime.tv_nsec)));
   }
   else
   {
      return user_time.tv_sec + 1e-9*user_time.tv_nsec;
   }
#elif (MFEM_TIMER_TYPE == 3)
   return RealTime();
#endif
}
Ejemplo n.º 7
0
int64 EMMediaTimer::MetronomeNowTime()
{
	int64 vTime = 0;
	Lock();

	if(m_eState == EM_COUNTING_IN_FOR_PLAYBACK || m_eState == EM_COUNTING_IN_FOR_RECORDING)
	{
		int64 vTimePassedSinceCIStart = RealTime() - m_vSystemTimeWhenCountInStarted;
		vTime = m_vMetronomeThen + vTimePassedSinceCIStart;
		int64 vMetronomeNowFrames = EMMediaUtility::Instance() -> TimeToFrames(vTime, EMMediaUtility::Instance() -> GetSystemAudioFormat());
		if(vMetronomeNowFrames >= m_vNow-1)
		{
			Unlock();
			SetState((m_eState == EM_COUNTING_IN_FOR_PLAYBACK ? EM_PLAYING : EM_RECORDING));
		}
		else
			Unlock();
		return vTime;
	}
	else
	{
		Unlock();
		return NowTime();
	}

	Unlock();
	return vTime;
}
Ejemplo n.º 8
0
void
PluginHostAdapter::convertFeatures(VampFeatureList *features,
                                   FeatureSet &fs)
{
    if (!features) return;

    unsigned int outputs = m_descriptor->getOutputCount(m_handle);

    for (unsigned int i = 0; i < outputs; ++i) {
        
        VampFeatureList &list = features[i];

        if (list.featureCount > 0) {

            for (unsigned int j = 0; j < list.featureCount; ++j) {
                
                Feature feature;
                feature.hasTimestamp = list.features[j].hasTimestamp;
                feature.timestamp = RealTime(list.features[j].sec,
                                             list.features[j].nsec);

                for (unsigned int k = 0; k < list.features[j].valueCount; ++k) {
                    feature.values.push_back(list.features[j].values[k]);
                }

                if (list.features[j].label) {
                    feature.label = list.features[j].label;
                }

                fs[i].push_back(feature);
            }
        }
    }
}
Ejemplo n.º 9
0
void
ManageMetronomeDialog::slotPreviewPitch(int pitch)
{
    RG_DEBUG << "ManageMetronomeDialog::slotPreviewPitch";

    DeviceList *devices = m_doc->getStudio().getDevices();
    DeviceListConstIterator it;
    int count = 0;
    Device *dev = 0;

    for (it = devices->begin(); it != devices->end(); it++) {

        dev = *it;
        if (!isSuitable(dev)) continue;

        if (count == m_metronomeDevice->currentIndex()) break;
        count++;
    }

    if (!dev || !isSuitable(dev)) return;

    const MidiMetronome *metronome = getMetronome(dev);
    if (metronome == 0) return;

    InstrumentList list = dev->getPresentationInstruments();

    Instrument *inst =
        list[m_metronomeInstrument->currentIndex()];
    StudioControl::playPreviewNote(inst, pitch, MidiMaxValue, RealTime(0, 10000000));
}
Ejemplo n.º 10
0
//o---------------------------------------------------------------------------o
//|   Function    -  Log
//|   Date        -  Unknown
//|   Programmer  -  Unknown
//o---------------------------------------------------------------------------o
//|   Purpose     -  Writes to the logfile
//o---------------------------------------------------------------------------o
void CConsole::Log( const char *toLog, const char *filename, ... )
{
	va_list argptr;
	char msg[MAX_CONSOLE_BUFF];

	if( !cwmWorldState->ServerData()->ServerConsoleLogStatus() )
		return;

	va_start( argptr, filename );
	vsnprintf( msg, MAX_CONSOLE_BUFF, toLog, argptr );
	va_end( argptr );

	std::ofstream toWrite;
	std::string realFileName;	// EviLDeD: 022602: in windows a path can be max 512 chars, this at 128 coud potentially cause crashes if the path is longer than 128 chars
	if( cwmWorldState != NULL )
		realFileName = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + filename;
	else
		realFileName = filename;

	char timeStr[128];
	RealTime( timeStr );

	toWrite.open( realFileName.c_str(), std::ios::out | std::ios::app );
	if( toWrite.is_open() )
		toWrite << "[" << timeStr << "] " << msg << std::endl;
	toWrite.close();
	if( LogEcho() )
	{
		char mtemp[256];
		sprintf( mtemp, "%s%s\n", timeStr, msg );
		Print( mtemp );
	}
}
Ejemplo n.º 11
0
status_t
SystemTimeSource::TimeSourceOp(const time_source_op_info & op, void * _reserved)
{
	TRACE("######## SystemTimeSource::TimeSourceOp\n");
	bigtime_t real = RealTime();
	PublishTime(real, real, 1.0);
	return B_OK;
}
Ejemplo n.º 12
0
void
StarServer::UpdateWorld()
{
    long   new_time      = real_time;
    double delta         = new_time - frame_time;
    seconds       = max_frame_length;
    gui_seconds   = delta * 0.001;

    if (frame_time == 0)
    gui_seconds = 0;

    time_comp = 1;

    if (delta < max_frame_length * 1000)
    seconds = delta * 0.001;

    frame_time = new_time;

    Galaxy* galaxy = Galaxy::GetInstance();
    if (galaxy) galaxy->ExecFrame();

    Campaign* campaign = Campaign::GetCampaign();
    if (campaign) campaign->ExecFrame();

    if (paused) {
        if (world)
        world->ExecFrame(0);
    }

    else {
        game_time += (DWORD) (seconds * 1000);

        Drive::StartFrame();

        if (world)
        world->ExecFrame(seconds);
    }

    static DWORD refresh_time = 0;
    if (RealTime() - refresh_time > 1000) {
        refresh_time = RealTime();
        RedrawWindow(hwnd, 0, 0, RDW_ERASE|RDW_INVALIDATE);
    }
}
Ejemplo n.º 13
0
RealTime
RealTime::operator/(int d) const
{
    int secdiv = sec / d;
    int secrem = sec % d;

    double nsecdiv = (double(nsec) + ONE_BILLION * double(secrem)) / d;
    
    return RealTime(secdiv, int(nsecdiv + 0.5));
}
Ejemplo n.º 14
0
Observer::Observer()
{
	mCurrentTime = Time(-1, 0);
    mOurInitSide = '?';
	mOurSide = '?';
	mOppSide = '?';
	mSelfUnum = 0;
	mOppGoalieUnum = 0;
	mOurScore = 0;
	mOppScore = 0;

	mPlayMode = PM_Before_Kick_Off;

	mLastCycleBeginRealTime = RealTime(0, 0);
	mLastSightRealTime      = RealTime(0, 0);

	Reset();

    mIsBeginDecision = false;
	mSenseArrived = false;
	mSightArrived = false;

	mBallKickTime = Time(-3, 0);
	mBallPosByKick = Vector(0.0, 0.0);
	mBallVelByKick = Vector(0.0, 0.0);

	mPlayerMoveTime = Time(-3, 0);
	mPlayerPosByMove = Vector(0.0, 0.0);
	mPlayerVelByMove = Vector(0.0, 0.0);

	mPlayerDashTime = Time(-3, 0);
	mPlayerPosByDash = Vector(0.0, 0.0);
	mPlayerVelByDash = Vector(0.0, 0.0);

	mPlayerTurnTime = Time(-3, 0);
	mPlayerBodyDirByTurn = 0.0;

	mPlayerTurnNeckTime = Time(-3, 0);
	mPlayerNeckDirByTurnNeck = 0.0; // 脖子角度,绝对量

	mIsNewOppType = false;
}
Ejemplo n.º 15
0
/*******************************************************************************
 *
 *     Name:        cam_display_list( camera_t *, object_t * )
 *
 *     Purpose:     Display list of given objecst is given list of cameras
 *
 *     Parameters:
 *
 *         Input:   (camera_t *) input list of cameras
 *                  (object_t *) input list of objecst
 *
 *         Output:  graphics
 *
 *   Return value:  if mouse interaction is going on and too slow FALSE,
 *                  otherwise TRUE
 *
 *******************************************************************************/
int cam_display_list( camera_t *camera, object_t *object )
{
    double t = RealTime(), ct = CPUTime();

    int FitToPage = 0, nofcameras;
    camera_t *cam;

    if ( GlobalOptions.OutputPS ) {
       initglp( Tcl_GetVar( TCLInterp, "PSFileName", TCL_GLOBAL_ONLY ), 
                GlobalOptions.FitToPagePS );
    }
    if ( user_hook_before_all ) (*user_hook_before_all)( camera,object );

     nofcameras = 0;
     for( cam=camera; cam != NULL; cam = cam->Next, nofcameras++ );

    for( GlobalPass=0; GlobalPass < 2; GlobalPass++ )
    {
        for( cam=camera; cam != NULL; cam = cam->Next )
        {
            if ( !cam->OnOff ) continue;

            gra_set_projection( cam->ProjectionType, cam->FieldAngle,
                                cam->ViewportLowX, cam->ViewportHighX,
                                cam->ViewportLowY, cam->ViewportHighY,
	       	 	        cam->ClipNear, cam->ClipFar, nofcameras>1 );

            gra_push_matrix();

            gra_look_at(
                         cam->LookFromX, cam->LookFromY, cam->LookFromZ,
                            cam->LookAtX, cam->LookAtY, cam->LookAtZ,
                                  cam->UpX, cam->UpY, cam->UpZ
                       );

            if ( user_hook_camera_before ) (*user_hook_camera_before)( GlobalPass,cam,object,t );

            if ( !obj_display_list( object, t ) ) return FALSE;

            if ( user_hook_camera_after ) (*user_hook_camera_after)( GlobalPass,cam,object,t );

            gra_pop_matrix();

             if ( BreakLoop ) break;

        }
        if ( BreakLoop ) break;
    } 

    if ( user_hook_after_all ) (*user_hook_after_all)( camera,object );
    if ( GlobalOptions.OutputPS ) stopglp();

    return TRUE;
}
Ejemplo n.º 16
0
RealTime
RealTime::fromSeconds(double sec)
{
    if (sec != sec) { // NaN
        cerr << "ERROR: NaN/Inf passed to Vamp::RealTime::fromSeconds" << endl;
        return RealTime::zeroTime;
    } else if (sec >= 0) {
        return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5));
    } else {
        return -fromSeconds(-sec);
    }
}
Ejemplo n.º 17
0
void offlinehtml()//HTML
{
	char sect[512], hfile[512],time_str[80];
	unsigned int total,hr,min,sec,loopexit=0; //bugfix LB
	FILE *html;

	total=(uiCurrentTime-starttime)/MY_CLOCKS_PER_SEC;
	hr=total/3600;
	total-=hr*3600;
	min=total/60;
	total-=min*60;
	sec=total;

	cScpIterator* iter = NULL;
    char script1[1024];
    char script2[1024];

	strcpy(sect,"SECTION OFFLINE");

    iter = Scripts::HtmlStrm->getNewIterator(sect);
    if (iter==NULL) return;
	strcpy(script1, iter->getEntry()->getFullLine().c_str()); //discard  {

	strcpy(script1, iter->getEntry()->getFullLine().c_str());
	strcpy(hfile, script1);
	html = fopen(hfile, "w");
	if (html == NULL) // LB
	{
		WarnOut("Could not create html file, plz check html.xss\n");
		safedelete(iter);
		return;
	}

	do {
		iter->parseLine(script1, script2);
		if(!(strcmp(script1,"LINE"))) fprintf(html,"%s\n",script2);
		else if(!(strcmp(script1,"TIME"))) fprintf(html,RealTime(time_str));
		else if(!(strcmp(script1,"UPTIME"))) fprintf(html,"%i:%i:%i",hr,min,sec);
	} while( (script1[0]!='}') && (++loopexit < MAXLOOPS) );

	fclose(html);
	safedelete(iter);
}
Ejemplo n.º 18
0
RealTime
RIFFAudioFile::getLength()
{
    // Fixed header size = 44 but prove by getting it from the file too
    //
    unsigned int headerLength = 44;

    if (m_inFile) {
        m_inFile->seekg(16, std::ios::beg);
        headerLength = getIntegerFromLittleEndian(getBytes(m_inFile, 4));
        m_inFile->seekg(headerLength, std::ios::cur);
        headerLength += (16 + 8);
    }

    if (!m_bytesPerFrame || !m_sampleRate) return RealTime::zeroTime;

    double frames = (m_fileSize - headerLength) / m_bytesPerFrame;
    double seconds = frames / ((double)m_sampleRate);

    int secs = int(seconds);
    int nsecs = int((seconds - secs) * 1000000000.0);

    return RealTime(secs, nsecs);
}
Ejemplo n.º 19
0
void
BTimeSource::DirectAddMe(const media_node &node)
{
	// XXX this code has race conditions and is pretty dumb, and it
	// XXX won't detect nodes that crash and don't remove themself.

	CALLED();
	ASSERT(fSlaveNodes != NULL);
	BAutolock lock(fSlaveNodes->locker);

	if (fSlaveNodes->count == SLAVE_NODES_COUNT) {
		ERROR("BTimeSource::DirectAddMe out of slave node slots\n");
		return;
	}
	if (fNodeID == node.node) {
		ERROR("BTimeSource::DirectAddMe should not add itself to slave nodes\n");
		return;
	}
	for (int i = 0; i < SLAVE_NODES_COUNT; i++) {
		if (fSlaveNodes->node_id[i] == 0) {
			fSlaveNodes->node_id[i] = node.node;
			fSlaveNodes->node_port[i] = node.port;
			fSlaveNodes->count += 1;
			if (fSlaveNodes->count == 1) {
				// start the time source
				time_source_op_info msg;
				msg.op = B_TIMESOURCE_START;
				msg.real_time = RealTime();
				TRACE_TIMESOURCE("starting time source %" B_PRId32 "\n", ID());
				write_port(fControlPort, TIMESOURCE_OP, &msg, sizeof(msg));
			}
			return;
		}
	}
	ERROR("BTimeSource::DirectAddMe failed\n");
}
Ejemplo n.º 20
0
std::vector<MappedEvent> &
MappedBufMetaIterator::getPlayingAudioFiles(const RealTime &songPosition)
{
    // Clear playing audio segments
    //
    m_playingAudioSegments.clear();

#ifdef DEBUG_PLAYING_AUDIO_FILES
    std::cout << "MBMI::getPlayingAudioFiles" << std::endl;
#endif

    for (mappedsegments::iterator i = m_segments.begin();
         i != m_segments.end(); ++i) {

        MappedEventBuffer::iterator iter(*i);

        while (!iter.atEnd()) {
            if ((*iter).getType() != MappedEvent::Audio) {
                ++iter;
                continue;
            }

            MappedEvent evt(*iter);

            // Check for this track being muted or soloed
            //
            if (ControlBlock::getInstance()->isTrackMuted(evt.getTrackId()) == true) {
#ifdef DEBUG_PLAYING_AUDIO_FILES
                std::cout << "MBMI::getPlayingAudioFiles - "
                << "track " << evt.getTrackId() << " is muted" << std::endl;
#endif

                ++iter;
                continue;
            }

            if (ControlBlock::getInstance()->isSolo() == true &&
                evt.getTrackId() != ControlBlock::getInstance()->getSelectedTrack()) {
#ifdef DEBUG_PLAYING_AUDIO_FILES
                std::cout << "MBMI::getPlayingAudioFiles - "
                << "track " << evt.getTrackId() << " is not solo track" << std::endl;
#endif

                ++iter;
                continue;
            }

            // If there's an audio event and it should be playing at this time
            // then flag as such.
            //
            if (songPosition > evt.getEventTime() - RealTime(1, 0) &&
                songPosition < evt.getEventTime() + evt.getDuration()) {

#ifdef DEBUG_PLAYING_AUDIO_FILES
                std::cout << "MBMI::getPlayingAudioFiles - "
                          << "instrument id = " << evt.getInstrument()
                          << std::endl;

                std::cout << "MBMI::getPlayingAudioFiles - "
                          << " id " << evt.getRuntimeSegmentId()
                          << ", audio event time     = " << evt.getEventTime()
                          << std::endl;

                std::cout << "MBMI::getPlayingAudioFiles - "
                          << "audio event duration = " << evt.getDuration()
                          << std::endl;
#endif // DEBUG_PLAYING_AUDIO_FILES

                m_playingAudioSegments.push_back(evt);
            }

            ++iter;
        }

        //std::cout << "END OF ITERATOR" << std::endl << std::endl;
    }

    return m_playingAudioSegments;
}
const RealTime RealTime::now()
{
  return RealTime(std::chrono::steady_clock::now());
}
const RealTime RealTimeDifference::operator+(const RealTime& other) const
{
  return RealTime(this->duration_ + other.time_point_);
}
Ejemplo n.º 23
0
void
SequencerThread::run()
{
    SEQUENCER_DEBUG << "SequencerThread::run()";

    RosegardenSequencer &seq = *RosegardenSequencer::getInstance();

    TransportStatus lastSeqStatus = seq.getStatus();

    RealTime sleepTime = RealTime(0, 10000000);

    QTime timer;
    timer.start();

    bool exiting = false;

    seq.lock();

    while (!exiting) {

        bool atLeisure = true;

        //SEQUENCER_DEBUG << "Sequencer status is " << seq.getStatus();

        switch (seq.getStatus()) {

        case QUIT:
            exiting = true;
            break;

        case STARTING_TO_PLAY:
            if (!seq.startPlaying()) {
                // send result failed and stop Sequencer
                seq.setStatus(STOPPING);
            } else {
                seq.setStatus(PLAYING);
            }
            break;

        case PLAYING:
            if (!seq.keepPlaying()) {
                // there's a problem or the piece has
                // finished - so stop playing
                seq.setStatus(STOPPING);
            } else {
                // process any async events
                //
                seq.processAsynchronousEvents();
            }
            break;

        case STARTING_TO_RECORD:
            if (!seq.startPlaying()) {
                seq.setStatus(STOPPING);
            } else {
                seq.setStatus(RECORDING);
            }
            break;

        case RECORDING:
            if (!seq.keepPlaying()) {
                // there's a problem or the piece has
                // finished - so stop playing
                seq.setStatus(STOPPING);
            } else {
                // Now process any incoming MIDI events
                // and return them to the gui
                //
                seq.processRecordedMidi();

                // Now process any incoming audio
                // and return it to the gui
                //
                seq.processRecordedAudio();

                // Still process these so we can send up
                // audio levels as MappedEvents
                //
                // Bug #3542166.  This line can occasionally steal MIDI
                // events that are needed by processRecordedMidi().
                // Need to track down what the above "audio levels" comment
                // means and whether it is a serious issue.  If so, we need
                // to address it in a different way.  This line probably
                // never did anything as by the time it was run,
                // processRecordedMidi() would have cleaned out all the
                // incoming events.
                //seq.processAsynchronousEvents();
            }
            break;

        case STOPPING:
            // There's no call to RosegardenSequencer to actually process the
            // stop, because this arises from a call from the GUI
            // direct to RosegardenSequencer to start with
            seq.setStatus(STOPPED);

            SEQUENCER_DEBUG << "SequencerThread::run() - Stopped";
            break;

        case RECORDING_ARMED:
            SEQUENCER_DEBUG << "SequencerThread::run() - Sequencer can't enter \"RECORDING_ARMED\" state - internal error";
            break;

        case STOPPED:
        default:
            seq.processAsynchronousEvents();
            break;
        }

        // Update internal clock and send pointer position
        // change event to GUI - this is the heartbeat of
        // the Sequencer - it doesn't tick over without
        // this call.
        //
        // Also attempt to send the MIDI clock at this point.
        //
        seq.updateClocks();

        if (lastSeqStatus != seq.getStatus()) {
            SEQUENCER_DEBUG << "Sequencer status changed from " << lastSeqStatus << " to " << seq.getStatus();
            lastSeqStatus = seq.getStatus();
            atLeisure = false;
        }

        if (timer.elapsed() > 3000) {
            seq.checkForNewClients();
            timer.restart();
        }

        seq.unlock();

        // permitting synchronised calls from the gui or wherever to
        // be made now

        // If the sequencer status hasn't changed, sleep for a bit
        if (atLeisure)
            seq.sleep(sleepTime);

        seq.lock();
    }

    seq.unlock();
}
Ejemplo n.º 24
0
int vis_particle( geometry_t *geometry, element_model_t *model, particle_t *particles, double gtime )
{
    double *f_x0 = NULL, *f_y0 = NULL, *f_z0 = NULL, *f_c0 = NULL;
    double *PartX, *PartY, *PartZ, *PartC, *PartI;

    double x, y, z, c, CAdd = 0.0, CScl = 1.0;

    double LX,LY,LZ, LC;
    double r = 0.05, *C;

    double x0,y0,x1,y1,z0,z1;
    double k1,k2,k3,k4;

    double t, dt, ddt;

    double CEPS = particles->Tolerance;

    int i, j, k, n, quick;

    double s = MAX(MAX(xmax-xmin,ymax-ymin),zmax-zmin);

    float pnt[3], vec[3];

    if ( !GlobalOptions.StereoMode )
      if ( particles->Material->Diffuse[3]  < 1.0 )
      {
          if ( GlobalPass != 0 ) return TRUE;
      } else if ( GlobalPass == 0 )
      {
          return TRUE;
      }

    if ( particles->NofParticles < 1 ) return TRUE;
    if ( !particles->VectorData   || !particles->VectorData[0]->f )   return TRUE;
    if ( !particles->ParticleData || !particles->ParticleData[0]->f ) return TRUE;

    f_x0 = particles->VectorData[0]->f;
    f_y0 = particles->VectorData[1]->f;
    f_z0 = particles->VectorData[2]->f;

    gra_set_material( particles->Material );

    if ( particles->ColorData && particles->ColorData->f )
    {
        f_c0 = particles->ColorData->f;

        CAdd = particles->ColorData->min;
        if ( particles->ColorData->max - particles->ColorData->min != 0.0 )
            CScl = 1.0 / ( particles->ColorData->max - particles->ColorData->min );
        else
            CScl = 1.0;

        gra_set_colormap( particles->ColorMap );
    } else gra_set_colormap( NULL );

    PartX = particles->ParticleData[0]->f;
    PartY = particles->ParticleData[1]->f;
    PartZ = particles->ParticleData[2]->f;
    PartC = particles->ParticleData[3]->f;
    PartI = particles->ParticleData[4]->f;

    n = particles->NofParticles;
    if ( particles->SaveNofParticles != n )
    {
        {
          VARIABLE *var = var_new( "_particle_last", TYPE_DOUBLE,5,n );

          particles->X = &M(var,0,0);
          particles->Y = &M(var,1,0);
          particles->Z = &M(var,2,0);
          particles->C = &M(var,3,0);
          particles->I = &M(var,4,0);
        }

        for( i=0; i<n; i++ )
        {
            particles->X[i] = PartX[i]; 
            particles->Y[i] = PartY[i];
            particles->Z[i] = PartZ[i];
            particles->C[i] = PartC[i];
            particles->I[i] = PartI[i];
        }
        particles->SaveNofParticles = n;
    }

    quick  = (particles->LineStyle == line_style_line);
    quick |= epMouseDown && epMouseDownTakesTooLong;

    if ( quick )
    {
        if ( particles->Style == particle_style_vector )
        {
           gra_beg_lines();
        } else
        {
           gra_polygon_mode( GRA_LINE );
        }
        gra_sphere_quality( 1 );

        if ( !(epMouseDown && epMouseDownTakesTooLong) )
          gra_line_width( particles->LineWidth );
        else
          gra_line_width( 1.0 );
    }

    if ( !quick && (particles->LineStyle == line_style_cylinder) )
    {
        gra_sphere_quality( particles->LineQuality );
    }

    t = 0.0;
    for( i=0; i<n; i++ )
    {
        if ( particles->ParticleData[4]->f[i]<0 ) continue;
        
        x = PartX[i];
        y = PartY[i];
        z = PartZ[i];
        c = PartC[i];

        if ( particles->Advance && !epMouseDown )
        {
            particles->X[i] = x;
            particles->Y[i] = y;
            particles->Z[i] = z;
            particles->C[i] = c;
            particles->I[i] = PartI[i];

            t = 0.0;
            while( t < particles->OutDT-CEPS )
            {
                dt = MIN( particles->OutDT-t,particles->MaxDT );
                while( TRUE )
                {
                    if ( dt < 1.0E-9 ) break;

                    x0 = x1 = x;
                    y0 = y1 = y;
                    z0 = z1 = z;

                    switch( particles->IntegMethod )
                    {
                        case particle_integ_euler:
                           vis_Euler( particles, model, i, &x0, &y0, &z0, &c, t, dt, f_x0, f_y0, f_z0, f_c0 );
                           if ( particles->IntegPolicy==particle_policy_adaptive )
                           {
                               vis_Euler( particles, model, i, &x1, &y1, &z1, &c, t,  dt / 2, f_x0, f_y0, f_z0, f_c0 );
                               vis_Euler( particles, model, i, &x1, &y1, &z1, &c, t + dt / 2, dt / 2, f_x0, f_y0, f_z0, f_c0 );
                           }
                        break;

                        case particle_integ_runge_kutta:
                           vis_RungeKutta( particles, model, i, &x0, &y0, &z0, &c, t,  dt, f_x0, f_y0, f_z0, f_c0 );
                           if ( particles->IntegPolicy==particle_policy_adaptive )
                           {
                               vis_RungeKutta( particles, model, i, &x1, &y1, &z1, &c, t, dt / 2, f_x0, f_y0, f_z0, f_c0 );
                               vis_RungeKutta( particles, model, i, &x1, &y1, &z1, &c, t + dt / 2, dt / 2, f_x0, f_y0, f_z0, f_c0 );
                           }
                        break;
                    }

                    if ( particles->IntegPolicy == particle_policy_fixed )
                    {
                        x1 = x0;
                        y1 = y0;
                        z1 = z0;
                        break;
                    }

                    if ( ABS(x0-x1) < CEPS && ABS(y0-y1) < CEPS && ABS(z0-z1) < CEPS ) break;

                    dt /= 2;

                    if ( BreakLoop ) break;
                }
                if ( BreakLoop ) break;

                t += dt;
                x = x1;
                y = y1;
                z = z1;

                if ( dt < 1.0E-9 )
                {
                    fprintf( stderr, "For Your record: stepping didn't succeed.\n" );
                    break;
                }
                if ( BreakLoop ) break;
            }
            if ( BreakLoop ) break;

            PartX[i] = x;
            PartY[i] = y;
            PartZ[i] = z;
            PartC[i] = c;
        }
        if ( BreakLoop ) break;

        if ( particles->Style == particle_style_vector )
        {
            LX = particles->X[i];
            LY = particles->Y[i];
            LZ = particles->Z[i];
            LC = particles->C[i];

            LX = ( 2.0*(LX-xmin) - (xmax-xmin) ) / s;
            LY = ( 2.0*(LY-ymin) - (ymax-ymin) ) / s;
            LZ = ( 2.0*(LZ-zmin) - (zmax-zmin) ) / s;

            x = ( 2.0*(x-xmin) - (xmax-xmin) ) / s;
            y = ( 2.0*(y-ymin) - (ymax-ymin) ) / s;
            z = ( 2.0*(z-zmin) - (zmax-zmin) ) / s;

#if 0
if ( i==185 )
{
extern double viewx,viewy,viewz,tox,toy,toz,upx,upy,upz;
viewx=LX;
viewy=LY;
viewz=LZ;
tox=x;
toy=y;
toz=z;
upx=0;
if ( ABS(LX-x)>ABS(LY-y) || ABS(LZ-z)>ABS(LY-y) ) { upy=1; upz=0; }
else { upy=0; upz=1; }
continue;
}
if ( (i%10) ) continue;
#endif


            pnt[0] = LX;
            pnt[1] = LY;
            pnt[2] = LZ;

            vec[0] = x - LX;
            vec[1] = y - LY;
            vec[2] = z - LZ;

            r = sqrt( vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2] );
            gra_arrow( pnt,vec,CScl*(c-CAdd),particles->LineStyle,
                   particles->ArrowStyle,0.1*particles->LineWidth*r );
        } else {
            x = ( 2.0*(x-xmin) - (xmax-xmin) ) / s;
            y = ( 2.0*(y-ymin) - (ymax-ymin) ) / s;
            z = ( 2.0*(z-zmin) - (zmax-zmin) ) / s;
            c = CScl*(c-CAdd);
            gra_sphere( x,y,z,c,particles->LineWidth*r*c );
        }

        if ( epMouseDown && ( i & 30 ) )
        {
            if ( RealTime() - gtime > TooLong2 )
                if ( ++epMouseDownTakesTooLong > 3 )
                {
                    if ( quick )
                        if ( particles->Style == particle_style_vector )
                        {
                             gra_end_lines( );
                        } else
                        {
                             gra_polygon_mode( GRA_FILL );
                        }
                    return FALSE;
                } else gtime = RealTime();
        }
    }

    particles->Advance = FALSE;

    if ( quick )
        if ( particles->Style == particle_style_vector )
        {
             gra_end_lines( );
        } else
        {
             gra_polygon_mode( GRA_FILL );
        }

    return TRUE;
}
Ejemplo n.º 25
0
RealTime
RealTime::fromTimeval(const struct timeval &tv)
{
    return RealTime(tv.tv_sec, tv.tv_usec * 1000);
}
Ejemplo n.º 26
0
RealTime
RealTime::fromMilliseconds(int msec)
{
    return RealTime(msec / 1000, (msec % 1000) * 1000000);
}
Ejemplo n.º 27
0
RealTime
RealTime::fromSeconds(double sec)
{
    return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION + 0.5));
}
Ejemplo n.º 28
0
void updatehtml()//HTML
{
	double eps=0.00000000001;
	char sect[512],time_str[80],hfile[512] /*,sh[3],sm[3],ss[3]*/;
	int a, n=0;
	//unsigned long int ip;
	int gm=0,cns=0,ccount=0,npccount=0,loopexit=0;
	unsigned long int total;
	unsigned int hr,min,sec;
	FILE *html;

	cScpIterator* iter = NULL;
	//char script1[1024];
	//char script2[1024];
	std::string script1;
	std::string script2;

	strcpy(sect,"SECTION ONLINE");

	iter = Scripts::HtmlStrm->getNewIterator(sect);
	if (iter==NULL)
		return;
	script1 = iter->getEntry()->getFullLine(); //discard  {

	script1 = iter->getEntry()->getFullLine();
	strcpy( hfile, script1.c_str() );

	//html=fopen(hfile,"w+");
	//a=remove(hfile);
	//ConOut("html-a: %i %s\n",a,hfile);

	html=fopen(hfile,"w");  // remove old one first

	if (html == NULL) // LB
	{
		WarnOut("Could not create html file, please check html.xss\n");
		safedelete(iter);
		return;
	}


	do {
		iter->parseLine(script1, script2);
		if( script1 == "LINE" )
		{
			fprintf(html,"%s\n",script2.c_str() );
		}
		else if( script1 == "TIME" )
		{
			fprintf(html,"%s <BR>",RealTime(time_str));
		}
		else if( script1 == "NOW" )
		{
			P_CHAR pc= MAKE_CHAR_REF(currchar[n]);
			//if(online(currchar[n])) //bugfix LB
			if( ISVALIDPC(pc) && pc->IsOnline() )
			{
				fprintf(html,pc->getCurrentNameC());
				n++;
			}
		}
		else if( script1 == "WHOLIST" )
		{
			a=0;
			for (n=0;n<now;n++)
			{
				P_CHAR pc= MAKE_CHAR_REF(currchar[n]);

				//if (online(currchar[n])) // bugfix, LB
				if( ISVALIDPC(pc) && pc->IsOnline() )
				{
					a++;
					fprintf(html,"%i) %s <BR>\n",a,pc->getCurrentNameC()); // bugfix lb
				}
			}
		}
		else if( script1 == "NOWNUM")
			fprintf(html,"%i",now);
		else if( script1 == "ACCOUNTNUM" )
			fprintf(html,"%i",Accounts->Count());
		else if( script1 == "CHARCOUNT" )
		{
			if(ccount==0)
			{
				npccount=0;
				/*for(a=0;a<charcount;a++)
				{
					P_CHAR pc_a=MAKE_CHAR_REF(a);
					if(ISVALIDPC(pc_a)) {
						if(!pc_a->free) ccount++;
						if(pc_a->npc && !pc_a->free) npccount++;
					}
				}*/
			}
			fprintf(html,"%i",ccount);
		}
		else if( script1 == "NPCS" )
		{
			if(npccount==0)
			{
				ccount=0;
				/*for(a=0;a<charcount;a++)
				{
					P_CHAR pc_a=MAKE_CHAR_REF(a);
					if(ISVALIDPC(pc_a)) {
						if(!pc_a->free) ccount++;
						if(pc_a->npc && !pc_a->free) npccount++; //bugfix LB
					}
				}*/
			}
			fprintf(html,"%i",npccount);
		}
		else if( script1 == "ITEMCOUNT" )
		{
			//fprintf(html,"%i",itemcount);
		}
		else if( script1 == "UPTIME" )
		{
			total=(uiCurrentTime-starttime)/MY_CLOCKS_PER_SEC;
			hr=total/3600;
//			if(hr<10 && hr<=60) sprintf(sh,"0%lu",hr);
//			else sprintf(sh,"%lu",hr);
			total-=hr*3600;
			min=total/60;
//			if(min<10 && min<=60) sprintf(sm,"0%lu",min);
//			else sprintf(sm,"%lu",min);
			total-=min*60;
			sec=total;
//			if(sec<10 && sec <=60) sprintf(ss,"0%lu",sec);
//			else sprintf(ss,"%lu",sec);
//			fprintf(html,"%s:%s:%s",sh,sm,ss);
			fprintf(html,"%02d:%02d:%02d",hr,min,sec);
		}
		else if( script1 == "IP" )
		{
			//ip=inet_addr(serv[str2num(script2)-1][1]);
			fprintf(html,serv[str2num(script2)-1][1]);
		}
		else if( script1 == "GMNUM" )
		{
			if(gm==0)
			{
				for(a=0;a<now;a++)
				{
					P_CHAR pc_a=MAKE_CHAR_REF(currchar[a]);
					if(ISVALIDPC(pc_a) && clientInfo[a]->ingame ) {
						if( pc_a->IsGM() ) gm++;
						else if( pc_a->IsCounselor() ) cns++;
					}
				}
			}
			fprintf(html,"%i",gm);
		}
		else if( script1 == "CNSNUM" )
		{
			if(cns==0)
			{
				for(a=0;a<now;a++)
				{
					P_CHAR pc_a=MAKE_CHAR_REF(currchar[a]);
					if(ISVALIDPC(pc_a) && clientInfo[a]->ingame ) {
						if( pc_a->IsGM() ) gm++;
						else if( pc_a->IsCounselor() ) cns++; //bugfix LB
					}
				}
			}
			fprintf(html,"%i",cns);
		}
		else if( script1 == "PDUMP" )
		{
			fprintf(html,"Network code: %fmsec [%i samples] <BR>",(float)((float)networkTime/(float)networkTimeCount),  networkTimeCount);
			fprintf(html,"Timer code: %fmsec [%i samples] <BR>" , (float)((float)timerTime/(float)timerTimeCount) , timerTimeCount);
			fprintf(html,"Auto code: %fmsec [%i samples] <BR>" , (float)((float)autoTime/(float)autoTimeCount) , autoTimeCount);
			fprintf(html,"Loop Time: %fmsec [%i samples] <BR>" , (float)((float)loopTime/(float)loopTimeCount) , loopTimeCount);
//			fprintf(html,"Characters: %i/Dynamic    Items: %i/Dynamic <BR>" , charcount, itemcount);
			if (!(loopTime <eps ||  loopTimeCount<eps)) //Bugfix LB
				fprintf(html,"Simulation Cycles: %f per sec <BR>" , (1000.0*(1.0/(float)((float)loopTime/(float)loopTimeCount))));
			else fprintf(html,"Simulation Cylces: too fast to be measured <BR>");

		}
		else if( script1 == "SIMCYC" )
		{
			if (!(loopTime <eps ||  loopTimeCount<eps))
				fprintf(html,"%f" , (1000.0*(1.0/(float)((float)loopTime/(float)loopTimeCount))));
			else fprintf(html,"too fast to be measured");
		}
		else if( script1 == "UDTIME" )
			fprintf(html,"%f",(float)(SrvParms->html/60));
		else if( script1 == "VER" ) fprintf(html,"%s %s [%s]",VER, VERNUMB, OS);
	} while( (script1[0]!='}') && (++loopexit < MAXLOOPS) );

	fclose(html);
	safedelete(iter);
}
Ejemplo n.º 29
0
bigtime_t
BTimeSource::Now()
{
	PRINT(8, "CALLED BTimeSource::Now()\n");
	return PerformanceTimeFor(RealTime());
}