/* name : dynparticles - part SERVER date : february 2007 auteur : iri pour I-Maginer (http://www.i-maginer.fr) */ typeof class = S;; struct PART = [ // couleur initcolor : S, colorcycle : S, // taille sizemax : S, sizecycle : S, sizetime : S, // expert life : S, maskEmitter : S, volume : S, volA : S, volB : S, effect : S, effectA : S, effectB :S, effectC : S, // inutilisé target : S, randcolor : S, mass : S, framerate : S ] mkPART;; typeof part = PART;; typeof clis = [[CLIENT I] r1];; typeof initON = I;; var cliALL = 0;; // si vaut 1 tous les clients enregistrés auront les modifications en live sinon seul le client admin les verra var editSave = 0;; // si vaut 1, toutes les modifs sont sauvegardés en tant réel sur le *.dms sinon elles sont perdues à la fermeture du serveur /* supprime un client de la liste l -> [[CLIENT I] r1] : clis cli -> CLIENT : client à supprimer <- [[CLIENT I] r1] : liste à jour */ fun remove_from_clis(l, cli)= if l == nil then l else let hd l -> [c _] in if cli == c then tl l else (hd l) :: remove_from_clis tl l cli;; fun getStateByCli(l, cli)= if l == nil then 0 else let hd l -> [c state] in if cli == c then state else getStateByCli tl l cli;; fun chgState(l, cli, value)= if l == nil then nil else let hd l -> [c _] in if cli == c then [cli value] :: (tl l) else chgState tl l cli value;; // Prépare les données à envoyer à un client fun prepareDatas()= strbuild ( "initcolor" :: part.initcolor :: nil ) :: ( "colorcycle" :: part.colorcycle :: nil ) :: ( "sizemax" :: part.sizemax :: nil ) :: ( "sizecycle" :: part.sizecycle :: nil ) :: ( "sizetime" :: part.sizetime :: nil ) :: ( "life" :: part.life :: nil ) :: ( "maskEmitter" :: part.maskEmitter :: nil ) :: ( "volume" :: part.volume :: nil ) :: ( "volA" :: part.volA :: nil ) :: ( "volB" :: part.volB :: nil ) :: ( "effect" :: part.effect :: nil ) :: ( "effectA" :: part.effectA :: nil ) :: ( "effectB" :: part.effectB :: nil ) :: ( "effectC" :: part.effectC :: nil ) :: ( "target" :: part.target :: nil ) :: ( "randcolor" :: part.randcolor :: nil ) :: ( "target" :: part.target :: nil ) :: ( "mass" :: part.mass :: nil ) :: ( "framerate" :: part.framerate :: nil ) :: nil;; /* Sauvegarde les données sur le *.dms */ fun saveChgDms()=0;; /* Envoi un message vers les clients enregistrés auprès du serveur l -> [[CLIENT I] r1] : clis : liste des clients enregistrés ui -> UserI action -> S : Nom de l'action à envoyer param -> S : paramètre à envoyer <- I */ fun _broadMsg(l, ui, action, param)= if l == nil then 0 else let hd l -> [cli _] in ( UsendMessage ui cli action param; _broadMsg tl l ui action param );; /* Envoi un message vers un client pour lancer un système de particules ui -> UserI cli -> CLIENT action -> S : nom de l'action a envoyé param -> S : paramètre de cette action <- i */ fun _sendMsgC(cli, ui, action, param)= _broadMsg [cli nil]::nil ui action param;; /* Communications intramodules (cli/srv) ui -> UserI cli -> CLIENT action -> S param -> S p -> [Ob] <- I */ fun cbComm(ui, cli, action, param, p)= // Générales if !strcmp action "register" then ( set clis = [cli initON] :: clis; if initON == 1 then UsendMessage ui cli "start" prepareDatas else 0; 0 ) else if !strcmp action "unregister" then ( set clis = remove_from_clis clis cli; UsendMessage ui cli "stop" nil; 0 ) else if !strcmp action "start" then _broadMsg clis ui "start" prepareDatas else if !strcmp action "started" then ( set clis = chgState clis cli 1; 0 ) // Edition en ligne du client admin : les noms des actions sont suffisamment explicites else if !strcmp action "size_newSizeMax" then ( set part.sizemax = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "color_cycleColor" then ( set part.colorcycle = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "color_chgAlpha" then ( let htoi part.initcolor -> col in let get_rgba col -> [r g b _] in let make_rgba r g b atoi param -> col in set part.initcolor = itoh col; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "color_chgColor" then ( let htoi part.initcolor -> col in let get_rgba col -> [_ _ _ a] in let htoi substr param 0 2 -> r in let htoi substr param 2 2 -> g in let htoi substr param 4 2 -> b in let make_rgba r g b a -> col in set part.initcolor = itoh col; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_infinit" then ( set part.life = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_volSphreRadius" then ( let hd strextr part.volA -> [a [b [c _]]] in set part.maskEmitter = linebuild param :: b :: c :: nil; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_volCone" then ( let lineextr param -> [n [value _]] in let atoi n -> n in let hd strextr part.volA -> [a [b [c _]]] in if n then set part.volA = linebuild value :: b :: c :: nil else if n == 2 then set part.volA = linebuild a :: value :: c :: nil else if n == 3 then set part.volA = linebuild a :: b :: value :: nil else nil; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_volPlan" then ( let lineextr param -> [n [value _]] in let atoi n -> n in let hd strextr part.volA -> [a [b [c _]]] in if n then set part.volA = linebuild value :: b :: c :: nil else if n == 2 then set part.volA = linebuild a :: value :: c :: nil else nil; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_volLine" then ( let hd strextr part.volA -> [a [b [c _]]] in set part.maskEmitter = linebuild param :: b :: c :: nil; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectNone" then ( set part.effect = nil; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectConstant" then ( set part.effect = "EFFECT_CONSTANT"; set part.effectA = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectElectric" then ( set part.effect = "EFFECT_ELECTRIC"; let lineextr param -> [ax [ay [az [bx _]]]] in ( set part.effectA = linebuild ax :: ay :: az :: nil; set part.effectB = linebuild bx :: "0" :: "0" :: nil; ); if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectMagnetic" then ( set part.effect = "EFFECT_MAGNETIC"; let lineextr param -> [ax [ay [az [bx _]]]] in ( set part.effectA = linebuild ax :: ay :: az :: nil; set part.effectB = linebuild bx :: "0" :: "0" :: nil; ); if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectChotic0" then ( set part.effect = "EFFECT_CHAOTIC0"; let lineextr param -> [ax [ay [az [bx [by [bz _]]]]]] in ( set part.effectA = linebuild ax :: ay :: az :: nil; set part.effectB = linebuild bx :: by :: bz :: nil; ); if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectChotic1" then ( set part.effect = "EFFECT_CHAOTIC1"; let lineextr param -> [ax [ay [az [bx [by [bz _]]]]]] in ( set part.effectA = linebuild ax :: ay :: az :: nil; set part.effectB = linebuild bx :: by :: bz :: nil; ); if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectHelicoid" then ( set part.effect = "EFFECT_HELICOID"; let lineextr param -> [ax [ay [az [bx [by [bz _]]]]]] in ( set part.effectA = linebuild ax :: ay :: az :: nil; set part.effectB = linebuild bx :: by :: bz :: nil; ); if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_effectPlancoll" then ( set part.effect = "EFFECT_PLANCOLL"; let lineextr param -> [ax [ay [az [bx [by [bz _]]]]]] in ( set part.effectA = linebuild ax :: ay :: az :: nil; set part.effectB = linebuild bx :: by :: bz :: nil; ); if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_allClients" then ( set cliALL = atoi param ) else if !strcmp action "expert_upload" then ( set editSave = atoi param ) else if !strcmp action "plugin_stop" then ( _broadMsg clis ui "stop" nil ) else if !strcmp action "expert_billboard" then ( set part.target = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_rainbow" then ( set part.randcolor = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_masse" then ( set part.mass = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "size_newSize" then ( set part.sizetime = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) else if !strcmp action "expert_rate" then ( set part.framerate = param; if cliALL then _broadMsg clis ui "start" prepareDatas else _sendMsgC cli ui "start" prepareDatas; if editSave then saveChgDms else 0 ) // Autres cas else 0;; /* Un client se déconnecte : il est supprimé de la liste ' clis ' o -> Ob cli -> CLIENT : client déconnecté <- I */ fun out(o, cli)= set clis = remove_from_clis clis cli; 0;; fun newOb(o)= let hd UgetParam ObUi o "init" -> tmp in set initON = if !strcmp tmp "on" then 1 else 0; let hd UgetParam ObUi o "initColor" -> p1 in let hd UgetParam ObUi o "initSizes" -> p2 in let hd UgetParam ObUi o "colorCycle" -> p3 in let hd UgetParam ObUi o "sizeCycle" -> p4 in let hd UgetParam ObUi o "maxSize" -> p5 in let hd UgetParam ObUi o "typeFX" -> p6 in let hd UgetParam ObUi o "typeVolEmitter" -> p7 in let hd UgetParam ObUi o "typeMaskEmitter" -> p8 in let hd UgetParam ObUi o "typeParticle" -> p9 in let hd UgetParam ObUi o "vectorA" -> p10 in let hd UgetParam ObUi o "vectorB" -> p11 in let hd UgetParam ObUi o "vectorC" -> p12 in set part = mkPART[ p1 p3 p5 p4 p2 "0" "PCL_INFINIT" p7 p10 p11 p8 p10 p11 p12 p9 p9 "0" "96" ]; UcbComm this ObUi o mkfun5 @cbComm [o]; OB_CBclientDestroyed o @out; 0;; fun IniPlug(file)= set class = getInfo strextr _getpack _checkpack file "name"; PlugRegister class @newOb nil; 0 ;;