changeset 72:5e7553e9aee0

Improve 'dirty' flag for only updating canvas when something changes. This is experimental and might be broken, and could get reverted.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Jul 2018 12:45:03 +0300
parents 15556815ebe2
children d2a89e88f958
files events.pde multipaint.pde
diffstat 2 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/events.pde	Thu Jul 05 12:41:35 2018 +0300
+++ b/events.pde	Thu Jul 05 12:45:03 2018 +0300
@@ -7,6 +7,7 @@
 
 
 void keyPressed() {
+    g_dirty = true;
     if (key == ESC)
     {
         key = 0;
@@ -66,11 +67,24 @@
     }
 }
 
+void mouseMoved() {
+    g_dirty = true;
+
+    if (moicon(16 * 16 * g_uizoom, height - 32 * g_uizoom, 16 * g_uizoom, 24 * g_uizoom)) help(int('<'));
+    if (moicon(16 * 16 * g_uizoom, height - 8 * g_uizoom, 16 * g_uizoom, 8 * g_uizoom)) help(int('>'));
+    if (moicon(0, height - 32 * g_uizoom, 15 * 16 * g_uizoom, 32 * g_uizoom)) help(TAB);
+    if (moicon(width - 32 * g_uizoom, 0, 32 * g_uizoom, 16 * g_uizoom)) help(int('.'));
+}
+
 
 void mouseDragged() {
     int msx, msy;
+
+    mouseMoved();
+
     g_iconx = mouseX;
     g_icony = mouseY;
+
     if (insidewindow(g_iconx, g_icony)) {
         if (g_phase == 0) {
             g_piconx = g_iconx;
@@ -110,6 +124,9 @@
 
 void mousePressed() {
     int msx, msy;
+
+    g_dirty = true;
+
     g_iconx = mouseX;
     g_icony = mouseY;
     g_button = mouseButton;
@@ -155,8 +172,12 @@
     }
 }
 
+
 void mouseReleased() {
     int swap;
+
+    g_dirty = true;
+
     g_tooltrigger = 0;
     g_klikkeri = 0;
     if (tool() == 8) {
@@ -241,6 +262,8 @@
 void command(int ckey) {
     int swap;
 
+    g_dirty = true;
+
     //keypresses change g_data[] values directly as 1/0 switches
     //handling these presses "indirectly" adds complexity here
     //but is valuable elsewhere = corresponding icons have shortcuts automatically
--- a/multipaint.pde	Thu Jul 05 12:41:35 2018 +0300
+++ b/multipaint.pde	Thu Jul 05 12:45:03 2018 +0300
@@ -23,7 +23,7 @@
 int g_active, g_tooltrigger, g_prevtool;
 int g_rband, g_rbang, g_boxreconstruct, g_sorsaa, g_charlimit;
 int g_animx, g_animy, g_animframes, g_animno, g_animtime, g_animspeed;
-int g_omag, g_bordh, g_bordv, g_keymacpos;
+int g_omag, g_bordh, g_bordv, g_keymacpos, g_dirty;
 
 boolean fileselect = false, saveas = false, refselect = false,
     g_control = false, g_shift = false, exporttxt = false,
@@ -90,6 +90,7 @@
 void setup() {
     int i, x, y;
 
+    g_dirty = true;
     frameRate(40);
 
     for (i = 0; i < g_data.length; i++)
@@ -404,6 +405,12 @@
         g_shift = false;
     }
 
+    // If there should be no update, do not update.
+    if (!g_dirty)
+        return;
+    g_dirty = false;
+
+    // Animate animbrush
     if (g_data[int('n')] == 1) {
         if (++g_animtime > 8 - g_animspeed * 2) {
             animbrush_do();
@@ -411,10 +418,6 @@
         }
     }
 
-    if (moicon(16 * 16 * g_uizoom, height - 32 * g_uizoom, 16 * g_uizoom, 24 * g_uizoom)) help(int('<'));
-    if (moicon(16 * 16 * g_uizoom, height - 8 * g_uizoom, 16 * g_uizoom, 8 * g_uizoom)) help(int('>'));
-    if (moicon(0, height - 32 * g_uizoom, 15 * 16 * g_uizoom, 32 * g_uizoom)) help(TAB);
-    if (moicon(width - 32 * g_uizoom, 0, 32 * g_uizoom, 16 * g_uizoom)) help(int('.'));
 
     // Update some mouse variables
     if (g_data[int('m')] == 0 && g_data[int('M')] == 0) {