CppAsset.cpp

Engine/source/T3D/assets/CppAsset.cpp

More...

Public Functions

ConsoleSetType(TypeCppAssetPtr )
ConsoleType(CppAssetPtr , TypeCppAssetPtr , CppAsset , ASSET_ID_FIELD_PREFIX )

Detailed Description

Public Functions

ConsoleSetType(TypeCppAssetPtr )

ConsoleType(CppAssetPtr , TypeCppAssetPtr , CppAsset , ASSET_ID_FIELD_PREFIX )

IMPLEMENT_CONOBJECT(CppAsset )

  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#ifndef CPP_ASSET_H
 24#include "CppAsset.h"
 25#endif
 26
 27#ifndef _ASSET_MANAGER_H_
 28#include "assets/assetManager.h"
 29#endif
 30
 31#ifndef _CONSOLETYPES_H_
 32#include "console/consoleTypes.h"
 33#endif
 34
 35#ifndef _TAML_
 36#include "persistence/taml/taml.h"
 37#endif
 38
 39#ifndef _ASSET_PTR_H_
 40#include "assets/assetPtr.h"
 41#endif
 42
 43// Debug Profiling.
 44#include "platform/profiler.h"
 45
 46//-----------------------------------------------------------------------------
 47
 48IMPLEMENT_CONOBJECT(CppAsset);
 49
 50ConsoleType(CppAssetPtr, TypeCppAssetPtr, CppAsset, ASSET_ID_FIELD_PREFIX)
 51
 52//-----------------------------------------------------------------------------
 53
 54ConsoleGetType(TypeCppAssetPtr)
 55{
 56   // Fetch asset Id.
 57   return (*((AssetPtr<CppAsset>*)dptr)).getAssetId();
 58}
 59
 60//-----------------------------------------------------------------------------
 61
 62ConsoleSetType(TypeCppAssetPtr)
 63{
 64   // Was a single argument specified?
 65   if (argc == 1)
 66   {
 67      // Yes, so fetch field value.
 68      const char* pFieldValue = argv[0];
 69
 70      // Fetch asset pointer.
 71      AssetPtr<CppAsset>* pAssetPtr = dynamic_cast<AssetPtr<CppAsset>*>((AssetPtrBase*)(dptr));
 72
 73      // Is the asset pointer the correct type?
 74      if (pAssetPtr == NULL)
 75      {
 76         // No, so fail.
 77         //Con::warnf("(TypeCppAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
 78         return;
 79      }
 80
 81      // Set asset.
 82      pAssetPtr->setAssetId(pFieldValue);
 83
 84      return;
 85   }
 86
 87   // Warn.
 88   Con::warnf("(TypeCppAssetPtr) - Cannot set multiple args to a single asset.");
 89}
 90
 91//-----------------------------------------------------------------------------
 92
 93CppAsset::CppAsset() : AssetBase()
 94{
 95   mCodeFile = StringTable->EmptyString();
 96   mHeaderFile = StringTable->EmptyString();
 97   mCodePath = StringTable->EmptyString();
 98   mHeaderPath = StringTable->EmptyString();
 99}
100
101//-----------------------------------------------------------------------------
102
103CppAsset::~CppAsset()
104{
105}
106
107//-----------------------------------------------------------------------------
108
109void CppAsset::initPersistFields()
110{
111   // Call parent.
112   Parent::initPersistFields();
113
114   addProtectedField("codeFile", TypeAssetLooseFilePath, Offset(mCodeFile, CppAsset),
115      &setCppFile, &getCppFile, "Path to the cpp file.");
116
117   addProtectedField("headerFile", TypeAssetLooseFilePath, Offset(mHeaderFile, CppAsset),
118      &setHeaderFile, &getHeaderFile, "Path to the h file.");
119
120}
121
122//------------------------------------------------------------------------------
123
124void CppAsset::copyTo(SimObject* object)
125{
126   // Call to parent.
127   Parent::copyTo(object);
128}
129
130void CppAsset::setCppFile(const char* pCppFile)
131{
132   // Sanity!
133   AssertFatal(pCppFile != NULL, "Cannot use a NULL code file.");
134
135   // Fetch image file.
136   pCppFile = StringTable->insert(pCppFile);
137
138   // Ignore no change,
139   if (pCppFile == mCodeFile)
140      return;
141
142   // Update.
143   mCodeFile = /*getOwned() ? expandAssetFilePath(pCppFile) : */StringTable->insert(pCppFile);
144
145   // Refresh the asset.
146   refreshAsset();
147}
148
149void CppAsset::setHeaderFile(const char* pHeaderFile)
150{
151   // Sanity!
152   AssertFatal(pHeaderFile != NULL, "Cannot use a NULL header file.");
153
154   // Fetch image file.
155   pHeaderFile = StringTable->insert(pHeaderFile);
156
157   // Ignore no change,
158   if (pHeaderFile == mHeaderFile)
159      return;
160
161   // Update.
162   mHeaderFile = /*getOwned() ? expandAssetFilePath(pHeaderFile) :*/ StringTable->insert(pHeaderFile);
163
164   // Refresh the asset.
165   refreshAsset();
166}
167
168void CppAsset::initializeAsset()
169{
170   mCodePath = getOwned() ? expandAssetFilePath(mCodeFile) : mCodePath;
171
172   mHeaderPath = getOwned() ? expandAssetFilePath(mHeaderFile) : mHeaderPath;
173}
174
175void CppAsset::onAssetRefresh(void)
176{
177   mCodePath = getOwned() ? expandAssetFilePath(mCodeFile) : mCodePath;
178
179   mHeaderPath = getOwned() ? expandAssetFilePath(mHeaderFile) : mHeaderPath;
180}
181