game.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef GAME_HEADER
  17. #define GAME_HEADER
  18. #include "irrlichttypes_extrabloated.h"
  19. #include <string>
  20. #include "keycode.h"
  21. #include <list>
  22. class KeyList : protected std::list<KeyPress>
  23. {
  24. typedef std::list<KeyPress> super;
  25. typedef super::iterator iterator;
  26. typedef super::const_iterator const_iterator;
  27. virtual const_iterator find(const KeyPress &key) const
  28. {
  29. const_iterator f(begin());
  30. const_iterator e(end());
  31. while (f!=e) {
  32. if (*f == key)
  33. return f;
  34. ++f;
  35. }
  36. return e;
  37. }
  38. virtual iterator find(const KeyPress &key)
  39. {
  40. iterator f(begin());
  41. iterator e(end());
  42. while (f!=e) {
  43. if (*f == key)
  44. return f;
  45. ++f;
  46. }
  47. return e;
  48. }
  49. public:
  50. void clear() { super::clear(); }
  51. void set(const KeyPress &key)
  52. {
  53. if (find(key) == end())
  54. push_back(key);
  55. }
  56. void unset(const KeyPress &key)
  57. {
  58. iterator p(find(key));
  59. if (p != end())
  60. erase(p);
  61. }
  62. void toggle(const KeyPress &key)
  63. {
  64. iterator p(this->find(key));
  65. if (p != end())
  66. erase(p);
  67. else
  68. push_back(key);
  69. }
  70. bool operator[](const KeyPress &key) const
  71. {
  72. return find(key) != end();
  73. }
  74. };
  75. class InputHandler
  76. {
  77. public:
  78. InputHandler()
  79. {
  80. }
  81. virtual ~InputHandler()
  82. {
  83. }
  84. virtual bool isKeyDown(const KeyPress &keyCode) = 0;
  85. virtual bool wasKeyDown(const KeyPress &keyCode) = 0;
  86. virtual v2s32 getMousePos() = 0;
  87. virtual void setMousePos(s32 x, s32 y) = 0;
  88. virtual bool getLeftState() = 0;
  89. virtual bool getRightState() = 0;
  90. virtual bool getLeftClicked() = 0;
  91. virtual bool getRightClicked() = 0;
  92. virtual void resetLeftClicked() = 0;
  93. virtual void resetRightClicked() = 0;
  94. virtual bool getLeftReleased() = 0;
  95. virtual bool getRightReleased() = 0;
  96. virtual void resetLeftReleased() = 0;
  97. virtual void resetRightReleased() = 0;
  98. virtual s32 getMouseWheel() = 0;
  99. virtual void step(float dtime) {};
  100. virtual void clear() {};
  101. };
  102. class ChatBackend; /* to avoid having to include chat.h */
  103. struct SubgameSpec;
  104. void the_game(
  105. bool &kill,
  106. bool random_input,
  107. InputHandler *input,
  108. IrrlichtDevice *device,
  109. gui::IGUIFont* font,
  110. std::string map_dir,
  111. std::string playername,
  112. std::string password,
  113. std::string address, // If "", local server is used
  114. u16 port,
  115. std::wstring &error_message,
  116. ChatBackend &chat_backend,
  117. const SubgameSpec &gamespec, // Used for local game
  118. bool simple_singleplayer_mode
  119. );
  120. #endif