[Orxonox-commit 1162] r5883 - in code/branches/core5: data/levels src/libraries/core

landauf at orxonox.net landauf at orxonox.net
Mon Oct 5 22:50:19 CEST 2009


Author: landauf
Date: 2009-10-05 22:50:19 +0200 (Mon, 05 Oct 2009)
New Revision: 5883

Modified:
   code/branches/core5/data/levels/events.oxw
   code/branches/core5/src/libraries/core/BaseObject.cc
Log:
main-state now supports also memoryless states (like "spawn" in ParticleSpawner).

Modified: code/branches/core5/data/levels/events.oxw
===================================================================
--- code/branches/core5/data/levels/events.oxw	2009-10-05 19:57:05 UTC (rev 5882)
+++ code/branches/core5/data/levels/events.oxw	2009-10-05 20:50:19 UTC (rev 5883)
@@ -28,7 +28,14 @@
     <Billboard position="-300,100,  0" material="Examples/Flare" colour="1.0, 0.0, 1.0" />
 
 
+
     <!--
+      Begin of the tutorial section.
+    -->
+
+
+
+    <!--
       Note:
       All following examples use only one subobject (in nested layouts). But of course you can add more
       objects. They will all follow the same rules (depending on the example receive, send or pipe events).
@@ -147,15 +154,16 @@
 
 
     <!-- blue -->
+    <!--
       Mainstate:
       Apart from the standard states (like activity and visibility), each object can have a mainstate.
       You can define the mainstate with an xml-attribute: mainstate="state". "state" must be one of the
-      supported boolean states of the object. If the mainstate is set (by default that's not the case),
-      you can send events to the "mainstate" state. This allows you to hide the actually affected state
-      in the event-listener, while the event-source just sends events.
+      supported states of the object (except states which need the originator as a second argument). If
+      the mainstate is set (by default that's not the case), you can send events to the "mainstate" state.
+      This allows you to hide the actually affected state in the event-listener, while the event-source
+      just sends events.
       Note that this example is exactly like the standard case, but the event is sent to the main-state,
       which in turn is set to "visibility".
-    <!--
     -->
     <Billboard position="-200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility">
       <events>
@@ -183,5 +191,33 @@
       </eventlisteners>
     </DistanceTrigger>
 
+
+
+    <!--
+      End of the tutorial section.
+    -->
+
+
+
+    <!--
+      The following example shows again the red (standard layout) and the violet (event forwarding) example,
+      but this time with a memoryless state (spawn) from the ParticleSpawner instead of the boolean state
+      (visibility) in the other examples.
+    -->
+    <Billboard position=" 300,100,300" material="Examples/Flare" colour="1.0, 0.0, 0.0" />
+    <Billboard position="-300,100,300" material="Examples/Flare" colour="1.0, 0.0, 1.0" />
+    <ParticleSpawner position="300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0>
+      <events>
+        <spawn>
+          <DistanceTrigger position="300,100,300" distance=25 target="ControllableEntity" />
+        </spawn>
+      </events>
+    </ParticleSpawner>
+    <DistanceTrigger position="-300,100,300" distance=25 target="ControllableEntity">
+      <eventlisteners>
+        <ParticleSpawner position="-300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0 mainstate="spawn" />
+      </eventlisteners>
+    </DistanceTrigger>
+
   </Scene>
 </Level>

Modified: code/branches/core5/src/libraries/core/BaseObject.cc
===================================================================
--- code/branches/core5/src/libraries/core/BaseObject.cc	2009-10-05 19:57:05 UTC (rev 5882)
+++ code/branches/core5/src/libraries/core/BaseObject.cc	2009-10-05 20:50:19 UTC (rev 5883)
@@ -355,7 +355,17 @@
     void BaseObject::setMainState(bool state)
     {
         if (this->mainStateFunctor_)
-            (*this->mainStateFunctor_)(state);
+        {
+            if (this->mainStateFunctor_->getParamCount() == 0)
+            {
+                if (state)
+                    (*this->mainStateFunctor_)();
+            }
+            else
+            {
+                (*this->mainStateFunctor_)(state);
+            }
+        }
         else
             COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     }
@@ -365,15 +375,23 @@
     */
     void BaseObject::changedMainStateName()
     {
-        this->registerEventStates();
-        
         this->mainStateFunctor_ = 0;
-        
-        std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(this->mainStateName_);
-        if (it != this->eventStates_.end() && it->second->getFunctor() && it->second->getFunctor()->getParamCount() == 1)
-            this->mainStateFunctor_ = it->second->getFunctor();
-        else
-            COUT(2) << "Warning: \"" << this->mainStateName_ << "\" is not a valid MainState." << std::endl;
+
+        if (this->mainStateName_ != "")
+        {
+            this->registerEventStates();
+            
+            std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(this->mainStateName_);
+            if (it != this->eventStates_.end() && it->second->getFunctor())
+            {
+                if (it->second->getFunctor()->getParamCount() <= 1)
+                    this->mainStateFunctor_ = it->second->getFunctor();
+                else
+                    COUT(2) << "Warning: Can't use \"" << this->mainStateName_ << "\" as MainState because it needs a second argument." << std::endl;
+            }
+            else
+                COUT(2) << "Warning: \"" << this->mainStateName_ << "\" is not a valid MainState." << std::endl;
+        }
     }
     
     /**




More information about the Orxonox-commit mailing list