Exemple #1
0
// Zeichnen der Spielkomponenten
void Game::draw()
{
    float elapsed = getElapsedTime();

    CL_Draw::fill(window.get_gc(), window.get_viewport(), CL_Colorf::black);

    for(std::list<GameComponent*>::iterator it = components.begin(); it != components.end(); ++it)
        (*it)->draw(elapsed);
}
void StartPhysics()
{
	// Update the time step
	gDeltaTime = getElapsedTime();

	// Start collision and dynamics for delta time since the last frame
    gScene->simulate(gDeltaTime);
	gScene->flushStream();
}
Exemple #3
0
void writeNodeFlooding()
{
    int    j, n = 0;
    int    days, hrs, mins;
    double t;

    WRITE("");
    WRITE("*********************");
    WRITE("Node Flooding Summary");
    WRITE("*********************");
    WRITE("");

    for ( j = 0; j < Nobjects[NODE]; j++ )
    {
        if ( Node[j].type == OUTFALL ) continue;
        if ( NodeStats[j].timeFlooded == 0.0 ) continue;
        t = MAX(0.01, (NodeStats[j].timeFlooded / 3600.0));

////  Following code segment was modified for release 5.0.019.  ////           //(5.0.019 - LR)
        if ( n == 0 )
        {
            WRITE("Flooding refers to all water that overflows a node, whether it ponds or not.");
            fprintf(Frpt.file, 
"\n  --------------------------------------------------------------------------"
"\n                                                             Total   Maximum"
"\n                                 Maximum   Time of Max       Flood    Ponded"
"\n                        Hours       Rate    Occurrence      Volume");
            if ( RouteModel == DW ) fprintf(Frpt.file, "     Depth");
            else                    fprintf(Frpt.file, "    Volume");
            fprintf(Frpt.file, 
"\n  Node                 Flooded       %3s   days hr:min    %8s",
                FlowUnitWords[FlowUnits], VolUnitsWords[UnitSystem]);
            if ( RouteModel == DW )      fprintf(Frpt.file, "    %6s",
                                         PondingUnitsWords[UnitSystem]);
            else if ( UnitSystem == US ) fprintf(Frpt.file, "  1000 ft3");
            else                         fprintf(Frpt.file, "   1000 m3");
            fprintf(Frpt.file,
"\n  --------------------------------------------------------------------------");
            n = 1;
        }
        fprintf(Frpt.file, "\n  %-20s", Node[j].ID);
        fprintf(Frpt.file, " %7.2f ", t);
        fprintf(Frpt.file, FlowFmt, NodeStats[j].maxOverflow * UCF(FLOW));
        getElapsedTime(NodeStats[j].maxOverflowDate, &days, &hrs, &mins);
        fprintf(Frpt.file, "   %4d  %02d:%02d", days, hrs, mins);
		fprintf(Frpt.file, "%12.3f", NodeStats[j].volFlooded * Vcf);
        if ( RouteModel == DW )
            fprintf(Frpt.file, " %9.2f", NodeStats[j].maxDepth * UCF(LENGTH)); //(5.0.019 - LR)
        else
            fprintf(Frpt.file, " %9.3f", NodeStats[j].maxPondedVol /
                                         1000.0 * UCF(VOLUME));
    }
////  End of modified code segment.  ////                                      //(5.0.019 - LR)

    if ( n == 0 ) WRITE("No nodes were flooded.");
    WRITE("");
}
Exemple #4
0
XmlNodeHelper
Meta::getXml() const {
    XmlNodeHelper result;
    xmlNodePtr last_insert_node = NULL;
    if (MetaCore::undefinedElapsedTime() != getElapsedTime()) {
        TypedValue value((boost::int64_t)getElapsedTime());
        processNewMetaNode(ELAPSED_TIME_META_KEY, value, result, last_insert_node);
    }

    if (undefinedExpireTime() != meta_data_->expire_time_) {
        TypedValue value((boost::int64_t)meta_data_->expire_time_);
        processNewMetaNode(EXPIRE_TIME_META_KEY, value, result, last_insert_node);
    }

    if (undefinedExpireTime() != meta_data_->last_modified_) {
        TypedValue value((boost::int64_t)meta_data_->last_modified_);
        processNewMetaNode(LAST_MODIFIED_META_KEY, value, result, last_insert_node);
    }

    const std::map<std::string, TypedValue> &values = meta_data_->child_.values();
    for(std::map<std::string, TypedValue>::const_iterator it = values.begin();
        it != values.end();
        ++it) {
        if (!allowKey(it->first)) {
            continue;
        }
        processNewMetaNode(it->first, it->second, result, last_insert_node);
    }

    if (NULL == meta_data_->core_.get()) {
        return result;
    }

    const std::map<std::string, TypedValue> &core_values = meta_data_->core_->values();
    for(std::map<std::string, TypedValue>::const_iterator it = core_values.begin();
        it != core_values.end();
        ++it) {
        if (meta_data_->child_.has(it->first)) {
            continue;
        }
        processNewMetaNode(it->first, it->second, result, last_insert_node);
    }
    return result;
}
void InitNx()
{
	// Create a memory allocator
    gAllocator = new UserAllocator;

    // Create the physics SDK
	gPhysicsSDK = CreatePhysics();

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = gDefaultGravity;
	sceneDesc.simType				= NX_SIMULATION_HW;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
	if(!gScene){ 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

    // Set Core Dump directory
	char buff[512];
	FindMediaFile(fnameCD, buff);
#ifdef WIN32
	SetCurrentDirectory(buff);
#elif LINUX
	chdir(buff);
#endif

	// Create the objects in the scene
	NxActor* groundPlane = CreateGroundPlane();

	NxActor* box = CreateBox(NxVec3(5,0,0), NxVec3(0.5,1,0.5), 20);
	NxActor* sphere = CreateSphere(NxVec3(0,0,0), 1, 10);
	NxActor* capsule = CreateCapsule(NxVec3(-5,0,0), 2, 0.5, 10);
//	pyramid = CreatePyramid(NxVec3(0,0,0), NxVec3(1,0.5,1.5), 10);

	AddUserDataToActors(gScene);

	gSelectedActor = capsule;
//	gSelectedActor = pyramid;

	// Initialize HUD
	InitializeHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}
void Game::update()
{
	double elapsedTime = getElapsedTime();

	_respawnTime += elapsedTime;
	if (_respawnTime > RESPAWN_TIME)
	{
		_respawnTime = 0.0;
	}
}
Exemple #7
0
  boost::posix_time::time_duration
  TimeFrame::getRemainingTime() const
  {
    static const boost::posix_time::time_duration zeroTime =
        boost::posix_time::microseconds(0);
    const boost::posix_time::time_duration remaining = getElapsedTime()
        - mTimeSlice;

    return std::max<boost::posix_time::time_duration>(zeroTime, -remaining);
  }
Exemple #8
0
// Updaten der Spielkomponenten
void Game::update()
{
    float elapsed = getElapsedTime();

    if (pause)
        return;

    for (std::list<GameComponent*>::iterator it = components.begin(); it != components.end(); ++it)
        (*it)->update(elapsed);
}
Exemple #9
0
void Menu::update(Game& game, sf::Time frameTime)
{
    State::update(game, frameTime);
    
    const int duration = 600;
    const int offset = 200;
    const int totalDuration = duration + m_items.size()*200;
    
    if (getElapsedTime().asMilliseconds() <= totalDuration)
    {
        int totalOffset = 0;
        for (std::vector<sf::Text>::iterator it = m_items.begin(); it != m_items.end(); ++it)
        {
            int t = getElapsedTime().asMilliseconds() - totalOffset;
            it->setScale((t < 0)? 0 : ((t > duration)? 1.f : std::sin(t * (M_PI/2) / duration)), 1.f);
            totalOffset += offset;
        }
    }
}
Exemple #10
0
void clsTimers::getElapsedTime(char *msg)
{
	unsigned long long elapssd = 0;
	elapssd = getElapsedTime();
	
	int minutesFromSecs = (elapssd/1000)/60;
	int secsFromMinutes = (elapssd/1000) % 100;
	
	snprintf(msg,128,"%02d:%02d:%03lld",minutesFromSecs,secsFromMinutes,elapssd%1000);
}
void InitNx()
{
	// Create a memory allocator
    gAllocator = new UserAllocator;

    // Create the physics SDK
    gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator);
    if (!gPhysicsSDK)  return;

	// Set the physics parameters
	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 2);
	gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
	gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1);

    // Create the scene
    NxSceneDesc sceneDesc;
    sceneDesc.gravity               = gDefaultGravity;
    sceneDesc.simType				= NX_SIMULATION_HW;
    gScene = gPhysicsSDK->createScene(sceneDesc);	
 if(!gScene){ 
		sceneDesc.simType				= NX_SIMULATION_SW; 
		gScene = gPhysicsSDK->createScene(sceneDesc);  
		if(!gScene) return;
	}

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

	// Create the objects in the scene
	CreateGroundPlane();

	mainBox = CreateMainObject();

	gSelectedActor = mainBox;
	gCameraPos = NxVec3(0,15,-50);
	gCameraSpeed = 20;
    gForceStrength = 50000000;

	// Initialize HUD
	InitializeHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}
