summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-23 19:20:20 +0200
committerAki <please@ignore.pl>2022-05-23 19:20:20 +0200
commit82737f92d16d35ba1d526b9118c32c47af5936aa (patch)
treedf482fed761d7db0878887bc02d9eab22471f4d8
parent3e8ebf3133ece10efc8cf9219dafc02e780bc3ab (diff)
downloadderelict-82737f92d16d35ba1d526b9118c32c47af5936aa.zip
derelict-82737f92d16d35ba1d526b9118c32c47af5936aa.tar.gz
derelict-82737f92d16d35ba1d526b9118c32c47af5936aa.tar.bz2
Icons are now cached by filename
-rw-r--r--Icons.cpp15
-rw-r--r--Icons.h3
2 files changed, 9 insertions, 9 deletions
diff --git a/Icons.cpp b/Icons.cpp
index 7b90ae0..cb50740 100644
--- a/Icons.cpp
+++ b/Icons.cpp
@@ -76,18 +76,17 @@ Icons::reset()
Texture2D
Icons::find(const long int type)
{
- const auto existing = m_cache.find(type);
+ const auto search = FILENAMES.find(type);
+ std::string filename = "resources/wreck.png";
+ if (search != FILENAMES.end())
+ filename = search->second;
+ const auto existing = m_cache.find(filename);
if (existing != m_cache.end()) {
return existing->second;
}
else {
- Texture2D texture;
- const auto filename = FILENAMES.find(type);
- if (filename != FILENAMES.end())
- texture = LoadTexture(filename->second.data());
- else
- texture = LoadTexture("resources/wreck.png");
- m_cache[type] = texture;
+ auto texture = LoadTexture(filename.data());
+ m_cache[filename] = texture;
return texture;
}
}
diff --git a/Icons.h b/Icons.h
index 367d9aa..3acc8cf 100644
--- a/Icons.h
+++ b/Icons.h
@@ -1,5 +1,6 @@
#pragma once
+#include <string>
#include <unordered_map>
#include <raylib.h>
@@ -13,5 +14,5 @@ public:
void reset();
Texture2D find(long int type);
private:
- std::unordered_map<long int, Texture2D> m_cache;
+ std::unordered_map<std::string, Texture2D> m_cache;
};