blob: 9d8f0e05830f2371b1a97784c12cd5e27cf6ae9f [file] [log] [blame]
Adrien Béraud04463092013-05-06 14:17:22 +10001package com.savoirfairelinux.sflphone.model;
2
3import java.util.ArrayList;
4
5public class BubbleModel
6{
Adrien Béraud25fc4092013-05-06 15:28:39 +10007 private static final String TAG = BubbleModel.class.getSimpleName();
8
9 public long lastUpdate = 0;
Adrien Béraud04463092013-05-06 14:17:22 +100010 public int width, height;
11 public ArrayList<Bubble> listBubbles = new ArrayList<Bubble>();
Adrien Béraud25fc4092013-05-06 15:28:39 +100012
13 private static final float BUBBLE_SPEED = 4.f;
14
15 public void update()
16 {
17 long now = System.nanoTime();
18
19 // Do nothing if lastUpdate is in the future.
20 if (lastUpdate > now)
21 return;
22
23 float dt = (float) Math.min((now - lastUpdate) / 1000000000.0, .2);
24 lastUpdate = now;
25
26 //Log.w(TAG, "update dt="+dt);
27
28 // Iterators should not be used in frequently called methods
29 // to avoid garbage collection glitches caused by iterator objects.
30 for(int i=0, n=listBubbles.size(); i<n; i++) {
31 Bubble b = listBubbles.get(i);
32 //Log.w(TAG, "update b");
33 if(!b.dragged && b.attractor != null) {
34 float bx=b.getPosX(), by=b.getPosY();
35 float dx = (b.attractor.x - bx) * dt * BUBBLE_SPEED;
36 float dy = (b.attractor.y - by) * dt * BUBBLE_SPEED;
37 //Log.w(TAG, "update dx="+dt+" dy="+dy);
38 b.setPos(bx+dx, by+dy);
39 }
40 }
41 }
Adrien Béraud04463092013-05-06 14:17:22 +100042}