Exemple #12
0
      /**
       *  randomized exponential backoff, stolen from Polite.hpp
       */
      void backoff()
      {
          if (tries > 0 && tries <= MAX_BACKOFF_RETRIES) {
              // what time is it now
              unsigned long long starttime = getElapsedTime();

              // how long should we wait (random)
              unsigned long delay = rand_r(&seed);
              delay = delay % (1 << (tries + MIN_BACKOFF));

              // spin until /delay/ nanoseconds have passed.  We can do
              // whatever we want in the spin, as long as it doesn't have
              // an impact on other threads
              unsigned long long endtime;
              do {
                  endtime = getElapsedTime();
              } while (endtime < starttime + delay);
          }
          tries++;
      }
Exemple #13
0
void KeyframeAnimation::fetchIntervalEndpointsForProperty(CSSPropertyID property, const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& prog) const
{
    // Find the first key
    double elapsedTime = getElapsedTime();
    if (m_animation->duration() && m_animation->iterationCount() != Animation::IterationCountInfinite)
        elapsedTime = std::min(elapsedTime, m_animation->duration() * m_animation->iterationCount());

    const double fractionalTime = this->fractionalTime(1, elapsedTime, 0);

    size_t numKeyframes = m_keyframes.size();
    if (!numKeyframes)
        return;
    
    ASSERT(!m_keyframes[0].key());
    ASSERT(m_keyframes[m_keyframes.size() - 1].key() == 1);
    
    int prevIndex = -1;
    int nextIndex = -1;
    
    // FIXME: with a lot of keys, this linear search will be slow. We could binary search.
    for (size_t i = 0; i < numKeyframes; ++i) {
        const KeyframeValue& currKeyFrame = m_keyframes[i];

        if (!currKeyFrame.containsProperty(property))
            continue;

        if (fractionalTime < currKeyFrame.key()) {
            nextIndex = i;
            break;
        }
        
        prevIndex = i;
    }

    double scale = 1;
    double offset = 0;

    if (prevIndex == -1)
        prevIndex = 0;

    if (nextIndex == -1)
        nextIndex = m_keyframes.size() - 1;

    const KeyframeValue& prevKeyframe = m_keyframes[prevIndex];
    const KeyframeValue& nextKeyframe = m_keyframes[nextIndex];

    fromStyle = prevKeyframe.style();
    toStyle = nextKeyframe.style();
    
    offset = prevKeyframe.key();
    scale = 1.0 / (nextKeyframe.key() - prevKeyframe.key());

    prog = progress(scale, offset, prevKeyframe.timingFunction(name()));
}
 void SceniXQGLSceneRendererWidget::hidNotify( dp::util::PropertyId property )
 {
   SceniXQGLWidget::hidNotify( property );
   if ( m_manipulator && m_manipulatorAutoRefresh )
   {
     if ( m_manipulator->updateFrame( getElapsedTime() ) )
     {
       update();
     }
   }
 }
