Пример #1
0
void
_SoNurbsSurfaceEvaluator::bgnqstrip( void )
{
    glBegin(GL_TRIANGLES);
    for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) )
        map->startNewTriStrip();
}
Пример #2
0
void
_SoNurbsSurfaceEvaluator::bgnclosedline( void )
{
    glBegin(GL_LINE_LOOP);
    for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) )
        map->startNewTriStrip();
}
Пример #3
0
void
_SoNurbsSurfaceEvaluator::setv( REAL v, int index )
{
    valid[index][0] = valid[index][1] = 0;
    vvals[index] = v;

    for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) ) 
  map->setv( v, index );
}
Пример #4
0
_SoNurbsSurfaceMap *
_SoNurbsSurfaceEvaluator::typeToMap( long type )
{
    _SoNurbsSurfaceMap *map;
    for( map = firstMap(); map; map = nextMap(map) )
        if( map->isType( type ) ) break;

    return map;
}
Пример #5
0
/*-------------------------------------------------------------------------
 * bgnmap2f - preamble to surface definition and evaluations
 *-------------------------------------------------------------------------
 */
void
_SoNurbsSurfaceEvaluator::bgnmap2f( long )
{
    for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) )
  map->disable();
    lru = 0;
    vvals[0] = vvals[1] = vvals[2] =*(REAL *)(& NaN);
    validreset();
}
Пример #6
0
void generateTagCloudData(struct hashMap *ht, char *outFileName ) {
  /* Read data to get max value */
  struct mapItr *myItr;
  
  myItr = createMapIterator(ht);
  
  char *word;
  int *count;
  int maxVal = 0;

  while(hasNextMap(myItr)) {
      word = (char *)nextMap(myItr);
      count = (int *)atMap(ht,word, myCompare, hash2);
      if(*count > maxVal)
          maxVal = *count;
    }
  
  printf("MAX VAL = %d\n", maxVal);

  initMapIterator(ht, myItr);


  /* Normalize all values */
   while(hasNextMap(myItr)) {
      word = (char*) nextMap(myItr);
      count = (int *)atMap(ht,word, myCompare, hash2);
      *count = sqrt(*count);
    } 

  /* Now write them to file */
  
  initMapIterator(ht, myItr);
  
  FILE *tagFile = fopen(outFileName, "w+");
  
  while(hasNextMap(myItr)) {
      word = (char *)nextMap(myItr);
      count = atMap(ht,word, myCompare, hash2);
      fprintf(tagFile, "%s,%d\n", word, *count);
    }

  fclose(tagFile);
}
Пример #7
0
void Game::onKeyPressed(sf::Event event) {
    switch(event.Key.Code) {
        case sf::Keyboard::Escape:
            onClose();
            break;
        case sf::Keyboard::N:
            nextMap();
            break;
        case sf::Keyboard::P:
            prevMap();
            break;
        default:
            break;
    }
}
Пример #8
0
void Game::update(sf::Time frametime) {
    Input input;
    input.Left = sf::Keyboard::IsKeyPressed(sf::Keyboard::Left);
    input.Right = sf::Keyboard::IsKeyPressed(sf::Keyboard::Right);
    input.Up = sf::Keyboard::IsKeyPressed(sf::Keyboard::Up);
    input.Down = sf::Keyboard::IsKeyPressed(sf::Keyboard::Down);
    input.LeftCarve = sf::Keyboard::IsKeyPressed(sf::Keyboard::A);
    input.RightCarve = sf::Keyboard::IsKeyPressed(sf::Keyboard::Z);
    
    int status = world->update(frametime, input);
    switch(status) {
        case World::WIN:
            nextMap();
            break;
        default:
            break;
    }
}
Пример #9
0
/*-------------------------------------------------------------------------
 * compute - output cached point or evaluate point and output
 *-------------------------------------------------------------------------
 */
