FutureSequenceCleanUp::FutureSequenceCleanUp(QList<JObjectWrapper> *sequence)
        : m_sequence(sequence)
{
    connect(this, SIGNAL(finished()), this, SLOT(cleanUp()));
}
IdentityConstraintHandler::~IdentityConstraintHandler()
{
    cleanUp();
}
Example #3
0
void FcitxQtConnectionPrivate::dbusDisconnected()
{
    cleanUp();

    createConnection();
}
Example #4
0
void naive(double *data,
	   double *distvec,
	   int *nrow,
	   int *ncol,
	   double *vcovi,
	   int *ntr,
	   int *l2,
	   int *l1names,
	   int *valid,
	   double *validvar,
	   double *validlb,
	   double *validub,
	   int *verbose,
	   double *pairdist,
	   int *ismahal,
	   int *result,
	   int *p)
{

  /*                                */
  /*       set up distances         */
  /*                                */
  
  
  unsigned n = choose(*nrow, 2), i;
  double *vec=Calloc(n, double), *vec2=Calloc(n, double);
  
  /* Compute distances between all units */
  if(*ismahal==1)
    {
      vec = allmahal(ncol, nrow, n, data, vcovi, vec);
    }
  else
    {
      /* put in user-supplied distances if mahalanobis distances are not wanted */
      for(i=1; i<n; i++)
	{
	  vec[i] = distvec[i];    
	}
    }
  for(i=1; i<n; i++)
    {
      vec2[i] = vec[i];    
    }
  /* Set some distances to INF to avoid unwanted matches if valid.var is set or if level.two=TRUE (return original distances otherwise) */

  vec = cleanUp(*l2, l1names, *valid, validvar, *validlb, *validub, n, vec);
 
  unsigned unitlist[*nrow], unit, k, matches[*ntr], mm, mn[*ntr], check=0, j=0;

  for(unit=0; unit<*nrow; unit++)
    {
      if(unitlist[unit] != 1)
	{
	  matches[0] = unit+1;
	      if(*l2 == 1) /* if level.two=TRUE, eliminate subunits within the same level two unit */
		{
		  for(i=0; i<n; i++)
		    {
		      if(levelTwoCheck(i, unit+1, l1names)==1)
			{
			  vec[i] = HUGE_VAL;
			  if(l1names[myrow(i)-1]==l1names[unit])
			    {
			      unitlist[myrow(i)-1] = 1;
			    }
			  else
			    {
			      unitlist[mycol(i)-1] = 1;
			    }
			}
		    }
		}

	  for(k=0; k<(*ntr-1); k++)
	    {

	      /* find minimum distance */
	      mn[k] = findMin2(vec, *nrow, unit+1);

	      /* record row and column */
	      mm = mycol(mn[k]);
	      if(mm==matches[0])
		{
		  matches[k+1] = myrow(mn[k]);
		}
	      else
		{
		  matches[k+1] = mm;
		}
	      unitlist[matches[k+1]-1] = 1;
	      
      
	      if(vec[mn[k]] == HUGE_VAL && check==0)
		{
		  check = k+1;
		}

	       /* inf out things not to be reused */
	      vec[mn[k]] = HUGE_VAL;
	      if(*l2 == 1) /* if level.two=TRUE, eliminate subunits within the same level two unit */
		{
		  for(i=0; i<n; i++)
		    {
		      if(levelTwoCheck(i, matches[k+1], l1names)==1)
			{
			  vec[i] = HUGE_VAL;
			  if(l1names[myrow(i)-1]==l1names[matches[k+1]-1])
			    {
			      unitlist[myrow(i)-1] = 1;
			    }
			  else
			    {
			      unitlist[mycol(i)-1] = 1;
			    }
			}
		    }
		}
	    }
	  pairdist[j] = maxDist(vec2, matches, *ntr);

	  /* get rid of used units */ 
	  for(i=0; i<*ntr; i++)
	    {
	      vec = eliminate(matches[i],vec, *nrow);
	    }

	  
	  /* record matches for the R output */
	  if(check > 0)
	    {
	      for(i=check; i<*ntr; i++)
		{
		  matches[i] = 0;
		}
	    }
	  check = 0;

	  for(i=0; i<*ntr; i++)
	    {
	      result[j*(*ntr) + i] = matches[i];
	    }

  /* reset matches to zero for next iteration */
	  for(i=0; i<*ntr; i++)
	    {
	      matches[i] = 0;
	    }
	  j++;
	}
    }
}
Example #5
0
int main()
{
  init();

  double ballVelX = BALL_VEL;
  double ballVelY = BALL_VEL;

  int topPaddleX;
  int bottomPaddleX;

  double ballX;
  double ballY;

  unsigned int topPlayerScore = 0;
  unsigned int bottomPlayerScore = 0;

  reset(topPaddleX, bottomPaddleX, ballX, ballY);

  bool quit = false;

  int key;
  while(!quit)
  {
    preFrame();
    
    key = getKey();
    if(key == 's')
      --topPaddleX;
    else if(key == 'd')
      ++topPaddleX;
    else if(key == 'k')
      --bottomPaddleX;
    else if(key == 'l')
      ++bottomPaddleX;
    else if(key == '`')
      quit = true;

    ballX += ballVelX;
    ballY += ballVelY;

    if(ballX >= XMAX)
      ballVelX = -ballVelX;
    else if(ballX <= 0)
      ballVelX = -ballVelX;
    if(ballY >= YMAX)
    {
      ballVelY = -ballVelY;

      if(ballX < (bottomPaddleX - PADDLE_HALF_SIZE) ||
         ballX > (bottomPaddleX + PADDLE_HALF_SIZE))
      {
        reset(topPaddleX, bottomPaddleX, ballX, ballY);
        ++topPlayerScore;
      }
    }
    else if(ballY <= 0)
    {
      ballVelY = -ballVelY;

      if(ballX < (topPaddleX - PADDLE_HALF_SIZE) ||
         ballX > (topPaddleX + PADDLE_HALF_SIZE))
      {
        ++bottomPlayerScore; 
        reset(topPaddleX, bottomPaddleX, ballX, ballY);
      }
    }


    postFrame();

    drawPaddle(topPaddleX, 0);
    drawPaddle(bottomPaddleX, YMAX);
    drawBall((int)ballX, (int)ballY);
    drawScore(topPlayerScore, bottomPlayerScore);
  }

  cleanUp();

  return 0;
}
Example #6
0
DccTransferRecv::~DccTransferRecv()
{
    cleanUp();
}
Example #7
0
/*
 * checkPointMem - checkpoint up to max bytes of memory
 */