Exemple #15
0
void App::draw()
{
    if( _needUpdate )  update();

    setTime( getElapsedTime() );                // [seconds]
    _scene->animate( *this, _config );

    _viewer->frame( *_scene );
    CHECK_GLERROR( "App::draw" );

    updateStats();
}
Exemple #16
0
void MovingDots::drawFrame(shared_ptr<StimulusDisplay> display) {
    //
    // If we're drawing to the main display, update dots
    //
    
    if (display->getCurrentContextIndex() == 0) {
        currentTime = getElapsedTime();
        if (previousTime != currentTime) {
            updateParameters();
            updateDots();
            previousTime = currentTime;
        }
    }
    
    if (0 == currentNumDots) {
        // No dots, so nothing to draw
        return;
    }
    
    //
    // Draw the dots
    //
    
    glPushMatrix();
    glTranslatef(fieldCenterX->getValue().getFloat(), fieldCenterY->getValue().getFloat(), 0.0f);
    glScalef(currentFieldRadius, currentFieldRadius, 1.0f);
    glRotatef(direction->getValue().getFloat(), 0.0f, 0.0f, 1.0f);
    
    // Enable antialiasing so dots are round, not square
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glBlendEquation(GL_FUNC_ADD);
    glEnable(GL_POINT_SMOOTH);
    glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
    
    glColor4f(red->getValue().getFloat(),
              green->getValue().getFloat(),
              blue->getValue().getFloat(),
              alpha->getValue().getFloat());

    glEnableClientState(GL_VERTEX_ARRAY);

    glPointSize(dotSize->getValue().getFloat() * dotSizeToPixels[display->getCurrentContextIndex()]);
    glVertexPointer(verticesPerDot, GL_FLOAT, 0, &(dotPositions[0]));
    glDrawArrays(GL_POINTS, 0, currentNumDots);

    glDisableClientState(GL_VERTEX_ARRAY);
    
    glDisable(GL_BLEND);
    glDisable(GL_POINT_SMOOTH);
    
    glPopMatrix();
}
void AnimationBase::fireAnimationEventsIfNeeded()
{
    if (!m_compAnim)
        return;

    // If we are waiting for the delay time to expire and it has, go to the next state
    if (m_animState != AnimationStateStartWaitTimer && m_animState != AnimationStateLooping && m_animState != AnimationStateEnding)
        return;

    // We have to make sure to keep a ref to the this pointer, because it could get destroyed
    // during an animation callback that might get called. Since the owner is a CompositeAnimation
    // and it ref counts this object, we will keep a ref to that instead. That way the AnimationBase
    // can still access the resources of its CompositeAnimation as needed.
    RefPtr<AnimationBase> protector(this);
    RefPtr<CompositeAnimation> compProtector(m_compAnim);

    // Check for start timeout
    if (m_animState == AnimationStateStartWaitTimer) {
        if (beginAnimationUpdateTime() - m_requestedStartTime >= m_animation->delay())
            updateStateMachine(AnimationStateInputStartTimerFired, 0);
        return;
    }

    double elapsedDuration = getElapsedTime();

    // Check for end timeout
    if (m_totalDuration >= 0 && elapsedDuration >= m_totalDuration) {
        // We may still be in AnimationStateLooping if we've managed to skip a
        // whole iteration, in which case we should jump to the end state.
        m_animState = AnimationStateEnding;

        // Fire an end event
        updateStateMachine(AnimationStateInputEndTimerFired, m_totalDuration);
    } else {
        // Check for iteration timeout
        if (m_nextIterationDuration < 0) {
            // Hasn't been set yet, set it
            double durationLeft = m_animation->duration() - fmod(elapsedDuration, m_animation->duration());
            m_nextIterationDuration = elapsedDuration + durationLeft;
        }

        if (elapsedDuration >= m_nextIterationDuration) {
            // Set to the next iteration
            double previous = m_nextIterationDuration;
            double durationLeft = m_animation->duration() - fmod(elapsedDuration, m_animation->duration());
            m_nextIterationDuration = elapsedDuration + durationLeft;

            // Send the event
            updateStateMachine(AnimationStateInputLoopTimerFired, previous);
        }
    }
}
Exemple #18
0
char *clsTimers::getElapsedTimeStr()
{
	unsigned long long elapssd = 0;
	elapssd = getElapsedTime();
	
	int minutesFromSecs = (elapssd/1000)/60;
	int secsFromMinutes = (elapssd/1000) % 100;
	
	char msg[128];
	snprintf(msg,128,"%02d:%02d:%03lld",minutesFromSecs,secsFromMinutes,elapssd%1000);
	
	return msg;
}
Exemple #19
0
uint32 QuickTimeDecoder::getTimeToNextFrame() const {
	if (!_started || _curFrame < 0)
		return 0;

	// Convert from the QuickTime rate base to 1000
	uint32 nextFrameStartTime = _nextFrameStartTime * 1000 / _tracks[_videoTrackIndex]->timeScale;
	uint32 elapsedTime = getElapsedTime();

	if (nextFrameStartTime <= elapsedTime)
		return 0;

	return nextFrameStartTime - elapsedTime;
}
Exemple #20
0
uint32 QuickTimeDecoder::getTimeToNextFrame() const {
	if (endOfVideo() || _curFrame < 0)
		return 0;

	// Convert from the QuickTime rate base to 1000
	uint32 nextFrameStartTime = _nextFrameStartTime * 1000 / _streams[_videoStreamIndex]->time_scale;
	uint32 elapsedTime = getElapsedTime();

	if (nextFrameStartTime <= elapsedTime)
		return 0;

	return nextFrameStartTime - elapsedTime;
}
Exemple #21
0
void FPSMeter::PerformanceStop() {
	
	if (useFpsLimit) {

		// FPS Limiter
		if (fpsLimit < 1) {
			return;
		}

		double waitTime = 1000 / fpsLimit - getElapsedTime() * 1000;

		if (waitTime < 0) {
			return;
		}

		Sleep(DWORD(waitTime));
	}


	// NuLogger::getInstance()->log("Render Frame: %f ms", floor(1000*dTimeDiff));
	lastFrameRenderDuration = 1000 * getElapsedTime();

	// counting real frames
	currentFrames++;

	// reset real frames when a second passed
	QueryPerformanceCounter((LARGE_INTEGER*)&g_LastFPS);
	double dTimeDiffFPS = (((double)(g_LastFPS - g_CurrentFPS)) / ((double)g_Frequency));
	if (1000 * dTimeDiffFPS > 1000) {
		// NuLogger::getInstance()->log("FPS: %i", currentFrames);
		realFramesLastSecond = currentFrames;
		currentFrames = 0;
		QueryPerformanceCounter((LARGE_INTEGER*)&g_CurrentFPS);
	}



}
Exemple #22
0
void _stdcall updateFramerate(unsigned int cmd) {	
	// If rendering was performed, update animation step-time
	if((cmd == 2) || (cmd == 5)) {
		// FPS regulation based on previous render
		double maxFPS = (double)Settings::get().getCurrentFPSLimit();
		double minFPS = 10.0f;
		double currentTime = getElapsedTime();
		double deltaTime = currentTime - lastRenderTime;
		lastRenderTime = currentTime;

		// Update step-time
		updateAnimationStepTime((float)deltaTime, (float)minFPS, (float)maxFPS);
	}
}
double serialcounter(int tcount){
	StopWatch_t tw;
	int privcount = 0;
	
	startTimer(&tw);
	
	while (privcount < tcount){
		privcount++;
		count++;
	}
	stopTimer(&tw);
	
	return getElapsedTime(&tw);
}
void StartTimerLoop(TimerCallback_t init_callback)
{
    getElapsedTime();
    last_alarm_set = last_time_read;
    last_occured_alarm = last_alarm_set;

    init_timer(&timer);
    timer.function = timer_notify;

    EnterMutex();
    // At first, TimeDispatch will call init_callback.
    SetAlarm(NULL, 0, init_callback, 0, 0);
    LeaveMutex();
}
Exemple #25
0
void serialFirewall (int numPackets,
					 int numSources,
					 long mean,
					 int uniformFlag,
					 short experimentNumber) {

    PacketSource_t *packetSource = createPacketSource(mean, numSources, experimentNumber);
    Packet_t **rcvd_pkts = malloc (numSources * numPackets * sizeof(Packet_t *));
    int packet_ctr = 0;

    StopWatch_t watch;
    long fingerprint = 0;

    if(uniformFlag) {
        startTimer(&watch);
        for(int i = 0; i < numSources; i++) {
            for(int j = 0; j < numPackets; j++) {
                Packet_t *tmp = getUniformPacket(packetSource,i);
                fingerprint += getFingerprint(tmp->iterations, tmp->seed);
                rcvd_pkts[packet_ctr] = tmp;
                packet_ctr += 1;
            }
        }
        stopTimer(&watch);
    }

    else {
        startTimer(&watch);
        for(int i = 0; i < numSources; i++) {
            for(int j = 0; j < numPackets; j++) {
                Packet_t *tmp = getExponentialPacket(packetSource,i);
                fingerprint += getFingerprint(tmp->iterations, tmp->seed);
                rcvd_pkts[packet_ctr] = tmp;
                packet_ctr += 1;
            }
        }
        stopTimer(&watch);
    }
    for (int i = 0; i < packet_ctr; i++) {
        free(rcvd_pkts[i]);
    }
    free (rcvd_pkts);
    
#ifdef PERF
    printf("%f\n",getElapsedTime(&watch));
#else
    printf("%ld\n", fingerprint);
#endif

}
void StartPhysics()
{
	if (gSceneRunning)
		return;

	// Update the time step
	gDeltaTime = getElapsedTime();

	// Start collision and dynamics for delta time since the last frame
    gScene->simulate(gDeltaTime);
	gSceneRunning = true;
	WaitForPhysics();
	gScene->flushStream();
}
Exemple #27
0
uint32 FixedRateVideoDecoder::getTimeToNextFrame() const {
    if (endOfVideo() || _curFrame < 0)
        return 0;

    uint32 elapsedTime = getElapsedTime();
    uint32 nextFrameStartTime = getFrameBeginTime(_curFrame + 1);

    // If the time that the next frame should be shown has past
    // the frame should be shown ASAP.
    if (nextFrameStartTime <= elapsedTime)
        return 0;

    return nextFrameStartTime - elapsedTime;
}
/**
 * Timer Task
 */