void
_SoNurbsSurfaceEvaluator::compute( REAL *domain, int index, int place )
{
    assert( vvals[index] == domain[1] );
    if( ((place >= valid[index][0]) && (place < valid[index][1])) ) {
  assert( place != 0 );
  for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) )
      map->output( domain, index, place );
    } else {
  if( place >= MAXCACHED ) {
      place = 0;
  } else if( place == valid[index][1] ) {
      valid[index][1]++;
  } else if( valid[index][0] == valid[index][1] ) {
      valid[index][0] = place;
      valid[index][1] = place+1;
  } else if( place == valid[index][0]-1 ) {
      valid[index][0]--;
  }
  mapeval( domain, index, place );
    }
}
Пример #10
0
 bool MapChangeCommandHandler::handle ( int playerID, bz_ApiString command, bz_ApiString message, bz_APIStringList *params )
 {
   std::string cmd;
   tolower(command.c_str(),cmd);

   std::string param;
   if ( params && params->size() )
     param = params->get(0).c_str();

   if ( cmd == "mapnext" )
   {
     if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange"))
      nextMap();
     else
      bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to change maps");
     return true;
   }
   else if ( cmd == "mapreset" )
   {
     if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange"))
     {
       resetGames();
       currentIndex = -1;
       nextMap();
     }
     else
       bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to reset map rotation");
     return true;
   }
   else if ( cmd == "mapcyclemode" )
   {
     if (param.size())
     {
       if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange"))
       {
	cycleMode = cycleFromString(param.c_str());
	std::string mode = "Map Rotation Mode changed to ";
	mode += param.c_str();
	bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,mode.c_str());
       }
       else
	 bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to set map modes");
    }
     else
     {
       std::string mode = "Current Map Rotation Mode:";
       mode += cycleToString(cycleMode);
       bz_sendTextMessage(BZ_SERVER,playerID,mode.c_str());
     }
     return true;
   }
   else if ( cmd == "mapendmode" )
   {
     if (param.size())
     {
	if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange"))
	{
	  startTime = bz_getCurrentTime();
	  endCond = condFromString(param);
	  std::string mode = "Map End Condition changed to ";
	  mode += param;
	  bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,mode.c_str());
	}
	else
	  bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to set map modes");
     }
     else
     {
       std::string mode = "Current End Condtion:";
       mode += condToString(endCond);
       bz_sendTextMessage(BZ_SERVER,playerID,mode.c_str());
     }
     return true;
   }
   else if ( cmd == "maplist" )
   {
     bz_sendTextMessage(BZ_SERVER,playerID,"Maps In Rotation");
     for (int i = 0; i < (int)gameList.size(); i++ )
	 bz_sendTextMessage(BZ_SERVER,playerID,gameList[i].mapFile.c_str());
     return true;
   }
   else if ( cmd == "maplimit" )
   {
     if (endCond == eNoPlayers || endCond == eManual )
     {
       bz_sendTextMessage(BZ_SERVER,playerID,"The currnet mode has no numeric limit");
       return true;
     }

     if (param.size())
     {
       if (bz_getAdmin (playerID) || bz_hasPerm(playerID,"mapchange"))
       {
	 std::string mode = "Map Change limit changed to ";
	if (endCond == eTimedGame)
	{
	  startTime = bz_getCurrentTime();
	  timeLimit = atof(param.c_str())*60;
	  mode += param.c_str();
	  mode += "minutes";
	}
	else
	{
	  scoreCapLimit = atoi(param.c_str());
	  mode += param.c_str();
	  if (endCond == eMaxKillScore)
	    mode += " Kills";
	  else
	    mode += " Caps";
	}
	bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,mode.c_str());
       }
       else
       {
	 std::string mode = "Map Change limit is ";
	 if (endCond == eTimedGame)
	   mode += format("%f minutes", timeLimit/60.0);
	 else
	 {
	    mode += format("%d", scoreCapLimit);
	   if (endCond == eMaxKillScore)
	     mode += " Kills";
	   else
	     mode += " Caps";
	 }
	 bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permision to set map limits");
       }
     }
     else
     {
       std::string mode = "Current End Condtion:";
       mode += condToString(endCond);
       bz_sendTextMessage(BZ_SERVER,playerID,mode.c_str());
     }
     return true;
   }
   return false;
 }
Пример #11
0
void MapChangeEventHandler::process ( bz_EventData *eventData )
{
  if (!eventData)
    return;

  switch(eventData->eventType)
  {
    case bz_ePlayerJoinEvent:
    case bz_ePlayerPartEvent:
    {
      bz_PlayerJoinPartEventData_V1 *joinPart = (bz_PlayerJoinPartEventData_V1*)eventData;

      if ( joinPart->eventType == bz_ePlayerJoinEvent )
      {
	if (startTime < 0)
	  startTime = joinPart->eventTime;
      }
      else if (endCond == eNoPlayers)
      {
	if (!anyPlayers())
	  nextMap();
      }
    }
    break;

    case bz_ePlayerDieEvent:
      {
	if (endCond != eMaxKillScore)
	  break;

	bz_PlayerDieEventData_V1 *die = (bz_PlayerDieEventData_V1*)eventData;

	if ( bz_getPlayerWins(die->killerID) >= scoreCapLimit )
	  nextMap();
      }
      break;

    case bz_eCaptureEvent:
      {
	if (endCond != eMaxCapScore)
	  break;

	bz_CTFCaptureEventData_V1 *cap = (bz_CTFCaptureEventData_V1*)eventData;

	if ( bz_getTeamWins(cap->teamCapping) >= scoreCapLimit )
	  nextMap();
      }
      break;

    case bz_eTickEvent:
      {
	if (endCond != eTimedGame && startTime >= 0)
	  break;

	bz_TickEventData_V1 *tick = (bz_TickEventData_V1*)eventData;

	double timeDelta = tick->eventTime - startTime;
	if ( timeDelta >= timeLimit )
	  nextMap();
      }
      break;

    case bz_eGetWorldEvent:
      {
	if (currentIndex < 0 )
	  break;

	bz_GetWorldEventData_V1 *world =(bz_GetWorldEventData_V1*)eventData;

	world->generated = false;
	world->worldFile = gameList[currentIndex].mapFile.c_str();
	gameList[currentIndex].hasBeenPlayed = true;
      }
      break;

    case bz_eListServerUpdateEvent:
      {
	if (currentIndex < 0 )
	  break;

	bz_ListServerUpdateEvent_V1 *update =(bz_ListServerUpdateEvent_V1*)eventData;

	std::string desc = update->description.c_str();
	desc = replace_all(desc,std::string("%M"),gameList[currentIndex].publicText);
	update->description = desc.c_str();
	update->handled = true;
     }
      break;
 }
}
Пример #12
0
Файл: main.c Проект: wsims/CS261
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    fileptr = fopen(filename, "r");
    if (fileptr != NULL) {
        int *val, *x;
        char *word;
        while ((word = getWord(fileptr))) {
            if (containsKey(hashTable, word)) {
                val = (int *) atMap(hashTable, word);
                (*val) ++;
                free(word);
            } else {
                x = malloc(sizeof(int));
                *x = 1;
                insertMap(hashTable, word, x);
            }
        }
        fclose(fileptr);
    } else printf("Error opening file.\n");
	/*... concordance code ends here ...*/

	printMap(hashTable, keyPrint, valPrint);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
    printMap(hashTable, keyPrint, valPrint);
    printKeyValues(hashTable, keyPrint, valPrint);
         /* Test out the iterator */
