summaryrefslogtreecommitdiffstats
path: root/o3d/plugin/idl/counter.idl
blob: be594cb4adb68ee9c150a2cd520c7875ce4b9598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
 * Copyright 2009, Google Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

namespace o3d {

typedef float[] NumberArray;
typedef NumberArray[] NumberArrayArray;

%[
  A Counter counts seconds, ticks or render frames depending on the type of
  counter. You can set where it starts counting from and where it stops counting
  at, whether or not it is running or paused and how it loops or does not loop.
  You can also give it callbacks to call at specific count values.

  @o3dparameter running ParamBoolean Whether or not this counter is running.
  @o3dparameter forward ParamBoolean The direction this counter is counting.
  @o3dparameter start ParamFloat The start value for this counter.
  @o3dparameter end ParamFloat The end value for this counter
  @o3dparameter countMode ParamInteger The counting mode for this counter.
  @o3dparameter count ParamFloat The current count for this counter.
  @o3dparameter multiplier ParamFloat The time multiplier for this counter.
%]
[nocpp, include="core/cross/counter.h"] class Counter
    : ParamObject {

  callback void CounterCallback();

  %[
    \var CountMode
    \li CONTINUOUS, Keep running the counter forever.
    \li ONCE, Stop at start or end depending on the direction.
    \li CYCLE, When at end, jump back to start or visa versa.
    \li OSCILLATE, Go from start to end back to start.
    };
  %]
  enum CountMode {
    CONTINUOUS,
    ONCE,
    CYCLE,
    OSCILLATE
  };

  %[
    Whether or not this counter is running. Default = true.
  %]
  [getter, setter] bool running_;

  %[
    Which direction this counter is counting. Default = true.
  %]
  [getter, setter] bool forward_;

  %[
    The start count for this counter. Default = 0.
  %]
  [getter, setter] float start_;

  %[
    The end count for this counter. Default = 0.
  %]
  [getter, setter] float end_;

  %[
    The current count value for this counter. Default = 0.
  %]
  [getter] float count_;

  %[
    The current count mode for this counter. Default = CONTINUOUS.
  %]
  [getter, setter] CountMode count_mode_;

  %[
    Sets the current count value for this counter as well as the resetting
    the state of the callbacks.

    In other words. Assume start = 1, end = 5, count = 1, and you have a
    callback at 3.

    <code>
    myCounter.start = 1;
    myCounter.end = 5;
    myCounter.addCallback(3, myCallback);
    myCounter.reset();

    myCounter.advance(2);  // count is now 3, myCallback is called.
    myCounter.advance(2);  // count is now 5
    </code>

    vs.

    <code>
    myCounter.start = 1;
    myCounter.end = 5;
    myCounter.addCallback(3, myCallback);
    myCounter.reset();

    myCounter.advance(2);  // count is now 3, myCallback is called.
    myCounter.setCount(3); // count is now 3, callback state has been reset.
    myCounter.advance(2);  // count is now 5, myCallback is called.
    </code>

    In the second case myCallback was called twice.

    \param count Value to set the count to.
  %]
  void SetCount(float count);

  %[
    A multiplier used when advancing the count. The default value is 1.0.
    For example you could set this to 0.5 to run the counter at half speed
    or 2.0 to run it at double speed. Default = 1.
  %]
  [getter, setter] float multiplier_;

  %[
    Resets the counter back to the start or end time depending on the forward
    setting and also resets the Callback state.
    Note: Reset does not change the running state of the counter.
  %]
  void Reset();

  %[
    Advances the counter the given amount. The actual amount advanced depends
    on the forward and multiplier settings. The formula is

    <code>
    new_count = count + advance_amount * multiplier * (forward ? 1.0 : -1.0);
    </code>

    Any callbacks that fall in the range between the counter's current count and
    the amount advanced will be called.

    This function is normally called automatically by the client if the counter
    is set to running = true. but you can call it manually.

    \param advance_amount Amount to advance count.
  %]
  [userglue] void Advance(float advance_amount);

  %[
    Adds a callback for a given count value. Only one callback can be
    added to a specific count value. If another callback is added with the
    same count value the previous callback for that value will be replaced.

    Note: A callback at start will only get called when counting backward, a
    callback at end will only get called counting forward.

    \param count Count at which to call callback.
    \param counter_callback Callback to call at given count.
  %]
  void AddCallback(float count, CounterCallback? counter_callback);

  %[
    Removes a callback for a given count value.

    \param count Count to remove callback for,
    \return true if there was a callback for that count, false if there was not
        a callback for that count.
  %]
  bool RemoveCallback(float count);

  %[
    Removes all the callbacks on this counter.
  %]
  void RemoveAllCallbacks();

  %[
    Returns all the counts for which all callback has been added.
    \return Array of counts.
  %]
  [userglue, const] NumberArray GetCallbackCounts();

  [verbatim=cpp_glue] %{
    // This is userglue because we need to force the client to call any
    // callbacks that need to be called as a result of the advance.
    void userglue_method_Advance(o3d::Counter* self,
                                 float advance_amount) {
      o3d::Counter::CounterCallbackQueue queue;
      self->Advance(advance_amount, &queue);
      queue.CallCounterCallbacks();
    }
    std::vector<float> userglue_method_GetCallbackCounts(
        o3d::Counter* self) {
      const o3d::Counter::CounterCallbackInfoArray& callbacks =
          self->GetCallbacks();
      std::vector<float> float_array;
      float_array.reserve(callbacks.size());
      for (unsigned ii = 0; ii < callbacks.size(); ++ii) {
        float_array.push_back(callbacks[ii].count());
      }
      return float_array;
    }
  %}
};  // Counter

%[
  A Counter that counts seconds.
%]
[nocpp, include="core/cross/counter.h"] class SecondCounter
    : Counter {
};  // SecondCounter

%[
  A Counter that counts render frames.
%]
[nocpp, include="core/cross/counter.h"] class RenderFrameCounter
    : Counter {
};  // RenderFrameCounter

%[
  A Counter that counts ticks.
%]
[nocpp, include="core/cross/counter.h"] class TickCounter
    : Counter {
};  // TickCounter

}  // namespace o3d