- Timestamp:
- Feb 2, 2006, 5:58:33 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/story_entities/multi_player_world_data.cc
r6985 r6986 250 250 { 251 251 playable = dynamic_cast<Playable*>(playableList->front()); 252 this->localPlayer->disconnectPlayable();253 252 this->localPlayer->setPlayable(playable); 254 253 this->toggle = !this->toggle; … … 257 256 { 258 257 playable = dynamic_cast<Playable*>(playableList->back()); 259 this->localPlayer->disconnectPlayable();260 258 this->localPlayer->setPlayable(playable); 261 259 this->toggle = !this->toggle; -
trunk/src/world_entities/creatures/md2_creature.cc
r6804 r6986 45 45 MD2Creature::~MD2Creature () 46 46 { 47 this->setPlayer(NULL); 47 48 } 48 49 -
trunk/src/world_entities/playable.cc
r6973 r6986 75 75 delete this->weaponMan; 76 76 77 if (this->currentPlayer) 78 { 79 PRINTF(2)("There is Still a Player subscribed to this Playable (%s::%s)\n", this->getClassName(), this->getName()); 80 81 } 77 // THE DERIVED CLASS MUST UNSUBSCRIBE THE PLAYER THROUGH 78 // this->setPlayer(NULL); 79 // IN ITS DESTRUCTOR. 80 assert(this->currentPlayer == NULL); 82 81 } 83 82 … … 158 157 * @param player the player that shall controll this Playable 159 158 */ 160 bool Playable::subscribePlayer(Player* player) 161 { 162 if (this->currentPlayer != NULL) 163 { 164 PRINTF(1)("Already registered Player:%s to this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName()); 159 bool Playable::setPlayer(Player* player) 160 { 161 // if we already have a Player inside do nothing 162 if (this->currentPlayer != NULL && player != NULL) 163 { 164 printf("No Change in Playable\n"); 165 165 return false; 166 166 } 167 else 168 { 167 168 // eject the Player if player == NULL 169 if (this->currentPlayer != NULL && player == NULL) 170 { 171 PRINTF(0)("Player gets ejected\n"); 172 173 // unsubscibe all events. 174 EventHandler* evh = EventHandler::getInstance(); 175 std::list<int>::iterator ev; 176 for (ev = this->events.begin(); ev != events.end(); ev++) 177 evh->unsubscribe( ES_GAME, (*ev)); 178 179 // leave the entity 180 this->leave(); 181 182 // eject the current Player. 183 Player* ejectPlayer = this->currentPlayer; 184 this->currentPlayer = NULL; 185 // eject the Player. 186 ejectPlayer->setPlayable(NULL); 187 188 return true; 189 } 190 191 // get the new Player inside 192 if (this->currentPlayer == NULL && player != NULL) 193 { 194 PRINTF(0)("New Player gets inside\n"); 169 195 this->currentPlayer = player; 196 if (this->currentPlayer->getPlayable() != this) 197 this->currentPlayer->setPlayable(this); 198 170 199 /*EventHandler*/ 171 200 EventHandler* evh = EventHandler::getInstance(); … … 173 202 for (ev = this->events.begin(); ev != events.end(); ev++) 174 203 evh->subscribe(player, ES_GAME, (*ev)); 204 175 205 this->enter(); 176 206 return true; 177 207 } 178 } 179 180 /** 181 * unsubscribe from all events the controllable needs 182 * @param player the Player, that controlled this Ship. 183 */ 184 bool Playable::unsubscribePlayer(Player* player) 185 { 186 if (this->currentPlayer != player) 187 { 188 PRINTF(1)("not the right Player to unregister from this Playable (%s:%s)\n", this->currentPlayer->getName(), this->getClassName(), this->getName()); 189 return false; 190 } 191 192 else 193 { 194 /*EventHandler*/ 195 EventHandler* evh = EventHandler::getInstance(); 196 std::list<int>::iterator ev; 197 for (ev = this->events.begin(); ev != events.end(); ev++) 198 evh->unsubscribe( ES_GAME, (*ev)); 199 200 this->leave(); 201 this->currentPlayer = NULL; 202 return true; 203 } 204 } 208 209 printf("none\n"); 210 return false; 211 } 212 205 213 206 214 bool Playable::pickup(PowerUp* powerUp) -
trunk/src/world_entities/playable.h
r6966 r6986 28 28 virtual ~Playable(); 29 29 30 virtual void enter() = 0;31 virtual void leave() = 0;32 30 33 31 virtual void die(); … … 44 42 45 43 46 bool s ubscribePlayer(Player* player);47 bool unsubscribePlayer(Player* player);44 bool setPlayer(Player* player); 45 Player* getCurrentPlayer() const { return this->currentPlayer; }; 48 46 49 47 void attachCamera(); … … 68 66 Playable(); 69 67 68 virtual void enter() = 0; 69 virtual void leave() = 0; 70 70 71 void registerEvent(int eventType); 71 72 void unregisterEvent(int eventType); -
trunk/src/world_entities/player.cc
r6985 r6986 49 49 Player::~Player () 50 50 { 51 51 this->setPlayable(NULL); 52 52 } 53 53 … … 55 55 bool Player::setPlayable(Playable* playable) 56 56 { 57 if(playable != NULL && playable->subscribePlayer(this)) 57 if (this->playable == playable) 58 return false; 59 60 // get out of the current Playable 61 if (this->playable != NULL) 58 62 { 63 printf("Player gets ejected from Playable\n"); 64 this->hud.setEnergyWidget(NULL); 65 this->hud.setWeaponManager(NULL); 66 67 Playable* ejectedPlayable = this->playable; 68 69 this->playable = NULL; 70 ejectedPlayable->setPlayer(NULL); 71 } 72 73 if (playable != NULL) 74 { 75 printf("Enter new Playable\n"); 59 76 this->playable = playable; 60 77 this->hud.setEnergyWidget(this->playable->getHealthWidget()); 61 78 this->hud.setWeaponManager(this->playable->getWeaponManager()); 79 80 this->playable->setPlayer(this); 62 81 return true; 63 82 } 64 else 65 return false; 83 84 printf("no change\n"); 85 return true; 66 86 } 67 87 68 bool Player:: disconnectPlayable()88 bool Player::eject() 69 89 { 70 if(this->playable == NULL) return true; 90 this->setPlayable(NULL); 91 } 71 92 72 if(this->playable->unsubscribePlayer(this))73 {74 this->playable = NULL;75 this->hud.setEnergyWidget(NULL);76 this->hud.setWeaponManager(NULL);77 return true;78 }79 else80 return false;81 }82 93 83 94 void Player::weaponConfigChanged() … … 99 110 { 100 111 101 this->disconnectPlayable();102 112 this->setPlayable(dynamic_cast<Playable*>(*node)); 103 113 -
trunk/src/world_entities/player.h
r6985 r6986 29 29 30 30 bool setPlayable(Playable* controllalble); 31 inline Playable* getPlayable() { return this->playable; };32 bool disconnectPlayable();31 inline Playable* getPlayable() const { return this->playable; }; 32 bool eject(); 33 33 34 34 void weaponConfigChanged(); -
trunk/src/world_entities/space_ships/helicopter.cc
r6947 r6986 48 48 Helicopter::~Helicopter () 49 49 { 50 this->setPlayer(NULL); 50 51 } 51 52 … … 123 124 this->cameraNode.setParentMode(PNODE_ALL); 124 125 this->cameraNode.setRelCoor(Vector(0,1,0)); 125 126 126 127 // rotors 127 128 this->topRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); … … 141 142 this->velocity = Vector(0.0,0.0,0.0); 142 143 this->velocityDir = Vector(1.0,0.0,0.0); 143 144 144 145 // very, very old stuff 145 146 // GLGuiButton* button = new GLGuiPushButton(); -
trunk/src/world_entities/space_ships/hover.cc
r6882 r6986 39 39 */ 40 40 Hover::~Hover () 41 {} 41 { 42 this->setPlayer(NULL); 43 } 42 44 43 45 /** -
trunk/src/world_entities/space_ships/space_ship.cc
r6966 r6986 62 62 SpaceShip::~SpaceShip () 63 63 { 64 this->setPlayer(NULL); 64 65 } 65 66
Note: See TracChangeset
for help on using the changeset viewer.