Changeset 11071 for code/trunk/src/modules/gametypes/SpaceRaceController.cc
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/gametypes/SpaceRaceController.cc
r10318 r11071 59 59 60 60 virtualCheckPointIndex = -2; 61 if (ObjectList<SpaceRaceManager> ::size() != 1)62 orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager> ::size() << endl;63 for ( ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)64 { 65 checkpoints = it->getAllCheckpoints();66 nextRaceCheckpoint_ = it->findCheckpoint(0);61 if (ObjectList<SpaceRaceManager>().size() != 1) 62 orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager>().size() << endl; 63 for (SpaceRaceManager* manager : ObjectList<SpaceRaceManager>()) 64 { 65 checkpoints = manager->getAllCheckpoints(); 66 nextRaceCheckpoint_ = manager->findCheckpoint(0); 67 67 } 68 68 … … 98 98 RaceCheckPoint* point2 = findCheckpoint((*numb)); 99 99 100 //if(point2 != NULL)100 //if(point2 != nullptr) 101 101 //placeVirtualCheckpoints((*it), point2); 102 102 } … … 126 126 staticRacePoints_ = findStaticCheckpoints(nextRaceCheckpoint_, checkpoints); 127 127 // initialisation of currentRaceCheckpoint_ 128 currentRaceCheckpoint_ = NULL;128 currentRaceCheckpoint_ = nullptr; 129 129 130 130 int i; 131 for (i = -2; findCheckpoint(i) != NULL; i--)131 for (i = -2; findCheckpoint(i) != nullptr; i--) 132 132 { 133 133 continue; … … 154 154 { 155 155 std::map<RaceCheckPoint*, int> zaehler; // counts how many times the checkpoint was reached (for simulation) 156 for ( unsigned int i = 0; i < allCheckpoints.size(); i++)157 { 158 zaehler.insert(std::pair<RaceCheckPoint*, int>( allCheckpoints[i],0));156 for (RaceCheckPoint* checkpoint : allCheckpoints) 157 { 158 zaehler.insert(std::pair<RaceCheckPoint*, int>(checkpoint,0)); 159 159 } 160 160 int maxWays = rekSimulationCheckpointsReached(currentCheckpoint, zaehler); 161 161 162 162 std::vector<RaceCheckPoint*> returnVec; 163 for ( std::map<RaceCheckPoint*, int>::iterator iter = zaehler.begin(); iter != zaehler.end(); iter++)164 { 165 if ( iter->second == maxWays)166 { 167 returnVec.push_back( iter->first);163 for (const auto& mapEntry : zaehler) 164 { 165 if (mapEntry.second == maxWays) 166 { 167 returnVec.push_back(mapEntry.first); 168 168 } 169 169 } … … 187 187 { 188 188 int numberOfWays = 0; // counts number of ways from this Point to the last point 189 for ( std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)190 { 191 if (currentCheckpoint == findCheckpoint( *it))189 for (int checkpointIndex : currentCheckpoint->getNextCheckpoints()) 190 { 191 if (currentCheckpoint == findCheckpoint(checkpointIndex)) 192 192 { 193 193 //orxout() << currentCheckpoint->getCheckpointIndex()<<endl; 194 194 continue; 195 195 } 196 if (findCheckpoint( *it) == NULL)197 orxout(internal_warning) << "Problematic Point: " << (*it)<< endl;196 if (findCheckpoint(checkpointIndex) == nullptr) 197 orxout(internal_warning) << "Problematic Point: " << checkpointIndex << endl; 198 198 else 199 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint( *it), zaehler);199 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(checkpointIndex), zaehler); 200 200 } 201 201 zaehler[currentCheckpoint] += numberOfWays; … … 209 209 float SpaceRaceController::distanceSpaceshipToCheckPoint(RaceCheckPoint* CheckPoint) 210 210 { 211 if (this->getControllableEntity() != NULL)211 if (this->getControllableEntity() != nullptr) 212 212 { 213 213 return (CheckPoint->getPosition()- this->getControllableEntity()->getPosition()).length(); … … 223 223 { 224 224 float minDistance = 0; 225 RaceCheckPoint* minNextRaceCheckPoint = NULL;225 RaceCheckPoint* minNextRaceCheckPoint = nullptr; 226 226 227 227 // find the next checkpoint with the minimal distance 228 for ( std::set<int>::iterator it = raceCheckpoint->getNextCheckpoints().begin(); it != raceCheckpoint->getNextCheckpoints().end(); ++it)229 { 230 RaceCheckPoint* nextRaceCheckPoint = findCheckpoint( *it);228 for (int checkpointIndex : raceCheckpoint->getNextCheckpoints()) 229 { 230 RaceCheckPoint* nextRaceCheckPoint = findCheckpoint(checkpointIndex); 231 231 float distance = recCalculateDistance(nextRaceCheckPoint, this->getControllableEntity()->getPosition()); 232 232 233 if (distance < minDistance || minNextRaceCheckPoint == NULL)233 if (distance < minDistance || minNextRaceCheckPoint == nullptr) 234 234 { 235 235 minDistance = distance; … … 255 255 { 256 256 float minimum = std::numeric_limits<float>::max(); 257 for ( std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it != currentCheckPoint->getNextCheckpoints().end(); ++it)257 for (int checkpointIndex : currentCheckPoint->getNextCheckpoints()) 258 258 { 259 259 int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length()); 260 260 261 minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint( *it), currentCheckPoint->getPosition()));261 minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(checkpointIndex), currentCheckPoint->getPosition())); 262 262 // minimum of distanz from 'currentPosition' to the next static Checkpoint 263 263 } … … 271 271 RaceCheckPoint* SpaceRaceController::adjustNextPoint() 272 272 { 273 if (currentRaceCheckpoint_ == NULL) // no Adjust possible273 if (currentRaceCheckpoint_ == nullptr) // no Adjust possible 274 274 275 275 { … … 289 289 RaceCheckPoint* SpaceRaceController::findCheckpoint(int index) const 290 290 { 291 for ( size_t i = 0; i < this->checkpoints_.size(); ++i)292 if ( this->checkpoints_[i]->getCheckpointIndex() == index)293 return this->checkpoints_[i];294 return NULL;291 for (RaceCheckPoint* checkpoint : this->checkpoints_) 292 if (checkpoint->getCheckpointIndex() == index) 293 return checkpoint; 294 return nullptr; 295 295 } 296 296 … … 299 299 orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl; 300 300 RaceCheckPoint* newTempRaceCheckPoint; 301 for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it) 301 ObjectList<SpaceRaceManager> list; 302 for (ObjectList<SpaceRaceManager>::iterator it = list.begin(); it!= list.end(); ++it) 302 303 { 303 304 newTempRaceCheckPoint = new RaceCheckPoint((*it)); … … 347 348 void SpaceRaceController::tick(float dt) 348 349 { 349 if (this->getControllableEntity() == NULL || this->getControllableEntity()->getPlayer() == NULL)350 if (this->getControllableEntity() == nullptr || this->getControllableEntity()->getPlayer() == nullptr ) 350 351 { 351 352 //orxout()<< this->getControllableEntity() << " in tick"<<endl; … … 414 415 btScalar radiusObject; 415 416 416 for ( std::vector<StaticEntity*>::const_iterator it = allObjects.begin(); it != allObjects.end(); ++it)417 { 418 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++)419 { 420 btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();421 if(currentShape == NULL)417 for (StaticEntity* object : allObjects) 418 { 419 for (int everyShape=0; object->getAttachedCollisionShape(everyShape) != nullptr; everyShape++) 420 { 421 btCollisionShape* currentShape = object->getAttachedCollisionShape(everyShape)->getCollisionShape(); 422 if(currentShape == nullptr) 422 423 continue; 423 424 … … 444 445 for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it) 445 446 { 446 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++)447 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != nullptr; everyShape++) 447 448 { 448 449 btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape(); 449 if(currentShape == NULL)450 if(currentShape == nullptr) 450 451 continue; 451 452 … … 488 489 std::vector<StaticEntity*> problematicObjects; 489 490 490 for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it) 491 { 492 493 if (dynamic_cast<RaceCheckPoint*>(*it) != NULL) 491 ObjectList<StaticEntity> list; 492 for (ObjectList<StaticEntity>::iterator it = list.begin(); it!= list.end(); ++it) 493 { 494 495 if (dynamic_cast<RaceCheckPoint*>(*it) != nullptr) 494 496 { 495 497 continue; … … 537 539 // btVector3 positionObject; 538 540 // btScalar radiusObject; 539 // if((*it)== NULL)541 // if((*it)==nullptr) 540 542 // { orxout()<<"Problempoint 1.1"<<endl; continue;} 541 543 // //TODO: Probably it points on a wrong object 542 // for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!= 0; everyShape++)544 // for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++) 543 545 // { 544 // if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()== NULL)546 // if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr) 545 547 // { continue;} 546 548 // … … 570 572 // btVector3 positionObject; 571 573 // btScalar radiusObject; 572 // if((*it)== NULL)574 // if((*it)==nullptr) 573 575 // { orxout()<<"Problempoint 1"<<endl; continue;} 574 // for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!= 0; everyShape++)576 // for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++) 575 577 // { 576 // if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()== NULL)578 // if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr) 577 579 // { orxout()<<"Problempoint 2.2"<<endl; continue;} 578 580 // (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
Note: See TracChangeset
for help on using the changeset viewer.