Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6986 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Feb 2, 2006, 5:58:33 PM (19 years ago)
Author:
bensch
Message:

trunk: brainfuck: interface to Playable much bea now

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/story_entities/multi_player_world_data.cc

    r6985 r6986  
    250250  {
    251251    playable = dynamic_cast<Playable*>(playableList->front());
    252     this->localPlayer->disconnectPlayable();
    253252    this->localPlayer->setPlayable(playable);
    254253    this->toggle = !this->toggle;
     
    257256  {
    258257    playable = dynamic_cast<Playable*>(playableList->back());
    259     this->localPlayer->disconnectPlayable();
    260258    this->localPlayer->setPlayable(playable);
    261259    this->toggle = !this->toggle;
  • trunk/src/world_entities/creatures/md2_creature.cc

    r6804 r6986  
    4545MD2Creature::~MD2Creature ()
    4646{
     47  this->setPlayer(NULL);
    4748}
    4849
  • trunk/src/world_entities/playable.cc

    r6973 r6986  
    7575  delete this->weaponMan;
    7676
    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);
    8281}
    8382
     
    158157 * @param player the player that shall controll this Playable
    159158 */
    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());
     159bool 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");
    165165    return false;
    166166  }
    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");
    169195    this->currentPlayer = player;
     196    if (this->currentPlayer->getPlayable() != this)
     197      this->currentPlayer->setPlayable(this);
     198
    170199    /*EventHandler*/
    171200    EventHandler* evh = EventHandler::getInstance();
     
    173202    for (ev = this->events.begin(); ev != events.end(); ev++)
    174203      evh->subscribe(player, ES_GAME, (*ev));
     204
    175205    this->enter();
    176206    return true;
    177207  }
    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
    205213
    206214bool Playable::pickup(PowerUp* powerUp)
  • trunk/src/world_entities/playable.h

    r6966 r6986  
    2828    virtual ~Playable();
    2929
    30     virtual void enter() = 0;
    31     virtual void leave() = 0;
    3230
    3331    virtual void die();
     
    4442
    4543
    46     bool subscribePlayer(Player* player);
    47     bool unsubscribePlayer(Player* player);
     44    bool setPlayer(Player* player);
     45    Player* getCurrentPlayer() const { return this->currentPlayer; };
    4846
    4947    void attachCamera();
     
    6866    Playable();
    6967
     68    virtual void enter() = 0;
     69    virtual void leave() = 0;
     70
    7071    void registerEvent(int eventType);
    7172    void unregisterEvent(int eventType);
  • trunk/src/world_entities/player.cc

    r6985 r6986  
    4949Player::~Player ()
    5050{
    51 
     51  this->setPlayable(NULL);
    5252}
    5353
     
    5555bool Player::setPlayable(Playable* playable)
    5656{
    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)
    5862  {
     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");
    5976      this->playable = playable;
    6077      this->hud.setEnergyWidget(this->playable->getHealthWidget());
    6178      this->hud.setWeaponManager(this->playable->getWeaponManager());
     79
     80      this->playable->setPlayer(this);
    6281      return true;
    6382  }
    64   else
    65     return false;
     83
     84  printf("no change\n");
     85  return true;
    6686}
    6787
    68 bool Player::disconnectPlayable()
     88bool Player::eject()
    6989 {
    70    if(this->playable == NULL) return true;
     90   this->setPlayable(NULL);
     91 }
    7192
    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    else
    80      return false;
    81  }
    8293
    8394 void Player::weaponConfigChanged()
     
    99110       {
    100111
    101          this->disconnectPlayable();
    102112         this->setPlayable(dynamic_cast<Playable*>(*node));
    103113
  • trunk/src/world_entities/player.h

    r6985 r6986  
    2929
    3030    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();
    3333
    3434    void              weaponConfigChanged();
  • trunk/src/world_entities/space_ships/helicopter.cc

    r6947 r6986  
    4848Helicopter::~Helicopter ()
    4949{
     50  this->setPlayer(NULL);
    5051}
    5152
     
    123124  this->cameraNode.setParentMode(PNODE_ALL);
    124125  this->cameraNode.setRelCoor(Vector(0,1,0));
    125  
     126
    126127  // rotors
    127128  this->topRotor.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     
    141142  this->velocity = Vector(0.0,0.0,0.0);
    142143  this->velocityDir = Vector(1.0,0.0,0.0);
    143  
     144
    144145  // very, very old stuff
    145146  //  GLGuiButton* button = new GLGuiPushButton();
  • trunk/src/world_entities/space_ships/hover.cc

    r6882 r6986  
    3939 */
    4040Hover::~Hover ()
    41 {}
     41{
     42  this->setPlayer(NULL);
     43}
    4244
    4345/**
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6966 r6986  
    6262SpaceShip::~SpaceShip ()
    6363{
     64  this->setPlayer(NULL);
    6465}
    6566
Note: See TracChangeset for help on using the changeset viewer.