Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 7, 2007, 12:39:30 AM (17 years ago)
Author:
rgrieder
Message:
 
Location:
code/branches/main_reto_vs05/src
Files:
2 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto_vs05/src/orxonox_prerequisites.h

    r169 r177  
    3434  class AmmunitionDump;
    3535  class Bullet;
     36  class BulletManager;
    3637  class CameraManager;
    3738  class OgreControl;
  • code/branches/main_reto_vs05/src/orxonox_ship.cc

    r169 r177  
    3333
    3434#include "bullet.h"
     35#include "bullet_manager.h"
    3536
    3637#include "orxonox_ship.h"
     
    6263  * @param mNode The scene node which the ship will be attached to later.
    6364  */
    64   OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node)
     65  OrxonoxShip::OrxonoxShip(SceneManager *sceneMgr, SceneNode *node,
     66        BulletManager *bulletManager)
    6567              : sceneMgr_(sceneMgr), rootNode_(node), currentSpeed_(Vector3(0, 0, 0)),
    6668        baseThrust_(1000), currentThrust_(Vector3::ZERO),
    67         objectCounter_(0), bulletSpeed_(400)
     69        objectCounter_(0), bulletManager_(bulletManager)//, bulletSpeed_(400)
    6870  {
    6971  }
     
    7678  OrxonoxShip::~OrxonoxShip()
    7779  {
     80    if (mainWeapon_)
     81      delete mainWeapon_;
    7882  }
    7983
     
    101105
    102106    // initialise weapon(s)
    103     SceneNode *mainWeaponNode = rootNode_->createChildSceneNode("mainWeaponNode");
    104     mainWeapon_ = new WeaponManager(sceneMgr_, mainWeaponNode, 1);
     107    SceneNode *mainWeaponNode = rootNode_
     108          ->createChildSceneNode("mainWeaponNode");
     109    mainWeapon_ = new WeaponManager(sceneMgr_, mainWeaponNode,
     110          bulletManager_, 1);
     111    mainWeapon_->addWeapon("Barrel Gun");
    105112
    106113          return true;
     
    110117  /**
    111118  * Gets the ship to accelerate in the current direction.
    112   * The value should be between 0 and 1, with one beeing full thrust and 0 none.
     119  * The value should be between 0 and 1, with one beeing full thrust and 0 none
    113120  * @param value Acceleration between 0 and 1
    114121  */
    115122  void OrxonoxShip::setMainThrust(const Real value)
    116123  {
    117           //currentThrust_ = value * baseThrust_;
    118124    currentThrust_.z = value * baseThrust_;
    119125  }
     
    122128  /**
    123129  * Gets the ship to accelerate sideways regarding the current direction.
    124   * The value should be between 0 and 1, with one beeing full thrust and 0 none.
     130  * The value should be between 0 and 1, with one beeing full thrust and 0 none
    125131  * @param value Acceleration between 0 and 1
    126132  */
    127133  void OrxonoxShip::setSideThrust(const Real value)
    128134  {
    129           //currentSideThrust_ = value * baseThrust_;
    130135    currentThrust_.x = value * baseThrust_;
    131136  }
     
    134139  /**
    135140  * Gets the ship to accelerate up and down.
    136   * The value should be between 0 and 1, with one beeing full thrust and 0 none.
     141  * The value should be between 0 and 1, with one beeing full thrust and 0 none
    137142  * @param value Acceleration between 0 and 1
    138143  */
    139144  void OrxonoxShip::setYThrust(const Real value)
    140145  {
    141     //currentYThrust_ = value * baseThrust_;
    142146    currentThrust_.y = value * baseThrust_;
    143147  }
     
    189193  * @return Bullet containing speed and entity.
    190194  */
    191   Bullet* OrxonoxShip::fire()
     195  void OrxonoxShip::fire()
    192196  {
    193197          // TODO: Names must be unique!
    194           SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode(
     198          /*SceneNode *temp = rootNode_->getParentSceneNode()->createChildSceneNode(
    195199          "BulletNode" + StringConverter::toString(objectCounter_));
    196200          temp->setOrientation(rootNode_->getOrientation());
     
    201205          + StringConverter::toString(objectCounter_++), "Barrel.mesh"), currentSpeed_
    202206          + (rootNode_->getOrientation() * Vector3(0, 0, -1)).normalisedCopy()
    203           * bulletSpeed_);
     207          * bulletSpeed_);*/
     208
     209    mainWeapon_->primaryFireRequest();
    204210  }
    205211
     
    214220  bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
    215221  {
     222    mainWeapon_->tick(time, deltaTime);
     223
    216224    Quaternion quad = rootNode_->getOrientation();
    217225    quad.normalise();
    218226    currentSpeed_ += quad * (Vector3(-1, -1, -1) * currentThrust_) * deltaTime;
    219     //currentSpeed_ += quad * Vector3(0, 0, -1) * currentThrust_ * deltaTime;
    220           //currentSpeed_ += quad * Vector3(-1, 0,  0) * currentSideThrust_ * deltaTime;
    221227
    222228          rootNode_->translate(currentSpeed_ * deltaTime);
  • code/branches/main_reto_vs05/src/orxonox_ship.h

    r169 r177  
    4040  {
    4141  public:
    42           OrxonoxShip(Ogre::SceneManager*, Ogre::SceneNode*);
     42          OrxonoxShip(Ogre::SceneManager*, Ogre::SceneNode*, BulletManager*);
    4343          virtual ~OrxonoxShip();
    4444
     
    5454    Ogre::Vector3 getSpeed();
    5555
    56           Bullet* fire();
     56          void fire();
    5757
    5858          bool tick(unsigned long, Ogre::Real);
     
    6969    Ogre::Real baseThrust_;
    7070          int objectCounter_;
    71           Ogre::Vector3 bulletSpeed_;
     71
     72    BulletManager *bulletManager_;
     73          //Ogre::Vector3 bulletSpeed_;
    7274
    7375    WeaponManager *mainWeapon_;
  • code/branches/main_reto_vs05/src/run_manager.cc

    r169 r177  
    5252#include "orxonox_ship.h"
    5353#include "bullet.h"
     54#include "bullet_manager.h"
    5455#include "camera_manager.h"
     56#include "weapon_manager.h"
    5557
    5658#include "run_manager.h"
     
    9799    // background scene (world objects, skybox, lights, etc.)
    98100    backgroundScene_ = new OrxonoxScene(sceneMgr_);
     101
     102
     103    // BULLET LIST FOR THE TEST APPLICATION
     104
     105    // create a bullet manager
     106    bulletManager_ = new BulletManager(sceneMgr_);
     107    WeaponManager::loadWeapons();
     108
     109    // TODO: Use STL to make life easier. But it works this way too..
     110    /*bullets_ = new Bullet*[10];
     111    bulletsIndex_ = 0;
     112    bulletsSize_ = 10;*/
     113
    99114
    100115    // PLAYER SPACESHIP
     
    114129    // Construct a new spaceship and give it the node
    115130    playerShip_ = new OrxonoxShip(sceneMgr_, sceneMgr_->getRootSceneNode()
    116       ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)));
     131      ->createChildSceneNode("ShipNode", Vector3(20, 20, 20)), bulletManager_);
    117132
    118133
     
    140155
    141156   
    142     // BULLET LIST FOR THE TEST APPLICATION
    143 
    144     // TODO: Use STL to make life easier. But it works this way too..
    145     bullets_ = new Bullet*[10];
    146     bulletsIndex_ = 0;
    147     bulletsSize_ = 10;
    148 
    149157
    150158    // HUMAN INTERFACE
     
    205213    if (playerShip_)
    206214      delete playerShip_;
     215    if (bulletManager_)
     216      delete bulletManager_;
     217
     218    WeaponManager::destroyWeapons();
    207219
    208220    // clean up the bullet list
    209     for (int i = 0; i < bulletsIndex_; i++)
     221    /*for (int i = 0; i < bulletsIndex_; i++)
    210222      delete bullets_[i];
    211     delete bullets_;
     223    delete bullets_;*/
    212224  }
    213225
     
    239251
    240252    // update the bullet positions
    241     for (int i = 0; i < bulletsIndex_; i++)
     253    bulletManager_->tick(time, deltaTime);
     254
     255    /*for (int i = 0; i < bulletsIndex_; i++)
    242256    {
    243257      bullets_[i]->node_->translate(bullets_[i]->speed_*deltaTime);
    244258      bullets_[i]->node_->yaw(Degree(deltaTime*100));
    245259      bullets_[i]->node_->roll(Degree(deltaTime*300));
    246     }
     260    }*/
    247261
    248262    // HUMAN INTERFACE
     
    447461      // Prevent continuous fire for the moment.
    448462      leftButtonDown_ = true;
     463
     464      playerShip_->fire();
    449465     
    450466      // let ship fire one shot with its only weapon (Barrels..)
    451       Bullet *tempBullet = playerShip_->fire();
     467      /*Bullet *tempBullet = playerShip_->fire();
    452468
    453469      // resize array if neccessary (double the size then)
     
    464480
    465481      // add the bullet to the list
    466       bullets_[bulletsIndex_++] = tempBullet;
     482      bullets_[bulletsIndex_++] = tempBullet;*/
    467483
    468484    }
  • code/branches/main_reto_vs05/src/run_manager.h

    r169 r177  
    109109
    110110    // Bullet array
    111           Bullet **bullets_;
     111          /*Bullet **bullets_;
    112112          int bulletsSize_;
    113           int bulletsIndex_;
     113          int bulletsIndex_;*/
     114    BulletManager *bulletManager_;
    114115
    115116          // previously elapsed render time
  • code/branches/main_reto_vs05/src/weapon.h

    r169 r177  
    3030#define WEAPON_H
    3131
     32#include "OgrePrerequisites.h"
    3233#include "OgreString.h"
    3334
     
    3940  {
    4041  public:
    41     Weapon(const Ogre::String &name, int firePower, int firingRate)
    42           : name_(name), firePower_(firePower), firingRate_(firingRate) { }
     42    Weapon(const Ogre::String &name, int firePower, int firingRate,
     43      Ogre::Real bulletSpeed)
     44          : name_(name), firePower_(firePower), firingRate_(firingRate),
     45          bulletSpeed_(bulletSpeed) { }
     46
    4347    virtual ~Weapon() { }
    4448
     
    4751    int firePower_;
    4852    int firingRate_;
     53    Ogre::Real bulletSpeed_;
    4954  };
    5055
  • code/branches/main_reto_vs05/src/weapon_manager.cc

    r169 r177  
    2727
    2828#include "OgreSceneManager.h"
     29#include "OgreEntity.h"
     30#include "OgreSceneNode.h"
     31#include "OgreVector3.h"
     32#include "OgreStringConverter.h"
    2933
    3034#include "weapon.h"
     35#include "bullet.h"
     36#include "bullet_manager.h"
    3137#include "weapon_manager.h"
     38
     39#define ACTION_LIST_SIZE 4
    3240
    3341
     
    3846
    3947  WeaponManager::WeaponManager(SceneManager *sceneMgr, SceneNode *node,
    40         int slotSize)
    41         : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0)
     48        BulletManager *bulletManager, int slotSize)
     49        : sceneMgr_(sceneMgr), node_(node), slotSize_(slotSize), slotIndex_(0),
     50        bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE),
     51        secondaryFireRequest_(false), selectedWeapon_(0),
     52        bulletManager_(bulletManager),
     53        actionListReadIndex_(0), actionListWriteIndex_(0)
    4254  {
    4355        slots_ = new Weapon*[slotSize];
     56    actionList_ = new Action[ACTION_LIST_SIZE];
     57    for (int i = 0; i < ACTION_LIST_SIZE; i++)
     58      actionList_[i] = NOTHING;
    4459  }
    4560
     
    4964    if (slots_)
    5065      delete slots_;
     66    if (actionList_)
     67      delete actionList_;
    5168  }
    5269
     
    5471  bool WeaponManager::addWeapon(const Ogre::String &name)
    5572  {
     73    if (!weaponList_s)
     74      return false;
     75
    5676    if (name == weaponList_s[0]->name_)
    5777    {
    5878      // this is ugly, but for the time being, it has to fit.
     79      selectedWeapon_ = slotIndex_;
    5980      slots_[slotIndex_++] = weaponList_s[0];
    6081      return true;
     
    6586
    6687
     88  bool WeaponManager::addAction(const Action act)
     89  {
     90    if (actionList_[actionListWriteIndex_] == NOTHING)
     91    {
     92      actionList_[actionListWriteIndex_] = act;
     93      actionListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE;
     94      return true;
     95    }
     96    else
     97      return false;
     98  }
     99
     100
     101  void WeaponManager::primaryFireRequest()
     102  {
     103    primaryFireRequest_ = true;
     104  }
     105
     106
     107  void WeaponManager::primaryFire()
     108  {
     109    currentState_ = PRIMARY_FIRE;
     110
     111    // TODO: add the name of the weapon manager. but for that,
     112    // the factory is required.
     113    SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode(
     114          "BulletNode" + StringConverter::toString(bulletCounter_),
     115          node_->getWorldPosition(), node_->getWorldOrientation());
     116          temp->setScale(Vector3(1, 1, 1) * 10);
     117          temp->yaw(Degree(-90));
     118    Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity"
     119          + StringConverter::toString(bulletCounter_++), "Barrel.mesh");
     120    Vector3 speed = (node_->getOrientation() * Vector3(0, 0, -1))
     121          .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_;
     122          bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed));
     123 
     124    currentState_ = IDLE;
     125  }
     126
     127
     128  void WeaponManager::secondaryFireRequest()
     129  {
     130    secondaryFireRequest_ = true;
     131  }
     132
     133  void WeaponManager::secondaryFire()
     134  {
     135  }
     136
     137
     138  bool WeaponManager::tick(unsigned long time, Real deltaTime)
     139  {
     140    // return if no weapon has been added
     141    if (!slots_[slotIndex_])
     142      return true;
     143
     144    switch (currentState_)
     145    {
     146    case IDLE:
     147      // first, process actions
     148      if (actionList_[actionListReadIndex_] != NOTHING)
     149      {
     150        actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE;
     151        break;
     152      }
     153
     154      switch (actionList_[actionListReadIndex_])
     155      {
     156      case RELOAD:
     157        break;
     158
     159      case ZOOM_IN:
     160        break;
     161
     162      case ZOOM_OUT:
     163        break;
     164
     165      default:
     166        break;
     167      }
     168
     169      // secondly, execute firing
     170      if (primaryFireRequest_)
     171        primaryFire();
     172      else if (secondaryFireRequest_)
     173        secondaryFire();
     174
     175      break;
     176
     177    case PRIMARY_FIRE:
     178      break;
     179
     180    case SECONDARY_FIRE:
     181      break;
     182
     183    case RELOADING:
     184      break;
     185    }
     186
     187    primaryFireRequest_ = false;
     188    secondaryFireRequest_ = false;
     189
     190    return true;
     191  }
     192
     193
    67194  // static
    68195  bool WeaponManager::loadWeapons()
    69196  {
    70     weaponList_s[0] = new Weapon("Barrel Gun", 10, 2);
     197    weaponList_s = new Weapon*[5];
     198    for (int i = 0; i < 5; i++)
     199      weaponList_s[i] = NULL;
     200    weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500);
    71201    return true;
    72202  }
     
    76206  void WeaponManager::destroyWeapons()
    77207  {
    78     delete weaponList_s[0];
     208    if (weaponList_s)
     209    {
     210      for (int i = 0; i < 5; i++)
     211        if (weaponList_s[i])
     212          delete weaponList_s[i];
     213      delete weaponList_s;
     214    }
    79215  }
    80216
  • code/branches/main_reto_vs05/src/weapon_manager.h

    r169 r177  
    4040  {
    4141  public:
    42     WeaponManager(Ogre::SceneManager*, Ogre::SceneNode*, int);
     42    enum Action {
     43      NOTHING  = 0,
     44      RELOAD   = 1,
     45      ZOOM_IN  = 2,
     46      ZOOM_OUT = 3
     47    };
     48
     49  protected:
     50    enum State {
     51      IDLE = 0,
     52      PRIMARY_FIRE = 1,
     53      SECONDARY_FIRE = 2,
     54      RELOADING = 4
     55    };
     56
     57  public:
     58    WeaponManager(Ogre::SceneManager*, Ogre::SceneNode*, BulletManager*, int);
    4359          virtual ~WeaponManager();
    4460
    4561    bool addWeapon(const Ogre::String&);
    4662
     63    bool addAction(const Action);
     64
     65    void primaryFireRequest();
     66
     67    void secondaryFireRequest();
     68
     69    bool tick(unsigned long, Ogre::Real);
     70
    4771    bool static loadWeapons();
    4872
    4973    void static destroyWeapons();
     74
     75  protected:
     76    void primaryFire();
     77
     78    void secondaryFire();
     79
     80  public:
    5081
    5182  protected:
     
    5687    int slotSize_;
    5788    int slotIndex_;
     89    int selectedWeapon_;
     90
     91    int bulletCounter_;
     92    BulletManager *bulletManager_;
     93
     94    bool primaryFireRequest_;
     95    bool secondaryFireRequest_;
     96
     97    State currentState_;
     98
     99    Action *actionList_;
     100    int actionListReadIndex_;
     101    int actionListWriteIndex_;
    58102
    59103    static Weapon **weaponList_s;
Note: See TracChangeset for help on using the changeset viewer.