Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandAnimate.cpp 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*!
  2. * \file src/commands/CommandAnimate.cpp
  3. * \brief Animate command
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Log.h"
  9. #include "Game.h"
  10. #include "Render.h"
  11. #include "World.h"
  12. #include "commands/CommandAnimate.h"
  13. std::string CommandAnimate::name() {
  14. return "animate";
  15. }
  16. std::string CommandAnimate::brief() {
  17. return "[BOOL|n|p] - Animate models";
  18. }
  19. void CommandAnimate::printHelp() {
  20. getLog() << "animate-Command Usage:" << Log::endl;
  21. getLog() << " animate [n|p|BOOL]" << Log::endl;
  22. getLog() << "Where the commands have the following meaning:" << Log::endl;
  23. getLog() << " BOOL to (de)activate animating all models" << Log::endl;
  24. getLog() << " n to step all models to their next animation" << Log::endl;
  25. getLog() << " p to step all models to their previous animation" << Log::endl;
  26. }
  27. int CommandAnimate::execute(std::istream& args) {
  28. if (!getGame().isLoaded()) {
  29. getLog() << "Use animate command interactively!" << Log::endl;
  30. return -1;
  31. }
  32. if (args.peek() == 'n') {
  33. // Step all skeletal models to their next animation
  34. if (getRender().getFlags() & Render::fAnimateAllModels) {
  35. for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
  36. Entity& e = getWorld().getEntity(i);
  37. SkeletalModel& m = e.getModel();
  38. if (e.getAnimation() < (m.size() - 1))
  39. e.setAnimation(e.getAnimation() + 1);
  40. else
  41. e.setAnimation(0);
  42. }
  43. } else {
  44. getLog() << "Animations need to be enabled!" << Log::endl;
  45. }
  46. } else if (args.peek() == 'p') {
  47. // Step all skeletal models to their previous animation
  48. if (getRender().getFlags() & Render::fAnimateAllModels) {
  49. for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
  50. Entity& e = getWorld().getEntity(i);
  51. SkeletalModel& m = e.getModel();
  52. if (e.getAnimation() > 0)
  53. e.setAnimation(e.getAnimation() - 1);
  54. else if (m.size() > 0)
  55. e.setAnimation(m.size() - 1);
  56. }
  57. } else {
  58. getLog() << "Animations need to be enabled!" << Log::endl;
  59. }
  60. } else {
  61. // Enable or disable animating all skeletal models
  62. bool b = false;
  63. if (!(args >> b)) {
  64. getLog() << "Pass BOOL to animate command!" << Log::endl;
  65. return -2;
  66. }
  67. if (b)
  68. getRender().setFlags(Render::fAnimateAllModels);
  69. else
  70. getRender().clearFlags(Render::fAnimateAllModels);
  71. getLog() << (b ? "Animating all models" : "No longer animating all models") << Log::endl;
  72. }
  73. return 0;
  74. }