Project

General

Profile

Download (4.13 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / main / InternalNodeData.java @ 246d021c

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// 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
// Distorted is distributed in the hope that it will be useful,                                  //
12
// 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
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
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
class InternalNodeData
30
  {
31
  private static HashMap<ArrayList<Long>, InternalNodeData> mMapNodeID = new HashMap<>();
32
  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
  private InternalNodeData(long id, ArrayList<Long> k)
44
    {
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
    InternalNodeData tmp;
66

    
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
  static InternalNodeData returnData(ArrayList<Long> list)
77
    {
78
    InternalNodeData newData = mMapNodeID.get(list);
79

    
80
    if( newData!=null )
81
      {
82
      newData.numPointingNodes++;
83
      }
84
    else
85
      {
86
      newData = new InternalNodeData(++mNextNodeID,list);
87
      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
  }
(10-10/14)