extern void SH_PruneAddrCache(SockBase base, int ageSecs, int usedSecs) { SockAddr lag = NULL; SockAddr ac = base->addrCache; TimeMarker now = GetCurrentTime(); while (ac != NULL) { SockAddr next = ac->next; double dAge = DeltaTime(ac->startTime, now); double dUse = DeltaTime(ac->lastUsed, now); if (dAge > ageSecs || dUse > usedSecs) { double dt = DeltaTime(base->startTime, now); // got a victim if (lag == NULL) base->addrCache = next; else lag->next = next; if (base->debug != NULL) fprintf(base->debug, "@%4.3f, SH_PruneAddrCache, %s, aged %4.1f, used %4.1f\n", dt, ac->host, dAge, dUse); Freestr(ac->host); Freestr(ac->kind); free(ac); base->nAddrs--; } else lag = ac; ac = next; } }
//--------------------------------------------------------------------------- void TCustomMsgServer::TerminateAll() { int c; longword Elapsed; bool Timeout; if (ClientsCount > 0) { for (c = 0; c < MaxWorkers; c++) { if (Workers[c] != 0) PMsgWorkerThread(Workers[c])->Terminate(); } // Wait for closing Elapsed = SysGetTick(); Timeout = false; while (!Timeout && (ClientsCount > 0)) { Timeout = DeltaTime(Elapsed) > WkTimeout; if (!Timeout) SysSleep(100); }; if (ClientsCount > 0) KillAll(); // one o more threads are hanged ClientsCount = 0; } }
void TIntegration_Manager_Cstruct::GetParameters() /* -------------------------- * Author : Gilles Orazi * Created : 06/2002 * Purpose : * History : * -------------------------- */ { //setting global parameters ReduceNoise(FParams->ReduceNoise) ; UseRelativeThreshold(FParams->UseRelativeThreshold) ; ComputeBaselines(FParams->ComputeBaselines) ; SpikeReduction(FParams->SpikeReduction) ; DeltaTime(FParams->DeltaTime) ; DeadTime(FParams->DeadTime) ; PeakSat_Max(FParams->PeakSat_Max); PeakSat_Min(FParams->PeakSat_Min); //reading event list ClearEventList(); for (int idxevent = 0; idxevent<FParams->NumberOfEvents; ++idxevent) { StoreEvent(FParams->events[idxevent]); } }
static int InnerConnect(SockBase base, struct sockaddr *sap) { int fd = socket(sap->sa_family, SOCK_STREAM, IPPROTO_TCP); if (fd >= 0) { // we've got a socket, so try for a connection int timeout = base->robustTimeout; uint64_t start = GetCurrentTime(); for (;;) { int connRes = connect(fd, sap, SockAddrLen(sap)); if (connRes >= 0) { // success! return fd; } MilliSleep(RobustMillis); uint64_t now = GetCurrentTime(); double dt = DeltaTime(start, now); int e = errno; if (dt > timeout || (e != EAGAIN && e != EINTR)) { // failed, so give back the socket and report the failure close(fd); return connRes; } } } return fd; }
/** * Performs a robust connect, restarting when interrupted. * Requires a valid socket (se->fd >= 0). */ extern int SH_RobustConnect(SockEntry se, struct sockaddr *sap) { int timeout = se->base->robustTimeout; uint64_t start = GetCurrentTime(); for (;;) { int connRes = connect(se->fd, sap, SockAddrLen(sap)); if (connRes >= 0) { se->lastUsed = GetCurrentTime(); return connRes; } int e = errno; if (e != EAGAIN && e != EINTR) break; MilliSleep(RobustMillis); uint64_t now = GetCurrentTime(); double dt = DeltaTime(start, now); if (dt > timeout) break; } se->errCount++; return -1; }
/** * Performs a robust accept, restarting when interrupted. * Requires a valid socket (se->fd >= 0). */ extern int SH_RobustAccept(SockEntry se) { int timeout = se->base->robustTimeout; uint64_t start = GetCurrentTime(); for (;;) { int connRes = accept(se->fd, NULL, NULL); if (connRes >= 0) { se->lastUsed = GetCurrentTime(); return connRes; } int e = errno; if (e != EAGAIN && e != EINTR) break; MilliSleep(RobustMillis); uint64_t now = GetCurrentTime(); double dt = DeltaTime(start, now); if (dt > timeout) break; } se->errCount++; return -1; }
/** * Performs a robust sendmsg, restarting when interrupted. * Requires a connection. */ extern ssize_t SH_RobustSendmsg(SockEntry se, struct msghdr *mp) { int timeout = se->base->robustTimeout; uint64_t start = GetCurrentTime(); for (;;) { ssize_t nb = sendmsg(se->fd, mp, 0); if (nb >= 0) { se->writeActive = 1; se->lastUsed = GetCurrentTime(); return nb; } int e = errno; if (e != EAGAIN && e != EINTR) break; MilliSleep(RobustMillis); uint64_t now = GetCurrentTime(); double dt = DeltaTime(start, now); if (dt > timeout) break; } se->errCount++; return -1; }
static DeltaTime milliseconds(double ms) { return DeltaTime((int64)(ms*1000.)); }
static DeltaTime seconds(double s) { return DeltaTime((int64)(s*1000000.)); }
static DeltaTime milliseconds(uint32 ms) { return DeltaTime(((int64)ms)*1000); }
/** * @returns the seconds since the last send/receive operation. */ extern double SH_TimeSinceLastUsed(SockEntry se) { uint64_t now = GetCurrentTime(); return DeltaTime(se->lastUsed, now); }
/// Arethmetic operator-- add two DeltaTime values. inline DeltaTime operator+ (const DeltaTime &other) const { return DeltaTime(mDeltaTime + other.mDeltaTime); }
static DeltaTime nanoseconds(uint32 ns) { return DeltaTime(((int64)ns)/1000); }
static DeltaTime nanoseconds(uint64 ns) { return DeltaTime(ns/1000); }
static DeltaTime microseconds(uint32 us) { return DeltaTime((int64)us); }
static DeltaTime microseconds(uint64 us) { return DeltaTime(us); }
static DeltaTime microseconds(double us) { return DeltaTime((int64)us); }
int main( void ) { int SCORE=0;//to keep score... string a = "SCORE:"; string score; string hoops; stringstream ss; stringstream hoo; string endg = "Your HighScore was : "; ball *Balls[1]; int bal=1; hoop *Hoops[21]; int h=21; float before[21]; edge wall(vector(10.950f, 0.95f, 0),vector(-10.95f, 0.95f, 0),0); edge wallleft(vector(-0.95f, 10.95f, 0),vector(-0.95f, -10.95f, 0),0); edge wallright(vector(1.95f, -10.95f, 0),vector(1.95f, 10.95f, 0),0); edge floor(vector(-10.950f, -0.95f, 0),vector(10.95f, -0.95f, 0),0); //DeltaTime variable and a useful boolean for when you //controling the game states. bool gamestate = 0; float DT; float time; bool Alpha = 1; float speed = 0.5; int *x = new int; int *y = new int; float Xmax , Ymax; float Ux , Uy; bool reset = 0; bool endgame = 0; float pointsX , pointsY; //Some variables to handle bunus points system: bool mouse_clicked = 0; int hoops_done = 0; for (int i = 0 ; i<bal ; i++) { Balls[i]= new ball(vector(0,0,0),vector(0,1,0),0.05); for (int j = 0 ; j <h ;j++) { float random = (rand()%3); Hoops[j]= new hoop(vector(2+1.5*j,-0.5+random*0.5,0),vector(2+1.5*j,random*0.5-0.1,0)); before[j] = (Balls[i]->position-Hoops[j]->mHorizon.start)*Hoops[j]->mHorizon.unit2;; } } string s = "PRESS 'D' TO START THE GAME "; //string d = "CONTROL WITH 'A' AND 'S'"; int running = GL_TRUE; // Initialize GLFW if( !glfwInit() ) { exit( EXIT_FAILURE ); } glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE ) ; // Open an OpenGL window if( !glfwOpenWindow( 800,480, 0,0,0,0,0,0, GLFW_WINDOW ) ) { glfwTerminate(); exit( EXIT_FAILURE ); } glfwSetWindowTitle( "''Hoops-1.0 Jumps Through The Hoops!!!''" ); glOrtho(-1, 2, -1, 1, -1.0, 1.0); glEnable(GL_LINE_SMOOTH); glLineWidth(2); string welcome1 = "Hi there! You see that Little Red Ball onn your screen? THAT'S ME , HOOPS!!!"; string welcome2 = "Whenever you click on the screen i will jump up to meet your cursor!"; string welcome3 = "Go Ahead! Give it a try!"; Balls[0]->Red=1.0f; Balls[0]->Green=0; Balls[0]->Blue=0; FadingText t(hoops,540,400,GLUT_BITMAP_TIMES_ROMAN_24,3.0); // Main loop while( running ) { //Calculate the DeltaTime //The function is in "vector.h" and it uses the clock() function. DeltaTime(DT); time+=DT; //if(DT>0.01)DT=0.005; glClear( GL_COLOR_BUFFER_BIT ); DrawBoard(); if(Hoops[20]->mHorizon.start.x<-1) endgame = 1; if(endgame) { Hoops[20]->mHorizon= edge(vector(1.5,0.5,0),vector(1.95,0.5,0)); } glColor3f(1,1,1); ss<<SCORE; score=ss.str(); ss.str(""); text(score,640,450,GLUT_BITMAP_TIMES_ROMAN_24); text(a,550,450,GLUT_BITMAP_TIMES_ROMAN_24); hoo<<"+"; hoo<<hoops_done; hoops=hoo.str(); hoo.str(""); t.t=hoops; //Move the player around with 'A' and 'S' if(glfwGetKey('A')) { } if(glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT)&&Alpha) { mouse_clicked=1; hoops_done=0; glfwGetMousePos( x, y ); Xmax = ((*x)/(800.0f/3.0f)-1); Ymax = (1-(*y)/240.0f); if(*x<800&&*y<480){ for (int i = 0 ; i<bal ; i++) { //if(Balls[i]->position.y<-0.5&&Ymax>-0.5) //{ Xmax-=Balls[i]->position.x; Ymax -= Balls[i]->position.y; if(Ymax>=0) { Uy = sqrt(2*10.0f*Ymax); Ux = Xmax* 10.0f /Uy; Balls[i]->velocity=vector(Ux,Uy,0); } //else Balls[i]->velocity=(vector(Xmax+Balls[i]->position.x,Ymax+Balls[i]->position.y,0)-Balls[i]->position).normal()*2; } //} } Alpha = 0; } if(!glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT)&&Alpha==0)Alpha=1; //if(glfwGetKey('F')&&Alpha) //{ // for (int i = 0 ; i<bal ; i++) // { // // Balls[i]->velocity+=vector(0,0.3f,0); // } // Alpha = 0; //} //if(!glfwGetKey('F')&&Alpha==0)Alpha=1; for(int j=0;j<h;j++) { Hoops[j]->DrawBack(); } for (int i = 0 ; i<bal ; i++) { Balls[i]->draw(); Balls[i]->bounce(wallleft); Balls[i]->bounce(wallright); Balls[i]->bounce(floor); Balls[i]->bounce(wall); for(int j=0;j<h;j++) { Balls[i]->GoThroughHoop(Hoops[j],before[j],hoops_done,mouse_clicked,SCORE,reset); if(reset) { t.timer=0; pointsX=Hoops[j]->mHorizon.end.x; pointsY=Hoops[j]->mHorizon.end.y; } Hoops[j]->DrawFront(); before[j] =(Balls[i]->position-Hoops[j]->mHorizon.start)*Hoops[j]->mHorizon.unit2; if(endgame==0)Hoops[j]->moveleft(DT,speed); } Balls[i]->move(DT); } t.draw(DT); reset = 0; // Swap front and back rendering buffers glfwSwapBuffers(); // Check if ESC key was pressed or window was closed running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED ); } // Close window and terminate GLFW glfwTerminate(); // Exit program exit( EXIT_SUCCESS ); }
/** * @returns the seconds since the start. */ extern double SH_TimeAlive(SockEntry se) { uint64_t now = GetCurrentTime(); return DeltaTime(se->startTime, now); }
static enum ccn_upcall_res CallMe(struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info) { // CallMe is the callback routine invoked by ccn_run when a registered // interest has something interesting happen. struct localClosure *req = (struct localClosure *)selfp->data; seg_t thisSeg = req->reqSeg; struct ccn_fetch_stream *fs = (struct ccn_fetch_stream *) req->fs; if (fs == NULL) { if (kind == CCN_UPCALL_FINAL) { // orphaned, so just get rid of it free(req); free(selfp); } return(CCN_UPCALL_RESULT_OK); } FILE *debug = fs->parent->debug; seg_t finalSeg = fs->finalSeg; ccn_fetch_flags flags = fs->parent->debugFlags; if (finalSeg < 0) { // worth a try to find the last segment finalSeg = GetFinalSegment(info); fs->finalSeg = finalSeg; } switch (kind) { case CCN_UPCALL_FINAL: // this is the cleanup for an expressed interest req = RemSegRequest(fs, req); if (fs->reqBusy > 0) fs->reqBusy--; free(selfp); return(CCN_UPCALL_RESULT_OK); case CCN_UPCALL_INTEREST_TIMED_OUT: { if (finalSeg >= 0 && thisSeg > finalSeg) // ignore this timeout quickly return(CCN_UPCALL_RESULT_OK); intmax_t dt = DeltaTime(req->startClock, GetCurrentTimeUSecs()); if (dt >= fs->timeoutUSecs) { // timed out, too many retries // assume that this interest will never produce seg_t timeoutSeg = fs->timeoutSeg; fs->timeoutsSeen++; fs->segsAhead = 0; if (timeoutSeg < 0 || thisSeg < timeoutSeg) { // we can infer a new timeoutSeg fs->timeoutSeg = thisSeg; } if (debug != NULL && (flags & ccn_fetch_flags_NoteTimeout)) { fprintf(debug, "** ccn_fetch timeout, %s, seg %jd", fs->id, thisSeg); fprintf(debug, ", dt %jd us, timeoutUSecs %jd\n", dt, fs->timeoutUSecs); fflush(debug); } return(CCN_UPCALL_RESULT_OK); } // TBD: may need to reseed bloom filter? who to ask? return(CCN_UPCALL_RESULT_REEXPRESS); } case CCN_UPCALL_CONTENT_UNVERIFIED: return (CCN_UPCALL_RESULT_VERIFY); case CCN_UPCALL_CONTENT: if (fs->timeoutSeg >= 0 && fs->timeoutSeg <= thisSeg) // we will ignore this, since we are blocked return(CCN_UPCALL_RESULT_OK); break; default: // SHOULD NOT HAPPEN return(CCN_UPCALL_RESULT_ERR); } struct ccn_fetch_buffer *fb = FindBufferForSeg(fs, thisSeg); if (fb == NULL) { // we don't already have the data yet const unsigned char *data = NULL; size_t dataLen = 0; size_t ccnb_size = info->pco->offset[CCN_PCO_E]; const unsigned char *ccnb = info->content_ccnb; int res = ccn_content_get_value(ccnb, ccnb_size, info->pco, &data, &dataLen); if (res < 0 || (thisSeg != finalSeg && dataLen == 0)) { // we got a bogus result, no data in this content! if (debug != NULL && (flags & ccn_fetch_flags_NoteAddRem)) { fprintf(debug, "-- ccn_fetch no data, %s, seg %jd, final %jd", fs->id, thisSeg, finalSeg); ShowDelta(debug, req->startClock); } if (fs->zeroLenSeg < 0 || thisSeg < fs->zeroLenSeg) // note this problem for future reporting fs->zeroLenSeg = thisSeg; } else if (thisSeg == finalSeg && dataLen == 0) { // EOF, but no buffer needed if (fs->fileSize < 0) fs->fileSize = InferPosition(fs, thisSeg); fs->finalSeg = finalSeg-1; if (debug != NULL && (flags & ccn_fetch_flags_NoteFinal)) { fprintf(debug, "-- ccn_fetch EOF, %s, seg %jd, len %d, fs %jd", fs->id, thisSeg, (int) dataLen, fs->fileSize); ShowDelta(debug, req->startClock); } } else { // alloc a buffer and transfer the data if (fs->segSize == 0) { // assuming fixed size segments, so any should do // EXCEPT for an incomplete final segment if (thisSeg == 0 || thisSeg < finalSeg) fs->segSize = dataLen; } if (thisSeg == finalSeg) fs->finalSegLen = dataLen; struct ccn_fetch_buffer *fb = NewBufferForSeg(fs, thisSeg, dataLen); memcpy(fb->buf, data, dataLen); if (debug != NULL && (flags & ccn_fetch_flags_NoteFill)) { fprintf(debug, "-- ccn_fetch FillSeg, %s, seg %jd, len %d, nbuf %d", fs->id, thisSeg, (int) dataLen, (int) fs->nBufs); ShowDelta(debug, req->startClock); } if (thisSeg == finalSeg) { // the file size is known in segments if (fs->segSize <= 0) { // variable or unknown segment size if (fb->pos >= 0) { fs->fileSize = fb->pos + dataLen; } } else { // fixed segment size, so file size is now known fs->fileSize = thisSeg * fs->segSize + dataLen; } if (debug != NULL && (flags & ccn_fetch_flags_NoteFinal)) { fprintf(debug, "-- ccn_fetch EOF, %s, seg %jd, len %d, fs %jd", fs->id, thisSeg, (int) dataLen, fs->fileSize); ShowDelta(debug, req->startClock); } } fs->segsRead++; } } ccn_set_run_timeout(fs->parent->h, 0); return(CCN_UPCALL_RESULT_OK); }
/// Arethmetic operator-- subtract two DeltaTime values. inline DeltaTime operator-= (const DeltaTime &other) { return DeltaTime(mDeltaTime -= other.mDeltaTime); }
static DeltaTime milliseconds(uint64 ms) { return DeltaTime(ms*1000); }
static void ShowDelta(FILE *f, TimeMarker from) { intmax_t dt = DeltaTime(from, GetCurrentTimeUSecs()); fprintf(f, ", dt %jd.%06d\n", dt / 1000000, (int) (dt % 1000000)); fflush(f); }
/// Arethmetic operator-- negate a DeltaTime. inline DeltaTime operator- () const { return DeltaTime(-mDeltaTime); }
inline DeltaTime operator/(float64 rhs) const { return DeltaTime((int64)((float64)mDeltaTime / (float64)rhs)); }
inline DeltaTime operator*(float32 rhs) const { return DeltaTime((int64)((float64)mDeltaTime * (float64)rhs)); }