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 19 of file AssetMgr.h.

Member Enumeration Documentation

◆ TYPE

enum CSE::AssetMgr::TYPE

Definition at line 21 of file AssetMgr.h.

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

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
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 375 of file AssetMgr.cpp.

375 {
376 std::string meta = LoadAssetFile(path + ".meta");
377 std::string&& hash = "";
378 if (!meta.empty()) {
379 const XNode* root = XFILE().loadBuffer(std::move(meta));
380 const auto& hashData = root->getNode("hash-data");
381 hash = hashData.getAttribute("hash").value;
382 SAFE_DELETE(root);
383 } else {
384 hash = GetRandomHash(16);
385 std::string meta = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
386 "<CSEMETA version=\"1.0.0\">\n"
387 "<hash-data hash=\"" + hash + "\">\n"
388 "\n</hash-data>\n</CSEMETA>";
389 if (!Settings::IsAssetsPacked())
390 SaveTxtFile(path + ".meta", meta);
391 }
392 return hash;
393}
Definition XML.h:77
Definition XML.h:43

◆ GetAssets()

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

Definition at line 324 of file AssetMgr.cpp.

324 {
325 std::list<AssetReference*> result;
326
327 for (const auto& asset : m_assetsList) {
328 if (asset->type == type) {
329 result.push_back(asset);
330 }
331 }
332
333 return result;
334}

◆ LoadAssetFile()

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

Definition at line 336 of file AssetMgr.cpp.

336 {
337 if (Settings::IsAssetsPacked() == false)
338 return OpenNativeAssetsTxtFile(path);
339
340 std::string result;
341 std::string path_convert;
342 const auto& zip = CORE->GetResMgrCore()->m_assetManager->m_zip;
343 if (path.find("/../") != std::string::npos) {
344 auto path_split = split(path, '/');
345 std::stack<std::string> path_stack;
346 for (const auto& part : path_split) {
347 if (part == "..") {
348 path_stack.pop();
349 continue;
350 }
351 path_stack.push(part);
352 }
353 while (!path_stack.empty()) {
354 path_convert = path_stack.top() + '/' + path_convert;
355 path_stack.pop();
356 }
357 path_convert = path_convert.substr(0, path_convert.size() - 1);
358 }
359 else {
360 path_convert = path;
361 }
362 zip_entry_open(zip, path_convert.c_str());
363 {
364 char* buf = nullptr;
365 size_t bufsize = 0;
366
367 zip_entry_read(zip, (void**) &buf, &bufsize);
368 result = std::string(buf, bufsize);
369 free(buf);
370 }
371 zip_entry_close(zip);
372 return result;
373}
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: