/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct DelayPlugin=[ DLY_inst : PInstance, DLY_trmTimer : Timer, DLY_iPeriod : I, DLY_bDuplicated : I, DLY_lastParam : S, DLY_previousParam : S, DLY_lastRep : S, DLY_iCount : I, DLY_bState : I ] mkDelayPlugin;; fun deleteOb(inst, trmstr)= setPluginInstanceCbScenePostRender inst nil; if trmstr.DLY_trmTimer == nil then nil else ( _deltimer trmstr.DLY_trmTimer; set trmstr.DLY_trmTimer = nil; ); 0;; fun cbTimer(trm, trmstr)= _deltimer trm; set trmstr.DLY_trmTimer = nil; if (trmstr.DLY_bDuplicated && (!strcmp trmstr.DLY_previousParam trmstr.DLY_lastParam)) then nil else SendPluginEvent trmstr.DLY_inst "Out" trmstr.DLY_lastParam trmstr.DLY_lastRep; 0;; fun cbPostRender(inst, sessionstr, etime, trmstr)= if (!trmstr.DLY_bState) then nil else ( set trmstr.DLY_iCount = trmstr.DLY_iCount + 1; if (trmstr.DLY_iCount <= 1) then nil else ( set trmstr.DLY_bState = 0; if (trmstr.DLY_bDuplicated && (!strcmp trmstr.DLY_previousParam trmstr.DLY_lastParam)) then nil else SendPluginEvent trmstr.DLY_inst "Out" trmstr.DLY_lastParam trmstr.DLY_lastRep; set trmstr.DLY_iCount = 0; ); ); 0;; fun cbStartDelay(inst, from, action, param, rep, trmstr) = set trmstr.DLY_previousParam = trmstr.DLY_lastParam; set trmstr.DLY_lastParam = param; set trmstr.DLY_lastRep = rep; //when period == 0 then wait 2 frame to unsure the 3D buffer have been updated if (trmstr.DLY_iPeriod == 0) then ( set trmstr.DLY_bState = 1; 0; ) else ( if trmstr.DLY_trmTimer != nil then nil else set trmstr.DLY_trmTimer = _rfltimer _starttimer _channel trmstr.DLY_iPeriod @cbTimer trmstr; 0; ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "delay") -> period in let atoi (getPluginInstanceParam inst "duplicated") -> duplicated in let if duplicated == nil then 0 else duplicated -> duplicated in let mkDelayPlugin [inst nil period duplicated nil nil nil 0 0] -> trmstr in ( PluginRegisterAction inst "In" mkfun6 @cbStartDelay trmstr; if (trmstr.DLY_iPeriod != 0) then nil else setPluginInstanceCbScenePostRender inst mkfun4 @cbPostRender trmstr; setPluginInstanceCbDel inst mkfun2 @deleteOb trmstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;