Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/levels/events.oxw @ 8957

Last change on this file since 8957 was 8706, checked in by dafrick, 13 years ago

Merging presentation branch back into trunk.
There are many new features and also a lot of other changes and bugfixes, if you want to know, digg through the svn log.
Not everything is yet working as it should, but it should be fairly stable. If you habe any bug reports, just send me an email.

  • Property svn:eol-style set to native
File size: 9.7 KB
RevLine 
[7648]1<LevelInfo
2  name = "Events showcase"
3  description = "Level to test and showcase events."
4  tags = "test, showcase"
5/>
6
[6417]7<?lua
[7679]8  include("HUDTemplates3.oxo")
[6417]9  include("stats.oxo")
[7679]10  include("templates/spaceshipAssff.oxt")
11  include("templates/spaceshipH2.oxt")
12  include("templates/lodInformation.oxt")
[6417]13?>
14
15<Level
16 name         = "Event testing"
17 description  = "A simple level to test the event-system (with comments)"
18>
[7163]19  <templates>
20    <Template link=lodtemplate_default />
21  </templates>
[8706]22  <?lua include("includes/notifications.oxi") ?>
[7163]23
[6417]24  <Scene
25   ambientlight = "0.5, 0.5, 0.5"
26   skybox       = "Orxonox/skypanoramagen1"
27  >
28    <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" />
29
30    <SpawnPoint position="0,-100,0" lookat="0,0,0" roll=180 spawnclass=SpaceShip pawndesign=spaceshipassff />
31
32    <Billboard position=" 300,100,  0" material="Examples/Flare" colour="1.0, 0.0, 0.0" />
33    <Billboard position=" 200,100,  0" material="Examples/Flare" colour="1.0, 0.5, 0.0" />
34    <Billboard position=" 200,100,100" material="Examples/Flare" colour="1.0, 0.5, 0.0" />
35    <Billboard position=" 100,100,  0" material="Examples/Flare" colour="1.0, 1.0, 0.0" />
36    <Billboard position="   0,100,  0" material="Examples/Flare" colour="0.0, 1.0, 0.0" />
37    <Billboard position="-100,100,  0" material="Examples/Flare" colour="0.0, 1.0, 1.0" />
38    <Billboard position="-100,100,100" material="Examples/Flare" colour="0.0, 1.0, 1.0" />
39    <Billboard position="-200,100,  0" material="Examples/Flare" colour="0.0, 0.0, 1.0" />
40    <Billboard position="-300,100,  0" material="Examples/Flare" colour="1.0, 0.0, 1.0" />
41
42
43
44    <!--
45      Begin of the tutorial section.
46    -->
47
48
49
50    <!--
51      Note:
52      All following examples use only one subobject (in nested layouts). But of course you can add more
53      objects. They will all follow the same rules (depending on the example receive, send or pipe events).
54
55      Some examples address objects by name. Those methods always address ALL objects with this name, no
56      matter where they are in the XML-file (before or after the addressing object). Of course this also
57      works with all amounts of objects from zero to infinity. In the examples I used two objects each.
58    -->
59
60
61    <!-- red -->
62    <!--
63      Standard:
64      Direct event-connection between an event-listener (Billboard) and an event source (DistanceTrigger).
65      Every fired event of the source is mapped to the "visibility" state of the listener.
66
67      This is a 1:1 mapping between event-listener and event-source.
68    -->
69    <Billboard position="300,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0>
70      <events>
71        <visibility>
72          <DistanceTrigger position="300,100,0" distance=25 target="ControllableEntity" />
73        </visibility>
74      </events>
75    </Billboard>
76
77
78    <!-- orange -->
79    <!--
80      EventListener:
81      The EventListener object forwards all events from objects, whose names equal the "event" attribute
82      of the EventListener, to the enclosing object (Billboard).
83      In this case, both triggers have the name "trigger2" and thus both triggers send events to the Billboard.
84
85      The EventListener provides an 1:n mapping between one listener and multiple event-sources.
86    -->
87    <Billboard position="200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0>
88      <events>
89        <visibility>
90          <EventListener event="trigger2" />
91        </visibility>
92      </events>
93    </Billboard>
94    <DistanceTrigger name="trigger2" position="200,100,0" distance=25 target="ControllableEntity" />
95    <DistanceTrigger name="trigger2" position="200,100,100" distance=25 target="ControllableEntity" />
96
97
98    <!-- yellow -->
99    <!--
100      EventTarget:
101      The EventTarget object forwards the events, received from objects whithin the "events" subsection,
102      to all  objects whose names equal the "name" attribute.
103      In this case, the EventTarget forwards the event from the DistanceTrigger to all listeners with
104      name "bb3".
105
106      The EventTarget provides an n:1 mapping between several listeners and one event-source.
107    -->
108    <Billboard name="bb3" position="100,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
109    <Billboard name="bb3" position="100,150,100" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
110    <EventTarget target="bb3">
111      <events>
112        <visibility>
113          <DistanceTrigger position="100,100,0" distance=25 target="ControllableEntity" />
114        </visibility>
115      </events>
116    </EventTarget>
117
118
119    <!-- green -->
120    <!--
121      EventDispatcher:
122      The EventDispatcher catches events from objects in its "events" subsection. Those events are forwared
123      to all objects in the "targets" subsection. The EventDispatcher resembles the EventTarget, but
124      doesn't address objects with the "name" attribute. It rather places them directly inside the "targets"
125      subsection.
126      In this case, the EventDispatcher receives events from the DistanceTrigger and forwards those events
127      to the Billboard object.
128
129      The EventDispatcher provides an n:1 mapping between several targets (listeners) and one event source.
130    -->
131    <EventDispatcher>
132      <targets>
133        <Billboard position="0,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
134      </targets>
135      <events>
136        <visibility>
137          <DistanceTrigger position="0,100,0" distance=25 target="ControllableEntity" />
138        </visibility>
139      </events>
140    </EventDispatcher>
141
142
143    <!-- turquoise -->
144    <!--
145      Combination:
146      By combinding the above three classes, namely EventDispatcher, EventTarget and EventListener, you can
147      extract the event logic completely from the actual objects (Billboards and DistanceTriggers).
148      In this case, both triggers (whith names "trigger5") send events to both Billboards (with names "bb5").
149
150      This combination allows an n:n mapping between event-listeners and event-sources.
151    -->
152    <Billboard name="bb5" position="-100,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
153    <Billboard name="bb5" position="-100,150,100" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
154    <DistanceTrigger name="trigger5" position="-100,100,0" distance=25 target="ControllableEntity" />
155    <DistanceTrigger name="trigger5" position="-100,100,100" distance=25 target="ControllableEntity" />
156    <EventDispatcher>
157      <targets>
158        <EventTarget target="bb5" />
159      </targets>
160      <events>
161        <visibility>
162          <EventListener event="trigger5" />
163        </visibility>
164      </events>
165    </EventDispatcher>
166
167
168    <!-- blue -->
169    <!--
170      Mainstate:
171      Apart from the standard states (like activity and visibility), each object can have a mainstate.
172      You can define the mainstate with an xml-attribute: mainstate="state". "state" must be one of the
173      supported states of the object (except states which need the originator as a second argument). If
174      the mainstate is set (by default that's not the case), you can send events to the "mainstate" state.
175      This allows you to hide the actually affected state in the event-listener, while the event-source
176      just sends events.
177      Note that this example is exactly like the standard case, but the event is sent to the main-state,
178      which in turn is set to "visibility".
179    -->
180    <Billboard position="-200,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility">
181      <events>
182        <mainstate>
183          <DistanceTrigger position="-200,100,0" distance=25 target="ControllableEntity" />
184        </mainstate>
185      </events>
186    </Billboard>
187
188
189    <!-- violet -->
190    <!--
191      Event forwarding:
192      As a consequence of the mainstate, events can also be sent without any explicit declaration of
193      the targets state. This allows us to forward events from an event-source directly to a bunch of
194      event-listeners. The events are automatically piped into the mainstate. Therefore the listeners
195      have to declare their main-state.
196      In this example, the DistanceTrigger forwards the events to the Billboards main-state (visibility).
197      This does the same like the example above, but instead of piping events backwards from the source
198      into the mainstate of the listener, we're forwarding the event implicitly to the mainstate.
199    -->
200    <DistanceTrigger position="-300,100,0" distance=25 target="ControllableEntity">
201      <eventlisteners>
202        <Billboard position="-300,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 mainstate="visibility" />
203      </eventlisteners>
204    </DistanceTrigger>
205
206
207
208    <!--
209      End of the tutorial section.
210    -->
211
212
213
214    <!--
215      The following example shows again the red (standard layout) and the violet (event forwarding) example,
216      but this time with a memoryless state (spawn) from the ParticleSpawner instead of the boolean state
217      (visibility) in the other examples.
218    -->
219    <Billboard position=" 300,100,300" material="Examples/Flare" colour="1.0, 0.0, 0.0" />
220    <Billboard position="-300,100,300" material="Examples/Flare" colour="1.0, 0.0, 1.0" />
221    <ParticleSpawner position="300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0>
222      <events>
223        <spawn>
224          <DistanceTrigger position="300,100,300" distance=25 target="ControllableEntity" />
225        </spawn>
226      </events>
227    </ParticleSpawner>
228    <DistanceTrigger position="-300,100,300" distance=25 target="ControllableEntity">
229      <eventlisteners>
230        <ParticleSpawner position="-300,150,300" source="Orxonox/BigExplosion1part1" lifetime=3.0 autostart=0 mainstate="spawn" />
231      </eventlisteners>
232    </DistanceTrigger>
233
234  </Scene>
235</Level>
Note: See TracBrowser for help on using the repository browser.