Changeset 2662 for code/trunk/src/orxonox
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 173 edited
- 86 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/CMakeLists.txt
r2171 r2662 4 4 LevelManager.cc 5 5 Main.cc 6 PawnManager.cc 6 7 PlayerManager.cc 7 8 Settings.cc … … 48 49 tinyxml_orxonox 49 50 tolualib_orxonox 51 BulletDynamics 52 BulletCollision 53 LinearMath 50 54 util 51 55 core -
code/trunk/src/orxonox/CameraManager.cc
- Property svn:mergeinfo changed
r2261 r2662 29 29 #include "CameraManager.h" 30 30 31 #include <OgreSceneManager.h> 31 32 #include <OgreViewport.h> 33 #include <OgreCamera.h> 34 #include <OgreCompositorManager.h> 35 #include <OgreResource.h> 32 36 33 37 #include "core/Core.h" 38 #include "core/Iterator.h" 34 39 #include "objects/worldentities/Camera.h" 35 40 #include "objects/Scene.h" 41 #include "tools/Shader.h" 42 #include "util/String.h" 36 43 37 44 namespace orxonox … … 44 51 assert(singletonRef_s == 0); 45 52 singletonRef_s = this; 53 54 this->fallbackCamera_ = 0; 46 55 } 47 56 … … 50 59 assert(singletonRef_s != 0); 51 60 singletonRef_s = 0; 61 62 if (this->fallbackCamera_) 63 this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_); 52 64 } 53 65 … … 68 80 if (this->cameraList_.size() > 0) 69 81 this->cameraList_.front()->removeFocus(); 82 else if (this->fallbackCamera_) 83 { 84 this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_); 85 this->fallbackCamera_ = 0; 86 } 70 87 71 camera->setFocus(this->viewport_); 88 camera->setFocus(); 89 90 // make sure we don't add it twice 91 for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it) 92 if ((*it) == camera) 93 return; 72 94 73 95 // add to list 74 std::list<Camera*>::iterator it;75 for (it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)76 {77 if ((*it) == camera)78 return; // make sure we don't add it twice79 }80 96 this->cameraList_.push_front(camera); 81 97 } … … 92 108 this->cameraList_.pop_front(); 93 109 94 // set new focus if necessary 95 if (cameraList_.size() > 0) 96 cameraList_.front()->setFocus(this->viewport_); 110 // set new focus if possible 111 if (this->cameraList_.size() > 0) 112 this->cameraList_.front()->setFocus(); 113 else 114 { 115 // there are no more cameras, create a fallback 116 if (!this->fallbackCamera_) 117 this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); 118 this->useCamera(this->fallbackCamera_); 119 } 97 120 } 98 121 else … … 101 124 } 102 125 } 126 127 void CameraManager::useCamera(Ogre::Camera* camera) 128 { 129 // This workaround is needed to avoid weird behaviour with active compositors while 130 // switching the camera (like freezing the image) 131 // 132 // Last known Ogre version needing this workaround: 133 // 1.4.8 134 135 // deactivate all compositors 136 { 137 Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator(); 138 while (iterator.hasMoreElements()) 139 Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false); 140 } 141 142 this->viewport_->setCamera(camera); 143 144 // reactivate all visible compositors 145 { 146 for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it) 147 it->updateVisibility(); 148 } 149 } 103 150 } -
code/trunk/src/orxonox/CameraManager.h
- Property svn:mergeinfo changed
r2261 r2662 57 57 static CameraManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 58 58 59 void useCamera(Ogre::Camera* camera); 60 59 61 private: 60 62 CameraManager(const CameraManager&); … … 62 64 std::list<Camera*> cameraList_; 63 65 Ogre::Viewport* viewport_; 66 Ogre::Camera* fallbackCamera_; 64 67 65 68 static CameraManager* singletonRef_s; -
code/trunk/src/orxonox/GraphicsEngine.cc
r2087 r2662 77 77 singletonRef_s = this; 78 78 79 this->viewport_ = 0; 80 79 81 this->detailLevelParticle_ = 0; 80 82 -
code/trunk/src/orxonox/GraphicsEngine.h
r2087 r2662 72 72 static GraphicsEngine* getInstancePtr() { return singletonRef_s; } 73 73 74 inline void setViewport(Ogre::Viewport* viewport) 75 { this->viewport_ = viewport; } 76 inline Ogre::Viewport* getViewport() const 77 { return this->viewport_; } 78 74 79 private: 75 80 // don't mess with singletons 76 81 GraphicsEngine(GraphicsEngine&); 82 83 Ogre::Viewport* viewport_; //!< default full size viewport 77 84 78 85 // stats -
code/trunk/src/orxonox/Main.cc
r2103 r2662 43 43 #include "core/ConfigFileManager.h" 44 44 #include "core/CommandLine.h" 45 #include "core/CommandExecutor.h" 46 #include "core/Identifier.h" 47 #include "core/Core.h" 48 #include "core/Language.h" 45 49 46 50 #include "gamestates/GSRoot.h" … … 92 96 93 97 // create a signal handler (only works for linux) 94 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 98 SignalHandler signalHandler; 99 signalHandler.doCatch(argv[0], "orxonox.log"); 95 100 96 101 // Parse command line arguments … … 109 114 ConfigFileManager* configFileManager = new ConfigFileManager(); 110 115 configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString()); 116 // create the Core settings to configure the output level 117 Language* language = new Language(); 118 Core* core = new Core(); 111 119 112 // create the gamestates 113 GSRoot root; 114 GSGraphics graphics; 115 GSStandalone standalone; 116 GSServer server; 117 GSClient client; 118 GSDedicated dedicated; 119 GSGUI gui; 120 GSIOConsole ioConsole; 120 // put GameStates in its own scope so we can destroy the identifiers at the end of main(). 121 { 122 // create the gamestates 123 GSRoot root; 124 GSGraphics graphics; 125 GSStandalone standalone; 126 GSServer server; 127 GSClient client; 128 GSDedicated dedicated; 129 GSGUI gui; 130 GSIOConsole ioConsole; 121 131 122 // make the hierarchy123 root.addChild(&graphics);124 graphics.addChild(&standalone);125 graphics.addChild(&server);126 graphics.addChild(&client);127 graphics.addChild(&gui);128 root.addChild(&ioConsole);129 root.addChild(&dedicated);132 // make the hierarchy 133 root.addChild(&graphics); 134 graphics.addChild(&standalone); 135 graphics.addChild(&server); 136 graphics.addChild(&client); 137 graphics.addChild(&gui); 138 root.addChild(&ioConsole); 139 root.addChild(&dedicated); 130 140 131 // Here happens the game 132 root.start(); 141 // Here happens the game 142 root.start(); 143 } 133 144 134 // Destroy ConfigFileManager again. 145 // destroy singletons 146 delete core; 147 delete language; 135 148 delete configFileManager; 149 150 // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand) 151 Identifier::destroyAllIdentifiers(); 152 // destroy command line arguments 153 CommandLine::destroyAllArguments(); 154 // Also delete external console command that don't belong to an Identifier 155 CommandExecutor::destroyExternalCommands(); 136 156 137 157 return 0; -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r2261 r2662 73 73 } 74 74 75 //put here all existing munitionTypes 76 namespace MunitionType 77 { 78 79 80 81 enum Enum 82 { laserGunMunition }; 83 } 84 85 //put here all weapon fire modes. 86 //they have to be added to Pawn and HumanController, too. 87 namespace WeaponMode 88 { 89 enum Enum 90 { 91 fire = 0x1, 92 altFire = 0x2, 93 altFire2 = 0x4 94 }; 95 } 96 97 75 98 class GraphicsEngine; 76 99 class Settings; … … 82 105 class CameraManager; 83 106 class LevelManager; 107 class PawnManager; 84 108 class PlayerManager; 85 109 … … 102 126 class QuestHint; 103 127 class QuestItem; 128 class QuestListener; 104 129 class QuestManager; 105 130 class Rewardable; 106 131 107 132 class WorldEntity; 108 class PositionableEntity; 133 class StaticEntity; 134 class MobileEntity; 135 class ControllableEntity; 109 136 class MovableEntity; 110 class ControllableEntity;111 137 class Sublevel; 112 138 … … 114 140 class Billboard; 115 141 class BlinkingBillboard; 142 class ExplosionChunk; 143 class FadingBillboard; 144 class GlobalShader; 116 145 class Light; 117 146 class Backlight; … … 127 156 class SpaceShip; 128 157 158 class Item; 159 class Engine; 160 class MultiStateEngine; 161 class RotatingEngine; 162 129 163 class Trigger; 130 164 class DistanceTrigger; … … 135 169 class WeaponSet; 136 170 class WeaponSlot; 171 class WeaponPack; 137 172 class Weapon; 138 173 class Munition; 174 class LaserGun; 175 class LaserGunMunition; 139 176 140 177 class EventListener; … … 144 181 class Controller; 145 182 class HumanController; 183 class ArtificialController; 184 class AIController; 185 class ScriptController; 146 186 147 187 class Info; 148 188 class PlayerInfo; 149 189 class HumanPlayer; 190 class Bot; 191 class GametypeInfo; 150 192 151 193 class Gametype; 152 194 153 195 class Scores; 196 class CreateLines; 197 class Scoreboard; 198 class Stats; 199 200 // collision 201 class CollisionShape; 202 class SphereCollisionShape; 203 class CompoundCollisionShape; 204 class PlaneCollisionShape; 205 class WorldEntityCollisionShape; 154 206 155 207 // tools … … 158 210 class Mesh; 159 211 class ParticleInterface; 212 class Shader; 160 213 template <class T> 161 214 class Timer; … … 169 222 class HUDRadar; 170 223 class HUDSpeedBar; 224 class HUDHealthBar; 171 225 class InGameConsole; 226 class Notification; 227 class NotificationManager; 228 class NotificationQueue; 172 229 class OrxonoxOverlay; 173 230 class OverlayGroup; 174 231 class OverlayText; 232 class GametypeStatus; 233 class CreateLines; 234 class Scoreboard; 175 235 176 236 //gui … … 206 266 } 207 267 268 // Bullet Physics Engine 269 270 class btTransform; 271 class btVector3; 272 273 class btRigidBody; 274 class btCollisionObject; 275 class btGhostObject; 276 class btManifoldPoint; 277 278 class btCollisionShape; 279 class btSphereShape; 280 class btCompoundShape; 281 class btStaticPlaneShape; 282 283 class btDiscreteDynamicsWorld; 284 class bt32BitAxisSweep3; 285 class btDefaultCollisionConfiguration; 286 class btCollisionDispatcher; 287 class btSequentialImpulseConstraintSolver; 288 289 // lua 208 290 struct lua_State; 209 291 -
code/trunk/src/orxonox/OrxonoxStableHeaders.h
r2087 r2662 47 47 #include <Ogre.h> 48 48 #include <CEGUI.h> 49 #include "ois/OIS.h"50 49 #include <boost/thread/recursive_mutex.hpp> 51 50 //#include <boost/thread/mutex.hpp> … … 53 52 //#include <boost/thread/thread.hpp> 54 53 #include <boost/static_assert.hpp> 54 55 #include "BulletDynamics/Dynamics/btRigidBody.h" 56 #include "ois/OIS.h" 55 57 #include "tinyxml/ticpp.h" 56 58 #include "tinyxml/tinyxml.h" … … 95 97 #include "core/input/InputManager.h" 96 98 97 #include "network/ Synchronisable.h"99 #include "network/synchronisable/Synchronisable.h" 98 100 99 #include "Settings.h"101 //#include "Settings.h" 100 102 101 103 //#endif /* ifdef NDEBUG */ 102 104 103 #endif /* ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && !defined(ORXONOX_DISABLE_PCH) */105 #endif /* defined(ORXONOX_ENABLE_PCH) */ 104 106 105 107 #endif /* _OrxonoxStableHeaders_H__ */ -
code/trunk/src/orxonox/PlayerManager.cc
r2171 r2662 38 38 namespace orxonox 39 39 { 40 PlayerManager* PlayerManager::singletonRef_s = 0; 41 40 42 PlayerManager::PlayerManager() 41 43 { 42 44 RegisterRootObject(PlayerManager); 45 46 assert(singletonRef_s == 0); 47 singletonRef_s = this; 43 48 44 49 this->getConnectedClients(); … … 47 52 PlayerManager::~PlayerManager() 48 53 { 49 } 50 51 PlayerManager& PlayerManager::getInstance() 52 { 53 static PlayerManager instance; 54 return instance; 54 assert(singletonRef_s); 55 singletonRef_s = 0; 55 56 } 56 57 -
code/trunk/src/orxonox/PlayerManager.h
r2171 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include <cassert> 34 35 #include <map> 35 36 #include "network/ClientConnectionListener.h" … … 43 44 virtual ~PlayerManager(); 44 45 45 static PlayerManager& getInstance(); 46 static PlayerManager& getInstance() 47 { assert(singletonRef_s); return *singletonRef_s; } 46 48 47 49 PlayerInfo* getClient(unsigned int clientID) const; … … 54 56 55 57 std::map<unsigned int, PlayerInfo*> clients_; 58 59 static PlayerManager* singletonRef_s; 56 60 }; 57 61 } -
code/trunk/src/orxonox/Settings.cc
r2087 r2662 83 83 } 84 84 85 LuaBind::getInstance() ->setIncludePath(this->dataPath_);85 LuaBind::getInstance().setIncludePath(this->dataPath_); 86 86 } 87 87 -
code/trunk/src/orxonox/gamestates/GSDedicated.cc
r2171 r2662 35 35 #include "network/Server.h" 36 36 #include "objects/Tickable.h" 37 #include "util/Sleep.h" 37 38 38 39 namespace orxonox … … 41 42 : GameState<GSRoot>("dedicated") 42 43 , server_(0) 44 , timeSinceLastUpdate_(0) 43 45 { 44 46 } … … 72 74 void GSDedicated::ticked(const Clock& time) 73 75 { 74 GSLevel::ticked(time); 75 server_->tick(time.getDeltaTime()); 76 this->tickChild(time); 76 // static float startTime = time.getSecondsPrecise(); 77 // static int nrOfTicks = 0; 78 timeSinceLastUpdate_ += time.getDeltaTime(); 79 if (timeSinceLastUpdate_ >= NETWORK_PERIOD) 80 { 81 // ++nrOfTicks; 82 // COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl; 83 timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD; 84 GSLevel::ticked(time); 85 server_->tick(time.getDeltaTime()); 86 this->tickChild(time); 87 } 88 else 89 { 90 usleep((int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000)); 91 // COUT(0) << "sleeping for " << (int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl; 92 } 77 93 } 78 94 } -
code/trunk/src/orxonox/gamestates/GSDedicated.h
r2171 r2662 49 49 50 50 Server* server_; 51 float timeSinceLastUpdate_; 51 52 }; 52 53 } -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r2171 r2662 31 31 32 32 #include <fstream> 33 #include <OgreCompositorManager.h> 33 34 #include <OgreConfigFile.h> 34 35 #include <OgreFrameListener.h> … … 75 76 , graphicsEngine_(0) 76 77 , masterKeyBinder_(0) 77 , frameCount_(0)78 , statisticsRefreshCycle_(0)79 , statisticsStartTime_(0)80 , statisticsStartCount_(0)81 , tickTime_(0)82 78 , debugOverlay_(0) 83 79 { … … 106 102 SetConfigValue(ogreLogLevelCritical_, 2) 107 103 .description("Corresponding orxonox debug level for ogre Critical"); 108 SetConfigValue(statisticsRefreshCycle_, 200000)109 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");110 104 SetConfigValue(defaultMasterKeybindings_, "def_masterKeybindings.ini") 111 105 .description("Filename of default master keybindings."); … … 155 149 guiManager_->initialise(this->renderWindow_); 156 150 157 // reset frame counter158 this->frameCount_ = 0;159 this->tickTime_ = 0;160 statisticsStartTime_ = 0;161 statisticsStartCount_ = 0;162 163 151 // add console commands 164 152 FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen); 165 153 functor1->setObject(this); 166 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen")); 154 ccPrintScreen_ = createConsoleCommand(functor1, "printScreen"); 155 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 167 156 } 168 157 … … 170 159 { 171 160 using namespace Ogre; 161 162 delete this->ccPrintScreen_; 172 163 173 164 // remove our WindowEventListener first to avoid bad calls after the window has been destroyed … … 184 175 Loader::unload(this->debugOverlay_); 185 176 delete this->debugOverlay_; 177 178 // unload all compositors 179 Ogre::CompositorManager::getSingleton().removeAll(); 186 180 187 181 // destroy render window … … 206 200 delete this->ogreRoot_; 207 201 208 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32202 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 209 203 // delete the ogre log and the logManager (since we have created it). 210 204 this->ogreLogger_->getDefaultLog()->removeListener(this); 211 205 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 212 206 delete this->ogreLogger_; 213 #endif207 //#endif 214 208 215 209 delete graphicsEngine_; … … 219 213 220 214 /** 221 Main loop of the orxonox game. 222 We use the Ogre::Timer to measure time since it uses the most precise 223 method an a platform (however the windows timer lacks time when under 224 heavy kernel load!). 225 There is a simple mechanism to measure the average time spent in our 226 ticks as it may indicate performance issues. 215 @note 227 216 A note about the Ogre::FrameListener: Even though we don't use them, 228 217 they still get called. However, the delta times are not correct (except … … 233 222 void GSGraphics::ticked(const Clock& time) 234 223 { 235 unsigned long long timeBeforeTick = time.getRealMicroseconds(); 224 uint64_t timeBeforeTick = time.getRealMicroseconds(); 225 236 226 float dt = time.getDeltaTime(); 237 227 … … 248 238 } 249 239 250 unsigned long long timeAfterTick = time.getRealMicroseconds(); 251 252 tickTime_ += (unsigned int)(timeAfterTick - timeBeforeTick); 253 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 254 { 255 GraphicsEngine::getInstance().setAverageTickTime( 256 (float)tickTime_ * 0.001f / (frameCount_ - statisticsStartCount_)); 257 float avgFPS = (float)(frameCount_ - statisticsStartCount_) 258 / (timeAfterTick - statisticsStartTime_) * 1000000.0; 259 GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 260 261 tickTime_ = 0; 262 statisticsStartCount_ = frameCount_; 263 statisticsStartTime_ = timeAfterTick; 264 } 240 uint64_t timeAfterTick = time.getRealMicroseconds(); 241 242 // Also add our tick time to the list in GSRoot 243 this->getParent()->addTickTime(timeAfterTick - timeBeforeTick); 244 245 // Update statistics overlay. Note that the values only change periodically in GSRoot. 246 GraphicsEngine::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS()); 247 GraphicsEngine::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime()); 265 248 266 249 // don't forget to call _fireFrameStarted in ogre to make sure … … 283 266 // again, just to be sure ogre works fine 284 267 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 285 286 ++frameCount_;287 268 } 288 269 … … 296 277 297 278 // TODO: LogManager doesn't work on oli platform. The why is yet unknown. 298 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32279 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 299 280 // create a new logManager 300 281 ogreLogger_ = new Ogre::LogManager(); … … 311 292 myLog->setLogDetail(Ogre::LL_BOREME); 312 293 myLog->addListener(this); 313 #endif294 //#endif 314 295 315 296 // Root will detect that we've already created a Log … … 430 411 // create a full screen default viewport 431 412 this->viewport_ = this->renderWindow_->addViewport(0, 0); 413 414 if (this->graphicsEngine_) 415 this->graphicsEngine_->setViewport(this->viewport_); 432 416 } 433 417 -
code/trunk/src/orxonox/gamestates/GSGraphics.h
r2103 r2662 93 93 94 94 KeyBinder* masterKeyBinder_; 95 96 // variables for time statistics97 unsigned long frameCount_;98 unsigned int statisticsRefreshCycle_;99 unsigned long long statisticsStartTime_;100 unsigned long statisticsStartCount_;101 unsigned int tickTime_;102 95 XMLFile* debugOverlay_; 103 96 … … 110 103 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 111 104 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 112 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)113 105 std::string defaultMasterKeybindings_; //!< Filename of default master keybindings. 106 107 // console commands 108 ConsoleCommand* ccPrintScreen_; 114 109 }; 115 110 } -
code/trunk/src/orxonox/gamestates/GSLevel.cc
r2103 r2662 41 41 #include "core/CoreIncludes.h" 42 42 #include "core/Core.h" 43 //#include "objects/Backlight.h"44 43 #include "objects/Tickable.h" 45 44 #include "objects/Radar.h" 46 //#include "tools/ParticleInterface.h"47 45 #include "CameraManager.h" 48 46 #include "LevelManager.h" 47 #include "PlayerManager.h" 49 48 #include "Settings.h" 50 49 51 50 namespace orxonox 52 51 { 53 SetCommandLineArgument(level, " sample2.oxw").shortcut("l");52 SetCommandLineArgument(level, "presentation.oxw").shortcut("l"); 54 53 55 54 GSLevel::GSLevel() 56 55 // : GameState<GSGraphics>(name) 57 : timeFactor_(1.0f) 58 , keyBinder_(0) 56 : keyBinder_(0) 59 57 , inputState_(0) 60 58 , radar_(0) … … 64 62 { 65 63 RegisterObject(GSLevel); 64 65 this->ccKeybind_ = 0; 66 this->ccTkeybind_ = 0; 67 66 68 setConfigValues(); 67 69 } … … 95 97 } 96 98 99 this->playerManager_ = new PlayerManager(); 100 97 101 if (Core::isMaster()) 98 102 { 99 103 // create the global LevelManager 100 104 this->levelManager_ = new LevelManager(); 101 102 // reset game speed to normal103 timeFactor_ = 1.0f;104 105 105 106 this->loadLevel(); … … 114 115 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 115 116 functor1->setObject(this); 116 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 117 ccKeybind_ = createConsoleCommand(functor1, "keybind"); 118 CommandExecutor::addConsoleCommandShortcut(ccKeybind_); 117 119 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 118 120 functor2->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 121 ccTkeybind_ = createConsoleCommand(functor2, "tkeybind"); 122 CommandExecutor::addConsoleCommandShortcut(ccTkeybind_); 120 123 // set our console command as callback for the key detector 121 124 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); … … 124 127 InputManager::getInstance().requestEnterState("game"); 125 128 } 126 127 if (Core::isMaster())128 {129 // time factor console command130 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);131 functor->setObject(this);132 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;133 }134 129 } 135 130 136 131 void GSLevel::leave() 137 132 { 133 // destroy console commands 134 if (this->ccKeybind_) 135 { 136 delete this->ccKeybind_; 137 this->ccKeybind_ = 0; 138 } 139 if (this->ccTkeybind_) 140 { 141 delete this->ccTkeybind_; 142 this->ccTkeybind_ = 0; 143 } 144 138 145 // this call will delete every BaseObject! 139 146 // But currently this will call methods of objects that exist no more … … 149 156 150 157 if (this->radar_) 158 { 151 159 delete this->radar_; 160 this->radar_ = 0; 161 } 152 162 153 163 if (this->cameraManager_) 164 { 154 165 delete this->cameraManager_; 166 this->cameraManager_ = 0; 167 } 155 168 156 169 if (this->levelManager_) 170 { 157 171 delete this->levelManager_; 172 this->levelManager_ = 0; 173 } 174 175 if (this->playerManager_) 176 { 177 delete this->playerManager_; 178 this->playerManager_ = 0; 179 } 158 180 159 181 if (Core::showsGraphics()) … … 162 184 InputManager::getInstance().requestDestroyState("game"); 163 185 if (this->keyBinder_) 186 { 164 187 delete this->keyBinder_; 188 this->keyBinder_ = 0; 189 } 165 190 } 166 191 } … … 172 197 //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 173 198 // it->tick(time.getDeltaTime() * this->timeFactor_); 174 }175 176 /**177 @brief178 Changes the speed of Orxonox179 */180 void GSLevel::setTimeFactor(float factor)181 {182 /*183 float change = factor / this->timeFactor_;184 */185 this->timeFactor_ = factor;186 /*187 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)188 it->setSpeedFactor(it->getSpeedFactor() * change);189 190 for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it)191 it->setTimeFactor(timeFactor_);192 */193 199 } 194 200 -
code/trunk/src/orxonox/gamestates/GSLevel.h
r2103 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 #include <OgrePrerequisites.h> 34 #include "core/GameState.h" 35 #include "GSGraphics.h" 34 #include "core/OrxonoxClass.h" 36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport GSLevel : public OrxonoxClass //,public GameState<GSGraphics>38 class _OrxonoxExport GSLevel : public OrxonoxClass 40 39 { 41 40 friend class ClassIdentifier<GSLevel>; … … 43 42 GSLevel(); 44 43 ~GSLevel(); 45 46 // this has to be public because proteced triggers a bug in msvc47 // when taking the function address.48 void setTimeFactor(float factor);49 float getTimeFactor() { return this->timeFactor_; }50 44 51 45 protected: … … 56 50 void loadLevel(); 57 51 void unloadLevel(); 58 59 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal.60 52 61 53 // console commands … … 70 62 CameraManager* cameraManager_; 71 63 LevelManager* levelManager_; 64 PlayerManager* playerManager_; 72 65 73 66 //##### ConfigValues ##### … … 75 68 //! Filename of default keybindings. 76 69 std::string defaultKeybindings_; 70 71 // console commands 72 ConsoleCommand* ccKeybind_; 73 ConsoleCommand* ccTkeybind_; 77 74 78 75 private: -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r2171 r2662 32 32 #include "util/Exception.h" 33 33 #include "util/Debug.h" 34 #include "core/Core.h" 34 35 #include "core/Factory.h" 35 36 #include "core/ConfigValueIncludes.h" … … 40 41 #include "core/TclBind.h" 41 42 #include "core/TclThreadManager.h" 43 #include "core/LuaBind.h" 42 44 #include "tools/Timer.h" 43 45 #include "objects/Tickable.h" 44 46 #include "Settings.h" 45 47 46 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 48 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 47 49 # ifndef WIN32_LEAN_AND_MEAN 48 50 # define WIN32_LEAN_AND_MEAN … … 66 68 GSRoot::GSRoot() 67 69 : RootGameState("root") 70 , timeFactor_(1.0f) 71 , bPaused_(false) 72 , timeFactorPauseBackup_(1.0f) 68 73 , settings_(0) 69 74 , tclBind_(0) … … 73 78 RegisterRootObject(GSRoot); 74 79 setConfigValues(); 80 81 this->ccSetTimeFactor_ = 0; 82 this->ccPause_ = 0; 75 83 } 76 84 … … 81 89 void GSRoot::setConfigValues() 82 90 { 91 SetConfigValue(statisticsRefreshCycle_, 250000) 92 .description("Sets the time in microseconds interval at which average fps, etc. get updated."); 93 SetConfigValue(statisticsAvgLength_, 1000000) 94 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 83 95 } 84 96 … … 87 99 // creates the class hierarchy for all classes with factories 88 100 Factory::createClassHierarchy(); 101 102 // reset game speed to normal 103 timeFactor_ = 1.0f; 104 105 // reset frame counter 106 this->statisticsStartTime_ = 0; 107 this->statisticsTickTimes_.clear(); 108 this->periodTickTime_ = 0; 109 this->avgFPS_ = 0.0f; 110 this->avgTickTime_ = 0.0f; 111 112 // Create the lua interface 113 this->luaBind_ = new LuaBind(); 89 114 90 115 // instantiate Settings class … … 114 139 setThreadAffinity((unsigned int)(limitToCPU - 1)); 115 140 116 // add console commands 117 FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame); 118 functor1->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit")); 120 121 // add console commands 122 FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState); 123 functor2->setObject(this); 124 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState")); 141 { 142 // add console commands 143 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame); 144 functor->setObject(this); 145 this->ccExit_ = createConsoleCommand(functor, "exit"); 146 CommandExecutor::addConsoleCommandShortcut(this->ccExit_); 147 } 148 149 { 150 // add console commands 151 FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState); 152 functor->setObject(this); 153 this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState"); 154 CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_); 155 } 156 157 { 158 // time factor console command 159 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor); 160 functor->setObject(this); 161 this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor"); 162 CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0); 163 } 164 165 { 166 // time factor console command 167 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause); 168 functor->setObject(this); 169 this->ccPause_ = createConsoleCommand(functor, "pause"); 170 CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline); 171 } 125 172 } 126 173 127 174 void GSRoot::leave() 128 175 { 129 // TODO: remove and destroy console commands 176 // destroy console commands 177 delete this->ccExit_; 178 delete this->ccSelectGameState_; 130 179 131 180 delete this->shell_; … … 133 182 delete this->tclBind_; 134 183 135 delete settings_; 136 184 delete this->settings_; 185 delete this->luaBind_; 186 187 if (this->ccSetTimeFactor_) 188 { 189 delete this->ccSetTimeFactor_; 190 this->ccSetTimeFactor_ = 0; 191 } 192 193 if (this->ccPause_) 194 { 195 delete this->ccPause_; 196 this->ccPause_ = 0; 197 } 137 198 } 138 199 139 200 void GSRoot::ticked(const Clock& time) 140 201 { 202 uint64_t timeBeforeTick = time.getRealMicroseconds(); 203 141 204 TclThreadManager::getInstance().tick(time.getDeltaTime()); 142 205 … … 146 209 /*** HACK *** HACK ***/ 147 210 // Call the Tickable objects 211 float leveldt = time.getDeltaTime(); 212 if (leveldt > 1.0f) 213 { 214 // just loaded 215 leveldt = 0.0f; 216 } 148 217 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 149 it->tick( time.getDeltaTime());218 it->tick(leveldt * this->timeFactor_); 150 219 /*** HACK *** HACK ***/ 151 220 221 uint64_t timeAfterTick = time.getRealMicroseconds(); 222 223 // STATISTICS 224 assert(timeAfterTick - timeBeforeTick >= 0 ); 225 statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick}; 226 statisticsTickTimes_.push_back(tickInfo); 227 assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength); 228 this->periodTickTime_ += tickInfo.tickLength; 229 230 // Ticks GSGraphics or GSDedicated 152 231 this->tickChild(time); 232 233 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 234 { 235 std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 236 assert(it != this->statisticsTickTimes_.end()); 237 int64_t lastTime = timeAfterTick - statisticsAvgLength_; 238 if ((int64_t)it->tickTime < lastTime) 239 { 240 do 241 { 242 assert(this->periodTickTime_ > it->tickLength); 243 this->periodTickTime_ -= it->tickLength; 244 ++it; 245 assert(it != this->statisticsTickTimes_.end()); 246 } while ((int64_t)it->tickTime < lastTime); 247 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it); 248 } 249 250 uint32_t framesPerPeriod = this->statisticsTickTimes_.size(); 251 this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0; 252 this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0; 253 254 statisticsStartTime_ = timeAfterTick; 255 } 256 153 257 } 154 258 … … 160 264 161 265 Copyright (c) 2000-2008 Torus Knot Software Ltd 162 266 163 267 OGRE is licensed under the LGPL. For more info, see OGRE license. 164 268 */ … … 167 271 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 168 272 // Get the current process core mask 169 170 273 DWORD procMask; 274 DWORD sysMask; 171 275 # if _MSC_VER >= 1400 && defined (_M_X64) 172 276 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 173 277 # else 174 278 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 175 279 # endif 176 280 177 178 179 180 281 // If procMask is 0, consider there is only one core available 282 // (using 0 as procMask will cause an infinite loop below) 283 if (procMask == 0) 284 procMask = 1; 181 285 182 286 // if the core specified with limitToCPU is not available, take the lowest one … … 184 288 limitToCPU = 0; 185 289 186 290 // Find the lowest core that this process uses and limitToCPU suggests 187 291 DWORD threadMask = 1; 188 189 190 191 192 292 while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU))) 293 threadMask <<= 1; 294 295 // Set affinity to the first core 296 SetThreadAffinityMask(GetCurrentThread(), threadMask); 193 297 #endif 194 298 } 299 300 /** 301 @brief 302 Changes the speed of Orxonox 303 */ 304 void GSRoot::setTimeFactor(float factor) 305 { 306 if (Core::isMaster()) 307 { 308 if (!this->bPaused_) 309 { 310 TimeFactorListener::timefactor_s = factor; 311 312 for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it) 313 it->changedTimeFactor(factor, this->timeFactor_); 314 315 this->timeFactor_ = factor; 316 } 317 else 318 this->timeFactorPauseBackup_ = factor; 319 } 320 } 321 322 void GSRoot::pause() 323 { 324 if (Core::isMaster()) 325 { 326 if (!this->bPaused_) 327 { 328 this->timeFactorPauseBackup_ = this->timeFactor_; 329 this->setTimeFactor(0.0f); 330 this->bPaused_ = true; 331 } 332 else 333 { 334 this->bPaused_ = false; 335 this->setTimeFactor(this->timeFactorPauseBackup_); 336 } 337 } 338 } 339 340 //////////////////////// 341 // TimeFactorListener // 342 //////////////////////// 343 float TimeFactorListener::timefactor_s = 1.0f; 344 345 TimeFactorListener::TimeFactorListener() 346 { 347 RegisterRootObject(TimeFactorListener); 348 } 195 349 } -
code/trunk/src/orxonox/gamestates/GSRoot.h
r1891 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include <list> 33 35 #include <OgreLog.h> 34 36 #include "core/RootGameState.h" … … 40 42 { 41 43 friend class ClassIdentifier<GSRoot>; 44 45 public: 46 struct statisticsTickInfo 47 { 48 uint64_t tickTime; 49 uint32_t tickLength; 50 }; 51 42 52 public: 43 53 GSRoot(); … … 46 56 void exitGame() 47 57 { requestState("root"); } 58 59 // this has to be public because proteced triggers a bug in msvc 60 // when taking the function address. 61 void setTimeFactor(float factor); 62 void pause(); 63 float getTimeFactor() { return this->timeFactor_; } 64 65 float getAvgTickTime() { return this->avgTickTime_; } 66 float getAvgFPS() { return this->avgFPS_; } 67 68 inline void addTickTime(uint32_t length) 69 { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length; 70 this->periodTickTime_+=length; } 48 71 49 72 private: … … 55 78 void setThreadAffinity(unsigned int limitToCPU); 56 79 80 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 81 bool bPaused_; 82 float timeFactorPauseBackup_; 57 83 Settings* settings_; 58 84 TclBind* tclBind_; 59 85 TclThreadManager* tclThreadManager_; 60 86 Shell* shell_; 87 LuaBind* luaBind_; 88 89 // variables for time statistics 90 uint64_t statisticsStartTime_; 91 std::list<statisticsTickInfo> 92 statisticsTickTimes_; 93 uint32_t periodTickTime_; 94 float avgFPS_; 95 float avgTickTime_; 96 97 // config values 98 unsigned int statisticsRefreshCycle_; 99 unsigned int statisticsAvgLength_; 100 101 // console commands 102 ConsoleCommand* ccExit_; 103 ConsoleCommand* ccSelectGameState_; 104 ConsoleCommand* ccSetTimeFactor_; 105 ConsoleCommand* ccPause_; 106 }; 107 108 class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass 109 { 110 friend class GSRoot; 111 112 public: 113 TimeFactorListener(); 114 virtual ~TimeFactorListener() {} 115 116 protected: 117 virtual void changedTimeFactor(float factor_new, float factor_old) {} 118 inline float getTimeFactor() const 119 { return TimeFactorListener::timefactor_s; } 120 121 private: 122 static float timefactor_s; 61 123 }; 62 124 } -
code/trunk/src/orxonox/gui/GUIManager.cc
r2087 r2662 96 96 { 97 97 // destroy our own tolua interfaces 98 //lua_pushnil(luaState_);99 //lua_setglobal(luaState_, "Orxonox");100 //lua_pushnil(luaState_);101 //lua_setglobal(luaState_, "Core");98 lua_pushnil(luaState_); 99 lua_setglobal(luaState_, "Orxonox"); 100 lua_pushnil(luaState_); 101 lua_setglobal(luaState_, "Core"); 102 102 // TODO: deleting the script module fails an assertation. 103 103 // However there is not much we can do about it since it occurs too when 104 104 // we don't open Core or Orxonox. Might be a CEGUI issue. 105 105 // The memory leak is not a problem anyway.. 106 //delete scriptModule_;106 delete scriptModule_; 107 107 } 108 108 -
code/trunk/src/orxonox/objects/CMakeLists.txt
r2171 r2662 3 3 EventDispatcher.cc 4 4 EventTarget.cc 5 GlobalShader.cc 5 6 Level.cc 6 7 Radar.cc … … 13 14 ) 14 15 16 ADD_SOURCE_DIRECTORY(SRC_FILES collisionshapes) 15 17 ADD_SOURCE_DIRECTORY(SRC_FILES controllers) 16 18 ADD_SOURCE_DIRECTORY(SRC_FILES gametypes) 17 19 ADD_SOURCE_DIRECTORY(SRC_FILES infos) 18 #ADD_SOURCE_DIRECTORY(SRC_FILES pickup) 20 ADD_SOURCE_DIRECTORY(SRC_FILES items) 21 ADD_SOURCE_DIRECTORY(SRC_FILES pickup) 19 22 ADD_SOURCE_DIRECTORY(SRC_FILES quest) 20 23 ADD_SOURCE_DIRECTORY(SRC_FILES weaponSystem) -
code/trunk/src/orxonox/objects/EventTarget.cc
r2087 r2662 48 48 void EventTarget::changedName() 49 49 { 50 SUPER(EventTarget, changedName); 51 50 52 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 51 53 if (it->getName() == this->getName()) -
code/trunk/src/orxonox/objects/Level.cc
- Property svn:mergeinfo changed
r2261 r2662 83 83 void Level::registerVariables() 84 84 { 85 REGISTERSTRING(this->xmlfilename_, direction::toclient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile));86 REGISTERSTRING(this->name_, direction::toclient, new NetworkCallback<Level>(this, &Level::changedName));87 REGISTERSTRING(this->description_, direction::toclient);85 registerVariable(this->xmlfilename_, variableDirection::toclient, new NetworkCallback<Level>(this, &Level::networkcallback_applyXMLFile)); 86 registerVariable(this->name_, variableDirection::toclient, new NetworkCallback<Level>(this, &Level::changedName)); 87 registerVariable(this->description_, variableDirection::toclient); 88 88 } 89 89 … … 141 141 void Level::playerEntered(PlayerInfo* player) 142 142 { 143 COUT(3) << "player entered level " << std::endl;143 COUT(3) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl; 144 144 player->setGametype(this->getGametype()); 145 145 } … … 147 147 void Level::playerLeft(PlayerInfo* player) 148 148 { 149 COUT(3) << "player left level " << std::endl;149 COUT(3) << "player left level (id: " << player->getClientID() << ", name: " << player->getName() << ")" << std::endl; 150 150 player->setGametype(0); 151 151 } -
code/trunk/src/orxonox/objects/Level.h
- Property svn:mergeinfo changed
r2261 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "network/ Synchronisable.h"34 #include "network/synchronisable/Synchronisable.h" 35 35 #include "core/BaseObject.h" 36 36 -
code/trunk/src/orxonox/objects/Radar.cc
r2087 r2662 99 99 void Radar::tick(float dt) 100 100 { 101 SUPER(Radar, tick, dt); 102 101 103 if (this->focus_ != *(this->itFocus_)) 102 104 { … … 112 114 for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement) 113 115 { 114 /* 115 if ((*itElement) != SpaceShip::getLocalShip() && (*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage()) 116 if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage()) 116 117 (*itListener)->displayObject(*itElement, *itElement == this->focus_); 117 */118 118 } 119 119 } … … 128 128 this->focus_ = 0; 129 129 } 130 else 131 { 132 Vector3 localPosition;// = SpaceShip::getLocalShip()->getPosition(); 130 /* 131 else if (this->owner_) 132 { 133 Vector3 localPosition = this->owner_->getPosition(); 133 134 Vector3 targetPosition = localPosition; 134 135 if (*(this->itFocus_)) 135 targetPosition = this->itFocus_->get WorldPosition();136 targetPosition = this->itFocus_->getRVWorldPosition(); 136 137 137 138 // find the closed object further away than targetPosition … … 143 144 for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it) 144 145 { 145 /* 146 if (*it == SpaceShip::getLocalShip()) 146 if (*it == (RadarViewable*)this->owner_) 147 147 continue; 148 */ 149 float targetDistance = localPosition.squaredDistance((*it)->get WorldPosition());148 149 float targetDistance = localPosition.squaredDistance((*it)->getRVWorldPosition()); 150 150 if (targetDistance > currentDistance && targetDistance < nextDistance) 151 151 { … … 171 171 } 172 172 } 173 */ 173 174 } 174 175 … … 186 187 for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it, ++i) 187 188 { 188 COUT(3) << i++ << ": " << (*it)->get WorldPosition() << std::endl;189 COUT(3) << i++ << ": " << (*it)->getRVWorldPosition() << std::endl; 189 190 } 190 191 } -
code/trunk/src/orxonox/objects/RadarViewable.cc
r2087 r2662 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "RadarViewable.h" 31 31 32 #include "util/Debug.h" 33 #include "util/Exception.h" 32 34 #include "core/CoreIncludes.h" 33 //#include "objects/WorldEntity.h"34 #include " Radar.h"35 #include "objects/worldentities/WorldEntity.h" 36 #include "objects/Radar.h" 35 37 36 38 namespace orxonox … … 40 42 */ 41 43 RadarViewable::RadarViewable() 42 : radarObject_(0) 43 , radarObjectCamouflage_(0.0f) 44 , radarObjectType_(Dot) 44 : radarObjectCamouflage_(0.0f) 45 , radarObjectShape_(Dot) 45 46 , radarObjectDescription_("staticObject") 46 47 { … … 52 53 Radar* radar = Radar::getInstancePtr(); 53 54 if (radar) 54 this->radarObject Type_ = radar->addObjectDescription(str);55 this->radarObjectShape_ = radar->addObjectDescription(str); 55 56 else 56 57 { … … 60 61 } 61 62 62 const Vector3& RadarViewable::get WorldPosition() const63 const Vector3& RadarViewable::getRVWorldPosition() const 63 64 { 64 validate(); 65 return Vector3::ZERO;//this->radarObject_->getWorldPosition(); 65 const WorldEntity* object = this->getWorldEntity(); 66 validate(object); 67 return object->getWorldPosition(); 66 68 } 67 69 68 Vector3 RadarViewable::get OrientedVelocity() const70 Vector3 RadarViewable::getRVOrientedVelocity() const 69 71 { 70 validate(); 71 return Vector3::ZERO;//this->radarObject_->getOrientation() * this->radarObject_->getVelocity(); 72 const WorldEntity* object = this->getWorldEntity(); 73 validate(object); 74 return object->getWorldOrientation() * object->getVelocity(); 72 75 } 73 76 } -
code/trunk/src/orxonox/objects/RadarViewable.h
r2087 r2662 44 44 class _OrxonoxExport RadarViewable : virtual public OrxonoxClass 45 45 { 46 class WorldEntity;47 48 46 public: 49 47 enum Shape … … 58 56 virtual ~RadarViewable() { } 59 57 60 float getRadarObjectCamouflage() const { return this->radarObjectCamouflage_; } 61 void setRadarObjectCamouflage(float camouflage) { this->radarObjectCamouflage_ = camouflage; } 58 inline void setRadarObjectCamouflage(float camouflage) 59 { this->radarObjectCamouflage_ = camouflage; } 60 inline float getRadarObjectCamouflage() const 61 { return this->radarObjectCamouflage_; } 62 62 63 const ColourValue& getRadarObjectColour() const { return this->radarObjectColour_; } 64 void setRadarObjectColour(const ColourValue& colour) { this->radarObjectColour_ = colour; } 63 inline void setRadarObjectColour(const ColourValue& colour) 64 { this->radarObjectColour_ = colour; } 65 inline const ColourValue& getRadarObjectColour() const 66 { return this->radarObjectColour_; } 65 67 66 const std::string& getRadarObjectDescription() const { return this->radarObjectDescription_; }67 68 void setRadarObjectDescription(const std::string& str); 69 inline const std::string& getRadarObjectDescription() const 70 { return this->radarObjectDescription_; } 68 71 69 const WorldEntity* getWorldEntity() const { return this->radarObject_; } 70 const Vector3& getWorldPosition() const; 71 Vector3 getOrientedVelocity() const; 72 virtual const WorldEntity* getWorldEntity() const = 0; 72 73 73 Shape getRadarObjectType() const { return this->radarObjectType_; } 74 const Vector3& getRVWorldPosition() const; 75 Vector3 getRVOrientedVelocity() const; 74 76 75 protected: 76 WorldEntity* radarObject_; 77 inline void setRadarObjectShape(Shape shape) 78 { this->radarObjectShape_ = shape; } 79 inline Shape getRadarObjectShape() const 80 { return this->radarObjectShape_; } 77 81 78 82 private: 79 void validate() const { if (!this->radarObject_) 80 { COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl; assert(0); } } 83 void validate(const WorldEntity* object) const 84 { 85 if (!object) 86 { 87 COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl; 88 assert(0); 89 } 90 } 81 91 82 92 float radarObjectCamouflage_; 83 Shape radarObject Type_;93 Shape radarObjectShape_; 84 94 std::string radarObjectDescription_; 85 95 ColourValue radarObjectColour_; -
code/trunk/src/orxonox/objects/Scene.cc
r2171 r2662 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder (physics) 24 25 * Co-authors: 25 26 * ... … … 33 34 #include <OgreSceneManagerEnumerator.h> 34 35 #include <OgreSceneNode.h> 35 #include <OgreLight.h> 36 37 #include "BulletCollision/BroadphaseCollision/btAxisSweep3.h" 38 #include "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h" 39 #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h" 40 #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" 36 41 37 42 #include "core/CoreIncludes.h" 38 43 #include "core/Core.h" 39 44 #include "core/XMLPort.h" 45 #include "tools/BulletConversions.h" 46 #include "objects/worldentities/WorldEntity.h" 40 47 41 48 namespace orxonox … … 48 55 49 56 this->setScene(this); 50 this->bShadows_ = false;57 this->bShadows_ = true; 51 58 52 59 if (Core::showsGraphics()) … … 70 77 } 71 78 72 // test test test 73 if (Core::showsGraphics() && this->sceneManager_) 74 { 75 Ogre::Light* light; 76 light = this->sceneManager_->createLight("Light-1"); 77 light->setType(Ogre::Light::LT_DIRECTIONAL); 78 light->setDiffuseColour(ColourValue(1.0, 0.9, 0.6, 1.0)); 79 light->setSpecularColour(ColourValue(1.0, 0.9, 0.6, 1.0)); 80 light->setDirection(1, -0.3, 0.3); 81 } 82 // test test test 79 // No physics yet, XMLPort will do that. 80 const int defaultMaxWorldSize = 100000; 81 this->negativeWorldRange_ = Vector3::UNIT_SCALE * -defaultMaxWorldSize; 82 this->positiveWorldRange_ = Vector3::UNIT_SCALE * defaultMaxWorldSize; 83 this->gravity_ = Vector3::ZERO; 84 this->physicalWorld_ = 0; 85 this->solver_ = 0; 86 this->dispatcher_ = 0; 87 this->collisionConfig_ = 0; 88 this->broadphase_ = 0; 83 89 84 90 this->registerVariables(); … … 91 97 if (Ogre::Root::getSingletonPtr()) 92 98 { 93 // this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre94 99 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 95 100 } … … 98 103 delete this->sceneManager_; 99 104 } 105 106 this->setPhysicalWorld(false); 100 107 } 101 108 } … … 109 116 XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true); 110 117 118 XMLPortParam(Scene, "gravity", setGravity, getGravity, xmlelement, mode); 119 XMLPortParam(Scene, "negativeWorldRange", setNegativeWorldRange, getNegativeWorldRange, xmlelement, mode); 120 XMLPortParam(Scene, "positiveWorldRange", setPositiveWorldRange, getPositiveWorldRange, xmlelement, mode); 121 XMLPortParam(Scene, "hasPhysics", setPhysicalWorld, hasPhysics, xmlelement, mode).defaultValues(true); 122 111 123 XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); 112 124 } … … 114 126 void Scene::registerVariables() 115 127 { 116 REGISTERSTRING(this->skybox_, direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox)); 117 REGISTERDATA(this->ambientLight_, direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight)); 128 registerVariable(this->skybox_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox)); 129 registerVariable(this->ambientLight_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight)); 130 registerVariable(this->negativeWorldRange_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_negativeWorldRange)); 131 registerVariable(this->positiveWorldRange_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_positiveWorldRange)); 132 registerVariable(this->gravity_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_gravity)); 133 registerVariable(this->bHasPhysics_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_hasPhysics)); 134 registerVariable(this->bShadows_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyShadows)); 135 } 136 137 void Scene::setNegativeWorldRange(const Vector3& range) 138 { 139 if (range.length() < 10.0f) 140 { 141 CCOUT(2) << "Warning: Setting the negative world range to a very small value: " 142 << omni_cast<std::string>(range) << std::endl; 143 } 144 if (this->hasPhysics()) 145 { 146 CCOUT(2) << "Warning: Attempting to set the physical world range at run time. " 147 << "This causes a complete physical reload which might take some time." << std::endl; 148 this->setPhysicalWorld(false); 149 this->negativeWorldRange_ = range; 150 this->setPhysicalWorld(true); 151 } 152 else 153 this->negativeWorldRange_ = range; 154 } 155 156 void Scene::setPositiveWorldRange(const Vector3& range) 157 { 158 if (range.length() < 10.0f) 159 { 160 CCOUT(2) << "Warning: Setting the positive world range to a very small value: " 161 << omni_cast<std::string>(range) << std::endl; 162 } 163 if (this->hasPhysics()) 164 { 165 CCOUT(2) << "Warning: Attempting to set the physical world range at run time. " 166 << "This causes a complete physical reload which might take some time." << std::endl; 167 this->setPhysicalWorld(false); 168 this->positiveWorldRange_ = range; 169 this->setPhysicalWorld(true); 170 } 171 else 172 this->positiveWorldRange_ = range; 173 } 174 175 void Scene::setGravity(const Vector3& gravity) 176 { 177 this->gravity_ = gravity; 178 if (this->hasPhysics()) 179 this->physicalWorld_->setGravity(omni_cast<btVector3>(this->gravity_)); 180 } 181 182 void Scene::setPhysicalWorld(bool wantPhysics) 183 { 184 this->bHasPhysics_ = wantPhysics; 185 if (wantPhysics && !hasPhysics()) 186 { 187 // Note: These are all little known default classes and values. 188 // It would require further investigation to properly dertermine the right choices. 189 this->broadphase_ = new bt32BitAxisSweep3( 190 omni_cast<btVector3>(this->negativeWorldRange_), omni_cast<btVector3>(this->positiveWorldRange_)); 191 this->collisionConfig_ = new btDefaultCollisionConfiguration(); 192 this->dispatcher_ = new btCollisionDispatcher(this->collisionConfig_); 193 this->solver_ = new btSequentialImpulseConstraintSolver(); 194 195 this->physicalWorld_ = new btDiscreteDynamicsWorld(this->dispatcher_, this->broadphase_, this->solver_, this->collisionConfig_); 196 this->physicalWorld_->setGravity(omni_cast<btVector3>(this->gravity_)); 197 198 // also set the collision callback variable. 199 // Note: This is a global variable which we assign a static function. 200 // TODO: Check whether this (or anything about Bullet) works with multiple physics engine instances. 201 gContactAddedCallback = &Scene::collisionCallback; 202 } 203 else if (!wantPhysics && hasPhysics()) 204 { 205 // Remove all WorldEntities and shove them to the queue since they would still like to be in a physical world. 206 for (std::set<WorldEntity*>::const_iterator it = this->physicalObjects_.begin(); 207 it != this->physicalObjects_.end(); ++it) 208 { 209 this->physicalWorld_->removeRigidBody((*it)->physicalBody_); 210 this->physicalObjectQueue_.insert(*it); 211 } 212 this->physicalObjects_.clear(); 213 214 delete this->physicalWorld_; 215 delete this->solver_; 216 delete this->dispatcher_; 217 delete this->collisionConfig_; 218 delete this->broadphase_; 219 this->physicalWorld_ = 0; 220 this->solver_ = 0; 221 this->dispatcher_ = 0; 222 this->collisionConfig_ = 0; 223 this->broadphase_ = 0; 224 } 225 } 226 227 void Scene::tick(float dt) 228 { 229 if (!Core::showsGraphics()) 230 { 231 // We need to update the scene nodes if we don't render 232 this->rootSceneNode_->_update(true, false); 233 } 234 if (this->hasPhysics()) 235 { 236 // TODO: This here is bad practice! It will slow down the first tick() by ages. 237 // Rather have an initialise() method as well, called by the Level after everything has been loaded. 238 if (this->physicalObjectQueue_.size() > 0) 239 { 240 // Add all scheduled WorldEntities 241 for (std::set<WorldEntity*>::const_iterator it = this->physicalObjectQueue_.begin(); 242 it != this->physicalObjectQueue_.end(); ++it) 243 { 244 this->physicalWorld_->addRigidBody((*it)->physicalBody_); 245 this->physicalObjects_.insert(*it); 246 } 247 this->physicalObjectQueue_.clear(); 248 } 249 250 // Note: 60 means that Bullet will do physics correctly down to 1 frames per seconds. 251 // Under that mark, the simulation will "loose time" and get unusable. 252 physicalWorld_->stepSimulation(dt, 60); 253 } 118 254 } 119 255 … … 165 301 } 166 302 167 void Scene::tick(float dt) 168 { 169 if (!Core::showsGraphics()) 170 { 171 // We need to update the scene nodes if we don't render 172 this->rootSceneNode_->_update(true, false); 173 } 303 void Scene::addPhysicalObject(WorldEntity* object) 304 { 305 if (object) 306 { 307 std::set<WorldEntity*>::iterator it = this->physicalObjects_.find(object); 308 if (it != this->physicalObjects_.end()) 309 return; 310 311 this->physicalObjectQueue_.insert(object); 312 } 313 } 314 315 void Scene::removePhysicalObject(WorldEntity* object) 316 { 317 // check queue first 318 std::set<WorldEntity*>::iterator it = this->physicalObjectQueue_.find(object); 319 if (it != this->physicalObjectQueue_.end()) 320 { 321 this->physicalObjectQueue_.erase(it); 322 return; 323 } 324 325 it = this->physicalObjects_.find(object); 326 if (it == this->physicalObjects_.end()) 327 return; 328 this->physicalObjects_.erase(it); 329 330 if (this->hasPhysics()) 331 this->physicalWorld_->removeRigidBody(object->physicalBody_); 332 } 333 334 /*static*/ bool Scene::collisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, 335 int index0, const btCollisionObject* colObj1, int partId1, int index1) 336 { 337 // get the WorldEntity pointers 338 WorldEntity* object0 = (WorldEntity*)colObj0->getUserPointer(); 339 assert(dynamic_cast<WorldEntity*>(object0)); 340 WorldEntity* object1 = (WorldEntity*)colObj1->getUserPointer(); 341 assert(dynamic_cast<WorldEntity*>(object1)); 342 343 // false means that bullet will assume we didn't modify the contact 344 bool modified = false; 345 if (object0->isCollisionCallbackActive()) 346 { 347 modified |= object0->collidesAgainst(object1, cp); 348 if (object1->isCollisionCallbackActive()) 349 modified |= object1->collidesAgainst(object0, cp); 350 } 351 else 352 modified |= object1->collidesAgainst(object0, cp); 353 354 return modified; 174 355 } 175 356 } -
code/trunk/src/orxonox/objects/Scene.h
r2171 r2662 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder (physics) 24 25 * Co-authors: 25 26 * ... … … 32 33 #include "OrxonoxPrereqs.h" 33 34 34 #include "network/ Synchronisable.h"35 #include "network/synchronisable/Synchronisable.h" 35 36 #include "core/BaseObject.h" 36 37 #include "util/Math.h" … … 75 76 void networkcallback_applyAmbientLight() 76 77 { this->setAmbientLight(this->ambientLight_); } 78 void networkcallback_applyShadows() 79 { this->setShadow(this->bShadows_); } 77 80 78 Ogre::SceneManager* sceneManager_; 79 Ogre::SceneNode* rootSceneNode_; 80 std::string skybox_; 81 ColourValue ambientLight_; 82 std::list<BaseObject*> objects_; 83 bool bShadows_; 81 Ogre::SceneManager* sceneManager_; 82 Ogre::SceneNode* rootSceneNode_; 83 84 std::string skybox_; 85 ColourValue ambientLight_; 86 std::list<BaseObject*> objects_; 87 bool bShadows_; 88 89 90 ///////////// 91 // Physics // 92 ///////////// 93 94 public: 95 inline bool hasPhysics() 96 { return this->physicalWorld_ != 0; } 97 void setPhysicalWorld(bool wantsPhysics); 98 99 void setNegativeWorldRange(const Vector3& range); 100 inline const Vector3& getNegativeWorldRange() const 101 { return this->negativeWorldRange_; } 102 103 void setPositiveWorldRange(const Vector3& range); 104 inline const Vector3& getPositiveWorldRange() const 105 { return this->positiveWorldRange_; } 106 107 void setGravity(const Vector3& gravity); 108 inline const Vector3& getGravity() const 109 { return this->gravity_; } 110 111 void addPhysicalObject(WorldEntity* object); 112 void removePhysicalObject(WorldEntity* object); 113 114 private: 115 inline void networkcallback_hasPhysics() 116 { this->setPhysicalWorld(this->bHasPhysics_); } 117 inline void networkcallback_negativeWorldRange() 118 { this->setNegativeWorldRange(this->negativeWorldRange_); } 119 inline void networkcallback_positiveWorldRange() 120 { this->setPositiveWorldRange(this->positiveWorldRange_); } 121 inline void networkcallback_gravity() 122 { this->setGravity(this->gravity_); } 123 124 // collision callback from bullet 125 static bool collisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, 126 int index0, const btCollisionObject* colObj1, int partId1, int index1); 127 128 // Bullet objects 129 btDiscreteDynamicsWorld* physicalWorld_; 130 bt32BitAxisSweep3* broadphase_; 131 btDefaultCollisionConfiguration* collisionConfig_; 132 btCollisionDispatcher* dispatcher_; 133 btSequentialImpulseConstraintSolver* solver_; 134 135 std::set<WorldEntity*> physicalObjectQueue_; 136 std::set<WorldEntity*> physicalObjects_; 137 bool bHasPhysics_; 138 Vector3 negativeWorldRange_; 139 Vector3 positiveWorldRange_; 140 Vector3 gravity_; 84 141 }; 85 142 } -
code/trunk/src/orxonox/objects/Script.cc
r2087 r2662 64 64 void Script::execute() 65 65 { 66 LuaBind *lua = LuaBind::getInstance();67 lua ->loadString(this->code_);68 lua ->run();66 LuaBind& lua = LuaBind::getInstance(); 67 lua.loadString(this->code_); 68 lua.run(); 69 69 } 70 70 } -
code/trunk/src/orxonox/objects/Test.cc
r2171 r2662 61 61 void Test::setConfigValues() 62 62 { 63 SetConfigValue ( v1, 1 )/*.callback ( this, &Test::checkV1 )*/; 64 SetConfigValue ( v2, 2 )/*.callback ( this, &Test::checkV2 )*/; 65 SetConfigValue ( v3, 3 )/*.callback ( this, &Test::checkV3 )*/; 66 SetConfigValue ( v4, 4 )/*.callback ( this, &Test::checkV4 )*/; 63 SetConfigValue ( u1, 1 )/*.callback ( this, &Test::checkV1 )*/; 64 SetConfigValue ( u2, 2 )/*.callback ( this, &Test::checkV2 )*/; 65 SetConfigValue ( u3, 3 )/*.callback ( this, &Test::checkV3 )*/; 66 SetConfigValue ( u4, 4 )/*.callback ( this, &Test::checkV4 )*/; 67 68 SetConfigValue ( s1, 1 )/*.callback ( this, &Test::checkV1 )*/; 69 SetConfigValue ( s2, 2 )/*.callback ( this, &Test::checkV2 )*/; 70 SetConfigValue ( s3, 3 )/*.callback ( this, &Test::checkV3 )*/; 71 SetConfigValue ( s4, 4 )/*.callback ( this, &Test::checkV4 )*/; 67 72 } 68 73 … … 70 75 void Test::registerVariables() 71 76 { 72 REGISTERDATA ( v1,direction::toclient, new NetworkCallback<Test> ( this, &Test::checkV1 ) ); 73 REGISTERDATA ( v2,direction::toserver, new NetworkCallback<Test> ( this, &Test::checkV2 ) ); 74 REGISTERDATA ( v3,direction::serverMaster, new NetworkCallback<Test> ( this, &Test::checkV3 ) ); 75 REGISTERDATA ( v4,direction::clientMaster, new NetworkCallback<Test> ( this, &Test::checkV4 ) ); 77 registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 )); 78 registerVariable ( u2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkU2 )); 79 registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true ); 80 registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true ); 81 82 registerVariable ( s1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkS1 )); 83 registerVariable ( s2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkS2 )); 84 registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true ); 85 registerVariable ( s4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true ); 76 86 } 77 87 78 void Test::checkV1(){ 79 COUT(1) << "V1 changed: " << v1 << std::endl; 80 } 88 void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; } 89 void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; } 90 void Test::checkU3(){ COUT(1) << "U3 changed: " << u3 << std::endl; } 91 void Test::checkU4(){ COUT(1) << "U4 changed: " << u4 << std::endl; } 81 92 82 void Test::checkV2(){ 83 COUT(1) << "V2 changed: " << v2 << std::endl; 84 } 85 86 void Test::checkV3(){ 87 COUT(1) << "V3 changed: " << v3 << std::endl; 88 } 89 90 void Test::checkV4(){ 91 COUT(1) << "V4 changed: " << v4 << std::endl; 92 } 93 93 void Test::checkS1(){ COUT(1) << "S1 changed: " << s1 << std::endl; } 94 void Test::checkS2(){ COUT(1) << "S2 changed: " << s2 << std::endl; } 95 void Test::checkS3(){ COUT(1) << "S3 changed: " << s3 << std::endl; } 96 void Test::checkS4(){ COUT(1) << "S4 changed: " << s4 << std::endl; } 94 97 95 98 } -
code/trunk/src/orxonox/objects/Test.h
r2171 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "core/BaseObject.h" 34 #include "network/Synchronisable.h" 34 #include "network/synchronisable/Synchronisable.h" 35 36 37 typedef int TYPE; 38 typedef unsigned int UTYPE; 39 35 40 36 41 namespace orxonox … … 45 50 void registerVariables(); 46 51 47 void setV1(unsigned int value){ v1 = value; }48 void setV2(unsigned int value){ v2 = value; }49 void setV3(unsigned int value){ v3 = value; }50 void setV4(unsigned int value){ v4 = value; }51 52 52 void checkV1(); 53 void checkV2(); 54 void checkV3(); 55 void checkV4(); 53 //unsigned functions 54 void setU1(UTYPE value){ u1 = value; } 55 void setU2(UTYPE value){ u2 = value; } 56 void setU3(UTYPE value){ u3 = value; } 57 void setU4(UTYPE value){ u4 = value; } 58 void checkU1(); 59 void checkU2(); 60 void checkU3(); 61 void checkU4(); 56 62 57 void printV1(){ instance_->checkV1(); } 58 void printV2(){ instance_->checkV2(); } 59 void printV3(){ instance_->checkV3(); } 60 void printV4(){ instance_->checkV4(); } 63 //signed functions 64 void setS1(TYPE value){ s1 = value; } 65 void setS2(TYPE value){ s2 = value; } 66 void setS3(TYPE value){ s3 = value; } 67 void setS4(TYPE value){ s4 = value; } 68 void checkS1(); 69 void checkS2(); 70 void checkS3(); 71 void checkS4(); 72 73 static void printV1(){ instance_->checkU1(); } 74 static void printV2(){ instance_->checkU2(); } 75 static void printV3(){ instance_->checkU3(); } 76 static void printV4(){ instance_->checkU4(); } 61 77 62 78 private: 63 unsigned int v1; 64 unsigned int v2; 65 unsigned int v3; 66 unsigned int v4; 79 UTYPE u1; 80 UTYPE u2; 81 UTYPE u3; 82 UTYPE u4; 83 84 TYPE s1; 85 TYPE s2; 86 TYPE s3; 87 TYPE s4; 67 88 68 89 static Test* instance_; -
code/trunk/src/orxonox/objects/collisionshapes
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/controllers/CMakeLists.txt
r2131 r2662 2 2 Controller.cc 3 3 HumanController.cc 4 ArtificialController.cc 5 AIController.cc 6 ScriptController.cc 4 7 ) 5 8 -
code/trunk/src/orxonox/objects/controllers/Controller.cc
r2087 r2662 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "overlays/OverlayGroup.h" 33 34 34 35 namespace orxonox … … 42 43 this->player_ = 0; 43 44 this->controllableEntity_ = 0; 45 this->hud_ = 0; 46 this->bUpdateHUD_ = false; 44 47 } 45 48 46 49 Controller::~Controller() 47 50 { 51 if (this->isInitialized() && this->hud_) 52 delete this->hud_; 53 } 54 55 void Controller::changedControllableEntity() 56 { 57 if (this->bUpdateHUD_) 58 { 59 this->updateHUD(); 60 this->bUpdateHUD_ = false; 61 } 62 63 if (this->hud_) 64 this->hud_->setOwner(this->getControllableEntity()); 65 } 66 67 void Controller::updateHUD() 68 { 69 if (this->hud_) 70 { 71 delete this->hud_; 72 this->hud_ = 0; 73 } 74 75 if (this->hudtemplate_ != "") 76 { 77 this->hud_ = new OverlayGroup(this); 78 this->hud_->addTemplate(this->hudtemplate_); 79 this->hud_->setOwner(this->getControllableEntity()); 80 } 48 81 } 49 82 } -
code/trunk/src/orxonox/objects/controllers/Controller.h
r2087 r2662 47 47 { return this->player_; } 48 48 49 virtual inline void setControllableEntity(ControllableEntity* entity) 50 { this->controllableEntity_ = entity; } 51 virtual inline ControllableEntity* getControllableEntity() const 49 inline void setControllableEntity(ControllableEntity* entity) 50 { 51 if (entity != this->controllableEntity_) 52 { 53 this->controllableEntity_ = entity; 54 this->changedControllableEntity(); 55 } 56 } 57 inline ControllableEntity* getControllableEntity() const 52 58 { return this->controllableEntity_; } 59 virtual void changedControllableEntity(); 60 61 inline void setHUDTemplate(const std::string& name) 62 { 63 if (name != this->hudtemplate_) 64 { 65 this->hudtemplate_ = name; 66 if (this->controllableEntity_) 67 this->updateHUD(); 68 else 69 this->bUpdateHUD_ = true; 70 } 71 } 72 inline const std::string& getHUDTemplate() const 73 { return this->hudtemplate_; } 74 75 inline OverlayGroup* getHUD() const 76 { return this->hud_; } 53 77 54 78 protected: 79 void updateHUD(); 80 55 81 PlayerInfo* player_; 56 82 ControllableEntity* controllableEntity_; 83 std::string hudtemplate_; 84 OverlayGroup* hud_; 85 bool bUpdateHUD_; 57 86 }; 58 87 } -
code/trunk/src/orxonox/objects/controllers/HumanController.cc
r2087 r2662 33 33 #include "core/ConsoleCommand.h" 34 34 #include "objects/worldentities/ControllableEntity.h" 35 #include "objects/worldentities/pawns/Pawn.h" 36 #include "objects/gametypes/Gametype.h" 35 37 36 38 namespace orxonox … … 44 46 SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); 45 47 SetConsoleCommand(HumanController, altFire, true).keybindMode(KeybindMode::OnHold); 48 SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); 46 49 SetConsoleCommand(HumanController, greet, true); 47 50 SetConsoleCommand(HumanController, use, true); 48 51 SetConsoleCommand(HumanController, switchCamera, true); 52 SetConsoleCommand(HumanController, mouseLook, true); 53 SetConsoleCommand(HumanController, suicide, true); 54 SetConsoleCommand(HumanController, addBots, true).defaultValues(1); 55 SetConsoleCommand(HumanController, killBots, true).defaultValues(0); 56 SetConsoleCommand(HumanController, dropItems, true); 49 57 50 58 CreateUnloadableFactory(HumanController); … … 103 111 { 104 112 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 105 HumanController::localController_s->controllableEntity_->fire( );113 HumanController::localController_s->controllableEntity_->fire(WeaponMode::fire); 106 114 } 107 115 … … 109 117 { 110 118 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 111 HumanController::localController_s->controllableEntity_->altFire(); 119 HumanController::localController_s->controllableEntity_->fire(WeaponMode::altFire); 120 } 121 122 void HumanController::boost() 123 { 124 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 125 HumanController::localController_s->controllableEntity_->boost(); 112 126 } 113 127 … … 129 143 HumanController::localController_s->controllableEntity_->switchCamera(); 130 144 } 145 146 void HumanController::mouseLook() 147 { 148 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 149 HumanController::localController_s->controllableEntity_->mouseLook(); 150 } 151 152 void HumanController::suicide() 153 { 154 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 155 { 156 Pawn* pawn = dynamic_cast<Pawn*>(HumanController::localController_s->controllableEntity_); 157 if (pawn) 158 pawn->kill(); 159 } 160 } 161 162 void HumanController::addBots(unsigned int amount) 163 { 164 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) 165 HumanController::localController_s->controllableEntity_->getGametype()->addBots(amount); 166 } 167 168 void HumanController::killBots(unsigned int amount) 169 { 170 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype()) 171 HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount); 172 } 173 174 void HumanController::dropItems() 175 { 176 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 177 HumanController::localController_s->controllableEntity_->dropItems(); 178 } 131 179 } -
code/trunk/src/orxonox/objects/controllers/HumanController.h
r2087 r2662 54 54 static void altFire(); 55 55 56 static void boost(); 56 57 static void greet(); 57 58 static void use(); 58 59 static void switchCamera(); 60 static void mouseLook(); 61 static void dropItems(); 62 63 static void suicide(); 64 65 static void addBots(unsigned int amount); 66 static void killBots(unsigned int amount = 0); 59 67 60 68 private: -
code/trunk/src/orxonox/objects/gametypes/Gametype.cc
r2171 r2662 34 34 35 35 #include "core/CoreIncludes.h" 36 #include "core/ConfigValueIncludes.h" 37 #include "core/Template.h" 38 #include "core/Core.h" 39 #include "overlays/OverlayGroup.h" 36 40 #include "objects/infos/PlayerInfo.h" 41 #include "objects/infos/Bot.h" 37 42 #include "objects/worldentities/pawns/Spectator.h" 38 43 #include "objects/worldentities/SpawnPoint.h" 44 #include "objects/worldentities/Camera.h" 45 #include "Settings.h" 39 46 40 47 #include "network/Host.h" … … 44 51 CreateUnloadableFactory(Gametype); 45 52 46 Gametype::Gametype(BaseObject* creator) : BaseObject(creator) 53 Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator) 47 54 { 48 55 RegisterObject(Gametype); 49 56 57 this->setGametype(this); 58 50 59 this->defaultControllableEntity_ = Class(Spectator); 51 60 52 this->bStarted_ = false;53 this->bEnded_ = false;54 61 this->bAutoStart_ = false; 55 62 this->bForceSpawn_ = false; 63 this->numberOfBots_ = 0; 56 64 57 65 this->initialStartCountdown_ = 3; 58 this->startCountdown_ = 0; 59 this->bStartCountdownRunning_ = false; 66 67 this->setConfigValues(); 68 69 this->addBots(this->numberOfBots_); 70 71 // load the corresponding score board 72 if (Core::showsGraphics() && this->scoreboardTemplate_ != "") 73 { 74 this->scoreboard_ = new OverlayGroup(this); 75 this->scoreboard_->addTemplate(this->scoreboardTemplate_); 76 this->scoreboard_->setGametype(this); 77 } 78 else 79 this->scoreboard_ = 0; 80 } 81 82 void Gametype::setConfigValues() 83 { 84 SetConfigValue(initialStartCountdown_, 3.0f); 85 SetConfigValue(bAutoStart_, false); 86 SetConfigValue(bForceSpawn_, false); 87 SetConfigValue(numberOfBots_, 0); 88 SetConfigValue(scoreboardTemplate_, "defaultScoreboard"); 60 89 } 61 90 62 91 void Gametype::tick(float dt) 63 92 { 64 if (this->bStartCountdownRunning_ && !this->bStarted_) 65 this->startCountdown_ -= dt; 66 67 if (!this->bStarted_) 93 SUPER(Gametype, tick, dt); 94 95 if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_) 96 this->gtinfo_.startCountdown_ -= dt; 97 98 if (!this->gtinfo_.bStarted_) 68 99 this->checkStart(); 69 100 else … … 76 107 { 77 108 COUT(0) << "game started" << std::endl; 78 this-> bStarted_ = true;109 this->gtinfo_.bStarted_ = true; 79 110 80 111 this->spawnPlayersIfRequested(); … … 84 115 { 85 116 COUT(0) << "game ended" << std::endl; 86 this-> bEnded_ = true;117 this->gtinfo_.bEnded_ = true; 87 118 } 88 119 89 120 void Gametype::playerEntered(PlayerInfo* player) 90 121 { 91 this->players_[player] = PlayerState::Joined;122 this->players_[player].state_ = PlayerState::Joined; 92 123 93 124 std::string message = player->getName() + " entered the game"; … … 98 129 void Gametype::playerLeft(PlayerInfo* player) 99 130 { 100 std::map<PlayerInfo*, Player State::Enum>::iterator it = this->players_.find(player);131 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(player); 101 132 if (it != this->players_.end()) 102 133 { … … 140 171 void Gametype::pawnKilled(Pawn* victim, Pawn* killer) 141 172 { 142 } 143 144 void Gametype::playerScored(PlayerInfo* player) 145 { 173 if (victim && victim->getPlayer()) 174 { 175 std::string message; 176 if (killer) 177 { 178 if (killer->getPlayer()) 179 message = victim->getPlayer()->getName() + " was killed by " + killer->getPlayer()->getName(); 180 else 181 message = victim->getPlayer()->getName() + " was killed"; 182 } 183 else 184 message = victim->getPlayer()->getName() + " died"; 185 186 COUT(0) << message << std::endl; 187 Host::Broadcast(message); 188 } 189 190 if (victim && victim->getPlayer()) 191 { 192 std::map<PlayerInfo*, Player>::iterator it = this->players_.find(victim->getPlayer()); 193 if (it != this->players_.end()) 194 { 195 it->second.state_ = PlayerState::Dead; 196 it->second.killed_++; 197 198 // Reward killer 199 if (killer) 200 { 201 std::map<PlayerInfo*, Player>::iterator itKiller = this->players_.find(killer->getPlayer()); 202 if (itKiller != this->players_.end()) 203 { 204 this->playerScored(itKiller->second); 205 } 206 else 207 COUT(2) << "Warning: Killing Pawn was not in the playerlist" << std::endl; 208 } 209 210 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(victim->getCreator()); 211 if (victim->getCamera()) 212 { 213 entity->setPosition(victim->getCamera()->getWorldPosition()); 214 entity->setOrientation(victim->getCamera()->getWorldOrientation()); 215 } 216 else 217 { 218 entity->setPosition(victim->getWorldPosition()); 219 entity->setOrientation(victim->getWorldOrientation()); 220 } 221 it->first->startControl(entity); 222 } 223 else 224 COUT(2) << "Warning: Killed Pawn was not in the playerlist" << std::endl; 225 } 226 } 227 228 void Gametype::playerScored(Player& player) 229 { 230 player.frags_++; 146 231 } 147 232 … … 150 235 if (this->spawnpoints_.size() > 0) 151 236 { 152 srand(time(0));153 rnd();154 155 237 unsigned int randomspawn = (unsigned int)rnd(this->spawnpoints_.size()); 156 238 unsigned int index = 0; … … 168 250 void Gametype::assignDefaultPawnsIfNeeded() 169 251 { 170 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 171 { 172 if (!it->first->getControllableEntity() && (!it->first->isReadyToSpawn() || !this->bStarted_)) 173 { 174 SpawnPoint* spawn = this->getBestSpawnPoint(it->first); 175 if (spawn) 176 { 177 // force spawn at spawnpoint with default pawn 178 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn); 179 spawn->spawn(entity); 180 it->first->startControl(entity); 181 it->second = PlayerState::Dead; 252 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 253 { 254 if (!it->first->getControllableEntity()) 255 { 256 it->second.state_ = PlayerState::Dead; 257 258 if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_) 259 { 260 SpawnPoint* spawn = this->getBestSpawnPoint(it->first); 261 if (spawn) 262 { 263 // force spawn at spawnpoint with default pawn 264 ControllableEntity* entity = this->defaultControllableEntity_.fabricate(spawn); 265 spawn->spawn(entity); 266 it->first->startControl(entity); 267 it->second.state_ = PlayerState::Dead; 268 } 269 else 270 { 271 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl; 272 abort(); 273 } 274 } 275 } 276 } 277 } 278 279 void Gametype::checkStart() 280 { 281 if (!this->gtinfo_.bStarted_) 282 { 283 if (this->gtinfo_.bStartCountdownRunning_) 284 { 285 if (this->gtinfo_.startCountdown_ <= 0) 286 { 287 this->gtinfo_.bStartCountdownRunning_ = false; 288 this->gtinfo_.startCountdown_ = 0; 289 this->start(); 290 } 291 } 292 else if (this->players_.size() > 0) 293 { 294 if (this->bAutoStart_) 295 { 296 this->start(); 182 297 } 183 298 else 184 299 { 185 COUT(1) << "Error: No SpawnPoints in current Gametype" << std::endl;186 abort();187 }188 }189 }190 }191 192 void Gametype::checkStart()193 {194 if (!this->bStarted_)195 {196 if (this->bStartCountdownRunning_)197 {198 if (this->startCountdown_ <= 0)199 {200 this->bStartCountdownRunning_ = false;201 this->startCountdown_ = 0;202 this->start();203 }204 }205 else if (this->players_.size() > 0)206 {207 if (this->bAutoStart_)208 {209 this->start();210 }211 else212 {213 300 bool allplayersready = true; 214 for (std::map<PlayerInfo*, PlayerState::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 301 bool hashumanplayers = false; 302 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 215 303 { 216 304 if (!it->first->isReadyToSpawn()) 217 305 allplayersready = false; 218 } 219 if (allplayersready) 220 { 221 this->startCountdown_ = this->initialStartCountdown_; 222 this->bStartCountdownRunning_ = true; 306 if (it->first->isHumanPlayer()) 307 hashumanplayers = true; 308 } 309 if (allplayersready && hashumanplayers) 310 { 311 this->gtinfo_.startCountdown_ = this->initialStartCountdown_; 312 this->gtinfo_.bStartCountdownRunning_ = true; 223 313 } 224 314 } … … 229 319 void Gametype::spawnPlayersIfRequested() 230 320 { 231 for (std::map<PlayerInfo*, Player State::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)321 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 232 322 if (it->first->isReadyToSpawn() || this->bForceSpawn_) 233 323 this->spawnPlayer(it->first); … … 236 326 void Gametype::spawnDeadPlayersIfRequested() 237 327 { 238 for (std::map<PlayerInfo*, Player State::Enum>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)239 if (it->second == PlayerState::Dead)328 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) 329 if (it->second.state_ == PlayerState::Dead) 240 330 if (it->first->isReadyToSpawn() || this->bForceSpawn_) 241 331 this->spawnPlayer(it->first); … … 248 338 { 249 339 player->startControl(spawnpoint->spawn()); 250 this->players_[player] = PlayerState::Alive;340 this->players_[player].state_ = PlayerState::Alive; 251 341 } 252 342 else … … 256 346 } 257 347 } 348 349 void Gametype::addBots(unsigned int amount) 350 { 351 for (unsigned int i = 0; i < amount; ++i) 352 new Bot(this); 353 } 354 355 void Gametype::killBots(unsigned int amount) 356 { 357 unsigned int i = 0; 358 for (ObjectList<Bot>::iterator it = ObjectList<Bot>::begin(); (it != ObjectList<Bot>::end()) && ((amount == 0) || (i < amount)); ) 359 { 360 if (it->getGametype() == this) 361 { 362 delete (*(it++)); 363 ++i; 364 } 365 } 366 } 258 367 } -
code/trunk/src/orxonox/objects/gametypes/Gametype.h
r2171 r2662 38 38 #include "objects/worldentities/ControllableEntity.h" 39 39 #include "objects/Tickable.h" 40 #include "objects/infos/GametypeInfo.h" 40 41 41 42 namespace orxonox … … 52 53 } 53 54 55 struct Player 56 { 57 PlayerInfo* info_; 58 PlayerState::Enum state_; 59 int frags_; 60 int killed_; 61 }; 62 54 63 class _OrxonoxExport Gametype : public BaseObject, public Tickable 55 64 { … … 60 69 virtual ~Gametype() {} 61 70 71 void setConfigValues(); 72 62 73 virtual void tick(float dt); 63 74 75 inline const GametypeInfo* getGametypeInfo() const 76 { return &this->gtinfo_; } 77 64 78 inline bool hasStarted() const 65 { return this-> bStarted_; }79 { return this->gtinfo_.bStarted_; } 66 80 inline bool hasEnded() const 67 { return this-> bEnded_; }81 { return this->gtinfo_.bEnded_; } 68 82 69 83 virtual void start(); … … 75 89 virtual void playerChangedName(PlayerInfo* player); 76 90 77 virtual void playerScored(Player Info*player);91 virtual void playerScored(Player& player); 78 92 79 93 virtual void pawnKilled(Pawn* victim, Pawn* killer = 0); … … 81 95 virtual void pawnPostSpawn(Pawn* pawn); 82 96 83 inline const std::map<PlayerInfo*, Player State::Enum>& getPlayers() const97 inline const std::map<PlayerInfo*, Player>& getPlayers() const 84 98 { return this->players_; } 85 99 … … 88 102 89 103 inline bool isStartCountdownRunning() const 90 { return this-> bStartCountdownRunning_; }104 { return this->gtinfo_.bStartCountdownRunning_; } 91 105 inline float getStartCountdown() const 92 { return this->startCountdown_; } 106 { return this->gtinfo_.startCountdown_; } 107 108 void addBots(unsigned int amount); 109 void killBots(unsigned int amount = 0); 110 111 inline unsigned int getNumberOfPlayers() const 112 { return this->players_.size(); } 93 113 94 114 private: … … 104 124 void spawnDeadPlayersIfRequested(); 105 125 106 bool bStarted_;107 bool bEnded_; 126 GametypeInfo gtinfo_; 127 108 128 bool bAutoStart_; 109 129 bool bForceSpawn_; 110 130 111 131 float initialStartCountdown_; 112 float startCountdown_; 113 bool bStartCountdownRunning_; 132 unsigned int numberOfBots_; 114 133 115 std::map<PlayerInfo*, Player State::Enum> players_;134 std::map<PlayerInfo*, Player> players_; 116 135 std::set<SpawnPoint*> spawnpoints_; 117 136 SubclassIdentifier<ControllableEntity> defaultControllableEntity_; 137 138 OverlayGroup* scoreboard_; 139 140 // Config Values 141 std::string scoreboardTemplate_; 118 142 }; 119 143 } -
code/trunk/src/orxonox/objects/infos/CMakeLists.txt
r2171 r2662 1 1 SET( SRC_FILES 2 Bot.cc 2 3 Info.cc 3 4 PlayerInfo.cc 4 5 HumanPlayer.cc 6 GametypeInfo.cc 5 7 ) 6 8 -
code/trunk/src/orxonox/objects/infos/HumanPlayer.cc
r2171 r2662 37 37 #include "objects/controllers/HumanController.h" 38 38 #include "objects/gametypes/Gametype.h" 39 #include "overlays/OverlayGroup.h" 39 40 40 41 namespace orxonox … … 63 64 { 64 65 SetConfigValue(nick_, "Player").callback(this, &HumanPlayer::configvaluecallback_changednick); 66 SetConfigValue(hudtemplate_, "defaultHUD").callback(this, &HumanPlayer::configvaluecallback_changedHUDTemplate); 65 67 } 66 68 67 69 void HumanPlayer::registerVariables() 68 70 { 69 REGISTERSTRING(this->synchronize_nick_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick));71 registerVariable(this->synchronize_nick_, variableDirection::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick)); 70 72 71 REGISTERDATA(this->clientID_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));72 REGISTERDATA(this->server_initialized_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized));73 REGISTERDATA(this->client_initialized_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized));73 registerVariable(this->clientID_, variableDirection::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged)); 74 registerVariable(this->server_initialized_, variableDirection::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized)); 75 registerVariable(this->client_initialized_, variableDirection::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized)); 74 76 } 75 77 … … 83 85 this->setName(this->nick_); 84 86 } 87 } 88 89 void HumanPlayer::configvaluecallback_changedHUDTemplate() 90 { 91 this->changedController(); 85 92 } 86 93 … … 99 106 100 107 if (!Core::isMaster()) 101 this->setObjectMode( direction::bidirectional);108 this->setObjectMode(objectDirection::bidirectional); 102 109 else 103 110 this->setName(this->nick_); … … 138 145 this->networkcallback_clientIDchanged(); 139 146 } 147 148 void HumanPlayer::changedController() 149 { 150 if (this->getController()) 151 { 152 this->getController()->setHUDTemplate(this->hudtemplate_); 153 154 if (this->getController() && this->getController()->getHUD()) 155 this->getController()->getHUD()->setOwner(this->getControllableEntity()); 156 } 157 } 140 158 } -
code/trunk/src/orxonox/objects/infos/HumanPlayer.h
r2171 r2662 33 33 34 34 #include "PlayerInfo.h" 35 #include "core/Identifier.h"36 #include "objects/controllers/Controller.h"37 35 38 36 namespace orxonox … … 53 51 void setClientID(unsigned int clientID); 54 52 53 virtual void changedController(); 54 55 55 protected: 56 56 void configvaluecallback_changednick(); 57 void configvaluecallback_changedHUDTemplate(); 57 58 void networkcallback_changednick(); 58 59 void networkcallback_clientIDchanged(); … … 62 63 std::string nick_; 63 64 std::string synchronize_nick_; 65 std::string hudtemplate_; 64 66 bool server_initialized_; 65 67 bool client_initialized_; -
code/trunk/src/orxonox/objects/infos/Info.h
r2171 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "network/ Synchronisable.h"34 #include "network/synchronisable/Synchronisable.h" 35 35 #include "core/BaseObject.h" 36 36 -
code/trunk/src/orxonox/objects/infos/PlayerInfo.cc
r2171 r2662 46 46 this->bLocalPlayer_ = false; 47 47 this->bReadyToSpawn_ = false; 48 this->bSetUnreadyAfterSpawn_ = true; 48 49 this->controller_ = 0; 49 50 this->controllableEntity_ = 0; … … 64 65 this->controller_ = 0; 65 66 } 67 68 if (this->getGametype()) 69 this->getGametype()->playerLeft(this); 66 70 } 67 71 } … … 69 73 void PlayerInfo::registerVariables() 70 74 { 71 REGISTERSTRING(this->name_, direction::toclient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName));72 REGISTERDATA (this->controllableEntityID_, direction::toclient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedcontrollableentityID));73 REGISTERDATA (this->bReadyToSpawn_, direction::toserver);75 registerVariable(this->name_, variableDirection::toclient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName)); 76 registerVariable(this->controllableEntityID_, variableDirection::toclient, new NetworkCallback<PlayerInfo>(this, &PlayerInfo::networkcallback_changedcontrollableentityID)); 77 registerVariable(this->bReadyToSpawn_, variableDirection::toserver); 74 78 } 75 79 76 80 void PlayerInfo::changedName() 77 81 { 82 SUPER(PlayerInfo, changedName); 83 78 84 if (this->isInitialized() && this->getGametype()) 79 85 this->getGametype()->playerChangedName(this); … … 109 115 if (this->controllableEntity_) 110 116 this->controller_->setControllableEntity(this->controllableEntity_); 117 this->changedController(); 111 118 } 112 119 113 void PlayerInfo::startControl(ControllableEntity* entity )120 void PlayerInfo::startControl(ControllableEntity* entity, bool callback) 114 121 { 122 if (entity == this->controllableEntity_) 123 return; 124 115 125 if (this->controllableEntity_) 116 this->stopControl(this->controllableEntity_ );126 this->stopControl(this->controllableEntity_, callback); 117 127 118 128 this->controllableEntity_ = entity; … … 122 132 this->controllableEntityID_ = entity->getObjectID(); 123 133 entity->setPlayer(this); 124 this->bReadyToSpawn_ = false;134 this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_); 125 135 } 126 136 else -
code/trunk/src/orxonox/objects/infos/PlayerInfo.h
r2171 r2662 65 65 { return this->bReadyToSpawn_; } 66 66 67 void startControl(ControllableEntity* entity );67 void startControl(ControllableEntity* entity, bool callback = true); 68 68 void stopControl(ControllableEntity* entity, bool callback = true); 69 69 … … 71 71 { return this->controllableEntity_; } 72 72 73 inline Controller* getController() const 74 { return this->controller_; } 75 virtual void changedController() {} 76 73 77 protected: 74 78 void createController(); 75 void networkcallback_changedcontrollableentityID();76 79 77 80 bool bHumanPlayer_; 78 81 bool bLocalPlayer_; 82 bool bSetUnreadyAfterSpawn_; 83 SubclassIdentifier<Controller> defaultController_; 84 unsigned int clientID_; 85 86 private: 87 void networkcallback_changedcontrollableentityID(); 88 79 89 bool bReadyToSpawn_; 80 SubclassIdentifier<Controller> defaultController_;81 90 Controller* controller_; 82 91 ControllableEntity* controllableEntity_; 83 92 unsigned int controllableEntityID_; 84 unsigned int clientID_;85 93 }; 86 94 } -
code/trunk/src/orxonox/objects/pickup/CMakeLists.txt
r2131 r2662 1 1 SET( SRC_FILES 2 ShipEquipmentClasses.cc 3 ShipItem.cc 2 PickupSpawner.cc 3 BaseItem.cc 4 Turbo.cc 5 ShipEquipment.cc 4 6 ) 5 7 -
code/trunk/src/orxonox/objects/pickup/ShipEquipment.h
r2094 r2662 1 2 1 #ifndef _ShipEquipment_H__ 3 2 #define _ShipEquipment_H__ 4 3 #include <string> 5 #include <multimap> 4 #include <map> 5 6 /* 7 multimap<std::string, BaseItem*> equipment_; 8 equipment_.insert(pair<std::string, BaseItem*>("Weapon", new BaseItem()));*/ 6 9 7 10 8 /* 9 multimap<std::string, Item*> equipment_;10 equipment_.insert(pair<std::string, Item*>("Weapon", new Item()));*/ 11 /* std::map<std::itemtype, BaseItem*> EQClasses; 12 EQClasses["jacke"] = 0; 13 BaseItem* item = itemMap_["jacke"]; 11 14 12 15 if (itemMap_["jacke"]) 16 if (itemMap_.find("jacke") != itemMap_.end()) */ 13 17 namespace orxonox 14 18 { 19 class BaseItem; 20 /** 21 @brief 22 ShipEquipment is the inventory of a player. It's part of the Pawn class. 23 24 */ 15 25 class _OrxonoxExport ShipEquipment 16 26 { 17 27 public: 18 void AddItem(Shipitem toAddItem); 19 void RemoveItem(Shipitem toRemoveItem); 20 bool CheckifValid(Shipitem toBeChecked); 21 int 22 28 inline int getSpace() 29 { 30 return Usable.size()+Trunk.size(); 31 }; 32 bool insert(BaseItem* item); 33 bool erase (BaseItem* item); 34 //void print(std::multimap<std::string, BaseItem*> eut); 35 void eraseAll(); 36 //bool checkSlot(BaseItem* item); 37 BaseItem* checkSlot(BaseItem* item); 38 // const std::multimap<std::string, BaseItem*>& getEquipment() const { return this->Equipment; } 39 inline std::multimap<std::string, BaseItem*>& getEquipment() {return this->Equipment;} 40 inline std::multimap<std::string, BaseItem*>& getUsable() {return this->Usable;} 41 inline std::multimap<std::string, BaseItem*>& getTrunk() {return this->Trunk;} 42 inline Pawn* getPlayer() {return this->player ;} 43 inline void setPlayer(Pawn* setplayer) 44 {this->player = setplayer;} 23 45 private: 24 std::multimap<std::string, Item*> Equipment; 46 Pawn* player;//!< Is a pointer to the belonging player 47 std::multimap<std::string, BaseItem*> Equipment;//!< the Equipment for permanent Items 48 std::multimap<std::string, BaseItem*> Usable;//!< Where Usables are stored 49 std::multimap<std::string, BaseItem*> Trunk;//!< Every other Item is stored here 25 50 }; 26 51 } … … 39 64 40 65 41 42 43 44 45 66 #endif -
code/trunk/src/orxonox/objects/pickup/ShipEquipmentClasses.cc
r2094 r2662 57 57 } 58 58 break; 59 default:;60 59 } 61 60 case Useable: 62 61 return CheckifSpace(); 63 case default:;64 62 } 65 63 return true; … … 67 65 68 66 /*Adds the Item to the Ship*/ 69 void ShipEquipment::AddItem(Ship item* toAddItem)67 void ShipEquipment::AddItem(ShipItem* toAddItem) 70 68 { 71 69 if(CheckifValid(toAddItem)==true) … … 90 88 } 91 89 } 90 91 /*Adds the Item to the Ship*/ 92 void ShipEquipment::AddItem(Shipitem* toAddItem) 93 { 94 if(CheckifValid(toAddItem)==true) 95 { 96 switch(toAddItem.CheckType()){ 97 case Permanent: 98 Equipment.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); 99 break; 100 case Usable: 101 Usable.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); 102 break; 103 case Trunk: 104 Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); 105 break; 106 } 107 } 108 else if(toAddItem.CheckType()==Permanent) 109 { 110 if(CheckifSpace()==true) 111 Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); 112 } 113 } 114 115 void ShipEquipment::SwitchItem(Permanent* toSwitchItem) 116 { 117 multimap<string, ShipItem*>::iterator it; 118 string equippedname; 119 equippedname=GetNameofPermanent(toSwitchItem.CheckSubType()); 120 it=Equipment.find(equippedname); 121 Trunk.insert (find(equippedname)); 122 Equipment.erase (it); 123 Equipment.insert(pair<std::string, ShipItem*>(toSwitchItem.itemname,toSwitchItem) 124 } 125 126 string ShipEquipment::GetNameofPermanent (subItemTypePermanent NametoGet) 127 { 128 multimap<string, ShipItem*>::iterator it; 129 for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ 130 if((*it).second->CheckSubType()==NametoGet){ 131 return (*it).first.itemname; 132 } 133 } 134 return 0; 135 } 92 136 } -
code/trunk/src/orxonox/objects/pickup/ShipEquipmentClasses.h
r2094 r2662 8 8 9 9 /* 10 multimap<std::string, Item*> equipment_;11 equipment_.insert(pair<std::string, Item*>("Weapon", newItem()));*/10 multimap<std::string, BaseItem*> equipment_; 11 equipment_.insert(pair<std::string, BaseItem*>("Weapon", new BaseItem()));*/ 12 12 13 13 14 /* std::map<std::itemtype, Item*> EQClasses;14 /* std::map<std::itemtype, BaseItem*> EQClasses; 15 15 EQClasses["jacke"] = 0; 16 Item* item = itemMap_["jacke"];16 BaseItem* item = itemMap_["jacke"]; 17 17 18 18 if (itemMap_["jacke"]) … … 23 23 { 24 24 public: 25 void AddItem(Shipitem* toAddItem);25 /*void AddItem(Shipitem* toAddItem); 26 26 void RemoveItem(Shipitem* toRemoveItem); 27 27 bool CheckifValid(Shipitem* toBeChecked); 28 28 bool CheckifSpace(); 29 void SwitchItem(Permanent* toSwitchItem); 30 string GetNameofPermanent (subItemTypePermanent NametoGet);*/ //holt den Namen des getragenen Items im jeweiligen Slot. 29 31 30 32 private: 31 multimap<std::string, ShipItem*> Equipment;32 multimap<std::string, ShipItem*> Usable;33 multimap<std::string, ShipItem*> Trunk;33 multimap<std::string, BaseItem*> Equipment; 34 multimap<std::string, BaseItem*> Usable; 35 multimap<std::string, BaseItem*> Trunk; 34 36 }; 35 37 } -
code/trunk/src/orxonox/objects/pickup/ShipItem.cc
r2089 r2662 5 5 itemtype ShipItem::CheckType() 6 6 { 7 return this .type;7 return this->type; 8 8 } 9 9 10 10 subItemTypePermanent CheckSubType() 11 11 { 12 return this .subtype_permanent;12 return this->subtype_permanent; 13 13 } 14 15 subItemTypePowerups CheckSubType() 16 { 17 return this->subtype_powerups; 18 } 19 subItemTypeUsable CheckSubType() 20 { 21 return this->subtype_usables; 22 } 23 14 24 } -
code/trunk/src/orxonox/objects/pickup/ShipItem.h
r2094 r2662 21 21 public: 22 22 itemType CheckType(); 23 virtual23 //virtual ChecksubType(); 24 24 25 25 private: … … 27 27 string itemname; 28 28 }; 29 30 29 31 30 /* Useables are Items the Player can choose when to activate and then show an instant action/effect … … 37 36 Rockets, 38 37 Repairkits, 39 Triggers, 38 Triggers, //trigger events usable by the player (Quests f.exp.) 40 39 Boosters, 41 40 Shields, -
code/trunk/src/orxonox/objects/pickup/Usable.h
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/quest/AddQuest.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file AddQuest.cc 31 @brief 32 Implementation of the AddQuest class. 30 @file 31 @brief Implementation of the AddQuest class. 33 32 */ 34 33 … … 45 44 #include "Quest.h" 46 45 47 namespace orxonox {48 46 namespace orxonox 47 { 49 48 CreateFactory(AddQuest); 50 49 … … 109 108 } 110 109 111 COUT(3) << "Quest {" << this->getQuestId() << "} successfully added to player ." << std::endl;110 COUT(3) << "Quest {" << this->getQuestId() << "} successfully added to player: " << player << " ." << std::endl; 112 111 return true; 113 112 } -
code/trunk/src/orxonox/objects/quest/AddQuest.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file AddQuest.h 31 @brief 32 Definition of the AddQuest class. 30 @file 31 @brief Definition of the AddQuest class. 33 32 */ 34 33 … … 43 42 #include "ChangeQuestStatus.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 /** 48 47 @brief … … 58 57 { 59 58 public: 60 61 62 63 64 65 59 AddQuest(BaseObject* creator); 60 virtual ~AddQuest(); 61 62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a AddQuest object through XML. 63 64 virtual bool invoke(PlayerInfo* player); //!< Invokes the QuestEffect. 66 65 67 66 }; -
code/trunk/src/orxonox/objects/quest/AddQuestHint.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file AddQuestHint.cc 31 @brief 32 Implementation of the AddQuestHint class. 30 @file 31 @brief Implementation of the AddQuestHint class. 33 32 */ 34 33 … … 44 43 #include "QuestHint.h" 45 44 46 namespace orxonox {47 45 namespace orxonox 46 { 48 47 CreateFactory(AddQuestHint); 49 48 … … 130 129 } 131 130 132 COUT(3) << "QuestHint {" << this->getHintId() << "} successfully added to player ." << std::endl;131 COUT(3) << "QuestHint {" << this->getHintId() << "} successfully added to player: " << player << " ." << std::endl; 133 132 return true; 134 133 -
code/trunk/src/orxonox/objects/quest/AddQuestHint.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file AddQuestHint.h 31 @brief 32 Definition of the AddQuestHint class. 30 @file 31 @brief Definition of the AddQuestHint class. 33 32 */ 34 33 … … 42 41 #include "QuestEffect.h" 43 42 44 namespace orxonox {45 43 namespace orxonox 44 { 46 45 /** 47 46 @brief … … 73 72 inline const std::string & getHintId(void) const 74 73 { return this->hintId_; } 74 75 75 bool setHintId(const std::string & id); //!< Sets the id of the QuestHint. 76 76 -
code/trunk/src/orxonox/objects/quest/AddReward.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file AddReward.cc 31 @brief 32 Implementation of the AddReward class. 30 @file 31 @brief Implementation of the AddReward class. 33 32 */ 34 33 … … 41 40 #include "Rewardable.h" 42 41 43 namespace orxonox {44 42 namespace orxonox 43 { 45 44 CreateFactory(AddReward); 46 45 … … 106 105 bool AddReward::invoke(PlayerInfo* player) 107 106 { 107 COUT(3) << "AddReward on player: " << player << " ." << std::endl; 108 108 109 bool check = true; 109 110 for ( std::list<Rewardable*>::iterator reward = this->rewards_.begin(); reward != this->rewards_.end(); ++reward ) … … 111 112 check = check && (*reward)->reward(player); 112 113 } 114 115 COUT(3) << "Rewardable successfully added to player." << player << " ." << std::endl; 113 116 114 117 return check; -
code/trunk/src/orxonox/objects/quest/AddReward.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file AddReward.h 31 @brief 32 Definition of the AddReward class. 30 @file 31 @brief Definition of the AddReward class. 33 32 */ 34 33 … … 43 42 #include "QuestEffect.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 /** 48 47 @brief … … 78 77 inline void addRewardable(Rewardable* reward) 79 78 { this->rewards_.push_back(reward); } 79 80 80 const Rewardable* getRewardables(unsigned int index) const; //!< Returns the Rewardable object at the given index. 81 81 -
code/trunk/src/orxonox/objects/quest/CMakeLists.txt
r2261 r2662 14 14 QuestHint.cc 15 15 QuestItem.cc 16 QuestListener.cc 16 17 QuestManager.cc 17 18 Rewardable.cc -
code/trunk/src/orxonox/objects/quest/ChangeQuestStatus.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file ChangeQuestStatus.cc 31 @brief 32 Implementation of the ChangeQuestStatus class. 30 @file 31 @brief Implementation of the ChangeQuestStatus class. 33 32 */ 34 33 … … 40 39 #include "QuestItem.h" 41 40 42 namespace orxonox {43 41 namespace orxonox 42 { 44 43 /** 45 44 @brief -
code/trunk/src/orxonox/objects/quest/ChangeQuestStatus.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file ChangeQuestStatus.h 31 @brief 32 Definition of the ChangeQuestStatus class. 30 @file 31 @brief Definition of the ChangeQuestStatus class. 33 32 */ 34 33 … … 43 42 #include "QuestEffect.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 /** 48 47 @brief … … 63 62 protected: 64 63 /** 65 66 64 @brief Returns the id of the Quest. 65 @return Returns the id of the Quest. 67 66 */ 68 67 inline const std::string & getQuestId(void) const -
code/trunk/src/orxonox/objects/quest/CompleteQuest.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file CompleteQuest.cc 31 @brief 32 Implementation of the CompleteQuest class. 30 @file 31 @brief Implementation of the CompleteQuest class. 33 32 */ 34 33 … … 43 42 #include "Quest.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 CreateFactory(CompleteQuest); 48 47 -
code/trunk/src/orxonox/objects/quest/CompleteQuest.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file CompleteQuest.h 31 @brief 32 Definition of the CompleteQuest class. 30 @file 31 @brief Definition of the CompleteQuest class. 33 32 */ 34 33 … … 43 42 #include "ChangeQuestStatus.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 /** 48 47 @brief -
code/trunk/src/orxonox/objects/quest/FailQuest.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file FailQuest.cc 31 @brief 32 Implementation of the FailQuest class. 30 @file 31 @brief Implementation of the FailQuest class. 33 32 */ 34 33 … … 43 42 #include "Quest.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 CreateFactory(FailQuest); 48 47 -
code/trunk/src/orxonox/objects/quest/FailQuest.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file FailQuest.h 31 @brief 32 Definition of the FailQuest class. 30 @file 31 @brief Definition of the FailQuest class. 33 32 */ 34 33 … … 43 42 #include "ChangeQuestStatus.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 /** 48 47 @brief -
code/trunk/src/orxonox/objects/quest/GlobalQuest.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file GlobalQuest.cc 31 @brief 32 Implementation of the GlobalQuest class. 30 @file 31 @brief Implementation of the GlobalQuest class. 33 32 */ 34 33 … … 38 37 #include "orxonox/objects/infos/PlayerInfo.h" 39 38 #include "core/CoreIncludes.h" 39 #include "core/Super.h" 40 40 #include "util/Exception.h" 41 41 42 42 #include "QuestEffect.h" 43 43 44 namespace orxonox {45 44 namespace orxonox 45 { 46 46 CreateFactory(GlobalQuest); 47 47 … … 88 88 bool GlobalQuest::fail(PlayerInfo* player) 89 89 { 90 if( this->isFailable(player)) //!< Check whether the Quest can be failed.91 { 92 this->setStatus(player, questStatus::failed);93 94 //! Iterate through all players possessing this Quest.95 for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)96 {97 QuestEffect::invokeEffects(*it, this->getFailEffectList());98 }99 100 return true;101 }102 103 COUT(4) << "A non-completable quest was trying to be failed." << std::endl; 104 return false;90 if(!this->isFailable(player)) //!< Check whether the Quest can be failed. 91 { 92 COUT(4) << "A non-completable quest was trying to be failed." << std::endl; 93 return false; 94 } 95 96 Quest::fail(player); 97 98 //! Iterate through all players possessing this Quest. 99 for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++) 100 { 101 QuestEffect::invokeEffects(*it, this->getFailEffectList()); 102 } 103 104 return true; 105 105 } 106 106 … … 117 117 bool GlobalQuest::complete(PlayerInfo* player) 118 118 { 119 if( this->isCompletable(player)) //!< Check whether the Quest can be completed.120 { 121 this->setStatus(player, questStatus::completed);122 123 //! Iterate through all players possessing the Quest.124 for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++)125 {126 QuestEffect::invokeEffects(*it, this->getCompleteEffectList());127 }128 129 QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward QuestEffects on the player completing the Quest.130 return true;131 }132 133 COUT(4) << "A non-completable quest was trying to be completed." << std::endl;134 return false;119 if(!this->isCompletable(player)) //!< Check whether the Quest can be completed. 120 { 121 COUT(4) << "A non-completable quest was trying to be completed." << std::endl; 122 return false; 123 } 124 125 //! Iterate through all players possessing the Quest. 126 for(std::set<PlayerInfo*>::const_iterator it = players_.begin(); it != players_.end(); it++) 127 { 128 QuestEffect::invokeEffects(*it, this->getCompleteEffectList()); 129 } 130 131 Quest::complete(player); 132 133 QuestEffect::invokeEffects(player, this->rewards_); //!< Invoke reward QuestEffects on the player completing the Quest. 134 return true; 135 135 } 136 136 … … 207 207 } 208 208 209 return questStatus::inactive;209 return questStatus::inactive; 210 210 } 211 211 -
code/trunk/src/orxonox/objects/quest/GlobalQuest.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file GlobalQuest.h 31 @brief 32 Definition of the GlobalQuest class. 30 @file 31 @brief Definition of the GlobalQuest class. 33 32 */ 34 33 … … 44 43 #include "Quest.h" 45 44 46 namespace orxonox {47 45 namespace orxonox 46 { 48 47 /** 49 48 @brief … … 56 55 <QuestDescription title="Title" description="Description." /> //The description of the quest. 57 56 <subquests> 58 <Quest id ="questId1" /> //A list of n subquest, be aware, each of the <Quest /> tags must have a description and so on and so forth as well.59 ...60 <Quest id="questIdn" />61 </subquests>62 <hints>63 <QuestHint id="hintId1" /> //A list of n QuestHints, see QuestHint for the full XML representation of those.64 ...65 <QuestHint id="hintIdn" />66 </hints>57 <Quest id ="questId1" /> //A list of n subquest, be aware, each of the <Quest /> tags must have a description and so on and so forth as well. 58 ... 59 <Quest id="questIdn" /> 60 </subquests> 61 <hints> 62 <QuestHint id="hintId1" /> //A list of n QuestHints, see QuestHint for the full XML representation of those. 63 ... 64 <QuestHint id="hintIdn" /> 65 </hints> 67 66 <fail-effects> 68 67 <QuestEffect /> //A list of QuestEffects, invoked on all players possessing this quest, when the Quest is failed, see QuestEffect for the full XML representation. -
code/trunk/src/orxonox/objects/quest/LocalQuest.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file LocalQuest.cc 31 @brief 32 Implementation of the LocalQuest class. 30 @file 31 @brief Implementation of the LocalQuest class. 33 32 */ 34 33 … … 37 36 38 37 #include "core/CoreIncludes.h" 38 #include "core/Super.h" 39 39 #include "util/Exception.h" 40 40 … … 42 42 #include "QuestEffect.h" 43 43 44 namespace orxonox {45 44 namespace orxonox 45 { 46 46 CreateFactory(LocalQuest); 47 47 … … 86 86 bool LocalQuest::fail(PlayerInfo* player) 87 87 { 88 if(this->isFailable(player)) //!< Checks whether the quest can be failed. 89 { 90 this->setStatus(player, questStatus::failed); 91 QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects. 92 return true; 93 } 94 95 COUT(4) << "A non-failable quest was trying to be failed." << std::endl; 96 return false; 88 if(!this->isFailable(player)) //!< Checks whether the quest can be failed. 89 { 90 COUT(4) << "A non-failable quest was trying to be failed." << std::endl; 91 return false; 92 } 93 94 Quest::fail(player); 95 96 QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects. 97 return true; 97 98 } 98 99 … … 108 109 bool LocalQuest::complete(PlayerInfo* player) 109 110 { 110 if(this->isCompletable(player)) //!< Checks whether the Quest can be completed. 111 { 112 this->setStatus(player, questStatus::completed); 113 QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects. 114 return true; 115 } 116 117 COUT(4) << "A non-completable quest was trying to be completed." << std::endl; 118 return false; 111 if(!this->isCompletable(player)) //!< Checks whether the Quest can be completed. 112 { 113 COUT(4) << "A non-completable quest was trying to be completed." << std::endl; 114 return false; 115 } 116 117 Quest::complete(player); 118 119 QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects. 120 return true; 119 121 } 120 122 -
code/trunk/src/orxonox/objects/quest/LocalQuest.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file LocalQuest.h 31 @brief 32 Definition of the LocalQuest class. 30 @file 31 @brief Definition of the LocalQuest class. 33 32 */ 34 33 … … 44 43 #include "Quest.h" 45 44 46 namespace orxonox {47 45 namespace orxonox 46 { 48 47 /** 49 48 @brief … … 56 55 <QuestDescription title="Title" description="Description." /> //The description of the quest. 57 56 <subquests> 58 <Quest id ="questId1" /> //A list of n subquest, be aware, each of the <Quest /> tags must have a description and so on and so forth as well.59 ...60 <Quest id="questIdn" />61 </subquests>62 <hints>63 <QuestHint id="hintId1" /> //A list of n QuestHints, see QuestHint for the full XML representation of those.64 ...65 <QuestHint id="hintIdn" />66 </hints>57 <Quest id ="questId1" /> //A list of n subquest, be aware, each of the <Quest /> tags must have a description and so on and so forth as well. 58 ... 59 <Quest id="questIdn" /> 60 </subquests> 61 <hints> 62 <QuestHint id="hintId1" /> //A list of n QuestHints, see QuestHint for the full XML representation of those. 63 ... 64 <QuestHint id="hintIdn" /> 65 </hints> 67 66 <fail-effects> 68 67 <QuestEffect /> //A list of QuestEffects, invoked when the Quest is failed, see QuestEffect for the full XML representation. -
code/trunk/src/orxonox/objects/quest/Quest.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file Quest.cc 31 @brief 32 Implementation of the Quest class. 30 @file 31 @brief Implementation of the Quest class. 33 32 */ 34 33 … … 43 42 #include "QuestHint.h" 44 43 #include "QuestEffect.h" 45 46 namespace orxonox { 47 44 #include "QuestListener.h" 45 46 namespace orxonox 47 { 48 48 /** 49 49 @brief … … 363 363 return this->getStatus(player) == questStatus::completed; 364 364 } 365 366 /** 367 @brief 368 Fails the Quest for an input player. 369 @param player 370 The player. 371 @return 372 Returns true if the Quest could be failed, false if not. 373 */ 374 bool Quest::fail(PlayerInfo* player) 375 { 376 QuestListener::advertiseStatusChange(this->listeners_, "fail"); //!< Tells the QuestListeners, that the status has changed to failed. 377 this->setStatus(player, questStatus::failed); 378 379 COUT(4) << "Quest {" << this->getId() << "} is failed for player: " << player << " ." <<std::endl; 380 381 this->getDescription()->sendFailQuestNotification(); 382 return true; 383 } 384 385 /** 386 @brief 387 Completes the Quest for an input player. 388 @param player 389 The player. 390 @return 391 Returns true if the Quest could be completed, false if not. 392 */ 393 bool Quest::complete(PlayerInfo* player) 394 { 395 QuestListener::advertiseStatusChange(this->listeners_, "complete"); //!< Tells the QuestListeners, that the status has changed to completed. 396 this->setStatus(player, questStatus::completed); 397 398 COUT(4) << "Quest {" << this->getId() << "} is completed for player: " << player << " ." <<std::endl; 399 400 this->getDescription()->sendCompleteQuestNotification(); 401 return true; 402 } 365 403 366 404 /** … … 374 412 bool Quest::start(PlayerInfo* player) 375 413 { 376 if(this->isStartable(player)) //!< Checks whether the quest can be started. 377 { 378 this->setStatus(player, questStatus::active); 379 return true; 380 } 381 382 COUT(4) << "A non-startable quest was trying to be started." << std::endl; 383 return false; 414 if(!this->isStartable(player)) //!< Checks whether the quest can be started. 415 { 416 COUT(4) << "A non-startable quest was trying to be started." << std::endl; 417 return false; 418 } 419 420 COUT(4) << "Quest {" << this->getId() << "} is started for player: " << player << " ." <<std::endl; 421 422 QuestListener::advertiseStatusChange(this->listeners_, "start"); //!< Tells the QuestListeners, that the status has changed to active. 423 424 this->setStatus(player, questStatus::active); 425 426 this->getDescription()->sendAddQuestNotification(); 427 return true; 428 } 429 430 /** 431 @brief 432 Adds a QuestListener to the list of QuestListeners listening to this Quest. 433 @param listener 434 The QuestListener to be added. 435 @return 436 Returns true if successful, false if not. 437 */ 438 bool Quest::addListener(QuestListener* listener) 439 { 440 if(listener == NULL) 441 { 442 COUT(2) << "A NULL-QuestListener was trying to be added to a Quests listeners." << std::endl; 443 return false; 444 } 445 446 this->listeners_.push_back(listener); 447 return true; 384 448 } 385 449 -
code/trunk/src/orxonox/objects/quest/Quest.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file Quest.h 31 @brief 32 Definition of the Quest class. 33 34 The Quest is the parent class of LocalQuest and GlobalQuest. 30 @file 31 @brief Definition of the Quest class. 32 The Quest is the parent class of LocalQuest and GlobalQuest. 35 33 */ 36 34 … … 47 45 #include "QuestItem.h" 48 46 49 namespace questStatus47 namespace orxonox 50 48 { 49 namespace questStatus 50 { 51 51 52 //!Different states of a Quest.53 enum Enum54 {55 inactive,56 active,57 failed,58 completed59 };52 //!Different states of a Quest. 53 enum Enum 54 { 55 inactive, 56 active, 57 failed, 58 completed 59 }; 60 60 61 } 62 63 namespace orxonox { 61 } 64 62 65 63 /** … … 90 88 { return this->parentQuest_; } 91 89 92 /** 93 @brief Returns the list of subquests. 94 @return Returns a reference to the list of subquests of the quest. 95 */ 96 inline const std::list<Quest*> & getSubQuestList(void) const 97 { return this->subQuests_; } 98 99 /** 100 @brief Returns the list of all QuestHints of this Quest. 101 @return Returns a reference to the list of QuestHints of the Quest. 102 */ 103 inline const std::list<QuestHint*> & getHintsList(void) const 104 { return this->hints_; } 105 106 bool isInactive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'inactive'. 107 bool isActive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'active'. 108 bool isFailed(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'failed'. 109 bool isCompleted(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'completed'. 110 111 bool start(PlayerInfo* player); //!< Sets a Quest to active. 112 virtual bool fail(PlayerInfo* player) = 0; //!< Fails the Quest. 113 virtual bool complete(PlayerInfo* player) = 0; //!< Completes the Quest. 90 /** 91 @brief Returns the list of subquests. 92 @return Returns a reference to the list of subquests of the quest. 93 */ 94 inline const std::list<Quest*> & getSubQuestList(void) const 95 { return this->subQuests_; } 96 97 /** 98 @brief Returns the list of all QuestHints of this Quest. 99 @return Returns a reference to the list of QuestHints of the Quest. 100 */ 101 inline const std::list<QuestHint*> & getHintsList(void) const 102 { return this->hints_; } 103 104 bool isInactive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'inactive'. 105 bool isActive(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'active'. 106 bool isFailed(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'failed'. 107 bool isCompleted(const PlayerInfo* player) const; //!< Returns true if the quest status for the specific player is 'completed'. 108 109 bool start(PlayerInfo* player); //!< Sets a Quest to active. 110 virtual bool fail(PlayerInfo* player); //!< Fails the Quest. 111 virtual bool complete(PlayerInfo* player); //!< Completes the Quest. 112 113 bool addListener(QuestListener* listener); //!< Adds a QuestListener to the list of QuestListeners listening to this Quest. 114 114 115 115 protected: … … 131 131 { return this->failEffects_; } 132 132 133 134 135 136 137 133 /** 134 @brief Returns the list of complete QuestEffects. 135 @return Returns a reference to the list of complete QuestEffects. 136 */ 137 inline std::list<QuestEffect*> & getCompleteEffectList(void) 138 138 { return this->completeEffects_; } 139 139 … … 141 141 virtual bool setStatus(PlayerInfo* player, const questStatus::Enum & status) = 0; //!< Changes the status for a specific player. 142 142 143 private:143 private: 144 144 Quest* parentQuest_; //!< Pointer to the parentquest. 145 145 std::list<Quest*> subQuests_; //!< List of all the subquests. … … 149 149 std::list<QuestEffect*> failEffects_; //!< A list of all QuestEffects to be invoked, when the Quest has been failed. 150 150 std::list<QuestEffect*> completeEffects_; //!< A list of QuestEffects to be invoked, when the Quest has been completed. 151 152 std::list<QuestListener*> listeners_; //!< A list of QuestListeners, that listen to what exactly happens with this Quest. 151 153 152 154 bool setParentQuest(Quest* quest); //!< Sets the parentquest of the Quest. -
code/trunk/src/orxonox/objects/quest/QuestDescription.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestDescription.cc 31 @brief 32 Implementation of the QuestDescription class. 30 @file 31 @brief Implementation of the QuestDescription class. 33 32 */ 34 33 … … 38 37 39 38 #include "core/CoreIncludes.h" 39 #include "orxonox/overlays/notifications/Notification.h" 40 40 41 namespace orxonox {42 41 namespace orxonox 42 { 43 43 CreateFactory(QuestDescription); 44 44 … … 74 74 XMLPortParam(QuestDescription, "title", setTitle, getTitle, xmlelement, mode); 75 75 XMLPortParam(QuestDescription, "description", setDescription, getDescription, xmlelement, mode); 76 XMLPortParam(QuestDescription, "failMessage", setFailMessage, getFailMessage, xmlelement, mode); 77 XMLPortParam(QuestDescription, "completeMessage", setCompleteMessage, getCompleteMessage, xmlelement, mode); 76 78 77 79 COUT(3) << "New QuestDescription with title '" << this->getTitle() << "' created." << std::endl; 80 } 81 82 /** 83 @brief 84 This method is a helper for sending QuestDescriptions as Notifications. 85 @param item 86 The item the QuestDescription is for. 87 @param status 88 The status the QuestDescription us for. 89 @return 90 Returns true if successful. 91 */ 92 bool QuestDescription::notificationHelper(const std::string & item, const std::string & status) const 93 { 94 std::string message = ""; 95 std::string title = ""; 96 if(item == "hint") 97 { 98 title = "You received a hint: '" + this->title_ + "'"; 99 message = this->description_; 100 } 101 else if(item == "quest") 102 { 103 if(status == "start") 104 { 105 title = "You received a new quest: '" + this->title_ + "'"; 106 message = this->description_; 107 } 108 else if(status == "fail") 109 { 110 title = "You failed the quest: '" + this->title_ + "'"; 111 message = this->failMessage_; 112 } 113 else if(status == "complete") 114 { 115 title = "You successfully completed the quest: '" + this->title_ + "'"; 116 message = this->completeMessage_; 117 } 118 else 119 { 120 COUT(2) << "Bad input in notificationHelper, this should not be happening!" << std::endl; 121 return false; 122 } 123 } 124 else 125 { 126 COUT(2) << "Bad input in notificationHelper, this should not be happening!" << std::endl; 127 return false; 128 } 129 130 Notification* notification = new Notification(0, message, title, 30); 131 notification->send(); 132 return true; 78 133 } 79 134 -
code/trunk/src/orxonox/objects/quest/QuestDescription.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestDescription.h 31 @brief 32 Definition of the QuestDescription class. 30 @file 31 @brief Definition of the QuestDescription class. 33 32 */ 34 33 … … 43 42 #include "core/XMLPort.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 /** 48 47 @brief … … 52 51 Creating a QuestDescription through XML goes as follows: 53 52 54 <QuestDescription title="Title" description="Description Text" />53 <QuestDescription title="Title" description="Description Text" failMessage="You fail." completeMessage="You win!" /> 55 54 @author 56 55 Damian 'Mozork' Frick 57 56 */ 58 class _OrxonoxExport QuestDescription : public BaseObject {59 57 class _OrxonoxExport QuestDescription : public BaseObject 58 { 60 59 public: 61 60 QuestDescription(BaseObject* creator); … … 64 63 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestDescription object through XML. 65 64 66 /**67 @brief Returns the title.68 @return Returns a string containing the title of the QuestDescription.69 */65 /** 66 @brief Returns the title. 67 @return Returns a string containing the title of the QuestDescription. 68 */ 70 69 inline const std::string & getTitle(void) const 71 70 { return this->title_; } 72 71 73 /**74 @brief Returns the description text.75 @return Returns a string containing the description text of the QuestDescription.76 */72 /** 73 @brief Returns the description text. 74 @return Returns a string containing the description text of the QuestDescription. 75 */ 77 76 inline const std::string & getDescription(void) const 78 77 { return this->description_; } 78 79 /** 80 @brief Returns the fail message. 81 @return Returns a string containing the fail message of the QuestDescription. 82 */ 83 inline const std::string & getFailMessage(void) const 84 { return this->failMessage_; } 85 86 /** 87 @brief Returns the complete message. 88 @return Returns a string containing the complete message of the QuestDescription. 89 */ 90 inline const std::string & getCompleteMessage(void) const 91 { return this->completeMessage_; } 92 93 /** 94 @brief Sends a Notification displaying that a QuestHint was added. 95 @return Returns true if successful. 96 */ 97 inline bool sendAddHintNotification(void) const 98 { return notificationHelper("hint", ""); } 99 100 /** 101 @brief Sends a Notification displaying that a Quest was added. 102 @return Returns true if successful. 103 */ 104 inline bool sendAddQuestNotification(void) const 105 { return notificationHelper("quest", "start"); } 106 107 /** 108 @brief Sends a Notification displaying that a Quest was failed. 109 @return Returns true if successful. 110 */ 111 inline bool sendFailQuestNotification(void) const 112 { return notificationHelper("quest", "fail"); } 113 114 /** 115 @brief Sends a Notification displaying that a Quest was completed. 116 @return Returns true if successful. 117 */ 118 inline bool sendCompleteQuestNotification(void) const 119 { return notificationHelper("quest", "complete"); } 79 120 80 121 private: 81 122 std::string title_; //!< The title. 82 123 std::string description_; //!< The description. 124 std::string failMessage_; //!< The message displayed when the Quest is failed. 125 std::string completeMessage_; //!< The message displayed when the Quest is completed. 126 127 bool notificationHelper(const std::string & item, const std::string & status) const; //!< Helper for sending QuestDescriptions as Notifications. 83 128 84 129 /** … … 89 134 { this->title_ = title; } 90 135 91 /**136 /** 92 137 @brief Sets the description text. 93 138 @param description The description text to be set. … … 96 141 { this->description_ = description; } 97 142 143 /** 144 @brief Sets the fail message. 145 @param message The fail message to be set. 146 */ 147 inline void setFailMessage(const std::string & message) 148 { this->failMessage_ = message; } 149 150 /** 151 @brief Sets the complete message. 152 @param message The complete message to be set. 153 */ 154 inline void setCompleteMessage(const std::string & message) 155 { this->completeMessage_ = message; } 156 98 157 }; 99 158 -
code/trunk/src/orxonox/objects/quest/QuestEffect.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestEffect.cc 31 @brief 32 Implementation of the QuestEffect class. 30 @file 31 @brief Implementation of the QuestEffect class. 33 32 */ 34 33 … … 40 39 #include "orxonox/objects/infos/PlayerInfo.h" 41 40 42 namespace orxonox {43 41 namespace orxonox 42 { 44 43 /** 45 44 @brief … … 71 70 Returns false if there was an error, view console of log for further detail. 72 71 */ 73 bool QuestEffect::invokeEffects(PlayerInfo* player, std::list<QuestEffect*> & effects)72 /*static*/ bool QuestEffect::invokeEffects(PlayerInfo* player, std::list<QuestEffect*> & effects) 74 73 { 75 74 bool check = true; 75 76 COUT(4) << "Invoking QuestEffects on player: " << player << " ." << std::endl; 76 77 77 78 for (std::list<QuestEffect*>::iterator effect = effects.begin(); effect != effects.end(); effect++) -
code/trunk/src/orxonox/objects/quest/QuestEffect.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestEffect.h 31 @brief 32 Definition of the QuestEffect class. 30 @file 31 @brief Definition of the QuestEffect class. 33 32 */ 34 33 … … 42 41 #include "core/BaseObject.h" 43 42 44 namespace orxonox {45 43 namespace orxonox 44 { 46 45 /** 47 46 @brief -
code/trunk/src/orxonox/objects/quest/QuestEffectBeacon.cc
r2262 r2662 28 28 29 29 /** 30 @file QuestEffectBeacon.cc 31 @brief 32 Implementation of the QuestEffectBeacon class. 30 @file 31 @brief Implementation of the QuestEffectBeacon class. 33 32 */ 34 33 … … 46 45 #include "QuestEffect.h" 47 46 48 namespace orxonox {49 47 namespace orxonox 48 { 50 49 CreateFactory(QuestEffectBeacon); 51 50 … … 54 53 Constructor. Registers the object and initializes defaults. 55 54 */ 56 QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator)55 QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : StaticEntity(creator) 57 56 { 58 57 RegisterObject(QuestEffectBeacon); 59 58 60 59 this->status_ = QuestEffectBeaconStatus::active; 61 this->times_ = INFINITE ;60 this->times_ = INFINITE_TIME; 62 61 } 63 62 … … 91 90 SUPER(QuestEffectBeacon, processEvent, event); 92 91 93 SetSubclassEvent(QuestEffectBeacon, "execute", execute, event, PlayerTrigger);92 SetSubclassEvent(QuestEffectBeacon, "execute", execute, event, PlayerTrigger); 94 93 } 95 94 … … 145 144 this->decrementTimes(); //!< Decrement the number of times the beacon can be used. 146 145 return true; 147 }148 149 return false;146 } 147 148 return false; 150 149 } 151 150 … … 187 186 return false; 188 187 } 189 if(this->getTimes() == INFINITE ) //!< If times is infinity the QuestEffectBeacon can be executed an infinite number fo times.188 if(this->getTimes() == INFINITE_TIME) //!< If times is infinity the QuestEffectBeacon can be executed an infinite number fo times. 190 189 { 191 190 return true; … … 193 192 194 193 this->times_ = this->times_ - 1; //!< Decrement number of times the QuestEffectBeacon can be executed. 195 if(this->getTimes() == 0) //!< Set the QuestEffectBeacon to inactive when the number of times it can be executed is reduced to 0.196 {194 if(this->getTimes() == 0) //!< Set the QuestEffectBeacon to inactive when the number of times it can be executed is reduced to 0. 195 { 197 196 this->status_ = QuestEffectBeaconStatus::inactive; 198 }197 } 199 198 200 199 return true; … … 213 212 bool QuestEffectBeacon::setTimes(const int & n) 214 213 { 215 if(n < 0 && n != INFINITE )214 if(n < 0 && n != INFINITE_TIME) 216 215 { 217 216 return false; -
code/trunk/src/orxonox/objects/quest/QuestEffectBeacon.h
r2262 r2662 28 28 29 29 /** 30 @file QuestEffectBeacon.h 31 @brief 32 Definition of the QuestEffectBeacon class. 30 @file 31 @brief Definition of the QuestEffectBeacon class. 33 32 */ 34 33 … … 38 37 #include "OrxonoxPrereqs.h" 39 38 40 #include "orxonox/objects/worldentities/ PositionableEntity.h"39 #include "orxonox/objects/worldentities/StaticEntity.h" 41 40 42 namespace QuestEffectBeaconStatus41 namespace orxonox 43 42 { 43 namespace QuestEffectBeaconStatus 44 { 44 45 45 //! The status of the beacon, can be either active or inactive.46 enum Enum47 {48 inactive,49 active50 };46 //! The status of the beacon, can be either active or inactive. 47 enum Enum 48 { 49 inactive, 50 active 51 }; 51 52 52 } 53 54 namespace orxonox { 53 } 55 54 56 55 /** … … 61 60 A QuestEffectBeacon can be inactive or active. 62 61 63 Creating a QuestEffectBeacon through XML goes as follows:64 65 <QuestEffectBeacon times=n> //Where 'n' is eighter a number >= 0, which means the QuestEffectBeacon can be executed n times. Or n = -1, which means the QuestEffectBeacon can be executed an infinite number of times.62 Creating a QuestEffectBeacon through XML goes as follows: 63 64 <QuestEffectBeacon times=n> //Where 'n' is eighter a number >= 0, which means the QuestEffectBeacon can be executed n times. Or n = -1, which means the QuestEffectBeacon can be executed an infinite number of times. 66 65 <effects> 67 66 <QuestEffect /> //A list of QuestEffects, invoked when the QuestEffectBeacon is executed, see QuestEffect for the full XML representation. … … 70 69 </effects> 71 70 <events> 72 <execute>73 <EventListener event=eventIdString />74 </execute>75 </events>76 <attached>77 <PlayerTrigger name=eventIdString /> //A PlayerTrigger triggering the execution of the QuestEffectBeacon.78 </attached>79 </QuestEffectBeacon>71 <execute> 72 <EventListener event=eventIdString /> 73 </execute> 74 </events> 75 <attached> 76 <PlayerTrigger name=eventIdString /> //A PlayerTrigger triggering the execution of the QuestEffectBeacon. 77 </attached> 78 </QuestEffectBeacon> 80 79 @author 81 80 Damian 'Mozork' Frick 82 81 */ 83 class _OrxonoxExport QuestEffectBeacon : public PositionableEntity82 class _OrxonoxExport QuestEffectBeacon : public StaticEntity 84 83 { 85 public:86 QuestEffectBeacon(BaseObject* creator);87 virtual ~QuestEffectBeacon();88 89 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestEffectBeacon object through XML.90 91 virtual void processEvent(Event& event); //!< Processes an event for this QuestEffectBeacon.92 93 bool execute(bool b, PlayerTrigger* trigger); //!< Executes the QuestEffects of the QuestEffectBeacon.94 95 /**96 @brief Tests whether the QuestEffectBeacon is active.97 @return Returns true if the QuestEffectBeacon is active, fals if not.98 */99 inline bool isActive(void)100 { return this->status_ == QuestEffectBeaconStatus::active; }101 102 bool setActive(bool activate); //!< Set the status of the QuestEffectBeacon.103 104 protected:84 public: 85 QuestEffectBeacon(BaseObject* creator); 86 virtual ~QuestEffectBeacon(); 87 88 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestEffectBeacon object through XML. 89 90 virtual void processEvent(Event& event); //!< Processes an event for this QuestEffectBeacon. 91 92 bool execute(bool b, PlayerTrigger* trigger); //!< Executes the QuestEffects of the QuestEffectBeacon. 93 94 /** 95 @brief Tests whether the QuestEffectBeacon is active. 96 @return Returns true if the QuestEffectBeacon is active, fals if not. 97 */ 98 inline bool isActive(void) 99 { return this->status_ == QuestEffectBeaconStatus::active; } 100 101 bool setActive(bool activate); //!< Set the status of the QuestEffectBeacon. 102 103 protected: 105 104 bool decrementTimes(void); //!< Decrement the number of times the QuestEffectBeacon can still be executed. 106 105 … … 111 110 inline const int & getTimes(void) const 112 111 { return this->times_; } 113 112 114 113 private: 115 static const int INFINITE = -1; //!< Constant to avoid using magic numbers.116 114 static const int INFINITE_TIME = -1; //!< Constant to avoid using magic numbers. 115 117 116 std::list<QuestEffect*> effects_; //!< The list of QuestEffects to be invoked on the executing player. 118 117 int times_; //!< Number of times the beacon can be exectued. -
code/trunk/src/orxonox/objects/quest/QuestHint.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestHint.cc 31 @brief 32 Implementation of the QuestHint class. 30 @file 31 @brief Implementation of the QuestHint class. 33 32 */ 34 33 … … 41 40 #include "orxonox/objects/infos/PlayerInfo.h" 42 41 #include "QuestManager.h" 42 #include "QuestDescription.h" 43 43 #include "Quest.h" 44 44 45 namespace orxonox {46 45 namespace orxonox 46 { 47 47 CreateFactory(QuestHint); 48 48 … … 122 122 { 123 123 this->playerStatus_[player] = questHintStatus::active; 124 125 this->getDescription()->sendAddHintNotification(); 124 126 return true; 125 127 } -
code/trunk/src/orxonox/objects/quest/QuestHint.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestHint.h 31 @brief 32 Definition of the QuestHint class. 30 @file 31 @brief Definition of the QuestHint class. 33 32 */ 34 33 … … 44 43 #include "QuestItem.h" 45 44 46 namespace questHintStatus47 {48 49 //! The status of the hint.50 enum Enum51 {52 inactive,53 active54 };55 56 }57 58 45 namespace orxonox 59 46 { 47 namespace questHintStatus 48 { 49 50 //! The state of the hint. 51 enum Enum 52 { 53 inactive, 54 active 55 }; 56 57 } 60 58 61 59 /** … … 96 94 private: 97 95 Quest* quest_; //!< The Quest the QuestHint belongs to. 98 std::map<const PlayerInfo*, questHintStatus::Enum> playerStatus_; //!< List of the stat us for each player, with the Player-pointer as key.96 std::map<const PlayerInfo*, questHintStatus::Enum> playerStatus_; //!< List of the states for each player, with the Player-pointer as key. 99 97 100 98 }; -
code/trunk/src/orxonox/objects/quest/QuestItem.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestItem.cc 31 @brief 32 Implementation of the QuestItem class. 30 @file 31 @brief Implementation of the QuestItem class. 33 32 */ 34 33 … … 40 39 #include "QuestDescription.h" 41 40 42 namespace orxonox {43 41 namespace orxonox 42 { 44 43 /** 45 44 @brief … … 99 98 @return 100 99 Returns true if the string is likely to be of the required form. 101 @todo102 Clarify form, more vigorous checks.103 100 */ 104 bool QuestItem::isId(const std::string & id)101 /*static*/ bool QuestItem::isId(const std::string & id) 105 102 { 106 103 return id.size() >= 32; -
code/trunk/src/orxonox/objects/quest/QuestItem.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestItem.h 31 @brief 32 Definition of the QuestItem class. 33 34 The QuestItem is the parent class of Quest and QuestHint. 30 @file 31 @brief Definition of the QuestItem class. 32 The QuestItem is the parent class of Quest and QuestHint. 35 33 */ 36 34 … … 46 44 #include "core/XMLPort.h" 47 45 48 namespace orxonox { 49 50 46 namespace orxonox 47 { 51 48 /** 52 49 @brief … … 67 64 /** 68 65 @brief Returns the id of this QuestItem. 69 @return Returns the id of the QuestItem.66 @return Returns the id of the QuestItem. 70 67 */ 71 68 inline const std::string & getId(void) const 72 69 { return this->id_; } 73 /** 74 @brief Returns the QuestDescription of the QuestItem. 75 @return Returns a pointer to the QuestDescription object of the QuestItem. 76 */ 70 71 /** 72 @brief Returns the QuestDescription of the QuestItem. 73 @return Returns a pointer to the QuestDescription object of the QuestItem. 74 */ 77 75 inline const QuestDescription* getDescription(void) const 78 76 { return this->description_; } -
code/trunk/src/orxonox/objects/quest/QuestManager.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestManager.cc 31 @brief 32 Implementation of the QuestManager class. 30 @file 31 @brief Implementation of the QuestManager class. 33 32 */ 34 33 … … 42 41 #include "QuestHint.h" 43 42 44 namespace orxonox {45 43 namespace orxonox 44 { 46 45 //! All Quests registered by their id's. 47 46 std::map<std::string, Quest*> QuestManager::questMap_s; … … 76 75 Returns true if successful, false if not. 77 76 */ 78 bool QuestManager::registerQuest(Quest* quest)77 /*static*/ bool QuestManager::registerQuest(Quest* quest) 79 78 { 80 79 if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers. … … 108 107 Returns true if successful, false if not. 109 108 */ 110 bool QuestManager::registerHint(QuestHint* hint)109 /*static*/ bool QuestManager::registerHint(QuestHint* hint) 111 110 { 112 111 if(hint == NULL) //!< Still not liking NULL-pointers. … … 142 141 Throws an exception if the given questId is invalid. 143 142 */ 144 Quest* QuestManager::findQuest(const std::string & questId)143 /*static*/ Quest* QuestManager::findQuest(const std::string & questId) 145 144 { 146 145 if(!QuestItem::isId(questId)) //!< Check vor validity of the given id. … … 176 175 Throws an exception if the given hintId is invalid. 177 176 */ 178 QuestHint* QuestManager::findHint(const std::string & hintId)177 /*static*/ QuestHint* QuestManager::findHint(const std::string & hintId) 179 178 { 180 179 if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id. -
code/trunk/src/orxonox/objects/quest/QuestManager.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file QuestManager.h 31 @brief 32 Definition of the QuestManager class. 30 @file 31 @brief Definition of the QuestManager class. 33 32 */ 34 33 … … 43 42 #include "core/BaseObject.h" 44 43 45 namespace orxonox {46 44 namespace orxonox 45 { 47 46 /** 48 47 @brief -
code/trunk/src/orxonox/objects/quest/Rewardable.cc
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file Rewardable.cc 31 @brief 32 Implementation of the Rewardable class. 30 @file 31 @brief Implementation of the Rewardable class. 33 32 */ 34 33 … … 38 37 #include "core/CoreIncludes.h" 39 38 40 namespace orxonox {41 39 namespace orxonox 40 { 42 41 /** 43 42 @brief -
code/trunk/src/orxonox/objects/quest/Rewardable.h
- Property svn:mergeinfo changed
r2261 r2662 28 28 29 29 /** 30 @file Rewardable.h 31 @brief 32 Definition of the Rewardable class. 30 @file 31 @brief Definition of the Rewardable class. 33 32 */ 34 33 … … 40 39 #include "core/BaseObject.h" 41 40 42 namespace orxonox {43 41 namespace orxonox 42 { 44 43 /** 45 44 @brief … … 52 51 class _OrxonoxExport Rewardable : public BaseObject 53 52 { 54 55 53 public: 56 54 Rewardable(BaseObject* creator); … … 61 59 Method to transcribe a rewardable object to the player. 62 60 Must be implemented by every class inheriting from Rewardable. 63 @param player61 @param player 64 62 A pointer to the ControllableEntity, do whatever you want with it. 65 @return63 @return 66 64 Return true if successful. 67 65 */ 68 virtual bool reward(PlayerInfo* player) = 0; //!<66 virtual bool reward(PlayerInfo* player) = 0; 69 67 70 68 }; -
code/trunk/src/orxonox/objects/weaponSystem/CMakeLists.txt
r2131 r2662 2 2 Munition.cc 3 3 Weapon.cc 4 WeaponPack.cc 4 5 WeaponSet.cc 5 6 WeaponSlot.cc … … 7 8 ) 8 9 9 #ADD_SOURCE_DIRECTORY(SRC_FILES munitions)10 #ADD_SOURCE_DIRECTORY(SRC_FILES projectiles)11 #ADD_SOURCE_DIRECTORY(SRC_FILES weapons)10 ADD_SOURCE_DIRECTORY(SRC_FILES munitions) 11 ADD_SOURCE_DIRECTORY(SRC_FILES projectiles) 12 ADD_SOURCE_DIRECTORY(SRC_FILES weapons) 12 13 13 14 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/objects/weaponSystem/Munition.cc
r2097 r2662 37 37 namespace orxonox 38 38 { 39 CreateFactory(Munition); 40 39 41 Munition::Munition(BaseObject* creator) : BaseObject(creator) 40 42 { … … 46 48 } 47 49 50 unsigned int Munition::bullets() 51 { 52 if (this->bullets_ > 0) 53 return bullets_; 54 else 55 return 0; 56 } 57 58 unsigned int Munition::magazines() 59 { 60 if (this->magazines_ > 0) 61 return magazines_; 62 else 63 return 0; 64 } 65 66 void Munition::setMaxBullets(unsigned int amount) 67 { this->maxBullets_ = amount; } 68 69 void Munition::setMaxMagazines(unsigned int amount) 70 { this->maxMagazines_ = amount; } 71 72 void Munition::removeBullets(unsigned int amount) 73 { 74 if ( this->bullets_ != 0 ) 75 this->bullets_ = this->bullets_ - amount; 76 } 77 78 void Munition::removeMagazines(unsigned int amount) 79 { 80 if ( this->magazines_ != 0 ) 81 this->magazines_ = this->magazines_ - amount; 82 } 83 84 void Munition::addBullets(unsigned int amount) 85 { 86 if ( this->bullets_ == this->maxBullets_ ) 87 { 88 //cannot add bullets to actual magazine 89 } 90 else 91 this->bullets_ = this->bullets_ + amount; 92 } 93 94 void Munition::addMagazines(unsigned int amount) 95 { 96 if ( this->magazines_ == this->maxMagazines_ ) 97 { 98 //no more capacity for another magazine 99 } 100 else 101 this->magazines_ = this->magazines_ + amount; 102 } 103 104 105 void Munition::fillBullets() 106 { 107 //COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl; 108 this->bullets_ = this->maxBullets_; 109 } 110 111 void Munition::fillMagazines() 112 { 113 this->magazines_ = this->maxMagazines_; 114 } 115 48 116 void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode) 49 117 { 50 118 SUPER(Munition, XMLPort, xmlelement, mode); 51 119 } 52 120 -
code/trunk/src/orxonox/objects/weaponSystem/Munition.h
r2106 r2662 34 34 #include "core/BaseObject.h" 35 35 36 #include "Weapon.h" 37 36 38 37 39 namespace orxonox … … 45 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 48 49 void setMaxBullets(unsigned int amount); 50 void setMaxMagazines(unsigned int amount); 51 52 void fillBullets(); 53 void fillMagazines(); 54 55 unsigned int bullets(); 56 unsigned int magazines(); 57 58 void removeBullets(unsigned int k); 59 void removeMagazines(unsigned int k); 60 void addBullets(unsigned int k); 61 void addMagazines(unsigned int k); 47 62 48 63 private: 49 64 50 65 protected: 66 unsigned int bullets_; 67 unsigned int magazines_; 68 unsigned int maxBullets_; 69 unsigned int maxMagazines_; 51 70 }; 52 71 } -
code/trunk/src/orxonox/objects/weaponSystem/Weapon.cc
r2098 r2662 37 37 namespace orxonox 38 38 { 39 Weapon::Weapon(BaseObject* creator) : BaseObject(creator) 39 CreateFactory(Weapon); 40 41 Weapon::Weapon(BaseObject* creator) : StaticEntity(creator) 40 42 { 41 43 RegisterObject(Weapon); 44 this->bulletReadyToShoot_ = true; 45 this->magazineReadyToShoot_ = true; 46 this->parentWeaponSystem_ = 0; 47 this->attachedToWeaponSlot_ = 0; 48 this->munition_ = 0; 49 this->bulletLoadingTime_ = 0; 50 this->magazineLoadingTime_ = 0; 51 this->bReloading_ = false; 42 52 43 this->loadingTime_ = 0; 44 this->munition_ = 0; 45 53 this->setObjectMode(0x0); 46 54 } 47 55 … … 50 58 } 51 59 52 void Weapon::addMunition() 60 61 void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) 53 62 { 63 SUPER(Weapon, XMLPort, xmlelement, mode); 64 XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode); 65 XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode); 66 XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode); 67 } 68 69 void Weapon::setWeapon() 70 { 71 this->munition_->fillBullets(); 72 this->munition_->fillMagazines(); 73 } 74 75 76 void Weapon::fire() 77 { 78 //COUT(0) << "LaserGun::fire, this=" << this << std::endl; 79 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_) 80 { 81 //COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; 82 //COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl; 83 this->bulletReadyToShoot_ = false; 84 if ( this->munition_->bullets() > 0) 85 { 86 //shoot 87 this->takeBullets(); 88 this->createProjectile(); 89 } 90 //if there are no bullets, but magazines 91 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 ) 92 { 93 //COUT(0) << "LaserGun::fire - no bullets" << std::endl; 94 this->takeMagazines(); 95 } 96 else 97 { 98 //COUT(0) << "LaserGun::fire - no magazines" << std::endl; 99 //actions 100 } 101 } 102 else 103 { 104 //COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl; 105 //actions 106 } 54 107 55 108 } 56 109 57 void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) 110 111 void Weapon::bulletTimer(float bulletLoadingTime) 58 112 { 59 113 //COUT(0) << "Weapon::bulletTimer started" << std::endl; 114 this->bReloading_ = true; 115 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); 116 } 117 void Weapon::magazineTimer(float magazineLoadingTime) 118 { 119 //COUT(0) << "Weapon::magazineTimer started" << std::endl; 120 this->bReloading_ = true; 121 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); 60 122 } 61 123 62 void Weapon:: fire()124 void Weapon::bulletReloaded() 63 125 { 126 this->bReloading_ = false; 127 this->bulletReadyToShoot_ = true; 128 } 64 129 130 void Weapon::magazineReloaded() 131 { 132 this->bReloading_ = false; 133 this->munition_->fillBullets(); 134 this->magazineReadyToShoot_ = true; 135 this->bulletReadyToShoot_ = true; 65 136 } 137 138 139 void Weapon::attachNeededMunition(std::string munitionName) 140 { 141 //COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl; 142 //if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem 143 if (this->parentWeaponSystem_) 144 { 145 //COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl; 146 Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); 147 if ( munition ) 148 this->munition_ = munition; 149 else 150 { 151 //create new munition with identifier 152 //COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl; 153 this->munitionIdentifier_ = ClassByString(munitionName); 154 this->munition_ = this->munitionIdentifier_.fabricate(this); 155 this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); 156 } 157 } 158 } 159 160 161 /*get and set functions 162 * 163 */ 164 165 void Weapon::setMunitionType(std::string munitionType) 166 { this->munitionType_ = munitionType; } 167 168 const std::string Weapon::getMunitionType() 169 { return this->munitionType_; } 170 171 void Weapon::setBulletLoadingTime(float loadingTime) 172 { this->bulletLoadingTime_ = loadingTime; } 173 174 const float Weapon::getBulletLoadingTime() 175 { return this->bulletLoadingTime_; } 176 177 void Weapon::setMagazineLoadingTime(float loadingTime) 178 { this->magazineLoadingTime_ = loadingTime; } 179 180 const float Weapon::getMagazineLoadingTime() 181 { return this->magazineLoadingTime_; } 182 183 184 Munition * Weapon::getAttachedMunition(std::string munitionType) 185 { 186 //COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl; 187 this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); 188 //COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl; 189 return this->munition_; 190 } 191 192 void Weapon::takeBullets() { }; 193 void Weapon::createProjectile() { }; 194 void Weapon::takeMagazines() { }; 195 66 196 } -
code/trunk/src/orxonox/objects/weaponSystem/Weapon.h
r2106 r2662 33 33 34 34 #include "core/BaseObject.h" 35 #include "tools/BillboardSet.h" 36 #include "tools/Timer.h" 37 #include "core/Identifier.h" 35 38 39 #include "WeaponSystem.h" 40 #include "Munition.h" 41 42 #include "objects/worldentities/StaticEntity.h" 36 43 37 44 namespace orxonox 38 45 { 39 class _OrxonoxExport Weapon : public BaseObject46 class _OrxonoxExport Weapon : public StaticEntity 40 47 { 41 48 public: … … 45 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 53 47 void addMunition();48 54 virtual void fire(); 55 void attachNeededMunition(std::string munitionType); 56 Munition * getAttachedMunition(std::string munitiontype); 57 58 //reloading 59 void bulletTimer(float bulletLoadingTime); 60 void magazineTimer(float magazineLoadingTime); 61 void bulletReloaded(); 62 void magazineReloaded(); 63 64 virtual void setMunitionType(std::string munitionType); 65 virtual const std::string getMunitionType(); 66 virtual void setBulletLoadingTime(float loadingTime); 67 virtual const float getBulletLoadingTime(); 68 virtual void setMagazineLoadingTime(float loadingTime); 69 virtual const float getMagazineLoadingTime(); 70 71 virtual void takeBullets(); 72 virtual void takeMagazines(); 73 virtual void createProjectile(); 74 75 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) 76 { this->parentWeaponSystem_=parentWeaponSystem; }; 77 inline WeaponSystem * getParentWeaponSystem() 78 { return this->parentWeaponSystem_; }; 79 80 inline void setAttachedToWeaponSlot(WeaponSlot * wSlot) 81 { this->attachedToWeaponSlot_ = wSlot; } 82 inline WeaponSlot * getAttachedToWeaponSlot() 83 { return this->attachedToWeaponSlot_; } 84 85 virtual void setWeapon(); 49 86 50 87 private: 51 int loadingTime_;52 Munition *munition_;53 88 89 protected: 90 bool bReloading_; 91 bool bulletReadyToShoot_; 92 bool magazineReadyToShoot_; 93 float bulletLoadingTime_; 94 float magazineLoadingTime_; 95 std::string munitionType_; 54 96 97 WeaponSlot * attachedToWeaponSlot_; 98 Munition * munition_; 99 WeaponSystem * parentWeaponSystem_; 55 100 101 SubclassIdentifier<Munition> munitionIdentifier_; 102 103 Timer<Weapon> bulletReloadTimer_; 104 Timer<Weapon> magazineReloadTimer_; 56 105 }; 57 106 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2098 r2662 33 33 #include "core/XMLPort.h" 34 34 #include "util/Debug.h" 35 #include "objects/worldentities/pawns/Pawn.h" 35 36 36 37 #include "WeaponSet.h" 38 #include "WeaponPack.h" 37 39 38 40 namespace orxonox 39 41 { 42 CreateFactory(WeaponSet); 43 40 44 WeaponSet::WeaponSet(BaseObject* creator, int k) : BaseObject(creator) 41 45 { … … 43 47 44 48 this->parentWeaponSystem_ = 0; 45 46 for (int i=0;i<k;i++) 47 { 48 attachWeaponSlot(new WeaponSlot(this)); 49 } 49 this->attachedWeaponPack_ = 0; 50 50 } 51 51 … … 54 54 } 55 55 56 //Vorwärtsdeklaration 57 WeaponSystem * parentWeaponSystem_; 56 void WeaponSet::attachWeaponPack(WeaponPack *wPack) 57 { 58 //COUT(0) << "WeaponSet::attachWeaponPack" << std::endl; 59 //COUT(0) << "........ parentWeaponSystem_=" << this->parentWeaponSystem_ << std::endl; 60 //COUT(0) << "........ this->parentWeaponSystem_->getWeaponSlotSize()" << this->parentWeaponSystem_->getWeaponSlotSize() << std::endl; 61 //COUT(0) << "........ wPack->getSize()" << wPack->getSize() << std::endl; 62 if ( this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) ) 63 { 64 //COUT(0) << "WeaponSet::attachWeaponPack after if" << std::endl; 65 this->attachedWeaponPack_ = wPack; 66 int wPackWeapon = 0; //WeaponCounter for Attaching 67 //should be possible to choose which slot to use 68 for ( int i=0; i < wPack->getSize() ; i++ ) 69 { 70 //at the moment this function only works for one weaponPack in the entire WeaponSystem... 71 if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 && this->parentWeaponSystem_->getWeaponSlotPointer(i) != 0) //if slot not full 72 { 73 //COUT(0) << "WeaponSet::attachWeaponPack attaching Weapon" << std::endl; 74 this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) ); 75 this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); 76 this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) ); 77 wPackWeapon++; 78 } 79 else 80 { 81 for (int k=0; k < this->parentWeaponSystem_->getWeaponSlotSize(); k++) 82 { 83 if ( this->parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 ) 84 { 85 //COUT(0) << "WeaponSet::attachWeaponPack mode 2 k="<< k << std::endl; 86 this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(k) ); 87 this->parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) ); 88 this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) ); 89 wPackWeapon++; 90 } 91 } 92 } 93 } 94 } 95 } 58 96 59 void WeaponSet::attachWeaponSlot(WeaponSlot *wSlot)60 {61 this->weaponSlots_.push_back(wSlot);62 }63 97 64 98 void WeaponSet::fire() 65 99 { 66 for (int i=0; i < (int) this->weaponSlots_.size(); i++)67 { 68 this->weaponSlots_[i]->fire();69 }100 //fires all WeaponSlots available for this weaponSet attached from the WeaponPack 101 //COUT(0) << "WeaponSet::fire from Pack: " << this->attachedWeaponPack_ << std::endl; 102 if (this->attachedWeaponPack_) 103 this->attachedWeaponPack_->fire(); 70 104 } 71 105 72 WeaponSlot * WeaponSet::getWeaponSlotPointer(unsigned int n) 73 { 74 if (n < this->weaponSlots_.size()) 75 return this->weaponSlots_[n]; 76 else 77 return 0; 78 } 106 void WeaponSet::setFireMode(const unsigned int firemode) 107 { this->firemode_ = firemode; } 79 108 109 const unsigned int WeaponSet::getFireMode() const 110 { return this->firemode_; } 80 111 81 112 void WeaponSet::XMLPort(Element& xmlelement, XMLPort::Mode mode) 82 113 { 83 114 SUPER(WeaponSet, XMLPort, xmlelement, mode); 115 XMLPortParam(WeaponSet, "firemode", setFireMode, getFireMode, xmlelement, mode); 84 116 } 85 117 -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSet.h
r2106 r2662 48 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 49 50 void attachWeapon Slot(WeaponSlot *wSlot);50 void attachWeaponPack(WeaponPack *wPack); 51 51 void fire(); 52 WeaponSlot * getWeaponSlotPointer(unsigned int n); 52 53 void setFireMode(const unsigned int firemode); 54 const unsigned int getFireMode() const; 53 55 54 56 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) … … 58 60 59 61 private: 60 std::vector<WeaponSlot *> weaponSlots_;61 62 WeaponSystem *parentWeaponSystem_; 63 std::vector<WeaponSlot *> setWeaponSlots_; 64 unsigned int firemode_; 65 WeaponPack * attachedWeaponPack_; 62 66 }; 63 67 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSlot.cc
r2098 r2662 36 36 37 37 38 39 38 namespace orxonox 40 39 { 41 WeaponSlot::WeaponSlot(BaseObject* creator) : BaseObject(creator) 40 CreateFactory(WeaponSlot); 41 42 WeaponSlot::WeaponSlot(BaseObject* creator) : StaticEntity(creator) 42 43 { 43 44 RegisterObject(WeaponSlot); 44 45 45 46 this->unlimitedAmmo_ = false; 46 47 47 this->attachedWeapon_ = 0; 48 this-> parentWeaponSet_ = 0;48 this->setObjectMode(0x0); 49 49 } 50 50 … … 53 53 } 54 54 55 void WeaponSlot::attachWeapon(Weapon *weaponName)56 {57 58 }59 55 60 56 /*sets the munition type … … 67 63 } 68 64 65 69 66 void WeaponSlot::fire() 70 67 { 68 if ( this->attachedWeapon_ ) 69 //COUT(0) << "WeaponSlot::fire" << std::endl; 70 this->attachedWeapon_->fire(); 71 } 71 72 72 }73 73 74 74 void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode) 75 75 { 76 SUPER(WeaponSlot, XMLPort, xmlelement, mode); 77 } 76 78 79 void WeaponSlot::attachWeapon(Weapon *weapon) 80 { 81 this->attachedWeapon_ = weapon; 82 weapon->setAttachedToWeaponSlot(this); 83 //COUT(0) << "WeaponSlot::attachWeapon position=" << this->getWorldPosition() << std::endl; 84 weapon->setPosition(this->getPosition()); 85 } 86 87 Weapon * WeaponSlot::getAttachedWeapon() const 88 { 89 return this->attachedWeapon_; 77 90 } 78 91 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSlot.h
r2106 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "core/BaseObject.h"35 36 37 34 #include "Weapon.h" 38 35 #include "objects/worldentities/StaticEntity.h" 39 36 40 37 namespace orxonox 41 38 { 42 class _OrxonoxExport WeaponSlot : public BaseObject39 class _OrxonoxExport WeaponSlot : public StaticEntity 43 40 { 44 41 public: … … 48 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 46 50 void attachWeapon(Weapon *weaponName); 47 void attachWeapon(Weapon *weapon); 48 Weapon * getAttachedWeapon() const; 51 49 void setAmmoType(bool isUnlimited); 52 50 void fire(); 53 51 54 inline void setParentWeaponSet(WeaponSet *parentWeaponSet) 55 { parentWeaponSet_=parentWeaponSet; } 56 inline WeaponSet * getParentWeaponSet() 57 { return parentWeaponSet_; } 58 52 inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem) 53 { parentWeaponSystem_=parentWeaponSystem; } 54 inline WeaponSystem * getParentWeaponSystem() 55 { return parentWeaponSystem_; } 59 56 60 57 … … 63 60 bool unlimitedAmmo_; 64 61 65 WeaponS et *parentWeaponSet_;62 WeaponSystem *parentWeaponSystem_; 66 63 }; 67 64 } -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.cc
- Property svn:mergeinfo changed
r2261 r2662 37 37 #include "WeaponSystem.h" 38 38 39 39 40 /* WEAPONSYSTEM 40 41 * creates the WeaponSystem and the ability to use weapons and munition … … 45 46 namespace orxonox 46 47 { 48 CreateFactory(WeaponSystem); 49 47 50 WeaponSystem::WeaponSystem(BaseObject* creator) : BaseObject(creator) 48 51 { … … 50 53 51 54 this->activeWeaponSet_ = 0; 52 this->parent SpaceShip_ = 0;55 this->parentPawn_ = 0; 53 56 } 54 57 … … 57 60 } 58 61 59 //creates empty weaponSet 62 void WeaponSystem::attachWeaponPack(WeaponPack *wPack, unsigned int firemode) 63 { 64 if (firemode < this->weaponSets_.size()) 65 this->weaponSets_[firemode]->attachWeaponPack(wPack); 66 this->weaponPacks_.push_back(wPack); 67 } 68 69 void WeaponSystem::attachWeaponSlot(WeaponSlot *wSlot) 70 { 71 wSlot->setParentWeaponSystem(this); 72 this->weaponSlots_.push_back(wSlot); 73 } 74 60 75 void WeaponSystem::attachWeaponSet(WeaponSet *wSet) 61 76 { 77 wSet->setParentWeaponSystem(this); 62 78 this->weaponSets_.push_back(wSet); 63 wSet->setParentWeaponSystem(this);64 79 } 65 80 81 void WeaponSystem::setNewMunition(std::string munitionType, Munition * munitionToAdd) 82 { 83 this->munitionSet_[munitionType] = munitionToAdd; 84 } 85 86 //returns the Pointer to the munitionType 87 Munition * WeaponSystem::getMunitionType(std::string munitionType) 88 { 89 //COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl; 90 std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType); 91 if (it != this->munitionSet_.end()) 92 return it->second; 93 else 94 return 0; 95 } 96 97 98 /* 66 99 //the first weaponSet is at n=0 67 100 void WeaponSystem::setActiveWeaponSet(unsigned int n) … … 69 102 if (n < this->weaponSets_.size()) 70 103 this->activeWeaponSet_ = this->weaponSets_[n]; 104 else 105 this->activeWeaponSet_ = this->weaponSets_[0]; 106 } 107 */ 108 109 110 //n is the n'th weaponSet, starting with zero 111 //SpaceShip.cc only needs to have the keybinding to a specific Set-number n 112 void WeaponSystem::fire(WeaponMode::Enum n) 113 { 114 int set = 0; 115 switch (n) 116 { 117 case WeaponMode::fire: 118 set = 0; 119 break; 120 case WeaponMode::altFire: 121 set = 1; 122 break; 123 case WeaponMode::altFire2: 124 set = 2; 125 break; 126 } 127 //COUT(0) << "WeaponSystem::fire" << std::endl; 128 if (set < (int)this->weaponSets_.size()) 129 //COUT(0) << "WeaponSystem::fire - after if" << std::endl; 130 this->weaponSets_[set]->fire(); 71 131 } 72 132 73 //n is the n'th weaponSet, starting with zero74 //Spaceship.cc only needs to have the keybinding to a specific Set-number n75 void WeaponSystem::fire(unsigned int n)76 {77 if (n < this->weaponSets_.size())78 this->weaponSets_[n]->fire();79 }80 81 void WeaponSystem::fire()82 {83 if (this->activeWeaponSet_)84 this->activeWeaponSet_->fire();85 }86 133 87 134 WeaponSet * WeaponSystem::getWeaponSetPointer(unsigned int n) … … 93 140 } 94 141 142 WeaponSlot * WeaponSystem::getWeaponSlotPointer(unsigned int n) 143 { 144 if (n < this->weaponSlots_.size()) 145 return this->weaponSlots_[n]; 146 else 147 return 0; 148 } 149 150 WeaponPack * WeaponSystem::getWeaponPackPointer(unsigned int n) 151 { 152 if (n < this->weaponPacks_.size()) 153 return this->weaponPacks_[n]; 154 else 155 return 0; 156 } 157 95 158 void WeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode) 96 159 { 97 160 SUPER(WeaponSystem, XMLPort, xmlelement, mode); 98 161 } 99 162 -
code/trunk/src/orxonox/objects/weaponSystem/WeaponSystem.h
- Property svn:mergeinfo changed
r2261 r2662 36 36 37 37 #include "WeaponSet.h" 38 #include "WeaponPack.h" 38 39 39 40 namespace orxonox 40 41 { 42 41 43 class _OrxonoxExport WeaponSystem : public BaseObject 42 44 { … … 47 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 50 51 void attachWeaponSlot(WeaponSlot *wSlot); 49 52 void attachWeaponSet(WeaponSet *wSet); 50 void fire(); 51 void fire(unsigned int n); 52 void setActiveWeaponSet(unsigned int n); 53 //void fire(); 54 void fire(WeaponMode::Enum fireMode); 55 //void setActiveWeaponSet(unsigned int n); 56 void attachWeaponPack(WeaponPack * wPack, unsigned int firemode); 53 57 WeaponSet * getWeaponSetPointer(unsigned int n); 58 WeaponSlot * getWeaponSlotPointer(unsigned int n); 59 WeaponPack * getWeaponPackPointer(unsigned int n); 60 void setNewMunition(std::string munitionType, Munition * munitionToAdd); 61 Munition * getMunitionType(std::string munitionType); 54 62 55 inline void setParent SpaceShip(SpaceShip *parentSpaceShip)56 { parent SpaceShip_=parentSpaceShip; }57 inline SpaceShip * getParentSpaceShip()58 { return parent SpaceShip_; }63 inline void setParentPawn(Pawn *parentPawn) 64 { parentPawn_=parentPawn; } 65 inline Pawn * getParentPawn() 66 { return parentPawn_; } 59 67 68 inline int getWeaponSlotSize() 69 { return this->weaponSlots_.size(); } 60 70 61 71 private: 62 72 std::vector<WeaponSet *> weaponSets_; 73 std::vector<WeaponSlot *> weaponSlots_; 74 std::vector<WeaponPack *> weaponPacks_; 75 std::map<std::string, Munition *> munitionSet_; 63 76 WeaponSet *activeWeaponSet_; 64 65 SpaceShip *parentSpaceShip_; 77 Pawn *parentPawn_; 66 78 }; 67 79 } -
code/trunk/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc
r2097 r2662 37 37 namespace orxonox 38 38 { 39 LaserGunMunition::LaserGunMunition(BaseObject* creator) : BaseObject(creator) 39 CreateFactory(LaserGunMunition); 40 41 LaserGunMunition::LaserGunMunition(BaseObject* creator) : Munition(creator) 40 42 { 41 43 RegisterObject(LaserGunMunition); 44 45 this->maxBullets_ = 40; 46 this->maxMagazines_ = 100; 42 47 } 43 48 -
code/trunk/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h
r2106 r2662 33 33 34 34 #include "core/BaseObject.h" 35 35 #include "../Munition.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport LaserGunMunition : public BaseObject39 class _OrxonoxExport LaserGunMunition : public Munition 40 40 { 41 41 public: … … 47 47 48 48 private: 49 int bullets_;50 int magazines_;51 int maxBullets_;52 int maxMagazines_;53 49 54 50 -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc
r2099 r2662 30 30 #include "BillboardProjectile.h" 31 31 32 #include <OgreBillboard .h>32 #include <OgreBillboardSet.h> 33 33 34 #include "core/Core.h" 34 35 #include "core/CoreIncludes.h" 36 #include "objects/Scene.h" 35 37 36 38 namespace orxonox … … 38 40 CreateFactory(BillboardProjectile); 39 41 40 BillboardProjectile::BillboardProjectile(BaseObject* creator , Weapon* owner) : Projectile(creator, owner)42 BillboardProjectile::BillboardProjectile(BaseObject* creator) : Projectile(creator) 41 43 { 42 44 RegisterObject(BillboardProjectile); 43 45 44 this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); 45 this->attachObject(this->billboard_.getBillboardSet()); 46 this->scale(0.5); 46 if (Core::showsGraphics()) 47 { 48 assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity 49 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5, 0.5, 0.7, 0.8), 1); 50 this->attachOgreObject(this->billboard_.getBillboardSet()); 51 } 52 53 this->setScale(0.2); 47 54 } 48 55 49 56 BillboardProjectile::~BillboardProjectile() 50 57 { 51 if (this->isInitialized() && this->owner_)52 this->detachO bject(this->billboard_.getBillboardSet());58 if (this->isInitialized() && Core::showsGraphics() && this->billboard_.getBillboardSet()) 59 this->detachOgreObject(this->billboard_.getBillboardSet()); 53 60 } 54 61 55 62 void BillboardProjectile::setColour(const ColourValue& colour) 56 63 { 57 this->billboard_. getBillboardSet()->getBillboard(0)->setColour(colour);64 this->billboard_.setColour(colour); 58 65 } 59 66 … … 61 68 { 62 69 SUPER(BillboardProjectile, changedVisibility); 70 63 71 this->billboard_.setVisible(this->isVisible()); 64 72 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.h
r2099 r2662 41 41 { 42 42 public: 43 BillboardProjectile(BaseObject* creator , Weapon* owner = 0);43 BillboardProjectile(BaseObject* creator); 44 44 virtual ~BillboardProjectile(); 45 45 -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc
r2099 r2662 30 30 #include "ParticleProjectile.h" 31 31 32 #include "SpaceShip.h" 32 #include <OgreParticleSystem.h> 33 #include <OgreParticleEmitter.h> 34 35 #include "core/Core.h" 33 36 #include "core/CoreIncludes.h" 34 37 #include "core/ConfigValueIncludes.h" 38 #include "objects/Scene.h" 35 39 36 40 namespace orxonox … … 38 42 CreateFactory(ParticleProjectile); 39 43 40 ParticleProjectile::ParticleProjectile(BaseObject* creator , Weapon* owner) : BillboardProjectile(creator, owner)44 ParticleProjectile::ParticleProjectile(BaseObject* creator) : BillboardProjectile(creator) 41 45 { 42 46 RegisterObject(ParticleProjectile); 43 47 44 this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal); 45 this->particles_->addToSceneNode(this->getNode()); 46 this->particles_->setKeepParticlesInLocalSpace(true); 47 if (this->owner_) 48 if (Core::showsGraphics()) 48 49 { 50 this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::normal); 51 this->attachOgreObject(this->particles_->getParticleSystem()); 52 this->particles_->setKeepParticlesInLocalSpace(0); 53 54 this->particles_->getAllEmitters()->setDirection(-WorldEntity::FRONT); 49 55 } 50 // else 51 // { 52 // this->particles_ = 0; 53 // } 54 55 this->setConfigValues(); 56 else 57 this->particles_ = 0; 56 58 } 57 59 … … 59 61 { 60 62 if (this->isInitialized() && this->particles_) 63 { 64 this->detachOgreObject(this->particles_->getParticleSystem()); 61 65 delete this->particles_; 62 } 63 64 void ParticleProjectile::setConfigValues() 65 { 66 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback((Projectile*)this, &ParticleProjectile::speedChanged); 66 } 67 67 } 68 68 … … 70 70 { 71 71 SUPER(ParticleProjectile, changedVisibility); 72 this->particles_->setEnabled(this->isVisible());73 }74 72 75 bool ParticleProjectile::create(){ 76 if(!Projectile::create()) 77 return false; 78 this->particles_->getAllEmitters()->setDirection(-this->getOrientation()*Vector3(1,0,0)); 79 return true; 73 if (this->particles_) 74 this->particles_->setEnabled(this->isVisible()); 80 75 } 81 76 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.h
r2099 r2662 41 41 { 42 42 public: 43 ParticleProjectile(BaseObject* creator , Weapon* owner = 0);43 ParticleProjectile(BaseObject* creator); 44 44 virtual ~ParticleProjectile(); 45 45 virtual void changedVisibility(); 46 void setConfigValues();47 48 virtual bool create();49 46 50 47 private: -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc
r2100 r2662 40 40 #include "objects/worldentities/Model.h" 41 41 #include "objects/worldentities/ParticleSpawner.h" 42 #include "Settings.h" 42 #include "objects/collisionshapes/SphereCollisionShape.h" 43 #include "core/Core.h" 43 44 44 45 namespace orxonox 45 46 { 46 float Projectile::speed_s = 5000; 47 48 Projectile::Projectile(BaseObject* creator, Weapon* owner) : MovableEntity(creator), owner_(owner) 47 Projectile::Projectile(BaseObject* creator) : MovableEntity(creator) 49 48 { 50 49 RegisterObject(Projectile); 51 50 52 51 this->setConfigValues(); 53 this-> explosionTemplateName_ = "Orxonox/explosion3";54 this-> smokeTemplateName_ = "Orxonox/smoke4";52 this->bDestroy_ = false; 53 this->owner_ = 0; 55 54 56 this->setStatic(false); 57 this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL); 55 // Get notification about collisions 58 56 59 if ( this->owner_)57 if (Core::isMaster()) 60 58 { 61 this->setOrientation(this->owner_->getOrientation()); 62 this->setPosition(this->owner_->getPosition()); 63 this->setVelocity(this->owner_->getInitialDir() * this->speed_); 59 this->enableCollisionCallback(); 60 61 this->setCollisionType(Kinematic); 62 63 SphereCollisionShape* shape = new SphereCollisionShape(this); 64 shape->setRadius(10); 65 this->attachCollisionShape(shape); 66 67 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 64 68 } 65 66 if(!orxonox::Settings::isClient()) //only if not on client67 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));68 69 } 69 70 … … 76 77 SetConfigValue(damage_, 15.0).description("The damage caused by the projectile"); 77 78 SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive"); 78 SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(this, &Projectile::speedChanged);79 79 } 80 80 81 void Projectile::speedChanged()82 {83 Projectile::speed_s = this->speed_;84 if (this->owner_)85 this->setVelocity(this->owner_->getInitialDir() * this->speed_);86 }87 81 88 82 void Projectile::tick(float dt) … … 93 87 return; 94 88 95 float radius; 96 for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it) 97 { 98 // if ((*it) != this->owner_) 99 { 100 radius = it->getScale3D().x * 3.0; 101 102 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) 103 { 104 // hit 105 ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0); 106 explosion->setPosition(this->getPosition()); 107 explosion->create(); 108 ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0); 109 smoke->setPosition(this->getPosition()); 110 // smoke->getParticleInterface()->setSpeedFactor(3.0); 111 smoke->create(); 112 delete this; 113 return; 114 } 115 } 116 } 89 if (this->bDestroy_) 90 delete this; 117 91 } 118 92 119 93 void Projectile::destroyObject() 120 94 { 121 delete this; 95 if (Core::isMaster()) 96 delete this; 122 97 } 123 98 124 bool Projectile::create(){ 125 return WorldEntity::create(); 99 bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 100 { 101 if (!this->bDestroy_ && Core::isMaster()) 102 { 103 this->bDestroy_ = true; 104 105 if (this->owner_) 106 { 107 { 108 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); 109 effect->setPosition(this->getPosition()); 110 effect->setOrientation(this->getOrientation()); 111 effect->setDestroyAfterLife(true); 112 effect->setSource("Orxonox/explosion3"); 113 effect->setLifetime(2.0f); 114 } 115 { 116 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); 117 effect->setPosition(this->getPosition()); 118 effect->setOrientation(this->getOrientation()); 119 effect->setDestroyAfterLife(true); 120 effect->setSource("Orxonox/smoke4"); 121 effect->setLifetime(3.0f); 122 } 123 } 124 125 Pawn* victim = dynamic_cast<Pawn*>(otherObject); 126 if (victim) 127 victim->damage(this->damage_, this->owner_); 128 } 129 return false; 130 } 131 132 void Projectile::destroyedPawn(Pawn* pawn) 133 { 134 if (this->owner_ == pawn) 135 this->owner_ = 0; 126 136 } 127 137 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.h
r2099 r2662 33 33 34 34 #include "objects/worldentities/MovableEntity.h" 35 #include "objects/worldentities/pawns/Pawn.h" 35 36 #include "tools/Timer.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport Projectile : public MovableEntity 40 class _OrxonoxExport Projectile : public MovableEntity, public PawnListener 40 41 { 41 42 public: 43 Projectile(BaseObject* creator); 42 44 virtual ~Projectile(); 45 43 46 void setConfigValues(); 44 void speedChanged();45 47 void destroyObject(); 48 46 49 virtual void tick(float dt); 50 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 51 virtual void destroyedPawn(Pawn* pawn); 47 52 48 virtual bool create(); 49 50 static float getSpeed() 51 { return Projectile::speed_s; } 52 53 protected: 54 Projectile(BaseObject* creator, Weapon* owner = 0); 55 SpaceShip* owner_; 53 inline void setOwner(Pawn* owner) 54 { this->owner_ = owner; } 55 inline Pawn* getOwner() const 56 { return this->owner_; } 56 57 57 58 private: 58 std::string explosionTemplateName_; 59 std::string smokeTemplateName_; 60 protected: 61 static float speed_s; 62 float speed_; 63 private: 59 Pawn* owner_; 64 60 float lifetime_; 65 61 float damage_; 62 bool bDestroy_; 66 63 Timer<Projectile> destroyTimer_; 67 64 }; -
code/trunk/src/orxonox/objects/weaponSystem/weapons/CMakeLists.txt
r2131 r2662 1 1 SET( SRC_FILES 2 Fusion.cc 2 3 LaserGun.cc 3 Missile.cc4 # Missile.cc 4 5 ) 5 6 -
code/trunk/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc
r2097 r2662 34 34 #include "util/Debug.h" 35 35 36 #include "LaserGun.h" 37 36 38 37 39 namespace orxonox 38 40 { 41 CreateFactory(LaserGun); 42 39 43 LaserGun::LaserGun(BaseObject* creator) : Weapon(creator) 40 44 { 41 45 RegisterObject(LaserGun); 42 46 43 projectileColor_ = ColourValue(1.0, 1.0, 0.5) 47 this->speed_ = 1250; 48 44 49 } 45 50 … … 48 53 } 49 54 50 LaserGun::fire()55 void LaserGun::takeBullets() 51 56 { 52 BillboardProjectile* projectile = new ParticleProjectile(this); 53 projectile->setColour(this->projectileColor_); 54 projectile->create(); 55 if (projectile->getClassID() == 0) 56 { 57 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 58 } 59 60 projectile->setObjectMode(0x3); 57 //COUT(0) << "LaserGun::takeBullets" << std::endl; 58 this->munition_->removeBullets(1); 59 this->bulletTimer(this->bulletLoadingTime_); 61 60 } 62 61 63 LaserGun::addMunition()62 void LaserGun::takeMagazines() 64 63 { 65 //this->munition_ = ; 64 this->munition_->removeMagazines(1); 65 this->magazineTimer(this->magazineLoadingTime_); 66 66 } 67 67 68 void LaserGun:: XMLPort(Element& xmlelement, XMLPort::Mode mode)68 void LaserGun::createProjectile() 69 69 { 70 71 }72 73 ColorValue LaserGun::getProjectileColor()74 {75 return projectileColor_;70 //COUT(0) << "LaserGun::createProjectile" << std::endl; 71 BillboardProjectile* projectile = new ParticleProjectile(this); 72 projectile->setOrientation(this->getWorldOrientation()); 73 projectile->setPosition(this->getWorldPosition()); 74 projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_); 75 projectile->setOwner(this->getParentWeaponSystem()->getParentPawn()); 76 76 } 77 77 } -
code/trunk/src/orxonox/objects/weaponSystem/weapons/LaserGun.h
r2106 r2662 34 34 #include "core/BaseObject.h" 35 35 36 #include "LaserGunMunition.h" 37 #include "tools/BillboardSet.h" 36 #include "../munitions/LaserGunMunition.h" 38 37 #include "util/Math.h" 38 #include "../Weapon.h" 39 #include "../projectiles/BillboardProjectile.h" 40 #include "../projectiles/ParticleProjectile.h" 39 41 40 42 namespace orxonox … … 46 48 virtual ~LaserGun(); 47 49 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);49 50 ColourValue LaserGun::getProjectileColour();50 virtual void takeBullets(); 51 virtual void takeMagazines(); 52 virtual void createProjectile(); 51 53 52 54 private: 53 ColorValue projectileColor_; 54 55 55 float speed_; 56 56 57 57 }; -
code/trunk/src/orxonox/objects/worldentities/Backlight.cc
- Property svn:mergeinfo changed
r2261 r2662 30 30 #include "Backlight.h" 31 31 32 #include <OgreBillboard.h>33 32 #include <OgreRibbonTrail.h> 34 33 #include <OgreSceneManager.h> 35 34 35 #include "core/Core.h" 36 36 #include "core/CoreIncludes.h" 37 #include "core/ConfigValueIncludes.h"38 37 #include "core/Executor.h" 39 #include "util/Math.h" 40 #include "GraphicsEngine.h" 38 #include "core/XMLPort.h" 39 #include "objects/Scene.h" 40 #include "util/Exception.h" 41 41 42 42 namespace orxonox … … 44 44 CreateFactory(Backlight); 45 45 46 float Backlight::timeFactor_s = 1.0; 47 48 Backlight::Backlight(float maxspeed, float brakingtime, float scale) 46 Backlight::Backlight(BaseObject* creator) : FadingBillboard(creator) 49 47 { 50 48 RegisterObject(Backlight); 51 49 52 this->setConfigValues(); 53 this->traillength_ = 1; 54 55 this->configure(maxspeed, brakingtime, scale); 56 } 57 58 bool Backlight::create(){ 59 if(!WorldEntity::create()) 60 return false; 61 62 this->getNode()->setInheritScale(false); 63 64 this->billboard_.setBillboardSet("Flares/backlightflare"); 65 this->attachObject(this->billboard_.getBillboardSet()); 66 67 this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail"); 68 this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode"); 69 this->ribbonTrailNode_->attachObject(this->ribbonTrail_); 70 this->ribbonTrail_->addNode(this->getNode()); 71 72 73 this->ribbonTrail_->setTrailLength(this->maxTraillength_); 74 this->ribbonTrail_->setMaterialName("Trail/backlighttrail"); 75 76 //this->setTimeFactor(Orxonox::getInstance().getTimeFactor()); 77 this->setTimeFactor(1.0f); 78 79 this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_); 80 this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_); 81 this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getScale()); 82 this->ribbonTrail_->setWidthChange(0, this->width_ * this->getScale() / this->maxLifeTime_ * Backlight::timeFactor_s); 83 return true; 50 this->ribbonTrail_ = 0; 51 this->ribbonTrailNode_ = 0; 52 53 this->width_ = 0; 54 this->length_ = 1.0f; 55 this->lifetime_ = 0.001f; 56 this->maxelements_ = 1; 57 58 this->tickcount_ = 0; 59 60 if (Core::showsGraphics()) 61 { 62 if (!this->getScene()) 63 ThrowException(AbortLoading, "Can't create Backlight, no scene given."); 64 if (!this->getScene()->getSceneManager()) 65 ThrowException(AbortLoading, "Can't create Backlight, no scene manager given."); 66 if (!this->getScene()->getRootSceneNode()) 67 ThrowException(AbortLoading, "Can't create Backlight, no root scene node given."); 68 69 this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName()); 70 71 this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode(); 72 this->ribbonTrailNode_->attachObject(this->ribbonTrail_); 73 74 this->ribbonTrail_->setMaxChainElements(this->maxelements_); 75 this->ribbonTrail_->setTrailLength(this->length_); 76 this->ribbonTrail_->setInitialWidth(0, 0); 77 } 78 79 this->registerVariables(); 84 80 } 85 81 … … 88 84 if (this->isInitialized()) 89 85 { 90 this->detachObject(this->billboard_.getBillboardSet()); 91 GraphicsEngine::getInstance().getLevelSceneManager()->destroySceneNode(this->getName() + "RibbonTrailNode"); 92 GraphicsEngine::getInstance().getLevelSceneManager()->destroyRibbonTrail(this->ribbonTrail_); 93 } 94 } 95 96 void Backlight::setConfigValues() 97 { 98 SetConfigValue(maxLifeTime_, 4.0).description("The maximal amount of seconds the trail behind a SpaceShip stays visible"); 99 SetConfigValue(trailSegmentLength_, 50).description("The length of one segment of the trail behind a SpaceShip (lower values make it more smooth)"); 100 SetConfigValue(width_, 7.0).description("The width of the trail"); 101 } 102 103 void Backlight::setTimeFactor(float factor) 104 { 105 Backlight::timeFactor_s = factor; 106 float change = Backlight::timeFactor_s / this->maxLifeTime_; 107 this->ribbonTrail_->setWidthChange(0, this->width_ * change); 108 this->updateColourChange(); 109 } 110 111 void Backlight::updateColourChange() 112 { 113 this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s)); 114 } 115 116 117 void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){ 118 SUPER(Backlight, XMLPort, xmlelement, mode); 119 120 Backlight::create(); 86 if (this->ribbonTrail_) 87 { 88 if (this->ribbonTrailNode_) 89 { 90 this->ribbonTrailNode_->detachObject(this->ribbonTrail_); 91 this->getScene()->getSceneManager()->destroySceneNode(this->ribbonTrailNode_->getName()); 92 } 93 this->getScene()->getSceneManager()->destroyRibbonTrail(this->ribbonTrail_); 94 } 95 } 96 } 97 98 void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode) 99 { 100 SUPER(Backlight, XMLPort, xmlelement, mode); 101 102 XMLPortParam(Backlight, "length", setLength, getLength, xmlelement, mode).defaultValues(100.0f); 103 XMLPortParam(Backlight, "width", setWidth, getWidth, xmlelement, mode).defaultValues(1.0f); 104 XMLPortParam(Backlight, "elements", setMaxElements, getMaxElements, xmlelement, mode).defaultValues(10); 105 XMLPortParam(Backlight, "lifetime", setLifetime, getLifetime, xmlelement, mode).defaultValues(1.0f); 106 XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode); 107 } 108 109 void Backlight::registerVariables() 110 { 111 registerVariable(this->width_, variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_width)); 112 registerVariable(this->lifetime_, variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_lifetime)); 113 registerVariable(this->length_, variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_length)); 114 registerVariable(this->maxelements_, variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_maxelements)); 115 registerVariable(this->trailmaterial_, variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_trailmaterial)); 116 } 117 118 void Backlight::changedColour() 119 { 120 FadingBillboard::changedColour(); 121 122 if (this->ribbonTrail_ && this->tickcount_ >= 2) 123 this->ribbonTrail_->setInitialColour(0, this->getFadedColour()); 124 } 125 126 void Backlight::update_width() 127 { 128 if (this->ribbonTrail_ && this->tickcount_ >= 2) 129 this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getWorldScale()); 130 this->update_lifetime(); 131 } 132 133 void Backlight::update_lifetime() 134 { 135 if (this->ribbonTrail_ && this->tickcount_ >= 2) 136 { 137 this->ribbonTrail_->setWidthChange(0, this->width_ * this->getWorldScale() / this->lifetime_ * this->getTimeFactor()); 138 this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_ * this->getTimeFactor()); 139 } 140 } 141 142 void Backlight::update_length() 143 { 144 if (this->ribbonTrail_ && this->tickcount_ >= 2) 145 this->ribbonTrail_->setTrailLength(this->length_ * this->getWorldScale()); 146 } 147 148 void Backlight::update_maxelements() 149 { 150 if (this->ribbonTrail_ && this->tickcount_ >= 2) 151 this->ribbonTrail_->setMaxChainElements(this->maxelements_); 152 } 153 154 void Backlight::update_trailmaterial() 155 { 156 if (this->ribbonTrail_ && this->tickcount_ >= 2) 157 this->ribbonTrail_->setMaterialName(this->trailmaterial_); 158 } 159 160 void Backlight::changedVisibility() 161 { 162 SUPER(Backlight, changedVisibility); 163 164 if (this->ribbonTrail_) 165 this->ribbonTrail_->setVisible(this->isVisible()); 166 } 167 168 void Backlight::startturnonoff() 169 { 170 FadingBillboard::startturnonoff(); 171 172 if (this->ribbonTrail_ && this->isActive() && this->isVisible()) 173 this->ribbonTrail_->setVisible(true); 174 } 175 176 void Backlight::stopturnonoff() 177 { 178 this->postprocessingtime_ = max(0.0f, this->lifetime_ - this->turnofftime_); 179 180 FadingBillboard::stopturnonoff(); 181 182 if (this->ribbonTrail_) 183 this->ribbonTrail_->setInitialColour(0, this->getFadedColour()); 184 } 185 186 void Backlight::poststopturnonoff() 187 { 188 FadingBillboard::poststopturnonoff(); 189 190 if (this->ribbonTrail_) 191 this->ribbonTrail_->setVisible(false); 192 } 193 194 void Backlight::changedScale() 195 { 196 SUPER(Backlight, changedScale); 197 198 this->update_width(); 199 this->update_length(); 121 200 } 122 201 123 202 void Backlight::tick(float dt) 124 203 { 204 if (this->tickcount_ < 2) 205 { 206 ++this->tickcount_; 207 if (this->tickcount_ == 2) 208 { 209 this->changedColour(); 210 this->update_width(); 211 this->update_lifetime(); 212 this->update_length(); 213 this->update_maxelements(); 214 this->update_trailmaterial(); 215 if (this->ribbonTrail_) 216 this->ribbonTrail_->addNode(this->node_); 217 } 218 } 219 125 220 SUPER(Backlight, tick, dt); 126 221 127 if (this->isActive()) 128 { 129 if (this->traillength_ < this->maxTraillength_) 130 { 131 this->traillength_ = min<float>(this->maxTraillength_, this->traillength_ + dt * this->maxTraillength_ / this->maxLifeTime_); 132 this->updateColourChange(); 133 } 134 } 135 else 136 { 137 if (this->traillength_ > 1) 138 { 139 this->traillength_ = max<float>(1, this->traillength_ - this->brakefactor_ * dt * this->maxTraillength_ / this->maxLifeTime_); 140 this->updateColourChange(); 141 } 142 } 143 144 this->ribbonTrail_->setTrailLength(this->traillength_); 145 } 146 147 void Backlight::setColour(const ColourValue& colour) 148 { 149 this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour); 150 this->ribbonTrail_->setInitialColour(0, ColourValue(colour.r / 4 + 0.75, colour.g / 4 + 0.75, colour.b / 4 + 0.75)); 151 } 152 153 void Backlight::configure(float maxspeed, float brakingtime, float scale) 154 { 155 this->maxTraillength_ = this->maxLifeTime_ * maxspeed; 156 this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_); 157 158 this->brakefactor_ = this->maxLifeTime_ / brakingtime; 159 160 this->scale(scale); 161 } 162 163 void Backlight::changedVisibility() 164 { 165 SUPER(Backlight, changedVisibility); 166 167 this->billboard_.setVisible(this->isVisible()); 168 this->ribbonTrail_->setVisible(this->isVisible()); 222 if (this->ribbonTrail_ && this->changedirection_ != 0) 223 { 224 // we use alpha_blend, only adjust alpha 225 const ColourValue& colour = this->getColour(); 226 this->ribbonTrail_->setInitialColour(0, colour.r, colour.g, colour.b, this->getFadedColour().a); 227 } 228 } 229 230 void Backlight::changedTimeFactor(float factor_new, float factor_old) 231 { 232 this->update_lifetime(); 169 233 } 170 234 } -
code/trunk/src/orxonox/objects/worldentities/Backlight.h
- Property svn:mergeinfo changed
r2261 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include "PositionableEntity.h" 35 #include "tools/BillboardSet.h" 33 #include "FadingBillboard.h" 34 #include "gamestates/GSRoot.h" 36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport Backlight : public PositionableEntity38 class _OrxonoxExport Backlight : public FadingBillboard, public TimeFactorListener 40 39 { 41 40 public: 42 Backlight( float maxspeed = 1.0, float brakingtime = 1.0, float scale = 1.0);41 Backlight(BaseObject* creator); 43 42 virtual ~Backlight(); 44 43 45 void setConfigValues();46 44 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 void registerVariables(); 46 47 47 virtual void tick(float dt); 48 48 virtual void changedVisibility(); 49 virtual bool create();50 49 51 void setColour(const ColourValue& colour); 52 void setTimeFactor(float factor); 50 inline void setWidth(float width) 51 { this->width_ = width; this->update_width(); } 52 inline float getWidth() const 53 { return this->width_; } 54 55 inline void setLifetime(float lifetime) 56 { this->lifetime_ = lifetime; this->update_lifetime(); } 57 inline float getLifetime() const 58 { return this->lifetime_; } 59 60 inline void setLength(float length) 61 { this->length_ = length; this->update_length(); } 62 inline float getLength() const 63 { return this->length_; } 64 65 inline void setMaxElements(size_t maxelements) 66 { this->maxelements_ = maxelements; this->update_maxelements(); } 67 inline size_t getMaxElements() const 68 { return this->maxelements_; } 69 70 inline void setTrailMaterial(const std::string& material) 71 { this->trailmaterial_ = material; this->update_trailmaterial(); } 72 inline const std::string& getTrailMaterial() const 73 { return this->trailmaterial_; } 74 75 virtual void changedScale(); 76 77 protected: 78 virtual void changedTimeFactor(float factor_new, float factor_old); 53 79 54 80 private: 55 void configure(float maxspeed, float brakingtime, float scale = 1); 56 void updateColourChange(); 81 virtual void startturnonoff(); 82 virtual void stopturnonoff(); 83 virtual void poststopturnonoff(); 84 virtual void changedColour(); 85 void update_width(); 86 void update_lifetime(); 87 void update_length(); 88 void update_maxelements(); 89 void update_trailmaterial(); 57 90 58 static float timeFactor_s; 59 BillboardSet billboard_; 91 Ogre::RibbonTrail* ribbonTrail_; 60 92 Ogre::SceneNode* ribbonTrailNode_; 61 Ogre::RibbonTrail* ribbonTrail_;62 63 float maxLifeTime_;64 float trailSegmentLength_;65 93 float width_; 66 67 float brakefactor_; 68 69 float maxTraillength_; 70 float traillength_; 71 72 size_t maxTrailsegments_; 94 float length_; 95 float lifetime_; 96 size_t maxelements_; 97 std::string trailmaterial_; 98 char tickcount_; 73 99 }; 74 100 } -
code/trunk/src/orxonox/objects/worldentities/Billboard.cc
r2171 r2662 30 30 #include "Billboard.h" 31 31 32 #include <OgreBillboardSet.h> 33 32 34 #include "core/CoreIncludes.h" 33 35 #include "core/XMLPort.h" 36 #include "core/Core.h" 34 37 #include "objects/Scene.h" 35 38 … … 38 41 CreateFactory(Billboard); 39 42 40 Billboard::Billboard(BaseObject* creator) : PositionableEntity(creator)43 Billboard::Billboard(BaseObject* creator) : StaticEntity(creator) 41 44 { 42 45 RegisterObject(Billboard); 46 47 this->material_ = ""; 48 this->colour_ = ColourValue::White; 43 49 44 50 this->registerVariables(); … … 50 56 { 51 57 if (this->isInitialized() && this->billboard_.getBillboardSet()) 52 this-> getNode()->detachObject(this->billboard_.getName());58 this->detachOgreObject(this->billboard_.getBillboardSet()); 53 59 } 54 60 } … … 64 70 void Billboard::registerVariables() 65 71 { 66 REGISTERSTRING(this->material_, direction::toclient, new NetworkCallback<Billboard>(this, &Billboard::changedMaterial));67 REGISTERDATA (this->colour_, direction::toclient, new NetworkCallback<Billboard>(this, &Billboard::changedColour));72 registerVariable(this->material_, variableDirection::toclient, new NetworkCallback<Billboard>(this, &Billboard::changedMaterial)); 73 registerVariable(this->colour_, variableDirection::toclient, new NetworkCallback<Billboard>(this, &Billboard::changedColour)); 68 74 } 69 75 70 76 void Billboard::changedMaterial() 71 77 { 78 if (this->material_ == "") 79 return; 80 72 81 if (!this->billboard_.getBillboardSet()) 73 82 { 74 if (this->getScene() && this->getScene()->getSceneManager())83 if (this->getScene() && Core::showsGraphics()) 75 84 { 76 85 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); 77 86 if (this->billboard_.getBillboardSet()) 78 this->getNode()->attachObject(this->billboard_.getBillboardSet());87 this->attachOgreObject(this->billboard_.getBillboardSet()); 79 88 this->billboard_.setVisible(this->isVisible()); 80 89 } … … 88 97 if (!this->billboard_.getBillboardSet()) 89 98 { 90 if (this->getScene() && this->getScene()->getSceneManager()) 99 /* 100 if (this->getScene() && Core::showsGraphics() && (this->material_ != "")) 91 101 { 92 102 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); 93 103 if (this->billboard_.getBillboardSet()) 94 this-> getNode()->attachObject(this->billboard_.getBillboardSet());104 this->attachOgreObject(this->billboard_.getBillboardSet()); 95 105 this->billboard_.setVisible(this->isVisible()); 96 106 } 107 */ 97 108 } 98 109 else -
code/trunk/src/orxonox/objects/worldentities/Billboard.h
r2087 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 #include "util/Math.h" 35 35 #include "tools/BillboardSet.h" … … 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Billboard : public PositionableEntity39 class _OrxonoxExport Billboard : public StaticEntity 40 40 { 41 41 public: … … 61 61 { return this->colour_; } 62 62 63 protected: 64 inline BillboardSet& getBillboardSet() 65 { return this->billboard_; } 66 67 virtual void changedColour(); 68 63 69 private: 64 70 void changedMaterial(); 65 void changedColour();66 71 67 72 BillboardSet billboard_; -
code/trunk/src/orxonox/objects/worldentities/BlinkingBillboard.cc
r2171 r2662 68 68 void BlinkingBillboard::registerVariables() 69 69 { 70 // REGISTERDATA(this->amplitude_, direction::toclient);71 // REGISTERDATA(this->frequency_, direction::toclient);72 // REGISTERDATA(this->phase_, direction::toclient);70 // registerVariable(this->amplitude_, variableDirection::toclient); 71 // registerVariable(this->frequency_, variableDirection::toclient); 72 // registerVariable(this->phase_, variableDirection::toclient); 73 73 } 74 74 75 75 void BlinkingBillboard::tick(float dt) 76 76 { 77 SUPER(BlinkingBillboard, tick, dt); 78 77 79 if (Core::isMaster() && this->isActive()) 78 80 { -
code/trunk/src/orxonox/objects/worldentities/CMakeLists.txt
r2131 r2662 1 1 SET( SRC_FILES 2 2 WorldEntity.cc 3 PositionableEntity.cc3 StaticEntity.cc 4 4 MovableEntity.cc 5 MobileEntity.cc 5 6 ControllableEntity.cc 6 Model.cc 7 8 Backlight.cc 7 9 Billboard.cc 8 10 BlinkingBillboard.cc 11 ExplosionChunk.cc 12 FadingBillboard.cc 9 13 Light.cc 10 14 Camera.cc 11 15 CameraPosition.cc 12 SpawnPoint.cc16 Model.cc 13 17 ParticleEmitter.cc 14 18 ParticleSpawner.cc 15 # Backlight.cc 19 Planet.cc 20 SpawnPoint.cc 16 21 ) 17 22 -
code/trunk/src/orxonox/objects/worldentities/Camera.cc
- Property svn:mergeinfo changed
r2261 r2662 36 36 #include <OgreSceneManager.h> 37 37 #include <OgreSceneNode.h> 38 #include <OgreViewport.h>39 38 40 39 #include "util/Exception.h" … … 48 47 CreateFactory(Camera); 49 48 50 Camera::Camera(BaseObject* creator) : PositionableEntity(creator)49 Camera::Camera(BaseObject* creator) : StaticEntity(creator) 51 50 { 52 51 RegisterObject(Camera); 53 52 54 if (!this->getScene() || !this->getScene()->getSceneManager()) 55 ThrowException(AbortLoading, "Can't create Camera, no scene or no scene manager given."); 53 if (!this->getScene()) 54 ThrowException(AbortLoading, "Can't create Camera, no scene."); 55 if (!this->getScene()->getSceneManager()) 56 ThrowException(AbortLoading, "Can't create Camera, no scene-manager given."); 57 if (!this->getScene()->getRootSceneNode()) 58 ThrowException(AbortLoading, "Can't create Camera, no root-scene-node given."); 56 59 57 60 this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); 58 this->getNode()->attachObject(this->camera_); 61 this->cameraNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode(); 62 this->attachNode(this->cameraNode_); 63 this->cameraNode_->attachObject(this->camera_); 59 64 60 65 this->bHasFocus_ = false; … … 66 71 this->setConfigValues(); 67 72 this->configvaluecallback_changedNearClipDistance(); 68 69 this->requestFocus(); // ! HACK ! REMOVE THIS !70 73 } 71 74 … … 75 78 { 76 79 this->releaseFocus(); 80 81 this->cameraNode_->detachAllObjects(); 82 this->getScene()->getSceneManager()->destroyCamera(this->camera_); 83 84 if (this->bDrag_) 85 this->detachNode(this->cameraNode_); 86 87 if (this->getScene()->getSceneManager()) 88 this->getScene()->getSceneManager()->destroySceneNode(this->cameraNode_->getName()); 77 89 } 78 90 } … … 90 102 void Camera::tick(float dt) 91 103 { 92 /* 93 // this stuff here may need some adjustments 94 float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f); 104 SUPER(Camera, tick, dt); 95 105 96 Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition(); 97 this->cameraNode_->translate(coeff * offset); 106 if (this->bDrag_) 107 { 108 // this stuff here may need some adjustments 109 float coeff = min(1.0f, 15.0f * dt); 98 110 99 this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false)); 100 */ 111 Vector3 offset = this->getWorldPosition() - this->cameraNode_->getWorldPosition(); 112 this->cameraNode_->translate(coeff * offset); 113 114 this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), true)); 115 //this->cameraNode_->setOrientation(this->getWorldOrientation()); 116 } 101 117 } 102 118 … … 120 136 } 121 137 122 void Camera::setFocus( Ogre::Viewport* viewport)138 void Camera::setFocus() 123 139 { 124 140 this->bHasFocus_ = true; 125 viewport->setCamera(this->camera_); 141 CameraManager::getInstance().useCamera(this->camera_); 142 } 143 144 void Camera::setDrag(bool bDrag) 145 { 146 if (bDrag != this->bDrag_) 147 { 148 this->bDrag_ = bDrag; 149 150 if (!bDrag) 151 { 152 this->attachNode(this->cameraNode_); 153 this->cameraNode_->setPosition(Vector3::ZERO); 154 this->cameraNode_->setOrientation(Quaternion::IDENTITY); 155 } 156 else 157 { 158 this->detachNode(this->cameraNode_); 159 this->cameraNode_->setPosition(this->getWorldPosition()); 160 this->cameraNode_->setOrientation(this->getWorldOrientation()); 161 } 162 } 126 163 } 127 164 } -
code/trunk/src/orxonox/objects/worldentities/Camera.h
- Property svn:mergeinfo changed
r2261 r2662 33 33 34 34 #include <OgrePrerequisites.h> 35 #include "objects/worldentities/ PositionableEntity.h"35 #include "objects/worldentities/StaticEntity.h" 36 36 #include "objects/Tickable.h" 37 37 38 38 namespace orxonox 39 39 { 40 class _OrxonoxExport Camera : public PositionableEntity, public Tickable40 class _OrxonoxExport Camera : public StaticEntity, public Tickable 41 41 { 42 42 friend class CameraManager; … … 55 55 { return this->bHasFocus_; } 56 56 57 inline void setDrag(bool bDrag) 58 { this->bDrag_ = bDrag; } 57 void setDrag(bool bDrag); 59 58 inline bool getDrag() const 60 59 { return this->bDrag_; } … … 62 61 private: 63 62 void removeFocus(); 64 void setFocus( Ogre::Viewport* viewport);63 void setFocus(); 65 64 void configvaluecallback_changedNearClipDistance(); 66 65 67 Ogre::Camera* camera_; 68 float nearClipDistance_; 69 bool bHasFocus_; 70 bool bDrag_; 66 Ogre::Camera* camera_; 67 Ogre::SceneNode* cameraNode_; 68 float nearClipDistance_; 69 bool bHasFocus_; 70 bool bDrag_; 71 71 }; 72 72 } -
code/trunk/src/orxonox/objects/worldentities/CameraPosition.cc
r2087 r2662 38 38 CreateFactory(CameraPosition); 39 39 40 CameraPosition::CameraPosition(BaseObject* creator) : PositionableEntity(creator)40 CameraPosition::CameraPosition(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(CameraPosition); 43 43 44 44 this->bDrag_ = false; 45 this->bAllowMouseLook_ = false; 45 46 46 47 this->setObjectMode(0x0); … … 56 57 57 58 XMLPortParam(CameraPosition, "drag", setDrag, getDrag, xmlelement, mode).defaultValues(false); 59 XMLPortParam(CameraPosition, "mouselook", setAllowMouseLook, getAllowMouseLook, xmlelement, mode).defaultValues(false); 58 60 } 59 61 60 62 void CameraPosition::attachCamera(Camera* camera) 61 63 { 62 camera->setDrag(this->bDrag_); 64 if (!this->bDrag_) 65 camera->setDrag(false); 66 63 67 this->attach(camera); 68 69 if (this->bDrag_) 70 camera->setDrag(true); 64 71 } 65 72 } -
code/trunk/src/orxonox/objects/worldentities/CameraPosition.h
r2087 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "objects/worldentities/ PositionableEntity.h"34 #include "objects/worldentities/StaticEntity.h" 35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport CameraPosition : public PositionableEntity38 class _OrxonoxExport CameraPosition : public StaticEntity 39 39 { 40 40 public: … … 49 49 { return this->bDrag_; } 50 50 51 inline void setAllowMouseLook(bool bAllow) 52 { this->bAllowMouseLook_ = bAllow; } 53 inline bool getAllowMouseLook() const 54 { return this->bAllowMouseLook_; } 55 51 56 void attachCamera(Camera* camera); 52 57 53 58 private: 54 59 bool bDrag_; 60 bool bAllowMouseLook_; 55 61 }; 56 62 } -
code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
r2171 r2662 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 30 30 #include "ControllableEntity.h" 31 31 32 #include <OgreSceneManager.h> 33 32 34 #include "core/CoreIncludes.h" 35 #include "core/ConfigValueIncludes.h" 33 36 #include "core/Core.h" 34 37 #include "core/XMLPort.h" 35 38 #include "core/Template.h" 36 39 40 #include "objects/Scene.h" 37 41 #include "objects/infos/PlayerInfo.h" 38 42 #include "objects/worldentities/Camera.h" 39 43 #include "objects/worldentities/CameraPosition.h" 44 #include "objects/gametypes/Gametype.h" 40 45 #include "overlays/OverlayGroup.h" 41 46 … … 44 49 CreateFactory(ControllableEntity); 45 50 46 ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator)51 ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator) 47 52 { 48 53 RegisterObject(ControllableEntity); 49 54 50 this->bControlled_ = false; 55 this->bHasLocalController_ = false; 56 this->bHasHumanController_ = false; 57 51 58 this->server_overwrite_ = 0; 52 59 this->client_overwrite_ = 0; … … 56 63 this->camera_ = 0; 57 64 this->bDestroyWhenPlayerLeft_ = false; 58 59 this->velocity_ = Vector3::ZERO; 60 this->acceleration_ = Vector3::ZERO; 61 62 this->server_position_ = Vector3::ZERO; 63 this->client_position_ = Vector3::ZERO; 64 this->server_velocity_ = Vector3::ZERO; 65 this->client_velocity_ = Vector3::ZERO; 66 this->server_orientation_ = Quaternion::IDENTITY; 67 this->client_orientation_ = Quaternion::IDENTITY; 68 65 this->cameraPositionRootNode_ = this->node_->createChildSceneNode(); 66 this->bMouseLook_ = false; 67 this->mouseLookSpeed_ = 200; 68 69 this->gtinfo_ = 0; 70 this->gtinfoID_ = OBJECTID_UNKNOWN; 71 this->changedGametype(); 72 73 this->server_position_ = Vector3::ZERO; 74 this->client_position_ = Vector3::ZERO; 75 this->server_linear_velocity_ = Vector3::ZERO; 76 this->client_linear_velocity_ = Vector3::ZERO; 77 this->server_orientation_ = Quaternion::IDENTITY; 78 this->client_orientation_ = Quaternion::IDENTITY; 79 this->server_angular_velocity_ = Vector3::ZERO; 80 this->client_angular_velocity_ = Vector3::ZERO; 81 82 83 this->setConfigValues(); 84 this->setPriority( priority::very_high ); 69 85 this->registerVariables(); 70 86 } … … 74 90 if (this->isInitialized()) 75 91 { 76 if (this->bControlled_) 77 this->stopLocalControl(); 92 this->bDestroyWhenPlayerLeft_ = false; 93 94 if (this->bHasLocalController_ && this->bHasHumanController_) 95 this->stopLocalHumanControl(); 96 97 if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this) 98 this->getPlayer()->stopControl(this, false); 78 99 79 100 if (this->hud_) … … 83 104 delete this->camera_; 84 105 85 if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this) 86 this->getPlayer()->stopControl(this, false); 106 for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) 107 delete (*it); 108 109 if (this->getScene()->getSceneManager()) 110 this->getScene()->getSceneManager()->destroySceneNode(this->cameraPositionRootNode_->getName()); 87 111 } 88 112 } … … 98 122 } 99 123 124 void ControllableEntity::setConfigValues() 125 { 126 SetConfigValue(mouseLookSpeed_, 3.0f); 127 } 128 129 void ControllableEntity::changedGametype() 130 { 131 //SUPER(ControllableEntity, changedGametype); 132 WorldEntity::changedGametype(); 133 134 this->gtinfo_ = 0; 135 this->gtinfoID_ = OBJECTID_UNKNOWN; 136 137 if (this->getGametype() && this->getGametype()->getGametypeInfo()) 138 { 139 this->gtinfo_ = this->getGametype()->getGametypeInfo(); 140 this->gtinfoID_ = this->gtinfo_->getObjectID(); 141 } 142 } 143 100 144 void ControllableEntity::addCameraPosition(CameraPosition* position) 101 145 { 102 this->attach(position); 146 if (position->getAllowMouseLook()) 147 position->attachToNode(this->cameraPositionRootNode_); 148 else 149 this->attach(position); 103 150 this->cameraPositions_.push_back(position); 104 151 } … … 141 188 else 142 189 { 143 this-> attach(this->camera_);190 this->camera_->attachToNode(this->cameraPositionRootNode_); 144 191 } 145 192 } 193 } 194 195 void ControllableEntity::mouseLook() 196 { 197 this->bMouseLook_ = !this->bMouseLook_; 198 199 if (!this->bMouseLook_) 200 this->cameraPositionRootNode_->setOrientation(Quaternion::IDENTITY); 201 } 202 203 void ControllableEntity::rotateYaw(const Vector2& value) 204 { 205 if (this->bMouseLook_) 206 this->cameraPositionRootNode_->yaw(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); 207 } 208 209 void ControllableEntity::rotatePitch(const Vector2& value) 210 { 211 if (this->bMouseLook_) 212 this->cameraPositionRootNode_->pitch(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); 213 } 214 215 void ControllableEntity::rotateRoll(const Vector2& value) 216 { 217 if (this->bMouseLook_) 218 this->cameraPositionRootNode_->roll(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); 146 219 } 147 220 … … 156 229 this->player_ = player; 157 230 this->playerID_ = player->getObjectID(); 158 this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer()); 159 if (this->bControlled_) 160 { 161 this->startLocalControl(); 231 this->bHasLocalController_ = player->isLocalPlayer(); 232 this->bHasHumanController_ = player->isHumanPlayer(); 233 234 if (this->bHasLocalController_ && this->bHasHumanController_) 235 { 236 this->startLocalHumanControl(); 162 237 163 238 if (!Core::isMaster()) 164 239 { 165 240 this->client_overwrite_ = this->server_overwrite_; 166 COUT(0) << "CE: bidirectional synchronization" << std::endl; 167 this->setObjectMode(direction::bidirectional); 241 this->setObjectMode(objectDirection::bidirectional); 168 242 } 169 243 } … … 172 246 void ControllableEntity::removePlayer() 173 247 { 174 if (this->b Controlled_)175 this->stopLocal Control();248 if (this->bHasLocalController_ && this->bHasHumanController_) 249 this->stopLocalHumanControl(); 176 250 177 251 this->player_ = 0; 178 252 this->playerID_ = OBJECTID_UNKNOWN; 179 this->bControlled_ = false; 180 this->setObjectMode(direction::toclient); 253 this->bHasLocalController_ = false; 254 this->bHasHumanController_ = false; 255 this->setObjectMode(objectDirection::toclient); 181 256 182 257 if (this->bDestroyWhenPlayerLeft_) … … 195 270 } 196 271 197 void ControllableEntity::startLocalControl() 198 { 199 // std::cout << this->getObjectID() << " ###### start local control" << std::endl; 200 this->camera_ = new Camera(this); 201 this->camera_->requestFocus(); 202 if (this->cameraPositionTemplate_ != "") 203 this->addTemplate(this->cameraPositionTemplate_); 204 if (this->cameraPositions_.size() > 0) 205 this->cameraPositions_.front()->attachCamera(this->camera_); 206 else 207 this->attach(this->camera_); 208 209 if (this->hudtemplate_ != "") 210 { 211 this->hud_ = new OverlayGroup(this); 212 this->hud_->addTemplate(this->hudtemplate_); 213 } 214 } 215 216 void ControllableEntity::stopLocalControl() 217 { 218 // std::cout << "###### stop local control" << std::endl; 219 this->camera_->detachFromParent(); 220 delete this->camera_; 221 this->camera_ = 0; 222 223 delete this->hud_; 224 this->hud_ = 0; 272 void ControllableEntity::networkcallback_changedgtinfoID() 273 { 274 if (this->gtinfoID_ != OBJECTID_UNKNOWN) 275 { 276 this->gtinfo_ = dynamic_cast<GametypeInfo*>(Synchronisable::getSynchronisable(this->gtinfoID_)); 277 278 if (!this->gtinfo_) 279 this->gtinfoID_ = OBJECTID_UNKNOWN; 280 } 281 } 282 283 void ControllableEntity::startLocalHumanControl() 284 { 285 if (!this->camera_) 286 { 287 this->camera_ = new Camera(this); 288 this->camera_->requestFocus(); 289 if (this->cameraPositionTemplate_ != "") 290 this->addTemplate(this->cameraPositionTemplate_); 291 if (this->cameraPositions_.size() > 0) 292 this->cameraPositions_.front()->attachCamera(this->camera_); 293 else 294 this->camera_->attachToNode(this->cameraPositionRootNode_); 295 } 296 297 if (!this->hud_) 298 { 299 if (this->hudtemplate_ != "") 300 { 301 this->hud_ = new OverlayGroup(this); 302 this->hud_->addTemplate(this->hudtemplate_); 303 this->hud_->setOwner(this); 304 } 305 } 306 } 307 308 void ControllableEntity::stopLocalHumanControl() 309 { 310 if (this->camera_) 311 { 312 this->camera_->detachFromParent(); 313 delete this->camera_; 314 this->camera_ = 0; 315 } 316 317 if (this->hud_) 318 { 319 delete this->hud_; 320 this->hud_ = 0; 321 } 225 322 } 226 323 227 324 void ControllableEntity::tick(float dt) 228 325 { 326 MobileEntity::tick(dt); 327 229 328 if (this->isActive()) 230 329 { 231 this->velocity_ += (dt * this->acceleration_); 232 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL); 233 234 if (Core::isMaster()) 330 // Check whether Bullet doesn't do the physics for us 331 if (!this->isDynamic()) 235 332 { 236 this->server_velocity_ = this->velocity_; 237 this->server_position_ = this->node_->getPosition(); 333 if (Core::isMaster()) 334 { 335 this->server_position_ = this->getPosition(); 336 this->server_orientation_ = this->getOrientation(); 337 this->server_linear_velocity_ = this->getVelocity(); 338 this->server_angular_velocity_ = this->getAngularVelocity(); 339 } 340 else if (this->bHasLocalController_) 341 { 342 this->client_position_ = this->getPosition(); 343 this->client_orientation_ = this->getOrientation(); 344 this->client_linear_velocity_ = this->getVelocity(); 345 this->client_angular_velocity_ = this->getAngularVelocity(); 346 } 238 347 } 239 else if (this->bControlled_)240 {241 // COUT(2) << "setting client position" << endl;242 this->client_velocity_ = this->velocity_;243 this->client_position_ = this->node_->getPosition();244 }245 348 } 246 349 } … … 248 351 void ControllableEntity::registerVariables() 249 352 { 250 REGISTERSTRING(this->cameraPositionTemplate_, direction::toclient); 251 252 REGISTERDATA(this->client_overwrite_, direction::toserver); 253 254 REGISTERDATA(this->server_position_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 255 REGISTERDATA(this->server_velocity_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity)); 256 REGISTERDATA(this->server_orientation_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 257 REGISTERDATA(this->server_overwrite_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 258 259 REGISTERDATA(this->client_position_, direction::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 260 REGISTERDATA(this->client_velocity_, direction::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity)); 261 REGISTERDATA(this->client_orientation_, direction::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 262 263 264 REGISTERDATA(this->playerID_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); 353 registerVariable(this->cameraPositionTemplate_, variableDirection::toclient); 354 registerVariable(this->hudtemplate_, variableDirection::toclient); 355 356 registerVariable(this->server_position_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 357 registerVariable(this->server_linear_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity)); 358 registerVariable(this->server_orientation_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 359 registerVariable(this->server_angular_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity)); 360 361 registerVariable(this->server_overwrite_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 362 registerVariable(this->client_overwrite_, variableDirection::toserver); 363 364 registerVariable(this->client_position_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 365 registerVariable(this->client_linear_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity)); 366 registerVariable(this->client_orientation_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 367 registerVariable(this->client_angular_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity)); 368 369 registerVariable(this->playerID_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); 370 registerVariable(this->gtinfoID_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedgtinfoID)); 265 371 } 266 372 267 373 void ControllableEntity::processServerPosition() 268 374 { 269 if (!this->b Controlled_)270 this->node_->setPosition(this->server_position_);271 } 272 273 void ControllableEntity::processServer Velocity()274 { 275 if (!this->b Controlled_)276 this->velocity_ = this->server_velocity_;375 if (!this->bHasLocalController_) 376 MobileEntity::setPosition(this->server_position_); 377 } 378 379 void ControllableEntity::processServerLinearVelocity() 380 { 381 if (!this->bHasLocalController_) 382 MobileEntity::setVelocity(this->server_linear_velocity_); 277 383 } 278 384 279 385 void ControllableEntity::processServerOrientation() 280 386 { 281 if (!this->bControlled_) 282 this->node_->setOrientation(this->server_orientation_); 387 if (!this->bHasLocalController_) 388 MobileEntity::setOrientation(this->server_orientation_); 389 } 390 391 void ControllableEntity::processServerAngularVelocity() 392 { 393 if (!this->bHasLocalController_) 394 MobileEntity::setAngularVelocity(this->server_angular_velocity_); 283 395 } 284 396 285 397 void ControllableEntity::processOverwrite() 286 398 { 287 if (this->b Controlled_)399 if (this->bHasLocalController_) 288 400 { 289 401 this->setPosition(this->server_position_); 290 this->setVelocity(this->server_velocity_);291 402 this->setOrientation(this->server_orientation_); 403 this->setVelocity(this->server_linear_velocity_); 404 this->setAngularVelocity(this->server_angular_velocity_); 292 405 293 406 this->client_overwrite_ = this->server_overwrite_; … … 299 412 if (this->server_overwrite_ == this->client_overwrite_) 300 413 { 301 // COUT(2) << "callback: setting client position" << endl; 302 this->node_->setPosition(this->client_position_); 303 this->server_position_ = this->client_position_; 304 } 305 // else 306 // COUT(2) << "callback: not setting client position" << endl; 307 } 308 309 void ControllableEntity::processClientVelocity() 414 MobileEntity::setPosition(this->client_position_); 415 this->server_position_ = this->getPosition(); 416 } 417 } 418 419 void ControllableEntity::processClientLinearVelocity() 310 420 { 311 421 if (this->server_overwrite_ == this->client_overwrite_) 312 422 { 313 this->velocity_ = this->client_velocity_;314 this->server_ velocity_ = this->client_velocity_;423 MobileEntity::setVelocity(this->client_linear_velocity_); 424 this->server_linear_velocity_ = this->getVelocity(); 315 425 } 316 426 } … … 320 430 if (this->server_overwrite_ == this->client_overwrite_) 321 431 { 322 this->node_->setOrientation(this->client_orientation_); 323 this->server_orientation_ = this->client_orientation_; 324 } 325 } 326 432 MobileEntity::setOrientation(this->client_orientation_); 433 this->server_orientation_ = this->getOrientation(); 434 } 435 } 436 437 void ControllableEntity::processClientAngularVelocity() 438 { 439 if (this->server_overwrite_ == this->client_overwrite_) 440 { 441 MobileEntity::setAngularVelocity(this->client_angular_velocity_); 442 this->server_angular_velocity_ = this->getAngularVelocity(); 443 } 444 } 327 445 328 446 void ControllableEntity::setPosition(const Vector3& position) … … 330 448 if (Core::isMaster()) 331 449 { 332 this->node_->setPosition(position);333 this->server_position_ = position;450 MobileEntity::setPosition(position); 451 this->server_position_ = this->getPosition(); 334 452 ++this->server_overwrite_; 335 453 } 336 else if (this->bControlled_) 337 { 338 this->node_->setPosition(position); 339 this->client_position_ = position; 454 else if (this->bHasLocalController_) 455 { 456 MobileEntity::setPosition(position); 457 this->client_position_ = this->getPosition(); 458 } 459 } 460 461 void ControllableEntity::setOrientation(const Quaternion& orientation) 462 { 463 if (Core::isMaster()) 464 { 465 MobileEntity::setOrientation(orientation); 466 this->server_orientation_ = this->getOrientation(); 467 ++this->server_overwrite_; 468 } 469 else if (this->bHasLocalController_) 470 { 471 MobileEntity::setOrientation(orientation); 472 this->client_orientation_ = this->getOrientation(); 340 473 } 341 474 } … … 345 478 if (Core::isMaster()) 346 479 { 347 this->velocity_ = velocity;348 this->server_ velocity_ = velocity;480 MobileEntity::setVelocity(velocity); 481 this->server_linear_velocity_ = this->getVelocity(); 349 482 ++this->server_overwrite_; 350 483 } 351 else if (this->b Controlled_)352 { 353 this->velocity_ = velocity;354 this->client_ velocity_ = velocity;355 } 356 } 357 358 void ControllableEntity:: translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)484 else if (this->bHasLocalController_) 485 { 486 MobileEntity::setVelocity(velocity); 487 this->client_linear_velocity_ = this->getVelocity(); 488 } 489 } 490 491 void ControllableEntity::setAngularVelocity(const Vector3& velocity) 359 492 { 360 493 if (Core::isMaster()) 361 494 { 362 this->node_->translate(distance, relativeTo);363 this->server_ position_ = this->node_->getPosition();495 MobileEntity::setAngularVelocity(velocity); 496 this->server_angular_velocity_ = this->getAngularVelocity(); 364 497 ++this->server_overwrite_; 365 498 } 366 else if (this->bControlled_) 367 { 368 this->node_->translate(distance, relativeTo); 369 this->client_position_ = this->node_->getPosition(); 370 } 371 } 372 373 void ControllableEntity::setOrientation(const Quaternion& orientation) 374 { 499 else if (this->bHasLocalController_) 500 { 501 MobileEntity::setAngularVelocity(velocity); 502 this->client_angular_velocity_ = this->getAngularVelocity(); 503 } 504 } 505 506 void ControllableEntity::setWorldTransform(const btTransform& worldTrans) 507 { 508 MobileEntity::setWorldTransform(worldTrans); 375 509 if (Core::isMaster()) 376 510 { 377 this->node_->setOrientation(orientation); 378 this->server_orientation_ = orientation; 379 ++this->server_overwrite_; 380 } 381 else if (this->bControlled_) 382 { 383 this->node_->setOrientation(orientation); 384 this->client_orientation_ = orientation; 385 } 386 } 387 388 void ControllableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo) 389 { 390 if (Core::isMaster()) 391 { 392 this->node_->rotate(rotation, relativeTo); 393 this->server_orientation_ = this->node_->getOrientation(); 394 ++this->server_overwrite_; 395 } 396 else if (this->bControlled_) 397 { 398 this->node_->rotate(rotation, relativeTo); 399 this->client_orientation_ = this->node_->getOrientation(); 400 } 401 } 402 403 void ControllableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 404 { 405 if (Core::isMaster()) 406 { 407 this->node_->yaw(angle, relativeTo); 408 this->server_orientation_ = this->node_->getOrientation(); 409 ++this->server_overwrite_; 410 } 411 else if (this->bControlled_) 412 { 413 this->node_->yaw(angle, relativeTo); 414 this->client_orientation_ = this->node_->getOrientation(); 415 } 416 } 417 418 void ControllableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 419 { 420 if (Core::isMaster()) 421 { 422 this->node_->pitch(angle, relativeTo); 423 this->server_orientation_ = this->node_->getOrientation(); 424 ++this->server_overwrite_; 425 } 426 else if (this->bControlled_) 427 { 428 this->node_->pitch(angle, relativeTo); 429 this->client_orientation_ = this->node_->getOrientation(); 430 } 431 } 432 433 void ControllableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 434 { 435 if (Core::isMaster()) 436 { 437 this->node_->roll(angle, relativeTo); 438 this->server_orientation_ = this->node_->getOrientation(); 439 ++this->server_overwrite_; 440 } 441 else if (this->bControlled_) 442 { 443 this->node_->roll(angle, relativeTo); 444 this->client_orientation_ = this->node_->getOrientation(); 445 } 446 } 447 448 void ControllableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 449 { 450 if (Core::isMaster()) 451 { 452 this->node_->lookAt(target, relativeTo, localDirectionVector); 453 this->server_orientation_ = this->node_->getOrientation(); 454 ++this->server_overwrite_; 455 } 456 else if (this->bControlled_) 457 { 458 this->node_->lookAt(target, relativeTo, localDirectionVector); 459 this->client_orientation_ = this->node_->getOrientation(); 460 } 461 } 462 463 void ControllableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 464 { 465 if (Core::isMaster()) 466 { 467 this->node_->setDirection(direction, relativeTo, localDirectionVector); 468 this->server_orientation_ = this->node_->getOrientation(); 469 ++this->server_overwrite_; 470 } 471 else if (this->bControlled_) 472 { 473 this->node_->setDirection(direction, relativeTo, localDirectionVector); 474 this->client_orientation_ = this->node_->getOrientation(); 511 this->server_position_ = this->getPosition(); 512 this->server_orientation_ = this->getOrientation(); 513 this->server_linear_velocity_ = this->getVelocity(); 514 this->server_angular_velocity_ = this->getAngularVelocity(); 515 } 516 else if (this->bHasLocalController_) 517 { 518 this->client_position_ = this->getPosition(); 519 this->client_orientation_ = this->getOrientation(); 520 this->client_linear_velocity_ = this->getVelocity(); 521 this->client_angular_velocity_ = this->getAngularVelocity(); 475 522 } 476 523 } -
code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h
r2087 r2662 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include " WorldEntity.h"35 #include "objects/ Tickable.h"34 #include "MobileEntity.h" 35 #include "objects/weaponSystem/WeaponSystem.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport ControllableEntity : public WorldEntity, public Tickable39 class _OrxonoxExport ControllableEntity : public MobileEntity 40 40 { 41 41 public: … … 46 46 virtual void tick(float dt); 47 47 void registerVariables(); 48 void setConfigValues(); 49 50 virtual void changedGametype(); 48 51 49 52 virtual void setPlayer(PlayerInfo* player); … … 61 64 virtual void moveUpDown(const Vector2& value) {} 62 65 63 virtual void rotateYaw(const Vector2& value) {}64 virtual void rotatePitch(const Vector2& value) {}65 virtual void rotateRoll(const Vector2& value) {}66 virtual void rotateYaw(const Vector2& value); 67 virtual void rotatePitch(const Vector2& value); 68 virtual void rotateRoll(const Vector2& value); 66 69 67 virtual void fire() {} 68 virtual void altFire() {} 70 inline void moveFrontBack(float value) 71 { this->moveFrontBack(Vector2(value, 0)); } 72 inline void moveRightLeft(float value) 73 { this->moveRightLeft(Vector2(value, 0)); } 74 inline void moveUpDown(float value) 75 { this->moveUpDown(Vector2(value, 0)); } 69 76 77 inline void rotateYaw(float value) 78 { this->rotateYaw(Vector2(value, 0)); } 79 inline void rotatePitch(float value) 80 { this->rotatePitch(Vector2(value, 0)); } 81 inline void rotateRoll(float value) 82 { this->rotateRoll(Vector2(value, 0)); } 83 84 virtual void fire(WeaponMode::Enum fireMode) {} 85 virtual void altFire(WeaponMode::Enum fireMode) {} 86 87 virtual void boost() {} 70 88 virtual void greet() {} 71 89 virtual void use() {} 90 virtual void dropItems() {} 72 91 virtual void switchCamera(); 92 virtual void mouseLook(); 73 93 74 inline const Vector3& getVelocity() const75 { return this->velocity_; }76 inline const Vector3& getAcceleration() const77 { return this->acceleration_; }78 94 inline const std::string& getHudTemplate() const 79 95 { return this->hudtemplate_; } 80 81 using WorldEntity::setPosition;82 using WorldEntity::translate;83 using WorldEntity::setOrientation;84 using WorldEntity::rotate;85 using WorldEntity::yaw;86 using WorldEntity::pitch;87 using WorldEntity::roll;88 using WorldEntity::lookAt;89 using WorldEntity::setDirection;90 91 void setPosition(const Vector3& position);92 void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);93 void setOrientation(const Quaternion& orientation);94 void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);95 void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);96 void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);97 void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);98 void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);99 void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);100 101 void setVelocity(const Vector3& velocity);102 inline void setVelocity(float x, float y, float z)103 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }104 105 inline void setAcceleration(const Vector3& acceleration)106 { this->acceleration_ = acceleration; }107 inline void setAcceleration(float x, float y, float z)108 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }109 96 110 97 inline Camera* getCamera() const … … 123 110 { return this->cameraPositionTemplate_; } 124 111 112 using WorldEntity::setPosition; 113 using WorldEntity::setOrientation; 114 using MobileEntity::setVelocity; 115 using MobileEntity::setAngularVelocity; 116 117 void setPosition(const Vector3& position); 118 void setOrientation(const Quaternion& orientation); 119 void setVelocity(const Vector3& velocity); 120 void setAngularVelocity(const Vector3& velocity); 121 122 inline bool hasLocalController() const 123 { return this->bHasLocalController_; } 124 inline bool hasHumanController() const 125 { return this->bHasHumanController_; } 126 127 inline const GametypeInfo* getGametypeInfo() const 128 { return this->gtinfo_; } 129 130 inline bool isInMouseLook() const 131 { return this->bMouseLook_; } 132 inline float getMouseLookSpeed() const 133 { return this->mouseLookSpeed_; } 134 125 135 protected: 126 virtual void startLocal Control();127 virtual void stopLocal Control();136 virtual void startLocalHumanControl(); 137 virtual void stopLocalHumanControl(); 128 138 129 139 inline void setHudTemplate(const std::string& name) 130 140 { this->hudtemplate_ = name; } 131 132 inline bool isLocallyControlled() const133 { return this->bControlled_; }134 135 Vector3 acceleration_;136 141 137 142 private: … … 140 145 141 146 void processServerPosition(); 142 void processServer Velocity();147 void processServerLinearVelocity(); 143 148 void processServerOrientation(); 149 void processServerAngularVelocity(); 144 150 145 151 void processClientPosition(); 146 void processClient Velocity();152 void processClientLinearVelocity(); 147 153 void processClientOrientation(); 154 void processClientAngularVelocity(); 148 155 149 156 void networkcallback_changedplayerID(); 157 void networkcallback_changedgtinfoID(); 158 159 // Bullet btMotionState related 160 void setWorldTransform(const btTransform& worldTrans); 150 161 151 162 unsigned int server_overwrite_; 152 163 unsigned int client_overwrite_; 153 164 154 Vector3 velocity_; 165 bool bHasLocalController_; 166 bool bHasHumanController_; 167 bool bDestroyWhenPlayerLeft_; 155 168 156 bool bControlled_;157 169 Vector3 server_position_; 158 170 Vector3 client_position_; 159 Vector3 server_ velocity_;160 Vector3 client_ velocity_;171 Vector3 server_linear_velocity_; 172 Vector3 client_linear_velocity_; 161 173 Quaternion server_orientation_; 162 174 Quaternion client_orientation_; 175 Vector3 server_angular_velocity_; 176 Vector3 client_angular_velocity_; 163 177 164 178 PlayerInfo* player_; 165 179 unsigned int playerID_; 180 166 181 std::string hudtemplate_; 167 182 OverlayGroup* hud_; 183 168 184 Camera* camera_; 169 bool bDestroyWhenPlayerLeft_; 170 185 bool bMouseLook_; 186 float mouseLookSpeed_; 187 Ogre::SceneNode* cameraPositionRootNode_; 171 188 std::list<CameraPosition*> cameraPositions_; 172 189 std::string cameraPositionTemplate_; 190 191 const GametypeInfo* gtinfo_; 192 unsigned int gtinfoID_; 173 193 }; 174 194 } -
code/trunk/src/orxonox/objects/worldentities/Light.cc
r2171 r2662 36 36 37 37 #include "util/String.h" 38 #include "util/Convert.h" 38 #include "util/Exception.h" 39 #include "core/Core.h" 39 40 #include "core/CoreIncludes.h" 40 41 #include "core/XMLPort.h" … … 43 44 namespace orxonox 44 45 { 45 unsigned int Light::lightCounter_s = 0;46 47 46 CreateFactory(Light); 48 47 49 Light::Light(BaseObject* creator) : PositionableEntity(creator)48 Light::Light(BaseObject* creator) : StaticEntity(creator) 50 49 { 51 50 RegisterObject(Light); 52 51 53 if (this->getScene() && this->getScene()->getSceneManager()) 54 this->light_ = this->getScene()->getSceneManager()->createLight("Light" + convertToString(Light::lightCounter_s++)); 55 this->getNode()->attachObject(this->light_); 52 this->light_ = 0; 53 this->diffuse_ = ColourValue::White; 54 this->specular_ = ColourValue::White; 55 this->type_ = Ogre::Light::LT_POINT; 56 this->attenuation_ = Vector4(100000, 1, 0, 0); 57 this->spotlightRange_ = Vector3(40.0f, 30.0f, 1.0f); 58 59 if (Core::showsGraphics()) 60 { 61 if (!this->getScene()) 62 ThrowException(AbortLoading, "Can't create Light, no scene given."); 63 if (!this->getScene()->getSceneManager()) 64 ThrowException(AbortLoading, "Can't create Light, no scene manager given."); 65 66 if (this->getScene() && this->getScene()->getSceneManager()) 67 { 68 this->light_ = this->getScene()->getSceneManager()->createLight("Light" + getUniqueNumberString()); 69 this->light_->setDirection(WorldEntity::FRONT); 70 this->attachOgreObject(this->light_); 71 72 this->updateType(); 73 this->updateDiffuseColour(); 74 this->updateSpecularColour(); 75 this->updateAttenuation(); 76 this->updateSpotlightRange(); 77 } 78 } 56 79 57 80 this->registerVariables(); … … 71 94 SUPER(Light, XMLPort, xmlelement, mode); 72 95 73 XMLPortParam(Light, "type", setTypeString, getTypeString, xmlelement, mode).defaultValues("point"); 74 XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "diffuse", setDiffuseColour, getDiffuseColour, xmlelement, mode, const ColourValue&); 75 XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "specular", setSpecularColour, getSpecularColour, xmlelement, mode, const ColourValue&); 76 XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "direction", setDirection, getDirection, xmlelement, mode, const Vector3&); 96 XMLPortParam(Light, "type", setTypeString, getTypeString, xmlelement, mode).defaultValues("point"); 97 XMLPortParam(Light, "diffuse", setDiffuseColour, getDiffuseColour, xmlelement, mode).defaultValues(ColourValue::White); 98 XMLPortParam(Light, "specular", setSpecularColour, getSpecularColour, xmlelement, mode).defaultValues(ColourValue::White); 99 XMLPortParam(Light, "attenuation", setAttenuation, getAttenuation, xmlelement, mode).defaultValues(Vector4(100000, 1, 0, 0)); 100 XMLPortParam(Light, "spotlightrange", setSpotlightRange, getSpotlightRange, xmlelement, mode).defaultValues(Vector3(40.0f, 30.0f, 1.0f)); 77 101 } 78 102 79 103 void Light::registerVariables() 80 104 { 81 REGISTERDATA(this->type_, direction::toclient, new NetworkCallback<Light>(this, &Light::changedType)); 82 REGISTERDATA(this->light_->getDiffuseColour(), direction::toclient); 83 REGISTERDATA(this->light_->getSpecularColour(), direction::toclient); 84 REGISTERDATA(this->light_->getDirection(), direction::toclient); 105 registerVariable((int&)this->type_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateType)); 106 registerVariable(this->diffuse_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateDiffuseColour)); 107 registerVariable(this->specular_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateSpecularColour)); 108 registerVariable(this->attenuation_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateAttenuation)); 109 registerVariable(this->spotlightRange_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateSpotlightRange)); 85 110 } 86 111 87 const std::string& Light::getName() const112 void Light::updateDiffuseColour() 88 113 { 89 114 if (this->light_) 90 return this->light_->getName(); 91 else 92 return BLANKSTRING; 115 this->light_->setDiffuseColour(this->diffuse_); 93 116 } 94 117 95 void Light:: setDiffuseColour(const ColourValue& colour)118 void Light::updateSpecularColour() 96 119 { 97 120 if (this->light_) 98 this->light_->set DiffuseColour(colour);121 this->light_->setSpecularColour(this->specular_); 99 122 } 100 123 101 const ColourValue& Light::getDiffuseColour() const124 void Light::updateAttenuation() 102 125 { 103 if (this->light_) 104 return this->light_->getDiffuseColour(); 105 else 106 return ColourValue::White; 126 if (this->light_ && this->type_ != Ogre::Light::LT_DIRECTIONAL) 127 this->light_->setAttenuation(this->attenuation_.x, this->attenuation_.y, this->attenuation_.z, this->attenuation_.w); 107 128 } 108 129 109 void Light:: setSpecularColour(const ColourValue& colour)130 void Light::updateSpotlightRange() 110 131 { 111 if (this->light_) 112 this->light_->setSpecularColour(colour); 113 } 114 115 const ColourValue& Light::getSpecularColour() const 116 { 117 if (this->light_) 118 return this->light_->getSpecularColour(); 119 else 120 return ColourValue::White; 121 } 122 123 void Light::setDirection(const Vector3& direction) 124 { 125 if (this->light_) 126 this->light_->setDirection(direction); 127 } 128 129 const Vector3& Light::getDirection() const 130 { 131 if (this->light_) 132 return this->light_->getDirection(); 133 else 134 return Vector3::ZERO; 132 if (this->light_ && this->type_ == Ogre::Light::LT_SPOTLIGHT) 133 this->light_->setSpotlightRange(Degree(this->spotlightRange_.x), Degree(this->spotlightRange_.y), this->spotlightRange_.z); 135 134 } 136 135 … … 157 156 case Ogre::Light::LT_POINT: 158 157 default: 159 return "poin T";158 return "point"; 160 159 } 161 160 } 162 161 163 void Light:: changedType()162 void Light::updateType() 164 163 { 165 this->light_->setType(this->type_); 164 if (this->light_) 165 { 166 this->light_->setType(this->type_); 167 168 if (this->type_ != Ogre::Light::LT_DIRECTIONAL) 169 this->updateAttenuation(); 170 if (this->type_ == Ogre::Light::LT_SPOTLIGHT) 171 this->updateSpotlightRange(); 172 } 166 173 } 167 174 … … 170 177 SUPER(Light, changedVisibility); 171 178 172 this->light_->setVisible(this->isVisible()); 179 if (this->light_) 180 this->light_->setVisible(this->isVisible()); 173 181 } 174 182 } -
code/trunk/src/orxonox/objects/worldentities/Light.h
r2087 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 35 35 #include <string> … … 40 40 namespace orxonox 41 41 { 42 class _OrxonoxExport Light : public PositionableEntity42 class _OrxonoxExport Light : public StaticEntity 43 43 { 44 44 public: … … 54 54 { return this->light_; } 55 55 56 const std::string& getName() const;57 58 56 inline void setType(Ogre::Light::LightTypes type) 59 { this->type_ = type; this-> changedType(); }60 Ogre::Light::LightTypes getType() const57 { this->type_ = type; this->updateType(); } 58 inline Ogre::Light::LightTypes getType() const 61 59 { return this->type_; } 62 60 63 void setDiffuseColour(const ColourValue& colour); 64 const ColourValue& getDiffuseColour() const; 61 inline void setDiffuseColour(const ColourValue& colour) 62 { this->diffuse_ = colour; this->updateDiffuseColour(); } 63 inline const ColourValue& getDiffuseColour() const 64 { return this->diffuse_; } 65 65 66 void setSpecularColour(const ColourValue& colour); 67 const ColourValue& getSpecularColour() const; 66 inline void setSpecularColour(const ColourValue& colour) 67 { this->specular_ = colour; this->updateSpecularColour(); } 68 inline const ColourValue& getSpecularColour() const 69 { return this->specular_; } 68 70 69 void setDirection(const Vector3& direction); 70 const Vector3& getDirection() const; 71 /** 72 @brief Sets the attenuation parameters of the light source i.e. how it diminishes with distance. 73 74 @param attenuation.x range (The absolute upper range of the light in world units) 75 @param attenuation.y constant (The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation) 76 @param attenuation.z linear (The linear factor in the attenuation formula: 1 means attenuate evenly over the distance) 77 @param attenuation.w quadratic (The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula) 78 79 Quote from the Ogre API: 80 Lights normally get fainter the further they are away. Also, each light is given a maximum range beyond which it cannot affect any objects. 81 Light attenuation is not applicable to directional lights since they have an infinite range and constant intensity. 82 This follows a standard attenuation approach - see any good 3D text for the details of what they mean since i don't have room here! 83 84 Quote from the Ogre wiki: 85 "Using these numbers, the light has 100% intensity at 0 distance, and 86 trails off to near black at a distance equal to the Range. Keep in mind 87 that most of the light falls in the first 20% of the range." 88 89 Range Constant Linear Quadratic 90 3250, 1.0, 0.0014, 0.000007 91 600, 1.0, 0.007, 0.0002 92 325, 1.0, 0.014, 0.0007 93 200, 1.0, 0.022, 0.0019 94 160, 1.0, 0.027, 0.0028 95 100, 1.0, 0.045, 0.0075 96 65, 1.0, 0.07, 0.017 97 50, 1.0, 0.09, 0.032 98 32, 1.0, 0.14, 0.07 99 20, 1.0, 0.22, 0.20 100 13, 1.0, 0.35, 0.44 101 7, 1.0, 0.7, 1.8 102 */ 103 inline void setAttenuation(const Vector4& attenuation) 104 { this->attenuation_ = attenuation; this->updateAttenuation(); } 105 inline const Vector4& getAttenuation() const 106 { return this->attenuation_; } 107 108 /** 109 @brief Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them. 110 111 @param spotlightRange.x innerAngle (The angle covered by the bright inner cone) 112 @param spotlightRange.x outerAngle (The angle covered by the outer cone) 113 @param spotlightRange.x falloff (The rate of falloff between the inner and outer cones. 1.0 means a linear falloff, less means slower falloff, higher means faster falloff.) 114 */ 115 inline void setSpotlightRange(const Vector3& spotlightRange) 116 { this->spotlightRange_ = spotlightRange; this->updateSpotlightRange(); } 117 inline const Vector3& getSpotlightRange() const 118 { return this->spotlightRange_; } 71 119 72 120 private: … … 74 122 std::string getTypeString() const; 75 123 76 void changedType(); 124 void updateType(); 125 void updateDiffuseColour(); 126 void updateSpecularColour(); 127 void updateAttenuation(); 128 void updateSpotlightRange(); 77 129 78 static unsigned int lightCounter_s;79 130 Ogre::Light* light_; 80 131 Ogre::Light::LightTypes type_; 81 132 ColourValue diffuse_; 133 ColourValue specular_; 134 Vector4 attenuation_; 135 Vector3 spotlightRange_; 82 136 }; 83 137 } -
code/trunk/src/orxonox/objects/worldentities/MobileEntity.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/MobileEntity.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/Model.cc
r2171 r2662 29 29 #include "OrxonoxStableHeaders.h" 30 30 31 #include <OgreEntity.h> 31 32 #include "Model.h" 32 33 #include "core/CoreIncludes.h" … … 38 39 CreateFactory(Model); 39 40 40 Model::Model(BaseObject* creator) : PositionableEntity(creator)41 Model::Model(BaseObject* creator) : StaticEntity(creator) 41 42 { 42 43 RegisterObject(Model); 44 45 this->bCastShadows_ = true; 43 46 44 47 this->registerVariables(); … … 48 51 { 49 52 if (this->isInitialized() && this->mesh_.getEntity()) 50 this-> getNode()->detachObject(this->mesh_.getEntity());53 this->detachOgreObject(this->mesh_.getEntity()); 51 54 } 52 55 … … 61 64 void Model::registerVariables() 62 65 { 63 REGISTERSTRING(this->meshSrc_, direction::toclient, new NetworkCallback<Model>(this, &Model::changedMesh));64 REGISTERDATA(this->bCastShadows_, direction::toclient, new NetworkCallback<Model>(this, &Model::changedShadows));66 registerVariable(this->meshSrc_, variableDirection::toclient, new NetworkCallback<Model>(this, &Model::changedMesh)); 67 registerVariable(this->bCastShadows_, variableDirection::toclient, new NetworkCallback<Model>(this, &Model::changedShadows)); 65 68 } 66 69 67 70 void Model::changedMesh() 68 71 { 69 if (this->mesh_.getEntity()) 70 this->getNode()->detachObject(this->mesh_.getEntity()); 72 if (Core::showsGraphics()) 73 { 74 if (this->mesh_.getEntity()) 75 this->detachOgreObject(this->mesh_.getEntity()); 71 76 72 this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);77 this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_); 73 78 74 if (this->mesh_.getEntity()) 75 { 76 this->getNode()->attachObject(this->mesh_.getEntity()); 77 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_); 78 this->mesh_.setVisible(this->isVisible()); 79 if (this->mesh_.getEntity()) 80 { 81 this->attachOgreObject(this->mesh_.getEntity()); 82 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_); 83 this->mesh_.setVisible(this->isVisible()); 84 } 79 85 } 80 86 } -
code/trunk/src/orxonox/objects/worldentities/Model.h
r2087 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 #include "tools/Mesh.h" 35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport Model : public PositionableEntity38 class _OrxonoxExport Model : public StaticEntity 39 39 { 40 40 public: … … 70 70 } 71 71 72 #endif /* _ PositionableEntity_H__ */72 #endif /* _Model_H__ */ -
code/trunk/src/orxonox/objects/worldentities/MovableEntity.cc
r2171 r2662 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 33 34 #include "core/XMLPort.h" 34 35 #include "core/Executor.h" 35 #include " tools/Timer.h"36 #include "core/Core.h" 36 37 37 38 namespace orxonox 38 39 { 39 40 static const float MAX_RESYNCHRONIZE_TIME = 3.0f; 41 static const float CONTINUOUS_SYNCHRONIZATION_TIME = 10.0f; 40 42 41 43 CreateFactory(MovableEntity); 42 44 43 MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator)45 MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator) 44 46 { 45 47 RegisterObject(MovableEntity); 46 48 47 this->velocity_ = Vector3::ZERO; 48 this->acceleration_ = Vector3::ZERO; 49 this->rotationAxis_ = Vector3::ZERO; 50 this->rotationRate_ = 0; 51 this->momentum_ = 0; 49 this->overwrite_position_ = Vector3::ZERO; 50 this->overwrite_orientation_ = Quaternion::IDENTITY; 52 51 53 this->overwrite_position_ = Vector3::ZERO; 54 this->overwrite_orientation_ = Quaternion::IDENTITY; 52 this->continuousResynchroTimer_ = 0; 53 54 this->setPriority(priority::low); 55 55 56 56 this->registerVariables(); … … 59 59 MovableEntity::~MovableEntity() 60 60 { 61 if (this->isInitialized()) 62 if (this->continuousResynchroTimer_) 63 delete this->continuousResynchroTimer_; 61 64 } 62 65 … … 64 67 { 65 68 SUPER(MovableEntity, XMLPort, xmlelement, mode); 66 67 XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);68 XMLPortParamTemplate(MovableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);69 XMLPortParamTemplate(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&);70 }71 72 void MovableEntity::tick(float dt)73 {74 if (this->isActive())75 {76 this->velocity_ += (dt * this->acceleration_);77 this->node_->translate(dt * this->velocity_);78 79 this->rotationRate_ += (dt * this->momentum_);80 this->node_->rotate(this->rotationAxis_, this->rotationRate_ * dt);81 }82 69 } 83 70 84 71 void MovableEntity::registerVariables() 85 72 { 86 REGISTERDATA(this->velocity_.x, direction::toclient); 87 REGISTERDATA(this->velocity_.y, direction::toclient); 88 REGISTERDATA(this->velocity_.z, direction::toclient); 73 registerVariable(this->linearVelocity_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity)); 74 registerVariable(this->angularVelocity_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity)); 89 75 90 REGISTERDATA(this->rotationAxis_.x, direction::toclient); 91 REGISTERDATA(this->rotationAxis_.y, direction::toclient); 92 REGISTERDATA(this->rotationAxis_.z, direction::toclient); 93 94 REGISTERDATA(this->rotationRate_, direction::toclient); 95 96 REGISTERDATA(this->overwrite_position_, direction::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition)); 97 REGISTERDATA(this->overwrite_orientation_, direction::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation)); 98 } 99 100 void MovableEntity::overwritePosition() 101 { 102 this->node_->setPosition(this->overwrite_position_); 103 } 104 105 void MovableEntity::overwriteOrientation() 106 { 107 this->node_->setOrientation(this->overwrite_orientation_); 76 registerVariable(this->overwrite_position_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition)); 77 registerVariable(this->overwrite_orientation_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation)); 108 78 } 109 79 110 80 void MovableEntity::clientConnected(unsigned int clientID) 111 81 { 112 new Timer<MovableEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), true);82 this->resynchronizeTimer_.setTimer(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&MovableEntity::resynchronize))); 113 83 } 114 84 … … 119 89 void MovableEntity::resynchronize() 120 90 { 91 if (Core::isMaster() && !this->continuousResynchroTimer_) 92 { 93 // Resynchronise every few seconds because we only work with velocities (no positions) 94 continuousResynchroTimer_ = new Timer<MovableEntity>(CONTINUOUS_SYNCHRONIZATION_TIME + rnd(-1, 1), 95 true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false); 96 } 97 121 98 this->overwrite_position_ = this->getPosition(); 122 99 this->overwrite_orientation_ = this->getOrientation(); 123 100 } 124 125 void MovableEntity::setPosition(const Vector3& position)126 {127 this->node_->setPosition(position);128 this->overwrite_position_ = this->node_->getPosition();129 }130 131 void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)132 {133 this->node_->translate(distance, relativeTo);134 this->overwrite_position_ = this->node_->getPosition();135 }136 137 void MovableEntity::setOrientation(const Quaternion& orientation)138 {139 this->node_->setOrientation(orientation);140 this->overwrite_orientation_ = this->node_->getOrientation();141 }142 143 void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)144 {145 this->node_->rotate(rotation, relativeTo);146 this->overwrite_orientation_ = this->node_->getOrientation();147 }148 149 void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)150 {151 this->node_->yaw(angle, relativeTo);152 this->overwrite_orientation_ = this->node_->getOrientation();153 }154 155 void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)156 {157 this->node_->pitch(angle, relativeTo);158 this->overwrite_orientation_ = this->node_->getOrientation();159 }160 161 void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)162 {163 this->node_->roll(angle, relativeTo);164 this->overwrite_orientation_ = this->node_->getOrientation();165 }166 167 void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)168 {169 this->node_->lookAt(target, relativeTo, localDirectionVector);170 this->overwrite_orientation_ = this->node_->getOrientation();171 }172 173 void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)174 {175 this->node_->setDirection(direction, relativeTo, localDirectionVector);176 this->overwrite_orientation_ = this->node_->getOrientation();177 }178 101 } -
code/trunk/src/orxonox/objects/worldentities/MovableEntity.h
r2171 r2662 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 32 33 #include "OrxonoxPrereqs.h" 33 34 34 #include "WorldEntity.h" 35 #include "objects/Tickable.h" 35 #include "MobileEntity.h" 36 36 #include "network/ClientConnectionListener.h" 37 #include "tools/Timer.h" 37 38 38 39 namespace orxonox 39 40 { 40 class _OrxonoxExport MovableEntity : public WorldEntity, public Tickable, public ClientConnectionListener41 class _OrxonoxExport MovableEntity : public MobileEntity, public ClientConnectionListener 41 42 { 42 43 public: … … 45 46 46 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 virtual void tick(float dt);48 48 void registerVariables(); 49 49 50 50 using WorldEntity::setPosition; 51 using WorldEntity::translate;52 51 using WorldEntity::setOrientation; 53 using WorldEntity::rotate;54 using WorldEntity::yaw;55 using WorldEntity::pitch;56 using WorldEntity::roll;57 using WorldEntity::lookAt;58 using WorldEntity::setDirection;59 52 60 void setPosition(const Vector3& position); 61 void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 62 void setOrientation(const Quaternion& orientation); 63 void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 64 void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 65 void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 66 void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 67 void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 68 void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 69 70 inline void setVelocity(const Vector3& velocity) 71 { this->velocity_ = velocity; } 72 inline void setVelocity(float x, float y, float z) 73 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; } 74 inline const Vector3& getVelocity() const 75 { return this->velocity_; } 76 77 inline void setAcceleration(const Vector3& acceleration) 78 { this->acceleration_ = acceleration; } 79 inline void setAcceleration(float x, float y, float z) 80 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; } 81 inline const Vector3& getAcceleration() const 82 { return this->acceleration_; } 83 84 inline void setRotationAxis(const Vector3& axis) 85 { this->rotationAxis_ = axis; this->rotationAxis_.normalise(); } 86 inline void setRotationAxis(float x, float y, float z) 87 { this->rotationAxis_.x = x; this->rotationAxis_.y = y; this->rotationAxis_.z = z; rotationAxis_.normalise(); } 88 inline const Vector3& getRotationAxis() const 89 { return this->rotationAxis_; } 90 91 inline void setRotationRate(const Degree& angle) 92 { this->rotationRate_ = angle; } 93 inline void setRotationRate(const Radian& angle) 94 { this->rotationRate_ = angle; } 95 inline const Degree& getRotationRate() const 96 { return this->rotationRate_; } 97 98 inline void setMomentum(const Degree& angle) 99 { this->momentum_ = angle; } 100 inline void setMomentum(const Radian& angle) 101 { this->momentum_ = angle; } 102 inline const Degree& getMomentum() const 103 { return this->momentum_; } 53 inline void setPosition(const Vector3& position) 54 { MobileEntity::setPosition(position); this->overwrite_position_ = this->getPosition(); } 55 inline void setOrientation(const Quaternion& orientation) 56 { MobileEntity::setOrientation(orientation); this->overwrite_orientation_ = this->getOrientation(); } 104 57 105 58 private: … … 108 61 void resynchronize(); 109 62 110 void overwritePosition(); 111 void overwriteOrientation(); 63 inline void processLinearVelocity() 64 { this->setVelocity(this->linearVelocity_); } 65 inline void processAngularVelocity() 66 { this->setAngularVelocity(this->angularVelocity_); } 112 67 113 Vector3 velocity_; 114 Vector3 acceleration_; 115 Vector3 rotationAxis_; 116 Degree rotationRate_; 117 Degree momentum_; 68 inline void overwritePosition() 69 { this->setPosition(this->overwrite_position_); } 70 inline void overwriteOrientation() 71 { this->setOrientation(this->overwrite_orientation_); } 118 72 119 Vector3 overwrite_position_;73 Vector3 overwrite_position_; 120 74 Quaternion overwrite_orientation_; 75 76 Timer<MovableEntity> resynchronizeTimer_; 77 Timer<MovableEntity>* continuousResynchroTimer_; 121 78 }; 122 79 } -
code/trunk/src/orxonox/objects/worldentities/ParticleEmitter.cc
r2171 r2662 33 33 34 34 #include "OrxonoxStableHeaders.h" 35 #include "ParticleEmitter.h" 35 36 36 #include "ParticleEmitter.h"37 #include <OgreParticleSystem.h> 37 38 38 39 #include "tools/ParticleInterface.h" … … 46 47 CreateFactory(ParticleEmitter); 47 48 48 ParticleEmitter::ParticleEmitter(BaseObject* creator) : PositionableEntity(creator)49 ParticleEmitter::ParticleEmitter(BaseObject* creator) : StaticEntity(creator) 49 50 { 50 51 RegisterObject(ParticleEmitter); 51 52 52 if ( !this->getScene() || !this->getScene()->getSceneManager())53 ThrowException(AbortLoading, "Can't create Camera, no scene or no scene manager given.");53 if (Core::showsGraphics() && (!this->getScene() || !this->getScene()->getSceneManager())) 54 ThrowException(AbortLoading, "Can't create ParticleEmitter, no scene or no scene manager given."); 54 55 55 56 this->particles_ = 0; … … 62 63 { 63 64 if (this->isInitialized() && this->particles_) 65 { 66 this->detachOgreObject(this->particles_->getParticleSystem()); 64 67 delete this->particles_; 68 } 65 69 } 66 70 … … 75 79 void ParticleEmitter::registerVariables() 76 80 { 77 REGISTERSTRING(this->source_, direction::toclient, new NetworkCallback<ParticleEmitter>(this, &ParticleEmitter::sourceChanged));78 REGISTERDATA (this->LOD_, direction::toclient, new NetworkCallback<ParticleEmitter>(this, &ParticleEmitter::LODchanged));81 registerVariable(this->source_, variableDirection::toclient, new NetworkCallback<ParticleEmitter>(this, &ParticleEmitter::sourceChanged)); 82 registerVariable((int&)(this->LOD_), variableDirection::toclient, new NetworkCallback<ParticleEmitter>(this, &ParticleEmitter::LODchanged)); 79 83 } 80 84 … … 98 102 { 99 103 if (this->particles_) 104 { 100 105 delete this->particles_; 106 this->particles_ = 0; 107 } 101 108 102 if ( this->getScene() && this->getScene()->getSceneManager())109 if (Core::showsGraphics() && this->getScene() && this->getScene()->getSceneManager()) 103 110 { 104 111 try 105 112 { 106 113 this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), this->source_, this->LOD_); 107 this-> particles_->addToSceneNode(this->getNode());114 this->attachOgreObject(this->particles_->getParticleSystem()); 108 115 this->particles_->setVisible(this->isVisible()); 109 116 this->particles_->setEnabled(this->isActive()); … … 115 122 } 116 123 } 117 else118 this->particles_ = 0;119 124 } 120 125 -
code/trunk/src/orxonox/objects/worldentities/ParticleEmitter.h
r2087 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport ParticleEmitter : public PositionableEntity37 class _OrxonoxExport ParticleEmitter : public StaticEntity 38 38 { 39 39 public: -
code/trunk/src/orxonox/objects/worldentities/ParticleSpawner.cc
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/ParticleSpawner.h
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/SpawnPoint.cc
r2087 r2662 38 38 CreateFactory(SpawnPoint); 39 39 40 SpawnPoint::SpawnPoint(BaseObject* creator) : PositionableEntity(creator)40 SpawnPoint::SpawnPoint(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(SpawnPoint); -
code/trunk/src/orxonox/objects/worldentities/SpawnPoint.h
r2087 r2662 34 34 #include "core/Identifier.h" 35 35 #include "core/Template.h" 36 #include "PositionableEntity.h"37 36 #include "objects/worldentities/pawns/Pawn.h" 37 #include "objects/worldentities/StaticEntity.h" 38 38 39 39 namespace orxonox 40 40 { 41 class _OrxonoxExport SpawnPoint : public PositionableEntity41 class _OrxonoxExport SpawnPoint : public StaticEntity 42 42 { 43 43 public: -
code/trunk/src/orxonox/objects/worldentities/StaticEntity.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/StaticEntity.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/orxonox/objects/worldentities/WorldEntity.cc
r2171 r2662 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder (physics) 24 25 * Co-authors: 25 26 * ... … … 31 32 32 33 #include <cassert> 34 #include <OgreSceneNode.h> 33 35 #include <OgreSceneManager.h> 34 36 #include "BulletDynamics/Dynamics/btRigidBody.h" 37 38 #include "util/Exception.h" 39 #include "util/Convert.h" 35 40 #include "core/CoreIncludes.h" 36 41 #include "core/XMLPort.h" 37 #include "util/Convert.h"38 #include "util/Exception.h"39 42 40 43 #include "objects/Scene.h" 44 #include "objects/collisionshapes/WorldEntityCollisionShape.h" 41 45 42 46 namespace orxonox … … 49 53 const Vector3 WorldEntity::UP = Vector3::UNIT_Y; 50 54 55 /** 56 @brief 57 Creates a new WorldEntity that may immediately be used. 58 All the default values are being set here. 59 */ 51 60 WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) 52 61 { … … 64 73 this->node_->setOrientation(Quaternion::IDENTITY); 65 74 75 76 // Default behaviour does not include physics 77 this->physicalBody_ = 0; 78 this->bPhysicsActive_ = false; 79 this->bPhysicsActiveSynchronised_ = false; 80 this->bPhysicsActiveBeforeAttaching_ = false; 81 this->collisionShape_ = new WorldEntityCollisionShape(this); 82 this->collisionType_ = None; 83 this->collisionTypeSynchronised_ = None; 84 this->mass_ = 0; 85 this->childrenMass_ = 0; 86 // Using bullet default values 87 this->restitution_ = 0; 88 this->angularFactor_ = 1; 89 this->linearDamping_ = 0; 90 this->angularDamping_ = 0; 91 this->friction_ = 0.5; 92 this->bCollisionCallbackActive_ = false; 93 this->bCollisionResponseActive_ = true; 94 66 95 this->registerVariables(); 67 96 } 68 97 98 /** 99 @brief 100 Destroys the WorldEntity AND ALL its children with it. 101 */ 69 102 WorldEntity::~WorldEntity() 70 103 { 71 104 if (this->isInitialized()) 72 105 { 106 if (this->parent_) 107 this->detachFromParent(); 108 109 for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ) 110 delete (*(it++)); 111 112 if (this->physicalBody_) 113 { 114 this->deactivatePhysics(); 115 delete this->physicalBody_; 116 } 117 delete this->collisionShape_; 118 73 119 this->node_->detachAllObjects(); 74 if (this->getScene()->getSceneManager()) 75 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); 120 this->node_->removeAllChildren(); 121 122 OrxAssert(this->getScene()->getSceneManager(), "No SceneManager defined in a WorldEntity."); 123 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); 76 124 } 77 125 } … … 81 129 SUPER(WorldEntity, XMLPort, xmlelement, mode); 82 130 83 XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition,xmlelement, mode, const Vector3&);131 XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition, xmlelement, mode, const Vector3&); 84 132 XMLPortParamTemplate(WorldEntity, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&); 85 XMLPortParamLoadOnly(WorldEntity, "lookat", lookAt_xmlport, xmlelement, mode); 86 XMLPortParamLoadOnly(WorldEntity, "direction", setDirection_xmlport, xmlelement, mode); 87 XMLPortParamLoadOnly(WorldEntity, "yaw", yaw_xmlport, xmlelement, mode); 88 XMLPortParamLoadOnly(WorldEntity, "pitch", pitch_xmlport, xmlelement, mode); 89 XMLPortParamLoadOnly(WorldEntity, "roll", roll_xmlport, xmlelement, mode); 90 XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 91 XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode); 92 133 XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 134 XMLPortParam (WorldEntity, "scale", setScale, getScale, xmlelement, mode); 135 XMLPortParamLoadOnly(WorldEntity, "lookat", lookAt_xmlport, xmlelement, mode); 136 XMLPortParamLoadOnly(WorldEntity, "direction", setDirection_xmlport, xmlelement, mode); 137 XMLPortParamLoadOnly(WorldEntity, "yaw", yaw_xmlport, xmlelement, mode); 138 XMLPortParamLoadOnly(WorldEntity, "pitch", pitch_xmlport, xmlelement, mode); 139 XMLPortParamLoadOnly(WorldEntity, "roll", roll_xmlport, xmlelement, mode); 140 141 // Physics 142 XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode); 143 XMLPortParam(WorldEntity, "collisionResponse", setCollisionResponse, hasCollisionResponse, xmlelement, mode); 144 XMLPortParam(WorldEntity, "mass", setMass, getMass, xmlelement, mode); 145 XMLPortParam(WorldEntity, "restitution", setRestitution, getRestitution, xmlelement, mode); 146 XMLPortParam(WorldEntity, "angularFactor", setAngularFactor, getAngularFactor, xmlelement, mode); 147 XMLPortParam(WorldEntity, "linearDamping", setLinearDamping, getLinearDamping, xmlelement, mode); 148 XMLPortParam(WorldEntity, "angularDamping", setAngularDamping, getAngularDamping, xmlelement, mode); 149 XMLPortParam(WorldEntity, "friction", setFriction, getFriction, xmlelement, mode); 150 151 // Other attached WorldEntities 93 152 XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode); 153 // Attached collision shapes 154 XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode); 94 155 } 95 156 96 157 void WorldEntity::registerVariables() 97 158 { 98 REGISTERDATA(this->bActive_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity)); 99 REGISTERDATA(this->bVisible_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility)); 100 101 REGISTERDATA(this->getScale3D().x, direction::toclient); 102 REGISTERDATA(this->getScale3D().y, direction::toclient); 103 REGISTERDATA(this->getScale3D().z, direction::toclient); 104 105 REGISTERDATA(this->parentID_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::updateParent)); 106 } 107 108 void WorldEntity::updateParent() 159 registerVariable(this->mainStateName_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainState)); 160 161 registerVariable(this->bActive_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity)); 162 registerVariable(this->bVisible_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility)); 163 164 registerVariable(this->getScale3D(), variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged)); 165 166 // Physics stuff 167 registerVariable(this->mass_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged)); 168 registerVariable(this->restitution_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::restitutionChanged)); 169 registerVariable(this->angularFactor_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::angularFactorChanged)); 170 registerVariable(this->linearDamping_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::linearDampingChanged)); 171 registerVariable(this->angularDamping_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::angularDampingChanged)); 172 registerVariable(this->friction_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::frictionChanged)); 173 registerVariable(this->bCollisionCallbackActive_, 174 variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionCallbackActivityChanged)); 175 registerVariable(this->bCollisionResponseActive_, 176 variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionResponseActivityChanged)); 177 registerVariable((int&)this->collisionTypeSynchronised_, 178 variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged)); 179 registerVariable(this->bPhysicsActiveSynchronised_, 180 variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::physicsActivityChanged)); 181 182 // Attach to parent if necessary 183 registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::parentChanged)); 184 } 185 186 /** 187 @brief 188 Network function that object this instance to its correct parent. 189 */ 190 void WorldEntity::parentChanged() 109 191 { 110 192 if (this->parentID_ != OBJECTID_UNKNOWN) … … 116 198 } 117 199 200 /** 201 @brief 202 Attaches this object to a parent SceneNode. 203 @Remarks 204 Only use this method if you know exactly what you're doing! 205 Normally, attaching works internally by attaching WE's. 206 */ 207 void WorldEntity::attachToNode(Ogre::SceneNode* node) 208 { 209 Ogre::Node* parent = this->node_->getParent(); 210 if (parent) 211 parent->removeChild(this->node_); 212 node->addChild(this->node_); 213 } 214 215 /** 216 @brief 217 Detaches this object from a parent SceneNode. 218 @Remarks 219 Only use this method if you know exactly what you're doing! 220 Normally, attaching works internally by attaching WE's. 221 */ 222 void WorldEntity::detachFromNode(Ogre::SceneNode* node) 223 { 224 node->removeChild(this->node_); 225 // this->getScene()->getRootSceneNode()->addChild(this->node_); 226 } 227 228 /** 229 @brief 230 Network callback for the collision type. Only change the type if it was valid. 231 */ 232 void WorldEntity::collisionTypeChanged() 233 { 234 if (this->collisionTypeSynchronised_ != Dynamic && 235 this->collisionTypeSynchronised_ != Kinematic && 236 this->collisionTypeSynchronised_ != Static && 237 this->collisionTypeSynchronised_ != None) 238 { 239 CCOUT(1) << "Error when collsion Type was received over network. Unknown enum value:" << this->collisionTypeSynchronised_ << std::endl; 240 } 241 else if (this->collisionTypeSynchronised_ != collisionType_) 242 { 243 if (this->parent_) 244 CCOUT(2) << "Warning: Network connection tried to set the collision type of an attached WE. Ignoring." << std::endl; 245 else 246 this->setCollisionType(this->collisionTypeSynchronised_); 247 } 248 } 249 250 //! Network callback for this->bPhysicsActive_ 251 void WorldEntity::physicsActivityChanged() 252 { 253 if (this->bPhysicsActiveSynchronised_) 254 this->activatePhysics(); 255 else 256 this->deactivatePhysics(); 257 } 258 259 //! Function sets whether Bullet should issue a callback on collisions 260 void WorldEntity::collisionCallbackActivityChanged() 261 { 262 if (this->hasPhysics()) 263 { 264 if (this->bCollisionCallbackActive_) 265 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() | 266 btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); 267 else 268 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & 269 ~btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); 270 } 271 } 272 273 //! Function sets whether Bullet should react itself to a collision 274 void WorldEntity::collisionResponseActivityChanged() 275 { 276 if (this->hasPhysics()) 277 { 278 if (this->bCollisionResponseActive_) 279 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & 280 ~btCollisionObject::CF_NO_CONTACT_RESPONSE); 281 else 282 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() | 283 btCollisionObject::CF_NO_CONTACT_RESPONSE); 284 } 285 } 286 287 /** 288 @brief 289 Attaches a child WorldEntity to this object. This calls notifyBeingAttached() 290 of the child WE. 291 @Note 292 The collision shape of the child object gets attached nevertheless. That also means 293 that you can change the collision shape of the child and it correctly cascadeds the changes to this instance. 294 Be aware of this implication: When implementing attaching of kinematic objects to others, you have to change 295 this behaviour because you then might not want to merge the collision shapes. 296 */ 118 297 void WorldEntity::attach(WorldEntity* object) 119 298 { 120 if (object ->getParent())121 object->detachFromParent();122 else123 {124 Ogre::Node* parent = object->node_->getParent();125 if (parent) 126 parent->removeChild(object->node_);127 }128 129 this-> node_->addChild(object->node_);299 if (object == this) 300 { 301 COUT(2) << "Warning: Can't attach a WorldEntity to itself." << std::endl; 302 return; 303 } 304 305 if (!object->notifyBeingAttached(this)) 306 return; 307 308 this->attachNode(object->node_); 130 309 this->children_.insert(object); 131 object->parent_ = this; 132 object->parentID_ = this->getObjectID(); 133 } 134 310 311 this->attachCollisionShape(object->collisionShape_); 312 // mass 313 this->childrenMass_ += object->getMass(); 314 recalculateMassProps(); 315 } 316 317 /** 318 @brief 319 Function gets called when this object is being attached to a new parent. 320 321 This operation is only allowed if the collision types "like" each other. 322 - You cannot a attach a non physical object to a physical one. 323 - Dynamic object can NOT be attached at all. 324 - It is also not possible to attach a kinematic to a dynamic one. 325 - Attaching of kinematic objects otherwise is not yet supported. 326 */ 327 bool WorldEntity::notifyBeingAttached(WorldEntity* newParent) 328 { 329 // check first whether attaching is even allowed 330 if (this->hasPhysics()) 331 { 332 if (!newParent->hasPhysics()) 333 { 334 COUT(2) << "Warning: Cannot attach a physical object to a non physical one." << std::endl; 335 return false; 336 } 337 else if (this->isDynamic()) 338 { 339 COUT(2) << "Warning: Cannot attach a dynamic object to a WorldEntity." << std::endl; 340 return false; 341 } 342 else if (this->isKinematic() && newParent->isDynamic()) 343 { 344 COUT(2) << "Warning: Cannot attach a kinematic object to a dynamic one." << std::endl; 345 return false; 346 } 347 else if (this->isKinematic()) 348 { 349 COUT(2) << "Warning: Cannot attach a kinematic object to a static or kinematic one: Not yet implemented." << std::endl; 350 return false; 351 } 352 } 353 354 if (this->isPhysicsActive()) 355 this->bPhysicsActiveBeforeAttaching_ = true; 356 this->deactivatePhysics(); 357 358 if (this->parent_) 359 this->detachFromParent(); 360 361 this->parent_ = newParent; 362 this->parentID_ = newParent->getObjectID(); 363 364 // apply transform to collision shape 365 this->collisionShape_->setPosition(this->getPosition()); 366 this->collisionShape_->setOrientation(this->getOrientation()); 367 // TODO: Scale 368 369 return true; 370 } 371 372 /** 373 @brief 374 Detaches a child WorldEntity from this instance. 375 */ 135 376 void WorldEntity::detach(WorldEntity* object) 136 377 { 137 this->node_->removeChild(object->node_); 378 if (this->children_.find(object) == this->children_.end()) 379 { 380 CCOUT(2) << "Warning: Cannot detach an object that is not a child." << std::endl; 381 return; 382 } 383 384 // collision shapes 385 this->detachCollisionShape(object->collisionShape_); 386 387 // mass 388 if (object->getMass() > 0.0f) 389 { 390 this->childrenMass_ -= object->getMass(); 391 recalculateMassProps(); 392 } 393 394 this->detachNode(object->node_); 138 395 this->children_.erase(object); 139 object->parent_ = 0; 140 object->parentID_ = OBJECTID_UNKNOWN; 141 142 // this->getScene()->getRootSceneNode()->addChild(object->node_); 143 } 144 145 WorldEntity* WorldEntity::getAttachedObject(unsigned int index) const 396 397 object->notifyDetached(); 398 } 399 400 /** 401 @brief 402 Function gets called when the object has been detached from its parent. 403 */ 404 void WorldEntity::notifyDetached() 405 { 406 this->parent_ = 0; 407 this->parentID_ = OBJECTID_UNKNOWN; 408 409 // reset orientation of the collisionShape (cannot be set within a WE usually) 410 this->collisionShape_->setPosition(Vector3::ZERO); 411 this->collisionShape_->setOrientation(Quaternion::IDENTITY); 412 // TODO: Scale 413 414 if (this->bPhysicsActiveBeforeAttaching_) 415 { 416 this->activatePhysics(); 417 this->bPhysicsActiveBeforeAttaching_ = false; 418 } 419 } 420 421 //! Returns an attached object (merely for XMLPort). 422 WorldEntity* WorldEntity::getAttachedObject(unsigned int index) 146 423 { 147 424 unsigned int i = 0; … … 154 431 return 0; 155 432 } 433 434 //! Attaches an Ogre::SceneNode to this WorldEntity. 435 void WorldEntity::attachNode(Ogre::SceneNode* node) 436 { 437 Ogre::Node* parent = node->getParent(); 438 if (parent) 439 parent->removeChild(node); 440 this->node_->addChild(node); 441 } 442 443 //! Detaches an Ogre::SceneNode from this WorldEntity. 444 void WorldEntity::detachNode(Ogre::SceneNode* node) 445 { 446 this->node_->removeChild(node); 447 // this->getScene()->getRootSceneNode()->addChild(node); 448 } 449 450 //! Attaches an Ogre::MovableObject to this WorldEntity. 451 void WorldEntity::attachOgreObject(Ogre::MovableObject* object) 452 { 453 this->node_->attachObject(object); 454 } 455 456 //! Detaches an Ogre::MovableObject from this WorldEntity. 457 void WorldEntity::detachOgreObject(Ogre::MovableObject* object) 458 { 459 this->node_->detachObject(object); 460 } 461 462 //! Detaches an Ogre::MovableObject (by string) from this WorldEntity. 463 Ogre::MovableObject* WorldEntity::detachOgreObject(const Ogre::String& name) 464 { 465 return this->node_->detachObject(name); 466 } 467 468 //! Attaches a collision Shape to this object (delegated to the internal CompoundCollisionShape) 469 void WorldEntity::attachCollisionShape(CollisionShape* shape) 470 { 471 this->collisionShape_->attach(shape); 472 // Note: this->collisionShape_ already notifies us of any changes. 473 } 474 475 //! Detaches a collision Shape from this object (delegated to the internal CompoundCollisionShape) 476 void WorldEntity::detachCollisionShape(CollisionShape* shape) 477 { 478 // Note: The collision shapes may not be detached with this function! 479 this->collisionShape_->detach(shape); 480 // Note: this->collisionShape_ already notifies us of any changes. 481 } 482 483 //! Returns an attached collision Shape of this object (delegated to the internal CompoundCollisionShape) 484 CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index) 485 { 486 return this->collisionShape_->getAttachedShape(index); 487 } 488 489 // Note: These functions are placed in WorldEntity.h as inline functions for the release build. 490 #ifndef _NDEBUG 491 const Vector3& WorldEntity::getPosition() const 492 { 493 return this->node_->getPosition(); 494 } 495 496 const Quaternion& WorldEntity::getOrientation() const 497 { 498 return this->node_->getOrientation(); 499 } 500 501 const Vector3& WorldEntity::getScale3D() const 502 { 503 return this->node_->getScale(); 504 } 505 #endif 506 507 //! Returns the position relative to the root space 508 const Vector3& WorldEntity::getWorldPosition() const 509 { 510 return this->node_->_getDerivedPosition(); 511 } 512 513 //! Returns the orientation relative to the root space 514 const Quaternion& WorldEntity::getWorldOrientation() const 515 { 516 return this->node_->_getDerivedOrientation(); 517 } 518 519 //! Returns the scaling applied relative to the root space in 3 coordinates 520 const Vector3& WorldEntity::getWorldScale3D() const 521 { 522 return this->node_->_getDerivedScale(); 523 } 524 525 /** 526 @brief 527 Returns the scaling applied relative to the root space in 3 coordinates 528 @return 529 Returns the scaling if it is uniform, 1.0f otherwise. 530 */ 531 float WorldEntity::getWorldScale() const 532 { 533 Vector3 scale = this->getWorldScale3D(); 534 return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; 535 } 536 537 /** 538 @brief 539 Sets the three dimensional scaling of this object. 540 @Note 541 Scaling physical objects has not yet been implemented and is therefore forbidden. 542 */ 543 void WorldEntity::setScale3D(const Vector3& scale) 544 { 545 /* 546 HACK HACK HACK 547 if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE) 548 { 549 CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl; 550 return; 551 } 552 HACK HACK HACK 553 */ 554 this->node_->setScale(scale); 555 556 this->changedScale(); 557 } 558 559 /** 560 @brief 561 Translates this WorldEntity by a vector. 562 @param relativeTo 563 @see TransformSpace::Enum 564 */ 565 void WorldEntity::translate(const Vector3& distance, TransformSpace::Enum relativeTo) 566 { 567 switch (relativeTo) 568 { 569 case TransformSpace::Local: 570 // position is relative to parent so transform downwards 571 this->setPosition(this->getPosition() + this->getOrientation() * distance); 572 break; 573 case TransformSpace::Parent: 574 this->setPosition(this->getPosition() + distance); 575 break; 576 case TransformSpace::World: 577 // position is relative to parent so transform upwards 578 if (this->node_->getParent()) 579 setPosition(getPosition() + (node_->getParent()->_getDerivedOrientation().Inverse() * distance) 580 / node_->getParent()->_getDerivedScale()); 581 else 582 this->setPosition(this->getPosition() + distance); 583 break; 584 } 585 } 586 587 /** 588 @brief 589 Rotates this WorldEntity by a quaternion. 590 @param relativeTo 591 @see TransformSpace::Enum 592 */ 593 void WorldEntity::rotate(const Quaternion& rotation, TransformSpace::Enum relativeTo) 594 { 595 switch(relativeTo) 596 { 597 case TransformSpace::Local: 598 this->setOrientation(this->getOrientation() * rotation); 599 break; 600 case TransformSpace::Parent: 601 // Rotations are normally relative to local axes, transform up 602 this->setOrientation(rotation * this->getOrientation()); 603 break; 604 case TransformSpace::World: 605 // Rotations are normally relative to local axes, transform up 606 this->setOrientation(this->getOrientation() * this->getWorldOrientation().Inverse() 607 * rotation * this->getWorldOrientation()); 608 break; 609 } 610 } 611 612 /** 613 @brief 614 Makes this WorldEntity look a specific target location. 615 @param relativeTo 616 @see TransformSpace::Enum 617 @param localDirectionVector 618 The vector which normally describes the natural direction of the object, usually -Z. 619 */ 620 void WorldEntity::lookAt(const Vector3& target, TransformSpace::Enum relativeTo, const Vector3& localDirectionVector) 621 { 622 Vector3 origin; 623 switch (relativeTo) 624 { 625 case TransformSpace::Local: 626 origin = Vector3::ZERO; 627 break; 628 case TransformSpace::Parent: 629 origin = this->getPosition(); 630 break; 631 case TransformSpace::World: 632 origin = this->getWorldPosition(); 633 break; 634 } 635 this->setDirection(target - origin, relativeTo, localDirectionVector); 636 } 637 638 /** 639 @brief 640 Makes this WorldEntity look in specific direction. 641 @param relativeTo 642 @see TransformSpace::Enum 643 @param localDirectionVector 644 The vector which normally describes the natural direction of the object, usually -Z. 645 */ 646 void WorldEntity::setDirection(const Vector3& direction, TransformSpace::Enum relativeTo, const Vector3& localDirectionVector) 647 { 648 Quaternion savedOrientation(this->getOrientation()); 649 Ogre::Node::TransformSpace ogreRelativeTo; 650 switch (relativeTo) 651 { 652 case TransformSpace::Local: 653 ogreRelativeTo = Ogre::Node::TS_LOCAL; break; 654 case TransformSpace::Parent: 655 ogreRelativeTo = Ogre::Node::TS_PARENT; break; 656 case TransformSpace::World: 657 ogreRelativeTo = Ogre::Node::TS_WORLD; break; 658 } 659 this->node_->setDirection(direction, ogreRelativeTo, localDirectionVector); 660 Quaternion newOrientation(this->node_->getOrientation()); 661 this->node_->setOrientation(savedOrientation); 662 this->setOrientation(newOrientation); 663 } 664 665 //! Activates physics if the CollisionType is not None. 666 void WorldEntity::activatePhysics() 667 { 668 if (this->isActive() && this->hasPhysics() && !this->isPhysicsActive() && !this->parent_) 669 { 670 this->getScene()->addPhysicalObject(this); 671 this->bPhysicsActive_ = true; 672 this->bPhysicsActiveSynchronised_ = true; 673 } 674 } 675 676 //! Deactivates physics but the CollisionType does not change. 677 void WorldEntity::deactivatePhysics() 678 { 679 if (this->isPhysicsActive()) 680 { 681 this->getScene()->removePhysicalObject(this); 682 this->bPhysicsActive_ = false; 683 this->bPhysicsActiveSynchronised_ = false; 684 } 685 } 686 687 //! Tells whether the object has already been added to the Bullet physics World. 688 bool WorldEntity::addedToPhysicalWorld() const 689 { 690 return this->physicalBody_ && this->physicalBody_->isInWorld(); 691 } 692 693 /** 694 @brief 695 Sets the CollisionType. This alters the object significantly! @see CollisionType. 696 @Note 697 Operation does not work on attached WorldEntities. 698 */ 699 void WorldEntity::setCollisionType(CollisionType type) 700 { 701 if (this->collisionType_ == type) 702 return; 703 704 // If we are already attached to a parent, this would be a bad idea.. 705 if (this->parent_) 706 { 707 CCOUT(2) << "Warning: Cannot set the collision type of a WorldEntity with a parent." << std::endl; 708 return; 709 } 710 711 // Check for type legality. Could be StaticEntity or MobileEntity. 712 if (!this->isCollisionTypeLegal(type)) 713 return; 714 715 if (this->isPhysicsActive()) 716 this->deactivatePhysics(); 717 718 bool bReactivatePhysics = true; 719 if (this->hasPhysics() && !this->isPhysicsActive()) 720 bReactivatePhysics = false; 721 722 // Check whether we have to create or destroy. 723 if (type != None && this->collisionType_ == None) 724 { 725 /* 726 HACK HACK HACK 727 // Check whether there was some scaling applied. 728 if (!this->node_->getScale().positionEquals(Vector3(1, 1, 1), 0.001)) 729 { 730 CCOUT(2) << "Warning: Cannot create a physical body if there is scaling applied to the node: Not yet implemented." << std::endl; 731 return; 732 } 733 HACK HACK HACK 734 */ 735 // Create new rigid body 736 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_->getCollisionShape()); 737 this->physicalBody_ = new btRigidBody(bodyConstructionInfo); 738 this->physicalBody_->setUserPointer(this); 739 this->physicalBody_->setActivationState(DISABLE_DEACTIVATION); 740 } 741 else if (type == None && this->collisionType_ != None) 742 { 743 // Destroy rigid body 744 assert(this->physicalBody_); 745 deactivatePhysics(); 746 delete this->physicalBody_; 747 this->physicalBody_ = 0; 748 this->collisionType_ = None; 749 this->collisionTypeSynchronised_ = None; 750 return; 751 } 752 753 // Change type 754 switch (type) 755 { 756 case Dynamic: 757 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !(btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT)); 758 break; 759 case Kinematic: 760 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT); 761 break; 762 case Static: 763 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !btCollisionObject::CF_KINEMATIC_OBJECT | btCollisionObject::CF_STATIC_OBJECT); 764 break; 765 case None: 766 assert(false); // Doesn't happen 767 return; 768 } 769 this->collisionType_ = type; 770 this->collisionTypeSynchronised_ = type; 771 772 // update mass and inertia tensor 773 recalculateMassProps(); 774 internalSetPhysicsProps(); 775 collisionCallbackActivityChanged(); 776 collisionResponseActivityChanged(); 777 if (bReactivatePhysics) 778 activatePhysics(); 779 } 780 781 //! Sets the CollisionType by string (used for the XMLPort) 782 void WorldEntity::setCollisionTypeStr(const std::string& typeStr) 783 { 784 std::string typeStrLower = getLowercase(typeStr); 785 CollisionType type; 786 if (typeStrLower == "dynamic") 787 type = Dynamic; 788 else if (typeStrLower == "static") 789 type = Static; 790 else if (typeStrLower == "kinematic") 791 type = Kinematic; 792 else if (typeStrLower == "none") 793 type = None; 794 else 795 ThrowException(ParseError, std::string("Attempting to set an unknown collision type: '") + typeStr + "'."); 796 this->setCollisionType(type); 797 } 798 799 //! Gets the CollisionType by string (used for the XMLPort) 800 std::string WorldEntity::getCollisionTypeStr() const 801 { 802 switch (this->getCollisionType()) 803 { 804 case Dynamic: 805 return "dynamic"; 806 case Kinematic: 807 return "kinematic"; 808 case Static: 809 return "static"; 810 case None: 811 return "none"; 812 default: 813 assert(false); 814 return ""; 815 } 816 } 817 818 /** 819 @brief 820 Recalculates the accumulated child mass and calls recalculateMassProps() 821 and notifies the parent of the change. 822 @Note 823 Called by a child WE 824 */ 825 void WorldEntity::notifyChildMassChanged() 826 { 827 // Note: CollisionShape changes of a child get handled over the internal CompoundCollisionShape already 828 // Recalculate mass 829 this->childrenMass_ = 0.0f; 830 for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it) 831 this->childrenMass_ += (*it)->getMass(); 832 recalculateMassProps(); 833 // Notify parent WE 834 if (this->parent_) 835 parent_->notifyChildMassChanged(); 836 } 837 838 /** 839 @brief 840 Undertakes the necessary steps to change the collision shape in Bullet, even at runtime. 841 @Note 842 - called by this->collisionShape_ 843 - May have a REALLY big overhead when called continuously at runtime, because then we need 844 to remove the physical body from Bullet and add it again. 845 */ 846 void WorldEntity::notifyCollisionShapeChanged() 847 { 848 if (hasPhysics()) 849 { 850 // Bullet doesn't like sudden changes of the collision shape, so we remove and add it again 851 if (this->addedToPhysicalWorld()) 852 { 853 this->deactivatePhysics(); 854 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 855 this->activatePhysics(); 856 } 857 else 858 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 859 } 860 recalculateMassProps(); 861 } 862 863 //! Updates all mass dependent parameters (mass, inertia tensor and child mass) 864 void WorldEntity::recalculateMassProps() 865 { 866 // Store local inertia for faster access. Evaluates to (0,0,0) if there is no collision shape. 867 float totalMass = this->mass_ + this->childrenMass_; 868 this->collisionShape_->calculateLocalInertia(totalMass, this->localInertia_); 869 if (this->hasPhysics()) 870 { 871 if (this->isStatic()) 872 { 873 // Just set everything to zero 874 this->physicalBody_->setMassProps(0.0f, btVector3(0, 0, 0)); 875 } 876 else if ((this->mass_ + this->childrenMass_) == 0.0f) 877 { 878 // Use default values to avoid very large or very small values 879 CCOUT(4) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0" << std::endl; 880 btVector3 inertia(0, 0, 0); 881 this->collisionShape_->calculateLocalInertia(1.0f, inertia); 882 this->physicalBody_->setMassProps(1.0f, inertia); 883 } 884 else 885 { 886 this->physicalBody_->setMassProps(totalMass, this->localInertia_); 887 } 888 } 889 } 890 891 //! Copies our own parameters for restitution, angular factor, dampings and friction to the bullet rigid body. 892 void WorldEntity::internalSetPhysicsProps() 893 { 894 if (this->hasPhysics()) 895 { 896 this->physicalBody_->setRestitution(this->restitution_); 897 this->physicalBody_->setAngularFactor(this->angularFactor_); 898 this->physicalBody_->setDamping(this->linearDamping_, this->angularDamping_); 899 this->physicalBody_->setFriction(this->friction_); 900 } 901 } 156 902 } -
code/trunk/src/orxonox/objects/worldentities/WorldEntity.h
r2171 r2662 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder (physics) 24 25 * Co-authors: 25 26 * ... … … 32 33 #include "OrxonoxPrereqs.h" 33 34 34 #define OGRE_FORCE_ANGLE_TYPES 35 35 #ifdef _NDEBUG 36 36 #include <OgreSceneNode.h> 37 38 #include "network/Synchronisable.h" 37 #else 38 #include <OgrePrerequisites.h> 39 #endif 40 #include "LinearMath/btMotionState.h" 41 42 #include "util/Math.h" 39 43 #include "core/BaseObject.h" 40 #include " util/Math.h"44 #include "network/synchronisable/Synchronisable.h" 41 45 42 46 namespace orxonox 43 47 { 44 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable 48 /** 49 @brief 50 The WorldEntity represents everything that can be put in a Scene at a certain location. 51 52 It is supposed to be the base class of everything you would call an 'object' in a Scene. 53 The class itself is abstract which means you cannot use it directly. You may use StaticEntity 54 as the simplest derivative or (derived from MobileEntity) MovableEntity and ControllableEntity 55 as more advanced ones. 56 57 The basic task of the WorldEntity is provide a location, a direction and a scaling and the possibility 58 to create an entire hierarchy of derivated objects. 59 It is also the basis for the physics interface to the Bullet physics engine. 60 Every WorldEntity can have a specific collision type: @see CollisionType 61 This would then imply that every scene object could have any collision type. To limit this, you can always 62 override this->isCollisionTypeLegal(CollisionType). Return false if the collision type is not supported 63 for a specific object. 64 There is also support for attaching WorldEntities with physics to each other. Currently, the collision shape 65 of both objects simply get merged into one larger shape (for static collision type). 66 The phyiscal body that is internally stored and administrated has the following supported properties: 67 - Restitution, angular factor, linear damping, angular damping, fricition, mass and collision shape. 68 You can get more information at the corresponding set function. 69 70 Collision shapes: These are controlled by the internal WorldEntityCollisionShape. @see WorldEntityCollisionShape. 71 */ 72 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState 45 73 { 74 friend class Scene; 75 46 76 public: 47 77 WorldEntity(BaseObject* creator); … … 51 81 void registerVariables(); 52 82 53 inline Ogre::SceneNode* getNode() const83 inline const Ogre::SceneNode* getNode() const 54 84 { return this->node_; } 55 85 … … 64 94 inline void setPosition(float x, float y, float z) 65 95 { this->setPosition(Vector3(x, y, z)); } 66 inline const Vector3& getPosition() const 67 { return this->node_->getPosition(); } 68 inline const Vector3& getWorldPosition() const 69 { return this->node_->getWorldPosition(); } 70 71 virtual void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 72 inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 96 const Vector3& getPosition() const; 97 const Vector3& getWorldPosition() const; 98 99 void translate(const Vector3& distance, TransformSpace::Enum relativeTo = TransformSpace::Parent); 100 inline void translate(float x, float y, float z, TransformSpace::Enum relativeTo = TransformSpace::Parent) 73 101 { this->translate(Vector3(x, y, z), relativeTo); } 102 103 virtual inline const Vector3& getVelocity() const 104 { return Vector3::ZERO; } 74 105 75 106 virtual void setOrientation(const Quaternion& orientation) = 0; … … 80 111 inline void setOrientation(const Vector3& axis, const Degree& angle) 81 112 { this->setOrientation(Quaternion(angle, axis)); } 82 inline const Quaternion& getOrientation() const 83 { return this->node_->getOrientation(); } 84 inline const Quaternion& getWorldOrientation() const 85 { return this->node_->getWorldOrientation(); } 86 87 virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 88 inline void rotate(const Vector3& axis, const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 113 const Quaternion& getOrientation() const; 114 const Quaternion& getWorldOrientation() const; 115 116 void rotate(const Quaternion& rotation, TransformSpace::Enum relativeTo = TransformSpace::Local); 117 inline void rotate(const Vector3& axis, const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 89 118 { this->rotate(Quaternion(angle, axis), relativeTo); } 90 inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 91 { this->rotate(Quaternion(angle, axis), relativeTo); } 92 93 virtual void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 94 inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 95 { this->yaw(Degree(angle), relativeTo); } 96 virtual void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 97 inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 98 { this->pitch(Degree(angle), relativeTo); } 99 virtual void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 100 inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 101 { this->roll(Degree(angle), relativeTo); } 102 103 virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0; 104 virtual void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0; 105 inline void setDirection(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 119 120 inline void yaw(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 121 { this->rotate(Quaternion(angle, Vector3::UNIT_Y), relativeTo); } 122 inline void pitch(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 123 { this->rotate(Quaternion(angle, Vector3::UNIT_X), relativeTo); } 124 inline void roll(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 125 { this->rotate(Quaternion(angle, Vector3::UNIT_Z), relativeTo); } 126 127 void lookAt(const Vector3& target, TransformSpace::Enum relativeTo = TransformSpace::Parent, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 128 void setDirection(const Vector3& direction, TransformSpace::Enum relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 129 inline void setDirection(float x, float y, float z, TransformSpace::Enum relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 106 130 { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); } 107 131 108 inline void setScale3D(const Vector3& scale) 109 { this->node_->setScale(scale); } 132 virtual void setScale3D(const Vector3& scale); 110 133 inline void setScale3D(float x, float y, float z) 111 { this-> node_->setScale(x, y, z); }112 inline const Vector3& getScale3D(void) const113 { return this->node_->getScale(); }134 { this->setScale3D(Vector3(x, y, z)); } 135 const Vector3& getScale3D(void) const; 136 const Vector3& getWorldScale3D() const; 114 137 115 138 inline void setScale(float scale) 116 { this-> node_->setScale(scale, scale, scale); }139 { this->setScale3D(scale, scale, scale); } 117 140 inline float getScale() const 118 141 { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; } 142 float getWorldScale() const; 119 143 120 144 inline void scale3D(const Vector3& scale) 121 { this-> node_->scale(scale); }145 { this->setScale3D(this->getScale3D() * scale); } 122 146 inline void scale3D(float x, float y, float z) 123 { this-> node_->scale(x, y, z); }147 { this->scale3D(Vector3(x, y, z)); } 124 148 inline void scale(float scale) 125 { this->node_->scale(scale, scale, scale); } 149 { this->scale3D(scale, scale, scale); } 150 151 virtual void changedScale() {} 126 152 127 153 void attach(WorldEntity* object); 128 154 void detach(WorldEntity* object); 129 WorldEntity* getAttachedObject(unsigned int index) const;155 WorldEntity* getAttachedObject(unsigned int index); 130 156 inline const std::set<WorldEntity*>& getAttachedObjects() const 131 157 { return this->children_; } 158 159 void attachOgreObject(Ogre::MovableObject* object); 160 void detachOgreObject(Ogre::MovableObject* object); 161 Ogre::MovableObject* detachOgreObject(const Ogre::String& name); 132 162 133 163 inline void attachToParent(WorldEntity* parent) … … 138 168 { return this->parent_; } 139 169 170 void attachNode(Ogre::SceneNode* node); 171 void detachNode(Ogre::SceneNode* node); 172 void attachToNode(Ogre::SceneNode* node); 173 void detachFromNode(Ogre::SceneNode* node); 174 175 void notifyChildPropsChanged(); 176 140 177 protected: 141 178 Ogre::SceneNode* node_; 142 179 143 180 private: 144 void updateParent();145 146 181 inline void lookAt_xmlport(const Vector3& target) 147 182 { this->lookAt(target); } … … 155 190 { this->roll(angle); } 156 191 192 // network callbacks 193 void parentChanged(); 194 inline void scaleChanged() 195 { this->setScale3D(this->getScale3D()); } 196 157 197 WorldEntity* parent_; 158 198 unsigned int parentID_; 159 199 std::set<WorldEntity*> children_; 200 201 202 ///////////// 203 // Physics // 204 ///////////// 205 206 public: 207 /** 208 @brief 209 Denotes the possible types of physical objects in a Scene. 210 211 Dynamic: The object is influenced by its physical environment, like for instance little ball. 212 Kinematic: The object can only influence other dynamic objects. It's movement is coordinated by your own saying. 213 Static: Like kinematic but the object is not allowed to move during the simulation. 214 None: The object has no physics at all. 215 */ 216 enum CollisionType 217 { 218 Dynamic, 219 Kinematic, 220 Static, 221 None 222 }; 223 224 //! Tells whether the object has any connection to the Bullet physics engine. If hasPhysics() is false, the object may still have a velocity. 225 bool hasPhysics() const { return getCollisionType() != None ; } 226 //! @see CollisionType 227 bool isStatic() const { return getCollisionType() == Static ; } 228 //! @see CollisionType 229 bool isKinematic() const { return getCollisionType() == Kinematic; } 230 //! @see CollisionType 231 bool isDynamic() const { return getCollisionType() == Dynamic ; } 232 //! Tells whether physics has been activated (you can temporarily deactivate it) 233 bool isPhysicsActive() const { return this->bPhysicsActive_; } 234 bool addedToPhysicalWorld() const; 235 236 void activatePhysics(); 237 void deactivatePhysics(); 238 239 //! Returns the CollisionType. @see CollisionType. 240 inline CollisionType getCollisionType() const 241 { return this->collisionType_; } 242 void setCollisionType(CollisionType type); 243 244 void setCollisionTypeStr(const std::string& type); 245 std::string getCollisionTypeStr() const; 246 247 //! Sets the mass of this object. Note that the total mass may be influenced by attached objects! 248 inline void setMass(float mass) 249 { this->mass_ = mass; recalculateMassProps(); } 250 //! Returns the mass of this object without its children. 251 inline float getMass() const 252 { return this->mass_; } 253 254 //! Returns the total mass of this object with all its attached children. 255 inline float getTotalMass() const 256 { return this->mass_ + this->childrenMass_; } 257 258 /** 259 @brief 260 Returns the diagonal elements of the inertia tensor when calculated in local coordinates. 261 @Note 262 The local inertia tensor cannot be set, but is calculated by Bullet according to the collisionShape. 263 With compound collision shapes, an approximation is used. 264 */ 265 inline const btVector3& getLocalInertia() const 266 { return this->localInertia_; } 267 268 /** 269 @brief 270 Sets how much reaction is applied in a collision. 271 272 Consider two equal spheres colliding with equal velocities: 273 Restitution 1 means that both spheres simply reverse their velocity (no loss of energy) 274 Restitution 0 means that both spheres will immediately stop moving 275 (maximum loss of energy without violating of the preservation of momentum) 276 */ 277 inline void setRestitution(float restitution) 278 { this->restitution_ = restitution; internalSetPhysicsProps(); } 279 //! Returns the restitution parameter. @see setRestitution. 280 inline float getRestitution() const 281 { return this->restitution_; } 282 283 /** 284 @brief 285 Sets an artificial parameter that tells how much torque is applied when you apply a non-central force. 286 287 Normally the angular factor is 1, which means it's physically 'correct'. Howerver if you have a player 288 character that should not rotate when hit sideways, you can set the angular factor to 0. 289 */ 290 inline void setAngularFactor(float angularFactor) 291 { this->angularFactor_ = angularFactor; internalSetPhysicsProps(); } 292 //! Returns the angular factor. @see setAngularFactor. 293 inline float getAngularFactor() const 294 { return this->angularFactor_; } 295 296 //! Applies a mass independent damping. Velocities will simply diminish exponentially. 297 inline void setLinearDamping(float linearDamping) 298 { this->linearDamping_ = linearDamping; internalSetPhysicsProps(); } 299 //! Returns the linear damping. @see setLinearDamping. 300 inline float getLinearDamping() const 301 { return this->linearDamping_; } 302 303 //! Applies a tensor independent rotation damping. Angular velocities will simply diminish exponentially. 304 inline void setAngularDamping(float angularDamping) 305 { this->angularDamping_ = angularDamping; internalSetPhysicsProps(); } 306 //! Returns the angular damping. @see setAngularDamping. 307 inline float getAngularDamping() const 308 { return this->angularDamping_; } 309 310 //! Applies friction to the object. Friction occurs when two objects collide. 311 inline void setFriction(float friction) 312 { this->friction_ = friction; internalSetPhysicsProps(); } 313 //! Returns the amount of friction applied to the object. 314 inline float getFriction() const 315 { return this->friction_; } 316 317 void attachCollisionShape(CollisionShape* shape); 318 void detachCollisionShape(CollisionShape* shape); 319 CollisionShape* getAttachedCollisionShape(unsigned int index); 320 321 void notifyCollisionShapeChanged(); 322 void notifyChildMassChanged(); 323 324 /** 325 @brief 326 Virtual function that gets called when this object collides with another. 327 @param otherObject 328 The object this one has collided into. 329 @pram contactPoint 330 Contact point provided by Bullet. Holds more information and can me modified. See return value. 331 @Return 332 Returning false means that no modification to the contactPoint has been made. Return true otherwise! 333 @Note 334 Condition is that enableCollisionCallback() was called. 335 */ 336 virtual inline bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 337 { return false; } /* With false, Bullet assumes no modification to the collision objects. */ 338 339 //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise! 340 inline void enableCollisionCallback() 341 { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); } 342 //! Disables the collidesAgainst(.) function. @see enableCollisionCallback() 343 inline void disableCollisionCallback() 344 { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); } 345 //! Tells whether there could be a collision callback via collidesAgainst(.) 346 inline bool isCollisionCallbackActive() const 347 { return this->bCollisionCallbackActive_; } 348 349 //! Enables or disables collision response (default is of course on) 350 inline void setCollisionResponse(bool value) 351 { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); } 352 //! Tells whether there could be a collision response 353 inline bool hasCollisionResponse() 354 { return this->bCollisionResponseActive_; } 355 356 protected: 357 /** 358 @brief 359 Function checks whether the requested collision type is legal to this object. 360 361 You can override this function in a derived class to constrain the collision to e.g. None or Dynamic. 362 A projectile may not prove very useful if there is no physical body. Simply set the CollisionType 363 in its constructor and override this method. But be careful that a derived classe's virtual functions 364 don't yet exist in the constructor if a base class. 365 */ 366 virtual bool isCollisionTypeLegal(CollisionType type) const = 0; 367 368 btRigidBody* physicalBody_; //!< Bullet rigid body. Everything physical is applied to this instance. 369 370 private: 371 void recalculateMassProps(); 372 void internalSetPhysicsProps(); 373 374 bool notifyBeingAttached(WorldEntity* newParent); 375 void notifyDetached(); 376 377 // network callbacks 378 void collisionTypeChanged(); 379 void physicsActivityChanged(); 380 void collisionCallbackActivityChanged(); 381 void collisionResponseActivityChanged(); 382 //! Network callback workaround to call a function when the value changes. 383 inline void massChanged() 384 { this->setMass(this->mass_); } 385 //! Network callback workaround to call a function when the value changes. 386 inline void restitutionChanged() 387 { this->setRestitution(this->restitution_); } 388 //! Network callback workaround to call a function when the value changes. 389 inline void angularFactorChanged() 390 { this->setAngularFactor(this->angularFactor_); } 391 //! Network callback workaround to call a function when the value changes. 392 inline void linearDampingChanged() 393 { this->setLinearDamping(this->linearDamping_); } 394 //! Network callback workaround to call a function when the value changes. 395 inline void angularDampingChanged() 396 { this->setAngularDamping(this->angularDamping_); } 397 //! Network callback workaround to call a function when the value changes. 398 inline void frictionChanged() 399 { this->setFriction(this->friction_); } 400 401 CollisionType collisionType_; //!< @see setCollisionType 402 CollisionType collisionTypeSynchronised_; //!< Network synchronised variable for collisionType_ 403 bool bPhysicsActive_; //!< @see isPhysicsActive 404 bool bPhysicsActiveSynchronised_; //!< Network synchronised variable for bPhysicsActive_ 405 //! When attaching objects hierarchically this variable tells this object (as child) whether physics was activated before attaching (because the deactivate physics while being attached). 406 bool bPhysicsActiveBeforeAttaching_; 407 WorldEntityCollisionShape* collisionShape_; //!< Attached collision shapes go here 408 btScalar mass_; //!< @see setMass 409 btVector3 localInertia_; //!< @see getLocalInertia 410 btScalar restitution_; //!< @see setRestitution 411 btScalar angularFactor_; //!< @see setAngularFactor 412 btScalar linearDamping_; //!< @see setLinearDamping 413 btScalar angularDamping_; //!< @see setAngularDamping 414 btScalar friction_; //!< @see setFriction 415 btScalar childrenMass_; //!< Sum of all the children's masses 416 bool bCollisionCallbackActive_; //!< @see enableCollisionCallback 417 bool bCollisionResponseActive_; //!< Tells whether the object should respond to collisions 160 418 }; 419 420 // Inline heavily used functions for release builds. In debug, we better avoid including OgreSceneNode here. 421 #ifdef _NDEBUG 422 inline const Vector3& WorldEntity::getPosition() const 423 { return this->node_->getPosition(); } 424 inline const Quaternion& WorldEntity::getOrientation() const 425 { return this->node_->getrOrientation(); } 426 inline const Vector3& WorldEntity::getScale3D(void) const 427 { return this->node_->getScale(); } 428 #endif 429 430 SUPER_FUNCTION(5, WorldEntity, changedScale, false); 161 431 } 162 432 -
code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2171 r2662 30 30 #include "Pawn.h" 31 31 32 #include "core/Core.h" 32 33 #include "core/CoreIncludes.h" 33 34 #include "core/XMLPort.h" 34 35 #include "util/Math.h" 36 #include "PawnManager.h" 35 37 #include "objects/infos/PlayerInfo.h" 36 38 #include "objects/gametypes/Gametype.h" 37 #include "objects/weaponSystem/WeaponSystem.h" 39 #include "objects/worldentities/ParticleSpawner.h" 40 #include "objects/worldentities/ExplosionChunk.h" 38 41 39 42 namespace orxonox … … 45 48 RegisterObject(Pawn); 46 49 47 this->bAlive_ = false; 50 PawnManager::touch(); 51 this->bAlive_ = true; 52 this->fire_ = 0x0; 53 this->firehack_ = 0x0; 48 54 49 55 this->health_ = 0; … … 52 58 53 59 this->lastHitOriginator_ = 0; 54 this->weaponSystem_ = 0; 55 56 /* 57 //WeaponSystem 58 weaponSystem_ = new WeaponSystem(); 59 WeaponSet * weaponSet1 = new WeaponSet(1); 60 this->weaponSystem_->attachWeaponSet(weaponSet1); 61 this->weaponSystem_->getWeaponSetPointer(0)->getWeaponSlotPointer(0)->setAmmoType(true); 62 */ 60 61 this->spawnparticleduration_ = 3.0f; 62 63 this->getPickUp().setPlayer(this); 64 65 if (Core::isMaster()) 66 { 67 this->weaponSystem_ = new WeaponSystem(this); 68 this->weaponSystem_->setParentPawn(this); 69 } 70 else 71 this->weaponSystem_ = 0; 72 73 this->setRadarObjectColour(ColourValue::Red); 74 this->setRadarObjectShape(RadarViewable::Dot); 63 75 64 76 this->registerVariables(); … … 67 79 Pawn::~Pawn() 68 80 { 81 if (this->isInitialized()) 82 { 83 for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it) 84 it->destroyedPawn(this); 85 86 if (this->weaponSystem_) 87 delete this->weaponSystem_; 88 } 69 89 } 70 90 … … 73 93 SUPER(Pawn, XMLPort, xmlelement, mode); 74 94 75 XMLPortParam(Pawn, "health", setHealth, getHeal ht, xmlelement, mode).defaultValues(100);95 XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100); 76 96 XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); 77 97 XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); 98 XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); 99 XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); 100 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7); 101 102 XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode); 103 XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode); 104 XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode); 78 105 } 79 106 80 107 void Pawn::registerVariables() 81 108 { 82 REGISTERDATA(this->bAlive_, direction::toclient); 83 REGISTERDATA(this->health_, direction::toclient); 109 registerVariable(this->bAlive_, variableDirection::toclient); 110 registerVariable(this->health_, variableDirection::toclient); 111 registerVariable(this->initialHealth_, variableDirection::toclient); 112 registerVariable(this->fire_, variableDirection::toserver); 84 113 } 85 114 … … 87 116 { 88 117 SUPER(Pawn, tick, dt); 118 119 if (this->weaponSystem_) 120 { 121 if (this->fire_ & WeaponMode::fire) 122 this->weaponSystem_->fire(WeaponMode::fire); 123 if (this->fire_ & WeaponMode::altFire) 124 this->weaponSystem_->fire(WeaponMode::altFire); 125 if (this->fire_ & WeaponMode::altFire2) 126 this->weaponSystem_->fire(WeaponMode::altFire2); 127 } 128 this->fire_ = this->firehack_; 129 this->firehack_ = 0x0; 89 130 90 131 if (this->health_ <= 0) … … 119 160 } 120 161 121 void Pawn::spawn ()162 void Pawn::spawneffect() 122 163 { 123 164 // play spawn effect 165 if (this->spawnparticlesource_ != "") 166 { 167 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 168 effect->setPosition(this->getPosition()); 169 effect->setOrientation(this->getOrientation()); 170 effect->setDestroyAfterLife(true); 171 effect->setSource(this->spawnparticlesource_); 172 effect->setLifetime(this->spawnparticleduration_); 173 } 124 174 } 125 175 126 176 void Pawn::death() 127 177 { 178 // Set bAlive_ to false and wait for PawnManager to do the destruction 128 179 this->bAlive_ = false; 180 181 this->setDestroyWhenPlayerLeft(false); 182 129 183 if (this->getGametype()) 130 184 this->getGametype()->pawnKilled(this, this->lastHitOriginator_); 185 131 186 if (this->getPlayer()) 132 187 this->getPlayer()->stopControl(this); 133 188 134 delete this; 135 189 if (Core::isMaster()) 190 this->deatheffect(); 191 } 192 193 void Pawn::deatheffect() 194 { 136 195 // play death effect 137 } 138 139 void Pawn::fire() 140 { 141 if (this->weaponSystem_) 142 this->weaponSystem_->fire(); 196 { 197 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 198 effect->setPosition(this->getPosition()); 199 effect->setOrientation(this->getOrientation()); 200 effect->setDestroyAfterLife(true); 201 effect->setSource("Orxonox/explosion2b"); 202 effect->setLifetime(4.0f); 203 } 204 { 205 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 206 effect->setPosition(this->getPosition()); 207 effect->setOrientation(this->getOrientation()); 208 effect->setDestroyAfterLife(true); 209 effect->setSource("Orxonox/smoke6"); 210 effect->setLifetime(4.0f); 211 } 212 { 213 ParticleSpawner* effect = new ParticleSpawner(this->getCreator()); 214 effect->setPosition(this->getPosition()); 215 effect->setOrientation(this->getOrientation()); 216 effect->setDestroyAfterLife(true); 217 effect->setSource("Orxonox/sparks"); 218 effect->setLifetime(4.0f); 219 } 220 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) 221 { 222 ExplosionChunk* chunk = new ExplosionChunk(this->getCreator()); 223 chunk->setPosition(this->getPosition()); 224 225 } 226 } 227 228 void Pawn::fire(WeaponMode::Enum fireMode) 229 { 230 this->firehack_ |= fireMode; 143 231 } 144 232 … … 146 234 { 147 235 this->setHealth(this->initialHealth_); 148 this->spawn(); 236 if (Core::isMaster()) 237 this->spawneffect(); 238 } 239 240 void Pawn::dropItems() 241 { 242 pickUp.eraseAll(); 243 } 244 245 void Pawn::setWeaponSlot(WeaponSlot * wSlot) 246 { 247 this->attach(wSlot); 248 if (this->weaponSystem_) 249 this->weaponSystem_->attachWeaponSlot(wSlot); 250 } 251 252 WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const 253 { 254 if (this->weaponSystem_) 255 return this->weaponSystem_->getWeaponSlotPointer(index); 256 else 257 return 0; 258 } 259 260 void Pawn::setWeaponPack(WeaponPack * wPack) 261 { 262 if (this->weaponSystem_) 263 { 264 wPack->setParentWeaponSystem(this->weaponSystem_); 265 wPack->setParentWeaponSystemToAllWeapons(this->weaponSystem_); 266 this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() ); 267 wPack->attachNeededMunitionToAllWeapons(); 268 } 269 } 270 271 WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const 272 { 273 if (this->weaponSystem_) 274 return this->weaponSystem_->getWeaponPackPointer(firemode); 275 else 276 return 0; 277 } 278 279 void Pawn::setWeaponSet(WeaponSet * wSet) 280 { 281 if (this->weaponSystem_) 282 this->weaponSystem_->attachWeaponSet(wSet); 283 } 284 285 WeaponSet * Pawn::getWeaponSet(unsigned int index) const 286 { 287 if (this->weaponSystem_) 288 return this->weaponSystem_->getWeaponSetPointer(index); 289 else 290 return 0; 291 } 292 293 294 /////////////////// 295 // Pawn Listener // 296 /////////////////// 297 PawnListener::PawnListener() 298 { 299 RegisterRootObject(PawnListener); 149 300 } 150 301 } -
code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.h
r2098 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "objects/pickup/ShipEquipment.h" 34 34 #include "objects/worldentities/ControllableEntity.h" 35 #include "objects/RadarViewable.h" 36 #include "objects/weaponSystem/WeaponSystem.h" 35 37 36 38 namespace orxonox 37 39 { 38 class _OrxonoxExport Pawn : public ControllableEntity 40 class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable 39 41 { 40 42 public: … … 54 56 inline void removeHealth(float health) 55 57 { this->setHealth(this->health_ - health); } 56 inline float getHeal ht() const58 inline float getHealth() const 57 59 { return this->health_; } 58 60 … … 74 76 virtual void kill(); 75 77 76 virtual void fire(); 77 78 virtual void fire(WeaponMode::Enum fireMode); 78 79 virtual void postSpawn(); 79 80 81 void setWeaponSlot(WeaponSlot * wSlot); 82 WeaponSlot * getWeaponSlot(unsigned int index) const; 83 void setWeaponPack(WeaponPack * wPack); 84 WeaponPack * getWeaponPack(unsigned int firemode) const; 85 void setWeaponSet(WeaponSet * wSet); 86 WeaponSet * getWeaponSet(unsigned int index) const; 87 88 inline const WorldEntity* getWorldEntity() const 89 { return const_cast<Pawn*>(this); } 90 91 inline void setSpawnParticleSource(const std::string& source) 92 { this->spawnparticlesource_ = source; } 93 inline const std::string& getSpawnParticleSource() const 94 { return this->spawnparticlesource_; } 95 96 inline void setSpawnParticleDuration(float duration) 97 { this->spawnparticleduration_ = duration; } 98 inline float getSpawnParticleDuration() const 99 { return this->spawnparticleduration_; } 100 101 inline void setExplosionChunks(unsigned int chunks) 102 { this->numexplosionchunks_ = chunks; } 103 inline unsigned int getExplosionChunks() const 104 { return this->numexplosionchunks_; } 105 106 inline ShipEquipment& getPickUp() 107 {return this->pickUp;} 108 109 virtual void dropItems(); 110 80 111 protected: 81 virtual void spawn();82 112 virtual void death(); 113 virtual void deatheffect(); 114 virtual void spawneffect(); 83 115 116 ShipEquipment pickUp; 84 117 bool bAlive_; 118 85 119 86 120 float health_; … … 91 125 92 126 WeaponSystem* weaponSystem_; 127 unsigned int fire_; 128 unsigned int firehack_; 129 130 std::string spawnparticlesource_; 131 float spawnparticleduration_; 132 unsigned int numexplosionchunks_; 133 }; 134 135 class _OrxonoxExport PawnListener : virtual public OrxonoxClass 136 { 137 friend class Pawn; 138 139 public: 140 PawnListener(); 141 virtual ~PawnListener() {} 142 143 protected: 144 virtual void destroyedPawn(Pawn* pawn) = 0; 93 145 }; 94 146 } -
code/trunk/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2171 r2662 30 30 #include "SpaceShip.h" 31 31 32 #include "BulletDynamics/Dynamics/btRigidBody.h" 33 34 #include "util/Math.h" 35 #include "util/Exception.h" 32 36 #include "core/CoreIncludes.h" 33 37 #include "core/ConfigValueIncludes.h" 38 #include "core/Template.h" 34 39 #include "core/XMLPort.h" 35 #include " util/Math.h"40 #include "objects/items/Engine.h" 36 41 37 42 namespace orxonox 38 43 { 44 const float orientationGain = 100; 39 45 CreateFactory(SpaceShip); 40 46 … … 43 49 RegisterObject(SpaceShip); 44 50 45 this->zeroDegree_ = 0; 46 47 this->maxSpeed_ = 0; 48 this->maxSecondarySpeed_ = 0; 49 this->maxRotation_ = 0; 50 this->translationAcceleration_ = 0; 51 this->rotationAcceleration_ = 0; 52 this->translationDamping_ = 0; 53 54 this->yawRotation_ = 0; 55 this->pitchRotation_ = 0; 56 this->rollRotation_ = 0; 51 this->primaryThrust_ = 100; 52 this->auxilaryThrust_ = 30; 53 this->rotationThrust_ = 10; 54 55 this->localLinearAcceleration_.setValue(0, 0, 0); 56 this->localAngularAcceleration_.setValue(0, 0, 0); 57 this->bBoost_ = false; 58 this->bPermanentBoost_ = false; 59 this->steering_ = Vector3::ZERO; 60 this->engine_ = 0; 61 57 62 58 63 this->bInvertYAxis_ = false; 59 64 60 65 this->setDestroyWhenPlayerLeft(true); 66 67 // SpaceShip is always a physical object per default 68 // Be aware of this call: The collision type legality check will not reach derived classes! 69 this->setCollisionType(WorldEntity::Dynamic); 70 // Get notification about collisions 71 this->enableCollisionCallback(); 61 72 62 73 this->setConfigValues(); … … 66 77 SpaceShip::~SpaceShip() 67 78 { 79 if (this->isInitialized() && this->engine_) 80 delete this->engine_; 68 81 } 69 82 … … 72 85 SUPER(SpaceShip, XMLPort, xmlelement, mode); 73 86 74 XMLPortParam(SpaceShip, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); 75 XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode); 76 XMLPortParam(SpaceShip, "maxrotation", setMaxRotation, getMaxRotation, xmlelement, mode); 77 XMLPortParam(SpaceShip, "transacc", setTransAcc, getTransAcc, xmlelement, mode); 78 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); 87 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 88 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 89 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); 90 XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode); 80 91 } 81 92 82 93 void SpaceShip::registerVariables() 83 94 { 84 REGISTERDATA(this->maxSpeed_, direction::toclient); 85 REGISTERDATA(this->maxSecondarySpeed_, direction::toclient); 86 REGISTERDATA(this->maxRotation_, direction::toclient); 87 REGISTERDATA(this->translationAcceleration_, direction::toclient); 88 REGISTERDATA(this->rotationAcceleration_, direction::toclient); 89 REGISTERDATA(this->translationDamping_, direction::toclient); 95 registerVariable(this->primaryThrust_, variableDirection::toclient); 96 registerVariable(this->auxilaryThrust_, variableDirection::toclient); 97 registerVariable(this->rotationThrust_, variableDirection::toclient); 90 98 } 91 99 … … 95 103 } 96 104 105 bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const 106 { 107 if (type != WorldEntity::Dynamic) 108 { 109 CCOUT(1) << "Error: Cannot tell a SpaceShip not to be dynamic! Ignoring." << std::endl; 110 assert(false); // Only in debug mode 111 return false; 112 } 113 else 114 return true; 115 } 116 97 117 void SpaceShip::tick(float dt) 98 118 { 99 if (this->isLocallyControlled()) 119 SUPER(SpaceShip, tick, dt); 120 121 if (this->hasLocalController()) 100 122 { 101 // ##################################### 102 // ############# STEERING ############## 103 // ##################################### 104 105 Vector3 velocity = this->getVelocity(); 106 if (velocity.x > this->maxSecondarySpeed_) 107 velocity.x = this->maxSecondarySpeed_; 108 if (velocity.x < -this->maxSecondarySpeed_) 109 velocity.x = -this->maxSecondarySpeed_; 110 if (velocity.y > this->maxSecondarySpeed_) 111 velocity.y = this->maxSecondarySpeed_; 112 if (velocity.y < -this->maxSecondarySpeed_) 113 velocity.y = -this->maxSecondarySpeed_; 114 if (velocity.z > this->maxSecondarySpeed_) 115 velocity.z = this->maxSecondarySpeed_; 116 if (velocity.z < -this->maxSpeed_) 117 velocity.z = -this->maxSpeed_; 118 119 // normalize velocity and acceleration 120 for (size_t dimension = 0; dimension < 3; ++dimension) 123 /* 124 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 125 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 126 if (this->localLinearAcceleration_.z() > 0) 127 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 128 else 129 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 130 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 131 this->localLinearAcceleration_.setValue(0, 0, 0); 132 */ 133 if (!this->isInMouseLook()) 121 134 { 122 if (this->acceleration_[dimension] == 0) 135 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 136 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 137 this->localAngularAcceleration_.setValue(0, 0, 0); 138 } 139 } 140 } 141 142 void SpaceShip::moveFrontBack(const Vector2& value) 143 { 144 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 145 this->steering_.z = -value.x; 146 } 147 148 void SpaceShip::moveRightLeft(const Vector2& value) 149 { 150 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 151 this->steering_.x = value.x; 152 } 153 154 void SpaceShip::moveUpDown(const Vector2& value) 155 { 156 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 157 this->steering_.y = value.x; 158 } 159 160 void SpaceShip::rotateYaw(const Vector2& value) 161 { 162 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x); 163 164 Pawn::rotateYaw(value); 165 } 166 167 void SpaceShip::rotatePitch(const Vector2& value) 168 { 169 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); 170 171 Pawn::rotatePitch(value); 172 } 173 174 void SpaceShip::rotateRoll(const Vector2& value) 175 { 176 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 177 178 Pawn::rotateRoll(value); 179 } 180 181 void SpaceShip::fire() 182 { 183 } 184 185 void SpaceShip::boost() 186 { 187 this->bBoost_ = true; 188 } 189 190 void SpaceShip::loadEngineTemplate() 191 { 192 if (this->enginetemplate_ != "") 193 { 194 Template* temp = Template::getTemplate(this->enginetemplate_); 195 196 if (temp) 197 { 198 Identifier* identifier = temp->getBaseclassIdentifier(); 199 200 if (identifier) 123 201 { 124 if (velocity[dimension] > 0) 202 BaseObject* object = identifier->fabricate(this); 203 this->engine_ = dynamic_cast<Engine*>(object); 204 205 if (this->engine_) 125 206 { 126 velocity[dimension] -= (this->translationDamping_ * dt); 127 if (velocity[dimension] < 0) 128 velocity[dimension] = 0; 207 this->engine_->addTemplate(temp); 208 this->engine_->addToSpaceShip(this); 129 209 } 130 else if (velocity[dimension] < 0)210 else 131 211 { 132 velocity[dimension] += (this->translationDamping_ * dt); 133 if (velocity[dimension] > 0) 134 velocity[dimension] = 0; 212 delete object; 135 213 } 136 214 } 137 215 } 138 139 this->setVelocity(velocity);140 216 } 141 142 143 SUPER(SpaceShip, tick, dt); 144 145 146 if (this->isLocallyControlled()) 147 { 148 this->yaw(this->yawRotation_ * dt); 149 if (this->bInvertYAxis_) 150 this->pitch(Degree(-this->pitchRotation_ * dt)); 151 else 152 this->pitch(Degree( this->pitchRotation_ * dt)); 153 this->roll(this->rollRotation_ * dt); 154 155 this->acceleration_.x = 0; 156 this->acceleration_.y = 0; 157 this->acceleration_.z = 0; 158 159 this->yawRotation_ = this->zeroDegree_; 160 this->pitchRotation_ = this->zeroDegree_; 161 this->rollRotation_ = this->zeroDegree_; 162 } 163 } 164 165 void SpaceShip::moveFrontBack(const Vector2& value) 166 { 167 this->acceleration_.z = -this->translationAcceleration_ * value.x; 168 } 169 170 void SpaceShip::moveRightLeft(const Vector2& value) 171 { 172 this->acceleration_.x = this->translationAcceleration_ * value.x; 173 } 174 175 void SpaceShip::moveUpDown(const Vector2& value) 176 { 177 this->acceleration_.y = this->translationAcceleration_ * value.x; 178 } 179 180 void SpaceShip::rotateYaw(const Vector2& value) 181 { 182 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 183 if (temp > this->maxRotation_) 184 temp = this->maxRotation_; 185 if (temp < -this->maxRotation_) 186 temp = -this->maxRotation_; 187 this->yawRotation_ = Degree(temp); 188 } 189 190 void SpaceShip::rotatePitch(const Vector2& value) 191 { 192 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 193 if (temp > this->maxRotation_) 194 temp = this->maxRotation_; 195 if (temp < -this->maxRotation_) 196 temp = -this->maxRotation_; 197 this->pitchRotation_ = Degree(temp); 198 } 199 200 void SpaceShip::rotateRoll(const Vector2& value) 201 { 202 Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 203 if (temp > this->maxRotation_) 204 temp = this->maxRotation_; 205 if (temp < -this->maxRotation_) 206 temp = -this->maxRotation_; 207 this->rollRotation_ = Degree(temp); 208 } 209 210 void SpaceShip::fire() 211 { 217 } 218 219 void SpaceShip::setEngine(Engine* engine) 220 { 221 this->engine_ = engine; 222 if (engine && engine->getShip() != this) 223 engine->addToSpaceShip(this); 212 224 } 213 225 } -
code/trunk/src/orxonox/objects/worldentities/pawns/SpaceShip.h
r2087 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "LinearMath/btVector3.h" 35 34 36 #include "Pawn.h" 35 37 … … 56 58 57 59 virtual void fire(); 60 virtual void boost(); 58 61 59 void setMaxSpeed(float value) 60 { this->maxSpeed_ = value; } 61 void setMaxSecondarySpeed(float value) 62 { this->maxSecondarySpeed_ = value; } 63 void setMaxRotation(const Degree& value) 64 { this->maxRotation_ = value; } 65 void setTransAcc(float value) 66 { this->translationAcceleration_ = value; } 67 void setRotAcc(const Degree& value) 68 { this->rotationAcceleration_ = value; } 69 void setTransDamp(float value) 70 { this->translationDamping_ = value; } 62 void setEngine(Engine* engine); 63 inline Engine* getEngine() const 64 { return this->engine_; } 71 65 72 inline float getMaxSpeed() const 73 { return this->maxSpeed_; } 74 inline float getMaxSecondarySpeed() const 75 { return this->maxSecondarySpeed_; } 76 inline float getMaxRotation() const 77 { return this->maxRotation_.valueDegrees(); } 78 inline float getTransAcc() const 79 { return this->translationAcceleration_; } 80 inline float getRotAcc() const 81 { return this->rotationAcceleration_.valueDegrees(); } 82 inline float getTransDamp() const 83 { return this->translationDamping_; } 66 inline void setSteeringDirection(const Vector3& direction) 67 { this->steering_ = direction; } 68 inline const Vector3& getSteeringDirection() const 69 { return this->steering_; } 70 71 inline void setBoost(bool bBoost) 72 { this->bBoost_ = bBoost; } 73 inline bool getBoost() const 74 { return this->bBoost_; } 75 76 inline void setEngineTemplate(const std::string& temp) 77 { this->enginetemplate_ = temp; this->loadEngineTemplate(); } 78 inline const std::string& getEngineTemplate() const 79 { return this->enginetemplate_; } 80 81 inline void setPermanentBoost(bool bPermanent) 82 { this->bPermanentBoost_ = bPermanent; } 83 inline bool getPermanentBoost() const 84 { return this->bPermanentBoost_; } 84 85 85 86 protected: 86 87 bool bInvertYAxis_; 87 88 88 float maxSpeed_; 89 float maxSecondarySpeed_; 90 float translationAcceleration_; 91 float translationDamping_; 89 bool bBoost_; 90 bool bPermanentBoost_; 91 Vector3 steering_; 92 float primaryThrust_; 93 float auxilaryThrust_; 94 float rotationThrust_; 95 btVector3 localLinearAcceleration_; 96 btVector3 localAngularAcceleration_; 92 97 93 Degree maxRotation_;94 Degree rotationAcceleration_;98 private: 99 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 95 100 96 Degree zeroDegree_; 97 Degree pitchRotation_; 98 Degree yawRotation_; 99 Degree rollRotation_; 101 private: 102 void loadEngineTemplate(); 103 104 std::string enginetemplate_; 105 Engine* engine_; 100 106 }; 101 107 } -
code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2171 r2662 30 30 #include "Spectator.h" 31 31 32 #include <OgreBillboardSet.h> 33 32 34 #include "core/CoreIncludes.h" 35 #include "core/ConfigValueIncludes.h" 33 36 #include "core/Core.h" 34 37 #include "objects/worldentities/Model.h" … … 49 52 RegisterObject(Spectator); 50 53 51 this->speed_ = 100; 52 this->rotationSpeed_ = 3; 54 this->speed_ = 200; 53 55 54 56 this->yaw_ = 0; 55 57 this->pitch_ = 0; 56 58 this->roll_ = 0; 59 this->localVelocity_ = Vector3::ZERO; 57 60 this->setHudTemplate("spectatorhud"); 58 this-> hudmode_ = 0;61 this->greetingFlare_ = 0; 59 62 60 63 this->setDestroyWhenPlayerLeft(true); 61 64 62 this->greetingFlare_ = new BillboardSet(); 63 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 64 if (this->greetingFlare_->getBillboardSet()) 65 this->getNode()->attachObject(this->greetingFlare_->getBillboardSet()); 66 this->greetingFlare_->setVisible(false); 65 if (Core::showsGraphics()) 66 { 67 this->greetingFlare_ = new BillboardSet(); 68 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 69 if (this->greetingFlare_->getBillboardSet()) 70 this->attachOgreObject(this->greetingFlare_->getBillboardSet()); 71 this->greetingFlare_->setVisible(false); 72 } 73 67 74 this->bGreetingFlareVisible_ = false; 68 75 this->bGreeting_ = false; 69 76 77 this->setConfigValues(); 70 78 this->registerVariables(); 71 79 } … … 78 86 { 79 87 if (this->greetingFlare_->getBillboardSet()) 80 this->getNode()->detachObject(this->greetingFlare_->getBillboardSet()); 88 this->detachOgreObject(this->greetingFlare_->getBillboardSet()); 89 81 90 delete this->greetingFlare_; 82 91 } … … 84 93 } 85 94 95 void Spectator::setConfigValues() 96 { 97 SetConfigValue(speed_, 200.0f); 98 } 99 86 100 void Spectator::registerVariables() 87 101 { 88 REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 89 REGISTERDATA(this->bGreeting_, direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 90 REGISTERDATA(this->hudmode_, direction::toclient); 102 registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 103 registerVariable(this->bGreeting_, variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 91 104 } 92 105 … … 99 112 void Spectator::changedFlareVisibility() 100 113 { 101 this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); 114 if ( this->greetingFlare_ ) 115 this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); 102 116 } 103 117 104 118 void Spectator::tick(float dt) 105 119 { 106 this->updateHUD(); 107 108 if (this->isLocallyControlled()) 109 { 110 Vector3 velocity = this->getVelocity(); 111 velocity.normalise(); 112 this->setVelocity(velocity * this->speed_); 113 114 this->yaw(Radian(this->yaw_ * this->rotationSpeed_)); 115 this->pitch(Radian(this->pitch_ * this->rotationSpeed_)); 116 this->roll(Radian(this->roll_ * this->rotationSpeed_)); 120 if (this->hasLocalController()) 121 { 122 float localSpeedSquared = this->localVelocity_.squaredLength(); 123 float localSpeed; 124 if (localSpeedSquared > 1.0) 125 localSpeed = this->speed_ / sqrtf(localSpeedSquared); 126 else 127 localSpeed = this->speed_; 128 129 this->localVelocity_.x *= localSpeed; 130 this->localVelocity_.y *= localSpeed; 131 this->localVelocity_.z *= localSpeed; 132 this->setVelocity(this->getOrientation() * this->localVelocity_); 133 this->localVelocity_.x = 0; 134 this->localVelocity_.y = 0; 135 this->localVelocity_.z = 0; 136 137 if (!this->isInMouseLook()) 138 { 139 this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed())); 140 this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed())); 141 this->roll(Radian(this->roll_ * this->getMouseLookSpeed())); 142 } 117 143 118 144 this->yaw_ = this->pitch_ = this->roll_ = 0; … … 120 146 121 147 SUPER(Spectator, tick, dt); 122 123 if (this->isLocallyControlled())124 {125 this->setVelocity(Vector3::ZERO);126 }127 148 } 128 149 … … 131 152 ControllableEntity::setPlayer(player); 132 153 133 // this->setObjectMode(direction::toclient); 134 } 135 136 void Spectator::startLocalControl() 137 { 138 ControllableEntity::startLocalControl(); 139 // if (this->isLocallyControlled()) 140 // this->testmesh_->setVisible(false); 154 // this->setObjectMode(objectDirection::toclient); 155 } 156 157 void Spectator::startLocalHumanControl() 158 { 159 ControllableEntity::startLocalHumanControl(); 141 160 } 142 161 143 162 void Spectator::moveFrontBack(const Vector2& value) 144 163 { 145 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);164 this->localVelocity_.z -= value.x; 146 165 } 147 166 148 167 void Spectator::moveRightLeft(const Vector2& value) 149 168 { 150 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);169 this->localVelocity_.x += value.x; 151 170 } 152 171 153 172 void Spectator::moveUpDown(const Vector2& value) 154 173 { 155 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);174 this->localVelocity_.y += value.x; 156 175 } 157 176 158 177 void Spectator::rotateYaw(const Vector2& value) 159 178 { 160 this->yaw_ = value.y; 179 this->yaw_ -= value.y; 180 181 ControllableEntity::rotateYaw(value); 161 182 } 162 183 163 184 void Spectator::rotatePitch(const Vector2& value) 164 185 { 165 this->pitch_ = value.y; 186 this->pitch_ += value.y; 187 188 ControllableEntity::rotatePitch(value); 166 189 } 167 190 168 191 void Spectator::rotateRoll(const Vector2& value) 169 192 { 170 this->roll_ = value.y; 171 } 172 173 void Spectator::fire() 193 this->roll_ += value.y; 194 195 ControllableEntity::rotateRoll(value); 196 } 197 198 void Spectator::fire(WeaponMode::Enum fireMode) 174 199 { 175 200 if (this->getPlayer()) … … 187 212 } 188 213 } 189 190 void Spectator::updateHUD()191 {192 // <hack>193 if (Core::isMaster())194 {195 if (this->getPlayer() && this->getGametype())196 {197 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())198 {199 if (!this->getPlayer()->isReadyToSpawn())200 this->hudmode_ = 0;201 else202 this->hudmode_ = 1;203 }204 else if (!this->getGametype()->hasEnded())205 {206 if (this->getGametype()->isStartCountdownRunning())207 this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());208 else209 this->hudmode_ = 3;210 }211 else212 this->hudmode_ = 4;213 }214 else215 return;216 }217 218 if (this->getHUD())219 {220 std::string text;221 int hudmode = this->hudmode_ % 10;222 223 switch (hudmode)224 {225 case 0:226 text = "Press [Fire] to start the match";227 break;228 case 1:229 text = "Waiting for other players";230 break;231 case 2:232 text = convertToString((this->hudmode_ - 2) / 10);233 break;234 case 3:235 text = "Press [Fire] to respawn";236 break;237 case 4:238 text = "Game has ended";239 break;240 default:;241 }242 243 std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();244 for (; it != this->getHUD()->getOverlays().end(); ++it)245 {246 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")247 {248 OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);249 if (overlay)250 overlay->setCaption(text);251 break;252 }253 }254 }255 // </hack>256 }257 214 } -
code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.h
r2087 r2662 42 42 virtual ~Spectator(); 43 43 44 void setConfigValues(); 44 45 void registerVariables(); 45 46 virtual void tick(float dt); 46 47 47 48 virtual void setPlayer(PlayerInfo* player); 48 virtual void startLocal Control();49 virtual void startLocalHumanControl(); 49 50 50 51 virtual void moveFrontBack(const Vector2& value); … … 56 57 virtual void rotateRoll(const Vector2& value); 57 58 58 virtual void fire( );59 virtual void fire(WeaponMode::Enum fireMode); 59 60 virtual void greet(); 60 61 … … 62 63 void changedGreeting(); 63 64 void changedFlareVisibility(); 64 void updateHUD();65 65 66 66 BillboardSet* greetingFlare_; … … 69 69 70 70 float speed_; 71 float rotationSpeed_;72 71 73 72 float yaw_; … … 75 74 float roll_; 76 75 77 int hudmode_;76 Vector3 localVelocity_; 78 77 }; 79 78 } -
code/trunk/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/triggers/PlayerTrigger.cc
r2262 r2662 28 28 29 29 /** 30 @file PlayerTrigger.cc30 @file 31 31 @brief 32 32 Implementation of the PlayerTrigger class. 33 33 */ 34 34 … … 38 38 #include "core/CoreIncludes.h" 39 39 40 namespace orxonox {41 40 namespace orxonox 41 { 42 42 /** 43 43 @brief … … 47 47 { 48 48 RegisterObject(PlayerTrigger); 49 49 50 50 this->player_ = NULL; 51 51 this->isForPlayer_ = true; 52 52 } 53 53 54 54 /** 55 55 @brief … … 66 66 void PlayerTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode) 67 67 { 68 68 SUPER(PlayerTrigger, XMLPort, xmlelement, mode); 69 69 } 70 71 70 } -
code/trunk/src/orxonox/objects/worldentities/triggers/PlayerTrigger.h
r2262 r2662 28 28 29 29 /** 30 @file PlayerTrigger.h30 @file 31 31 @brief 32 32 Definition of the PlayerTrigger class. 33 33 */ 34 34 … … 40 40 #include "Trigger.h" 41 41 42 namespace orxonox {43 42 namespace orxonox 43 { 44 44 /** 45 45 @brief … … 50 50 class _OrxonoxExport PlayerTrigger : public Trigger 51 51 { 52 public: 53 PlayerTrigger(BaseObject* creator); 54 virtual ~PlayerTrigger(); 55 56 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PlayerTrigger object through XML. 52 public: 53 PlayerTrigger(BaseObject* creator); 54 virtual ~PlayerTrigger(); 55 56 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PlayerTrigger object through XML. 57 58 /** 59 @brief Returns the player that triggered the PlayerTrigger. 60 @return Returns a pointer to the ControllableEntity that triggered the PlayerTrigger. 61 */ 62 inline ControllableEntity* getTriggeringPlayer(void) const 63 { return this->player_; } 64 65 /** 66 @brief Checks whether the PlayerTrigger normally returns a ControllableEntity. 67 @return Returns true if the PlayerTrigger normally returns a ControllableEntity. 68 */ 69 inline bool isForPlayer(void) const 70 { return this->isForPlayer_; } 57 71 58 /** 59 @brief Returns the player that triggered the PlayerTrigger. 60 @return Returns a pointer to the ControllableEntity that triggered the PlayerTrigger. 61 */ 62 inline ControllableEntity* getTriggeringPlayer(void) const 63 { return this->player_; } 64 65 /** 66 @brief Checks whether the PlayerTrigger normally returns a ControllableEntity. 67 @return Returns true if the PlayerTrigger normally returns a ControllableEntity. 68 */ 69 inline bool isForPlayer(void) const 70 { return this->isForPlayer_; } 71 72 protected: 73 virtual bool isTriggered(TriggerMode mode) = 0; 74 75 /** 76 @brief Set the player that triggered the PlayerTrigger. This is normally done by classes inheriting vom PlayerTrigger. 77 @param player A pointer to the ControllableEntity that triggered the PlayerTrigger. 78 */ 79 inline void setTriggeringPlayer(ControllableEntity* player) 80 { this->player_ = player; } 72 protected: 73 virtual bool isTriggered(TriggerMode mode) = 0; 74 75 /** 76 @brief Set the player that triggered the PlayerTrigger. This is normally done by classes inheriting vom PlayerTrigger. 77 @param player A pointer to the ControllableEntity that triggered the PlayerTrigger. 78 */ 79 inline void setTriggeringPlayer(ControllableEntity* player) 80 { this->player_ = player; } 81 81 82 82 /** … … 84 84 @param isForPlayer Should be true when the PlayerTrigger schould be set to normally be triggered by ControllableEntities, false if not. 85 85 */ 86 87 88 89 90 91 92 86 inline void setForPlayer(bool isForPlayer) 87 { this->isForPlayer_ = isForPlayer; } 88 89 private: 90 ControllableEntity* player_; //!< The player that triggered the PlayerTrigger. 91 bool isForPlayer_; //!< Is true when the PlayerTrigger schould be set to normally be triggered by ControllableEntities. 92 93 93 }; 94 94 -
code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.cc
- Property svn:mergeinfo changed
r2261 r2662 31 31 32 32 #include <OgreBillboard.h> 33 #include <OgreBillboardSet.h> 33 34 #include "util/Debug.h" 34 35 #include "core/CoreIncludes.h" 35 36 #include "core/ConsoleCommand.h" 36 37 #include "core/XMLPort.h" 38 #include "core/Core.h" 37 39 #include "objects/Scene.h" 38 40 … … 44 46 CreateFactory(Trigger); 45 47 46 Trigger::Trigger(BaseObject* creator) : PositionableEntity(creator)48 Trigger::Trigger(BaseObject* creator) : StaticEntity(creator) 47 49 { 48 50 RegisterObject(Trigger); … … 65 67 // this->bUpdating_ = false; 66 68 67 if (this->getScene() && this->getScene()->getSceneManager())69 if (this->getScene() && Core::showsGraphics()) 68 70 { 69 71 this->debugBillboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); … … 71 73 72 74 if (this->debugBillboard_.getBillboardSet()) 73 this->getNode()->attachObject(this->debugBillboard_.getBillboardSet());75 this->attachOgreObject(this->debugBillboard_.getBillboardSet()); 74 76 } 75 77 … … 106 108 if (!this->BaseObject::isActive()) 107 109 return; 110 111 SUPER(Trigger, tick, dt); 108 112 109 113 bool newTriggered = this->isTriggered() ^ this->bInvertMode_; -
code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.h
- Property svn:mergeinfo changed
r2261 r2662 36 36 37 37 #include "objects/Tickable.h" 38 #include "objects/worldentities/ PositionableEntity.h"38 #include "objects/worldentities/StaticEntity.h" 39 39 #include "tools/BillboardSet.h" 40 40 … … 48 48 }; 49 49 50 class _OrxonoxExport Trigger : public PositionableEntity, public Tickable50 class _OrxonoxExport Trigger : public StaticEntity, public Tickable 51 51 { 52 52 public: -
code/trunk/src/orxonox/overlays/CMakeLists.txt
r2131 r2662 8 8 ADD_SOURCE_DIRECTORY(SRC_FILES debug) 9 9 ADD_SOURCE_DIRECTORY(SRC_FILES hud) 10 ADD_SOURCE_DIRECTORY(SRC_FILES notifications) 11 ADD_SOURCE_DIRECTORY(SRC_FILES stats) 10 12 11 13 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
r2171 r2662 61 61 RegisterObject(OrxonoxOverlay); 62 62 63 this->owner_ = 0; 64 this->group_ = 0; 65 63 66 if (!Core::showsGraphics()) 64 67 ThrowException(NoGraphics, "Can't create OrxonoxOverlay, graphics engine not initialized"); 65 66 // add this overlay to the static map of OrxonoxOverlays67 if (overlays_s.find(this->getName()) != overlays_s.end())68 {69 COUT(1) << "Overlay names should be unique or you cannnot access them via console. Name: \"" << this->getName() << "\"" << std::endl;70 }71 overlays_s[this->getName()] = this;72 68 73 69 // create the Ogre::Overlay … … 92 88 setPosition(Vector2(0.0f, 0.0f)); 93 89 setRotation(Degree(0.0)); 94 setAspectCorrection( true);90 setAspectCorrection(false); 95 91 setBackgroundMaterial(""); 96 92 } … … 130 126 131 127 XMLPortParam(OrxonoxOverlay, "size", setSize, getSize, xmlElement, mode); 132 XMLPortParam(OrxonoxOverlay, "pick Point", setPickPoint, getPickPoint, xmlElement, mode);128 XMLPortParam(OrxonoxOverlay, "pickpoint", setPickPoint, getPickPoint, xmlElement, mode); 133 129 XMLPortParam(OrxonoxOverlay, "position", setPosition, getPosition, xmlElement, mode); 134 130 XMLPortParam(OrxonoxOverlay, "rotation", setRotation, getRotation, xmlElement, mode); 135 XMLPortParam(OrxonoxOverlay, "correct Aspect", setAspectCorrection, getAspectCorrection, xmlElement, mode);131 XMLPortParam(OrxonoxOverlay, "correctaspect", setAspectCorrection, getAspectCorrection, xmlElement, mode); 136 132 XMLPortParam(OrxonoxOverlay, "background", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode); 137 133 } … … 139 135 void OrxonoxOverlay::changedName() 140 136 { 137 SUPER(OrxonoxOverlay, changedName); 138 141 139 OrxonoxOverlay::overlays_s.erase(this->getOldName()); 142 140 -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.h
r2087 r2662 125 125 126 126 //! Gets the rotation angle applied to this overlay in degrees. 127 const Radian& getRotation() const { return this->angle_; }127 const Degree& getRotation() const { return this->angle_; } 128 128 129 129 //! Rotates the overlay by angle degrees. … … 154 154 virtual void changedVisibility(); 155 155 156 inline void setOwner(ControllableEntity* owner) 157 { 158 if (this->owner_ != owner) 159 { 160 this->owner_ = owner; 161 this->changedOwner(); 162 } 163 } 164 inline ControllableEntity* getOwner() const 165 { return this->owner_; } 166 virtual void changedOwner() {} 167 168 inline void setOverlayGroup(OverlayGroup* group) 169 { 170 if (group != this->group_) 171 { 172 this->group_ = group; 173 this->changedOverlayGroup(); 174 } 175 } 176 inline OverlayGroup* getOverlayGroup() const 177 { return this->group_; } 178 virtual void changedOverlayGroup() {} 179 156 180 protected: 157 181 virtual void angleChanged(); … … 172 196 Vector2 position_; //!< Position of the pickPoint on the screen. 173 197 Vector2 pickPoint_; //!< Point on the overlay to pick when translating 174 Radianangle_; //!< Rotation angle of the overlay198 Degree angle_; //!< Rotation angle of the overlay 175 199 RotationState rotState_; //!< horizontal, vertical or inbetween 176 200 … … 182 206 We could also use the ObjectList, but that doesn't guarantee XMLPort(.) was called and is slower. */ 183 207 static std::map<std::string, OrxonoxOverlay*> overlays_s; 208 ControllableEntity* owner_; 209 OverlayGroup* group_; 184 210 }; 211 212 SUPER_FUNCTION(7, OrxonoxOverlay, changedOwner, false); 213 SUPER_FUNCTION(8, OrxonoxOverlay, changedOverlayGroup, false); 185 214 } 186 215 -
code/trunk/src/orxonox/overlays/OverlayGroup.cc
r2087 r2662 55 55 RegisterObject(OverlayGroup); 56 56 57 this->owner_ = 0; 58 57 59 setScale(Vector2(1.0, 1.0)); 58 60 setScroll(Vector2(0.0, 0.0)); … … 113 115 hudElements_[element->getName()] = element; 114 116 element->setVisible(this->isVisible()); 117 if (this->owner_) 118 element->setOwner(this->owner_); 115 119 } 116 120 } … … 137 141 } 138 142 143 void OverlayGroup::setOwner(ControllableEntity* owner) 144 { 145 this->owner_ = owner; 146 147 for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) 148 (*it).second->setOwner(owner); 149 } 139 150 140 151 //########### Console commands ############ -
code/trunk/src/orxonox/overlays/OverlayGroup.h
r2087 r2662 69 69 void changedVisibility(); 70 70 71 private: 71 void setOwner(ControllableEntity* owner); 72 inline ControllableEntity* getOwner() const 73 { return this->owner_; } 74 72 75 //! Scales each OrxonoxOverlay individually by scale. 73 76 void scale(const Vector2& scale) { this->setScale(scale * this->scale_); } … … 85 88 OrxonoxOverlay* getElement(unsigned int index); 86 89 90 private: 87 91 std::map<std::string, OrxonoxOverlay*> hudElements_; //!< Contains all the OrxonoxOverlays of the this group. 88 Vector2 scale_; //!< Current scale (independ ant of the elements).92 Vector2 scale_; //!< Current scale (independent of the elements). 89 93 Vector2 scroll_; //!< Current scrolling offset. 94 ControllableEntity* owner_; //!< The owner of this OverlayGroup 90 95 }; 91 96 } -
code/trunk/src/orxonox/overlays/OverlayText.cc
r2087 r2662 50 50 this->text_->setCharHeight(1.0); 51 51 52 setFont("Monofur");53 setColour(ColourValue(1.0, 1.0, 1.0, 1.0));54 setCaption("");55 setTextSize(1.0f);56 setAlignmentString("left");52 this->setFont("Monofur"); 53 this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 54 this->setCaption(""); 55 this->setTextSize(1.0f); 56 this->setAlignmentString("left"); 57 57 58 58 this->background_->addChild(this->text_); … … 69 69 SUPER(OverlayText, XMLPort, xmlElement, mode); 70 70 71 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode); 72 XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode); 73 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode); 74 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode); 75 XMLPortParam(OverlayText, "align", setAlignmentString, getAlignmentString, xmlElement, mode); 71 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode); 72 XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode); 73 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode); 74 XMLPortParam(OverlayText, "textsize", setTextSize, getTextSize, xmlElement, mode); 75 XMLPortParam(OverlayText, "align", setAlignmentString, getAlignmentString, xmlElement, mode); 76 XMLPortParam(OverlayText, "spacewidth", setSpaceWidth, getSpaceWidth, xmlElement, mode); 76 77 } 77 78 -
code/trunk/src/orxonox/overlays/OverlayText.h
r2087 r2662 47 47 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 48 48 49 void setCaption(const std::string& caption) { this->text_->setCaption(caption); }50 std::string getCaption() const { return this->text_->getCaption(); }49 inline void setCaption(const std::string& caption) { this->text_->setCaption(caption); } 50 inline std::string getCaption() const { return this->text_->getCaption(); } 51 51 52 52 void setFont(const std::string& font); 53 const std::string& getFont() const { return this->text_->getFontName(); }53 inline const std::string& getFont() const { return this->text_->getFontName(); } 54 54 55 void setColour(const ColourValue& colour) { this->text_->setColour(colour); }56 const ColourValue& getColour() const { return this->text_->getColour(); }55 inline void setSpaceWidth(float width) { this->text_->setSpaceWidth(width); } 56 inline float getSpaceWidth() const { return this->text_->getSpaceWidth(); } 57 57 58 void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment) { this->text_->setAlignment(alignment); }59 Ogre::TextAreaOverlayElement::Alignment getAlignment() const { return this->text_->getAlignment(); }58 inline void setColour(const ColourValue& colour) { this->text_->setColour(colour); } 59 inline const ColourValue& getColour() const { return this->text_->getColour(); } 60 60 61 protected:62 virtual void sizeChanged();61 inline void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment) { this->text_->setAlignment(alignment); } 62 inline Ogre::TextAreaOverlayElement::Alignment getAlignment() const { return this->text_->getAlignment(); } 63 63 64 64 void setAlignmentString(const std::string& alignment); 65 65 std::string getAlignmentString() const; 66 66 67 void setTextSize(float size) { this->setSize(Vector2(size, size)); } 68 float getTextSize() const { return this->getSize().y; } 67 inline void setTextSize(float size) { this->setSize(Vector2(size, size)); } 68 inline float getTextSize() const { return this->getSize().y; } 69 70 protected: 71 virtual void sizeChanged(); 69 72 70 73 Ogre::TextAreaOverlayElement* text_; -
code/trunk/src/orxonox/overlays/debug/DebugFPSText.cc
r2087 r2662 49 49 void DebugFPSText::tick(float dt) 50 50 { 51 SUPER(DebugFPSText, tick, dt); 52 51 53 float fps = GraphicsEngine::getInstance().getAverageFramesPerSecond(); 52 54 this->setCaption(convertToString(fps)); -
code/trunk/src/orxonox/overlays/debug/DebugRTRText.cc
r2087 r2662 49 49 void DebugRTRText::tick(float dt) 50 50 { 51 SUPER(DebugRTRText, tick, dt); 52 51 53 float rtr = GraphicsEngine::getInstance().getAverageTickTime(); 52 54 this->setCaption(convertToString(rtr)); -
code/trunk/src/orxonox/overlays/hud/CMakeLists.txt
r2131 r2662 4 4 HUDRadar.cc 5 5 HUDSpeedBar.cc 6 HUDHealthBar.cc 6 7 ChatOverlay.cc 8 GametypeStatus.cc 7 9 ) 8 10 -
code/trunk/src/orxonox/overlays/hud/HUDBar.cc
r2087 r2662 51 51 RegisterObject(BarColour); 52 52 53 setColour(ColourValue(1.0, 1.0, 1.0, 1.0));54 setPosition(0.0);53 this->setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 54 this->setPosition(0.0); 55 55 } 56 56 … … 84 84 this->bar_->setMaterialName(materialname); 85 85 86 setValue(0.4567654f); 87 setRightToLeft(false); 88 setAutoColour(true); 86 this->value_ = 1.0f; // initielize with 1.0f to trigger a change when calling setValue(0.0f) on the line below 87 this->setValue(0.0f); // <-- 88 this->setRightToLeft(false); 89 this->setAutoColour(true); 90 this->currentColour_ = ColourValue::White; 89 91 90 92 this->background_->addChild(bar_); … … 101 103 SUPER(HUDBar, XMLPort, xmlElement, mode); 102 104 103 XMLPortParam(HUDBar, "initialValue", setValue, getValue, xmlElement, mode); 104 XMLPortParam(HUDBar, "rightToLeft", setRightToLeft, getRightToLeft, xmlElement, mode); 105 XMLPortParam(HUDBar, "autoColour", setAutoColour, getAutoColour, xmlElement, mode); 105 XMLPortParam(HUDBar, "initialvalue", setValue, getValue, xmlElement, mode); 106 XMLPortParam(HUDBar, "righttoleft", setRightToLeft, getRightToLeft, xmlElement, mode); 107 XMLPortParam(HUDBar, "autocolour", setAutoColour, getAutoColour, xmlElement, mode); 108 XMLPortParam(HUDBar, "bartexture", setBarTexture, getBarTexture, xmlElement, mode); 106 109 XMLPortObject(HUDBar, BarColour, "", addColour, getColour, xmlElement, mode); 107 110 } … … 130 133 { 131 134 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour2); 135 this->currentColour_ = colour2; 132 136 } 133 137 else if (value1 < this->value_) 134 138 { 135 139 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1); 140 this->currentColour_ = colour1; 136 141 } 137 142 else … … 139 144 //float interpolationfactor = (this->value_ - value2) / (value1 - value2); 140 145 float interpolationfactor = interpolateSmooth((this->value_ - value2) / (value1 - value2), 0.0f, 1.0f); 141 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1 * interpolationfactor + colour2 * (1 - interpolationfactor)); 146 this->currentColour_ = colour1 * interpolationfactor + colour2 * (1 - interpolationfactor); 147 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, this->currentColour_); 148 142 149 } 143 150 } … … 181 188 this->colours_.clear(); 182 189 } 190 191 void HUDBar::setBarTexture(const std::string& texture) 192 { 193 this->textureUnitState_->setTextureName(texture); 194 } 195 196 const std::string& HUDBar::getBarTexture() const 197 { 198 return this->textureUnitState_->getTextureName(); 199 } 183 200 } -
code/trunk/src/orxonox/overlays/hud/HUDBar.h
r2087 r2662 71 71 void clearColours(); 72 72 73 void setRightToLeft(bool r2l) { this->right2Left_ = r2l; this->valueChanged(); } 74 bool getRightToLeft() const { return this->right2Left_; } 73 inline void setRightToLeft(bool r2l) 74 { 75 if (r2l != this->right2Left_) 76 { 77 this->right2Left_ = r2l; 78 this->valueChanged(); 79 } 80 } 81 inline bool getRightToLeft() const 82 { return this->right2Left_; } 75 83 76 void setValue(float value) { this->value_ = clamp(value, 0.0f, 1.0f); this->valueChanged(); } 77 float getValue() const { return this->value_; } 84 inline void setValue(float value) 85 { 86 float temp = clamp(value, 0.0f, 1.0f); 87 if (temp != this->value_) 88 { 89 this->value_ = temp; 90 this->valueChanged(); 91 } 92 } 93 inline float getValue() const 94 { return this->value_; } 78 95 79 void setAutoColour(bool val) { this->autoColour_ = val; this->valueChanged(); } 80 bool getAutoColour() const { return this->autoColour_; } 96 inline void setAutoColour(bool val) 97 { 98 if (val != this->autoColour_) 99 { 100 this->autoColour_ = val; 101 this->valueChanged(); 102 103 if (!val) 104 this->currentColour_ = ColourValue::White; 105 } 106 } 107 inline bool getAutoColour() const 108 { return this->autoColour_; } 109 110 void setBarTexture(const std::string& texture); 111 const std::string& getBarTexture() const; 112 113 inline const ColourValue& getCurrentBarColour() const 114 { return this->currentColour_; } 81 115 82 116 protected: … … 90 124 bool autoColour_; //!< whether bar changes colour automatically 91 125 float value_; //!< progress of bar 126 ColourValue currentColour_; 92 127 93 128 Ogre::PanelOverlayElement* bar_; -
code/trunk/src/orxonox/overlays/hud/HUDNavigation.cc
r2087 r2662 129 129 void HUDNavigation::tick(float dt) 130 130 { 131 SUPER(HUDNavigation, tick, dt); 132 131 133 if (!Radar::getInstance().getFocus()) 132 134 { … … 149 151 */ 150 152 // transform to screen coordinates 151 Vector3 pos = /*transformationMatrix * */Radar::getInstance().getFocus()->get WorldPosition();153 Vector3 pos = /*transformationMatrix * */Radar::getInstance().getFocus()->getRVWorldPosition(); 152 154 153 155 bool outOfView; … … 223 225 /* 224 226 Vector3 aimpos = transformationMatrix * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), 225 Projectile::getSpeed(), Radar::getInstance().getFocus()->get WorldPosition(), Radar::getInstance().getFocus()->getOrientedVelocity());227 Projectile::getSpeed(), Radar::getInstance().getFocus()->getRVWorldPosition(), Radar::getInstance().getFocus()->getRVOrientedVelocity()); 226 228 */ 227 229 if (wasOutOfView_) … … 250 252 /* 251 253 if (Radar::getInstance().getFocus()) 252 return (Radar::getInstance().getFocus()->get WorldPosition() - SpaceShip::getLocalShip()->getPosition()).length();254 return (Radar::getInstance().getFocus()->getRVWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 253 255 else 254 256 */ -
code/trunk/src/orxonox/overlays/hud/HUDRadar.cc
r2087 r2662 40 40 #include "core/XMLPort.h" 41 41 #include "objects/Radar.h" 42 #include "objects/worldentities/WorldEntity.h" 43 #include "objects/worldentities/pawns/Pawn.h" 42 44 #include "tools/TextureGenerator.h" 43 45 … … 51 53 RegisterObject(HUDRadar); 52 54 53 marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()55 this->marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 54 56 .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberString())); 55 marker_->setMaterialName("Orxonox/RadarMarker");56 overlay_->add2D(marker_);57 marker_->hide();57 this->marker_->setMaterialName("Orxonox/RadarMarker"); 58 this->overlay_->add2D(this->marker_); 59 this->marker_->hide(); 58 60 59 setRadarSensitivity(1.0f);60 setHalfDotSizeDistance(3000.0f);61 setMaximumDotSize(0.1f);61 this->setRadarSensitivity(1.0f); 62 this->setHalfDotSizeDistance(3000.0f); 63 this->setMaximumDotSize(0.1f); 62 64 63 shapeMaterials_[RadarViewable::Dot] = "RadarSquare.tga"; 64 shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga"; 65 shapeMaterials_[RadarViewable::Square] = "RadarSquare.tga"; 65 this->shapeMaterials_[RadarViewable::Dot] = "RadarDot.tga"; 66 this->shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga"; 67 this->shapeMaterials_[RadarViewable::Square] = "RadarSquare.tga"; 68 69 this->owner_ = 0; 66 70 } 67 71 … … 90 94 void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked) 91 95 { 92 /* 96 if (object == (RadarViewable*)this->owner_) 97 return; 98 93 99 const WorldEntity* wePointer = object->getWorldEntity(); 94 100 95 101 // Just to be sure that we actually have a WorldEntity. 96 102 // We could do a dynamic_cast, but that would be a lot slower. 97 if (!wePointer )103 if (!wePointer || !this->owner_) 98 104 { 99 CCOUT(4) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 105 if (!wePointer) 106 CCOUT(2) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 107 if (!this->owner_) 108 CCOUT(2) << "No owner defined" << std::endl; 100 109 return; 101 110 } 102 */ 111 103 112 // try to find a panel already created 104 113 Ogre::PanelOverlayElement* panel; … … 112 121 // get right material 113 122 panel->setMaterialName(TextureGenerator::getMaterialName( 114 shapeMaterials_[object->getRadarObject Type()], object->getRadarObjectColour()));123 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour())); 115 124 this->overlay_->add2D(panel); 116 125 this->itRadarDots_ = this->radarDots_.end(); … … 121 130 ++itRadarDots_; 122 131 std::string materialName = TextureGenerator::getMaterialName( 123 shapeMaterials_[object->getRadarObject Type()], object->getRadarObjectColour());132 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour()); 124 133 if (materialName != panel->getMaterialName()) 125 134 panel->setMaterialName(materialName); 126 135 } 127 136 panel->show(); 128 /* 137 129 138 // set size to fit distance... 130 float distance = (wePointer->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length();139 float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length(); 131 140 // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda) 132 141 float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance); … … 134 143 135 144 // calc position on radar... 136 Vector2 coord = get2DViewcoordinates( SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), wePointer->getWorldPosition());145 Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition()); 137 146 coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 138 147 panel->setPosition((1.0 + coord.x - size) * 0.5, (1.0 - coord.y - size) * 0.5); … … 144 153 this->marker_->setPosition((1.0 + coord.x - size * 1.5) * 0.5, (1.0 - coord.y - size * 1.5) * 0.5); 145 154 } 146 */147 155 } 148 156 … … 154 162 this->marker_->hide(); 155 163 } 164 165 void HUDRadar::changedOwner() 166 { 167 SUPER(HUDRadar, changedOwner); 168 169 this->owner_ = dynamic_cast<Pawn*>(this->getOwner()); 170 } 156 171 } -
code/trunk/src/orxonox/overlays/hud/HUDRadar.h
r2087 r2662 49 49 50 50 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 51 virtual void changedOwner(); 51 52 52 53 private: … … 76 77 77 78 float sensitivity_; 79 80 Pawn* owner_; 78 81 }; 79 82 } -
code/trunk/src/orxonox/overlays/hud/HUDSpeedBar.cc
r2087 r2662 31 31 #include "HUDSpeedBar.h" 32 32 #include "core/CoreIncludes.h" 33 #include "objects/worldentities/pawns/SpaceShip.h" 34 #include "objects/items/Engine.h" 33 35 34 36 namespace orxonox … … 41 43 RegisterObject(HUDSpeedBar); 42 44 45 this->owner_ = 0; 43 46 } 44 47 … … 49 52 void HUDSpeedBar::tick(float dt) 50 53 { 51 /* 52 SpaceShip* ship = SpaceShip::getLocalShip(); 53 if ( ship)54 SUPER(HUDSpeedBar, tick, dt); 55 56 if (this->owner_ && this->owner_->getEngine()) 54 57 { 55 float v = ship->getVelocity().length(); 56 float value = v / ship->getMaxSpeed(); 57 if (value != this->getValue()) 58 this->setValue(value); 58 float value = this->owner_->getVelocity().length() / (this->owner_->getEngine()->getMaxSpeedFront() * this->owner_->getEngine()->getSpeedFactor() * this->owner_->getEngine()->getBoostFactor()); 59 this->setValue(value); 59 60 } 60 */ 61 } 62 63 void HUDSpeedBar::changedOwner() 64 { 65 SUPER(HUDSpeedBar, changedOwner); 66 67 this->owner_ = dynamic_cast<SpaceShip*>(this->getOwner()); 61 68 } 62 69 } -
code/trunk/src/orxonox/overlays/hud/HUDSpeedBar.h
r2087 r2662 45 45 46 46 virtual void tick(float dt); 47 virtual void changedOwner(); 48 49 private: 50 SpaceShip* owner_; 47 51 }; 48 52 } -
code/trunk/src/orxonox/tools/BillboardSet.cc
r2171 r2662 34 34 35 35 #include <OgreSceneManager.h> 36 #include <OgreBillboardSet.h> 36 37 #include <OgreBillboard.h> 37 38 -
code/trunk/src/orxonox/tools/BillboardSet.h
r2087 r2662 33 33 34 34 #include <string> 35 #include <Ogre BillboardSet.h>35 #include <OgrePrerequisites.h> 36 36 37 37 #include "util/Math.h" … … 52 52 inline Ogre::BillboardSet* getBillboardSet() 53 53 { return this->billboardSet_; } 54 inline Ogre::SceneManager* getSceneManager() 55 { return this->scenemanager_; } 54 56 55 57 const std::string& getName() const; -
code/trunk/src/orxonox/tools/CMakeLists.txt
r2131 r2662 3 3 Mesh.cc 4 4 ParticleInterface.cc 5 Shader.cc 5 6 TextureGenerator.cc 6 7 Timer.cc -
code/trunk/src/orxonox/tools/Mesh.cc
r2171 r2662 31 31 32 32 #include <sstream> 33 #include <OgreEntity.h> 33 34 #include <OgreSceneManager.h> 34 35 #include <cassert> -
code/trunk/src/orxonox/tools/Mesh.h
r2087 r2662 33 33 34 34 #include <string> 35 #include <Ogre Entity.h>35 #include <OgrePrerequisites.h> 36 36 37 37 namespace orxonox -
code/trunk/src/orxonox/tools/ParticleInterface.cc
r2171 r2662 52 52 ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) 53 53 { 54 Register RootObject(ParticleInterface);54 RegisterObject(ParticleInterface); 55 55 56 56 assert(scenemanager); 57 57 58 58 this->scenemanager_ = scenemanager; 59 this->sceneNode_ = 0;60 59 this->particleSystem_ = 0; 61 60 … … 63 62 this->bVisible_ = true; 64 63 this->bAllowedByLOD_ = true; 64 this->speedFactor_ = 1.0f; 65 65 66 66 if (Core::showsGraphics()) … … 69 69 { 70 70 this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 71 this->particleSystem_->setSpeedFactor(1.0f); 72 // this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 71 this->setSpeedFactor(1.0f); 73 72 } 74 73 catch (...) … … 87 86 { 88 87 this->particleSystem_->removeAllEmitters(); 89 this->detachFromSceneNode();90 88 this->scenemanager_->destroyParticleSystem(this->particleSystem_); 91 }92 }93 94 void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)95 {96 if (this->sceneNode_)97 this->detachFromSceneNode();98 99 if (this->particleSystem_)100 {101 this->sceneNode_ = sceneNode;102 this->sceneNode_->attachObject(this->particleSystem_);103 }104 }105 106 void ParticleInterface::detachFromSceneNode()107 {108 if (this->sceneNode_)109 {110 if (this->particleSystem_)111 this->sceneNode_->detachObject(this->particleSystem_);112 this->sceneNode_ = 0;113 89 } 114 90 } … … 224 200 void ParticleInterface::setSpeedFactor(float factor) 225 201 { 226 if (this->particleSystem_) 227 { 228 // this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); 229 this->particleSystem_->setSpeedFactor(1.0f * factor); 230 } 231 } 232 float ParticleInterface::getSpeedFactor() const 233 { 234 if (this->particleSystem_) 235 { 236 // return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); 237 return (this->particleSystem_->getSpeedFactor() / 1.0f); 238 } 239 else 240 return 1.0f; 202 this->speedFactor_ = factor; 203 204 if (this->particleSystem_) 205 this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor()); 206 } 207 void ParticleInterface::changedTimeFactor(float factor_new, float factor_old) 208 { 209 this->setSpeedFactor(this->speedFactor_); 241 210 } 242 211 -
code/trunk/src/orxonox/tools/ParticleInterface.h
r2087 r2662 33 33 34 34 #include <string> 35 #include <OgreP articleEmitter.h>35 #include <OgrePrerequisites.h> 36 36 37 37 #include "core/OrxonoxClass.h" 38 38 #include "util/Math.h" 39 #include "gamestates/GSRoot.h" 39 40 40 41 #define getAllEmitters() \ … … 45 46 namespace orxonox 46 47 { 47 class _OrxonoxExport ParticleInterface : public OrxonoxClass48 class _OrxonoxExport ParticleInterface : public TimeFactorListener 48 49 { 49 50 public: … … 53 54 inline Ogre::ParticleSystem* getParticleSystem() const 54 55 { return this->particleSystem_; } 55 56 void addToSceneNode(Ogre::SceneNode* sceneNode);57 void detachFromSceneNode();58 56 59 57 Ogre::ParticleEmitter* createNewEmitter(); … … 69 67 unsigned int getNumAffectors() const; 70 68 71 float getSpeedFactor() const; 69 inline float getSpeedFactor() const 70 { return this->speedFactor_; } 72 71 void setSpeedFactor(float factor); 73 72 bool getKeepParticlesInLocalSpace() const; … … 90 89 { return ParticleInterface::currentParticleInterface_s; } 91 90 91 protected: 92 virtual void changedTimeFactor(float factor_new, float factor_old); 93 92 94 private: 93 95 void updateVisibility(); … … 96 98 static unsigned int counter_s; 97 99 98 Ogre::SceneNode* sceneNode_;99 100 Ogre::ParticleSystem* particleSystem_; 100 101 bool bVisible_; … … 102 103 bool bAllowedByLOD_; 103 104 unsigned int detaillevel_; //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high) 105 float speedFactor_; 104 106 Ogre::SceneManager* scenemanager_; 105 107 }; -
code/trunk/src/orxonox/tools/Timer.cc
r2087 r2662 96 96 this->time_ = 0; 97 97 98 Register RootObject(TimerBase);98 RegisterObject(TimerBase); 99 99 } 100 100 … … 137 137 { 138 138 // If active: Decrease the timer by the duration of the last frame 139 this->time_ -= time.getDeltaTimeMicroseconds();139 this->time_ -= (long long)(time.getDeltaTimeMicroseconds() * this->getTimeFactor()); 140 140 141 141 if (this->time_ <= 0) -
code/trunk/src/orxonox/tools/Timer.h
r2171 r2662 62 62 63 63 #include "OrxonoxPrereqs.h" 64 #include "core/Executor.h" 64 65 #include "core/OrxonoxClass.h" 66 #include "gamestates/GSRoot.h" 65 67 66 68 namespace orxonox … … 72 74 73 75 //! TimerBase is the parent of the Timer class. 74 class _OrxonoxExport TimerBase : public OrxonoxClass76 class _OrxonoxExport TimerBase : public TimeFactorListener 75 77 { 76 78 public: … … 159 161 this->bLoop_ = bLoop; 160 162 executor->setObject(object); 161 this->executor_ = (Executor*)executor;163 this->executor_ = static_cast<Executor*>(executor); 162 164 this->bActive_ = true; 163 165 … … 197 199 this->setInterval(interval); 198 200 this->bLoop_ = bLoop; 199 this->executor_ = (Executor*)executor;201 this->executor_ = executor; 200 202 this->bActive_ = true; 201 203 -
code/trunk/src/orxonox/tools/WindowEventListener.h
r1755 r2662 41 41 class _OrxonoxExport WindowEventListener : virtual public OrxonoxClass 42 42 { 43 public:44 WindowEventListener();45 virtual ~WindowEventListener() { }43 public: 44 WindowEventListener(); 45 virtual ~WindowEventListener() { } 46 46 47 47 /** Window has moved position */
Note: See TracChangeset
for help on using the changeset viewer.