CSEngine
Loading...
Searching...
No Matches
CSE::AssetMgr Class Reference

Classes

struct  AssetReference
 

Public Types

enum  TYPE {
  NONE , TEX_2D , TEX_CUBEMAP , FRAMEBUFFER ,
  MATERIAL , DAE , PREFAB , SCENE ,
  SCRIPT , TXT , SHADER , SHADER_HANDLE ,
  INI
}
 

Public Member Functions

void Exterminate ()
 
void LoadAssets (bool isPacked)
 
AssetReferenceGetAsset (const std::string &name) const
 
std::list< AssetMgr::AssetReference * > GetAssets (TYPE type) const
 

Static Public Member Functions

static std::string LoadAssetFile (const std::string &path)
 
static std::string GetAssetHash (const std::string &path)
 

Detailed Description

Definition at line 21 of file AssetMgr.h.

Member Enumeration Documentation

◆ TYPE

enum CSE::AssetMgr::TYPE

Definition at line 23 of file AssetMgr.h.

23 {
24 NONE, TEX_2D, TEX_CUBEMAP, FRAMEBUFFER, MATERIAL, DAE, PREFAB, SCENE, SCRIPT, TXT, SHADER, SHADER_HANDLE, INI
25 };

Constructor & Destructor Documentation

◆ ~AssetMgr()

AssetMgr::~AssetMgr ( )

Definition at line 38 of file AssetMgr.cpp.

38 {
39 Exterminate();
40}

Member Function Documentation

◆ Exterminate()

void AssetMgr::Exterminate ( )

Definition at line 43 of file AssetMgr.cpp.

43 {
44 m_assets.clear();
45
46 for (auto& asset: m_assetsList) {
47 SAFE_DELETE(asset);
48 }
49
50#ifdef __ANDROID__
51 SAFE_DELETE(m_assetManager);
52#endif
53
54 zip_close(m_zip);
55 m_assetsList.clear();
56}
void zip_close(struct zip_t *zip)
Definition zip.cpp:836

◆ GetAsset()

AssetMgr::AssetReference * AssetMgr::GetAsset ( const std::string & name) const

Definition at line 68 of file AssetMgr.cpp.

68 {
69 // Get an asset by hash
70 if (m_assets.count(name) > 0) return m_assets.at(name);
71
72 std::string lowerName = name;
73 make_lower(lowerName);
74 for (const auto& asset: m_assetsList) {
75 if (make_lower_copy(asset->name) == lowerName) return asset;
76 if (make_lower_copy(asset->id) == lowerName) return asset;
77 if (make_lower_copy(asset->name_path) == lowerName) return asset;
78 if (make_lower_copy(asset->name_full) == lowerName) return asset;
79 }
80 auto errorLog = "[Assets Warning] " + name + " does not exist.";
81 SafeLog::Log(errorLog.c_str());
82 return nullptr;
83}

◆ GetAssetHash()

std::string AssetMgr::GetAssetHash ( const std::string & path)
static

Definition at line 422 of file AssetMgr.cpp.

422 {
423 std::string meta = LoadAssetFile(path + ".meta");
424 std::string&& hash = "";
425 if (!meta.empty()) {
426 const XNode* root = XFILE().loadBuffer(std::move(meta));
427 const auto& hashData = root->getNode("hash-data");
428 hash = hashData.getAttribute("hash").value;
429 SAFE_DELETE(root);
430 } else {
431 hash = GetRandomHash(16);
432 std::string meta = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
433 "<CSEMETA version=\"1.0.0\">\n"
434 "<hash-data hash=\"" + hash + "\">\n"
435 "\n</hash-data>\n</CSEMETA>";
436 if (!Settings::IsAssetsPacked())
437 SaveTxtFile(path + ".meta", meta);
438 }
439 return hash;
440}
Definition XML.h:77
Definition XML.h:43

◆ GetAssets()

std::list< AssetMgr::AssetReference * > AssetMgr::GetAssets ( TYPE type) const

Definition at line 372 of file AssetMgr.cpp.

372 {
373 std::list<AssetReference*> result;
374
375 for (const auto& asset: m_assetsList) {
376 if (asset->type == type) {
377 result.push_back(asset);
378 }
379 }
380
381 return result;
382}

◆ LoadAssetFile()

std::string AssetMgr::LoadAssetFile ( const std::string & path)
static

Definition at line 384 of file AssetMgr.cpp.

384 {
385 if (Settings::IsAssetsPacked() == false)
386 return OpenNativeAssetsTxtFile(path);
387
388 std::string result;
389 std::string path_convert;
390 const auto& zip = CORE->GetResMgrCore()->m_assetManager->m_zip;
391 if (path.find("/../") != std::string::npos) {
392 auto path_split = split(path, '/');
393 std::stack<std::string> path_stack;
394 for (const auto& part: path_split) {
395 if (part == "..") {
396 path_stack.pop();
397 continue;
398 }
399 path_stack.push(part);
400 }
401 while (!path_stack.empty()) {
402 path_convert = path_stack.top() + '/' + path_convert;
403 path_stack.pop();
404 }
405 path_convert = path_convert.substr(0, path_convert.size() - 1);
406 } else {
407 path_convert = path;
408 }
409 zip_entry_open(zip, path_convert.c_str());
410 {
411 char* buf = nullptr;
412 size_t bufsize = 0;
413
414 zip_entry_read(zip, (void**) &buf, &bufsize);
415 result = std::string(buf, bufsize);
416 free(buf);
417 }
418 zip_entry_close(zip);
419 return result;
420}
int zip_entry_open(struct zip_t *zip, const char *entryname)
Definition zip.cpp:858
int zip_entry_close(struct zip_t *zip)
Definition zip.cpp:1087
ssize_t zip_entry_read(struct zip_t *zip, void **buf, size_t *bufsize)
Definition zip.cpp:1295

◆ LoadAssets()

void AssetMgr::LoadAssets ( bool isPacked)

Definition at line 58 of file AssetMgr.cpp.

58 {
59
60 if (!isPacked) {
61 ReadDirectory(CSE::NativeAssetsPath());
62 } else {
63 ReadPackage(CSE::NativeAssetsPath() + "Assets.zip");
64 }
65 SetType();
66}

The documentation for this class was generated from the following files: