Normand Briere
2017-05-07 314b34423070cf127464da79a53cddf6b1c38587
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
class RandomNode extends Composite
{
static final long serialVersionUID = 6286502202432779788L; // ? -9091094008965972116L;
// prior to new behavior: -5041564709139164666
    
    RandomNode()
    {
        this("Random");
    }
    
    RandomNode(String name)
    {
        super(name);
    }
 
    Object3D deepCopy()
    {
            Composite comp = new RandomNode();
            deepCopySelf(comp);
            return comp;
    }
    
//    public int Size()
//    {
//        return 1;
//    }
    
    public int size()
    {
        if (CameraPane.RANDOM)
        {
            if (super.size() > 0)
                return 1;
            else
                return 0;
        }
        else
            return super.size();
    }
    
    int rnd = -1;
    
    static int globalseed = 0;
    static int globalseed2 = 0; // mocap frames???
    
    //static
    transient
            int whatevercount = 0;
    
        void ResetRandom()
        {
            whatevercount = 0;
            
            super.ResetRandom();
        }
        
    int firstchoice = 0;
//    int currentpass = 0;
    
    public Object3D reserve(int i)
    {
        if (!CameraPane.RANDOM)
            return super.reserve(i);
        
        //assert(rnd == -1);
//        if (!link2master && rnd != -1)
//            new Exception().printStackTrace();
        
        if (link2master && rnd != -1) // freeze current value
            return super.reserve(rnd);
        
        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();
        
        rnd = gcount%super.Size(); //
        
            //(int)(Math.random()*super.size());
        //globalcount++;
        gcount += GrafreeD.mix3(rnd+12345,firstchoice*12345,gcount);
        
        gcount &= 0x7fffffff;
        
        if (Size() > 0 && get(0) instanceof FrameSelector)
            globalseed2 = gcount;
        else
            globalseed = gcount;
            
        if (!random) // aout 2013 link2master)
            rnd = whatevercount++;
        
        rnd %= super.Size();
        
        //GraphreeD.tracein("RESERVE " + this + " = ", i);
        Object3D child = super.get(rnd);
        //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 (!CameraPane.RANDOM)
        {
            super.release(i);
            return;
        }
        
        //GraphreeD.traceout("RELEASE " + this + " = ", i);
     //   Object3D child = super.get(i);
     //   //Applet3D.traceout("RELEASE ", child);
     //   child.count++;
 
    //    globalcount--;
        
        super.get(rnd).count++;
    //assert (child.count >= 0);
        
        if (!link2master) // volatile value
            rnd = -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();
    }
}