Commit 1d5bf4b4 authored by ogg.k.ogg.k's avatar ogg.k.ogg.k
Browse files

optimize a bit: do not render if all currently active items are not visible

while there, rename a data member of Item to match libtiger, makes it easier
parent 8c4932e4
......@@ -26,7 +26,7 @@ import com.fluendo.utils.*;
public class Item {
private Tracker kin = null;
private boolean alive = false;
private boolean active = false;
private Font font = null;
private int font_size = 0;
private String text = null;
......@@ -116,7 +116,7 @@ public class Item {
/**
* Updates the item at the given time.
* returns true for alive, false for dead
* returns false if the item should be destroyed, true otherwise.
*/
public boolean update(Component c, Dimension d, double t) {
com.fluendo.jkate.Event ev = kin.ev;
......@@ -125,13 +125,13 @@ public class Item {
/* early out if we're not within the lifetime of the event */
if (t < ev.start_time) return true;
if (t >= ev.end_time) {
alive = false;
active = false;
dirty = true;
return false; /* we're done, and will get destroyed */
}
if (!alive) {
alive = true;
if (!active) {
active = true;
dirty = true;
}
......@@ -161,7 +161,7 @@ public class Item {
* Renders the item on the given image.
*/
public void render(Component c, Image img) {
if (!alive)
if (!active)
return;
updateCachedData(c, img);
......@@ -209,4 +209,7 @@ public class Item {
public boolean isDirty() {
return dirty;
}
public boolean isActive() {
return active;
}
}
......@@ -40,20 +40,25 @@ public class Renderer {
* Returns 1 if there is nothing to draw, as an optimization
*/
public synchronized int update(Component c, Dimension d, double t) {
int nactive = 0;
for (int n=0; n<items.size(); ++n) {
boolean ret = ((Item)items.elementAt(n)).update(c, d, t);
Item item = (Item)items.elementAt(n);
boolean ret = item.update(c, d, t);
if (!ret) {
items.removeElementAt(n);
dirty = true;
--n;
}
else {
if (((Item)items.elementAt(n)).isDirty()) {
if (item.isDirty()) {
dirty = true;
}
if (item.isActive()) {
++nactive;
}
}
}
if (items.size() == 0)
if (nactive == 0)
return 1;
return 0;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment