Changeset 11241
- Timestamp:
- Oct 17, 2016, 8:35:19 PM (8 years ago)
- Location:
- code/branches/HUD_HS16/src/modules/pickup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc
r11240 r11241 76 76 this->defaultRepresentation_ = new PickupRepresentation(); 77 77 78 orxout( ) << "PickupManager created." << endl;78 orxout(internal_info, context::pickups) << "PickupManager created." << endl; 79 79 } 80 80 … … 285 285 if(pickedUp) // If the Pickupable has changed to picked up, it is added to the required lists. 286 286 { 287 index = this->getPickupIndex(); // Ge a new identifier (index) for the Pickupable.287 index = this->getPickupIndex(); // Get a new identifier (index) for the Pickupable. 288 288 // Add the Pickupable to the indexes_ and pickups_ lists. 289 289 this->indexes_[pickup] = index; 290 290 this->pickups_[index] = pickup; 291 // TODO: Add pickup keybinding ------------------------------------------- 291 292 //Add pickup keybinding 292 293 if( KeyBinderManager::exists() ) 293 KeyBinderManager::getInstance().getCurrent()->setBinding("KeyESC", "Keys.KeyNumpad0",true);294 addKeyBindingForNewPickup(pickup, index); 294 295 else 295 296 orxout() << "Could not create new keybinding because KeyBinderManager doesn't exist." << endl; 296 //----------------------------297 298 297 } 299 298 else // If it was dropped, it is removed from the required lists. … … 303 302 index = it->second; 304 303 305 // Remove the Pickupable from the indexes_ and pickups_ list. 306 this->indexes_.erase(it); 307 this->pickups_.erase(index); 308 // TODO: Remove pickup keybinding ------------------------------------ 304 //Remove pickup keybinding 309 305 if( KeyBinderManager::exists() ) 310 KeyBinderManager::getInstance().getCurrent()->setBinding("", "Keys.KeyNumpad0",true);306 removeKeyBindingForOldPickup(pickup, index); 311 307 else 312 308 orxout() << "Could not delete old keybinding because KeyBinderManager doesn't exist." << endl; 313 //---------------------------- 309 310 // Remove the Pickupable from the indexes_ and pickups_ list. 311 this->indexes_.erase(pickup); 312 this->pickups_.find(index)->second=nullptr; //set to null, so that can be indentified as free slot by getPickupIndex() 314 313 } 315 314 … … 336 335 } 337 336 } 337 338 } 339 340 //PRECONDITION: KeyBinderManager exists, pickup is not NULL, 0 < index < 9 341 //FUNCTION: Adds a keybinding for the new pickup using its index 342 void PickupManager::addKeyBindingForNewPickup(Pickupable* pickup, uint32_t index) 343 { 344 std::string name="Keys.KeyNumpad"; 345 std::string binding=""; 346 347 name.append(std::to_string(index)); 348 349 KeyBinderManager::getInstance().getCurrent()->setBinding("KeyESC", name, true); // TODO do not set all bindings to ESC 350 351 orxout() << "Keybinding for item " << index << " has been added on keybinding " << name << endl; 352 353 354 } 355 356 //PRECONDITION: KeyBinderManager exists, pickup is not NULL, 0 < index < 9 357 //FUNCTION: Removes the keybinding of the pickup using its index 358 void PickupManager::removeKeyBindingForOldPickup(Pickupable* pickup, uint32_t index) 359 { 360 std::string name="Keys.KeyNumpad"; 361 std::string binding=""; 362 363 name.append(std::to_string(index)); 364 365 KeyBinderManager::getInstance().getCurrent()->setBinding("", name, true); 366 367 orxout() << "Keybinding for item " << index << " has been removed on keybinding " << name << endl; 338 368 339 369 } … … 417 447 Pickupable* pickupable = this->pickups_.find(pickup)->second; 418 448 if(pickupable != nullptr) 449 { 419 450 pickupable->drop(); 451 452 } 420 453 } 421 454 // If we're neither server nor standalone we drop the pickup by calling dropPickupNetworked() of the PickupManager on the server. … … 510 543 /** 511 544 @brief 512 Get a new index for a Pickupable.513 This will work as long as the number of Pickupables that are picked up is sufficiently small and as long as they don't exist forever.545 Get a new index between 0 and 9 for a Pickupable. 546 If all slots are occupied, the Pickupable in the first slot will be dropped. 514 547 @return 515 548 Returns the new index. … … 517 550 uint32_t PickupManager::getPickupIndex(void) 518 551 { 519 if(this->pickupHighestIndex_ == uint32_t(~0x0)-1) // If we've reached the highest possible number, we wrap around. 520 this->pickupHighestIndex_ = 0; 521 return this->pickupHighestIndex_++; 552 //check if there are free slots available 553 554 for(uint32_t i=0; i<10; i++) 555 { 556 if(pickups_.find(i)->second==nullptr) return i; 557 } 558 //all slots are full and we have to drop sth 559 orxout() << "everything was full and we have now dropped the first element" << endl; 560 this->dropPickup(0); 561 return 0; 522 562 } 523 563 -
code/branches/HUD_HS16/src/modules/pickup/PickupManager.h
r11071 r11241 167 167 uint32_t getPickupIndex(void); //!< Get a new index for a Pickupable. 168 168 169 void addKeyBindingForNewPickup(Pickupable* pickup, uint32_t index); 170 void removeKeyBindingForOldPickup(Pickupable* pickup, uint32_t index); 171 169 172 }; // tolua_export 170 173
Note: See TracChangeset
for help on using the changeset viewer.