Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7404


Ignore:
Timestamp:
Sep 11, 2010, 2:42:47 PM (14 years ago)
Author:
dafrick
Message:

Adding new level notifications.oxw, to "showcase", or at this stage rather "test" Notifications.
Restoring tutorial.oxw to its old state, before it was hijacked by me for testing.

Extending Script class. Now also normal orxonox code can be executed with it, the execution of code can be triggered with Triggers (obviously) and cod can also executed on load.
I needed this to load the NotificationLayer in levels where it is needed.
Also inserted a Script that loads the NotificationQueue to display Notifications in all levels it was needed.

Location:
code/trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/data/levels/Fight in our Back.oxw

    r7403 r7404  
    6868     skybox="Orxonox/skypanoramagen1"
    6969    >
     70
     71        <Script code="showGUI NotificationLayer false true" />
    7072
    7173        <!--Light: noch zu aendern -->
  • code/trunk/data/levels/Quest_PirateAttack.oxw

    r7403 r7404  
    3434        skybox       = "Orxonox/skypanoramagen1"
    3535    >
    36           <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
    37    
    38    
     36
     37        <Script code="showGUI NotificationLayer false true" />
     38
     39        <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
     40
     41
    3942          <GlobalQuest id="dbd02b4c-ab7c-46fd-bdaf-fd4c19ac1551">
    4043        <QuestDescription title="Fight for freedom"
  • code/trunk/data/levels/old/princessaeryn.oxw

    r7403 r7404  
    1717        skybox       = "Orxonox/skypanoramagen1"
    1818    >
     19
     20        <Script code="showGUI NotificationLayer false true" />
     21
    1922      <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
    2023
  • code/trunk/data/levels/old/questsystem.oxw

    r7403 r7404  
    1313    skybox       = "Orxonox/Starbox"
    1414    >
     15
     16        <Script code="showGUI NotificationLayer false true" />
    1517
    1618        <GlobalQuest id="b80c2c60-e62c-4637-80f8-5aa18dc93b34">
  • code/trunk/data/levels/princessaeryn.oxw

    r7403 r7404  
    2323    skybox     = "Orxonox/skypanoramagen1"
    2424  >
     25
     26    <Script code="showGUI NotificationLayer false true" /
     27
    2528    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
    2629
  • code/trunk/data/levels/tutorial.oxw

    r7403 r7404  
    1919  >
    2020
    21       <CommandNotification preMessage="Move '" postMessage="' to look left." command="scale 1 rotateYaw">
    22         <events>
    23             <trigger>
    24                 <DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn" />
    25             </trigger>
    26         </events>
    27     </CommandNotification>
    28     <Billboard position="0,0,-100" colour="1.0,1.0,0" material="Examples/Flare" />
    2921
    30     <SimpleNotification message="Awesome!!!">
    31         <events>
    32             <trigger>
    33                 <DistanceTrigger name=trigger position="0,0,100" distance=10 target="Pawn" />
    34             </trigger>
    35         </events>
    36     </SimpleNotification>
    37     <Billboard position="0,0,100" colour="1.0,0,1.0" material="Examples/Flare" />
    38  
    3922
     23
     24<Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
     25  <attached>
     26    <Model scale="1" mesh="drone.mesh"/>
     27  </attached>
     28  <collisionShapes>
     29    <BoxCollisionShape position="0,0,0"      halfExtents="10, 10, 10" />
     30  </collisionShapes>
     31</Drone>
     32
     33    <Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
     34      <attached>
     35        <Model scale="1" mesh="rocket.mesh"/>
     36      </attached>
     37      <collisionShapes>
     38        <BoxCollisionShape position="0,0,0"      halfExtents="10, 10, 10" />
     39      </collisionShapes>
     40    </Drone>
    4041
    4142    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
    4243
     44    <Model mesh="hs-w01.mesh" scale=10 position="0,0,-100" />
     45    <Model mesh="hs-w01s.mesh" scale=10 position="0,0,-100" />
    4346
    4447    <?lua
     
    4851    <?lua end ?>
    4952
     53    <GlobalShader compositor="Bloom" visible=false>
     54      <events>
     55        <visibility>
     56          <DistanceTrigger position="0,0,0" distance=30 target="Spectator" switch=true />
     57        </visibility>
     58      </events>
     59    </GlobalShader>
     60    <Model position="0,0,0" scale=8 mesh="ast1.mesh" />
     61    <StaticEntity position="0,0,0" collisionType=static>
     62      <collisionShapes>
     63        <SphereCollisionShape radius="20" />
     64      </collisionShapes>
     65    </StaticEntity>
     66
     67<!--
     68    <?lua
     69      for i = 1, 70, 1 do
     70    ?>
     71      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 1000 + 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
     72        <attached>
     73          <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
     74        </attached>
     75      </MovableEntity>
     76      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * -1000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
     77        <attached>
     78          <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
     79        </attached>
     80      </MovableEntity>
     81
     82      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 1000 + 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
     83        <attached>
     84          <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
     85        </attached>
     86      </MovableEntity>
     87      <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * -1000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
     88        <attached>
     89          <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
     90        </attached>
     91      </MovableEntity>
     92
     93      <MovableEntity position="<?lua print(math.random() * 1000 + 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
     94        <attached>
     95          <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
     96        </attached>
     97      </MovableEntity>
     98      <MovableEntity position="<?lua print(math.random() * -1000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
     99        <attached>
     100          <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
     101        </attached>
     102      </MovableEntity>
     103    <?lua end ?>
     104-->
    50105
    51106  </Scene>
  • code/trunk/src/modules/notifications/NotificationDispatcher.cc

    r7403 r7404  
    7272        Method for creating a NotificationDispatcher object through XML.
    7373    */
    74     void NotificationDispatcher::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     74    void NotificationDispatcher::XMLPort(Element& xmlElement, XMLPort::Mode mode)
    7575    {
    76         SUPER(NotificationDispatcher, XMLPort, xmlelement, mode);
     76        SUPER(NotificationDispatcher, XMLPort, xmlElement, mode);
    7777
    78         XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
     78        XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlElement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
    7979    }
    8080
    81     void NotificationDispatcher::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
     81    void NotificationDispatcher::XMLEventPort(Element& xmlElement, XMLPort::Mode mode)
    8282    {
    83         SUPER(NotificationDispatcher, XMLEventPort, xmlelement, mode);
     83        SUPER(NotificationDispatcher, XMLEventPort, xmlElement, mode);
    8484
    85         XMLPortEventState(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode);
     85        XMLPortEventState(NotificationDispatcher, BaseObject, "trigger", trigger, xmlElement, mode);
    8686    }
    8787
  • code/trunk/src/modules/notifications/NotificationDispatcher.h

    r7403 r7404  
    5555            virtual ~NotificationDispatcher(); //!< Destructor.
    5656
    57             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationDispatcher object through XML.
    58             virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
     57            virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationDispatcher object through XML.
     58            virtual void XMLEventPort(Element& xmlElement, XMLPort::Mode mode);
    5959
    6060            /**
  • code/trunk/src/modules/objects/Script.cc

    r5781 r7404  
    2323 *      Benjamin Knecht
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     
    2929#include "Script.h"
    3030
     31#include "core/command/CommandExecutor.h"
    3132#include "core/CoreIncludes.h"
     33#include "core/EventIncludes.h"
    3234#include "core/LuaState.h"
    3335#include "core/XMLPort.h"
     
    3739    CreateFactory(Script);
    3840
     41    // Initializing constants.
     42    /*static*/ const std::string Script::NORMAL = "normal";
     43    /*static*/ const std::string Script::LUA = "lua";
     44
     45    /**
     46    @brief
     47        Constructor. Registers and initializes the object.
     48    @param creator
     49        The creator of this object.
     50    */
    3951    Script::Script(BaseObject* creator) : BaseObject(creator)
    4052    {
    4153        RegisterObject(Script);
    4254
    43         // Get a new LuaState
    44         luaState_ = new LuaState();
    45     }
    46 
     55        // Initialize variables.
     56        this->luaState_ = NULL;
     57        this->remainingExecutions_ = Script::INF;
     58
     59    }
     60
     61    /**
     62    @brief
     63        Destructor. Cleans up.
     64    */
    4765    Script::~Script()
    4866    {
    49         if (this->isInitialized())
    50             delete luaState_;
    51     }
    52 
    53     void Script::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    54     {
    55         BaseObject::XMLPort(xmlelement, mode);
    56 
    57         XMLPortParam(Script, "code", setCode, getCode, xmlelement, mode);
    58     }
    59 
     67        if(this->isInitialized() && this->luaState_ != NULL)
     68            delete this->luaState_;
     69    }
     70
     71    /**
     72    @brief
     73        Method for creating a Script object through XML.
     74    @param xmlElement
     75        The element.
     76    @param mode
     77        The mode.
     78    */
     79    void Script::XMLPort(Element& xmlElement, XMLPort::Mode mode)
     80    {
     81        SUPER(Script, XMLPort, xmlElement, mode);
     82
     83        XMLPortParam(Script, "code", setCode, getCode, xmlElement, mode);
     84        XMLPortParamTemplate(Script, "mode", setMode, getMode, xmlElement, mode, const std::string&).defaultValues(Script::NORMAL);
     85        XMLPortParam(Script, "onLoad", setOnLoad, isOnLoad, xmlElement, mode).defaultValues(true);
     86        XMLPortParam(Script, "times", setTimes, getTimes, xmlElement, mode).defaultValues(Script::INF);
     87
     88        XMLPortEventSink(Script, BaseObject, "trigger", trigger, xmlElement, mode);
     89
     90        if(this->isOnLoad()) // If the object is onLoad the code is executed at once.
     91            this->execute();
     92    }
     93
     94    /**
     95    @brief
     96        Creates a port that can be used to channel events and react to them.
     97    @param xmlElement
     98        The element.
     99    @param mode
     100        The mode.
     101    */
     102    void Script::XMLEventPort(Element& xmlElement, XMLPort::Mode mode)
     103    {
     104        SUPER(Script, XMLEventPort, xmlElement, mode);
     105
     106        XMLPortEventState(Script, BaseObject, "trigger", trigger, xmlElement, mode);
     107    }
     108
     109    /**
     110    @brief
     111        Is called when an event comes in trough the event port.
     112    @param triggered
     113        Whether the event is triggering or un-triggering.
     114    */
     115    void Script::trigger(bool triggered)
     116    {
     117        if(triggered) // If the event is triggering (instead of un-triggering) the code of this Script  is executed.
     118            this->execute();
     119    }
     120
     121    /**
     122    @brief
     123        Executes the Scripts code, depending on the mode.
     124    */
    60125    void Script::execute()
    61126    {
    62         luaState_->doString(code_);
    63     }
     127        if(this->times_ != Script::INF && this->remainingExecutions_ == 0)
     128            return;
     129
     130        if(this->mode_ == ScriptMode::normal) // If the mode is 'normal'.
     131            CommandExecutor::execute(this->code_);
     132        else if(this->mode_ == ScriptMode::lua) // If it's 'lua'.
     133        {
     134            assert(this->luaState_);
     135            this->luaState_->doString(this->code_);
     136        }
     137
     138        if(this->times_ != Script::INF)
     139            this->remainingExecutions_--;
     140    }
     141
     142    /**
     143    @brief
     144        Sets the mode of the Script.
     145    @param mode
     146        The mode as a string.
     147    */
     148    void Script::setMode(const std::string& mode)
     149    {
     150        if(mode == Script::NORMAL)
     151            this->setMode(ScriptMode::normal);
     152        else if(mode == Script::LUA)
     153        {
     154            this->setMode(ScriptMode::lua);
     155            // Creates a new LuaState.
     156            if(this->luaState_ == NULL)
     157                this->luaState_ = new LuaState();
     158        }
     159        else
     160        {
     161            COUT(2) << "Invalid mode '" << mode << "' in Script object." << std::endl;
     162            this->setMode(ScriptMode::normal);
     163        }
     164    }
     165
     166    /**
     167    @brief
     168        Get the mode of the Script.
     169    @return
     170        Returns the mode as a string.
     171    */
     172    const std::string& Script::getMode(void)
     173    {
     174        switch(this->mode_)
     175        {
     176            case ScriptMode::normal:
     177                return Script::NORMAL;
     178            case ScriptMode::lua:
     179                return Script::LUA;
     180        }
     181    }
     182
     183    /**
     184    @brief
     185        Set the number of times this Script is executed at the most.
     186        -1 denotes infinity.
     187    @param times
     188        The number of times to be set.
     189    */
     190    void Script::setTimes(int times)
     191    {
     192        if(times >= -1)
     193        {
     194            this->times_ = times;
     195            this->remainingExecutions_ = times;
     196        }
     197        else
     198        {
     199            COUT(2) << "Invalid times '" << times << "' in Script." << std::endl;
     200            this->times_ = Script::INF;
     201        }
     202    }
     203
    64204}
  • code/trunk/src/modules/objects/Script.h

    r5781 r7404  
    2323 *      Benjamin Knecht
    2424 *   Co-authors:
    25  *      ...
     25 *      Damian 'Mozork' Frick
    2626 *
    2727 */
     
    3737namespace orxonox
    3838{
     39
     40    namespace ScriptMode
     41    {
     42        //! Modes of the Script class.
     43        enum Value
     44        {
     45            normal,
     46            lua
     47        };
     48    }
     49
     50    /**
     51    @brief
     52        The Script class lets you execute a piece of code, either the normal way or in lua, through XML. It can be specified whether the code is executed upon loading (creation) of the object. Additionally the code is executed each time a trigger event comes in.
     53        There are three parameters:
     54        'code': The code that should be executed.
     55        'mode': The mode, specifying whether the set code should be executed the normal way ('normal') or in lua ('lua'). Default is 'normal'.
     56        'onLoad': Whether the code is executed upon loading (creation) of this object. Default is true.
     57
     58        Here are two examples illustrating the usage:
     59        @code
     60        <Script code="showGUI QuestGUI" />
     61        @endcode
     62        This would show the QuestGUI opon creation of the object. The mode is 'normal', not specified here since that is the default, also onLoad is true, also not specified, since it is the default as well.
     63
     64        @code
     65        <Script code="hideGUI QuestGUI" mode="normal" onLoad="false">
     66            <events>
     67                <trigger>
     68                    <DistanceTrigger distance=10 target="Pawn" />
     69                </trigger>
     70            </events>
     71        </Script>
     72        @endcode
     73        This would hide the QuestGUI as soon as a Pawn got in range of the DistanceTrigger. The mode is 'normal', it is specified here, but could be ommitted as well, since it is the default. OnLoad is false, that is why it can't be ommitted.
     74    @author
     75        Benjamin Knecht
     76        Damian 'Mozork' Frick
     77    */
    3978    class _ObjectsExport Script : public BaseObject
    4079    {
    41     public:
    42         Script(BaseObject* creator);
    43         ~Script();
    44         void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    45         void execute();
     80        public:
     81            Script(BaseObject* creator);
     82            virtual ~Script();
    4683
    47         void setCode(const std::string& code) { code_ = code; }
    48         const std::string& getCode() const { return code_; }
     84            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Script object through XML.
     85            virtual void XMLEventPort(Element& xmlElement, XMLPort::Mode mode); //!< Creates a port that can be used to channel events and react to them.
    4986
    50     private:
    51         std::string code_;
    52         LuaState* luaState_;
     87            void trigger(bool triggered); //!< Is called when an event comes in trough the event port.
     88            void execute(); //!< Executes the Scripts code, depending on the mode.
     89
     90            /**
     91            @brief Sets the code that is executed by this Script.
     92            @param code  The code that is executed by this Script.
     93            */
     94            inline void setCode(const std::string& code)
     95                { code_ = code; }
     96            /**
     97            @brief Get the code that is executed by this Script.
     98            @return Returns the code that is executed by this Script.
     99            */
     100            inline const std::string& getCode() const
     101                { return code_; }
     102
     103            void setMode(const std::string& mode); //!< Sets the mode of the Script.
     104            const std::string& getMode(void); //!< Get the mode of the Script.
     105
     106            /**
     107            @brief Set whether this Script is executed onLoad or not.
     108            @param onLoad if true the Script is executed onLoad, if false it's not.
     109            */
     110            inline void setOnLoad(bool onLoad)
     111                { this->onLoad_ = onLoad; }
     112            /**
     113            @brief Get whether this Script is executed onLoad.
     114            @return Returns true if this Script is executed onLoad, false if not.
     115            */
     116            inline bool isOnLoad(void)
     117                { return this->onLoad_; }
     118
     119            void setTimes(int times); //!< Set the number of times this Script is executed at the most.
     120            /**
     121            @brief Get the number of times this Script is executed at the most.
     122            @return Returns the number of times this Script is executed at the most. -1 denotes infinity.
     123            */
     124            inline int getTimes(void)
     125                { return this->times_; }
     126
     127        private:
     128            //! Static variables to avoid magic strings.
     129            static const std::string NORMAL;
     130            static const std::string LUA;
     131            static const int INF = -1;
     132
     133            std::string code_; //!< The code that is executed by this Script.
     134            ScriptMode::Value mode_; //!< The mode the Script is in. Determines whether the code is executed the normal way or in lua.
     135            bool onLoad_; //!< Whether the Scripts code is executed upon loading (creation) of this Script.
     136            int times_; //!< The number of times the Scripts code is executed at the most. -1 denotes infinity.
     137
     138            LuaState* luaState_; //!< The LuaState to execute the code in lua.
     139            int remainingExecutions_; //!< The number of remainign executions. -1 denotes infinity.
     140
     141            /**
     142            @brief Sets the mode of the Script.
     143            @param mode The mode of the Script.
     144            */
     145            inline void setMode(ScriptMode::Value mode)
     146                { this->mode_ = mode; }
    53147    };
    54148}
Note: See TracChangeset for help on using the changeset viewer.