1 /***************************************************************************** 2 * Copyright (c) 2014-2020 OpenRCT2 developers 3 * 4 * For a complete list of all authors, please refer to contributors.md 5 * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 6 * 7 * OpenRCT2 is licensed under the GNU General Public License version 3. 8 *****************************************************************************/ 9 10 #pragma once 11 12 #include "Date.h" 13 14 #include <array> 15 #include <chrono> 16 #include <memory> 17 #include <unordered_map> 18 19 namespace OpenRCT2 20 { 21 class Park; 22 23 // Information regarding various pieces of logic update 24 enum class LogicTimePart 25 { 26 NetworkUpdate, 27 Date, 28 Scenario, 29 Climate, 30 MapTiles, 31 MapStashProvisionalElements, 32 MapPathWideFlags, 33 Peep, 34 MapRestoreProvisionalElements, 35 Vehicle, 36 Misc, 37 Ride, 38 Park, 39 Research, 40 RideRatings, 41 RideMeasurments, 42 News, 43 MapAnimation, 44 Sounds, 45 GameActions, 46 NetworkFlush, 47 Scripts, 48 }; 49 50 // ~6.5s at 40Hz 51 constexpr size_t LOGIC_UPDATE_MEASUREMENTS_COUNT = 256; 52 53 // In order not to cause allocations, collect multiple samples into single pre-allocated struct 54 using LogicTimingInfo = std::unordered_map< 55 LogicTimePart, std::array<std::chrono::duration<double>, LOGIC_UPDATE_MEASUREMENTS_COUNT>>; 56 57 struct LogicTimings 58 { 59 LogicTimingInfo TimingInfo; 60 size_t CurrentIdx{}; 61 }; 62 63 /** 64 * Class to update the state of the map and park. 65 */ 66 class GameState final 67 { 68 private: 69 std::unique_ptr<Park> _park; 70 Date _date; 71 72 public: 73 GameState(); 74 GameState(const GameState&) = delete; 75 GetDate()76 Date& GetDate() 77 { 78 return _date; 79 } GetPark()80 Park& GetPark() 81 { 82 return *_park; 83 } 84 85 void InitAll(int32_t mapSize); 86 void Update(); 87 void UpdateLogic(LogicTimings* timings = nullptr); 88 89 private: 90 void CreateStateSnapshot(); 91 }; 92 } // namespace OpenRCT2 93