PFront results gazillion amount of cache file, how to avoid it?

Hi my friends,
I am trying to convert the guest tutorial matrix rain from coding train to processing version. But I found that the code will result gazillion amount of cache file to my disk, maybe because I am using PFont. Each steam of characters will take as cache file. I wonder if there is way to avoid to build such amount of cache by changing the code or cleaning up the caches when the code running.
here is my code:

float symbolSize;
Stream[] streams;
int streamSize;

void setup()
{
  size(800, 400);
  background(0, 100);
  symbolSize = 15;
  streamSize = (int)(width/symbolSize);
  
  streams = new Stream[streamSize]; 
  
  int x = 0;
  int y = int(random(-1000, 0));
  for(int i = 0; i <= streamSize-1; i++)
  {
    Stream stream = new Stream(x, y, symbolSize);
    streams[i] = stream;
    x += symbolSize;
  }
}

void draw()
{
  background(0, 100);
  for(Stream s: streams)
  {
    s.render();  
  }
  
}

class Stream
{
  Symbol[] symbols;
  Symbol symbol;
  int totalSymbols;
  float symbolSize;
  float rainSpeed;
  int x, y;
  float fateInterval;
  
  Stream(int x, int y, float symbolSize)
  {
    this.x = x;
    this.y = y;
    this.symbolSize = symbolSize;
    rainSpeed = random(1, 10);
    fateInterval = 1.6;
    totalSymbols = floor(random(5, height/symbolSize-1));
    

    symbols = new Symbol[totalSymbols];
    
    generateSymbols();
    println(totalSymbols);
  }

  void generateSymbols()
  { 
    //boolean first = round(random(0, 4))==1? true:false;
    boolean first = round(random(0, 4))==1;
    float opacity = 255;
    for(int i = 0; i <= totalSymbols-1; i++)
    {
      symbol = new Symbol(x, y, symbolSize, rainSpeed, first, opacity);
      symbol.setToRandomSymbol();
      symbols[i] = symbol;
      y -= symbolSize;
      opacity -= (255/totalSymbols)/fateInterval;
      first = false;
    }
  }

  void render()
  {
    for(Symbol s: symbols)
    {
      if(s.first)
      {
        fill(200, 250, 230, s.opacity);
      }
      else
      {
        fill(10, 250, 110, s.opacity);
      }
      textFont(s.font);
      s.setToRandomSymbol();
      text(s.word, s.x, s.y);
      s.rain();
    }
  }



}


class Symbol
{
  PFont font;
  int x, y;
  char word;
  float size;
  float speed;
  int switchInterval ;
  boolean first;
  float opacity;
  
  Symbol(int _x, int _y, float _size, float _speed, boolean _first, float _opacity)
  {
    x = _x;
    y = _y; 
    size = _size;
    speed = _speed;
    first = _first;
    opacity = _opacity;
    //font = createFont("SawarabiMincho-Regular.ttf", size);
    font = createFont("Yomogi-Regular.ttf", size);
    switchInterval = round(random(2, 25));
  }

  void setToRandomSymbol()
  {
    //float charType = round(random(0, 5));
    if(frameCount%switchInterval == 0)
    {
      //if(charType > 1)
      //{
        // set it to Katakana
        word = char(0x30A0 + floor(random(0, 97)));
      //}
      //else
      //{
      //  // set it to numeric 
      //  word = char(floor(random(0, 10)));
      //}
    }
  }
  
  void rain()
  {
   
    y = (y >= height)? 0: y+(int)speed;
    println(speed);
  }

}

The statement above is an asset resource loading operation.
Best place to load assets is inside setup().

1 Like

Thanks GoToLoop. I figure out it if the statement put in the setup() , It only load the resource once and result one cache file. But if it was in the object, it will load and write the cache file as many as the object occurring.