view buffers.pde @ 193:7a9dc175ece5

Use dst = src.slice(0) instead of Processing arrayCopy(src, dst) for cloning arrays. Should be faster, but if not, this can be reverted later.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 23 Aug 2018 18:01:16 +0300
parents 72ae62f2036b
children
line wrap: on
line source

// undo / spare

final int UNDOSTEPS = 20; // max # of undo steps

byte[] g_sparepage = new byte[88000];
byte[] g_swappage = new byte[88000];
byte[][] g_undob = new byte[UNDOSTEPS + 1][88000];
byte[][] g_undobs = new byte[UNDOSTEPS + 1][88000];
int[] g_uindex = new int[8];
int[] g_ubottom = new int[8];
int[] g_utop = new int[8];


void ustats()
{
    //a debug thingie in case the step undo does not work
    //println("UINDEX:"+g_uindex[g_spare]);
    //println("UTOP:"+g_utop[g_spare]);
    //println("UBOTTOM:"+g_ubottom[g_spare]);
}


void store_undo()
{
    if (g_spare)
        g_undobs[g_uindex[g_spare]] = g_map.slice(0);
    else
        g_undob[g_uindex[g_spare]] = g_map.slice(0);

    g_uindex[g_spare]++;
    if (g_uindex[g_spare] > UNDOSTEPS)
        g_uindex[g_spare] = 0;

    if (g_uindex[g_spare] == g_ubottom[g_spare])
    {
        g_ubottom[g_spare]++;
        if (g_ubottom[g_spare] > UNDOSTEPS)
            g_ubottom[g_spare] = 0;
    }
    g_utop[g_spare] = g_uindex[g_spare];

    refreshpalette();
    ustats();
}


void restore_undo()
{
    if (g_uindex[g_spare] == g_ubottom[g_spare])
        return;

    if (g_spare)
        g_undobs[g_uindex[g_spare]] = g_map.slice(0);
    else
        g_undob[g_uindex[g_spare]] = g_map.slice(0);

    g_uindex[g_spare]--;
    if (g_uindex[g_spare] < 0)
        g_uindex[g_spare] = UNDOSTEPS;

    if (g_spare)
        g_map = g_undobs[g_uindex[g_spare]].slice(0);
    else
        g_map = g_undob[g_uindex[g_spare]].slice(0);

    refreshpalette();
    ustats();
}


void redo_undo()
{
    if (g_uindex[g_spare] == g_utop[g_spare])
        return;

    g_uindex[g_spare]++;
    if (g_uindex[g_spare] > UNDOSTEPS)
        g_uindex[g_spare] = 0;

    if (g_spare)
        g_map = g_undobs[g_uindex[g_spare]].slice(0);
    else
        g_map = g_undob[g_uindex[g_spare]].slice(0);

    refreshpalette();
    ustats();
}


void spare() //dpaint style spare page
{
    g_swappage = g_sparepage.slice(0);
    g_sparepage = g_map.slice(0);
    g_map = g_swappage.slice(0);

    mpSetTitle(g_spare ? sfilename : filename);

    g_spare = 1 - g_spare;
    g_realfront = byte(g_farge);
    g_realback = byte(g_backg);
    refreshpalette();
}


void switcher(int mode)
{
    // this achieves varieties of whole screen copying
    // needed for brush copy and pre-drawing the shapes when a
    // tool is active etc.
    switch (mode)
    {
        case 0:
            g_rmap = g_map.slice(0);
            break;
        case 1:
            g_map = g_rmap.slice(0);
            for (int i = 0; i < 1024; i++)
            {
                if (g_remdo[i] == 1)
                {
                    g_remdo[i] = 0;
                    g_redo[i] = 0;
                }
            }
            break;
        case 2:
            g_brush = g_map.slice(0);
            break;
        case 3:
            g_sparepage = g_map.slice(0);
            break;
        case 4:
            g_mapm = g_sparepage.slice(0);
            break;
    }
}