animloop.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "../idlib/precompiled.h"
  2. #pragma hdrstop
  3. #include "Game_local.h"
  4. const idEventDef EV_loopsetactive("loopsetactive", "d");
  5. const idEventDef EV_loopdone( "<loopdone>" );
  6. CLASS_DECLARATION( idAnimated, idAnimloop )
  7. EVENT( EV_loopdone, idAnimloop::Loopdone )
  8. EVENT( EV_loopsetactive, idAnimloop::loopsetactive )
  9. END_CLASS
  10. void idAnimloop::Save( idSaveGame *savefile ) const
  11. {
  12. savefile->WriteInt(blendFrames);
  13. savefile->WriteFloat(randomtime);
  14. savefile->WriteFloat(randomstart);
  15. savefile->WriteString(animName.c_str());
  16. savefile->WriteBool(active);
  17. }
  18. void idAnimloop::Restore( idRestoreGame *savefile )
  19. {
  20. savefile->ReadInt(blendFrames);
  21. savefile->ReadFloat(randomtime);
  22. savefile->ReadFloat(randomstart);
  23. savefile->ReadString(animName);
  24. savefile->ReadBool(active);
  25. }
  26. void idAnimloop::loopsetactive(int value)
  27. {
  28. active = value;
  29. }
  30. void idAnimloop::Loopdone( void )
  31. {
  32. if (!active)
  33. return;
  34. idAnimatedEntity::Event_PlayAnim(animName, blendFrames);
  35. int len = animator.CurrentAnim( ANIMCHANNEL_ALL )->PlayLength();
  36. if (randomtime > 0)
  37. {
  38. len -= gameLocal.random.RandomFloat() * randomtime;
  39. }
  40. PostEventMS( &EV_loopdone, len );
  41. }
  42. void idAnimloop::Spawn( void )
  43. {
  44. active = true;
  45. blendFrames = spawnArgs.GetInt("blendframes", "24");
  46. randomtime = spawnArgs.GetFloat("randomtime", "0");
  47. randomstart = spawnArgs.GetFloat("randomstart", "0");
  48. animName = spawnArgs.GetString("anim");
  49. if (randomstart > 0)
  50. {
  51. idAnimatedEntity::Event_PlayAnim(animName, blendFrames);
  52. PostEventSec( &EV_loopdone, randomstart );
  53. }
  54. else if (randomstart < 0)
  55. {
  56. //choose a random value.
  57. idAnimatedEntity::Event_PlayAnim(animName, blendFrames);
  58. float randValue = gameLocal.random.RandomFloat() * 3.1f;
  59. PostEventSec( &EV_loopdone, randValue );
  60. }
  61. else
  62. {
  63. Loopdone();
  64. }
  65. }