/* ----------------------------------------------------------------------------- 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 IntervalPlugin=[ INV_inst : PInstance, INV_trmTimer : Timer, INV_iPeriod : I, INV_bDuplicated : I, INV_lActions : [[S S] r1], INV_bOneAtTime : I, INV_bState : I ] mkIntervalPlugin;; fun deleteOb(inst, trmstr)= if trmstr.INV_trmTimer == nil then nil else ( _deltimer trmstr.INV_trmTimer; set trmstr.INV_trmTimer = nil; ); 0;; fun cbTimer(trm, trmstr)= if (trmstr.INV_lActions == nil) then nil else if (trmstr.INV_bOneAtTime) then ( let hd trmstr.INV_lActions -> [param rep] in SendPluginEvent trmstr.INV_inst "Out" param rep; set trmstr.INV_lActions = tl trmstr.INV_lActions; 0; ) else ( while (trmstr.INV_lActions != nil) do ( let hd trmstr.INV_lActions -> [param rep] in SendPluginEvent trmstr.INV_inst "Out" param rep; set trmstr.INV_lActions = tl trmstr.INV_lActions; ); 0; ); 0;; fun cbInAction(inst, from, action, param, rep, trmstr) = if (!trmstr.INV_bState) then nil else ( if (trmstr.INV_bDuplicated) then set trmstr.INV_lActions = [param rep]::nil else set trmstr.INV_lActions = lcat trmstr.INV_lActions [param rep]::nil; ); 0;; fun cbStartInterval(inst, from, action, param, rep, trmstr) = if (trmstr.INV_bState) then nil else ( set trmstr.INV_lActions = nil; set trmstr.INV_bState = 1; if trmstr.INV_trmTimer != nil then nil else set trmstr.INV_trmTimer = _rfltimer _starttimer _channel trmstr.INV_iPeriod @cbTimer trmstr; ); 0;; fun cbStopInterval(inst, from, action, param, rep, trmstr) = _deltimer trmstr.INV_trmTimer; set trmstr.INV_trmTimer = nil; set trmstr.INV_lActions = nil; set trmstr.INV_bState = 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 atoi (getPluginInstanceParam inst "oneattime") -> oneattime in let if oneattime == nil then 0 else oneattime -> oneattime in let atoi (getPluginInstanceParam inst "init") -> init in let mkIntervalPlugin [inst nil period duplicated nil oneattime 0] -> trmstr in ( PluginRegisterAction inst "In" mkfun6 @cbInAction trmstr; PluginRegisterAction inst "Start" mkfun6 @cbStartInterval trmstr; PluginRegisterAction inst "Stop" mkfun6 @cbStopInterval trmstr; if (!init) then nil else cbStartInterval inst nil nil nil nil trmstr; setPluginInstanceCbDel inst mkfun2 @deleteOb trmstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;