summaryrefslogtreecommitdiffstats
path: root/core/binfile.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-06-29 22:24:42 +0500
committeruntodesu <kirill@untode.su>2025-06-29 22:24:42 +0500
commit6cd00aacfa22fed6a54a9b812f6b069ad16feec0 (patch)
treeb77f4e665da3dd235cdb01e7e6ea78c1c02ecf2e /core/binfile.cc
parentf440914e1ae453768d09383f332bc7844e0a700e (diff)
downloadvoxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.tar.bz2
voxelius-6cd00aacfa22fed6a54a9b812f6b069ad16feec0.zip
Move game sources into src subdirectory
Diffstat (limited to 'core/binfile.cc')
-rw-r--r--core/binfile.cc70
1 files changed, 0 insertions, 70 deletions
diff --git a/core/binfile.cc b/core/binfile.cc
deleted file mode 100644
index aa39039..0000000
--- a/core/binfile.cc
+++ /dev/null
@@ -1,70 +0,0 @@
-#include "core/pch.hh"
-
-#include "core/binfile.hh"
-
-#include "core/resource.hh"
-
-static emhash8::HashMap<std::string, resource_ptr<BinFile>> resource_map;
-
-template<>
-resource_ptr<BinFile> resource::load<BinFile>(const char* name, unsigned int flags)
-{
- auto it = resource_map.find(name);
-
- if(it != resource_map.cend()) {
- // Return an existing resource
- return it->second;
- }
-
- auto file = PHYSFS_openRead(name);
-
- if(file == nullptr) {
- spdlog::warn("resource: {}: {}", name, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
- return nullptr;
- }
-
- auto new_resource = std::make_shared<BinFile>();
- new_resource->size = PHYSFS_fileLength(file);
- new_resource->buffer = new std::byte[new_resource->size];
-
- PHYSFS_readBytes(file, new_resource->buffer, new_resource->size);
- PHYSFS_close(file);
-
- return resource_map.insert_or_assign(name, new_resource).first->second;
-}
-
-template<>
-void resource::hard_cleanup<BinFile>(void)
-{
- for(const auto& it : resource_map) {
- if(it.second.use_count() > 1L) {
- spdlog::warn("resource: zombie resource [BinFile] {} [use_count={}]", it.first, it.second.use_count());
- } else {
- spdlog::debug("resource: releasing [BinFile] {}", it.first);
- }
-
- delete[] it.second->buffer;
- }
-
- resource_map.clear();
-}
-
-template<>
-void resource::soft_cleanup<BinFile>(void)
-{
- auto iter = resource_map.cbegin();
-
- while(iter != resource_map.cend()) {
- if(iter->second.use_count() == 1L) {
- spdlog::debug("resource: releasing [BinFile] {}", iter->first);
-
- delete[] iter->second->buffer;
-
- iter = resource_map.erase(iter);
-
- continue;
- }
-
- iter = std::next(iter);
- }
-}