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.

RunTime.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*!
  2. * \file src/RunTime.cpp
  3. * \brief run time configuration storage
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "utils/strings.h"
  9. #include "utils/time.h"
  10. #include "RunTime.h"
  11. RunTime::RunTime()
  12. : baseDir(expandHomeDirectory("~/.OpenRaider")) {
  13. pakDir = baseDir + "/paks";
  14. audioDir = baseDir + "/music";
  15. dataDir = baseDir + "/data";
  16. gameIsRunning = false;
  17. #ifdef DEBUG
  18. showFPS = true;
  19. #else
  20. showFPS = false;
  21. #endif
  22. for (int i = 0; i < ActionEventCount; i++)
  23. keyBindings[i] = unknownKey;
  24. // Default key bindings
  25. keyBindings[menuAction] = escapeKey;
  26. keyBindings[debugAction] = qKey;
  27. keyBindings[forwardAction] = wKey;
  28. keyBindings[backwardAction] = sKey;
  29. keyBindings[leftAction] = aKey;
  30. keyBindings[rightAction] = dKey;
  31. lastTime = 0;
  32. frameCount = 0;
  33. frameCount2 = 0;
  34. frameTimeSum = 0;
  35. frameTimeSum2 = 0;
  36. fps = 0;
  37. }
  38. std::string RunTime::getBaseDir() {
  39. return baseDir;
  40. }
  41. void RunTime::setBaseDir(std::string dir) {
  42. baseDir = dir;
  43. }
  44. std::string RunTime::getPakDir() {
  45. return pakDir;
  46. }
  47. void RunTime::setPakDir(std::string dir) {
  48. pakDir = dir;
  49. }
  50. std::string RunTime::getAudioDir() {
  51. return audioDir;
  52. }
  53. void RunTime::setAudioDir(std::string dir) {
  54. audioDir = dir;
  55. }
  56. std::string RunTime::getDataDir() {
  57. return dataDir;
  58. }
  59. void RunTime::setDataDir(std::string dir) {
  60. dataDir = dir;
  61. }
  62. KeyboardButton RunTime::getKeyBinding(ActionEvents event) {
  63. assert(event < ActionEventCount);
  64. return keyBindings[event];
  65. }
  66. void RunTime::setKeyBinding(ActionEvents event, KeyboardButton button) {
  67. assert(event < ActionEventCount);
  68. keyBindings[event] = button;
  69. }
  70. bool RunTime::isRunning() {
  71. return gameIsRunning;
  72. }
  73. void RunTime::setRunning(bool run) {
  74. gameIsRunning = run;
  75. }
  76. bool RunTime::getShowFPS() {
  77. return showFPS;
  78. }
  79. void RunTime::setShowFPS(bool fps) {
  80. showFPS = fps;
  81. }
  82. void RunTime::updateFPS() {
  83. frameCount++;
  84. frameTimeSum += (systemTimerGet() - lastTime);
  85. frameTimeSum2 += (systemTimerGet() - lastTime);
  86. lastTime = systemTimerGet();
  87. if (frameTimeSum >= 200) {
  88. fps = frameCount * (1000 / frameTimeSum);
  89. frameCount = frameTimeSum = 0;
  90. }
  91. if (frameTimeSum2 >= 1000) {
  92. history.push_back(frameCount2);
  93. frameCount2 = frameTimeSum2 = 0;
  94. }
  95. frameCount2++;
  96. }
  97. unsigned long RunTime::getFPS() {
  98. return fps;
  99. }
  100. const std::vector<float>& RunTime::getHistoryFPS() {
  101. return history;
  102. }