Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
ResourceManager.cpp
1 /*
2  Harmonic Flow Framework
3  Copyright (C) 2011-2018 Andreas Widen <andreas@harmonicflow.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "ResourceManager.h"
22 
23 #include <algorithm>
24 
25 #include "platform/Environment.h"
26 #include "platform/FileDirUtils.h"
28 #include "platform/Sound.h"
29 #include "platform/Image.h"
30 
31 #include "font/HFBMFontXML.h"
32 #include "font/HFBMFontBIN.h"
33 #include "font/HFBMFontTXT.h"
34 
35 #include "crypto/Crypto.h"
36 #include "atlas/HFTexPackImageAtlasBIN.h"
37 #include "atlas/HFTexPackImageAtlasTXT.h"
38 #include "atlas/HFTexPackImageAtlasXML.h"
39 #include "resource/Resource.h"
40 #include "resource/ResourceGroup.h"
41 #include "unicode/UStringStream.h"
42 #include <fstream>
43 #include <string>
44 
45 using namespace HFCore;
46 
47 #include "debug/CrtDbgNew.h"
48 
50  const std::string &language)
51 {
52  mLanguage = language;
53 
54  std::string filePath = "data/strings_";
55  filePath.append(mLanguage);
56  filePath.append(".xml");
57 
58  const int8_hf *fullFilePath = NULL;
59  if (HFCORE_ENV->getPakDataFileName().length() > 0)
60  fullFilePath = (const int8_hf *)filePath.c_str();
61  else
62  fullFilePath = HFCORE_FDU->makeFilePath((int8_hf *)filePath.c_str());
63 
64  // load string resources:
65  loadStrings(fullFilePath);
66 
67  assert(loader != NULL);
68  mResourceLoader = loader;
69 }
70 
72 {
73  // unload all resource groups:
74  envDebugLog("=============================================\r\n");
75  envDebugLog("= Unload all Resource Groups Start\r\n");
76  envDebugLog("=============================================\r\n");
77  ResourceGroupMap::iterator groupIter;
78  for (groupIter = mResourceGroups.begin();
79  groupIter != mResourceGroups.end(); groupIter++)
80  {
81  envDebugLog("Unloading %s\r\n", groupIter->first.c_str());
82  unloadResourceGroup(groupIter->first);
83  HF_SAFE_DELETE(groupIter->second);
84  }
85  mResourceGroups.clear();
86  envDebugLog("=============================================\r\n");
87  envDebugLog("= Unload all Resource Groups End\r\n");
88  envDebugLog("=============================================\r\n");
89 
90  // delete all resources:
91  envDebugLog("=============================================\r\n");
92  envDebugLog("= Delete all Resources Start\r\n");
93  envDebugLog("=============================================\r\n");
94  std::map<std::string, Resource *>::iterator resIter;
95  for (resIter = mResourcesByPath.begin();
96  resIter != mResourcesByPath.end(); resIter++)
97  {
98  // assert(!resIter->second->isLoaded());
99  if (resIter->second == NULL)
100  {
101  continue;
102  }
103 
104  // if the resource is loaded (this will happen
105  // when we call getImageFromPath directly):
106  while (resIter->second->isLoaded())
107  {
108  // unload it:
109  envDebugLog("Unloading %s\r\n", resIter->first.c_str());
110  resIter->second->release();
111  }
112 
113  envDebugLog("Deleting %s\r\n", resIter->first.c_str());
114  HF_SAFE_DELETE(resIter->second);
115  }
116  mResourcesByPath.clear();
117  envDebugLog("=============================================\r\n");
118  envDebugLog("= Delete all Resources End\r\n");
119  envDebugLog("=============================================\r\n");
120 
121  // clear the rest of the data
122  mParsedResourceFiles.clear();
123  mResourcesById.clear();
124  mText.clear();
125 
126 }
127 
128 void ResourceManager::loadStrings(const int8_hf *filename)
129 {
130  TiXmlDocument doc;
131 
132  // load the clear text strings directly
133  if (doc.LoadFile(filename) == false)
134  {
135  return;
136  }
137 
138  TiXmlElement *root = doc.RootElement();
139 
140  for (TiXmlElement *e = root->FirstChildElement(); e != NULL;
141  e = e->NextSiblingElement())
142  {
143  assert(strcmp(e->Value(), "string") == 0);
144  const int8_hf *id = e->Attribute("id");
145  const int8_hf *text = e->Attribute("text");
146  assert(id != NULL && text != NULL);
147 
148  // look for localized text:
149  for (TiXmlAttribute *a = e->FirstAttribute(); a != NULL; a = a->Next())
150  {
151  // skip the 'id' and 'text' attributes:
152  const int8_hf *name = a->Name();
153  if (HFCORE_ENV->hf_stricmp("id", name) == 0 ||
154  HFCORE_ENV->hf_stricmp("text", name) == 0)
155  {
156  continue;
157  }
158 
159  // if this attribute is the localized version for the first language:
160  if (mLanguage == a->Name())
161  {
162  // remebmer the localized text:
163  text = a->Value();
164  break;
165  }
166  }
167 
168  // store the text:
169  mText[id] = text;
170  }
171 
172  doc.Clear();
173 }
174 
175 bool ResourceManager::parseResourceFile(const std::string &fileName)
176 {
177  // if we've already loaded:
178  if (find(mParsedResourceFiles.begin(), mParsedResourceFiles.end(), fileName) !=
179  mParsedResourceFiles.end())
180  {
181  // ignore this call:
182  return true;
183  }
184 
185  TiXmlDocument doc;
186 
187  bool success = doc.LoadFile(fileName.c_str());
188  if (!success)
189  {
190  return false;
191  }
192 
193  TiXmlElement *root = doc.RootElement();
194 
195  for (TiXmlElement *e = root->FirstChildElement(); e != NULL; e = e->NextSiblingElement())
196  {
197  if (HFCORE_ENV->hf_stricmp(e->Value(), "resources") == 0)
198  {
199  parseResourceGroup(e);
200  }
201  else
202  {
203  assert(false);
204  }
205  }
206 
207  doc.Clear();
208 
209  return true;
210 }
211 
212 void ResourceManager::parseResourceGroup(TiXmlElement *elem)
213 {
214  std::string groupId = elem->Attribute("id");
215  ResourceGroup *group = new ResourceGroup();
216  mResourceGroups[groupId] = group;
217 
218  std::string basePath;
219  std::string idPrefix;
220 
221  for (TiXmlElement *child = elem->FirstChildElement(); child != NULL;
222  child = child->NextSiblingElement())
223  {
224  const int8_hf *val = child->Value();
225  if (HFCORE_ENV->hf_stricmp(val, "SetDefaults") == 0)
226  {
227  idPrefix = child->Attribute("idprefix");
228  basePath = child->Attribute("path");
229  // add trailing slash if necessary:
230  if (basePath[basePath.size() - 1] != '/' &&
231  basePath[basePath.size() - 1] != '\\')
232  {
233  basePath += '/';
234  }
235  // remove "./" from begining if it's there:
236  if (basePath.substr(0, 2) == "./" ||
237  basePath.substr(0, 2) == ".\\")
238  {
239  basePath = basePath.substr(2);
240  }
241  }
242  else
243  {
244  std::string id = idPrefix + child->Attribute("id");
245  std::string fullPath = basePath;
246  if (mLanguage.size() > 0 && child->Attribute(mLanguage.c_str()) != NULL)
247  {
248  fullPath.append(child->Attribute(mLanguage.c_str()));
249  }
250  else
251  {
252  fullPath.append(child->Attribute("path"));
253  }
254 
255  // if this resource path already exists:
256  if (mResourcesByPath.find(fullPath) != mResourcesByPath.end())
257  {
258  // just create a mapping:
259  mapResource(id, fullPath, group);
260  }
261  else
262  {
263  // create and add the resource:
264  Resource *res = createResource(val, fullPath);
265  addResource(id, fullPath, group, res);
266  }
267  }
268  }
269 }
270 
271 Resource *ResourceManager::createResource(const int8_hf *type, const std::string &path)
272 {
273  Resource *res = NULL;
274  if (HFCORE_ENV->hf_stricmp(type, "image") == 0)
275  {
276  res = mResourceLoader->createImage(path);
277  }
278  else if (HFCORE_ENV->hf_stricmp(type, "imageatlas") == 0)
279  {
280  res = createImageAtlas(mResourceLoader, path);
281  }
282  else if (HFCORE_ENV->hf_stricmp(type, "font") == 0)
283  {
284  res = createFont(mResourceLoader, path);
285  }
286  else if (HFCORE_ENV->hf_stricmp(type, "sound") == 0)
287  {
288  res = mResourceLoader->createSound(path);
289  }
290  else if (HFCORE_ENV->hf_stricmp(type, "tmxtilemap") == 0)
291  {
292 #if defined(HF_MODULE_TMXPARSER)
293  res = new HFModule::TmxMap(mResourceLoader, path);
294 #else
295  envEngineLog("ERROR: Engine not compiled with TmxParser support. \
296 Enable by setting pre-processor -DHF_MODULE_TMXPARSER.\r\n");
297  assert(false);
298 #endif
299  }
300  else if (HFCORE_ENV->hf_stricmp(type, "shader_vsfs") == 0)
301  {
302  res = createShader(path, Shader::SHADER_TYPE_VSFS);
303  }
304  else if (HFCORE_ENV->hf_stricmp(type, "wavefrontobj") == 0)
305  {
306  res = new WavefrontOBJ(mResourceLoader, path);
307  }
308  else
309  {
310  assert(false);
311  }
312  return res;
313 }
314 
315 Shader *ResourceManager::createShader(const std::string &path, Shader::Type type)
316 {
317  Shader *res = NULL;
318 
319  if (type == Shader::SHADER_TYPE_VSFS)
320  {
321 #if defined(HF_PLATFORM_WINDOWS_D3D9)
322  StringUtil::StringVector pathVec = parsePath(path);
323  assert(pathVec.size() == 2);
324  ShaderCompileInfo vs = getShaderCompileInfoFromPath(pathVec[0], "main", "vs_3_0");
325  ShaderCompileInfo fs = getShaderCompileInfoFromPath(pathVec[1], "main", "ps_3_0");
326  res = mResourceLoader->createShader(path, Shader::SHADER_TYPE_VSFS, vs.entryFunction,
327  vs.compileVersion, fs.entryFunction, fs.compileVersion);
328 #else
329  res = mResourceLoader->createShader(path, Shader::SHADER_TYPE_VSFS);
330 #endif
331  }
332 
333  return res;
334 }
335 
336 StringUtil::StringVector ResourceManager::parsePath(const std::string &path)
337 {
339 
340  UStringStream paths(path.c_str());
341 
342  // readUntil ',' so that we get each path:
343  while (!paths.eof())
344  {
345  UString tmpBuffer = paths.readUntil(",");
346  retVec.push_back(tmpBuffer.toUtf8());
347  }
348 
349  return retVec;
350 }
351 
352 ResourceManager::ShaderCompileInfo ResourceManager::getShaderCompileInfoFromPath(
353  const std::string &path,
354  const std::string &defaultEntryFunction,
355  const std::string &defaultCompileVersion)
356 {
357  ShaderCompileInfo retval;
358  retval.entryFunction = defaultEntryFunction;
359  retval.compileVersion = defaultCompileVersion;
360 
361  UStringStream p(path.c_str());
362 
363  // skipUntil ':' so that we get entryFunction and compileVersion if any:
364  if (!p.eof())
365  p.skipUntil(L':');
366 
367  int32_hf index = 0;
368  while (!p.eof())
369  {
370  UString buf = p.readUntil("|");
371 
372  if (index == 0 && buf.length() > 0)
373  {
374  retval.entryFunction = buf.toUtf8();
375  }
376  else if (index == 1 && buf.length() > 0)
377  {
378  retval.compileVersion = buf.toUtf8();
379  }
380  else
381  {
382  // unsupported string format:
383  assert(false);
384  }
385 
386  index++;
387  }
388 
389  return retval;
390 }
391 
392 ImageAtlas *ResourceManager::createImageAtlas(ResourceLoader *loader,
393  const std::string &path)
394 {
395  std::string ext = "";
396  HFCORE_FDU->splitDirFileExt(path, NULL, NULL, &ext);
397  std::string extlower = StringUtil::StringToLower(ext);
398  envDebugLog("ImageAtlas descriptor file extension is: %s\r\n", extlower.c_str());
399 
400  if (extlower == "bin")
401  {
402  return new HFTexPackImageAtlasBIN(loader, path);
403  }
404  else if (extlower == "txt")
405  {
406  return new HFTexPackImageAtlasTXT(loader, path);
407  }
408  else if (extlower == "xml")
409  {
410  return new HFTexPackImageAtlasXML(loader, path);
411  }
412  else
413  {
414  envEngineLog("ERROR: Unknown ImageAtlas type!\r\n", path.c_str());
415  return NULL;
416  }
417 }
418 
419 Font *ResourceManager::createFont(ResourceLoader *loader,
420  const std::string &path)
421 {
422  int32_hf type = getFontType(path);
423 
424  if (type == FONT_TYPE_HFBMFONT_XML)
425  {
426  envDebugLog("Creating Font of type FONT_TYPE_HFBMFONT_XML\r\n");
427  return new HFBMFontXML(loader, path);
428  }
429  else if (type == FONT_TYPE_HFBMFONT_BIN)
430  {
431  envDebugLog("Creating Font of type FONT_TYPE_HFBMFONT_BIN\r\n");
432  return new HFBMFontBIN(loader, path);
433  }
434  else if (type == FONT_TYPE_HFBMFONT_TXT)
435  {
436  envDebugLog("Creating Font of type FONT_TYPE_HFBMFONT_TXT\r\n");
437  return new HFBMFontTXT(loader, path);
438  }
439  else
440  {
441  envEngineLog("ERROR: getFontType(%s) returns FONT_TYPE_UNKNOWN\r\n", path.c_str());
442  return NULL;
443  }
444 }
445 
446 int32_hf ResourceManager::getFontType(const std::string &path)
447 {
448  std::string ext = "";
449  HFCORE_FDU->splitDirFileExt(path, NULL, NULL, &ext);
450  std::string extlower = StringUtil::StringToLower(ext);
451  envDebugLog("Font descriptor file extension is: %s\r\n", extlower.c_str());
452 
453  // hfbmfont check:
454  if (extlower == "bin")
455  {
456  return FONT_TYPE_HFBMFONT_BIN;
457  }
458  else if (extlower == "txt")
459  {
460  return FONT_TYPE_HFBMFONT_TXT;
461  }
462  else if (extlower == "xml")
463  {
464  return FONT_TYPE_HFBMFONT_XML;
465  }
466 
467  return FONT_TYPE_UNKNOWN;
468 }
469 
470 void ResourceManager::addResource(const std::string &id, const std::string &path,
471  ResourceGroup *group, Resource *resource)
472 {
473  assert(resource != NULL);
474 
475  // add it to the group:
476  group->addResourcePath(path);
477 
478  // create a path->resource mapping:
479  mResourcesByPath[path] = resource;
480  envDebugLog("[%p] %s\r\n", resource, path.c_str());
481 
482  // create an id->resource mapping:
483  mResourcesById[id] = resource;
484 }
485 
486 void ResourceManager::mapResource(const std::string &id, const std::string &path,
487  ResourceGroup *group)
488 {
489  group->addResourcePath(path);
490 
491  // get the resource pointed to by this resource path:
492  Resource *res = mResourcesByPath[path];
493 
494  // map new id to existing resource:
495  mResourcesById[id] = res;
496 }
497 
498 bool ResourceManager::loadResourceGroup(const std::string &groupName)
499 {
500  // note: it's ok to load a group more than once as long as it's
501  // released more than once too. different parts of the code
502  // can use the same resource group and each of them should load
503  // it when they need it and unload it when they done with it
504  if (mResourceGroups.find(groupName) != mResourceGroups.end())
505  {
506  // disable full screen toggle while resource load/unload:
507  HFCORE_ENV->disableFullScreenToggle();
508 
509  ResourceGroup *g = mResourceGroups[groupName];
510  bool success = true;
511  if (!g->isEmpty())
512  {
513  for (const std::string *path = g->getFirstPath(); path != NULL;
514  path = g->getNextPath())
515  {
516  assert(mResourcesByPath.find(*path) != mResourcesByPath.end());
517  Resource *res = mResourcesByPath[*path];
518  assert(res != NULL);
519  success &= res->load();
520  }
521  }
522 
523  HFCORE_ENV->enableFullScreenToggle();
524 
525  return success;
526  }
527  else
528  {
529  assert(false);
530 
531  return false;
532  }
533 }
534 
535 ResourceGroup *ResourceManager::getResourceGroup(const std::string &groupName)
536 {
537  ResourceGroup *g = NULL;
538  if (mResourceGroups.find(groupName) != mResourceGroups.end())
539  {
540  g = mResourceGroups[groupName];
541  }
542  return g;
543 }
544 
545 void ResourceManager::unloadResourceGroup(const std::string &groupName)
546 {
547  if (mResourceGroups.find(groupName) != mResourceGroups.end())
548  {
549  // disable full screen toggle while resource load/unload:
550  HFCORE_ENV->disableFullScreenToggle();
551 
552  ResourceGroup *g = mResourceGroups[groupName];
553  for (const std::string *path = g->getFirstPath(); path != NULL;
554  path = g->getNextPath())
555  {
556  Resource *res = mResourcesByPath[*path];
557  if (res != NULL)
558  {
559  res->release();
560  res = NULL;
561  }
562  }
563 
564  HFCORE_ENV->enableFullScreenToggle();
565  }
566  else
567  {
568  assert(false);
569  }
570 }
571 
573 {
574  // disable full screen toggle while resource load/unload:
575  HFCORE_ENV->disableFullScreenToggle();
576 
577  // iterate over all reasources:
578  for (ResourceMap::iterator iter = mResourcesByPath.begin();
579  iter != mResourcesByPath.end(); iter++)
580  {
581  iter->second->reload();
582  }
583 
584  HFCORE_ENV->enableFullScreenToggle();
585 }
586 
587 void ResourceManager::destroyResources(bool includeSounds)
588 {
589  // disable full screen toggle while resource load/unload:
590  HFCORE_ENV->disableFullScreenToggle();
591 
592  // iterate over all reasources:
593  for (ResourceMap::iterator iter = mResourcesByPath.begin();
594  iter != mResourcesByPath.end(); iter++)
595  {
596  if (iter->second->isLoaded())
597  {
598  envDebugLog("destroyResources: %s\r\n", iter->first.c_str());
599  iter->second->destroy(includeSounds);
600  }
601  }
602 
603  HFCORE_ENV->enableFullScreenToggle();
604 }
605 
606 void ResourceManager::initResources(bool includeSounds)
607 {
608  // disable full screen toggle while resource load/unload:
609  HFCORE_ENV->disableFullScreenToggle();
610 
611  // iterate over all reasources:
612  for (ResourceMap::iterator iter = mResourcesByPath.begin();
613  iter != mResourcesByPath.end(); iter++)
614  {
615  if (iter->second->isLoaded())
616  {
617  envDebugLog("initResources: %s\r\n", iter->first.c_str());
618  iter->second->init(includeSounds);
619  }
620  }
621 
622  HFCORE_ENV->enableFullScreenToggle();
623 }
624 
625 Font *ResourceManager::getFont(const std::string &id)
626 {
627  assert(mResourcesById.find(id) != mResourcesById.end());
628  Font *font = dynamic_cast<Font *>(mResourcesById[id]);
629  assert(font->isLoaded());
630  return font;
631 }
632 
633 Image *ResourceManager::getImage(const std::string &id)
634 {
635  ResourceMap::iterator iter = mResourcesById.find(id);
636  if (iter == mResourcesById.end())
637  {
638  envDebugLog("[WARNING: ResourceManager::getImage] image with id %s not found\r\n",
639  id.c_str());
640  return NULL;
641  }
642  Image *image = dynamic_cast<Image *>(iter->second);
643  assert(image->isLoaded());
644  return image;
645 }
646 
648 {
649  ResourceMap::iterator iter = mResourcesById.find(id);
650  if (iter == mResourcesById.end())
651  {
652  envDebugLog("[WARNING: ResourceManager::getImageAtlas] imageatlas with id %s not found\r\n",
653  id.c_str());
654  return NULL;
655  }
656  ImageAtlas *imageAtlas = dynamic_cast<ImageAtlas *>(iter->second);
657  assert(imageAtlas->isLoaded());
658  return imageAtlas;
659 }
660 
661 UString ResourceManager::getString(const std::string &id)
662 {
663  assert(mText.find(id) != mText.end());
664  return mText[id];
665 }
666 
667 bool ResourceManager::hasString(const std::string &id)
668 {
669  return mText.find(id) != mText.end();
670 }
671 
672 Sound *ResourceManager::getSound(const std::string &id)
673 {
674  ResourceMap::iterator iter = mResourcesById.find(id);
675  if (iter == mResourcesById.end())
676  {
677  return NULL;
678  }
679 
680  Sound *sound = dynamic_cast<Sound *>(iter->second);
681  assert(sound->isLoaded());
682  return sound;
683 }
684 
685 #if defined(HF_MODULE_TMXPARSER)
686 HFModule::TmxMap *ResourceManager::getTmxTileMap(const std::string &id)
687 {
688  ResourceMap::iterator iter = mResourcesById.find(id);
689  if (iter == mResourcesById.end())
690  {
691  envDebugLog("[WARNING: ResourceManager::getTmxTileMap] TmxTileMap with id %s not found\r\n",
692  id.c_str());
693  return NULL;
694  }
695  HFModule::TmxMap *tmxTileMap = dynamic_cast<HFModule::TmxMap *>(iter->second);
696  assert(tmxTileMap->isLoaded());
697  return tmxTileMap;
698 }
699 #endif
700 
701 Shader *ResourceManager::getShader(const std::string &id)
702 {
703  ResourceMap::iterator iter = mResourcesById.find(id);
704  if (iter == mResourcesById.end())
705  {
706  envDebugLog("[WARNING: ResourceManager::getShader] shader with id %s not found\r\n",
707  id.c_str());
708  return NULL;
709  }
710  Shader *shader = dynamic_cast<Shader *>(iter->second);
711  assert(shader->isLoaded());
712  return shader;
713 }
714 
716 {
717  ResourceMap::iterator iter = mResourcesById.find(id);
718  if (iter == mResourcesById.end())
719  {
720  envDebugLog("[WARNING: ResourceManager::getWavefrontOBJ] WavefrontOBJ with id %s not found\r\n",
721  id.c_str());
722  return NULL;
723  }
724  WavefrontOBJ *obj = dynamic_cast<WavefrontOBJ *>(iter->second);
725  assert(obj->isLoaded());
726  return obj;
727 }
728 
729 Image *ResourceManager::getImageFromPath(const std::string &path)
730 {
731  ResourceMap::iterator iter = mResourcesByPath.find(path);
732 
733  // if we have a reference to this image path:
734  if (iter != mResourcesByPath.end() && iter->second != NULL)
735  {
736  // disable full screen toggle while resource load/unload:
737  HFCORE_ENV->disableFullScreenToggle();
738 
739  // increment its ref count:
740  Image *img = dynamic_cast<Image *>(iter->second);
741 
742  // increment ref count:
743  img->load();
744 
745  HFCORE_ENV->enableFullScreenToggle();
746 
747  // return the image:
748  return img;
749  }
750  else
751  {
752  // disable full screen toggle while resource load/unload:
753  HFCORE_ENV->disableFullScreenToggle();
754 
755  // create it:
756  Image *img = mResourceLoader->createImage(path);
757 
758  // manually loaded:
759  img->setIsManuallyLoaded(true);
760 
761  // try to load it:
762  if (img->load())
763  {
764  // keep track of it:
765  mResourcesByPath[path] = img;
766 
767  HFCORE_ENV->enableFullScreenToggle();
768 
769  // return it:
770  return img;
771  }
772  else
773  {
774  // get rid of it:
775  HF_SAFE_DELETE(img);
776 
777  HFCORE_ENV->enableFullScreenToggle();
778 
779  // return NULL;
780  return NULL;
781  }
782  }
783 }
784 
786 {
787  ResourceMap::iterator iter = mResourcesByPath.find(path);
788 
789  // if we have a reference to this image path:
790  if (iter != mResourcesByPath.end() && iter->second != NULL)
791  {
792  // disable full screen toggle while resource load/unload:
793  HFCORE_ENV->disableFullScreenToggle();
794 
795  // increment its ref count:
796  ImageAtlas *imgAtlas = dynamic_cast<ImageAtlas *>(iter->second);
797 
798  // increment ref count:
799  imgAtlas->load();
800 
801  HFCORE_ENV->enableFullScreenToggle();
802 
803  // return the image:
804  return imgAtlas;
805  }
806  else
807  {
808  // disable full screen toggle while resource load/unload:
809  HFCORE_ENV->disableFullScreenToggle();
810 
811  // create it:
812  ImageAtlas *imgAtlas = createImageAtlas(mResourceLoader, path);
813 
814  // manually loaded:
815  imgAtlas->setIsManuallyLoaded(true);
816 
817  // try to load it:
818  if (imgAtlas->load())
819  {
820  // keep track of it:
821  mResourcesByPath[path] = imgAtlas;
822 
823  HFCORE_ENV->enableFullScreenToggle();
824 
825  // return it:
826  return imgAtlas;
827  }
828  else
829  {
830  // get rid of it:
831  HF_SAFE_DELETE(imgAtlas);
832 
833  HFCORE_ENV->enableFullScreenToggle();
834 
835  // return NULL;
836  return NULL;
837  }
838  }
839 }
840 
841 #if defined(HF_MODULE_TMXPARSER)
842 HFModule::TmxMap *ResourceManager::getTmxTileMapFromPath(const std::string &path)
843 {
844  ResourceMap::iterator iter = mResourcesByPath.find(path);
845 
846  // if we have a reference to this TmxMap path:
847  if (iter != mResourcesByPath.end() && iter->second != NULL)
848  {
849  // disable full screen toggle while resource load/unload:
850  HFCORE_ENV->disableFullScreenToggle();
851 
852  // increment its ref count:
853  HFModule::TmxMap *tmxTileMap = dynamic_cast<HFModule::TmxMap *>(iter->second);
854 
855  // increment ref count:
856  tmxTileMap->load();
857 
858  HFCORE_ENV->enableFullScreenToggle();
859 
860  // return the TmxTileMap:
861  return tmxTileMap;
862  }
863  else
864  {
865  // disable full screen toggle while resource load/unload:
866  HFCORE_ENV->disableFullScreenToggle();
867 
868  // create it:
869  HFModule::TmxMap *tmxTileMap = new HFModule::TmxMap(mResourceLoader, path);
870 
871  // manually loaded:
872  tmxTileMap->setIsManuallyLoaded(true);
873 
874  // try to load it:
875  if (tmxTileMap->load())
876  {
877  // keep track of it:
878  mResourcesByPath[path] = tmxTileMap;
879 
880  HFCORE_ENV->enableFullScreenToggle();
881 
882  // return it:
883  return tmxTileMap;
884  }
885  else
886  {
887  // get rid of it:
888  HF_SAFE_DELETE(tmxTileMap);
889 
890  HFCORE_ENV->enableFullScreenToggle();
891 
892  // return NULL;
893  return NULL;
894  }
895  }
896 }
897 #endif
898 
899 Font *ResourceManager::getFontFromPath(const std::string &path)
900 {
901  ResourceMap::iterator iter = mResourcesByPath.find(path);
902 
903  // if we have a reference to this Font path:
904  if (iter != mResourcesByPath.end() && iter->second != NULL)
905  {
906  // disable full screen toggle while resource load/unload:
907  HFCORE_ENV->disableFullScreenToggle();
908 
909  // increment its ref count:
910  Font *font = dynamic_cast<Font *>(iter->second);
911 
912  // increment ref count:
913  font->load();
914 
915  HFCORE_ENV->enableFullScreenToggle();
916 
917  // return the Font:
918  return font;
919  }
920  else
921  {
922  // disable full screen toggle while resource load/unload:
923  HFCORE_ENV->disableFullScreenToggle();
924 
925  // create it:
926  Font *font = createFont(mResourceLoader, path);
927 
928  // manually loaded:
929  font->setIsManuallyLoaded(true);
930 
931  // try to load it:
932  if (font->load())
933  {
934  // keep track of it:
935  mResourcesByPath[path] = font;
936 
937  HFCORE_ENV->enableFullScreenToggle();
938 
939  // return it:
940  return font;
941  }
942  else
943  {
944  // get rid of it:
945  HF_SAFE_DELETE(font);
946 
947  HFCORE_ENV->enableFullScreenToggle();
948 
949  // return NULL;
950  return NULL;
951  }
952  }
953 }
954 
956  const std::string &entryFunctionVS,
957  const std::string &compileVersionVS,
958  const std::string &entryFunctionFS,
959  const std::string &compileVersionFS)
960 {
961  ResourceMap::iterator iter = mResourcesByPath.find(path);
962 
963  // if we have a reference to this Shader path:
964  if (iter != mResourcesByPath.end() && iter->second != NULL)
965  {
966  // disable full screen toggle while resource load/unload:
967  HFCORE_ENV->disableFullScreenToggle();
968 
969  // increment its ref count:
970  Shader *shader = dynamic_cast<Shader *>(iter->second);
971 
972  // increment ref count:
973  shader->load();
974 
975  HFCORE_ENV->enableFullScreenToggle();
976 
977  // return the Shader:
978  return shader;
979  }
980  else
981  {
982  // disable full screen toggle while resource load/unload:
983  HFCORE_ENV->disableFullScreenToggle();
984 
985  // create it:
986  Shader *shader = mResourceLoader->createShader(path, type,
987  entryFunctionVS,
988  compileVersionVS,
989  entryFunctionFS,
990  compileVersionFS);
991 
992  // manually loaded:
993  shader->setIsManuallyLoaded(true);
994 
995  // try to load it:
996  if (shader->load())
997  {
998  // keep track of it:
999  mResourcesByPath[path] = shader;
1000 
1001  HFCORE_ENV->enableFullScreenToggle();
1002 
1003  // return it:
1004  return shader;
1005  }
1006  else
1007  {
1008  // get rid of it:
1009  HF_SAFE_DELETE(shader);
1010 
1011  HFCORE_ENV->enableFullScreenToggle();
1012 
1013  // return NULL;
1014  return NULL;
1015  }
1016  }
1017 }
1018 
1019 Shader *ResourceManager::getShaderFromSource(const std::string &vertexShaderSrc,
1020  const std::string &fragmentShaderSrc,
1021  const std::string &entryFunctionVS,
1022  const std::string &compileVersionVS,
1023  const std::string &entryFunctionFS,
1024  const std::string &compileVersionFS)
1025 {
1026  const std::string sha256sum = Crypto::sha256sum(vertexShaderSrc + fragmentShaderSrc);
1027  ResourceMap::iterator iter = mResourcesByPath.find(sha256sum);
1028 
1029  // if we have a reference to this Shader path:
1030  if (iter != mResourcesByPath.end() && iter->second != NULL)
1031  {
1032  // disable full screen toggle while resource load/unload:
1033  HFCORE_ENV->disableFullScreenToggle();
1034 
1035  // increment its ref count:
1036  Shader *shader = dynamic_cast<Shader *>(iter->second);
1037 
1038  // increment ref count:
1039  shader->load();
1040 
1041  HFCORE_ENV->enableFullScreenToggle();
1042 
1043  // return the Shader:
1044  return shader;
1045  }
1046  else
1047  {
1048  // disable full screen toggle while resource load/unload:
1049  HFCORE_ENV->disableFullScreenToggle();
1050 
1051  // create it:
1052  Shader *shader = mResourceLoader->createShaderFromSource(vertexShaderSrc,
1053  fragmentShaderSrc,
1054  entryFunctionVS,
1055  compileVersionVS,
1056  entryFunctionFS,
1057  compileVersionFS);
1058 
1059  // manually loaded:
1060  shader->setIsManuallyLoaded(true);
1061 
1062  // try to load it:
1063  if (shader->load())
1064  {
1065  // keep track of it:
1066  mResourcesByPath[sha256sum] = shader;
1067 
1068  HFCORE_ENV->enableFullScreenToggle();
1069 
1070  // return it:
1071  return shader;
1072  }
1073  else
1074  {
1075  // get rid of it:
1076  HF_SAFE_DELETE(shader);
1077 
1078  HFCORE_ENV->enableFullScreenToggle();
1079 
1080  // return NULL;
1081  return NULL;
1082  }
1083  }
1084 }
1085 
1087 {
1088  ResourceMap::iterator iter = mResourcesByPath.find(path);
1089 
1090  // if we have a reference to this WavefrontOBJ path:
1091  if (iter != mResourcesByPath.end() && iter->second != NULL)
1092  {
1093  // disable full screen toggle while resource load/unload:
1094  HFCORE_ENV->disableFullScreenToggle();
1095 
1096  // increment its ref count:
1097  WavefrontOBJ *obj = dynamic_cast<WavefrontOBJ *>(iter->second);
1098 
1099  // increment ref count:
1100  obj->load();
1101 
1102  HFCORE_ENV->enableFullScreenToggle();
1103 
1104  // return the WavefrontOBJ:
1105  return obj;
1106  }
1107  else
1108  {
1109  // disable full screen toggle while resource load/unload:
1110  HFCORE_ENV->disableFullScreenToggle();
1111 
1112  // create it:
1113  WavefrontOBJ *obj = new WavefrontOBJ(mResourceLoader, path);
1114 
1115  // manually loaded:
1116  obj->setIsManuallyLoaded(true);
1117 
1118  // try to load it:
1119  if (obj->load())
1120  {
1121  // keep track of it:
1122  mResourcesByPath[path] = obj;
1123 
1124  HFCORE_ENV->enableFullScreenToggle();
1125 
1126  // return it:
1127  return obj;
1128  }
1129  else
1130  {
1131  // get rid of it:
1132  HF_SAFE_DELETE(obj);
1133 
1134  HFCORE_ENV->enableFullScreenToggle();
1135 
1136  // return NULL;
1137  return NULL;
1138  }
1139  }
1140 }
1141 
1143 {
1144  envDebugLog("=============================================\r\n");
1145  envDebugLog("= Delete all Manually Loaded Resources Start\r\n");
1146  envDebugLog("=============================================\r\n");
1147  ResourceMap::iterator resIter;
1148  std::vector<ResourceMap::iterator> vecResIter;
1149  for (resIter = mResourcesByPath.begin();
1150  resIter != mResourcesByPath.end(); resIter++)
1151  {
1152  Resource *res = resIter->second;
1153  // could happen if image is released manually:
1154  if (res == NULL)
1155  {
1156  continue;
1157  }
1158 
1159  // only interested in those manually loaded (i.e XXXFromPath):
1160  if (res->getIsManuallyLoaded())
1161  {
1162  // if the resource is loaded (this will happen
1163  // when we call XXXFromPath directly):
1164  while (resIter->second->isLoaded())
1165  {
1166  // unload it:
1167  envDebugLog("Unloading %s\r\n", resIter->first.c_str());
1168  resIter->second->release();
1169  }
1170 
1171  envDebugLog("Deleting %s\r\n", resIter->first.c_str());
1172  HF_SAFE_DELETE(resIter->second);
1173 
1174  // push to vector so that will be removed from map later:
1175  vecResIter.push_back(resIter);
1176  }
1177  }
1178  envDebugLog("=============================================\r\n");
1179  envDebugLog("= Delete all Manually Loaded Resources End\r\n");
1180  envDebugLog("=============================================\r\n");
1181 
1182  // remove from map:
1183  for (int32_hf i = 0; i < (int32_hf)vecResIter.size(); i++)
1184  {
1185  // fetch iterator:
1186  ResourceMap::iterator resIter = vecResIter[i];
1187 
1188  // remove from map:
1189  mResourcesByPath.erase(resIter);
1190  }
1191 }
1192 
1194 {
1195  std::string typeStr = "Invalid";
1196  if (type == HF_RESOURCE_TYPE_IMAGE)
1197  typeStr = "HF_RESOURCE_TYPE_IMAGE";
1198  else if (type == HF_RESOURCE_TYPE_IMAGEATLAS)
1199  typeStr = "HF_RESOURCE_TYPE_IMAGEATLAS";
1200  else if (type == HF_RESOURCE_TYPE_FONT)
1201  typeStr = "HF_RESOURCE_TYPE_FONT";
1202  else if (type == HF_RESOURCE_TYPE_SHADER)
1203  typeStr = "HF_RESOURCE_TYPE_SHADER";
1204  else if (type == HF_RESOURCE_TYPE_SOUND)
1205  typeStr = "HF_RESOURCE_TYPE_SOUND";
1206  else if (type == HF_RESOURCE_TYPE_TMXTILEMAP)
1207  typeStr = "HF_RESOURCE_TYPE_TMXTILEMAP";
1208 
1209  envDebugLog("======================================================================================\r\n");
1210  envDebugLog("= Delete all Manually Loaded Resources by type (%s) Start\r\n", typeStr.c_str());
1211  envDebugLog("======================================================================================\r\n");
1212  ResourceMap::iterator resIter;
1213  std::vector<ResourceMap::iterator> vecResIter;
1214  for (resIter = mResourcesByPath.begin();
1215  resIter != mResourcesByPath.end(); resIter++)
1216  {
1217  Resource *res = resIter->second;
1218  // could happen if image is released manually:
1219  if (res == NULL)
1220  {
1221  continue;
1222  }
1223 
1224  // only interested in those manually loaded (i.e XXXFromPath):
1225  if (res->getIsManuallyLoaded() && res->getResourceType() == type)
1226  {
1227  // if the resource is loaded (this will happen
1228  // when we call XXXFromPath directly):
1229  while (resIter->second->isLoaded())
1230  {
1231  // unload it:
1232  envDebugLog("Unloading %s\r\n", resIter->first.c_str());
1233  resIter->second->release();
1234  }
1235 
1236  envDebugLog("Deleting %s\r\n", resIter->first.c_str());
1237  HF_SAFE_DELETE(resIter->second);
1238 
1239  // push to vector so that will be removed from map later:
1240  vecResIter.push_back(resIter);
1241  }
1242  }
1243  envDebugLog("======================================================================================\r\n");
1244  envDebugLog("= Delete all Manually Loaded Resources by type (%s) End\r\n", typeStr.c_str());
1245  envDebugLog("======================================================================================\r\n");
1246 
1247  // remove from map:
1248  for (int32_hf i = 0; i < (int32_hf)vecResIter.size(); i++)
1249  {
1250  // fetch iterator:
1251  ResourceMap::iterator resIter = vecResIter[i];
1252 
1253  // remove from map:
1254  mResourcesByPath.erase(resIter);
1255  }
1256 }
1257 
1259 {
1260  ResourceMap::iterator resIter;
1261  std::vector<ResourceMap::iterator> vecResIter;
1262  for (resIter = mResourcesByPath.begin();
1263  resIter != mResourcesByPath.end(); resIter++)
1264  {
1265  if (resIter->second == res)
1266  {
1267  while (resIter->second->isLoaded())
1268  {
1269  // unload it:
1270  envDebugLog("Unloading %s\r\n", resIter->first.c_str());
1271  resIter->second->release();
1272  }
1273 
1274  envDebugLog("Deleting %s\r\n", resIter->first.c_str());
1275  HF_SAFE_DELETE(resIter->second);
1276 
1277  // push to vector so that will be removed from map later:
1278  vecResIter.push_back(resIter);
1279 
1280  // exit loop:
1281  break;
1282  }
1283  }
1284 
1285  // remove from map:
1286  for (int32_hf i = 0; i < (int32_hf)vecResIter.size(); i++)
1287  {
1288  // fetch iterator:
1289  ResourceMap::iterator resIter = vecResIter[i];
1290 
1291  // remove from map:
1292  mResourcesByPath.erase(resIter);
1293  }
1294 }
1295 
1296 void ResourceManager::getAllSounds(std::vector<Sound *> &sounds)
1297 {
1298  // TODO: this implementation is kinda hacky, we
1299  // shouldn't be relying on the resource ID to
1300  // identify whether it as a sound.
1301 
1302  ResourceMap::iterator iter = mResourcesById.begin();
1303  ResourceMap::iterator end = mResourcesById.end();
1304 
1305  while (iter != end)
1306  {
1307  if (iter->first.substr(0, 5) == "SOUND")
1308  {
1309  sounds.push_back(dynamic_cast<Sound *>(iter->second));
1310  }
1311  iter++;
1312  }
1313 }
1314 
1316 {
1317  std::map<std::string, int32_hf>::iterator refIter;
1318 
1319  envDebugLog("===============================================================\r\n");
1320  envDebugLog("------------------- ResourceManager: files --------------------\r\n");
1321  StringUtil::StringVector::iterator iter1;
1322  for (iter1 = mParsedResourceFiles.begin();
1323  iter1 != mParsedResourceFiles.end(); iter1++)
1324  {
1325  envDebugLog("file: %s\r\n", iter1->c_str());
1326  }
1327 
1328  envDebugLog("------------------- ResourceManager: groups --------------------\r\n");
1329  std::map<std::string, ResourceGroup *>::iterator iter2;
1330  for (iter2 = mResourceGroups.begin();
1331  iter2 != mResourceGroups.end(); iter2++)
1332  {
1333  envDebugLog("group(%p): %s\r\n", iter2->second, iter2->first.c_str());
1334  }
1335  envDebugLog("------------------- ResourceManager: resources -----------------\r\n");
1336  ResourceMap::iterator iter3;
1337  ResourceMap::iterator iter4;
1338  for (iter3 = mResourcesById.begin();
1339  iter3 != mResourcesById.end(); iter3++)
1340  {
1341  ResourceMap::iterator iter4;
1342  std::string path;
1343  for (iter4 = mResourcesById.begin(); iter4 != mResourcesById.end(); iter4++)
1344  {
1345  if (iter4->second == iter3->second)
1346  {
1347  path = iter4->first;
1348  break;
1349  }
1350  }
1351 
1352  envDebugLog("resource(%p): %s=%s\r\n", iter3->second,
1353  iter3->first.c_str(), path.c_str());
1354  }
1355  envDebugLog("===============================================================\r\n");
1356 }
Interface representing a ResourceGroup within a resource file.
Definition: ResourceGroup.h:50
virtual ~ResourceManager()
Destructor.
Resource type: TmxTileMap.
Definition: HFDataTypes.h:669
Font type: hfbmfont text descriptor (engine tool &#39;src/tools/hfbmfont&#39;).
Font type: hfbmfont xml descriptor (engine tool &#39;src/tools/hfbmfont&#39;).
Interface for Resource type Sound.
bool getIsManuallyLoaded()
Determines whether Resource has been manually loaded.
Definition: Resource.cpp:90
virtual Image * getImage(const std::string &id)
Get Image by it&#39;s id.
Interface for unicode string class UString.
Definition: UString.h:35
void addResourcePath(const std::string &path)
Add a path to internal resource path vector.
#define HF_SAFE_DELETE(p)
Check if not NULL, delete and set to NULL.
Definition: HFDataTypes.h:49
int int32_hf
A type definition for int.
Definition: HFDataTypes.h:349
virtual bool load()
This method handles the loading and calls init() if internal refCount is 0, otherwise refCount is inc...
Definition: Resource.cpp:41
virtual void destroyManuallyLoadedResources()
Destroy and remove from map all manually loaded Resource&#39;s (those with Resource::getIsManuallyLoaded(...
virtual Shader * getShaderFromSource(const std::string &vertexShaderSrc, const std::string &fragmentShaderSrc, const std::string &entryFunctionVS="main", const std::string &compileVersionVS="vs_3_0", const std::string &entryFunctionFS="main", const std::string &compileVersionFS="ps_3_0")
Get Shader from given source code.
virtual ResourceGroup * getResourceGroup(const std::string &groupName)
Get a pointer to ResourceGroup for given groupName.
virtual bool parseResourceFile(const std::string &fileName)
Parse resource file and all of its ResourceGroup&#39;s.
Resource type: ImageAtlas.
Definition: HFDataTypes.h:666
Interface representing a ResourceGroup within a resource file.
Interface useful for AES encryption / decryption and for cryptographic hash checksums.
virtual Sound * getSound(const std::string &id)
Get Sound by it&#39;s id.
Interface for unicode string stream class UStringStream.
bool isEmpty()
Determines if internal resource path vector is empty.
Definition: ResourceGroup.h:68
virtual UString getString(const std::string &id)
Get UString by it&#39;s id.
virtual bool loadResourceGroup(const std::string &groupName)
Load ResourceGroup named groupName and call Resource::load() for each item in group.
virtual Image * createImage(const std::string &filename)=0
Called from ResourceManager when needing to create the resource.
virtual HFModule::TmxMap * getTmxTileMap(const std::string &id)
Get HFModule::TmxMap by it&#39;s id.
virtual Shader * createShader(const std::string &path, Shader::Type type, const std::string &entryFunctionVS="main", const std::string &compileVersionVS="vs_3_0", const std::string &entryFunctionFS="main", const std::string &compileVersionFS="ps_3_0")=0
Called from ResourceManager when needing to create the resource.
virtual void initResources(bool includeSounds)
Iterate through all Resource&#39;s in ResourceManager::ResourceMap and call Resource::init().
bool isLoaded()
Determines whether Resource is loaded (refCount > 0).
Definition: Resource.cpp:80
Interface for Resource type WavefrontOBJ.
Definition: WavefrontOBJ.h:186
static std::string StringToLower(const std::string &string)
Convert string to lowercase.
Definition: StringUtil.cpp:462
Font type: hfbmfont binary descriptor (engine tool &#39;src/tools/hfbmfont&#39;).
Vertex and Fragment (pixel) shader.
Definition: Shader.h:116
Interface for unicode string stream class UStringStream.
Definition: UStringStream.h:70
virtual void unloadResourceGroup(const std::string &groupName)
Unload ResourceGroup named groupName and call Resource::release() for each item in group...
Interface for Resource type Sound.
Definition: Sound.h:64
virtual Shader * getShader(const std::string &id)
Get Shader by it&#39;s id.
Resource type: Image.
Definition: HFDataTypes.h:665
virtual void reloadResources()
Iterate through all Resource&#39;s in ResourceManager::ResourceMap and call Resource::reload().
Resource type: Shader.
Definition: HFDataTypes.h:670
Interface for Resource type Image.
Type
Types of shaders enum.
Definition: Shader.h:114
#define NULL
Convenient define for 0.
Definition: HFDataTypes.h:42
wchar_t skipUntil(const UString &delimiters)
Skip until reaching delimeters.
Interface for Resource base class.
virtual Image * getImageFromPath(const std::string &path)
Load Image from given path.
ResourceManager(ResourceLoader *loader, const std::string &language)
Constructor.
Resource type: Font.
Definition: HFDataTypes.h:668
int32_hf length() const
Get the length of the string.
Definition: UString.cpp:178
const int8_hf * toUtf8() const
Get the utf8 encoded string.
Definition: UString.cpp:574
virtual void destroyManuallyLoadedResourcesByType(HF_ResourceType type)
Destroy and remove from map all manually loaded Resource&#39;s (those with Resource::getIsManuallyLoaded(...
virtual Sound * createSound(const std::string &filename)=0
Called from ResourceManager when needing to create the resource.
virtual void destroyResource(Resource *res)
Destroy a Resource and remove from internal map.
char int8_hf
A type definition for char.
Definition: HFDataTypes.h:329
Interface for Resource base class.
Definition: Resource.h:39
virtual Font * getFontFromPath(const std::string &path)
Load Font from given path.
virtual HF_ResourceType getResourceType()=0
This method should be implemented by those who inherit and it&#39;s purpose is to return HF_ResourceType ...
const std::string * getNextPath()
Get the next path from internal resource path vector.
virtual bool hasString(const std::string &id)
Determines whether string with id exists.
virtual Font * getFont(const std::string &id)
Get Font by it&#39;s id.
virtual void destroyResources(bool includeSounds)
Iterate through all Resource&#39;s in ResourceManager::ResourceMap and call Resource::destroy().
virtual void release()
This method handles the unloading and call destroy() if internal refCount is 0.
Definition: Resource.cpp:63
Interface for Resource type ImageAtlas.
Definition: ImageAtlas.h:78
virtual ImageAtlas * getImageAtlasFromPath(const std::string &path)
Load ImageAtlas from given path.
void setIsManuallyLoaded(bool isManuallyLoaded)
Use this method to indicate that the Resource is manually loaded.
Definition: Resource.cpp:85
Interface for Resource type Shader.
Definition: Shader.h:108
virtual Shader * createShaderFromSource(const std::string &vertexShaderSrc, const std::string &fragmentShaderSrc, const std::string &entryFunctionVS="main", const std::string &compileVersionVS="vs_3_0", const std::string &entryFunctionFS="main", const std::string &compileVersionFS="ps_3_0")=0
Called from ResourceManager when needing to create the resource.
Interface for ResourceManager which handles all Resource loading etc.
Definition: Actor.h:34
Interface for Resource type Image.
Definition: Image.h:63
std::string compileVersion
Shader compile version.
Interface for Resource type Font.
Definition: Font.h:84
virtual WavefrontOBJ * getWavefrontOBJFromPath(const std::string &path)
Load WavefrontOBJ from given path.
Singleton interface for platform specific things.
std::vector< std::string > StringVector
typedef for Vector holding std::string.
Definition: StringUtil.h:58
Interface for Image and Sound loading (called from ResourceManager).
void getAllSounds(std::vector< Sound *> &sounds)
Get all Sound&#39;s in a convenient vector.
#define envEngineLog(format, args...)
Shortcut macro for logging to &#39;engine.log&#39;.
Definition: Environment.h:2369
static std::string sha256sum(const std::string &s)
Get the sha256 checksum hash as hex representation for input s.
Definition: Crypto.cpp:185
#define HFCORE_FDU
Get HFCore::FileDirUtils instance shortcut macro.
Definition: Environment.h:83
Interface for Image and Sound loading (called from ResourceManager).
virtual WavefrontOBJ * getWavefrontOBJ(const std::string &id)
Get WavefrontOBJ by it&#39;s id.
#define HFCORE_ENV
Get HFCore::Environment instance shortcut macro.
Definition: Environment.h:68
Shader compile info struct (used for Windows Direct3D).
virtual Shader * getShaderFromPath(const std::string &path, Shader::Type type, const std::string &entryFunctionVS="main", const std::string &compileVersionVS="vs_3_0", const std::string &entryFunctionFS="main", const std::string &compileVersionFS="ps_3_0")
Get Shader from given path.
HF_ResourceType
Resource type enum.
Definition: HFDataTypes.h:663
virtual HFModule::TmxMap * getTmxTileMapFromPath(const std::string &path)
Load HFModule::TmxMap from given path.
const std::string * getFirstPath()
Get the first path from internal resource path vector.
#define envDebugLog(format, args...)
Shortcut macro for logging to &#39;debug.log&#39;.
Definition: Environment.h:2364
virtual ImageAtlas * getImageAtlas(const std::string &id)
Get ImageAtlas by it&#39;s id.
void dump()
Dump parsed resource files names, ResourceGroup&#39;s names and Resource&#39;s string ids (useful for Debug)...
std::string entryFunction
Shader entry point function.
Resource type: Sound.
Definition: HFDataTypes.h:667
Interface useful for generic directory and file operations.