#ifdef ITERATOR_IN
         struct mapItr *myItr;
         myItr = createMapIterator(hashTable);

         KeyType  key;

         /* Free up our keys and values using our iterator!!  Also printing them as we go along */
         while(hasNextMap(myItr))
           {
             key = nextMap(myItr);
             int *value = atMap(hashTable,key);
             printf("Freeing ...Key = %s, value = %d \n", key, *value);
             free(value);  /* To match the malloc above*/
             free(key);

           }
#endif


        deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
Пример #13
0
void
_SoNurbsSurfaceEvaluator::mapeval( REAL *domain, int index, int place )
{
    for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) )
  map->mapeval( domain, index, place );
}
Пример #14
0
/*-------------------------------------------------------------------------
 * endmap2f - postamble to a map
 *-------------------------------------------------------------------------
 */
void
_SoNurbsSurfaceEvaluator::endmap2f( void )
{
    for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) )
  map->disable();
}
Пример #15
0
void
_SoNurbsSurfaceEvaluator::swaptmesh( void )
{
    for( _SoNurbsSurfaceMap *map = firstMap(); isMap( map ); map = nextMap(map) )
        map->swapTriStripVertices();
}
Пример #16
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
  int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
  void*  key;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
  if(argc == 2)
      filename = argv[1];
  else
      filename = "input1.txt"; /*specify your input text file here*/

  printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);
  printf("Successfully created hashtable\n");
	/*... concordance code goes here ...*/
    fileptr = fopen(filename, "r+");
    char* wordNext = "starter";
    while(wordNext != 0) {
        wordNext = getWord(fileptr);
        if(wordNext != 0) {
            if(containsKey(hashTable, wordNext, myCompare, hash2) == 0){
                void* v = malloc(sizeof(void*));
                *(int*)v = 1;
                insertMap(hashTable, wordNext, v, myCompare, hash2);
            }
            else {
                /*int newVal = *(int*)(atMap(hashTable, wordNext, myCompare, hash2)) + 1;
                 void* newVal2 = &newVal;
                 insertMap(hashTable, wordNext, newVal2, myCompare, hash2);*/
                *(int*)(atMap(hashTable, wordNext, myCompare, hash2)) = *(int*)atMap(hashTable, wordNext, myCompare, hash2)+1;
            }
        }
    }
	/*... concordance code ends here ...*/

	printMap(hashTable, keyPrint, valPrint);

	fclose(fileptr);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

  assert(containsKey(hashTable, "and", myCompare, hash2));
	removeKey(hashTable, "and", myCompare, hash2);
	removeKey(hashTable, "me", myCompare, hash2);
	removeKey(hashTable, "the", myCompare, hash2);
	
    /* printMap(hashTable); */
    printKeyValues(hashTable, keyPrint, valPrint);

    /* For Tag Cloud */
    generateTagCloudData(hashTable,"tag.csv");

    /* Free up our keys and values using our iterator!!  Also printing them as we go along */
    struct mapItr *myItr = createMapIterator(hashTable);
    while(hasNextMap(myItr)) {
        key = nextMap(myItr);
        int *value = atMap(hashTable,key, myCompare, hash2);
        printf("Freeing ...Key = %s, value = %d \n", key, *value);
        free(value);  /* To match the malloc above*/
        free(key);
    }

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}