1 |
8bfefd68
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
46b572b5
|
Leszek Koltunski
|
// This file is part of Distorted. //
|
5 |
8bfefd68
|
Leszek Koltunski
|
// //
|
6 |
46b572b5
|
Leszek Koltunski
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
8bfefd68
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
46b572b5
|
Leszek Koltunski
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
8bfefd68
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
46b572b5
|
Leszek Koltunski
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
8bfefd68
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.library.main;
|
21 |
|
|
|
22 |
|
|
import java.util.ArrayList;
|
23 |
|
|
import java.util.HashMap;
|
24 |
|
|
|
25 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26 |
|
|
/**
|
27 |
|
|
* This is a member of DistortedNode. Makes sure two isomorphic Nodes only get rendered once.
|
28 |
|
|
*/
|
29 |
7602a827
|
Leszek Koltunski
|
class InternalNodeData
|
30 |
8bfefd68
|
Leszek Koltunski
|
{
|
31 |
7602a827
|
Leszek Koltunski
|
private static HashMap<ArrayList<Long>, InternalNodeData> mMapNodeID = new HashMap<>();
|
32 |
8bfefd68
|
Leszek Koltunski
|
private static long mNextNodeID =0;
|
33 |
|
|
|
34 |
|
|
private final ArrayList<Long> key;
|
35 |
|
|
private int numPointingNodes;
|
36 |
|
|
private long currTime;
|
37 |
|
|
|
38 |
|
|
final long ID;
|
39 |
|
|
DistortedFramebuffer mFBO;
|
40 |
|
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
7602a827
|
Leszek Koltunski
|
private InternalNodeData(long id, ArrayList<Long> k)
|
44 |
8bfefd68
|
Leszek Koltunski
|
{
|
45 |
|
|
ID = id;
|
46 |
|
|
key = k;
|
47 |
|
|
numPointingNodes= 1;
|
48 |
|
|
currTime =-1;
|
49 |
|
|
mFBO = null;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
|
|
static synchronized void onDestroy()
|
55 |
|
|
{
|
56 |
|
|
mNextNodeID = 0;
|
57 |
|
|
mMapNodeID.clear();
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61 |
|
|
|
62 |
|
|
@SuppressWarnings("unused")
|
63 |
|
|
static void debugMap()
|
64 |
|
|
{
|
65 |
7602a827
|
Leszek Koltunski
|
InternalNodeData tmp;
|
66 |
8bfefd68
|
Leszek Koltunski
|
|
67 |
|
|
for(ArrayList<Long> key: mMapNodeID.keySet())
|
68 |
|
|
{
|
69 |
|
|
tmp = mMapNodeID.get(key);
|
70 |
|
|
android.util.Log.e("NodeData", "NodeID: "+tmp.ID+" <-- "+key);
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
7602a827
|
Leszek Koltunski
|
static InternalNodeData returnData(ArrayList<Long> list)
|
77 |
8bfefd68
|
Leszek Koltunski
|
{
|
78 |
7602a827
|
Leszek Koltunski
|
InternalNodeData newData = mMapNodeID.get(list);
|
79 |
8bfefd68
|
Leszek Koltunski
|
|
80 |
|
|
if( newData!=null )
|
81 |
|
|
{
|
82 |
|
|
newData.numPointingNodes++;
|
83 |
|
|
}
|
84 |
|
|
else
|
85 |
|
|
{
|
86 |
7602a827
|
Leszek Koltunski
|
newData = new InternalNodeData(++mNextNodeID,list);
|
87 |
8bfefd68
|
Leszek Koltunski
|
mMapNodeID.put(list,newData);
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
return newData;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
|
|
|
95 |
|
|
boolean removeData()
|
96 |
|
|
{
|
97 |
|
|
if( --numPointingNodes==0 )
|
98 |
|
|
{
|
99 |
|
|
mMapNodeID.remove(key);
|
100 |
|
|
|
101 |
|
|
if( mFBO!=null ) return true;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
return false;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
|
|
boolean notRenderedYetAtThisTime(long time)
|
110 |
|
|
{
|
111 |
|
|
if( currTime!=time )
|
112 |
|
|
{
|
113 |
|
|
currTime = time;
|
114 |
|
|
return true;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
return false;
|
118 |
|
|
}
|
119 |
|
|
}
|