| 1 | // SuperTux |
| 2 | // Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com> |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | #ifndef HEADER_SUPERTUX_SQUIRREL_SQUIRREL_VIRTUAL_MACHINE_HPP |
| 18 | #define |
| 19 | |
| 20 | #include <memory> |
| 21 | |
| 22 | #include <squirrel.h> |
| 23 | |
| 24 | #include "squirrel/squirrel_vm.hpp" |
| 25 | #include "util/currenton.hpp" |
| 26 | |
| 27 | class SquirrelThreadQueue; |
| 28 | class SquirrelScheduler; |
| 29 | |
| 30 | class SquirrelVirtualMachine final : public Currenton<SquirrelVirtualMachine> |
| 31 | { |
| 32 | public: |
| 33 | SquirrelVirtualMachine(bool enable_debugger); |
| 34 | ~SquirrelVirtualMachine(); |
| 35 | |
| 36 | SquirrelVM& get_vm() { return m_vm; } |
| 37 | |
| 38 | void wait_for_seconds(HSQUIRRELVM vm, float seconds); |
| 39 | void update(float dt_sec); |
| 40 | |
| 41 | /** adds thread waiting for a screen switch event */ |
| 42 | void wait_for_screenswitch(HSQUIRRELVM vm); |
| 43 | |
| 44 | /** wakes up threads waiting for a screen switch event */ |
| 45 | void wakeup_screenswitch(); |
| 46 | |
| 47 | private: |
| 48 | void update_debugger(); |
| 49 | |
| 50 | private: |
| 51 | SquirrelVM m_vm; |
| 52 | |
| 53 | std::unique_ptr<SquirrelThreadQueue> m_screenswitch_queue; |
| 54 | std::unique_ptr<SquirrelScheduler> m_scheduler; |
| 55 | |
| 56 | private: |
| 57 | SquirrelVirtualMachine(const SquirrelVirtualMachine&) = delete; |
| 58 | SquirrelVirtualMachine& operator=(const SquirrelVirtualMachine&) = delete; |
| 59 | }; |
| 60 | |
| 61 | #endif |
| 62 | |
| 63 | /* EOF */ |
| 64 | |