Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 141 for code/branches


Ignore:
Timestamp:
Nov 1, 2007, 7:48:48 PM (17 years ago)
Author:
rgrieder
Message:

RunManager.cpp completely commented in Doxygen style.
One or two comments are yet inappropriate since a few changes to the code have to be made anyway. coming soon.

Location:
code/branches/main_reto
Files:
5 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • code/branches/main_reto/include/Bullet.h

    r133 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __Bullet__
    230#define __Bullet__
  • code/branches/main_reto/include/CameraManager.h

    r126 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __CameraManager__
    230#define __CameraManager__
  • code/branches/main_reto/include/OgreControl.h

    r123 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __OgreControl__
    230#define __OgreControl__
  • code/branches/main_reto/include/Orxonox.h

    r123 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __Orxonox__
    230#define __Orxonox__
  • code/branches/main_reto/include/OrxonoxScene.h

    r123 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __DemoScene__
    230#define __DemoScene__
  • code/branches/main_reto/include/OrxonoxShip.h

    r133 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __OrxonoxShip__
    230#define __OrxonoxShip__
     
    2957        Bullet* fire();
    3058
    31         bool tick(unsigned long, float);
     59        bool tick(unsigned long, Real);
     60
     61        SceneNode *mRootNode;
    3262
    3363protected:
    3464        SceneManager *mSceneMgr;
    35         SceneNode *mRootNode;
    3665        Entity *mShip;
    3766
  • code/branches/main_reto/include/RunManager.h

    r133 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __RunManager__
    230#define __RunManager__
     
    937#include "OrxonoxScene.h"
    1038#include "OrxonoxShip.h"
    11 #include "SteerableNode.h"
    1239
    1340//Use this define to signify OIS will be used as a DLL
  • code/branches/main_reto/include/WeaponManager.h

    r136 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#ifndef __WeaponManager__
    230#define __WeaponManager__
  • code/branches/main_reto/src/Bullet.cpp

    r133 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
    128#include "Bullet.h"
    229
    330
    4 Bullet::Bullet(SceneNode *mNode, Entity *mEntity, Vector3 mSpeed) : mNode(mNode), mEntity(mEntity), mSpeed(mSpeed)
     31Bullet::Bullet(SceneNode *mNode, Entity *mEntity, Vector3 mSpeed)
     32      : mNode(mNode), mEntity(mEntity), mSpeed(mSpeed)
    533{
    634        mNode->attachObject(mEntity);
  • code/branches/main_reto/src/CameraManager.cpp

    r126 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
    128#include "CameraManager.h"
    229
  • code/branches/main_reto/src/OgreControl.cpp

    r123 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
    128#include "OgreControl.h"
    229
     
    1441        assert(mainBundleURL);
    1542
    16         CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
     43        CFStringRef cfStringRef =
     44        CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
    1745        assert(cfStringRef);
    1846
     
    3058{
    3159        mRoot = 0;
    32         // Provide a nice cross platform solution for locating the configuration files
    33         // On windows files are searched for in the current working directory, on OS X however
    34         // you must provide the full path, the helper function macBundlePath does this for us.
     60        // Provide a nice cross platform solution for locating the configuration
     61        // files. On windows files are searched for in the current working
     62  // directory, on OS X however you must provide the full path, the helper
     63  // function macBundlePath does this for us.
    3564#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
    3665        mResourcePath = macBundlePath() + "/Contents/Resources/";
     
    71100
    72101
    73 /// Method which will define the source of resources (other than current folder)
     102// Method which will define the source of resources
     103// (other than current folder)
    74104void OgreControl::setupResources(void)
    75105{
     
    115145
    116146        // user clicked OK so initialise
    117         // Here we choose to let the system create a default rendering window by passing 'true'
     147        // Here we choose to let the system create a default
     148  // rendering window by passing 'true'
    118149        mWindow = mRoot->initialise(true);
    119150        mRoot->saveConfig();
  • code/branches/main_reto/src/Orxonox.cpp

    r123 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
    129#include "Orxonox.h"
    230
     
    1846                mOgre->getRoot()->renderOneFrame();
    1947
    20                 if (!mRunMgr->tick(mTimer->getMilliseconds(), (mTimer->getMilliseconds() - lastTime) / 1000.0))
     48                if (!mRunMgr->tick(mTimer->getMilliseconds(),
     49            (mTimer->getMilliseconds() - lastTime) / 1000.0))
    2150                        break;
    2251                lastTime = mTimer->getMilliseconds();
     
    2655        destroy();
    2756}
     57
    2858
    2959bool Orxonox::setup(void)
  • code/branches/main_reto/src/OrxonoxScene.cpp

    r123 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
    128#include "OrxonoxScene.h"
    229
     
    2653
    2754
    28 /// method where you can perform resource group loading
    29 /// Must at least do ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     55// method where you can perform resource group loading
     56// Must at least do
     57// ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    3058void OrxonoxScene::loadResources(void)
    3159{
     
    4472
    4573        //create a scene node to attach the head to
    46         SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("OgreHeadNode",
    47                 Vector3(0,0,0));
     74        SceneNode *node = mSceneMgr->getRootSceneNode()
     75        ->createChildSceneNode("OgreHeadNode", Vector3(0,0,0));
    4876        //attach the ogre head
    4977        node->attachObject(head);
    5078
    5179        // set up skybox
    52         mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
     80        mSceneMgr->setSkyBox(true, "Examples/SceneSkyBox2");
    5381
    5482        // set up one mLight source
     
    6492        bbs->setMaterialName("Examples/Flare");
    6593
    66         lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LightNode",
    67                 Vector3(0, 100, 0));
     94        lightNode = mSceneMgr->getRootSceneNode()
     95        ->createChildSceneNode("LightNode", Vector3(0, 100, 0));
    6896
    6997        lightNode->attachObject(bbs);
     
    82110        mLight->setSpecularColour(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2));
    83111
    84         bbs->getBillboard(0)->setColour(ColourValue(sin(1*t), sin(1*t + 2.09), sin(1*t + 2.09*2)));
     112        bbs->getBillboard(0)->setColour(ColourValue(sin(1*t),
     113        sin(1*t + 2.09), sin(1*t + 2.09*2)));
    85114}
  • code/branches/main_reto/src/OrxonoxShip.cpp

    r136 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
    128#include "OrxonoxShip.h"
    229
    330
    431OrxonoxShip::OrxonoxShip(SceneManager *mSceneMgr, SceneNode *mNode)
    5         : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)), baseThrust(1000), thrust(0), sideThrust(0), n(0),
     32            : mSceneMgr(mSceneMgr), mRootNode(mNode), speed(Vector3(0, 0, 0)),
     33      baseThrust(1000), thrust(0), sideThrust(0), n(0),
    634        bulletSpeed(400)
    735{
     
    1644bool OrxonoxShip::initialise()
    1745{
    18         // load all the resources needed (no resource groups yet, so the allInit is not executed!)
    19         //ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     46        // load all the resources needed (no resource groups yet,
     47  // so the allInit is not executed!)
     48        // ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    2049
    2150        // create the "space ship" (currently a fish..)
     
    6493{
    6594        // TODO: Names must be unique!
    66         SceneNode *temp = mRootNode->getParentSceneNode()->createChildSceneNode("BulletNode" + StringConverter::toString(n));
     95        SceneNode *temp = mRootNode->getParentSceneNode()->createChildSceneNode(
     96        "BulletNode" + StringConverter::toString(n));
    6797        temp->setOrientation(mRootNode->getOrientation());
    6898        temp->setPosition(mRootNode->getPosition());
    6999        temp->setScale(Vector3(1, 1, 1) * 10);
    70100        temp->yaw(Degree(-90));
    71         return new Bullet(temp,
    72                 mSceneMgr->createEntity("bullet" + StringConverter::toString(n++), "Barrel.mesh"),
    73                 speed + (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy() * bulletSpeed);
     101        return new Bullet(temp, mSceneMgr->createEntity("bullet"
     102        + StringConverter::toString(n++), "Barrel.mesh"), speed
     103        + (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy()
     104        * bulletSpeed);
    74105}
    75106
    76 bool OrxonoxShip::tick(unsigned long time, float deltaTime)
     107bool OrxonoxShip::tick(unsigned long time, Real deltaTime)
    77108{
    78         speed += (mRootNode->getLocalAxes() * Vector3(0, 0, -1)).normalisedCopy() * thrust * deltaTime;
    79         speed += (mRootNode->getLocalAxes() * Vector3(-1, 0,  0)).normalisedCopy() * sideThrust * deltaTime;
     109  Quaternion quad = mRootNode->getOrientation();
     110  quad.normalise();
     111  speed += quad * Vector3(0, 0, -1) * thrust * deltaTime;
     112        speed += quad * Vector3(-1, 0,  0) * sideThrust * deltaTime;
    80113
    81114        mRootNode->translate(speed * deltaTime);
  • code/branches/main_reto/src/RunManager.cpp

    r133 r141  
     1/*
     2*   ORXONOX - the hottest 3D action shooter ever to exist
     3*
     4*
     5*   License notice:
     6*
     7*   This program is free software: you can redistribute it and/or modify
     8*   it under the terms of the GNU General Public License as published by
     9*   the Free Software Foundation, either version 3 of the License, or
     10*   (at your option) any later version.
     11*
     12*   This program is distributed in the hope that it will be useful,
     13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15*   GNU General Public License for more details.
     16*
     17*   You should have received a copy of the GNU General Public License
     18*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19*
     20*
     21*   Author:
     22*      Reto Grieder
     23*   Co-authors:
     24*      ...
     25*/
     26
     27/**
     28* RunManager is the basic control object during the game.
     29*
     30* The RunManger class is designed to actually "run" the main part of the
     31* game. The Idea is, that you could derive from the RunManager in order
     32* to distinguish between a first person shooter or a space craft shooter.
     33* RunManager loads and initialises everything in the scene (like the ship,
     34* the enemies in the scene, any scripts, the physics, window events,
     35* environment, HUD, etc.).
     36* It also captures any input from keyboard, mous, joystick (optional) or
     37* Ogre (window events).
     38*/
     39
    140#include "RunManager.h"
    241
    342
    4 // Constructor takes a RenderWindow because it uses that to determine input context
    5 RunManager::RunManager(OgreControl * mOgre, bool bufferedKeys, bool bufferedMouse,
    6                                            bool bufferedJoy ) :
    7 mOgre(mOgre), mWindow(mOgre->getRenderWindow()), leftButtonDown(false),
    8 mStatsOn(true), mNumScreenShots(0),
    9 mTimeUntilNextToggle(0), mFiltering(TFO_BILINEAR),
    10 mAniso(1), mSceneDetailIndex(0), mDebugOverlay(0),
    11 mInputManager(0), mMouse(0), mKeyboard(0), mJoy(0)
    12 {
    13         // create new SceneManger
    14         mSceneMgr = mOgre->getRoot()->createSceneManager(ST_GENERIC,"mScene");
    15 
    16 
    17         // create various objects
    18         // background scene
    19         mScene = new OrxonoxScene(mSceneMgr);
    20 
    21         // create a steerable SceneNode for the spaceship to be attached to
    22         mShipNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ShipNode", Vector3(20, 20, 20));
    23 
    24         // spaceship
    25         mShip = new OrxonoxShip(mSceneMgr, mShipNode);
    26 
    27         // load all resources and create the entities
    28         mScene->initialise();
    29         mShip->initialise();
    30 
    31         // create camera and viewport
    32         createCamera();
    33         createViewports();
    34 
    35         // Set default mipmap level (NB some APIs ignore this)
    36         TextureManager::getSingleton().setDefaultNumMipmaps(5);
    37 
    38         // initialise bullets list
    39         mBullets = new Bullet*[10];
    40         mBulletsPosition = 0;
    41         mBulletsSize = 10;
    42 
    43         using namespace OIS;
    44 
    45         mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
    46 
    47         LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    48         ParamList pl;
    49         size_t windowHnd = 0;
    50         std::ostringstream windowHndStr;
    51 
    52         mWindow->getCustomAttribute("WINDOW", &windowHnd);
    53         windowHndStr << windowHnd;
    54         pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    55 
    56         mInputManager = InputManager::createInputSystem( pl );
    57 
    58         //Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse)
    59         mKeyboard = static_cast<Keyboard*>(mInputManager->createInputObject( OISKeyboard, bufferedKeys ));
    60         mMouse = static_cast<Mouse*>(mInputManager->createInputObject( OISMouse, bufferedMouse ));
    61         try {
    62                 mJoy = static_cast<JoyStick*>(mInputManager->createInputObject( OISJoyStick, bufferedJoy ));
    63         }
    64         catch(...) {
    65                 mJoy = 0;
    66         }
    67 
    68         //Set initial mouse clipping size
    69         windowResized(mWindow);
    70 
    71         showDebugOverlay(true);
    72 
    73         //Register as a Window listener
    74         WindowEventUtilities::addWindowEventListener(mWindow, this);
    75 }
    76 
    77 
     43/**
     44* Contructor only needs the render window and the Root object which are both
     45* the OgreControl object.
     46* Right now the constructor does all the initialisation work. This could also
     47* be done in a new method "initialize()", for whatever purpose.
     48*
     49*
     50* @param mOgre The OgreControl object holding the render window and the Root
     51*/
     52RunManager::RunManager(OgreControl * mOgre, bool bufferedKeys,
     53                       bool bufferedMouse, bool bufferedJoy )
     54                       : mOgre(mOgre), mWindow(mOgre->getRenderWindow()), leftButtonDown(false),
     55                       mStatsOn(true), mNumScreenShots(0), mTimeUntilNextToggle(0),
     56                       mFiltering(TFO_BILINEAR), mAniso(1), mSceneDetailIndex(0),
     57                       mDebugOverlay(0), mInputManager(0), mMouse(0), mKeyboard(0), mJoy(0)
     58{
     59
     60  // SETTING UP THE SCENE
     61
     62  // create one new SceneManger
     63  mSceneMgr = mOgre->getRoot()->createSceneManager(ST_GENERIC, "mScene");
     64
     65  // background scene (world objects, skybox, lights, etc.)
     66  mScene = new OrxonoxScene(mSceneMgr);
     67
     68  // PLAYER SPACESHIP
     69
     70  // create a steerable SceneNode (not derived!) object. The idea is that this
     71  // object only receives the mouse and the keyboard input (not specifi keys,
     72  // more like up, down, left, right, roll left, roll right, move down,
     73  // move up). The steering class can then decide how to control the node for
     74  // the spaceship. This gives a certain flexibility.
     75  // It should also be considered, that this class should provide another Node
     76  // for a camera to be attached (otherwise the spaceship in front of the
     77  // would be very static, never moving at all.
     78  mShipNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("ShipNode",
     79    Vector3(20, 20, 20));
     80
     81  // Construct a new spaceship and attach it to the node
     82  mShip = new OrxonoxShip(mSceneMgr, mShipNode);
     83
     84
     85  // RESOURCE LOADING (using ResourceGroups if implemented)
     86
     87  // load all resources and create the entities by calling the initialise()
     88  // methods for each object (don't initialise in the constructor!).
     89  mScene->initialise();
     90  mShip->initialise();
     91
     92
     93  // CAMERA AND VIEWPORT
     94  // TODO: create a camera manager. It should be able to change its position
     95  // around the space ship (predefined states would be nice too). And it should
     96  // also be able to switch between different locations (like ship, spactator,
     97  // certain fixed positions (e.g. finish line, etc.)). These are just ideas.
     98
     99  // create camera and viewport
     100  createCamera();
     101  createViewports();
     102
     103
     104  // Set default mipmap level (NB some APIs ignore this)
     105  TextureManager::getSingleton().setDefaultNumMipmaps(5);
     106
     107 
     108  // BULLET LIST FOR THE TEST APPLICATION
     109
     110  // TODO: Use STL to make life easier. But it works this way too..
     111  mBullets = new Bullet*[10];
     112  mBulletsPosition = 0;
     113  mBulletsSize = 10;
     114
     115
     116  // HUMAN INTERFACE
     117
     118  using namespace OIS;
     119
     120  mDebugOverlay = OverlayManager::getSingleton()
     121    .getByName("Core/DebugOverlay");
     122
     123  LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
     124  ParamList pl;
     125  size_t windowHnd = 0;
     126  std::ostringstream windowHndStr;
     127
     128  mWindow->getCustomAttribute("WINDOW", &windowHnd);
     129  windowHndStr << windowHnd;
     130  pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
     131
     132  mInputManager = InputManager::createInputSystem( pl );
     133
     134  // Create all devices (We only catch joystick exceptions here,
     135  // as, most people have Key/Mouse)
     136  mKeyboard = static_cast<Keyboard*>(mInputManager
     137    ->createInputObject( OISKeyboard, bufferedKeys ));
     138  mMouse = static_cast<Mouse*>(mInputManager
     139    ->createInputObject( OISMouse, bufferedMouse ));
     140  try {
     141    mJoy = static_cast<JoyStick*>(mInputManager
     142      ->createInputObject( OISJoyStick, bufferedJoy ));
     143  }
     144  catch(...) {
     145    mJoy = 0;
     146  }
     147
     148  //Set initial mouse clipping size
     149  windowResized(mWindow);
     150
     151  showDebugOverlay(true);
     152
     153  // REGISTER THIS OBJECT AS A WINDOW EVENT LISTENER IN OGRE
     154  // It will then receive events liek windowClosed, windowResized, etc.
     155  WindowEventUtilities::addWindowEventListener(mWindow, this);
     156}
     157
     158/**
     159* Standard destructor.
     160* Removes this object as a window event listener and deletes all created
     161* variables.
     162*/
    78163RunManager::~RunManager()
    79164{
    80         //Remove ourself as a Window listener
    81         WindowEventUtilities::removeWindowEventListener(mWindow, this);
    82         windowClosed(mWindow);
    83 
    84         if (mScene)
    85                 delete mScene;
    86 
    87         for (int i = 0; i < mBulletsPosition; i++)
    88                 delete mBullets[i];
    89         delete mBullets;
    90 }
    91 
    92 
    93 // Override frameStarted event to process that (don't care about frameEnded)
     165  //Remove ourself as a Window listener
     166  WindowEventUtilities::removeWindowEventListener(mWindow, this);
     167  windowClosed(mWindow);
     168
     169  if (mScene)
     170    delete mScene;
     171  if (mShip)
     172    delete mShip;
     173
     174  // clean up the bullet list
     175  for (int i = 0; i < mBulletsPosition; i++)
     176    delete mBullets[i];
     177  delete mBullets;
     178}
     179
     180
     181/**
     182* Method to compute anyting between 2 frames.
     183*
     184* Everything that needs to be computed during the games happens right here.
     185* The only exception are the listeners (which should only set variables,
     186* not actually do something).
     187*
     188* @param time Absolute play time
     189* @param deltaTime Time passed since last frame
     190* @return Return false to end rendering
     191*/
    94192bool RunManager::tick(unsigned long time, float deltaTime)
    95193{
    96         mTime = time;
    97 
    98         updateStats();
    99        
    100         mScene->tick(time, deltaTime);
    101         mShip->tick(time, deltaTime);
    102 
    103         // update the bullet positions
    104         for (int i = 0; i < mBulletsPosition; i++)
    105         {
    106                 mBullets[i]->mNode->translate(mBullets[i]->mSpeed*deltaTime);
    107                 mBullets[i]->mNode->yaw(Degree(deltaTime*100));
    108                 mBullets[i]->mNode->roll(Degree(deltaTime*300));
    109         }
    110 
    111         using namespace OIS;
    112 
    113         if(mWindow->isClosed()) return false;
    114 
    115         //Need to capture/update each device
    116         mKeyboard->capture();
    117         mMouse->capture();
    118         if( mJoy ) mJoy->capture();
    119 
    120         bool buffJ = (mJoy) ? mJoy->buffered() : true;
    121 
    122         //Check if one of the devices is not buffered
    123         if( !mMouse->buffered() || !mKeyboard->buffered() || !buffJ )
    124         {
    125                 // one of the input modes is immediate, so setup what is needed for immediate movement
    126                 if (mTimeUntilNextToggle >= 0)
    127                         mTimeUntilNextToggle -= deltaTime;
    128         }
    129 
    130         //Check to see which device is not buffered, and handle it
    131         if( !mKeyboard->buffered() )
    132                 if( processUnbufferedKeyInput() == false )
    133                         return false;
    134         if( !mMouse->buffered() )
    135                 if( processUnbufferedMouseInput() == false )
    136                         return false;
    137 
    138         return true;
    139 }
    140 
    141 
    142 //Adjust mouse clipping area
     194  // synchronize with internal class timer
     195  mTime = time;
     196
     197  // Call tick() for every object
     198  // This could be done by registering (needs a factory..)
     199  mScene->tick(time, deltaTime);
     200  mShip->tick(time, deltaTime);
     201
     202
     203  // Update the 'HUD'
     204  updateStats();
     205
     206  // update the bullet positions
     207  for (int i = 0; i < mBulletsPosition; i++)
     208  {
     209    mBullets[i]->mNode->translate(mBullets[i]->mSpeed*deltaTime);
     210    mBullets[i]->mNode->yaw(Degree(deltaTime*100));
     211    mBullets[i]->mNode->roll(Degree(deltaTime*300));
     212  }
     213
     214  // HUMAN INTERFACE
     215
     216  using namespace OIS;
     217
     218  if(mWindow->isClosed())       return false;
     219
     220  //Need to capture/update each device
     221  mKeyboard->capture();
     222  mMouse->capture();
     223  if( mJoy ) mJoy->capture();
     224
     225  bool buffJ = (mJoy) ? mJoy->buffered() : true;
     226
     227  //Check if one of the devices is not buffered
     228  if( !mMouse->buffered() || !mKeyboard->buffered() || !buffJ )
     229  {
     230    // one of the input modes is immediate, so setup what
     231    // is needed for immediate movement
     232    if (mTimeUntilNextToggle >= 0)
     233      mTimeUntilNextToggle -= deltaTime;
     234  }
     235
     236  //Check to see which device is not buffered, and handle it
     237  if( !mKeyboard->buffered() )
     238    if( processUnbufferedKeyInput() == false )
     239      return false;
     240  if( !mMouse->buffered() )
     241    if( processUnbufferedMouseInput() == false )
     242      return false;
     243
     244  // keep rendering
     245  return true;
     246}
     247
     248
     249/**
     250* Adjust mouse clipping area.
     251* This method is called by Ogre without regards of tick()!
     252* Avoid doing too much in this call.
     253* @param rw render window
     254*/
    143255void RunManager::windowResized(RenderWindow* rw)
    144256{
    145         unsigned int width, height, depth;
    146         int left, top;
    147         rw->getMetrics(width, height, depth, left, top);
    148 
    149         const OIS::MouseState &ms = mMouse->getMouseState();
    150         ms.width = width;
    151         ms.height = height;
    152 }
    153 
    154 
    155 //Unattach OIS before window shutdown (very important under Linux)
     257  unsigned int width, height, depth;
     258  int left, top;
     259  rw->getMetrics(width, height, depth, left, top);
     260
     261  const OIS::MouseState &ms = mMouse->getMouseState();
     262  ms.width = width;
     263  ms.height = height;
     264}
     265
     266
     267/**
     268* Unattach OIS before window shutdown (very important under Linux).
     269* Again, avoid computing a lot in this function.
     270* @param rw Render Window
     271*/
    156272void RunManager::windowClosed(RenderWindow* rw)
    157273{
    158         //Only close for window that created OIS (the main window in these demos)
    159         if( rw == mWindow )
    160         {
    161                 if( mInputManager )
    162                 {
    163                         mInputManager->destroyInputObject( mMouse );
    164                         mInputManager->destroyInputObject( mKeyboard );
    165                         mInputManager->destroyInputObject( mJoy );
    166 
    167                         OIS::InputManager::destroyInputSystem(mInputManager);
    168                         mInputManager = 0;
    169                 }
    170         }
    171 }
    172 
    173 
     274  //Only close for window that created OIS (the main window in these demos)
     275  if( rw == mWindow )
     276  {
     277    if( mInputManager )
     278    {
     279      mInputManager->destroyInputObject( mMouse );
     280      mInputManager->destroyInputObject( mKeyboard );
     281      mInputManager->destroyInputObject( mJoy );
     282
     283      OIS::InputManager::destroyInputSystem(mInputManager);
     284      mInputManager = 0;
     285    }
     286  }
     287}
     288
     289/**
     290* Processes the Keyboard input.
     291* TODO: Use listeners to improve performance.
     292* A lookup table should be implemented to bind any key to a specific action.
     293* @return Return true to keep rendering
     294*/
    174295bool RunManager::processUnbufferedKeyInput()
    175296{
    176         using namespace OIS;
    177 
    178         if(mKeyboard->isKeyDown(KC_A) || mKeyboard->isKeyDown(KC_LEFT))
    179                 mShip->setSideThrust(1);
    180         else if(mKeyboard->isKeyDown(KC_D) || mKeyboard->isKeyDown(KC_RIGHT))
    181                 mShip->setSideThrust(-1);
    182         else
    183                 mShip->setSideThrust(0);
    184 
    185         if(mKeyboard->isKeyDown(KC_UP) || mKeyboard->isKeyDown(KC_W) )
    186                 mShip->setThrust(1);
    187         else if(mKeyboard->isKeyDown(KC_DOWN) || mKeyboard->isKeyDown(KC_S) )
    188                 mShip->setThrust(-1);
    189         else
    190                 mShip->setThrust(0);
    191 
    192         if( mKeyboard->isKeyDown(KC_ESCAPE) || mKeyboard->isKeyDown(KC_Q) )
    193                 return false;
    194 
    195         if( mKeyboard->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0 )
    196         {
    197                 mStatsOn = !mStatsOn;
    198                 showDebugOverlay(mStatsOn);
    199                 mTimeUntilNextToggle = 1;
    200         }
    201 
    202         if( mKeyboard->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0 )
    203         {
    204                 switch(mFiltering)
    205                 {
    206                 case TFO_BILINEAR:
    207                         mFiltering = TFO_TRILINEAR;
    208                         mAniso = 1;
    209                         break;
    210                 case TFO_TRILINEAR:
    211                         mFiltering = TFO_ANISOTROPIC;
    212                         mAniso = 8;
    213                         break;
    214                 case TFO_ANISOTROPIC:
    215                         mFiltering = TFO_BILINEAR;
    216                         mAniso = 1;
    217                         break;
    218                 default: break;
    219                 }
    220                 MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
    221                 MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
    222 
    223                 showDebugOverlay(mStatsOn);
    224                 mTimeUntilNextToggle = 1;
    225         }
    226 
    227         if(mKeyboard->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
    228         {
    229                 std::ostringstream ss;
    230                 ss << "screenshot_" << ++mNumScreenShots << ".png";
    231                 mWindow->writeContentsToFile(ss.str());
    232                 mTimeUntilNextToggle = 0.5;
    233                 mDebugText = "Saved: " + ss.str();
    234         }
    235 
    236         if(mKeyboard->isKeyDown(KC_R) && mTimeUntilNextToggle <=0)
    237         {
    238                 mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
    239                 switch(mSceneDetailIndex) {
    240                                 case 0 : mCamera->setPolygonMode(PM_SOLID); break;
    241                                 case 1 : mCamera->setPolygonMode(PM_WIREFRAME); break;
    242                                 case 2 : mCamera->setPolygonMode(PM_POINTS); break;
    243                 }
    244                 mTimeUntilNextToggle = 0.5;
    245         }
    246 
    247         static bool displayCameraDetails = false;
    248         if(mKeyboard->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
    249         {
    250                 displayCameraDetails = !displayCameraDetails;
    251                 mTimeUntilNextToggle = 0.5;
    252                 if (!displayCameraDetails)
    253                         mDebugText = "";
    254         }
    255 
    256         // Print camera details
    257         if(displayCameraDetails)
    258                 mDebugText = StringConverter::toString(mShip->getThrust())
    259                 + " | Speed = " + StringConverter::toString(mShip->speed);
    260                 // mDebugText = "P: " + StringConverter::toString(mCamera->getDerivedPosition()) +
    261                 // " " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation());
    262 
    263         // Return true to continue rendering
    264         return true;
    265 }
    266 
    267 
     297  using namespace OIS;
     298
     299  if(mKeyboard->isKeyDown(KC_A) || mKeyboard->isKeyDown(KC_LEFT))
     300    mShip->setSideThrust(1);
     301  else if(mKeyboard->isKeyDown(KC_D) || mKeyboard->isKeyDown(KC_RIGHT))
     302    mShip->setSideThrust(-1);
     303  else
     304    mShip->setSideThrust(0);
     305
     306  if(mKeyboard->isKeyDown(KC_UP) || mKeyboard->isKeyDown(KC_W) )
     307    mShip->setThrust(1);
     308  else if(mKeyboard->isKeyDown(KC_DOWN) || mKeyboard->isKeyDown(KC_S) )
     309    mShip->setThrust(-1);
     310  else
     311    mShip->setThrust(0);
     312
     313  if( mKeyboard->isKeyDown(KC_ESCAPE) || mKeyboard->isKeyDown(KC_Q) )
     314    return false;
     315
     316  if( mKeyboard->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0 )
     317  {
     318    mStatsOn = !mStatsOn;
     319    showDebugOverlay(mStatsOn);
     320    mTimeUntilNextToggle = 1;
     321  }
     322
     323  if( mKeyboard->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0 )
     324  {
     325    switch(mFiltering)
     326    {
     327    case TFO_BILINEAR:
     328      mFiltering = TFO_TRILINEAR;
     329      mAniso = 1;
     330      break;
     331    case TFO_TRILINEAR:
     332      mFiltering = TFO_ANISOTROPIC;
     333      mAniso = 8;
     334      break;
     335    case TFO_ANISOTROPIC:
     336      mFiltering = TFO_BILINEAR;
     337      mAniso = 1;
     338      break;
     339    default: break;
     340    }
     341    MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
     342    MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
     343
     344    showDebugOverlay(mStatsOn);
     345    mTimeUntilNextToggle = 1;
     346  }
     347
     348  if(mKeyboard->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
     349  {
     350    std::ostringstream ss;
     351    ss << "screenshot_" << ++mNumScreenShots << ".png";
     352    mWindow->writeContentsToFile(ss.str());
     353    mTimeUntilNextToggle = 0.5;
     354    mDebugText = "Saved: " + ss.str();
     355  }
     356
     357  if(mKeyboard->isKeyDown(KC_R) && mTimeUntilNextToggle <=0)
     358  {
     359    mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
     360    switch(mSceneDetailIndex) {
     361        case 0 : mCamera->setPolygonMode(PM_SOLID); break;
     362        case 1 : mCamera->setPolygonMode(PM_WIREFRAME); break;
     363        case 2 : mCamera->setPolygonMode(PM_POINTS); break;
     364    }
     365    mTimeUntilNextToggle = 0.5;
     366  }
     367
     368  static bool displayCameraDetails = false;
     369  if(mKeyboard->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
     370  {
     371    displayCameraDetails = !displayCameraDetails;
     372    mTimeUntilNextToggle = 0.5;
     373    if (!displayCameraDetails)
     374      mDebugText = "";
     375  }
     376
     377  // Print camera details
     378  if(displayCameraDetails)
     379    mDebugText = StringConverter::toString(mShip->getThrust())
     380    + " | Speed = " + StringConverter::toString(mShip->speed);
     381  // mDebugText = "P: " + StringConverter::toString(mCamera
     382  //      ->getDerivedPosition()) + " " + "O: "
     383  //      + StringConverter::toString(mCamera->getDerivedOrientation());
     384
     385  // Return true to continue rendering
     386  return true;
     387}
     388
     389
     390/**
     391* Processes the Mouse input.
     392* TODO: Use listeners to improve performance.
     393* A lookup table should be implemented to bind ANY button or movement
     394* to a specific action.
     395* @return Return true to keep rendering
     396*/
    268397bool RunManager::processUnbufferedMouseInput()
    269398{
    270         using namespace OIS;
    271 
    272         // Rotation factors, may not be used if the second mouse button is pressed
    273         // 2nd mouse button - slide, otherwise rotate
    274         const MouseState &ms = mMouse->getMouseState();
    275 
    276         if (ms.buttonDown(MB_Left) && !leftButtonDown)
    277         {
    278                 leftButtonDown = true;
    279                 // fire
    280                 Bullet *mTempBullet = mShip->fire();
    281                 if (mBulletsPosition >= mBulletsSize)
    282                 {
    283                         // redimension the array
    284                         Bullet **mTempArray = new Bullet*[2*mBulletsSize];
    285                         for (int i = 0; i < mBulletsSize; i++)
    286                                 mTempArray[i] = mBullets[i];
    287                         mBulletsSize *= 2;
    288                         delete mBullets;
    289                         mBullets = mTempArray;
    290                 }
    291                 mBullets[mBulletsPosition++] = mTempBullet;
    292 
    293         }
    294         else if (!ms.buttons)
    295                 leftButtonDown = false;
    296 
    297         mShip->setYaw(Degree(-ms.X.rel * 0.13));
    298         mShip->setPitch(Degree(-ms.Y.rel * 0.13));
    299 
    300         return true;
    301 }
    302 
    303 
     399  using namespace OIS;
     400
     401  const MouseState &ms = mMouse->getMouseState();
     402
     403  // This is a 'hack' to show some flying barrels..
     404  // Usually, the Bullet created by the ship should be managed
     405  // by the physics engine..
     406  if (ms.buttonDown(MB_Left) && !leftButtonDown)
     407  {
     408    // Prevent continuous fire for the moment.
     409    leftButtonDown = true;
     410   
     411    // let ship fire one shot with its only weapon (Barrels..)
     412    Bullet *mTempBullet = mShip->fire();
     413
     414    // resize array if neccessary (double the size then)
     415    if (mBulletsPosition >= mBulletsSize)
     416    {
     417      // redimension the array
     418      Bullet **mTempArray = new Bullet*[2*mBulletsSize];
     419      for (int i = 0; i < mBulletsSize; i++)
     420        mTempArray[i] = mBullets[i];
     421      mBulletsSize *= 2;
     422      delete mBullets;
     423      mBullets = mTempArray;
     424    }
     425
     426    // add the bullet to the list
     427    mBullets[mBulletsPosition++] = mTempBullet;
     428
     429  }
     430  else if (!ms.buttons)
     431    leftButtonDown = false;
     432
     433  // space ship steering. This should definitely be done in the steering object
     434  // Simply give it the mouse movements.
     435  mShip->mRootNode->pitch(Degree(-ms.Y.rel * 0.13), Ogre::Node::TransformSpace::TS_LOCAL);
     436  mShip->mRootNode->yaw(Degree(-ms.X.rel * 0.13), Ogre::Node::TransformSpace::TS_PARENT);
     437
     438  // keep rendering
     439  return true;
     440}
     441
     442/**
     443* Show the debug overlay of desired.
     444* @param show Whether or not to show the debug overlay
     445*/
    304446void RunManager::showDebugOverlay(bool show)
    305447{
    306         if (mDebugOverlay)
    307         {
    308                 if (show)
    309                         mDebugOverlay->show();
    310                 else
    311                         mDebugOverlay->hide();
    312         }
    313 }
    314 
    315 
    316 
     448  if (mDebugOverlay)
     449  {
     450    if (show)
     451      mDebugOverlay->show();
     452    else
     453      mDebugOverlay->hide();
     454  }
     455}
     456
     457
     458/**
     459* Show stats (e.g. FPS) in the left lower corner of the screen.
     460* Copied from the ExampleFrameListener.h in the Ogre SDK
     461*/
    317462void RunManager::updateStats(void)
    318463{
    319         static String currFps = "Current FPS: ";
    320         static String avgFps = "Average FPS: ";
    321         static String bestFps = "Best FPS: ";
    322         static String worstFps = "Worst FPS: ";
    323         static String tris = "Triangle Count: ";
    324         static String batches = "Batch Count: ";
    325 
    326         // update stats when necessary
    327         try {
    328                 OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps");
    329                 OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps");
    330                 OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps");
    331                 OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps");
    332                 //OverlayElement* asfd = OverlayManager::getSingleton().getOverlayElement(
    333 
    334                 const RenderTarget::FrameStats& stats = mWindow->getStatistics();
    335                 guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
    336                 guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS));
    337                 guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)
    338                         +" "+StringConverter::toString(stats.bestFrameTime)+" ms");
    339                 guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)
    340                         +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
    341 
    342                 OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris");
    343                 guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
    344 
    345                 OverlayElement* guiBatches = OverlayManager::getSingleton().getOverlayElement("Core/NumBatches");
    346                 guiBatches->setCaption(batches + StringConverter::toString(stats.batchCount));
    347 
    348                 OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
    349                 guiDbg->setCaption(mDebugText);
    350         }
    351         catch(...) { /* ignore */ }
    352 }
    353 
    354 
    355 
    356 // create camera
     464  static String currFps = "Current FPS: ";
     465  static String avgFps = "Average FPS: ";
     466  static String bestFps = "Best FPS: ";
     467  static String worstFps = "Worst FPS: ";
     468  static String tris = "Triangle Count: ";
     469  static String batches = "Batch Count: ";
     470
     471  // update stats when necessary
     472  try {
     473    OverlayElement* guiAvg = OverlayManager::getSingleton()
     474      .getOverlayElement("Core/AverageFps");
     475    OverlayElement* guiCurr = OverlayManager::getSingleton()
     476      .getOverlayElement("Core/CurrFps");
     477    OverlayElement* guiBest = OverlayManager::getSingleton()
     478      .getOverlayElement("Core/BestFps");
     479    OverlayElement* guiWorst = OverlayManager::getSingleton()
     480      .getOverlayElement("Core/WorstFps");
     481
     482    const RenderTarget::FrameStats& stats = mWindow->getStatistics();
     483    guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
     484    guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS));
     485    guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)
     486      +" "+StringConverter::toString(stats.bestFrameTime)+" ms");
     487    guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)
     488      +" "+StringConverter::toString(stats.worstFrameTime)+" ms");
     489
     490    OverlayElement* guiTris = OverlayManager::getSingleton()
     491      .getOverlayElement("Core/NumTris");
     492    guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount));
     493
     494    OverlayElement* guiBatches = OverlayManager::getSingleton()
     495      .getOverlayElement("Core/NumBatches");
     496    guiBatches->setCaption(batches
     497      + StringConverter::toString(stats.batchCount));
     498
     499    OverlayElement* guiDbg = OverlayManager::getSingleton()
     500      .getOverlayElement("Core/DebugText");
     501    guiDbg->setCaption(mDebugText);
     502  }
     503  catch(...) { /* ignore */ }
     504}
     505
     506
     507
     508/**
     509* Simple camera creator.
     510* mShipNode->attachObject(mCamera) should no be here! This is what the camera
     511* manager is for. Right now, this method should do just fine, setting the
     512* cam behind the ship.
     513*/
    357514void RunManager::createCamera(void)
    358515{
    359         mCamera = mSceneMgr->createCamera("PlayerCam");
    360         mShipNode->attachObject(mCamera);
    361         mCamera->setNearClipDistance(5);
    362         mCamera->setPosition(Vector3(0,10,500));
    363         mCamera->lookAt(Vector3(0,0,0));
    364 }
    365 
    366 
     516  mCamera = mSceneMgr->createCamera("PlayerCam");
     517  mShipNode->attachObject(mCamera);
     518  mCamera->setNearClipDistance(5);
     519  mCamera->setPosition(Vector3(0,10,500));
     520  mCamera->lookAt(Vector3(0,0,0));
     521}
     522
     523/**
     524* Simple viewport creator.
     525* TODO: fully understand the concept of viewports concerning orxnox.
     526* E.g. do we need splitscreen mode?
     527* For now the viewport uses the entire render window and is based on the one
     528* camera created so far.
     529*/
    367530void RunManager::createViewports(void)
    368531{
    369         // Create one viewport, entire window
    370         Viewport* vp = mWindow->addViewport(mCamera);
    371         vp->setBackgroundColour(ColourValue(0,0,0));
    372 
    373         // Alter the camera aspect ratio to match the viewport
    374         mCamera->setAspectRatio(
    375                 Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
    376 }
    377 
    378 
     532  // Create one viewport, entire window
     533  Viewport* vp = mWindow->addViewport(mCamera);
     534  vp->setBackgroundColour(ColourValue(0,0,0));
     535
     536  // Alter the camera aspect ratio to match the viewport
     537  mCamera->setAspectRatio(
     538    Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
     539}
     540
     541
  • code/branches/main_reto/src/WeaponManager.cpp

    r136 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
    128#include "WeaponManager.h"
    229
  • code/branches/main_reto/src/main.cpp

    r123 r141  
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *
     4 *
     5 *   License notice:
     6 *
     7 *   This program is free software: you can redistribute it and/or modify
     8 *   it under the terms of the GNU General Public License as published by
     9 *   the Free Software Foundation, either version 3 of the License, or
     10 *   (at your option) any later version.
     11 *
     12 *   This program is distributed in the hope that it will be useful,
     13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *   GNU General Public License for more details.
     16 *
     17 *   You should have received a copy of the GNU General Public License
     18 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19 *
     20 *
     21 *   Author:
     22 *      Reto Grieder
     23 *   Co-authors:
     24 *      ...
     25 *
     26 */
     27
     28
     29
    130#include "Orxonox.h"
    231
     
    837#define WIN32_LEAN_AND_MEAN
    938#include "windows.h"
    10         INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
     39  INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
    1140#else
    12         int main(int argc, char **argv)
     41  int main(int argc, char **argv)
    1342#endif
    14         {
    15                 try {
    16                         Orxonox myApp;
     43  {
     44    try {
     45      // create an orxonox aplication and run it
     46      Orxonox myApp;
    1747
    18                         // ExampleApplication provides a go method, which starts the rendering.
    19                         myApp.go();
    20                 }
    21                 catch (Ogre::Exception& e) {
     48      myApp.go();
     49    }
     50    catch (Ogre::Exception& e) {
    2251#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    23                         MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
     52      MessageBoxA(NULL, e.getFullDescription().c_str(),
     53            "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
    2454#else
    25                         std::cerr << "Exception:\n";
    26                         std::cerr << e.getFullDescription().c_str() << "\n";
     55      std::cerr << "Exception:\n";
     56      std::cerr << e.getFullDescription().c_str() << "\n";
    2757#endif
    28                         return 1;
    29                 }
     58      return 1;
     59    }
    3060
    31                 return 0;
    32         }
     61    return 0;
     62  }
    3363
    3464#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.