static bool checkPointMem( unsigned max )
{
    dos_mem_block       *mem, *start, *end, *next, *chk;
    unsigned            size, psp;

    if( max == 0 ) {
        return( false );
    }
    psp = TinyGetPSP();
    start = MK_FP( psp - 1, 0 );
    if( start->chain == END_OF_CHAIN ) {
        return( false );
    }
    start = NEXT_BLOCK( start );
    mem = start;
    for( ;; ) {
        if( mem->owner == 0 && mem->size >= max ) {
            return( false );
        }
        if( mem->chain == END_OF_CHAIN ) {
            break;
        }
        mem = NEXT_BLOCK( mem );
    }
    end = NEXT_BLOCK( mem );
    size = FP_SEG( end ) - FP_SEG( start );
    if( size < 0x100 ) {
        return( false );
    }

    if( size > max ) {
        size = max;
    }
    chk = MK_FP( FP_SEG( end ) - size - 1, 0 );
    mem = start;
    for( ;; ) {
        next = NEXT_BLOCK( mem );
        if( FP_SEG( next ) > FP_SEG( chk ) ) {
            break;
        }
        mem = next;
    }

    savePtrMem = mem;
    memcpy( &saveMem, mem, sizeof( dos_mem_block ) );
    savePtrChk = chk;

    next = chk;
    while( FP_SEG( next ) < FP_SEG( end ) ) {
        size = FP_SEG( end ) - FP_SEG( next );
        if( !chkWrite( next, &size ) ) {
            cleanUp();
            return( false );
        }
        next = MK_FP( FP_SEG( next ) + size, 0 );
    }
    chkClose();
    mem->chain = MEMORY_BLOCK;
    mem->size = FP_SEG( chk ) - FP_SEG( mem ) - 1;
    chk->size = FP_SEG( end ) - FP_SEG( chk ) - 1;
    chk->chain = END_OF_CHAIN;
    chk->owner = 0;
    return( true );
}
Example #8
0
/** The assignment operator copies all the data on an
    element-by-element basis, freeing old storage and allocating new
    storage where necessary.  It does \b NOT simply copy pointers. */
