#ifndef UDO_TWIST_CHECKPOINTING #define UDO_TWIST_CHECKPOINTING ## gitwst_maxundolevels = 32 gitwst_checkpoints[][] init imaxinstances, gitwst_maxundolevels gitwst_checkpointstate[] init imaxinstances gitwst_checkpointencodemult = 10000 opcode twst_checkpoint_encode, i, ii ifnL, ifnR xin iencoded = (ifnL * gitwst_checkpointencodemult) + (ifnR / gitwst_checkpointencodemult) xout iencoded endop opcode twst_checkpoint_decode, ii, i iencoded xin ifnL = int(iencoded) / gitwst_checkpointencodemult ifnR = frac(iencoded) * gitwst_checkpointencodemult xout ifnL, ifnR endop opcode twst_checkpoint_clear, 0, j instanceindex xin instanceindex = (instanceindex == -1) ? gitwst_instanceindex : instanceindex icheckpointnumber = gitwst_checkpointstate[instanceindex] while (icheckpointnumber >= 0) do ifnL, ifnR twst_checkpoint_decode gitwst_checkpoints[instanceindex][icheckpointnumber] if (ifnL > 0 && ftexists(ifnL) == 1) then ftfree ifnL, 0 endif if (ifnR > 0 && ftexists(ifnR) == 1) then ftfree ifnR, 0 endif icheckpointnumber -= 1 od gitwst_checkpointstate[instanceindex] = 0 endop opcode twst_checkpoint, 0, j instanceindex xin imaxundo chnget "twst_maxundo" imaxundo = (imaxundo == -1) ? gitwst_maxundolevels : imaxundo if (imaxundo == 0 || imaxundo > gitwst_maxundolevels) then goto complete endif instanceindex = (instanceindex == -1) ? gitwst_instanceindex : instanceindex icheckpointnumber = gitwst_checkpointstate[instanceindex] if (icheckpointnumber >= imaxundo) then ifnL, ifnR twst_checkpoint_decode gitwst_checkpoints[instanceindex][0] if (ifnL > 0 && ftexists(ifnL) == 1) then ftfree ifnL, 0 endif if (ifnR > 0 && ftexists(ifnR) == 1) then ftfree ifnR, 0 endif index = 1 itemp[] getrow gitwst_checkpoints, instanceindex while (index <= imaxundo) do gitwst_checkpoints[instanceindex][index - 1] = itemp[index] index += 1 od gitwst_checkpointstate[instanceindex] = icheckpointnumber ;- 1 else gitwst_checkpointstate[instanceindex] = icheckpointnumber + 1 endif ifnL = gitwst_bufferL[instanceindex] ifnR = gitwst_bufferR[instanceindex] ilen = ftlen(ifnL) ifnCheckpointL ftgen 0, 0, ilen, 2, 0 tableicopy ifnCheckpointL, ifnL if (ifnR > 0) then ifnCheckpointR ftgen 0, 0, ilen, 2, 0 tableicopy ifnCheckpointR, ifnR else ifnCheckpointR = 0 endif iencoded twst_checkpoint_encode ifnCheckpointL, ifnCheckpointR gitwst_checkpoints[instanceindex][icheckpointnumber] = iencoded complete: endop opcode twst_undo, i, jp instanceindex, iapplyundo xin instanceindex = (instanceindex == -1) ? gitwst_instanceindex : instanceindex icheckpointnumber = gitwst_checkpointstate[instanceindex] icheckpointnumber -= 1 if (icheckpointnumber < 0) then istatus = -1 goto complete endif gitwst_checkpointstate[instanceindex] = icheckpointnumber ifnL, ifnR twst_checkpoint_decode gitwst_checkpoints[instanceindex][icheckpointnumber] if (iapplyundo == 1) then ; apply or just step back and forget if (ifnL > 0 && ftexists(ifnL) = 1) then ftfree gitwst_bufferL[instanceindex], 0 gitwst_bufferL[instanceindex] = ifnL endif if (ifnR > 0 && ftexists(ifnR) == 1) then ftfree gitwst_bufferR[instanceindex], 0 gitwst_bufferR[instanceindex] = ifnR endif else if (ifnL > 0 && ftexists(ifnL) = 1) then ftfree ifnL, 0 endif if (ifnL > 0 && ftexists(ifnR) = 1) then ftfree ifnR, 0 endif endif istatus = 1 complete: xout istatus endop #end