View Javadoc

1   package org.catacomb.numeric.data;
2   
3   import java.lang.reflect.Field;
4   
5   import org.catacomb.datalish.*;
6   import org.catacomb.report.E;
7   
8   
9   // REFAC - if there is a specific block type for animations, don't
10  // need the reflection stuff
11  
12  
13  public class AnimSlice extends StackSingleSlice implements SpriteAnim {
14  
15  
16      SceneConfig[] data;
17      double[] times;
18  
19      int npcache;
20  
21      SpriteStore spriteStore;
22  
23      public AnimSlice(BlockStack bs, String fnm, Field f, String t,
24                       SpriteStore ss) {
25          super(bs, fnm, f, null, t);
26          spriteStore = ss;
27          npcache = 0;
28          data = new SceneConfig[10];
29          times = new double[10];
30      }
31  
32      public SpriteStore getSpriteStore() {
33          return spriteStore;
34      }
35  
36  
37      public SceneConfig getSceneConfig(int ip) {
38          int np = blockStack.getSize();
39          if (np > data.length) {
40              int nn = np + np/2 + 10;
41              SceneConfig[] dn = new SceneConfig[nn];
42              for (int i = 0; i < npcache; i++) {
43                  dn[i] = data[i];
44              }
45              data = dn;
46          }
47  
48          SceneConfig ret = null;
49          if (ip < np) {
50              ret = data[ip];
51              if (ret == null) {
52                  try {
53                      ret = (SceneConfig)(field.get(blockStack.getBlock(ip)));
54                      data[ip] = ret;
55                      if (npcache < ip) {
56                          npcache = ip;
57                      }
58                  } catch (Exception ex) {
59                      E.error("exception reading slice from block stack " + this + " " + ex);
60                  }
61  
62              }
63          }
64          return ret;
65      }
66  
67  
68  
69  
70      void clearCache() {
71          npcache = 0;
72      }
73  
74      public Box getBox() {
75          // REFAC - cold know sprite sizes (currently painter does)
76          int np = blockStack.getSize();
77          Box box = new Box();
78          int ival = 1 + np / 20;
79          for (int i = 0; i < np; i += ival) {
80              for (SpritePlacement sp : getSceneConfig(i).getPlacements()) {
81                  box.push(sp.getPosition());
82              }
83          }
84          box.enlarge(0.2);
85          return box;
86      }
87  
88  
89  
90  
91      public String getFrameDescription(int ifr) {
92          SceneConfig sc = getSceneConfig(ifr);
93          return String.format("%8.3g", new Double(sc.getTime()));
94      }
95  
96  }