Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CommandAnimate.cpp 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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
  55. if (m.size() > 0)
  56. e.setAnimation(m.size() - 1);
  57. }
  58. } else {
  59. getLog() << "Animations need to be enabled!" << Log::endl;
  60. }
  61. } else {
  62. // Enable or disable animating all skeletal models
  63. bool b = false;
  64. if (!(args >> b)) {
  65. getLog() << "Pass BOOL to animate command!" << Log::endl;
  66. return -2;
  67. }
  68. if (b)
  69. getRender().setFlags(Render::fAnimateAllModels);
  70. else
  71. getRender().clearFlags(Render::fAnimateAllModels);
  72. getLog() << (b ? "Animating all models" : "No longer animating all models") << Log::endl;
  73. }
  74. return 0;
  75. }