/** * NOTE: the second parameter is `user data` * but this user data is shared for *all* watches * b/c this chart can be in use simultaneously by multiple watches. * * its only status->hsm ( the machine ) and status->ctx ( the context data ) * that are potentially unique for every watch. */ static void RunTickTime( hsm_status status, void * user_data ) { // our context is the watch object Watch* watch= ((WatchContext*)status->ctx)->watch; // our event is the tick event TickEvent * tick= ((TickEvent*)status->evt); // tick by this much time TickTime ( watch, tick->time ); // print the total time printf("%d,", watch->elapsed_time ); }
void TimerManager::Tick() { if (m_timers.empty()) { return; } time_t tnow = TickTime(); time_t dt = (tnow - m_last_ttime) / 1000; m_last_ttime = tnow; auto iter = m_timers.begin(); for (; iter < m_timers.end();) { if (!(*iter)->Update(dt)) { iter = m_timers.erase(iter); } else { ++iter; } } }
TimerManager::TimerManager() : m_last_ttime(TickTime()) { }
void render_LoadSensor (struct X3D_LoadSensor *node) { int count; int nowLoading; int nowFinished; struct X3D_ImageTexture *tnode; #ifdef HAVE_TO_REIMPLEMENT_MOVIETEXTURES struct X3D_MovieTexture *mnode; #endif /* HAVE_TO_REIMPLEMENT_MOVIETEXTURES */ struct X3D_AudioClip *anode; //struct X3D_Inline *inode; /* if not enabled, do nothing */ if (!node) return; if (node->__oldEnabled != node->enabled) { node->__oldEnabled = node->enabled; MARK_EVENT(X3D_NODE(node),offsetof (struct X3D_LoadSensor, enabled)); } if (!node->enabled) return; /* we only need to look at this during the rendering pass - once per event loop */ if (!renderstate()->render_geom) return; /* do we need to re-generate our internal variables? */ if NODE_NEEDS_COMPILING { MARK_NODE_COMPILED node->__loading = 0; node->__finishedloading = 0; node->progress = (float) 0.0; node->__StartLoadTime = 0.0; } /* do we actually have any nodes to watch? */ if (node->watchList.n<=0) return; /* are all nodes loaded? */ if (node->__finishedloading == node->watchList.n) return; /* our current status... */ nowLoading = 0; nowFinished = 0; /* go through node list, and check to see what the status is */ /* printf ("have %d nodes to watch\n",node->watchList.n); */ for (count = 0; count < node->watchList.n; count ++) { tnode = (struct X3D_ImageTexture *) node->watchList.p[count]; /* printf ("node type of node %d is %d\n",count,tnode->_nodeType); */ switch (tnode->_nodeType) { case NODE_ImageTexture: /* printf ("opengl tex is %d\n",tnode->__texture); */ /* is this texture thought of yet? */ nowLoading++; if (fwl_isTextureLoaded(tnode->__textureTableIndex)) { /* is it finished loading? */ nowFinished ++; } break; case NODE_MovieTexture: #ifdef HAVE_TO_REIMPLEMENT_MOVIETEXTURES mnode = (struct X3D_MovieTexture *) tnode; /* change type to MovieTexture */ /* printf ("opengl tex is %d\n",mnode->__texture0_); */ /* is this texture thought of yet? */ if (mnode->__texture0_ > 0) { nowLoading++; /* is it finished loading? */ if (fwl_isTextureLoaded(mnode->__texture0_)) nowFinished ++; } #endif /* HAVE_TO_REIMPLEMENT_MOVIETEXTURES */ break; case NODE_Inline: //inode = (struct X3D_Inline *) tnode; /* change type to Inline */ /* printf ("LoadSensor, Inline %d, type %d loadstatus %d at %d\n",inode,inode->_nodeType,inode->__loadstatus, &inode->__loadstatus); */ break; case NODE_Script: nowLoading ++; /* broken - assume that the url is ok for now */ break; case NODE_AudioClip: anode = (struct X3D_AudioClip *) tnode; /* change type to AudioClip */ /* AudioClip sourceNumber will be gt -1 if the clip is ok. see code for details */ if (anode->__sourceNumber > -1) nowLoading ++; break; default :{} /* there should never be anything here, but... */ } } /* ok, are we NOW finished loading? */ if (nowFinished == node->watchList.n) { node->isActive = 0; MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, isActive)); node->isLoaded = 1; MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, isLoaded)); node->progress = (float) 1.0; MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, progress)); node->loadTime = TickTime(); MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, loadTime)); } /* have we NOW started loading? */ if ((nowLoading > 0) && (node->__loading == 0)) { /* mark event isActive TRUE */ node->isActive = 1; MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, isActive)); node->__StartLoadTime = TickTime(); } /* what is our progress? */ if (node->isActive == 1) { node->progress = (float)(nowFinished)/(float)(node->watchList.n); MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, progress)); } /* remember our status for next time. */ node->__loading = nowLoading; node->__finishedloading = nowFinished; /* did we run out of time? */ if (node->timeOut > 0.0001) { /* we have a timeOut specified */ if (node->__StartLoadTime > 0.001) { /* we have a start Time recorded from the isActive = TRUE */ /* ok, we should look at time outs */ if ((TickTime() - node->__StartLoadTime) > node->timeOut) { node->isLoaded = 0; MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, isLoaded)); node->isActive = 0; MARK_EVENT (X3D_NODE(node), offsetof (struct X3D_LoadSensor, isActive)); /* and, we will just assume that we have loaded everything next iteration */ node->__finishedloading = node->watchList.n; } } } }