Normand Briere
2019-09-08 4a303a7b3635adfee8f46ac76af4e1b7b4a7029b
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
247
248
249
250
251
252
/*
 * Copyright (c) 2003-2009 jMonkeyEngine
 * 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 'jMonkeyEngine' 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.
 */
 
//package com.jme.scene;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
 
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;
 
/**
 * <code>Controller</code> provides a base class for creation of controllers
 * to modify nodes and render states over time. The base controller provides a
 * repeat type, min and max time, as well as speed. Subclasses of this will
 * provide the update method that takes the time between the last call and the
 * current one and modifies an object in a application specific way.
 * 
 * @author Mark Powell
 * @version $Id: Controller.java 4131 2009-03-19 20:15:28Z blaine.dev $
 */
public abstract class Controller implements Serializable, Savable
{
 
    /**
     * A clamped repeat type signals that the controller should look like its
     * final state when it's done <br>
     * Example: 0 1 5 8 9 10 10 10 10 10 10 10 10 10 10 10...
     */
    public static final int RT_CLAMP = 0;
    /**
     * A wrapped repeat type signals that the controller should start back at
     * the begining when it's final state is reached <br>
     * Example: 0 1 5 8 9 10 0 1 5 8 9 10 0 1 5 ....
     *  
     */
    public static final int RT_WRAP = 1;
    /**
     * A cycled repeat type signals that the controller should cycle it's states
     * forwards and backwards <br>
     * Example: 0 1 5 8 9 10 9 8 5 1 0 1 5 8 9 10 9 ....
     */
    public static final int RT_CYCLE = 2;
    /**
     * Defines how this controller should repeat itself. This can be one of
     * RT_CLAMP, RT_WRAP, RT_CYCLE, or an application specific repeat flag.
     */
    private int repeatType;
    /**
     * The controller's minimum cycle time
     */
    private float minTime;
    /**
     * The controller's maximum cycle time
     */
    private float maxTime;
    /**
     * The 'speed' of this Controller. Genericly, less than 1 is slower, more
     * than 1 is faster, and 1 represents the base speed
     */
    public float timestep = 1;
    /**
     * True if this controller is active, false otherwise
     */
    private boolean active = true;
    private static final long serialVersionUID = 1;
 
    /**
     * Returns the speed of this controller. Speed is 1 by default.
     * 
     * @return
     */
    public float getTimeStep()
    {
        return timestep;
    }
 
    /**
     * Sets the speed of this controller
     * 
     * @param speed
     *            The new speed
     */
    public void setTimeStep(float speed)
    {
        this.timestep = speed;
    }
 
    /**
     * Returns the current maximum time for this controller.
     * 
     * @return This controller's maximum time.
     */
    public float getMaxTime()
    {
        return maxTime;
    }
 
    /**
     * Sets the maximum time for this controller
     * 
     * @param maxTime
     *            The new maximum time
     */
    public void setMaxTime(float maxTime)
    {
        this.maxTime = maxTime;
    }
 
    /**
     * Returns the current minimum time of this controller
     * 
     * @return This controller's minimum time
     */
    public float getMinTime()
    {
        return minTime;
    }
 
    /**
     * Sets the minimum time of this controller
     * 
     * @param minTime
     *            The new minimum time.
     */
    public void setMinTime(float minTime)
    {
        this.minTime = minTime;
    }
 
    /**
     * Returns the current repeat type of this controller.
     * 
     * @return The current repeat type
     */
    public int getRepeatType()
    {
        return repeatType;
    }
 
    /**
     * Sets the repeat type of this controller.
     * 
     * @param repeatType
     *            The new repeat type.
     */
    public void setRepeatType(int repeatType)
    {
        this.repeatType = repeatType;
    }
 
    /**
     * Sets the active flag of this controller. Note: updates on controllers are
     * still called even if this flag is set to false. It is the responsibility
     * of the extending class to check isActive if it wishes to be
     * turn-off-able.
     * 
     * @param active
     *            The new active state.
     */
    public void setActive(boolean active)
    {
        this.active = active;
    }
 
    /**
     * Returns if this Controller is active or not.
     * 
     * @return True if this controller is set to active, false if not.
     */
    public boolean isActive()
    {
        return active;
    }
 
    /**
     * Defined by extending classes, <code>update</code> is a signal to
     * Controller that it should update whatever object(s) it is controlling.
     * 
     * @param time
     *            The time in seconds between the last call to update and the
     *            current one
     */
    public abstract void update(float time);
 
    public void write(JMEExporter e) throws IOException
    {
        OutputCapsule capsule = e.getCapsule(this);
        capsule.write(repeatType, "repeatType", RT_CLAMP);
        capsule.write(minTime, "minTime", 0);
        capsule.write(maxTime, "maxTime", 0);
        capsule.write(timestep, "speed", 1);
        capsule.write(active, "active", true);
    }
 
    public void read(JMEImporter e) throws IOException
    {
        InputCapsule capsule = e.getCapsule(this);
        repeatType = capsule.readInt("repeatType", RT_CLAMP);
        minTime = capsule.readFloat("minTime", 0);
        maxTime = capsule.readFloat("maxTime", 0);
        timestep = capsule.readFloat("speed", 1);
        active = capsule.readBoolean("active", true);
    }
 
    public Class getClassTag()
    {
        return this.getClass();
    }
 
    public void getControllerValues(HashMap<String, Object> store)
    {
 
    }
 
    public void setControllerValues(HashMap<String, Object> values)
    {
 
    }
}