quicktune.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. /*
  17. Used for tuning constants when developing.
  18. Eg. if you have this constant somewhere that you just can't get right
  19. by changing it and recompiling all over again:
  20. v3f wield_position = v3f(55, -35, 65);
  21. Make it look like this:
  22. v3f wield_position = v3f(55, -35, 65);
  23. QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.X, 0, 100);
  24. QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Y, -80, 20);
  25. QUICKTUNE_AUTONAME(QVT_FLOAT, wield_position.Z, 0, 100);
  26. Then you can modify the values at runtime, using the keys
  27. keymap_quicktune_prev
  28. keymap_quicktune_next
  29. keymap_quicktune_dec
  30. keymap_quicktune_inc
  31. Once you have modified the values at runtime and then quit, the game
  32. will print out all the modified values at the end:
  33. Modified quicktune values:
  34. wield_position.X = 60
  35. wield_position.Y = -30
  36. wield_position.Z = 65
  37. The QUICKTUNE macros shouldn't generally be left in committed code.
  38. */
  39. #pragma once
  40. #include <string>
  41. #include <map>
  42. #include <vector>
  43. enum QuicktuneValueType{
  44. QVT_NONE,
  45. QVT_FLOAT
  46. };
  47. struct QuicktuneValue
  48. {
  49. QuicktuneValueType type = QVT_NONE;
  50. union{
  51. struct{
  52. float current;
  53. float min;
  54. float max;
  55. } value_QVT_FLOAT;
  56. };
  57. bool modified = false;
  58. QuicktuneValue() = default;
  59. std::string getString();
  60. void relativeAdd(float amount);
  61. };
  62. std::vector<std::string> getQuicktuneNames();
  63. QuicktuneValue getQuicktuneValue(const std::string &name);
  64. void setQuicktuneValue(const std::string &name, const QuicktuneValue &val);
  65. void updateQuicktuneValue(const std::string &name, QuicktuneValue &val);
  66. #ifndef NDEBUG
  67. #define QUICKTUNE(type_, var, min_, max_, name){\
  68. QuicktuneValue qv;\
  69. qv.type = type_;\
  70. qv.value_##type_.current = var;\
  71. qv.value_##type_.min = min_;\
  72. qv.value_##type_.max = max_;\
  73. updateQuicktuneValue(name, qv);\
  74. var = qv.value_##type_.current;\
  75. }
  76. #else // NDEBUG
  77. #define QUICKTUNE(type, var, min_, max_, name){}
  78. #endif
  79. #define QUICKTUNE_AUTONAME(type_, var, min_, max_)\
  80. QUICKTUNE(type_, var, min_, max_, #var)