/* ----------------------------------------------------------------------------- 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 TimerPlugin=[ TRM_inst : PInstance, TRM_trmTimer : Timer, TRM_iPeriod : I, TRM_bLoop : I ] mkTimerPlugin;; fun deleteOb(inst, trmstr)= if trmstr.TRM_trmTimer == nil then nil else ( _deltimer trmstr.TRM_trmTimer; set trmstr.TRM_trmTimer = nil; ); 0;; fun cbTimer(trm, trmstr)= if trmstr.TRM_bLoop then nil else ( _deltimer trmstr.TRM_trmTimer; set trmstr.TRM_trmTimer = nil; ); SendPluginEvent trmstr.TRM_inst "Top" nil nil; 0;; fun cbStartTimer(inst, from, action, param, rep, trmstr) = if trmstr.TRM_trmTimer == nil then nil else ( _deltimer trmstr.TRM_trmTimer; set trmstr.TRM_trmTimer = nil; ); set trmstr.TRM_trmTimer = _rfltimer _starttimer _channel trmstr.TRM_iPeriod @cbTimer trmstr; 0;; fun cbStopTimer(inst, from, action, param, rep, trmstr) = if trmstr.TRM_trmTimer == nil then nil else ( _deltimer trmstr.TRM_trmTimer; set trmstr.TRM_trmTimer = nil; ); 0;; fun cbSetPeriod(inst, from, action, param, rep, trmstr) = if (atoi param) == nil then nil else set trmstr.TRM_iPeriod = (atoi param); if trmstr.TRM_trmTimer == nil then nil else ( _deltimer trmstr.TRM_trmTimer; set trmstr.TRM_trmTimer = _rfltimer _starttimer _channel trmstr.TRM_iPeriod @cbTimer trmstr; ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "period") -> period in let atoi (getPluginInstanceParam inst "loop") -> loop in let atoi (getPluginInstanceParam inst "autostart") -> autostart in let mkTimerPlugin [inst nil period loop] -> trmstr in ( PluginRegisterAction inst "Start" mkfun6 @cbStartTimer trmstr; PluginRegisterAction inst "Stop" mkfun6 @cbStopTimer trmstr; PluginRegisterAction inst "Set period" mkfun6 @cbSetPeriod trmstr; if !autostart then nil else set trmstr.TRM_trmTimer = _rfltimer _starttimer _channel trmstr.TRM_iPeriod @cbTimer trmstr; setPluginInstanceCbDel inst mkfun2 @deleteOb trmstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;