NuclearData& NuclearData::operator=(const NuclearData& n)
{

  if (this == &n)
    return *this;

  int rxnNum,gNum;
 
  cleanUp();
  delete[] single;
  single = NULL;
  P = NULL;

  nPaths = n.nPaths;
  origNPaths = n.origNPaths;

  if (nPaths < 0)
    return *this;

  /* only need relations and emitted if nPaths > 0 */
  if (nPaths>0)
    {

      relations = new int[nPaths];
      memCheck(relations,"NuclearData::NuclearData(...) copy constructor: relations");
      
      emitted = new char*[nPaths];
      memCheck(emitted,"NuclearData::NuclearData(...) copy constructor: emitted");
    }

  /* always need paths */
  paths = new double*[nPaths+1];
  memCheck(paths,"NuclearData::NuclearData(...) copy constructor: paths");
  
  /* copy data */
  for (rxnNum=0;rxnNum<nPaths;rxnNum++)
    {
      relations[rxnNum] = n.relations[rxnNum];
      
      emitted[rxnNum] = new char[strlen(n.emitted[rxnNum])+1];
      memCheck(emitted[rxnNum],"NuclearData::NuclearData(...) copy constructor: emitted[n]");
      strcpy(emitted[rxnNum],n.emitted[rxnNum]);
      
      paths[rxnNum] = new double[nGroups+1];
      memCheck(paths[rxnNum],"NuclearData::NuclearData(...) copy constructor: paths[n]");
      for (gNum=0;gNum<=nGroups;gNum++)
	paths[rxnNum][gNum] = n.paths[rxnNum][gNum];
      
      if (n.D == n.paths[rxnNum])
	{
	  D = paths[rxnNum];
	  P = single;
	}
      if (n.P == n.paths[rxnNum])
	{
	  P = paths[rxnNum];
	  D = single;
	}
      
    }

  /* allocate and fill total xsections */
  paths[nPaths] = new double[nGroups+1];
  memCheck(paths[nPaths],"NuclearData::NuclearData(...) copy constructor: paths[n]");
  single = new double[nGroups+1];
  memCheck(single,"NuclearData::NuclearData(...) copy constructor: single");
  
  for (gNum=0;gNum<=nGroups;gNum++)
    {
      paths[rxnNum][gNum] = n.paths[rxnNum][gNum];
      single[gNum] = n.single[gNum];
    }
  
  if (n.D == n.paths[rxnNum])
    {
      D = paths[rxnNum];
      P = single;
    }
  if (n.P == n.paths[rxnNum])
    {
      P = paths[rxnNum];
      D = single;
    }
  
  E[0] = n.E[0];
  E[1] = n.E[1];
  E[2] = n.E[2];

  return *this;


}  
Example #9
0
/** This function implements a callback from the nuclear data
    library modules.  The arguments for this function are the data as
    read from the library (Note that single precision is sufficient
    for library data).  These data are copied into
    NuclearData::nPaths, NuclearData::E, NuclearData::relations,
    NuclearData::emitted, NuclearData::paths, NuclearData::D[ngroups],
    and NuclearData::single respectively. */
