Normand Briere
2019-11-17 cb37a129d1adb403019c96e798e86e2da9667f15
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
class RandomNode extends Composite
{
static final long serialVersionUID = 6286502202432779788L; // ? -9091094008965972116L;
// prior to new behavior: -5041564709139164666
    
    RandomNode()
    {
        this("Switch");
    }
    
    RandomNode(String name)
    {
        super(name);
    }
 
    Object3D deepCopy()
    {
            Composite comp = new RandomNode();
            deepCopySelf(comp);
            return comp;
    }
    
    protected void deepCopyNode(Object3D other)
    {
        super.deepCopyNode(other);
        RandomNode bp = (RandomNode)other;
        bp.rndIndex = rndIndex;
        bp.damp = damp;
        bp.firstchoice = firstchoice;
    }
    
//    public int Size()
//    {
//        return 1;
//    }
    
    boolean IsSwitch()
    {
        return CameraPane.SWITCH && !this.Link2Support();
    }
    
    public int size()
    {
        if (IsSwitch())
        {
            if (super.size() > 0)
                return 1;
            else
                return 0;
        }
        else
            return super.size();
    }
    
    void addChild(Object3D child)
    {
        super.addChild(child);
        
        this.rndIndex = Size() - 1;
        
        if (this.editWindow != null)
        {
            ((RandomEditor)this.objectUI).refreshContents();
        }
    }
    
    int rndIndex = -1;
    
    static int globalseed = 0;
    static int globalseed2 = 0; // mocap frames???
    
    //static
    transient
            int whatevercount = 0;
    
        void ResetRandom()
        {
            whatevercount = 0;
            
            super.ResetRandom();
        }
        
    int damp;
    transient int countdamp;
    transient int globaloffset;
    
    void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
    {
        if (live && Globals.isLIVE() && (display.DrawMode() == display.SHADOW || !Globals.RENDERSHADOW) &&
                currentframe != Globals.framecount)
        {
            currentframe = Globals.framecount;
            
            if (countdamp <= 0)
            {
                countdamp = damp;
                
                globaloffset += 1;
            }
            else
            {
                if (CameraPane.FAST)
                    countdamp -= CameraPane.STEP;
                else
                    countdamp--;
            }
        }
        
        super.DrawNode(display, root, selected);
    }
    
    int firstchoice = 0;
//    int currentpass = 0;
    
    public Object3D reserve(int i)
    {
        if (!IsSwitch())
            return super.reserve(i);
        
        //assert(rnd == -1);
//        if (!link2master && rnd != -1)
//            new Exception().printStackTrace();
        
        if (!random && rndIndex != -1) // freeze current value
            return super.reserve(rndIndex);
        
        if (firstchoice == 0)
            firstchoice = (int)(Math.random()*super.Size()) + 1;
      
//        if (currentpass != CameraPane.renderpass)
//        {
//            currentpass = CameraPane.renderpass;
//            globalcount = firstchoice-1;
//            //System.err.println("firstchoice = " + firstchoice);
//        }
        
        //System.err.println("currentpass = " + currentpass);
        //System.err.println("renderpass = " + CameraPane.renderpass);
        //System.err.println("globalcount = " + globalcount);
        
        int gcount = globalseed;
        
        if (Size() > 0 && get(0) instanceof FrameSelector)
        {
            gcount = globalseed2;
        }
        //int tabarnak = super.Size();
        
        rndIndex = gcount%super.Size(); //
        
            //(int)(Math.random()*super.size());
        //globalcount++;
        gcount += Grafreed.mix3(rndIndex+12345,firstchoice*12345,gcount);
        
        gcount &= 0x7fffffff;
        
        if (Size() > 0 && get(0) instanceof FrameSelector)
            globalseed2 = gcount;
        else
            globalseed = gcount;
            
        if (!random) // aout 2013 link2master)
            rndIndex = whatevercount++;
        
        if (live) // aout 2019
        {
            rndIndex += globaloffset;
        }
        
        rndIndex %= super.Size();
        
        //GraphreeD.tracein("RESERVE " + this + " = ", i);
        Object3D child = super.get(rndIndex);
        //Applet3D.tracein("RESERVE ", child);
 
        child.count--;
        //assert (child.count >= 0);
 
        return child;
    }
    
    public Object3D reserve0(int i)
    {
        return reserve(i);
    }
 
    public void release(int i)
    {
        if (!IsSwitch())
        {
            super.release(i);
            return;
        }
        
        //GraphreeD.traceout("RELEASE " + this + " = ", i);
     //   Object3D child = super.get(i);
     //   //Applet3D.traceout("RELEASE ", child);
     //   child.count++;
 
    //    globalcount--;
        
        super.get(rndIndex).count++;
    //assert (child.count >= 0);
        
        if (random) // volatile value
            rndIndex = -1;
    }
    
    void createEditWindow(GroupEditor callee, boolean newWindow)
    {
        //editWindow = (new SphereEditor(this, deepCopy(), callee)).GetEditor();
        if (newWindow)
        {
            objectUI = new RandomEditor(this, deepCopy(), callee);
        } else
        {
            objectUI = new RandomEditor(this, callee);
        }
        editWindow = objectUI.GetEditor();
    }
}