ShapeAsset.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SHAPE_ASSET_H_
  23. #include "ShapeAsset.h"
  24. #endif
  25. #ifndef _ASSET_MANAGER_H_
  26. #include "assets/assetManager.h"
  27. #endif
  28. #ifndef _CONSOLETYPES_H_
  29. #include "console/consoleTypes.h"
  30. #endif
  31. #ifndef _TAML_
  32. #include "persistence/taml/taml.h"
  33. #endif
  34. #ifndef _ASSET_PTR_H_
  35. #include "assets/assetPtr.h"
  36. #endif
  37. #include "core/resourceManager.h"
  38. // Debug Profiling.
  39. #include "platform/profiler.h"
  40. static U32 execDepth = 0;
  41. static U32 journalDepth = 1;
  42. //-----------------------------------------------------------------------------
  43. IMPLEMENT_CONOBJECT(ShapeAsset);
  44. ConsoleType(TestAssetPtr, TypeShapeAssetPtr, ShapeAsset, ASSET_ID_FIELD_PREFIX)
  45. //-----------------------------------------------------------------------------
  46. ConsoleGetType(TypeShapeAssetPtr)
  47. {
  48. // Fetch asset Id.
  49. return (*((AssetPtr<ShapeAsset>*)dptr)).getAssetId();
  50. }
  51. //-----------------------------------------------------------------------------
  52. ConsoleSetType(TypeShapeAssetPtr)
  53. {
  54. // Was a single argument specified?
  55. if (argc == 1)
  56. {
  57. // Yes, so fetch field value.
  58. const char* pFieldValue = argv[0];
  59. // Fetch asset pointer.
  60. AssetPtr<ShapeAsset>* pAssetPtr = dynamic_cast<AssetPtr<ShapeAsset>*>((AssetPtrBase*)(dptr));
  61. // Is the asset pointer the correct type?
  62. if (pAssetPtr == NULL)
  63. {
  64. // No, so fail.
  65. //Con::warnf("(TypeTextureAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
  66. return;
  67. }
  68. // Set asset.
  69. pAssetPtr->setAssetId(pFieldValue);
  70. return;
  71. }
  72. // Warn.
  73. Con::warnf("(TypeTextureAssetPtr) - Cannot set multiple args to a single asset.");
  74. }
  75. //-----------------------------------------------------------------------------
  76. ShapeAsset::ShapeAsset() :
  77. mAcquireReferenceCount(0),
  78. mpOwningAssetManager(NULL),
  79. mAssetInitialized(false)
  80. {
  81. }
  82. //-----------------------------------------------------------------------------
  83. ShapeAsset::~ShapeAsset()
  84. {
  85. // If the asset manager does not own the asset then we own the
  86. // asset definition so delete it.
  87. if (!getOwned())
  88. delete mpAssetDefinition;
  89. }
  90. //-----------------------------------------------------------------------------
  91. void ShapeAsset::initPersistFields()
  92. {
  93. // Call parent.
  94. Parent::initPersistFields();
  95. addField("fileName", TypeFilename, Offset(mFileName, ShapeAsset), "Path to the script file we want to execute");
  96. }
  97. void ShapeAsset::initializeAsset()
  98. {
  99. // Call parent.
  100. Parent::initializeAsset();
  101. if (dStrcmp(mFileName, "") == 0)
  102. return;
  103. loadShape();
  104. }
  105. bool ShapeAsset::loadShape()
  106. {
  107. mShape = ResourceManager::get().load(mFileName);
  108. if (!mShape)
  109. {
  110. Con::errorf("StaticMesh::updateShape : failed to load shape file!");
  111. return false; //if it failed to load, bail out
  112. }
  113. return true;
  114. }
  115. //------------------------------------------------------------------------------
  116. void ShapeAsset::copyTo(SimObject* object)
  117. {
  118. // Call to parent.
  119. Parent::copyTo(object);
  120. }
  121. void ShapeAsset::onAssetRefresh(void)
  122. {
  123. }