Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
TilesetCache.cpp
Go to the documentation of this file.
1/*
2 * TilesetCache.cpp - Implementation of tileset cache
3 */
4
5#include "../include/TilesetCache.h"
6#include "../include/TilesetParser.h"
7#include "../../system/system_utils.h"
8
9namespace Olympe {
10namespace Tiled {
11
17
18 std::shared_ptr<TiledTileset> TilesetCache::GetTileset(const std::string& filepath)
19 {
20 std::lock_guard<std::mutex> lock(mutex_);
21
22 // Check if already cached
23 auto it = cache_.find(filepath);
24 if (it != cache_.end()) {
25 return it->second;
26 }
27
28 // Not cached, load it
29 SYSTEM_LOG << "TilesetCache: Loading tileset from " << filepath << "\n";
30
31 auto tileset = std::make_shared<TiledTileset>();
33
34 if (!parser.ParseFile(filepath, *tileset)) {
35 SYSTEM_LOG << "TilesetCache: Failed to load tileset from " << filepath << "\n";
36 return nullptr;
37 }
38
39 // Add to cache
40 cache_[filepath] = tileset;
41 return tileset;
42 }
43
44 void TilesetCache::AddTileset(const std::string& filepath, std::shared_ptr<TiledTileset> tileset)
45 {
46 std::lock_guard<std::mutex> lock(mutex_);
47 cache_[filepath] = tileset;
48 }
49
51 {
52 std::lock_guard<std::mutex> lock(mutex_);
53 cache_.clear();
54 SYSTEM_LOG << "TilesetCache: Cleared all cached tilesets" << std::endl;
55 }
56
57 bool TilesetCache::HasTileset(const std::string& filepath) const
58 {
59 std::lock_guard<std::mutex> lock(mutex_);
60 return cache_.find(filepath) != cache_.end();
61 }
62
63} // namespace Tiled
64} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::map< std::string, std::shared_ptr< TiledTileset > > cache_
std::shared_ptr< TiledTileset > GetTileset(const std::string &filepath)
void AddTileset(const std::string &filepath, std::shared_ptr< TiledTileset > tileset)
bool HasTileset(const std::string &filepath) const
static TilesetCache & GetInstance()
#define SYSTEM_LOG