summaryrefslogtreecommitdiff
path: root/src/client/client.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2019-11-08 20:01:47 +0100
committersfan5 <sfan5@live.de>2019-11-09 16:08:38 +0100
commit82a2e02323615473fc3039508b4c4529591e27d9 (patch)
tree3d66f3bf530df8403cdf77199d15a1a9a3fea384 /src/client/client.cpp
parent5ab546f99bf3f438a8d19a3582798b5ab98476d6 (diff)
downloadminetest-82a2e02323615473fc3039508b4c4529591e27d9.tar.gz
minetest-82a2e02323615473fc3039508b4c4529591e27d9.tar.bz2
minetest-82a2e02323615473fc3039508b4c4529591e27d9.zip
Load client mods into memory before execution.
Preperation for server-sent CSM which will eventually need this.
Diffstat (limited to 'src/client/client.cpp')
-rw-r--r--src/client/client.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index caa3cc78c..3190641cf 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -200,14 +200,30 @@ void Client::scanModSubfolder(const std::string &mod_name, const std::string &mo
std::string full_path = mod_path + DIR_DELIM + mod_subpath;
std::vector<fs::DirListNode> mod = fs::GetDirListing(full_path);
for (const fs::DirListNode &j : mod) {
- std::string filename = j.name;
if (j.dir) {
- scanModSubfolder(mod_name, mod_path, mod_subpath
- + filename + DIR_DELIM);
+ scanModSubfolder(mod_name, mod_path, mod_subpath + j.name + DIR_DELIM);
continue;
}
- std::replace( mod_subpath.begin(), mod_subpath.end(), DIR_DELIM_CHAR, '/');
- m_mod_files[mod_name + ":" + mod_subpath + filename] = full_path + filename;
+ std::replace(mod_subpath.begin(), mod_subpath.end(), DIR_DELIM_CHAR, '/');
+
+ std::string real_path = full_path + j.name;
+ std::string vfs_path = mod_name + ":" + mod_subpath + j.name;
+ infostream << "Client::scanModSubfolder(): Loading \"" << real_path
+ << "\" as \"" << vfs_path << "\"." << std::endl;
+
+ std::ifstream is(real_path, std::ios::binary | std::ios::ate);
+ if(!is.good()) {
+ errorstream << "Client::scanModSubfolder(): Can't read file \""
+ << real_path << "\"." << std::endl;
+ continue;
+ }
+ auto size = is.tellg();
+ std::string contents(size, '\0');
+ is.seekg(0);
+ is.read(&contents[0], size);
+
+ infostream << " size: " << size << " bytes" << std::endl;
+ m_mod_vfs.emplace(vfs_path, contents);
}
}
@@ -1866,12 +1882,9 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename, bool cache)
const std::string* Client::getModFile(const std::string &filename)
{
- StringMap::const_iterator it = m_mod_files.find(filename);
- if (it == m_mod_files.end()) {
- errorstream << "Client::getModFile(): File not found: \"" << filename
- << "\"" << std::endl;
- return NULL;
- }
+ StringMap::const_iterator it = m_mod_vfs.find(filename);
+ if (it == m_mod_vfs.end())
+ return nullptr;
return &it->second;
}