/* ----------------------------------------------------------------------------- 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 TunnelInstance = [ PTUNI_instance : PInstance, PTUNI_bSelf : I ] MkTunnelInstanceStr;; struct TunnelStr = [ PTUN_sName : S, PTUN_lInstance : [TunnelInstance r1] ] MkTunnelStr;; typeof lGlobalTunnel = [[S TunnelStr] r1];; fun deleteOb(inst, p)= let p -> [tunstr inststr] in ( set tunstr.PTUN_lInstance = remove_from_list tunstr.PTUN_lInstance inststr; //remove the tunnel from list only if there is no more instance if (tunstr.PTUN_lInstance != nil) then nil else set lGlobalTunnel = remove_sid_from_list lGlobalTunnel tunstr.PTUN_sName; ); 0;; fun cbInput(inst, from, action, param, reply, tunstr)= let sizelist tunstr.PTUN_lInstance -> size in let 0 -> i in while (i < size) do ( let nth_list tunstr.PTUN_lInstance i -> cinststr in if (cinststr.PTUNI_bSelf && (inst == cinststr.PTUNI_instance)) then nil else ( SendPluginEvent cinststr.PTUNI_instance "Out" param reply; ); set i = i + 1; ); 0;; fun newOb(inst)= let (getPluginInstanceParam inst "name") -> name in let atoi (getPluginInstanceParam inst "self") -> self in let if self == nil then 0 else self -> self in let switchstr lGlobalTunnel name -> tunstr in let if tunstr == nil then let MkTunnelStr [name nil] -> tmpstr in ( set lGlobalTunnel = [name tmpstr]::lGlobalTunnel; tmpstr; ) else tunstr -> tunstr in let MkTunnelInstanceStr [inst self] -> inststr in ( set tunstr.PTUN_lInstance = inststr::tunstr.PTUN_lInstance; PluginRegisterAction inst "Input" mkfun6 @cbInput tunstr; setPluginInstanceCbDel inst mkfun2 @deleteOb [tunstr inststr]; ); 0;; fun IniPlug(file)= set lGlobalTunnel = nil; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;