// insert one job into the queue void datacloud::insertjob(int col,int row,const unsigned char *mapfile,int hlod,const unsigned char *texfile,int tlod,const unsigned char *fogfile,BOOLINT immediate,BOOLINT loprio) { double time; jobqueueelem *oldjob,*newjob; // check for already existing job oldjob=checkjob(col,row,mapfile,hlod,texfile,tlod,fogfile,immediate,loprio); // reset access time if (oldjob!=NULL) { time=gettime(); if (mapfile!=NULL) oldjob->hfield->access=time; if (texfile!=NULL) oldjob->texture->access=time; if (fogfile!=NULL) oldjob->fogmap->access=time; return; } // create new job newjob=new jobqueueelem; newjob->col=col; newjob->row=row; // schedule height field if (mapfile!=NULL) newjob->hfield=inserttile(mapfile,col,row,FALSE,immediate,loprio,hlod); else newjob->hfield=NULL; newjob->hlod=hlod; // schedule texture map if (texfile!=NULL) newjob->texture=inserttile(texfile,col,row,TRUE,immediate,loprio,tlod); else newjob->texture=NULL; newjob->tlod=tlod; // schedule fog field if (fogfile!=NULL) newjob->fogmap=inserttile(fogfile,col,row,FALSE,immediate,loprio,0); else newjob->fogmap=NULL; newjob->loprio=loprio; // insert job into job queue if (immediate) insertjob(NULL,newjob); // insert immediate job at head else insertjob(JOBQUEUETAIL,newjob); // insert job at tail }
// insert one job into the queue void datacloud::insertjob(int col,int row,unsigned char *mapfile,int hlod,unsigned char *texfile,int tlod,unsigned char *fogfile,BOOLINT immediate,BOOLINT loprio) { // check for already existing job if (checkjob(mapfile,texfile,fogfile,immediate,loprio)) return; jobqueueelem *newjob=new jobqueueelem; newjob->col=col; newjob->row=row; // schedule height field if (mapfile!=NULL) newjob->hfield=inserttile(mapfile,col,row,FALSE,immediate,loprio); else newjob->hfield=NULL; newjob->hlod=hlod; // schedule texture map if (texfile!=NULL) newjob->texture=inserttile(texfile,col,row,TRUE,immediate,loprio); else newjob->texture=NULL; newjob->tlod=tlod; // schedule fog field if (fogfile!=NULL) newjob->fogmap=inserttile(fogfile,col,row,FALSE,immediate,loprio); else newjob->fogmap=NULL; newjob->loprio=loprio; // insert immediate job at begin if (immediate) insertjob(NULL,newjob); // insert hi prio job before lo prio jobs else if (!loprio) { jobqueueelem *job=JOBQUEUETAIL; // scan past lo prio jobs in reverse order while (job!=NULL) { if (!job->loprio) break; job=job->prev; } // insert after last hi prio job insertjob(job,newjob); } // insert lo prio job at end else insertjob(JOBQUEUETAIL,newjob); }
// insert a tile into the cache tilecacheelem *datacloud::inserttile(const unsigned char *tileid,int col,int row,BOOLINT istexture,BOOLINT immediate,BOOLINT loprio,int lod) { tilecacheelem *oldtile,*newtile; // check for already existing tile oldtile=checktile(tileid,col,row,istexture,immediate,loprio,lod); // lock critical section if (ISNOTREADY) LOCK_CALLBACK(START_DATA); // already existing tile if (oldtile!=NULL) { oldtile->refcount++; newtile=oldtile; } // allocate and initialize new tile else { newtile=new tilecacheelem; newtile->tileid=(unsigned char *)strdup((char *)tileid); newtile->tile=new databuf; newtile->col=col; newtile->row=row; newtile->istexture=istexture; newtile->loprio=loprio; newtile->lod=lod; newtile->refcount=1; newtile->isavailable=FALSE; newtile->isloading=FALSE; newtile->background=0; } // load immediate data if (immediate && !newtile->isavailable) { // signal background thread to finish signalthread(); // check if actual tile is already being loaded in the background if (newtile->isloading) { // unlock critical section if (ISNOTREADY) UNLOCK_CALLBACK(START_DATA); // wait for background thread to finish loading stopthread(newtile->background); // relock critical section if (ISNOTREADY) LOCK_CALLBACK(START_DATA); } // load actual tile directly if (!newtile->isavailable) { // load in foreground loadtile(newtile); // decrease pending tile count if (oldtile!=NULL) PENDINGTILES--; } } // reset access time newtile->access=gettime(); newtile->isdelayed=FALSE; // unlock critical section if (ISNOTREADY) UNLOCK_CALLBACK(START_DATA); // insert tile at cache tail if (oldtile==NULL) inserttile(TILECACHETAIL,newtile); return(newtile); }
// insert a tile into the cache tilecacheelem *datacloud::inserttile(unsigned char *tileid,int col,int row,BOOLINT istexture,BOOLINT immediate,BOOLINT loprio) { int i; tilecacheelem *oldtile,*newtile; // check for already existing tile oldtile=checktile(tileid,col,row,istexture,immediate,loprio); // already existing tile if (oldtile!=NULL) { newtile=oldtile; newtile->refcount++; } // allocate and initialize new tile else { newtile=new tilecacheelem; newtile->tileid=(unsigned char *)strdup((char *)tileid); newtile->tile=new databuf; newtile->col=col; newtile->row=row; newtile->istexture=istexture; newtile->loprio=loprio; newtile->refcount=1; newtile->isavailable=FALSE; newtile->isloading=FALSE; newtile->background=0; } // lock critical section if (ISNOTREADY) LOCK_CALLBACK(START_DATA); // load immediate data if (immediate && !newtile->isavailable) { // signal background thread to finish signalthread(); // check if actual tile is already being loaded in the background if (newtile->isloading) { // unlock critical section if (ISNOTREADY) UNLOCK_CALLBACK(START_DATA); // wait for background thread to finish loading stopthread(newtile->background); // relock critical section if (ISNOTREADY) LOCK_CALLBACK(START_DATA); } // load actual tile directly if (!newtile->isavailable) { // signal direct loading newtile->isloading=TRUE; // unlock critical section if (ISNOTREADY) UNLOCK_CALLBACK(START_DATA); // lock io if (ISNOTREADY) if (CONFIGURE_AUTOLOCKIO!=0) if (LOCKIO_CALLBACK!=NULL) LOCKIO_CALLBACK(START_DATA); // load data REQUEST_CALLBACK(tileid,newtile->tile,istexture,0,REQUEST_DATA); // autocompress textures if (CONFIGURE_AUTOCOMPRESS!=0) newtile->tile->autocompress(); // unlock io if (ISNOTREADY) if (CONFIGURE_AUTOLOCKIO!=0) if (LOCKIO_CALLBACK!=NULL) UNLOCKIO_CALLBACK(START_DATA); // relock critical section if (ISNOTREADY) LOCK_CALLBACK(START_DATA); // signal availability newtile->isavailable=TRUE; newtile->isloading=FALSE; // decrease pending tile count if (oldtile!=NULL) PENDINGTILES--; } } // unlock critical section if (ISNOTREADY) UNLOCK_CALLBACK(START_DATA); // set access time newtile->access=minitime(); // insert tile at cache tail if (oldtile==NULL) inserttile(TILECACHETAIL,newtile); return(newtile); }