[5882] | 1 | <?lua |
---|
| 2 | include("hudtemplates3.oxo") |
---|
| 3 | include("stats.oxo") |
---|
| 4 | include("templates/spaceship_assff.oxt") |
---|
| 5 | include("templates/spaceship_H2.oxt") |
---|
| 6 | ?> |
---|
| 7 | |
---|
| 8 | <Level |
---|
| 9 | name = "Event testing" |
---|
| 10 | description = "A simple level to test the event-system (with comments)" |
---|
| 11 | > |
---|
| 12 | <Scene |
---|
| 13 | ambientlight = "0.5, 0.5, 0.5" |
---|
| 14 | skybox = "Orxonox/skypanoramagen1" |
---|
| 15 | > |
---|
| 16 | <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" /> |
---|
| 17 | |
---|
| 18 | <SpawnPoint position="0,-100,0" lookat="0,0,0" roll=180 spawnclass=SpaceShip pawndesign=spaceshipassff /> |
---|
| 19 | |
---|
| 20 | <Billboard position=" 300,100, 0" material="Examples/Flare" colour="1.0, 0.0, 0.0" /> |
---|
| 21 | <Billboard position=" 200,100, 0" material="Examples/Flare" colour="1.0, 0.5, 0.0" /> |
---|
| 22 | <Billboard position=" 200,100,100" material="Examples/Flare" colour="1.0, 0.5, 0.0" /> |
---|
| 23 | <Billboard position=" 100,100, 0" material="Examples/Flare" colour="1.0, 1.0, 0.0" /> |
---|
| 24 | <Billboard position=" 0,100, 0" material="Examples/Flare" colour="0.0, 1.0, 0.0" /> |
---|
| 25 | <Billboard position="-100,100, 0" material="Examples/Flare" colour="0.0, 1.0, 1.0" /> |
---|
| 26 | <Billboard position="-100,100,100" material="Examples/Flare" colour="0.0, 1.0, 1.0" /> |
---|
| 27 | <Billboard position="-200,100, 0" material="Examples/Flare" colour="0.0, 0.0, 1.0" /> |
---|
| 28 | <Billboard position="-300,100, 0" material="Examples/Flare" colour="1.0, 0.0, 1.0" /> |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | <!-- |
---|
| 32 | Note: |
---|
| 33 | All following examples use only one subobject (in nested layouts). But of course you can add more |
---|
| 34 | objects. They will all follow the same rules (depending on the example receive, send or pipe events). |
---|
| 35 | |
---|
| 36 | Some examples address objects by name. Those methods always address ALL objects with this name, no |
---|
| 37 | matter where they are in the XML-file (before or after the addressing object). Of course this also |
---|
| 38 | works with all amounts of objects from zero to infinity. In the examples I used two objects each. |
---|
| 39 | --> |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | <!-- red --> |
---|
| 43 | <!-- |
---|
| 44 | Standard: |
---|
| 45 | Direct event-connection between an event-listener (Billboard) and an event source (DistanceTrigger). |
---|
| 46 | Every fired event of the source is mapped to the "visibility" state of the listener. |
---|
| 47 | |
---|
| 48 | This is a 1:1 mapping between event-listener and event-source. |
---|
| 49 | --> |
---|
| 50 | <Billboard position="300,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0> |
---|
| 51 | <events> |
---|
| 52 | <visibility> |
---|
| 53 | <DistanceTrigger position="300,100,0" distance=25 target="ControllableEntity" /> |
---|
| 54 | </visibility> |
---|
| 55 | </events> |
---|
| 56 | </Billboard> |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | <!-- orange --> |
---|
| 60 | <!-- |
---|
| 61 | EventListener: |
---|
| 62 | The EventListener object forwards all events from objects, whose names equal the "event" attribute |
---|
| 63 | of the EventListener, to the enclosing object (Billboard). |
---|
| 64 | In this case, both triggers have the name "trigger2" and thus both triggers send events to the Billboard. |
---|
| 65 | |
---|
| 66 | The EventListener provides an 1:n mapping between one listener and multiple event-sources. |
---|
| 67 | --> |
---|
| 68 | <Billboard position="200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0> |
---|
| 69 | <events> |
---|
| 70 | <visibility> |
---|
| 71 | <EventListener event="trigger2" /> |
---|
| 72 | </visibility> |
---|
| 73 | </events> |
---|
| 74 | </Billboard> |
---|
| 75 | <DistanceTrigger name="trigger2" position="200,100,0" distance=25 target="ControllableEntity" /> |
---|
| 76 | <DistanceTrigger name="trigger2" position="200,100,100" distance=25 target="ControllableEntity" /> |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | <!-- yellow --> |
---|
| 80 | <!-- |
---|
| 81 | EventTarget: |
---|
| 82 | The EventTarget object forwards the events, received from objects whithin the "events" subsection, |
---|
| 83 | to all objects whose names equal the "name" attribute. |
---|
| 84 | In this case, the EventTarget forwards the event from the DistanceTrigger to all listeners with |
---|
| 85 | name "bb3". |
---|
| 86 | |
---|
| 87 | The EventTarget provides an n:1 mapping between several listeners and one event-source. |
---|
| 88 | --> |
---|
| 89 | <Billboard name="bb3" position="100,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 /> |
---|
| 90 | <Billboard name="bb3" position="100,150,100" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 /> |
---|
| 91 | <EventTarget name="bb3"> |
---|
| 92 | <events> |
---|
| 93 | <visibility> |
---|
| 94 | <DistanceTrigger position="100,100,0" distance=25 target="ControllableEntity" /> |
---|
| 95 | </visibility> |
---|
| 96 | </events> |
---|
| 97 | </EventTarget> |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | <!-- green --> |
---|
| 101 | <!-- |
---|
| 102 | EventDispatcher: |
---|
| 103 | The EventDispatcher catches events from objects in its "events" subsection. Those events are forwared |
---|
| 104 | to all objects in the "targets" subsection. The EventDispatcher resembles the EventTarget, but |
---|
| 105 | doesn't address objects with the "name" attribute. It rather places them directly inside the "targets" |
---|
| 106 | subsection. |
---|
| 107 | In this case, the EventDispatcher receives events from the DistanceTrigger and forwards those events |
---|
| 108 | to the Billboard object. |
---|
| 109 | |
---|
| 110 | The EventDispatcher provides an n:1 mapping between several targets (listeners) and one event source. |
---|
| 111 | --> |
---|
| 112 | <EventDispatcher> |
---|
| 113 | <targets> |
---|
| 114 | <Billboard position="0,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 /> |
---|
| 115 | </targets> |
---|
| 116 | <events> |
---|
| 117 | <visibility> |
---|
| 118 | <DistanceTrigger position="0,100,0" distance=25 target="ControllableEntity" /> |
---|
| 119 | </visibility> |
---|
| 120 | </events> |
---|
| 121 | </EventDispatcher> |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | <!-- turquoise --> |
---|
| 125 | <!-- |
---|
| 126 | Combination: |
---|
| 127 | By combinding the above three classes, namely EventDispatcher, EventTarget and EventListener, you can |
---|
| 128 | extract the event logic completely from the actual objects (Billboards and DistanceTriggers). |
---|
| 129 | In this case, both triggers (whith names "trigger5") send events to both Billboards (with names "bb5"). |
---|
| 130 | |
---|
| 131 | This combination allows an n:n mapping between event-listeners and event-sources. |
---|
| 132 | --> |
---|
| 133 | <Billboard name="bb5" position="-100,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 /> |
---|
| 134 | <Billboard name="bb5" position="-100,150,100" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 /> |
---|
| 135 | <DistanceTrigger name="trigger5" position="-100,100,0" distance=25 target="ControllableEntity" /> |
---|
| 136 | <DistanceTrigger name="trigger5" position="-100,100,100" distance=25 target="ControllableEntity" /> |
---|
| 137 | <EventDispatcher> |
---|
| 138 | <targets> |
---|
| 139 | <EventTarget name="bb5" /> |
---|
| 140 | </targets> |
---|
| 141 | <events> |
---|
| 142 | <visibility> |
---|
| 143 | <EventListener event="trigger5" /> |
---|
| 144 | </visibility> |
---|
| 145 | </events> |
---|
| 146 | </EventDispatcher> |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | <!-- blue --> |
---|
| 150 | Mainstate: |
---|
| 151 | Apart from the standard states (like activity and visibility), each object can have a mainstate. |
---|
| 152 | 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. |
---|
| 156 | Note that this example is exactly like the standard case, but the event is sent to the main-state, |
---|
| 157 | which in turn is set to "visibility". |
---|
| 158 | <!-- |
---|
| 159 | --> |
---|
| 160 | <Billboard position="-200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility"> |
---|
| 161 | <events> |
---|
| 162 | <mainstate> |
---|
| 163 | <DistanceTrigger position="-200,100,0" distance=25 target="ControllableEntity" /> |
---|
| 164 | </mainstate> |
---|
| 165 | </events> |
---|
| 166 | </Billboard> |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | <!-- violet --> |
---|
| 170 | <!-- |
---|
| 171 | Event forwarding: |
---|
| 172 | As a consequence of the mainstate, events can also be sent without any explicit declaration of |
---|
| 173 | the targets state. This allows us to forward events from an event-source directly to a bunch of |
---|
| 174 | event-listeners. The events are automatically piped into the mainstate. Therefore the listeners |
---|
| 175 | have to declare their main-state. |
---|
| 176 | In this example, the DistanceTrigger forwards the events to the Billboards main-state (visibility). |
---|
| 177 | This does the same like the example above, but instead of piping events backwards from the source |
---|
| 178 | into the mainstate of the listener, we're forwarding the event implicitly to the mainstate. |
---|
| 179 | --> |
---|
| 180 | <DistanceTrigger position="-300,100,0" distance=25 target="ControllableEntity"> |
---|
| 181 | <eventlisteners> |
---|
| 182 | <Billboard position="-300,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility" /> |
---|
| 183 | </eventlisteners> |
---|
| 184 | </DistanceTrigger> |
---|
| 185 | |
---|
| 186 | </Scene> |
---|
| 187 | </Level> |
---|