/***************************************************************/ /* */ /* PBGUNCAM.PKG */ /* */ /* plug-in PhotoPaintBall */ /* client - camera and guns animation */ /* */ /* version 5 : Loïc Berthelot, dec 2000 */ /* */ /* d'après le plugin AvTool de Christophe Lorek */ /* */ /***************************************************************/ /***************************************************************/ /* */ /* */ /* DATA STRUCT : */ /* typeof class : S */ /* struct GunCam */ /* typeof gunCam : GunCam */ /* struct GunCamManager */ /* typeof gcm : GunCamManager */ /* */ /* */ /* INTERNAL BODY : */ /* gunCam_animTool : fun [H3d I I] _ */ /* gunCam_toolAnim : fun [Ob GunCam] I */ /* gunCam_playonce : fun [I I] I */ /* gunCam_playloop : fun [I I] I */ /* */ /* */ /* EXTERNAL BODY : */ /* gunCam_reload : fun [] I */ /* gunCam_shoot : fun [] I */ /* gunCam_walk : fun [] I */ /* gunCam_wait : fun [] I */ /* gunCam_show : fun [I] I */ /* gunCam_hide : fun [] I */ /* gunCam_start : fun [Ob] I */ /* */ /* */ /* EXTERNAL BODY GUNCAM MANAGER : */ /* gcm_load : fun [I] I */ /* gcm_start : fun [] I */ /* */ /* gunCam_load : fun [I] I */ /* */ /* */ /***************************************************************/ /*************************************************************************/ /* */ /* D A T A S T R U C T */ /* */ /*************************************************************************/ struct GunCam = [ /* index of gun in library */ index_GC : I, /* render framerate */ framerate_GC : I, /* flag to play or not */ playstop_GC : I, /* flag to play in loop or not */ looponce_GC : I, /* first frame of animation */ startframe_GC : I, /* last frame of animation */ endframe_GC : I, /* current frame printed */ currentframe_GC : I, /* buffers */ accum_GC : I, tick_GC : I ] mkGunCam;; typeof gunCam = GunCam;; /**************************/ /* GunCam Manager */ /* */ /* set of flags to manage */ /* guns animations. */ /**************************/ struct GunCamManager = [ isWaiting : I, isWalking : I, isShooting : I, isReloading : I, frameRate : I, nbShootFrames : I, shootTimer : Timer, shootTimeout : I, nbReloadFrames : I, reloadTimer : Timer, reloadTimeout : I ] mkGunCamManager;; typeof gcm = GunCamManager;; /*************************************************************************/ /* */ /* I N T E R N A L B O D Y */ /* */ /*************************************************************************/ /**********************************/ /* gunCam_animTool [H3d I I] _ */ /* */ /* set an animation key */ /**********************************/ fun gunCam_animTool (current_h3d, currentframe, taux) = M3setAnimKey2 session current_h3d currentframe currentframe+1 taux;; /**********************************/ /* gunCam_toolAnim [Ob GunCam] I */ /* */ /* animation callback */ /**********************************/ fun gunCam_toolAnim (o, gc) = let _tickcount -> newTime in if gc.playstop_GC then ( if gc.tick_GC == nil then set gc.tick_GC = _tickcount else nil; let _tickcount -> currenttick in let ((currenttick - gc.tick_GC) * gc.framerate_GC) -> timeframe in let mod timeframe 1000 -> accum in let (timeframe / 1000) -> deltaframe in let gc.currentframe_GC -> prevframe in ( set gc.accum_GC = gc.accum_GC + accum; if gc.accum_GC > 1000 then ( set deltaframe = deltaframe + 1; set gc.accum_GC = gc.accum_GC - 1000; ) else nil; set gc.currentframe_GC = gc.currentframe_GC + deltaframe; if gc.currentframe_GC < gc.endframe_GC then ( gunCam_animTool gunsLib.(gc.index_GC).shellGunCam_GEL gc.currentframe_GC (gc.accum_GC * 256 / 1000); set gc.tick_GC = currenttick; ) else ( if gc.looponce_GC then ( set gc.playstop_GC = 0; set gc.currentframe_GC = gc.startframe_GC; set gc.tick_GC = nil ) else ( set gc.playstop_GC = 1; set gc.currentframe_GC = gc.startframe_GC; set gc.tick_GC = nil ) ); 0; ); ) else nil;; /**********************************/ /* gunCam_playonce [I I] I */ /* */ /* sf : startframe, ef : endframe */ /**********************************/ fun gunCam_playonce (sf, ef) = set gunCam.playstop_GC = 1; set gunCam.looponce_GC = 1; set gunCam.startframe_GC = sf; set gunCam.endframe_GC = ef; set gunCam.currentframe_GC = sf; set gunCam.tick_GC = nil; 1 ;; /**********************************/ /* gunCam_playloop [I I] I */ /* */ /* sf : startframe, ef : endframe */ /**********************************/ fun gunCam_playloop (sf, ef) = set gunCam.playstop_GC = 1; set gunCam.looponce_GC = 0; set gunCam.startframe_GC = sf; set gunCam.endframe_GC = ef; set gunCam.currentframe_GC = sf; set gunCam.tick_GC = nil; 1 ;; /*************************************************************************/ /* */ /* E X T E R N A L B O D Y */ /* */ /*************************************************************************/ /*******************************/ /* gunCam_reload [] I */ /* */ /*******************************/ fun gunCam_reload () = let gunsLib.(gunCam.index_GC).reload_GEL -> [sf ef] in gunCam_playonce sf ef ;; /*******************************/ /* gunCam_shoot [] I */ /* */ /*******************************/ fun gunCam_shoot () = let gunsLib.(gunCam.index_GC).shoot_GEL -> [sf ef] in gunCam_playonce sf ef ;; /*******************************/ /* gunCam_walk [] I */ /* */ /*******************************/ fun gunCam_walk () = let gunsLib.(gunCam.index_GC).walk_GEL -> [sf ef] in gunCam_playloop sf ef ;; /*******************************/ /* gunCam_wait [] I */ /* */ /*******************************/ fun gunCam_wait () = let gunsLib.(gunCam.index_GC).wait_GEL -> [sf ef] in gunCam_playloop sf ef ;; /*******************************/ /* gunCam_show [I] I */ /* */ /*******************************/ fun gunCam_show (index) = set gunCam.index_GC = index; M3link session gunsLib.(index).ammoShellGunCam_GEL (ObGetMain owner); M3setObjVec session gunsLib.(index).ammoShellGunCam_GEL gunsLib.(index).ammoPos_GEL; if (gunsLib.(index).ammoShellGunCam2_GEL != nil) then ( M3link session gunsLib.(index).ammoShellGunCam2_GEL (ObGetMain owner); M3setObjVec session gunsLib.(index).ammoShellGunCam2_GEL gunsLib.(index).ammoPos2_GEL; ) else nil; let M3objName session M3getFirstSon session gunsLib.(index).shellGunCam_GEL -> myname in let if (myname == nil) then "NIL" else myname -> myname in M3link session gunsLib.(index).shellGunCam_GEL (ObGetMain owner); let gunsLib.(index).campos_GEL -> pos in let gunsLib.(index).camorient_GEL -> orient in let gunsLib.(index).camscale_GEL -> s in ( M3setObjVec session gunsLib.(index).shellGunCam_GEL pos; M3setObjAng session gunsLib.(index).shellGunCam_GEL orient; M3setObjScale session gunsLib.(index).shellGunCam_GEL s; ); 1 ;; /*******************************/ /* gunCam_hide [] I */ /* */ /*******************************/ fun gunCam_hide () = M3unLink session gunsLib.(gunCam.index_GC).shellGunCam_GEL; M3unLink session gunsLib.(gunCam.index_GC).ammoShellGunCam_GEL; if (gunsLib.(gunCam.index_GC).ammoShellGunCam2_GEL != nil) then M3unLink session gunsLib.(gunCam.index_GC).ammoShellGunCam2_GEL else nil; M3freeMemory session; 1 ;; /*******************************/ /* gunCam_start [Ob] I */ /* */ /* start the camera gun item */ /* o is the user instance */ /* */ /*******************************/ fun gunCam_start (o) = set gunCam = mkGunCam [ nil pbParams.gunCamFramerate_PBP 0 0 0 0 0 0 _tickcount ]; ObCbAnim o mkfun2 @gunCam_toolAnim gunCam; 1 ;; /*************************************************************************/ /* */ /* E X T E R N A L B O D Y GUNCAM MANAGER */ /* */ /*************************************************************************/ /******************************************************************************* Set parameter for the Animation Reload Gun index -> I : The index of the gun <- I *******************************************************************************/ fun gcm_load (index) = let gunsLib.(index).reload_GEL -> [sf ef] in set gcm.nbReloadFrames = ef - sf + 1; let gunsLib.(index).shoot_GEL -> [sf ef] in set gcm.nbShootFrames = ef - sf + 1; set gcm.shootTimeout = gunsLib.(index).timeout_GEL; set gcm.reloadTimeout = (gcm.nbReloadFrames * 1000) / gcm.frameRate; 1 ;; fun gcm_start () = set gcm = mkGunCamManager [0 0 0 0 0 0 nil 0 0 nil 0]; set gcm.frameRate = pbParams.gunCamFramerate_PBP; 1 ;; fun gunCam_load (index) = gcm_load index; gunCam_hide; gunCam_show index; 1 ;;