LevelAsset.cpp

Engine/source/T3D/assets/LevelAsset.cpp

More...

Public Functions

ConsoleSetType(TypeLevelAssetPtr )
ConsoleType(LevelAssetPtr , TypeLevelAssetPtr , String , ASSET_ID_FIELD_PREFIX )
DefineEngineMethod(LevelAsset , getDecalsPath , const char * , () , "Gets the full path of the asset's defined decal <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the decal path" )
DefineEngineMethod(LevelAsset , getLevelPath , const char * , () , "Gets the full path of the asset's defined level <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the level path" )
DefineEngineMethod(LevelAsset , getPostFXPresetPath , const char * , () , "Gets the full path of the asset's defined postFX preset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the postFX preset path" )
DefineEngineMethod(LevelAsset , getPreviewImagePath , const char * , () , "Gets the full path of the asset's defined preview image <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the level preview image path" )
DefineEngineMethod(LevelAsset , loadDependencies , void , () , "Initiates the loading of asset dependencies <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this level." )
DefineEngineMethod(LevelAsset , unloadDependencies , void , () , "Initiates the unloading of previously loaded asset dependencies <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this level." )

Detailed Description

Public Functions

ConsoleSetType(TypeLevelAssetPtr )

ConsoleType(LevelAssetPtr , TypeLevelAssetPtr , String , ASSET_ID_FIELD_PREFIX )

DefineEngineMethod(LevelAsset , getDecalsPath , const char * , () , "Gets the full path of the asset's defined decal <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the decal path" )

DefineEngineMethod(LevelAsset , getLevelPath , const char * , () , "Gets the full path of the asset's defined level <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the level path" )

DefineEngineMethod(LevelAsset , getPostFXPresetPath , const char * , () , "Gets the full path of the asset's defined postFX preset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the postFX preset path" )

