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.

CommandEngine.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*!
  2. * \file src/commands/CommandEngine.cpp
  3. * \brief Engine commands
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "Game.h"
  9. #include "Log.h"
  10. #include "Menu.h"
  11. #include "RunTime.h"
  12. #include "Render.h"
  13. #include "UI.h"
  14. #include "commands/CommandEngine.h"
  15. std::string CommandLoad::name() {
  16. return "load";
  17. }
  18. std::string CommandLoad::brief() {
  19. return "load a level file";
  20. }
  21. void CommandLoad::printHelp() {
  22. getLog() << "load-Command Usage:" << Log::endl;
  23. getLog() << " load /path/to/level" << Log::endl;
  24. }
  25. int CommandLoad::execute(std::istream& args) {
  26. if (!getRunTime().isRunning()) {
  27. getLog() << "Use load command interactively!" << Log::endl;
  28. return -1;
  29. }
  30. std::string map;
  31. args >> map;
  32. int error = getGame().loadLevel(map.c_str());
  33. return error;
  34. }
  35. // --------------------------------------
  36. std::string CommandScreenshot::name() {
  37. return "sshot";
  38. }
  39. std::string CommandScreenshot::brief() {
  40. return "make a screenshot";
  41. }
  42. void CommandScreenshot::printHelp() {
  43. getLog() << "sshot-Command Usage:" << Log::endl;
  44. getLog() << " sshot [debug|menu] [debug|menu]" << Log::endl;
  45. getLog() << "Add console/menu to capture them too" << Log::endl;
  46. }
  47. int CommandScreenshot::execute(std::istream& args) {
  48. if (!getRunTime().isRunning()) {
  49. getLog() << "Use sshot command interactively!" << Log::endl;
  50. return -1;
  51. }
  52. std::string filename(getRunTime().getBaseDir());
  53. filename += "/sshots/";
  54. filename += VERSION_SHORT;
  55. std::string temp, temp2;
  56. args >> temp >> temp2;
  57. UI::setVisible(false);
  58. getMenu().setVisible(false);
  59. if (temp == "debug")
  60. UI::setVisible(true);
  61. else if (temp == "menu")
  62. getMenu().setVisible(true);
  63. if (temp2 == "debug")
  64. UI::setVisible(true);
  65. else if (temp2 == "menu")
  66. getMenu().setVisible(true);
  67. renderFrame();
  68. renderFrame(); // Double buffered
  69. getRender().screenShot(filename.c_str());
  70. getMenu().setVisible(false);
  71. UI::setVisible(true);
  72. getLog() << "Screenshot stored..." << Log::endl;
  73. return 0;
  74. }
  75. // --------------------------------------
  76. std::string CommandQuit::name() {
  77. return "quit";
  78. }
  79. std::string CommandQuit::brief() {
  80. return "exit OpenRaider";
  81. }
  82. int CommandQuit::execute(std::istream& args) {
  83. exit(0);
  84. return 0;
  85. }