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.9KB

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