DefineEngineMethod(LevelAsset , getPreviewImagePath , const char * , () , "Gets the full path of the asset's defined preview image <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">file.\n</a>" "@return The string result of the level preview image path" )

DefineEngineMethod(LevelAsset , loadDependencies , void , () , "Initiates the loading of asset dependencies <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this level." )

DefineEngineMethod(LevelAsset , unloadDependencies , void , () , "Initiates the unloading of previously loaded asset dependencies <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this level." )

IMPLEMENT_CONOBJECT(LevelAsset )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef LEVEL_ASSET_H
 25#include "LevelAsset.h"
 26#endif
 27
 28#ifndef _ASSET_MANAGER_H_
 29#include "assets/assetManager.h"
 30#endif
 31
 32#ifndef _CONSOLETYPES_H_
 33#include "console/consoleTypes.h"
 34#endif
 35
 36#ifndef _TAML_
 37#include "persistence/taml/taml.h"
 38#endif
 39
 40#ifndef _ASSET_PTR_H_
 41#include "assets/assetPtr.h"
 42#endif
 43
 44// Debug Profiling.
 45#include "platform/profiler.h"
 46
 47//-----------------------------------------------------------------------------
 48
 49IMPLEMENT_CONOBJECT(LevelAsset);
 50
 51ConsoleType(LevelAssetPtr, TypeLevelAssetPtr, String, ASSET_ID_FIELD_PREFIX)
 52
 53//-----------------------------------------------------------------------------
 54
 55ConsoleGetType(TypeLevelAssetPtr)
 56{
 57   // Fetch asset Id.
 58   return *((StringTableEntry*)dptr);
 59}
 60
 61//-----------------------------------------------------------------------------
 62
 63ConsoleSetType(TypeLevelAssetPtr)
 64{
 65   // Was a single argument specified?
 66   if (argc == 1)
 67   {
 68      // Yes, so fetch field value.
 69      const char* pFieldValue = argv[0];
 70
 71      // Fetch asset Id.
 72      StringTableEntry* assetId = (StringTableEntry*)(dptr);
 73
 74      // Update asset value.
 75      *assetId = StringTable->insert(pFieldValue);
 76
 77      return;
 78   }
 79
 80   // Warn.
 81   Con::warnf("(TypeLevelAssetPtr) - Cannot set multiple args to a single asset.");
 82}
 83
 84//-----------------------------------------------------------------------------
 85
 86LevelAsset::LevelAsset() : AssetBase(), mIsSubLevel(false)
 87{
 88   mLevelName = StringTable->EmptyString();
 89   mLevelFile = StringTable->EmptyString();
 90   mPreviewImage = StringTable->EmptyString();
 91   mPostFXPresetFile = StringTable->EmptyString();
 92   mDecalsFile = StringTable->EmptyString();
 93   mForestFile = StringTable->EmptyString();
 94   mNavmeshFile = StringTable->EmptyString();
 95
 96   mLevelPath = StringTable->EmptyString();
 97   mPreviewImagePath = StringTable->EmptyString();
 98   mPostFXPresetPath = StringTable->EmptyString();
 99   mDecalsPath = StringTable->EmptyString();
100   mForestPath = StringTable->EmptyString();
101   mNavmeshPath = StringTable->EmptyString();
102
103   mGamemodeName = StringTable->EmptyString();
104   mMainLevelAsset = StringTable->EmptyString();
105
106   mEditorFile = StringTable->EmptyString();
107   mBakedSceneFile = StringTable->EmptyString();
108}
109
110//-----------------------------------------------------------------------------
111
112LevelAsset::~LevelAsset()
113{
114}
115
116//-----------------------------------------------------------------------------
117
118void LevelAsset::initPersistFields()
119{
120   // Call parent.
121   Parent::initPersistFields();
122
123   addProtectedField("LevelFile", TypeAssetLooseFilePath, Offset(mLevelFile, LevelAsset),
124      &setLevelFile, &getLevelFile, "Path to the actual level file.");
125   addField("LevelName", TypeString, Offset(mLevelName, LevelAsset), "Human-friendly name for the level.");
126   addProtectedField("PreviewImage", TypeAssetLooseFilePath, Offset(mPreviewImage, LevelAsset),
127      &setPreviewImageFile, &getPreviewImageFile, "Path to the image used for selection preview.");
128
129   addProtectedField("PostFXPresetFile", TypeAssetLooseFilePath, Offset(mPostFXPresetFile, LevelAsset),
130      &setPostFXPresetFile, &getPostFXPresetFile, "Path to the level's postFXPreset.");
131   addProtectedField("DecalsFile", TypeAssetLooseFilePath, Offset(mDecalsFile, LevelAsset),
132      &setDecalsFile, &getDecalsFile, "Path to the decals cache file.");
133   addProtectedField("ForestFile", TypeAssetLooseFilePath, Offset(mForestFile, LevelAsset),
134      &setForestFile, &getForestFile, "Path to the Forest cache file.");
135   addProtectedField("NavmeshFile", TypeAssetLooseFilePath, Offset(mNavmeshFile, LevelAsset),
136      &setNavmeshFile, &getNavmeshFile, "Path to the navmesh file.");
137
138   addProtectedField("EditorFile", TypeAssetLooseFilePath, Offset(mEditorFile, LevelAsset),
139      &setEditorFile, &getEditorFile, "Path to the level file with objects that were removed as part of the baking process. Loaded when the editor is loaded for ease of editing.");
140   addProtectedField("BakedSceneFile", TypeAssetLooseFilePath, Offset(mBakedSceneFile, LevelAsset),
141      &setBakedSceneFile, &getBakedSceneFile, "Path to the level file with the objects generated as part of the baking process");
142
143   addField("isSubScene", TypeBool, Offset(mIsSubLevel, LevelAsset), "Is this a sublevel to another Scene");
144   addField("gameModeName", TypeString, Offset(mGamemodeName, LevelAsset), "Name of the Game Mode to be used with this level");
145}
146
147//------------------------------------------------------------------------------
148
149void LevelAsset::copyTo(SimObject* object)
150{
151   // Call to parent.
152   Parent::copyTo(object);
153}
154
155//
156void LevelAsset::initializeAsset()
157{
158   // Call parent.
159   Parent::initializeAsset();
160
161   // Ensure the image-file is expanded.
162   mPreviewImagePath = expandAssetFilePath(mPreviewImage);
163   mLevelPath = expandAssetFilePath(mLevelFile);
164   mPostFXPresetPath = expandAssetFilePath(mPostFXPresetFile);
165   mDecalsPath = expandAssetFilePath(mDecalsFile);
166   mForestPath = expandAssetFilePath(mForestFile);
167   mNavmeshPath = expandAssetFilePath(mNavmeshFile);
168}
169
170void LevelAsset::onAssetRefresh(void)
171{
172   // Ensure the image-file is expanded.
173   mPreviewImagePath = expandAssetFilePath(mPreviewImage);
174   mLevelPath = expandAssetFilePath(mLevelFile);
175   mPostFXPresetPath = expandAssetFilePath(mPostFXPresetFile);
176   mDecalsPath = expandAssetFilePath(mDecalsFile);
177   mForestPath = expandAssetFilePath(mForestFile);
178   mNavmeshPath = expandAssetFilePath(mNavmeshFile);
179}
180
181//
182void LevelAsset::setLevelFile(const char* pLevelFile)
183{
184   // Sanity!
185   AssertFatal(pLevelFile != NULL, "Cannot use a NULL level file.");
186
187   // Fetch image file.
188   pLevelFile = StringTable->insert(pLevelFile);
189
190   // Ignore no change,
191   if (pLevelFile == mLevelFile)
192      return;
193
194   // Update.
195   mLevelFile = pLevelFile;
196
197   // Refresh the asset.
198   refreshAsset();
199}
200
201void LevelAsset::setImageFile(const char* pImageFile)
202{
203   // Sanity!
204   AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
205
206   // Fetch image file.
207   pImageFile = StringTable->insert(pImageFile);
208
209   // Ignore no change,
210   if (pImageFile == mPreviewImage)
211      return;
212
213   // Update.
214   mPreviewImage = pImageFile;
215
216   // Refresh the asset.
217   refreshAsset();
218}
219
220void LevelAsset::setEditorFile(const char* pEditorFile)
221{
222   // Sanity!
223   AssertFatal(pEditorFile != NULL, "Cannot use a NULL level file.");
224
225   // Fetch image file.
226   pEditorFile = StringTable->insert(pEditorFile);
227
228   // Ignore no change,
229   if (pEditorFile == mEditorFile)
230      return;
231
232   // Update.
233   mEditorFile = pEditorFile;
234
235   // Refresh the asset.
236   refreshAsset();
237}
238
239void LevelAsset::setBakedSceneFile(const char* pBakedSceneFile)
240{
241   // Sanity!
242   AssertFatal(pBakedSceneFile != NULL, "Cannot use a NULL level file.");
243
244   // Fetch image file.
245   pBakedSceneFile = StringTable->insert(pBakedSceneFile);
246
247   // Ignore no change,
248   if (pBakedSceneFile == mBakedSceneFile)
249      return;
250
251   // Update.
252   mBakedSceneFile = pBakedSceneFile;
253
254   // Refresh the asset.
255   refreshAsset();
256}
257
258void LevelAsset::setPostFXPresetFile(const char* pPostFXPresetFile)
259{
260   // Sanity!
261   AssertFatal(pPostFXPresetFile != NULL, "Cannot use a NULL postFX preset file.");
262
263   // Fetch file.
264   pPostFXPresetFile = StringTable->insert(pPostFXPresetFile);
265
266   // Ignore no change,
267   if (pPostFXPresetFile == mPostFXPresetFile)
268      return;
269
270   // Update.
271   mPostFXPresetFile = pPostFXPresetFile;
272
273   // Refresh the asset.
274   refreshAsset();
275}
276
277void LevelAsset::setDecalsFile(const char* pDecalsFile)
278{
279   // Sanity!
280   AssertFatal(pDecalsFile != NULL, "Cannot use a NULL decals file.");
281
282   // Fetch file.
283   pDecalsFile = StringTable->insert(pDecalsFile);
284
285   // Ignore no change,
286   if (pDecalsFile == mDecalsFile)
287      return;
288
289   // Update.
290   mDecalsFile = pDecalsFile;
291
292   // Refresh the asset.
293   refreshAsset();
294}
295
296void LevelAsset::setForestFile(const char* pForestFile)
297{
298   // Sanity!
299   AssertFatal(pForestFile != NULL, "Cannot use a NULL decals file.");
300
301   // Fetch file.
302   pForestFile = StringTable->insert(pForestFile);
303
304   // Ignore no change,
305   if (pForestFile == mForestFile)
306      return;
307
308   // Update.
309   mForestFile = pForestFile;
310
311   // Refresh the asset.
312   refreshAsset();
313}
314
315void LevelAsset::setNavmeshFile(const char* pNavmeshFile)
316{
317   // Sanity!
318   AssertFatal(pNavmeshFile != NULL, "Cannot use a NULL Navmesh file.");
319
320   // Fetch file.
321   pNavmeshFile = StringTable->insert(pNavmeshFile);
322
323   // Ignore no change,
324   if (pNavmeshFile == mNavmeshFile)
325      return;
326
327   // Update.
328   mNavmeshFile = pNavmeshFile;
329
330   // Refresh the asset.
331   refreshAsset();
332}
333
334void LevelAsset::loadDependencies()
335{
336   //First, load any material, animation, etc assets we may be referencing in our asset
337   // Find any asset dependencies.
338   AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
339
340   // Does the asset have any dependencies?
341   if (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end())
342   {
343      // Iterate all dependencies.
344      while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId)
345      {
346         //Force it to be loaded by acquiring it
347         StringTableEntry assetId = assetDependenciesItr->value;
348         mAssetDependencies.push_back(AssetDatabase.acquireAsset<AssetBase>(assetId));
349
350         // Next dependency.
351         assetDependenciesItr++;
352      }
353   }
354}
355
356void LevelAsset::unloadDependencies()
357{
358   for (U32 i = 0; i < mAssetDependencies.size(); i++)
359   {
360      AssetBase* assetDef = mAssetDependencies[i];
361      AssetDatabase.releaseAsset(assetDef->getAssetId());
362   }
363}
364
365DefineEngineMethod(LevelAsset, getLevelPath, const char*, (),,
366   "Gets the full path of the asset's defined level file.\n"
367   "@return The string result of the level path")
368{
369   return object->getLevelPath();
370}
371
372DefineEngineMethod(LevelAsset, getPreviewImagePath, const char*, (), ,
373   "Gets the full path of the asset's defined preview image file.\n"
374   "@return The string result of the level preview image path")
375{
376   return object->getImagePath();
377}
378
379DefineEngineMethod(LevelAsset, getPostFXPresetPath, const char*, (), ,
380   "Gets the full path of the asset's defined postFX preset file.\n"
381   "@return The string result of the postFX preset path")
382{
383   return object->getPostFXPresetPath();
384}
385
386DefineEngineMethod(LevelAsset, getDecalsPath, const char*, (), ,
387   "Gets the full path of the asset's defined decal file.\n"
388   "@return The string result of the decal path")
389{
390   return object->getDecalsPath();
391}
392
393DefineEngineMethod(LevelAsset, loadDependencies, void, (), ,
394   "Initiates the loading of asset dependencies for this level.")
395{
396   return object->loadDependencies();
397}
398
399DefineEngineMethod(LevelAsset, unloadDependencies, void, (), ,
400   "Initiates the unloading of previously loaded asset dependencies for this level.")
401{
402   return object->unloadDependencies();
403}
404