1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus 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  * Solarus 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 along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef SOLARUS_RESOURCE_PROVIDER_H
18 #define SOLARUS_RESOURCE_PROVIDER_H
19 
20 #include "solarus/core/Common.h"
21 #include "solarus/core/ResourceType.h"
22 #include "solarus/entities/Tileset.h"
23 #include "solarus/entities/TilePattern.h"
24 #include <map>
25 #include <memory>
26 #include <thread>
27 #include <string>
28 
29 namespace Solarus {
30 
31 /**
32  * \brief Provides fast access to quest resources.
33  *
34  * Maintains a cache of already loaded quest resources
35  * so that next accesses are faster.
36  */
37 class SOLARUS_API ResourceProvider {
38 
39   public:
40 
41     ResourceProvider();
42     void clear();
43 
44     Tileset& get_tileset(const std::string& tileset_id);
45     const std::map<std::string, std::shared_ptr<Tileset>>& get_loaded_tilesets();
46 
47     // TODO other types of resources
48     // TODO clear/update when the resource list changes dynamically
49 
50     void invalidate_resource_element(ResourceType resource_type, const std::string& element_id);
51 
52     void start_preloading_resources();
53 
54   private:
55 
56     std::thread preloader_thread;  /**< Thread that loads resources in background. */
57     std::map<std::string, std::shared_ptr<Tileset>>
58         tileset_cache;             /**< Cache of loaded tilesets. */
59 };
60 
61 }
62 
63 #endif
64 
65