Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mac_osx/data/levels/events.oxw @ 8501

Last change on this file since 8501 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

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