void NuclearData::setData(int numRxns, float* radE, int* daugKza, 
			  char** emissions, float** xSection, 
			  float thalf, float *totalXSection)
{
  int gNum, rxnNum, totalRxnNum=-1;
  
  verbose(4,"Setting NuclearData members.");

  cleanUp();

  /* set dimensions */
  nPaths = numRxns;
  origNPaths = nPaths;

  if (nPaths < 0)
    return;

  /* only need relations and emitted if nPaths > 0 */
  if (nPaths > 0)
    {
      relations = new int[nPaths];
      memCheck(relations,"NuclearData::setData(...) : relations");
      
      emitted = new char*[nPaths];
      memCheck(emitted,"NuclearData::setData(...) : emitted");
    }

  paths = new double*[nPaths+1];
  memCheck(paths,"NuclearData::setData(...) : paths");

  E[0] = radE[0];  
  E[1] = radE[1];  
  E[2] = radE[2];

  /* initialize total x-sections */

  /* total of all paths */
  paths[nPaths] = new double[nGroups+1];
  memCheck(paths[nPaths],"NuclearData::setData(...) : paths[n]");
  for (gNum=0;gNum<nGroups;gNum++)
    paths[nPaths][gNum] = 0;

  /* if we are passed a total xsection (we must be in reverse mode) */
  if ( (NuclearData::mode == MODE_REVERSE) && (totalXSection != NULL) )
    {  
      delete[] single;
      single = NULL;
      P = NULL;

      single = new double[nGroups+1];
      for (gNum=0;gNum<nGroups;gNum++)
	single[gNum] = totalXSection[gNum]*1e-24;
      D = single;
    }
  else
    D = paths[nPaths];

  //For FEINDLib, a value of thalf is "inf" for a stable isotope. D[nGroups] will be re-initialized. 
  if (thalf>0)
    D[nGroups] = log(2.0)/thalf;
  else
    D[nGroups] = 0;

  /* setup each reaction */
  if ( (NuclearData::mode == MODE_REVERSE) || (totalXSection == NULL) ) // ALARALib and ADJLib always yield "true"
    for (rxnNum=0;rxnNum<nPaths;rxnNum++)
      {
        debug(4,"Copying reaction %d with %d groups.",rxnNum,nGroups+1);
        relations[rxnNum] = daugKza[rxnNum];
        /* log location of total reaction */
        if (daugKza[rxnNum] == 0)
	  totalRxnNum = rxnNum;
        emitted[rxnNum] = new char[strlen(emissions[rxnNum])+1];
        memCheck(emitted[rxnNum],"NuclearData::setData(...) : emitted[n]");
        strcpy(emitted[rxnNum],emissions[rxnNum]);

        paths[rxnNum] = new double[nGroups+1];
        memCheck(paths[rxnNum],"NuclearData::setData(...) : paths[n]");

        for (gNum=0;gNum<nGroups;gNum++)
	  {
	    paths[rxnNum][gNum] = xSection[rxnNum][gNum]*1e-24;
	    if (strcmp(emitted[rxnNum],"x"))
	      paths[nPaths][gNum] += paths[rxnNum][gNum];
	  }
        paths[rxnNum][nGroups] = xSection[rxnNum][nGroups];
      }
  else //FIENDLib always comes here. It doesn't have a emitted particle implemented
    {
    for (rxnNum=0;rxnNum<nPaths;rxnNum++)
      {
        debug(4,"Copying reaction %d with %d groups.",rxnNum,nGroups+1);
        relations[rxnNum] = daugKza[rxnNum];
        /* log location of total reaction */
        if (daugKza[rxnNum] == 0)
	  totalRxnNum = rxnNum;
        emitted[rxnNum] = new char[strlen(emissions[rxnNum])+1];
        memCheck(emitted[rxnNum],"NuclearData::setData(...) : emitted[n]");
        strcpy(emitted[rxnNum],emissions[rxnNum]);

        paths[rxnNum] = new double[nGroups+1];
        memCheck(paths[rxnNum],"NuclearData::setData(...) : paths[n]");

        for (gNum=0;gNum<nGroups;gNum++)
	  {
	    paths[rxnNum][gNum] = xSection[rxnNum][gNum]*1e-24;
// 	    if (strcmp(emitted[rxnNum],"x"))
// 	      paths[nPaths][gNum] += paths[rxnNum][gNum];
	  }
        paths[rxnNum][nGroups] = xSection[rxnNum][nGroups];
      }

      //Initialize path[nPaths] with totalXSection
       for (gNum=0; gNum<nGroups;gNum++)
         paths[nPaths][gNum] = totalXSection[gNum]*1e-24;

       paths[nPaths][nGroups] = totalXSection[nGroups];
    }

  if (totalRxnNum>-1)
    {
      /* make sure that the decay constant is copied */
      paths[totalRxnNum][nGroups] = paths[nPaths][nGroups];

      /* check where D is pointing */
      if (D == paths[nPaths])
	D = paths[totalRxnNum];

      /* delete summation based total reaction rate */
      delete[] paths[nPaths];

      /* point nPaths to the totalRxnNum */
      paths[nPaths] = paths[totalRxnNum];

      /* delete the emitted entry for the total reaction rate */
      delete[] emitted[totalRxnNum];

      /* shift all channel reactions down by one */
      for (rxnNum=totalRxnNum;rxnNum<nPaths-1;rxnNum++)
	{
	  paths[rxnNum] = paths[rxnNum+1];
	  relations[rxnNum] = relations[rxnNum+1];
	  emitted[rxnNum] = emitted[rxnNum+1];
	}
      /* unpoint the last emitted */
      emitted[nPaths-1] = NULL;
      
      /* shift the total destruction rate down */
      nPaths--;
      paths[nPaths]=paths[nPaths+1];
      paths[nPaths+1] = NULL;
      
    }

  origNPaths = nPaths;

}
Example #10
0
FabAtHomePrinter::~FabAtHomePrinter()
{
     cleanUp();
}
Example #11
0
FieldValueMap::~FieldValueMap()
{
    cleanUp();
}
XPathMatcher::~XPathMatcher()
{
    cleanUp();
}
Example #13
0
int main(int argc , char *argv[])
{
    char str[60];
    int pagesToGet[1024];
    int totalPagesRequested = 0;
    char *cacheSizeString = argv[1];
    int cacheSize = atoi(cacheSizeString);
    page *cache[cacheSize];
    int itemsInCache = 0;
    
    //Get a line from stdin
    while(fgets(str, 60, stdin) != NULL)
    {
        //If the line doesn't start with a number, go to next line
        if(!isdigit(str[0])) continue;
        else {
            int i = 0;
            char currentPage[10];
            
            //Get the number at the beginning of line and put into currentPage
            while(isdigit(str[i])) {
                currentPage[i] = str[i];
                i++;
            }
            
            //After the last digit of the page number we're getting, put a \0
            currentPage[i] = '\0';
            
            //Convert currentPage to an int and add that page number to pagesToGet
            int pageNum = atoi(currentPage);
            pagesToGet[totalPagesRequested] = pageNum;
            totalPagesRequested++;
        }
    }
    
    ///////////////////////////
    // IMPLEMENTATION OF LRU //
    ///////////////////////////
    
    int i;
    int pageFaultCount = 0;
    for(i = 0; i < totalPagesRequested; i++) {
        int positionInCache = isInArray(pagesToGet[i], cache, itemsInCache);
        
        //If the page already exists in cache, continue
        if(positionInCache != -1) {
            cache[positionInCache]->timeInCache = 0;
        }
        else {
            printf("Page fault for page %d\n", pagesToGet[i]);
            pageFaultCount++;
            
            //If there is still empty space in cache, insert page
            if(itemsInCache < cacheSize) {
                page *currentPage = (page *)malloc(sizeof(page));
                cache[itemsInCache] = currentPage;
                cache[itemsInCache]->pageNumber = pagesToGet[i];
                cache[itemsInCache]->timeInCache = 0;
                itemsInCache++;
            }
            
            //We're going to have to remove an old page
            else {
                int indexOfRemoval = findOldestPage(cache, itemsInCache);
                cache[indexOfRemoval]->pageNumber = pagesToGet[i];
                cache[indexOfRemoval]->timeInCache = 0;
            }
        }
        
        incrementTimes(cache, itemsInCache);
    }
    
    printf("Total of %d page requests, total of %d page faults\n", totalPagesRequested, pageFaultCount);
    cleanUp(cache, itemsInCache);
    
    return 0;
}
SieveOfEratosthenes::~SieveOfEratosthenes()
{
  cleanUp();
}
Example #15
0
XMLBigDecimal::~XMLBigDecimal()
{
    cleanUp();
}
Example #16
0
// ================================================
// ~EnvRegionMgr
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
EnvRegionMgr::~EnvRegionMgr() 
{
   cleanUp();
}
Example #17
0
// just for convenience
void DccTransferRecv::failed( const QString& errorMessage )
{
    setStatus( Failed, errorMessage );
    cleanUp();
    emit done( this );
}
Example #18
0
// ================================================
// act
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
void EnvRegionMgr::act( SystemState::ID state, StateContext &stateContext )
{
   switch( state )
   {

   case SystemState::BlackboardPost:
      // This state is for posting things to the blackboard
      bb_->put("EnvRegionsList",&EnvRegions);
      bb_->put("DestroyEnvRegionsList",&DestroyEnvRegions);
      bb_->put("EnvRegionAccessTable",&EnvRegionTable[0]);
      bb_->put("EnvRegionExtendedData",PostedAddEnvRegionExtendedData);

      break;


   case SystemState::BlackboardRetrieve:
      // This state is for retrieving things from the blackboard
      bb_->get( "CigiOutgoingMsg", OmsgPtr );
      bb_->get( "CigiIncomingMsg", ImsgPtr );

      // Position conversion
      bb_->get("CoordCigi2DBase", CoordCigi2DBase);
      bb_->get("CoordDBase2Cigi", CoordDBase2Cigi);

      // Initialize the packet processors
      EnvRegionCtrlP.Init(&EnvRegions,
                          &EnvRegionTable[0],
                          CoordCigi2DBase,
                          CoordDBase2Cigi);
      CompCtrlP.Init(&EnvRegions,&EnvRegionTable[0]);
      ShortCompCtrlP.Init(&EnvRegions,&EnvRegionTable[0]);
      WeatherCtrlP.Init(&EnvRegions,&EnvRegionTable[0]);

      if( ImsgPtr != NULL )
      {
         ImsgPtr->RegisterEventProcessor(CIGI_ENV_RGN_CTRL_PACKET_ID_V3,
            (CigiBaseEventProcessor *) &EnvRegionCtrlP);

         ImsgPtr->RegisterEventProcessor(CIGI_COMP_CTRL_PACKET_ID_V3,
            (CigiBaseEventProcessor *) &CompCtrlP);

         ImsgPtr->RegisterEventProcessor(CIGI_SHORT_COMP_CTRL_PACKET_ID_V3,
            (CigiBaseEventProcessor *) &ShortCompCtrlP);

         ImsgPtr->RegisterEventProcessor(CIGI_WEATHER_CTRL_PACKET_ID_V3,
            (CigiBaseEventProcessor *) &WeatherCtrlP);
      }

      break;

   case SystemState::Reset:
      cleanUp();
      break;

   case SystemState::Operate:
   case SystemState::Debug:
      operate();
	  break;

   case SystemState::Shutdown:
      cleanUp();
      break;

   default:
      break;
	}
	
}
Example #19
0
XMLStringTokenizer::~XMLStringTokenizer()
{
	cleanUp();
}
Example #20
0
NetDemo::~NetDemo()
{
    cleanUp();
}
Example #21
0
File: io.c Project: timburrow/ovj3
node *loadMacro(char *n, int search, int *res)
{   char *prevTempID;
    node *finalTree;
    node *p;

    *res = 0;
    if (3 <= Dflag)
	fprintf(stderr,"load: macro named \"%s\"...\n",n);
    if (init_input(n,search))
    {	finalTree = NULL;
	if (3 <= Dflag)
	    fprintf(stderr,"load: ...initialization of file %s is complete\n"
		   ,fileName
		   );
	prevTempID = tempID; tempID = newTempName("tmpLoadID");
	while (1)
	{   codeTree   = NULL;
	    if (3 <= Dflag)
		fprintf(stderr,"load: ...off to the parser!\n");
	    if (yyparse())
	    {   if (3 <= Dflag)
		    fprintf(stderr,"load: ...parser bombed!\n");
		finalTree = NULL;
                *res = 1;
		releaseWithId(tempID);
		break;
	    }
	    else
	    {   renameAllocation(tempID,"newMacro");
	        if (3 <= Dflag)
		{   fprintf(stderr,"load: ...parser done\n");
		    if (codeTree)
		    {   fprintf(stderr,"load: ...got...\n");
			showTree(0,"load:    ",codeTree);
		    }
		}
		if (codeTree && codeTree->flavour != ENDFILE)
		{   if (codeTree->flavour != EOL)
			if (finalTree)
			{   if (3 <= Dflag)
				fprintf(stderr,"load: ...tie it in\n");
			    p = newNode(CM,&(codeTree->location));
			    addLeftSon(p,codeTree);
			    addLeftSon(p,finalTree);
			    finalTree = p;
			}
			else
			{   if (3 <= Dflag)
				fprintf(stderr,"load: ...first one\n");
			    finalTree = codeTree;
			}
		    else
			if (3 <= Dflag)
			    fprintf(stderr,"load: ...just noise\n");
		}
		else
		{   if (3 <= Dflag)
		    {   fprintf(stderr,"load: ...have...\n");
			showTree(0,"load:    ",finalTree);
		    }
		    break;
		}
	    }
	}
	if (3 < Dflag)
	   fprintf(stderr,"load: time to clean-up!\n");
	free(tempID); tempID = prevTempID;
	cleanUp(n);
	return(finalTree);
    }
    else
   {
           Werrprintf("Command or macro \"%s\" does not exist",n);
           *res = 1;
	   return(NULL);
   }
}
Example #22
0
Match::~Match() {

    cleanUp();
}
Example #23
0
File: Game.cpp Project: lutzee/0x58
int Game::Run(){
    win = new Window(1280,760);

    //The gmae timers start and end
    Stopwatch time;

    //Calls the init function to initilise everything
    if(init() == false){
        return -1;
    }

    //Gets the surface of the screen
    displaySurface = win->getGraphics();

    //initialises SDLs event handler
    SDL_Event event;

    //Gets a timestamp for calculating delta times between ticks
    double oldTime = GetTime();

    //Start the timer
    time.start();

    //The main game loop
    while(running){
        //initialises the player entity velocity to 0,
        //this resets velocity on each loop to prevent the player from carrying
        // on in one direction after the movement keys have stopped being pressed
        entity.velocityX = 0;
        entity.velocityY = 0;

        //Checks to see if an event has occured,
        while(SDL_PollEvent(&event)){
            onEvent(&event);
        }

        //Calculates the delta time for dealing with the tick since last loop
        const double newTime = GetTime();
        double dt = newTime - oldTime;
        oldTime = newTime;

        //Deals with all game state changes
        loop(dt);

        //deals with all rendering
        win->setText(" Score: " + std::to_string(score) + "       Time Left: " + std::to_string(60-(int)(time.read()/1000)) + "s");
        render();
        if(time.read() > 60000 && !theend){
            theend = true;
            time.stop();
            std::ofstream score;
            score.open("score.txt", std::ios::ate | std::ios::out);
            score << "Last score: " << this->score << "\n" << scorestring;
            score.flush();
            score.close();
        running=false;

        while(SDL_WaitEvent(&event)){
            if(event.key.keysym.sym == SDLK_RETURN)
                break;
        }
    }
}
    //this is only called when the game is exiting, makes sure the game exits cleanly with all memory cleared correctly
    cleanUp();

    return 0;
}
Example #24
0
XPathMatcherStack::~XPathMatcherStack() {

    cleanUp();
}
Example #25
0
int main(int argc, char **argv) {
  uchar4 *h_inputImageRGBA, *d_inputImageRGBA;
  uchar4 *h_outputImageRGBA, *d_outputImageRGBA;
  unsigned char *d_redBlurred, *d_greenBlurred, *d_blueBlurred;

  float *h_filter;
  int filterWidth;

  std::string input_file;
  std::string output_file;
  std::string reference_file;
  double perPixelError = 0.0;
  double globalError = 0.0;
  bool useEpsCheck = false;
  std::string blur_impl = "hw";
  switch (argc) {
    case 2:
      input_file = std::string(argv[1]);
      output_file = "HW2_output.png";
      reference_file = "HW2_reference.png";
      break;
    case 3:
      input_file = std::string(argv[1]);
      output_file = std::string(argv[2]);
      reference_file = "HW2_reference.png";
      break;
    case 4:
      input_file = std::string(argv[1]);
      output_file = std::string(argv[2]);
      reference_file = std::string(argv[3]);
      break;
    case 5:
      input_file = std::string(argv[1]);
      output_file = std::string(argv[2]);
      reference_file = std::string(argv[3]);
      blur_impl = std::string(argv[4]);
      break;
    default:
      std::cerr << "Usage: ./HW2 input_file [output_filename] "
                   "[reference_filename] [blur_impl]]"
                << std::endl;
      exit(1);
  }
  // load the image and give us our input and output pointers
  preProcess(&h_inputImageRGBA, &h_outputImageRGBA, &d_inputImageRGBA,
             &d_outputImageRGBA, &d_redBlurred, &d_greenBlurred, &d_blueBlurred,
             &h_filter, &filterWidth, input_file);

  allocateMemoryAndCopyToGPU(numRows(), numCols(), h_filter, filterWidth);
  GpuTimer timer;
  timer.Start();
  // call the students' code
  if (blur_impl == "hw") {
    your_gaussian_blur(h_inputImageRGBA, d_inputImageRGBA, d_outputImageRGBA,
                       numRows(), numCols(), d_redBlurred, d_greenBlurred,
                       d_blueBlurred, filterWidth);
  } else if (blur_impl == "shared") {
    gaussian_blur_shared(h_inputImageRGBA, d_inputImageRGBA, d_outputImageRGBA,
                       numRows(), numCols(), d_redBlurred, d_greenBlurred,
                       d_blueBlurred, filterWidth);
  }

  timer.Stop();
  cudaDeviceSynchronize();
  checkCudaErrors(cudaGetLastError());
  int err = printf("Your code ran in: %f msecs.\n", timer.Elapsed());

  if (err < 0) {
    // Couldn't print! Probably the student closed stdout - bad news
    std::cerr << "Couldn't print timing information! STDOUT Closed!"
              << std::endl;
    exit(1);
  }

  // check results and output the blurred image

  size_t numPixels = numRows() * numCols();
  // copy the output back to the host
  checkCudaErrors(cudaMemcpy(h_outputImageRGBA, d_outputImageRGBA__,
                             sizeof(uchar4) * numPixels,
                             cudaMemcpyDeviceToHost));

  std::cerr << "postProcess output...\n";
  postProcess(output_file, h_outputImageRGBA);

  timer.Start();
  referenceCalculation(h_inputImageRGBA, h_outputImageRGBA, numRows(),
                       numCols(), h_filter, filterWidth);
  timer.Stop();
  std::cerr << "referenceCalculation elapsed: " << timer.Elapsed() << " ms\n";

  std::cerr << "postProcess reference...\n";
  postProcess(reference_file, h_outputImageRGBA);

  //  Cheater easy way with OpenCV
  // generateReferenceImage(input_file, reference_file, filterWidth);

  compareImages(reference_file, output_file, useEpsCheck, perPixelError,
                globalError);

  checkCudaErrors(cudaFree(d_redBlurred));
  checkCudaErrors(cudaFree(d_greenBlurred));
  checkCudaErrors(cudaFree(d_blueBlurred));

  cleanUp();

  return 0;
}
Texture2DManager::~Texture2DManager()
{
	cleanUp();
}
Example #27
0
DatatypeValidator::~DatatypeValidator()
{
	cleanUp();
}
Example #28
0
int main (void) {
	//VECTORS
	pnt A;
	pnt B;

	A.x = 150;
	A.y = 100;

	B.x = 500;
	B.y = 380;

	int speed = 10;
	int vectorA[2] = {A.x, A.y}, vectorB[2] = {B.x, B.y}, vectorP[2] = {200, 200}, vectorH[2], vectorR[2];
	//VECTORS

	int WidthBack, HeightBack, i, j;
	bool quit = 0, gotoAndStopA = 1;
	//const Uint8 *kbState = SDL_GetKeyboardState(NULL);
	char **imgFromSrc;

	SDL_Event e;
	SDL_Window *win;
	SDL_Renderer *ren;
	SDL_Texture *background;
	SDL_Texture *points;
	SDL_Texture *character;

	if (SDL_Init(SDL_INIT_VIDEO) != 0 || (IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG) {
		logSDLError("Init");
		return 1;
	}

	win = SDL_CreateWindow("Vector Movement", WINDOW_OFFSET_X, WINDOW_OFFSET_Y, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
	if (win == NULL) {
		logSDLError("CreateWindow");
		return 2;
	}

	ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (ren == NULL) {
		logSDLError("CreateRenderer");
		return 3;
	}

	imgFromSrc = bmp_xpm;
	background = loadHeader(imgFromSrc, ren);
	points = loadTexture("point.png", ren);
	character = loadTexture("char.png", ren);
	if (background == NULL || points == NULL || character == NULL) {
		logSDLError("loadTexture");
		return 4;
	}

	SDL_RenderClear(ren);

	SDL_QueryTexture(background, NULL, NULL, &WidthBack, &HeightBack);

	WidthBack /= 2;
	HeightBack /= 2;

	for (i = 0; i < WINDOW_WIDTH / WidthBack; i++) {
		for (j = 0; j <= WINDOW_HEIGHT / HeightBack; j++) {
			renderTextureS(background, ren, i * WidthBack, j * HeightBack, WidthBack, HeightBack);
		}
	}

	//WidthPoint = 50;
	//HeightPoint = 50;

	renderTexture(points, ren, A.x, A.y);
	renderTexture(points, ren, B.x, B.y);

	renderTexture(character, ren, vectorP[0], vectorP[1]);

	SDL_RenderPresent(ren);

	while (!quit) {
		while (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT) quit = 1;
			if (e.type == SDL_MOUSEBUTTONDOWN) quit = 1;
		}

		SDL_RenderClear(ren);

		for (i = 0; i < WINDOW_WIDTH / WidthBack; i++) {
			for (j = 0; j <= WINDOW_HEIGHT / HeightBack; j++) {
				renderTextureS(background, ren, i * WidthBack, j * HeightBack, WidthBack, HeightBack);
			}
		}

		renderTexture(points, ren, vectorA[0], vectorA[1]);
		renderTexture(points, ren, vectorB[0], vectorB[1]);

		if (gotoAndStopA == 1) {
			vectorA[0] = A.x; vectorA[1] = A.y; vectorB[0] = B.x; vectorB[1] = B.y;
			vectorR[0] = vectorA[0] - vectorP[0]; vectorR[1] = vectorA[1] - vectorP[1];
			vectorH[0] = speed * vectorR[0] / vectorLen(vectorR); vectorH[1] = speed * vectorR[1] / vectorLen(vectorR);
			vectorP[0] += vectorH[0]; vectorP[1] += vectorH[1];

			renderTextureR(character, ren, vectorA, vectorP[0], vectorP[1]);

			if (vectorLen(vectorR) <= speed / 2) {
				SDL_Delay(1000);

				gotoAndStopA = 0;
			}
		} else if (gotoAndStopA == 0) {
			vectorB[0] = B.x; vectorB[1] = B.y; vectorA[0] = A.x; vectorA[1] = A.y;
			vectorR[0] = vectorB[0] - vectorP[0]; vectorR[1] = vectorB[1] - vectorP[1];
			vectorH[0] = speed * vectorR[0] / vectorLen(vectorR); vectorH[1] = speed * vectorR[1] / vectorLen(vectorR);
			vectorP[0] += vectorH[0]; vectorP[1] += vectorH[1];

			renderTextureR(character, ren, vectorB, vectorP[0], vectorP[1]);

			if (vectorLen(vectorR) <= speed / 2) {
				SDL_Delay(1000);

				gotoAndStopA = 1;
			}
		}

		SDL_Delay(50);
		SDL_RenderPresent(ren);
	}

	SDL_DestroyTexture(background);
	SDL_DestroyTexture(points);
	SDL_DestroyTexture(character);

	cleanUp(win, ren);

	return 0;
}
Example #29
0
Model::~Model(){
  cleanUp();
}
CreationStates::~CreationStates() {cleanUp();}