Changeset 6187
- Timestamp:
- Dec 1, 2009, 6:48:51 PM (15 years ago)
- Location:
- code/branches/presentation2
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/data/levels/templates/spaceship_assff.oxt
r6147 r6187 70 70 accelerationupdown = 125 71 71 > 72 <active> 72 <EffectContainer condition="idle"> 73 <WorldSound mainstate="activity" source="sounds/Engine_idle.ogg" loop=1 active=false/> 74 </EffectContainer> 75 <EffectContainer condition="not idle"> 73 76 <FadingBillboard mainstate=activity active=false scale=0.1 position="0, 0, 9" colour="0.2, 0.65, 1.0, 1.0" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 /> 74 77 <!-- … … 76 79 <Light mainstate=visibility position="-8, 0, 8" diffuse="0.3, 0.6, 1.0" specular="0.3, 0.6, 1.0" attenuation="600, 1.0, 0.007, 0.0002" type=point /> 77 80 --> 78 <!--WorldSound mainstate=activity source="sounds/Engine_low.ogg" loop=1 /--> 79 </active> 80 <forward> 81 </EffectContainer> 82 <EffectContainer condition="normal or brake"> 83 <WorldSound mainstate="activity" source="sounds/Engine_low.ogg" loop=1 active=false/> 84 </EffectContainer> 85 <EffectContainer condition="normal or boost"> 81 86 <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" /> 82 87 <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.2, 0.65, 1.0, 1.0" width=15 length=1500 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" /> 83 <WorldSound mainstate=activity source="sounds/Engine_low.ogg" loop=1 /> 84 </forward> 85 <boost> 88 </EffectContainer> 89 <EffectContainer condition="boost"> 86 90 <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 7.6, 0, 6" colour="0.6, 0.75, 0.8, 0.7" width=40 length=1000 lifetime=1 elements=30 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Examples/Flare" /> 87 91 <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-7.6, 0, 6" colour="0.6, 0.75, 0.8, 0.7" width=40 length=1000 lifetime=1 elements=30 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Examples/Flare" /> 88 < !--WorldSound mainstate=activity source="sounds/Engine_high.ogg" loop=1 /-->89 </ boost>90 < brake>92 <WorldSound mainstate="activity" source="sounds/Engine_high.ogg" loop=1 active=false/> 93 </EffectContainer> 94 <EffectContainer condition="brake"> 91 95 <FadingBillboard mainstate=activity active=false scale=0.3 position=" 8, 0, 6" colour="0.5, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 /> 92 96 <FadingBillboard mainstate=activity active=false scale=0.3 position="-8, 0, 6" colour="0.5, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 /> 93 97 <FadingBillboard mainstate=activity active=false scale=0.15 position=" 8, 0, 6" colour="1.0, 0.0, 0.0, 1.0" material="Flares/backlightflare" turnontime=0.5 turnofftime=0.5 /> 94 98 <FadingBillboard mainstate=activity active=false scale=0.15 position="-8, 0, 6" colour="1.0, 0.0, 0.0, 1.0" material="Flares/backlightflare" turnontime=0.5 turnofftime=0.5 /> 95 </ brake>99 </EffectContainer> 96 100 </MultiStateEngine> 97 101 </Template> -
code/branches/presentation2/src/orxonox/items/MultiStateEngine.cc
r5929 r6187 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 29 30 #include "MultiStateEngine.h" 30 31 32 extern "C" { 33 #include <lua.h> 34 } 35 36 #include "util/Convert.h" 31 37 #include "core/CoreIncludes.h" 32 38 #include "core/GameMode.h" 39 #include "core/LuaState.h" 33 40 #include "core/XMLPort.h" 41 #include "worldentities/EffectContainer.h" 34 42 #include "worldentities/pawns/SpaceShip.h" 35 43 … … 37 45 { 38 46 static const float FORWARD_EFFECT_VELOCITY_THRESHOLD = 20; 39 40 static const unsigned char STATE_ACTIVE = 1;41 static const unsigned char STATE_FORWARD = 2;42 static const unsigned char STATE_BOOST = 4;43 static const unsigned char STATE_BRAKE = 8;44 47 45 48 CreateFactory(MultiStateEngine); … … 49 52 RegisterObject(MultiStateEngine); 50 53 54 this->lua_ = new LuaState(); 51 55 this->state_ = 0; 52 56 … … 59 63 { 60 64 // We have no ship, so the effects are not attached and won't be destroyed automatically 61 for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it) 62 (*it)->destroy(); 63 for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it) 64 (*it)->destroy(); 65 for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it) 66 (*it)->destroy(); 67 for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it) 68 (*it)->destroy(); 65 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 66 for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsBegin(); ++it2) 67 (*it2)->destroy(); 68 delete this->lua_; 69 69 } 70 70 } … … 73 73 { 74 74 SUPER(MultiStateEngine, XMLPort, xmlelement, mode); 75 76 XMLPortObject(MultiStateEngine, WorldEntity, "active", addActiveEffect, getActiveEffect, xmlelement, mode); 77 XMLPortObject(MultiStateEngine, WorldEntity, "forward", addForwardEffect, getForwardEffect, xmlelement, mode); 78 XMLPortObject(MultiStateEngine, WorldEntity, "boost", addBoostEffect, getBoostEffect, xmlelement, mode); 79 XMLPortObject(MultiStateEngine, WorldEntity, "brake", addBrakeEffect, getBrakeEffect, xmlelement, mode); 75 XMLPortObject(MultiStateEngine, EffectContainer, "", addEffectContainer, getEffectContainer, xmlelement, mode); 80 76 } 81 77 … … 97 93 98 94 bool forward = (direction.z < 0 && velocity.z < -FORWARD_EFFECT_VELOCITY_THRESHOLD); 99 bool boost = (this->getShip()->getBoost() && forward);100 bool brake = (direction.z > 0 && velocity.z < 0);101 bool active = (direction != Vector3::ZERO && !brake);102 95 103 if (active) 104 this->state_ |= STATE_ACTIVE; 96 int newState = 0; 97 if (this->getShip()->getBoost() && forward) 98 newState = Boost; 99 else if (forward && !newState) // newState == Boost 100 newState = Normal; 101 else if (direction.z > 0 && velocity.z < 0) 102 newState = Brake; 105 103 else 106 this->state_ &= ~STATE_ACTIVE;104 newState = Idle; 107 105 108 if (forward) 109 this->state_ |= STATE_FORWARD; 110 else 111 this->state_ &= ~STATE_FORWARD; 106 if (newState != this->state_) 107 { 108 int changes = newState | this->state_; 109 if (changes & Idle) 110 { 111 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Idle); 112 lua_setglobal(this->lua_->getInternalLuaState(), "idle"); 113 } 114 if (changes & Normal) 115 { 116 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Normal); 117 lua_setglobal(this->lua_->getInternalLuaState(), "normal"); 118 } 119 if (changes & Brake) 120 { 121 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Brake); 122 lua_setglobal(this->lua_->getInternalLuaState(), "brake"); 123 } 124 if (changes & Boost) 125 { 126 lua_pushboolean(this->lua_->getInternalLuaState(), newState & Boost); 127 lua_setglobal(this->lua_->getInternalLuaState(), "boost"); 128 } 112 129 113 if (boost) 114 this->state_ |= STATE_BOOST; 115 else 116 this->state_ &= ~STATE_BOOST; 130 // Update all effect conditions 131 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 132 (*it)->updateCondition(); 117 133 118 if (brake) 119 this->state_ |= STATE_BRAKE; 120 else 121 this->state_ &= ~STATE_BRAKE; 134 this->state_ = newState; 135 } 122 136 } 123 137 124 138 if (GameMode::isMaster()) 125 139 { 126 for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)127 (*it)->setMainState(this->state_ & STATE_ACTIVE);128 for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)129 (*it)->setMainState(this->state_ & STATE_FORWARD);130 for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)131 (*it)->setMainState(this->state_ & STATE_BOOST);132 for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)133 (*it)->setMainState(this->state_ & STATE_BRAKE);134 140 } 135 141 } … … 145 151 return; 146 152 147 for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it) 148 ship->attach(*it); 149 for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it) 150 ship->attach(*it); 151 for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it) 152 ship->attach(*it); 153 for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it) 154 ship->attach(*it); 153 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 154 for (std::vector<WorldEntity*>::const_iterator it2 = (*it)->getEffectsBegin(); it2 != (*it)->getEffectsEnd(); ++it2) 155 this->getShip()->attach(*it2); 155 156 } 156 157 157 void MultiStateEngine::add ActiveEffect(WorldEntity* effect)158 void MultiStateEngine::addEffectContainer(EffectContainer* effect) 158 159 { 159 this->activeEffects_.push_back(effect); 160 if (effect == NULL) 161 return; 162 effect->setLuaState(this->lua_, "f" + multi_cast<std::string>(this->effectContainers_.size())); 163 this->effectContainers_.push_back(effect); 160 164 if (this->getShip()) 161 this->getShip()->attach(effect); 165 { 166 for (std::vector<WorldEntity*>::const_iterator it = effect->getEffectsBegin(); it != effect->getEffectsBegin(); ++it) 167 this->getShip()->attach(*it); 168 } 162 169 } 163 170 164 void MultiStateEngine::addForwardEffect(WorldEntity* effect) 165 { 166 this->forwardEffects_.push_back(effect); 167 if (this->getShip()) 168 this->getShip()->attach(effect); 169 } 170 171 void MultiStateEngine::addBoostEffect(WorldEntity* effect) 172 { 173 this->boostEffects_.push_back(effect); 174 if (this->getShip()) 175 this->getShip()->attach(effect); 176 } 177 178 void MultiStateEngine::addBrakeEffect(WorldEntity* effect) 179 { 180 this->brakeEffects_.push_back(effect); 181 if (this->getShip()) 182 this->getShip()->attach(effect); 183 } 184 185 WorldEntity* MultiStateEngine::getActiveEffect(unsigned int index) const 171 EffectContainer* MultiStateEngine::getEffectContainer(unsigned int index) const 186 172 { 187 173 unsigned int i = 0; 188 for (std:: list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)174 for (std::vector<EffectContainer*>::const_iterator it = this->effectContainers_.begin(); it != this->effectContainers_.end(); ++it) 189 175 { 190 176 if (i == index) 191 177 return (*it); 192 ++i;193 178 } 194 return 0; 195 } 196 197 WorldEntity* MultiStateEngine::getForwardEffect(unsigned int index) const 198 { 199 unsigned int i = 0; 200 for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it) 201 { 202 if (i == index) 203 return (*it); 204 ++i; 205 } 206 return 0; 207 } 208 209 WorldEntity* MultiStateEngine::getBoostEffect(unsigned int index) const 210 { 211 unsigned int i = 0; 212 for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it) 213 { 214 if (i == index) 215 return (*it); 216 ++i; 217 } 218 return 0; 219 } 220 221 WorldEntity* MultiStateEngine::getBrakeEffect(unsigned int index) const 222 { 223 unsigned int i = 0; 224 for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it) 225 { 226 if (i == index) 227 return (*it); 228 ++i; 229 } 230 return 0; 179 return NULL; 231 180 } 232 181 } -
code/branches/presentation2/src/orxonox/items/MultiStateEngine.h
r5781 r6187 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 < list>35 #include <vector> 35 36 #include "Engine.h" 36 37 37 38 namespace orxonox 38 39 { 40 // forward declaration 41 class EffectContainer; 42 39 43 class _OrxonoxExport MultiStateEngine : public Engine 40 44 { 41 45 public: 46 enum EngineState 47 { 48 Idle = 1, 49 Normal = 2, 50 Brake = 4, 51 Boost = 8 52 }; 53 42 54 MultiStateEngine(BaseObject* creator); 43 55 virtual ~MultiStateEngine(); … … 50 62 virtual void addToSpaceShip(SpaceShip* ship); 51 63 52 void addActiveEffect(WorldEntity* effect); 53 void addForwardEffect(WorldEntity* effect); 54 void addBoostEffect(WorldEntity* effect); 55 void addBrakeEffect(WorldEntity* effect); 56 57 WorldEntity* getActiveEffect(unsigned int index) const; 58 WorldEntity* getForwardEffect(unsigned int index) const; 59 WorldEntity* getBoostEffect(unsigned int index) const; 60 WorldEntity* getBrakeEffect(unsigned int index) const; 64 void addEffectContainer(EffectContainer* effect); 65 EffectContainer* getEffectContainer(unsigned int index) const; 61 66 62 67 private: 63 unsigned char state_; 64 std::list<WorldEntity*> activeEffects_; 65 std::list<WorldEntity*> forwardEffects_; 66 std::list<WorldEntity*> boostEffects_; 67 std::list<WorldEntity*> brakeEffects_; 68 int state_; 69 LuaState* lua_; 70 std::vector<EffectContainer*> effectContainers_; 68 71 }; 69 72 } -
code/branches/presentation2/src/orxonox/worldentities/CMakeLists.txt
r5781 r6187 7 7 8 8 BigExplosion.cc 9 EffectContainer.cc 9 10 ExplosionChunk.cc 10 11 CameraPosition.cc
Note: See TracChangeset
for help on using the changeset viewer.