void timerloop_task_proc(void *arg)
{
	int ret = 0;

	getElapsedTime();
	last_timeout_set = 0;
	last_occured_alarm = last_time_read;

	/* trigger first alarm */
	SetAlarm(callback_od, 0, init_callback, 0, 0);
	RTIME current_time;
	RTIME real_alarm;
	do{

		rt_mutex_acquire(&condition_mutex, TM_INFINITE);
		if(last_timeout_set == TIMEVAL_MAX)
		{
			ret = rt_cond_wait(
				&timer_set,
				&condition_mutex,
				TM_INFINITE
				);		/* Then sleep until next message*/
			rt_mutex_release(&condition_mutex);
		}else{
			current_time = rt_timer_read();
			real_alarm = last_time_read + last_timeout_set;
			ret = rt_cond_wait( /* sleep until next deadline */
				&timer_set,
				&condition_mutex,
				(real_alarm - current_time)); /* else alarm consider expired */
			if(ret == -ETIMEDOUT){
				last_occured_alarm = real_alarm;
				rt_mutex_release(&condition_mutex);
				EnterMutex();
				TimeDispatch();
				LeaveMutex();
			}else{
				rt_mutex_release(&condition_mutex);
			}
		}
	}while ((ret == 0 || ret == -EINTR || ret == -ETIMEDOUT) && !stop_timer);

	if(exitall){
		EnterMutex();
		exitall(callback_od, 0);
		LeaveMutex();
	}
}
Exemple #29
0
void writeNodeFlows()
//
//  Input:   none
//  Output:  none
//  Purpose: writes flow statistics for nodes to report file.
//
{
    int j;
    int days1, hrs1, mins1;

    WRITE("");
    WRITE("*******************");
    WRITE("Node Inflow Summary");
    WRITE("*******************");
    WRITE("");

    fprintf(Frpt.file,
"\n  -------------------------------------------------------------------------------------------------"
"\n                                  Maximum  Maximum                  Lateral       Total        Flow"
"\n                                  Lateral    Total  Time of Max      Inflow      Inflow     Balance"
"\n                                   Inflow   Inflow   Occurrence      Volume      Volume       Error"
"\n  Node                 Type           %3s      %3s  days hr:min    %8s    %8s     Percent",
        FlowUnitWords[FlowUnits], FlowUnitWords[FlowUnits], VolUnitsWords[UnitSystem],
        VolUnitsWords[UnitSystem]);                                            //(5.1.009)
    fprintf(Frpt.file,
"\n  -------------------------------------------------------------------------------------------------");

    for ( j = 0; j < Nobjects[NODE]; j++ )
    {
        fprintf(Frpt.file, "\n  %-20s", Node[j].ID);
        fprintf(Frpt.file, " %-9s", NodeTypeWords[Node[j].type]);
        getElapsedTime(NodeStats[j].maxInflowDate, &days1, &hrs1, &mins1);
        fprintf(Frpt.file, FlowFmt, NodeStats[j].maxLatFlow * UCF(FLOW));
        fprintf(Frpt.file, FlowFmt, NodeStats[j].maxInflow * UCF(FLOW));
        fprintf(Frpt.file, "  %4d  %02d:%02d", days1, hrs1, mins1);
		fprintf(Frpt.file, "%12.3g", NodeStats[j].totLatFlow * Vcf);
		fprintf(Frpt.file, "%12.3g", NodeInflow[j] * Vcf);
    	if ( fabs(NodeOutflow[j]) < 1.0 )
            fprintf(Frpt.file, "%12.3f %s",
                (NodeInflow[j]-NodeOutflow[j])*Vcf*1.0e6,
                VolUnitsWords2[UnitSystem]);
	    else
            fprintf(Frpt.file, "%12.3f", (NodeInflow[j]-NodeOutflow[j]) /
                                          NodeOutflow[j]*100.); 
    }
    WRITE("");
}
void InitNx()
{
	// Create a memory allocator
	gAllocator = new UserAllocator;

	// Create the physics SDK
	gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator);
	if (!gPhysicsSDK)  return;

	// Set the physics parameters
	gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01);

	// Set the debug visualization parameters
	gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1);
	//gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
	//gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
	//gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_FNORMALS, 1);

	// Create the scene
	NxSceneDesc sceneDesc;
	sceneDesc.simType				= NX_SIMULATION_SW;
	sceneDesc.gravity               = gDefaultGravity;
	gScene = gPhysicsSDK->createScene(sceneDesc);	

	// Create the default material
	NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); 
	defaultMaterial->setRestitution(0.5);
	defaultMaterial->setStaticFriction(0.5);
	defaultMaterial->setDynamicFriction(0.5);

	groundPlane	= CreateGroundPlane();
	//groundPlane->getShapes()[0]->setFlag(NX_SF_FLUID_DRAIN,true);

	// Create drain actors
	CreateDrainActors();

	fluidEmitter = CreateFluidEmitter(0.35, 0.35);

	// Initialize HUD
	InitializeHUD();

	// Get the current time
	getElapsedTime();

	// Start the first frame of the simulation
	if (gScene)  StartPhysics();
}