| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2020 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D 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 | // Dust Racing 2D 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 General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #ifndef DATABASE_HPP |
| 17 | #define DATABASE_HPP |
| 18 | |
| 19 | #include "difficultyprofile.hpp" |
| 20 | |
| 21 | #include <map> |
| 22 | #include <mutex> |
| 23 | |
| 24 | class Track; |
| 25 | |
| 26 | class Database |
| 27 | { |
| 28 | public: |
| 29 | Database(); |
| 30 | |
| 31 | void saveLapRecord(const Track & track, int msecs); |
| 32 | |
| 33 | std::pair<int, bool> loadLapRecord(const Track & track) const; |
| 34 | |
| 35 | void resetLapRecords(); |
| 36 | |
| 37 | void saveRaceRecord(const Track & track, int msecs, int lapCount, DifficultyProfile::Difficulty difficulty); |
| 38 | |
| 39 | std::pair<int, bool> loadRaceRecord(const Track & track, int lapCount, DifficultyProfile::Difficulty difficulty) const; |
| 40 | |
| 41 | void resetRaceRecords(); |
| 42 | |
| 43 | void saveBestPos(const Track & track, int pos, int lapCount, DifficultyProfile::Difficulty difficulty); |
| 44 | |
| 45 | std::pair<int, bool> loadBestPos(const Track & track, int lapCount, DifficultyProfile::Difficulty difficulty) const; |
| 46 | |
| 47 | void resetBestPos(); |
| 48 | |
| 49 | void saveTrackUnlockStatus(const Track & track, int lapCount, DifficultyProfile::Difficulty difficulty); |
| 50 | |
| 51 | bool loadTrackUnlockStatus(const Track & track, int lapCount, DifficultyProfile::Difficulty difficulty) const; |
| 52 | |
| 53 | void resetTrackUnlockStatuses(); |
| 54 | |
| 55 | static Database & instance(); |
| 56 | |
| 57 | private: |
| 58 | void initialize(); |
| 59 | |
| 60 | static Database * m_instance; |
| 61 | |
| 62 | mutable std::mutex m_mutex; |
| 63 | }; |
| 64 | |
| 65 | #endif // DATABASE_HPP |