Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5883


Ignore:
Timestamp:
Oct 5, 2009, 10:50:19 PM (15 years ago)
Author:
landauf
Message:

main-state now supports also memoryless states (like "spawn" in ParticleSpawner).

Location:
code/branches/core5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/data/levels/events.oxw

    r5882 r5883  
    2929
    3030
     31
     32    <!--
     33      Begin of the tutorial section.
     34    -->
     35
     36
     37
    3138    <!--
    3239      Note:
     
    148155
    149156    <!-- blue -->
     157    <!--
    150158      Mainstate:
    151159      Apart from the standard states (like activity and visibility), each object can have a mainstate.
    152160      You can define the mainstate with an xml-attribute: mainstate="state". "state" must be one of the
    153       supported boolean states of the object. If the mainstate is set (by default that's not the case),
    154       you can send events to the "mainstate" state. This allows you to hide the actually affected state
    155       in the event-listener, while the event-source just sends events.
     161      supported states of the object (except states which need the originator as a second argument). If
     162      the mainstate is set (by default that's not the case), you can send events to the "mainstate" state.
     163      This allows you to hide the actually affected state in the event-listener, while the event-source
     164      just sends events.
    156165      Note that this example is exactly like the standard case, but the event is sent to the main-state,
    157166      which in turn is set to "visibility".
    158     <!--
    159167    -->
    160168    <Billboard position="-200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility">
     
    184192    </DistanceTrigger>
    185193
     194
     195
     196    <!--
     197      End of the tutorial section.
     198    -->
     199
     200
     201
     202    <!--
     203      The following example shows again the red (standard layout) and the violet (event forwarding) example,
     204      but this time with a memoryless state (spawn) from the ParticleSpawner instead of the boolean state
     205      (visibility) in the other examples.
     206    -->
     207    <Billboard position=" 300,100,300" material="Examples/Flare" colour="1.0, 0.0, 0.0" />
     208    <Billboard position="-300,100,300" material="Examples/Flare" colour="1.0, 0.0, 1.0" />
     209    <ParticleSpawner position="300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0>
     210      <events>
     211        <spawn>
     212          <DistanceTrigger position="300,100,300" distance=25 target="ControllableEntity" />
     213        </spawn>
     214      </events>
     215    </ParticleSpawner>
     216    <DistanceTrigger position="-300,100,300" distance=25 target="ControllableEntity">
     217      <eventlisteners>
     218        <ParticleSpawner position="-300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0 mainstate="spawn" />
     219      </eventlisteners>
     220    </DistanceTrigger>
     221
    186222  </Scene>
    187223</Level>
  • code/branches/core5/src/libraries/core/BaseObject.cc

    r5882 r5883  
    356356    {
    357357        if (this->mainStateFunctor_)
    358             (*this->mainStateFunctor_)(state);
     358        {
     359            if (this->mainStateFunctor_->getParamCount() == 0)
     360            {
     361                if (state)
     362                    (*this->mainStateFunctor_)();
     363            }
     364            else
     365            {
     366                (*this->mainStateFunctor_)(state);
     367            }
     368        }
    359369        else
    360370            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     
    366376    void BaseObject::changedMainStateName()
    367377    {
    368         this->registerEventStates();
    369        
    370378        this->mainStateFunctor_ = 0;
    371        
    372         std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(this->mainStateName_);
    373         if (it != this->eventStates_.end() && it->second->getFunctor() && it->second->getFunctor()->getParamCount() == 1)
    374             this->mainStateFunctor_ = it->second->getFunctor();
    375         else
    376             COUT(2) << "Warning: \"" << this->mainStateName_ << "\" is not a valid MainState." << std::endl;
     379
     380        if (this->mainStateName_ != "")
     381        {
     382            this->registerEventStates();
     383           
     384            std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(this->mainStateName_);
     385            if (it != this->eventStates_.end() && it->second->getFunctor())
     386            {
     387                if (it->second->getFunctor()->getParamCount() <= 1)
     388                    this->mainStateFunctor_ = it->second->getFunctor();
     389                else
     390                    COUT(2) << "Warning: Can't use \"" << this->mainStateName_ << "\" as MainState because it needs a second argument." << std::endl;
     391            }
     392            else
     393                COUT(2) << "Warning: \"" << this->mainStateName_ << "\" is not a valid MainState." << std::endl;
     394        }
    377395    }
    378396   
Note: See TracChangeset for help on using the changeset viewer.