1 /* 2 game.h 3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com> 4 */ 5 6 /* 7 This file is part of Freeminer. 8 9 Freeminer is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Freeminer is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Freeminer. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef GAME_HEADER 24 #define GAME_HEADER 25 26 #include "irrlichttypes_extrabloated.h" 27 #include <string> 28 #include "keycode.h" 29 #include <list> 30 31 class KeyList : protected std::list<KeyPress> 32 { 33 typedef std::list<KeyPress> super; 34 typedef super::iterator iterator; 35 typedef super::const_iterator const_iterator; 36 find(const KeyPress & key)37 virtual const_iterator find(const KeyPress &key) const 38 { 39 const_iterator f(begin()); 40 const_iterator e(end()); 41 42 while (f != e) { 43 if (*f == key) 44 return f; 45 46 ++f; 47 } 48 49 return e; 50 } 51 find(const KeyPress & key)52 virtual iterator find(const KeyPress &key) 53 { 54 iterator f(begin()); 55 iterator e(end()); 56 57 while (f != e) { 58 if (*f == key) 59 return f; 60 61 ++f; 62 } 63 64 return e; 65 } 66 67 public: clear()68 void clear() 69 { 70 super::clear(); 71 } 72 set(const KeyPress & key)73 void set(const KeyPress &key) 74 { 75 if (find(key) == end()) 76 push_back(key); 77 } 78 unset(const KeyPress & key)79 void unset(const KeyPress &key) 80 { 81 iterator p(find(key)); 82 83 if (p != end()) 84 erase(p); 85 } 86 toggle(const KeyPress & key)87 void toggle(const KeyPress &key) 88 { 89 iterator p(this->find(key)); 90 91 if (p != end()) 92 erase(p); 93 else 94 push_back(key); 95 } 96 97 bool operator[](const KeyPress &key) const 98 { 99 return find(key) != end(); 100 } 101 }; 102 103 class InputHandler 104 { 105 public: InputHandler()106 InputHandler() 107 { 108 } ~InputHandler()109 virtual ~InputHandler() 110 { 111 } 112 113 virtual bool isKeyDown(const KeyPress &keyCode) = 0; 114 virtual bool wasKeyDown(const KeyPress &keyCode) = 0; 115 116 virtual v2s32 getMousePos() = 0; 117 virtual void setMousePos(s32 x, s32 y) = 0; 118 119 virtual bool getLeftState() = 0; 120 virtual bool getRightState() = 0; 121 122 virtual bool getLeftClicked() = 0; 123 virtual bool getRightClicked() = 0; 124 virtual void resetLeftClicked() = 0; 125 virtual void resetRightClicked() = 0; 126 127 virtual bool getLeftReleased() = 0; 128 virtual bool getRightReleased() = 0; 129 virtual void resetLeftReleased() = 0; 130 virtual void resetRightReleased() = 0; 131 132 virtual s32 getMouseWheel() = 0; 133 step(float dtime)134 virtual void step(float dtime) {} 135 clear()136 virtual void clear() {} 137 }; 138 139 class ChatBackend; /* to avoid having to include chat.h */ 140 struct SubgameSpec; 141 142 bool the_game(bool *kill, 143 bool random_input, 144 InputHandler *input, 145 IrrlichtDevice *device, 146 gui::IGUIFont *font, 147 const std::string &map_dir, 148 const std::string &playername, 149 const std::string &password, 150 const std::string &address, // If "", local server is used 151 u16 port, 152 std::wstring &error_message, 153 ChatBackend &chat_backend, 154 const SubgameSpec &gamespec, // Used for local game 155 bool simple_singleplayer_mode, 156 unsigned int autoexit 157 ); 158 159 #endif 160 161