diff --git a/Engine/source/T3D/assets/ComponentAsset.cpp b/Engine/source/T3D/assets/ComponentAsset.cpp index b329d391f..83045832e 100644 --- a/Engine/source/T3D/assets/ComponentAsset.cpp +++ b/Engine/source/T3D/assets/ComponentAsset.cpp @@ -74,7 +74,7 @@ ConsoleSetType(TypeComponentAssetPtr) if (pAssetPtr == NULL) { // No, so fail. - //Con::warnf("(TypeTextureAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + //Con::warnf("(TypeComponentAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); return; } @@ -85,24 +85,20 @@ ConsoleSetType(TypeComponentAssetPtr) } // Warn. - Con::warnf("(TypeTextureAssetPtr) - Cannot set multiple args to a single asset."); + Con::warnf("(TypeComponentAssetPtr) - Cannot set multiple args to a single asset."); } //----------------------------------------------------------------------------- -ComponentAsset::ComponentAsset() : - mpOwningAssetManager(NULL), - mAssetInitialized(false), - mAcquireReferenceCount(0) +ComponentAsset::ComponentAsset() { - // Generate an asset definition. - mpAssetDefinition = new AssetDefinition(); + mComponentName = StringTable->EmptyString(); + mComponentClass = StringTable->EmptyString(); + mFriendlyName = StringTable->EmptyString(); + mComponentType = StringTable->EmptyString(); + mDescription = StringTable->EmptyString(); - mComponentName = StringTable->lookup(""); - mComponentClass = StringTable->lookup(""); - mFriendlyName = StringTable->lookup(""); - mComponentType = StringTable->lookup(""); - mDescription = StringTable->lookup(""); + mScriptFile = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -127,6 +123,8 @@ void ComponentAsset::initPersistFields() addField("friendlyName", TypeString, Offset(mFriendlyName, ComponentAsset), "The human-readble name for the component."); addField("componentType", TypeString, Offset(mComponentType, ComponentAsset), "The category of the component for organizing in the editor."); addField("description", TypeString, Offset(mDescription, ComponentAsset), "Simple description of the component."); + + addField("scriptFile", TypeString, Offset(mScriptFile, ComponentAsset), "A script file with additional scripted functionality for this component."); } //------------------------------------------------------------------------------ @@ -135,4 +133,16 @@ void ComponentAsset::copyTo(SimObject* object) { // Call to parent. Parent::copyTo(object); +} + +void ComponentAsset::initializeAsset() +{ + if(Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); +} + +void ComponentAsset::onAssetRefresh() +{ + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); } \ No newline at end of file diff --git a/Engine/source/T3D/assets/ComponentAsset.h b/Engine/source/T3D/assets/ComponentAsset.h index 1db53b8c8..9d803970b 100644 --- a/Engine/source/T3D/assets/ComponentAsset.h +++ b/Engine/source/T3D/assets/ComponentAsset.h @@ -44,17 +44,14 @@ class ComponentAsset : public AssetBase { typedef AssetBase Parent; - AssetManager* mpOwningAssetManager; - bool mAssetInitialized; - AssetDefinition* mpAssetDefinition; - U32 mAcquireReferenceCount; - StringTableEntry mComponentName; StringTableEntry mComponentClass; StringTableEntry mFriendlyName; StringTableEntry mComponentType; StringTableEntry mDescription; + StringTableEntry mScriptFile; + public: ComponentAsset(); virtual ~ComponentAsset(); @@ -69,12 +66,20 @@ public: StringTableEntry getComponentName() { return mComponentName; } StringTableEntry getComponentClass() { return mComponentClass; } StringTableEntry getFriendlyName() { return mFriendlyName; } - StringTableEntry getFriendlyType() { return mComponentType; } + StringTableEntry getComponentType() { return mComponentType; } StringTableEntry getDescription() { return mDescription; } + void setComponentName(StringTableEntry name) { mComponentName = name; } + void setComponentClass(StringTableEntry name) { mComponentClass = name; } + void setFriendlyName(StringTableEntry name) { mFriendlyName = name; } + void setComponentType(StringTableEntry typeName) { mComponentType = typeName; } + void setDescription(StringTableEntry description) { mDescription = description; } + + AssetDefinition* getAssetDefinition() { return mpAssetDefinition; } + protected: - virtual void initializeAsset(void) {} - virtual void onAssetRefresh(void) {} + virtual void initializeAsset(void); + virtual void onAssetRefresh(void); }; DefineConsoleType(TypeComponentAssetPtr, ComponentAsset) diff --git a/Engine/source/T3D/assets/ExampleAsset.cpp b/Engine/source/T3D/assets/ExampleAsset.cpp index eed7a4d19..b8c43ac07 100644 --- a/Engine/source/T3D/assets/ExampleAsset.cpp +++ b/Engine/source/T3D/assets/ExampleAsset.cpp @@ -74,7 +74,7 @@ ConsoleSetType(TypeExampleAssetPtr) if (pAssetPtr == NULL) { // No, so fail. - //Con::warnf("(TypeTextureAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + //Con::warnf("(TypeExampleAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); return; } @@ -85,18 +85,13 @@ ConsoleSetType(TypeExampleAssetPtr) } // Warn. - Con::warnf("(TypeTextureAssetPtr) - Cannot set multiple args to a single asset."); + Con::warnf("(TypeExampleAssetPtr) - Cannot set multiple args to a single asset."); } //----------------------------------------------------------------------------- -ExampleAsset::ExampleAsset() : -mpOwningAssetManager(NULL), -mAssetInitialized(false), -mAcquireReferenceCount(0) +ExampleAsset::ExampleAsset() { - // Generate an asset definition. - mpAssetDefinition = new AssetDefinition(); } //----------------------------------------------------------------------------- diff --git a/Engine/source/T3D/assets/ExampleAsset.h b/Engine/source/T3D/assets/ExampleAsset.h index 43532a6e5..b3a5a7695 100644 --- a/Engine/source/T3D/assets/ExampleAsset.h +++ b/Engine/source/T3D/assets/ExampleAsset.h @@ -43,11 +43,6 @@ class ExampleAsset : public AssetBase { typedef AssetBase Parent; - AssetManager* mpOwningAssetManager; - bool mAssetInitialized; - AssetDefinition* mpAssetDefinition; - U32 mAcquireReferenceCount; - public: ExampleAsset(); virtual ~ExampleAsset(); diff --git a/Engine/source/T3D/assets/GUIAsset.cpp b/Engine/source/T3D/assets/GUIAsset.cpp new file mode 100644 index 000000000..a011b56e3 --- /dev/null +++ b/Engine/source/T3D/assets/GUIAsset.cpp @@ -0,0 +1,222 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef GUI_ASSET_H +#include "GUIAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(GUIAsset); + +ConsoleType(GUIAssetPtr, TypeGUIAssetPtr, GUIAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeGUIAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeGUIAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeGUIAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeGUIAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +GUIAsset::GUIAsset() +{ + mScriptFilePath = StringTable->EmptyString(); + mGUIFilePath = StringTable->EmptyString(); +} + +//----------------------------------------------------------------------------- + +GUIAsset::~GUIAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void GUIAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("scriptFilePath", TypeString, Offset(mScriptFilePath, GUIAsset), "Path to the script file for the gui"); + addField("GUIFilePath", TypeString, Offset(mGUIFilePath, GUIAsset), "Path to the gui file"); +} + +//------------------------------------------------------------------------------ + +void GUIAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +void GUIAsset::initializeAsset() +{ + if (Platform::isFile(mGUIFilePath)) + Con::executeFile(mGUIFilePath, false, false); + + if (Platform::isFile(mScriptFilePath)) + Con::executeFile(mScriptFilePath, false, false); +} + +void GUIAsset::onAssetRefresh() +{ + if (Platform::isFile(mGUIFilePath)) + Con::executeFile(mGUIFilePath, false, false); + + if (Platform::isFile(mScriptFilePath)) + Con::executeFile(mScriptFilePath, false, false); +} + +//----------------------------------------------------------------------------- +// GuiInspectorTypeAssetId +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(GuiInspectorTypeGUIAssetPtr); + +ConsoleDocClass(GuiInspectorTypeGUIAssetPtr, + "@brief Inspector field type for GUI Asset Objects\n\n" + "Editor use only.\n\n" + "@internal" +); + +void GuiInspectorTypeGUIAssetPtr::consoleInit() +{ + Parent::consoleInit(); + + ConsoleBaseType::getType(TypeGUIAssetPtr)->setInspectorFieldType("GuiInspectorTypeGUIAssetPtr"); +} + +GuiControl* GuiInspectorTypeGUIAssetPtr::constructEditControl() +{ + // Create base filename edit controls + GuiControl *retCtrl = Parent::constructEditControl(); + if (retCtrl == NULL) + return retCtrl; + + // Change filespec + char szBuffer[512]; + dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"GUIAsset\", \"AssetBrowser.changeAsset\", %d, %s);", + mInspector->getComponentGroupTargetId(), mCaption); + mBrowseButton->setField("Command", szBuffer); + + // Create "Open in ShapeEditor" button + mSMEdButton = new GuiBitmapButtonCtrl(); + + dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId()); + mSMEdButton->setField("Command", szBuffer); + + char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; + mSMEdButton->setBitmap(bitmapName); + + mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); + mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor"); + + mSMEdButton->registerObject(); + addObject(mSMEdButton); + + return retCtrl; +} + +bool GuiInspectorTypeGUIAssetPtr::updateRects() +{ + S32 dividerPos, dividerMargin; + mInspector->getDivider(dividerPos, dividerMargin); + Point2I fieldExtent = getExtent(); + Point2I fieldPos = getPosition(); + + mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); + mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); + + bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); + if (mBrowseButton != NULL) + { + mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); + resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); + } + + if (mSMEdButton != NULL) + { + RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); + resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + } + + return resized; +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/GUIAsset.h b/Engine/source/T3D/assets/GUIAsset.h new file mode 100644 index 000000000..5668f9afd --- /dev/null +++ b/Engine/source/T3D/assets/GUIAsset.h @@ -0,0 +1,89 @@ +#pragma once +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef GUI_ASSET_H +#define GUI_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +#include "gui/editor/guiInspectorTypes.h" + +//----------------------------------------------------------------------------- +class GUIAsset : public AssetBase +{ + typedef AssetBase Parent; + + StringTableEntry mScriptFilePath; + StringTableEntry mGUIFilePath; + +public: + GUIAsset(); + virtual ~GUIAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(GUIAsset); + +protected: + virtual void initializeAsset(void); + virtual void onAssetRefresh(void); +}; + +DefineConsoleType(TypeGUIAssetPtr, GUIAsset) + + +//----------------------------------------------------------------------------- +// TypeAssetId GuiInspectorField Class +//----------------------------------------------------------------------------- +class GuiInspectorTypeGUIAssetPtr : public GuiInspectorTypeFileName +{ + typedef GuiInspectorTypeFileName Parent; +public: + + GuiBitmapButtonCtrl *mSMEdButton; + + DECLARE_CONOBJECT(GuiInspectorTypeGUIAssetPtr); + static void consoleInit(); + + virtual GuiControl* constructEditControl(); + virtual bool updateRects(); +}; + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/GameObjectAsset.cpp b/Engine/source/T3D/assets/GameObjectAsset.cpp index 6659504bd..45b33b086 100644 --- a/Engine/source/T3D/assets/GameObjectAsset.cpp +++ b/Engine/source/T3D/assets/GameObjectAsset.cpp @@ -74,7 +74,7 @@ ConsoleSetType(TypeGameObjectAssetPtr) if (pAssetPtr == NULL) { // No, so fail. - //Con::warnf("(TypeTextureAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + //Con::warnf("(TypeGameObjectAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); return; } @@ -85,19 +85,13 @@ ConsoleSetType(TypeGameObjectAssetPtr) } // Warn. - Con::warnf("(TypeTextureAssetPtr) - Cannot set multiple args to a single asset."); + Con::warnf("(TypeGameObjectAssetPtr) - Cannot set multiple args to a single asset."); } //----------------------------------------------------------------------------- -GameObjectAsset::GameObjectAsset() : - mpOwningAssetManager(NULL), - mAssetInitialized(false), - mAcquireReferenceCount(0) +GameObjectAsset::GameObjectAsset() { - // Generate an asset definition. - mpAssetDefinition = new AssetDefinition(); - mGameObjectName = StringTable->lookup(""); mScriptFilePath = StringTable->lookup(""); mTAMLFilePath = StringTable->lookup(""); @@ -131,4 +125,94 @@ void GameObjectAsset::copyTo(SimObject* object) { // Call to parent. Parent::copyTo(object); +} + +void GameObjectAsset::initializeAsset() +{ + if (Platform::isFile(mScriptFilePath)) + Con::executeFile(mScriptFilePath, false, false); +} + +void GameObjectAsset::onAssetRefresh() +{ + if (Platform::isFile(mScriptFilePath)) + Con::executeFile(mScriptFilePath, false, false); +} + +//----------------------------------------------------------------------------- +// GuiInspectorTypeAssetId +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(GuiInspectorTypeGameObjectAssetPtr); + +ConsoleDocClass(GuiInspectorTypeGameObjectAssetPtr, + "@brief Inspector field type for Game Objects\n\n" + "Editor use only.\n\n" + "@internal" +); + +void GuiInspectorTypeGameObjectAssetPtr::consoleInit() +{ + Parent::consoleInit(); + + ConsoleBaseType::getType(TypeGameObjectAssetPtr)->setInspectorFieldType("GuiInspectorTypeGameObjectAssetPtr"); +} + +GuiControl* GuiInspectorTypeGameObjectAssetPtr::constructEditControl() +{ + // Create base filename edit controls + GuiControl *retCtrl = Parent::constructEditControl(); + if (retCtrl == NULL) + return retCtrl; + + // Change filespec + char szBuffer[512]; + dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"GameObjectAsset\", \"AssetBrowser.changeAsset\", %d, %s);", + mInspector->getComponentGroupTargetId(), mCaption); + mBrowseButton->setField("Command", szBuffer); + + // Create "Open in ShapeEditor" button + mSMEdButton = new GuiBitmapButtonCtrl(); + + dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId()); + mSMEdButton->setField("Command", szBuffer); + + char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; + mSMEdButton->setBitmap(bitmapName); + + mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); + mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor"); + + mSMEdButton->registerObject(); + addObject(mSMEdButton); + + return retCtrl; +} + +bool GuiInspectorTypeGameObjectAssetPtr::updateRects() +{ + S32 dividerPos, dividerMargin; + mInspector->getDivider(dividerPos, dividerMargin); + Point2I fieldExtent = getExtent(); + Point2I fieldPos = getPosition(); + + mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); + mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); + + bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); + if (mBrowseButton != NULL) + { + mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); + resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); + } + + if (mSMEdButton != NULL) + { + RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); + resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + } + + return resized; } \ No newline at end of file diff --git a/Engine/source/T3D/assets/GameObjectAsset.h b/Engine/source/T3D/assets/GameObjectAsset.h index 82230cd5c..954a11300 100644 --- a/Engine/source/T3D/assets/GameObjectAsset.h +++ b/Engine/source/T3D/assets/GameObjectAsset.h @@ -38,17 +38,15 @@ #ifndef _ASSET_FIELD_TYPES_H_ #include "assets/assetFieldTypes.h" #endif +#ifndef _GUI_INSPECTOR_TYPES_H_ +#include "gui/editor/guiInspectorTypes.h" +#endif //----------------------------------------------------------------------------- class GameObjectAsset : public AssetBase { typedef AssetBase Parent; - AssetManager* mpOwningAssetManager; - bool mAssetInitialized; - AssetDefinition* mpAssetDefinition; - U32 mAcquireReferenceCount; - StringTableEntry mGameObjectName; StringTableEntry mScriptFilePath; StringTableEntry mTAMLFilePath; @@ -65,11 +63,29 @@ public: DECLARE_CONOBJECT(GameObjectAsset); protected: - virtual void initializeAsset(void) {} - virtual void onAssetRefresh(void) {} + virtual void initializeAsset(void); + virtual void onAssetRefresh(void); }; DefineConsoleType(TypeGameObjectAssetPtr, GameObjectAsset) + +//----------------------------------------------------------------------------- +// TypeAssetId GuiInspectorField Class +//----------------------------------------------------------------------------- +class GuiInspectorTypeGameObjectAssetPtr : public GuiInspectorTypeFileName +{ + typedef GuiInspectorTypeFileName Parent; +public: + + GuiBitmapButtonCtrl *mSMEdButton; + + DECLARE_CONOBJECT(GuiInspectorTypeGameObjectAssetPtr); + static void consoleInit(); + + virtual GuiControl* constructEditControl(); + virtual bool updateRects(); +}; + #endif // _ASSET_BASE_H_ diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp new file mode 100644 index 000000000..3e29b0bdf --- /dev/null +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -0,0 +1,161 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef IMAGE_ASSET_H +#include "ImageAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(ImageAsset); + +ConsoleType(ImageAssetPtr, TypeImageAssetPtr, ImageAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeImageAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeImageAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeImageAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeImageAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +ImageAsset::ImageAsset() +{ + mImageFileName = StringTable->EmptyString(); + + mImage = NULL; + mUseMips = true; + mIsHDRImage = false; + mIsValidImage = false; +} + +//----------------------------------------------------------------------------- + +ImageAsset::~ImageAsset() +{ +} + +//----------------------------------------------------------------------------- + +void ImageAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("imageFile", TypeString, Offset(mImageFileName, ImageAsset), "Path to the image file."); + addField("useMips", TypeBool, Offset(mUseMips, ImageAsset), "Should the image use mips? (Currently unused)."); + addField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), "Is the image in an HDR format? (Currently unused)"); +} + +//------------------------------------------------------------------------------ + +void ImageAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +void ImageAsset::loadImage() +{ + SAFE_DELETE(mImage); + + if (mImageFileName) + { + if (!Platform::isFile(mImageFileName)) + { + Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName); + return; + } + + mImage.set(mImageFileName, &GFXStaticTextureSRGBProfile, avar("%s() - mImage (line %d)", __FUNCTION__, __LINE__)); + + if (mImage) + { + mIsValidImage = true; + return; + } + } + + mIsValidImage = false; +} + +void ImageAsset::initializeAsset() +{ + loadImage(); +} + +void ImageAsset::onAssetRefresh() +{ + loadImage(); +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h new file mode 100644 index 000000000..d289ac195 --- /dev/null +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -0,0 +1,90 @@ +#pragma once +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef IMAGE_ASSET_H +#define IMAGE_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +#include "gfx/bitmap/gBitmap.h" +#include "gfx/gfxTextureHandle.h" + +//----------------------------------------------------------------------------- +class ImageAsset : public AssetBase +{ + typedef AssetBase Parent; + + AssetManager* mpOwningAssetManager; + bool mAssetInitialized; + AssetDefinition* mpAssetDefinition; + U32 mAcquireReferenceCount; + + StringTableEntry mImageFileName; + + GFXTexHandle mImage; + + bool mIsValidImage; + bool mUseMips; + bool mIsHDRImage; + +public: + ImageAsset(); + virtual ~ImageAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(ImageAsset); + + StringTableEntry getImageFileName() { return mImageFileName; } + + bool isValid() { return mIsValidImage; } + + GFXTexHandle* getImage() { return &mImage; } + +protected: + virtual void initializeAsset(void); + virtual void onAssetRefresh(void); + + void loadImage(); +}; + +DefineConsoleType(TypeImageAssetPtr, ImageAsset) + +#endif + diff --git a/Engine/source/T3D/assets/LevelAsset.cpp b/Engine/source/T3D/assets/LevelAsset.cpp new file mode 100644 index 000000000..849cdc8d7 --- /dev/null +++ b/Engine/source/T3D/assets/LevelAsset.cpp @@ -0,0 +1,126 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef LEVEL_ASSET_H +#include "LevelAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(LevelAsset); + +ConsoleType(LevelAssetPtr, TypeLevelAssetPtr, LevelAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeLevelAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeLevelAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeLevelAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeLevelAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +LevelAsset::LevelAsset() +{ + mLevelFile = StringTable->EmptyString(); + mPreviewImage = StringTable->EmptyString(); +} + +//----------------------------------------------------------------------------- + +LevelAsset::~LevelAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void LevelAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("LevelFile", TypeString, Offset(mLevelFile, LevelAsset), "Path to the actual level file."); + addField("PreviewImage", TypeString, Offset(mPreviewImage, LevelAsset), "Path to the image used for selection preview."); +} + +//------------------------------------------------------------------------------ + +void LevelAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/LevelAsset.h b/Engine/source/T3D/assets/LevelAsset.h new file mode 100644 index 000000000..3fc58c183 --- /dev/null +++ b/Engine/source/T3D/assets/LevelAsset.h @@ -0,0 +1,72 @@ +#pragma once +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef LEVEL_ASSET_H +#define LEVEL_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +//----------------------------------------------------------------------------- +class LevelAsset : public AssetBase +{ + typedef AssetBase Parent; + + StringTableEntry mLevelFile; + StringTableEntry mPreviewImage; + + bool mIsSubLevel; + StringTableEntry mMainLevelAsset; + +public: + LevelAsset(); + virtual ~LevelAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(LevelAsset); + +protected: + virtual void initializeAsset(void) {} + virtual void onAssetRefresh(void) {} +}; + +DefineConsoleType(TypeLevelAssetPtr, LevelAsset) + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/MaterialAsset.cpp b/Engine/source/T3D/assets/MaterialAsset.cpp new file mode 100644 index 000000000..697f21e37 --- /dev/null +++ b/Engine/source/T3D/assets/MaterialAsset.cpp @@ -0,0 +1,241 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef MATERIALASSET_H +#include "MaterialAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(MaterialAsset); + +ConsoleType(MaterialAssetPtr, TypeMaterialAssetPtr, MaterialAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeMaterialAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeMaterialAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeMaterialAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeMaterialAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +MaterialAsset::MaterialAsset() +{ + mShaderGraphFile = ""; + mScriptFile = ""; + mMatDefinitionName = ""; +} + +//----------------------------------------------------------------------------- + +MaterialAsset::~MaterialAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void MaterialAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + //addField("shaderGraph", TypeRealString, Offset(mShaderGraphFile, MaterialAsset), ""); + addField("scriptFile", TypeRealString, Offset(mScriptFile, MaterialAsset), "Path to the file containing the material definition."); + addField("materialDefinitionName", TypeRealString, Offset(mMatDefinitionName, MaterialAsset), "Name of the material definition this asset is for."); +} + +void MaterialAsset::initializeAsset() +{ + // Call parent. + Parent::initializeAsset(); + + compileShader(); + + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); +} + +void MaterialAsset::onAssetRefresh() +{ + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); + + if (!mMatDefinitionName.isEmpty()) + { + Material* matDef; + if (!Sim::findObject(mMatDefinitionName.c_str(), matDef)) + { + Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName.c_str()); + return; + } + + matDef->reload(); + } +} + +//------------------------------------------------------------------------------ + +void MaterialAsset::compileShader() +{ +} + +void MaterialAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +ConsoleMethod(MaterialAsset, compileShader, void, 2, 2, "() - Compiles the material's generated shader, if any. Not yet implemented\n") +{ + object->compileShader(); +} + +//----------------------------------------------------------------------------- +// GuiInspectorTypeAssetId +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(GuiInspectorTypeMaterialAssetPtr); + +ConsoleDocClass(GuiInspectorTypeMaterialAssetPtr, + "@brief Inspector field type for Material Asset Objects\n\n" + "Editor use only.\n\n" + "@internal" +); + +void GuiInspectorTypeMaterialAssetPtr::consoleInit() +{ + Parent::consoleInit(); + + ConsoleBaseType::getType(TypeMaterialAssetPtr)->setInspectorFieldType("GuiInspectorTypeMaterialAssetPtr"); +} + +GuiControl* GuiInspectorTypeMaterialAssetPtr::constructEditControl() +{ + // Create base filename edit controls + GuiControl *retCtrl = Parent::constructEditControl(); + if (retCtrl == NULL) + return retCtrl; + + // Change filespec + char szBuffer[512]; + dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"MaterialAsset\", \"AssetBrowser.changeAsset\", %d, %s);", + mInspector->getComponentGroupTargetId(), mCaption); + mBrowseButton->setField("Command", szBuffer); + + // Create "Open in ShapeEditor" button + mSMEdButton = new GuiBitmapButtonCtrl(); + + dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId()); + mSMEdButton->setField("Command", szBuffer); + + char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; + mSMEdButton->setBitmap(bitmapName); + + mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); + mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the Material Editor"); + + mSMEdButton->registerObject(); + addObject(mSMEdButton); + + return retCtrl; +} + +bool GuiInspectorTypeMaterialAssetPtr::updateRects() +{ + S32 dividerPos, dividerMargin; + mInspector->getDivider(dividerPos, dividerMargin); + Point2I fieldExtent = getExtent(); + Point2I fieldPos = getPosition(); + + mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); + mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); + + bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); + if (mBrowseButton != NULL) + { + mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); + resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); + } + + if (mSMEdButton != NULL) + { + RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); + resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + } + + return resized; +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/MaterialAsset.h b/Engine/source/T3D/assets/MaterialAsset.h new file mode 100644 index 000000000..2cb9f15b1 --- /dev/null +++ b/Engine/source/T3D/assets/MaterialAsset.h @@ -0,0 +1,101 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef MATERIALASSET_H +#define MATERIALASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +#ifndef _GFXDEVICE_H_ +#include "gfx/gfxDevice.h" +#endif + +#ifndef _GUI_INSPECTOR_TYPES_H_ +#include "gui/editor/guiInspectorTypes.h" +#endif + +#include "materials/matTextureTarget.h" +#include "materials/materialDefinition.h" +#include "materials/customMaterialDefinition.h" + +//----------------------------------------------------------------------------- +class MaterialAsset : public AssetBase +{ + typedef AssetBase Parent; + + String mShaderGraphFile; + String mScriptFile; + String mMatDefinitionName; + +public: + MaterialAsset(); + virtual ~MaterialAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + virtual void initializeAsset(); + virtual void onAssetRefresh(void); + + void compileShader(); + + String getMaterialDefinitionName() { return mMatDefinitionName; } + + /// Declare Console Object. + DECLARE_CONOBJECT(MaterialAsset); +}; + +DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset) + +//----------------------------------------------------------------------------- +// TypeAssetId GuiInspectorField Class +//----------------------------------------------------------------------------- +class GuiInspectorTypeMaterialAssetPtr : public GuiInspectorTypeFileName +{ + typedef GuiInspectorTypeFileName Parent; +public: + + GuiBitmapButtonCtrl *mSMEdButton; + + DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetPtr); + static void consoleInit(); + + virtual GuiControl* constructEditControl(); + virtual bool updateRects(); +}; + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/ParticleAsset.cpp b/Engine/source/T3D/assets/ParticleAsset.cpp new file mode 100644 index 000000000..bcefd2dfa --- /dev/null +++ b/Engine/source/T3D/assets/ParticleAsset.cpp @@ -0,0 +1,205 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef PARTICLE_ASSET_H +#include "ParticleAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(ParticleAsset); + +ConsoleType(ParticleAssetPtr, TypeParticleAssetPtr, ParticleAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeParticleAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeParticleAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeParticleAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeParticleAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +ParticleAsset::ParticleAsset() +{ + mScriptFilePath = StringTable->EmptyString(); + mDatablockFilePath = StringTable->EmptyString(); +} + +//----------------------------------------------------------------------------- + +ParticleAsset::~ParticleAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void ParticleAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("scriptFilePath", TypeString, Offset(mScriptFilePath, ParticleAsset), "Path to the script file for the particle effect"); + addField("DatablockFilePath", TypeString, Offset(mDatablockFilePath, ParticleAsset), "Path to the datablock file"); +} + +//------------------------------------------------------------------------------ + +void ParticleAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + + +//----------------------------------------------------------------------------- +// GuiInspectorTypeAssetId +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(GuiInspectorTypeParticleAssetPtr); + +ConsoleDocClass(GuiInspectorTypeParticleAssetPtr, + "@brief Inspector field type for Partial Asset Objects\n\n" + "Editor use only.\n\n" + "@internal" +); + +void GuiInspectorTypeParticleAssetPtr::consoleInit() +{ + Parent::consoleInit(); + + ConsoleBaseType::getType(TypeParticleAssetPtr)->setInspectorFieldType("GuiInspectorTypeParticleAssetPtr"); +} + +GuiControl* GuiInspectorTypeParticleAssetPtr::constructEditControl() +{ + // Create base filename edit controls + GuiControl *retCtrl = Parent::constructEditControl(); + if (retCtrl == NULL) + return retCtrl; + + // Change filespec + char szBuffer[512]; + dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"ParticleAsset\", \"AssetBrowser.changeAsset\", %d, %s);", + mInspector->getComponentGroupTargetId(), mCaption); + mBrowseButton->setField("Command", szBuffer); + + // Create "Open in ShapeEditor" button + mSMEdButton = new GuiBitmapButtonCtrl(); + + dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId()); + mSMEdButton->setField("Command", szBuffer); + + char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; + mSMEdButton->setBitmap(bitmapName); + + mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); + mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor"); + + mSMEdButton->registerObject(); + addObject(mSMEdButton); + + return retCtrl; +} + +bool GuiInspectorTypeParticleAssetPtr::updateRects() +{ + S32 dividerPos, dividerMargin; + mInspector->getDivider(dividerPos, dividerMargin); + Point2I fieldExtent = getExtent(); + Point2I fieldPos = getPosition(); + + mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); + mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); + + bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); + if (mBrowseButton != NULL) + { + mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); + resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); + } + + if (mSMEdButton != NULL) + { + RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); + resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + } + + return resized; +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/ParticleAsset.h b/Engine/source/T3D/assets/ParticleAsset.h new file mode 100644 index 000000000..b446c2cf0 --- /dev/null +++ b/Engine/source/T3D/assets/ParticleAsset.h @@ -0,0 +1,89 @@ +#pragma once +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef PARTICLE_ASSET_H +#define PARTICLE_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +#include "gui/editor/guiInspectorTypes.h" + +//----------------------------------------------------------------------------- +class ParticleAsset : public AssetBase +{ + typedef AssetBase Parent; + + StringTableEntry mScriptFilePath; + StringTableEntry mDatablockFilePath; + +public: + ParticleAsset(); + virtual ~ParticleAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(ParticleAsset); + +protected: + virtual void initializeAsset(void) {} + virtual void onAssetRefresh(void) {} +}; + +DefineConsoleType(TypeParticleAssetPtr, ParticleAsset) + + +//----------------------------------------------------------------------------- +// TypeAssetId GuiInspectorField Class +//----------------------------------------------------------------------------- +class GuiInspectorTypeParticleAssetPtr : public GuiInspectorTypeFileName +{ + typedef GuiInspectorTypeFileName Parent; +public: + + GuiBitmapButtonCtrl *mSMEdButton; + + DECLARE_CONOBJECT(GuiInspectorTypeParticleAssetPtr); + static void consoleInit(); + + virtual GuiControl* constructEditControl(); + virtual bool updateRects(); +}; + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/PostEffectAsset.cpp b/Engine/source/T3D/assets/PostEffectAsset.cpp new file mode 100644 index 000000000..4eb67a6a3 --- /dev/null +++ b/Engine/source/T3D/assets/PostEffectAsset.cpp @@ -0,0 +1,129 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef POSTEFFECT_ASSET_H +#include "PostEffectAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(PostEffectAsset); + +ConsoleType(PostEffectAssetPtr, TypePostEffectAssetPtr, PostEffectAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypePostEffectAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypePostEffectAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypePostEffectAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypePostEffectAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +PostEffectAsset::PostEffectAsset() +{ + mScriptFile = StringTable->EmptyString(); +} + +//----------------------------------------------------------------------------- + +PostEffectAsset::~PostEffectAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void PostEffectAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("scriptFile", TypeString, Offset(mScriptFile, PostEffectAsset), "Path to the script file."); +} + +//------------------------------------------------------------------------------ + +void PostEffectAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +void PostEffectAsset::initializeAsset() +{ + //mPostEffect = new PostEffect(); +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/PostEffectAsset.h b/Engine/source/T3D/assets/PostEffectAsset.h new file mode 100644 index 000000000..381fa1576 --- /dev/null +++ b/Engine/source/T3D/assets/PostEffectAsset.h @@ -0,0 +1,71 @@ +#pragma once +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef POSTEFFECT_ASSET_H +#define POSTEFFECT_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +#include "postFx/postEffect.h" + +//----------------------------------------------------------------------------- +class PostEffectAsset : public AssetBase +{ + typedef AssetBase Parent; + + StringTableEntry mScriptFile; + +public: + PostEffectAsset(); + virtual ~PostEffectAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + virtual void initializeAsset(); + + /// Declare Console Object. + DECLARE_CONOBJECT(PostEffectAsset); + +protected: + virtual void onAssetRefresh(void) {} +}; + +DefineConsoleType(TypePostEffectAssetPtr, PostEffectAsset) + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/ScriptAsset.cpp b/Engine/source/T3D/assets/ScriptAsset.cpp new file mode 100644 index 000000000..dbc5e7a2e --- /dev/null +++ b/Engine/source/T3D/assets/ScriptAsset.cpp @@ -0,0 +1,137 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef SCRIPT_ASSET_H +#include "ScriptAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(ScriptAsset); + +ConsoleType(ScriptAssetPtr, TypeScriptAssetPtr, ScriptAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeScriptAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeScriptAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeScriptAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeScriptAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +ScriptAsset::ScriptAsset() +{ + mScriptFilePath = StringTable->EmptyString(); +} + +//----------------------------------------------------------------------------- + +ScriptAsset::~ScriptAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void ScriptAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("scriptFilePath", TypeString, Offset(mScriptFilePath, ScriptAsset), "Path to the script file."); + addField("isServerSide", TypeBool, Offset(mIsServerSide, ScriptAsset), "Is this script file to be run on the server side?"); + +} + +//------------------------------------------------------------------------------ + +void ScriptAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +void ScriptAsset::initializeAsset() +{ + if (Platform::isFile(mScriptFilePath)) + Con::executeFile(mScriptFilePath, false, false); +} + +void ScriptAsset::onAssetRefresh() +{ + if (Platform::isFile(mScriptFilePath)) + Con::executeFile(mScriptFilePath, false, false); +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/ScriptAsset.h b/Engine/source/T3D/assets/ScriptAsset.h new file mode 100644 index 000000000..8c12f2b88 --- /dev/null +++ b/Engine/source/T3D/assets/ScriptAsset.h @@ -0,0 +1,69 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef SCRIPT_ASSET_H +#define SCRIPT_ASSET_H +#pragma once + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +//----------------------------------------------------------------------------- +class ScriptAsset : public AssetBase +{ + typedef AssetBase Parent; + + StringTableEntry mScriptFilePath; + bool mIsServerSide; + +public: + ScriptAsset(); + virtual ~ScriptAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(ScriptAsset); + +protected: + virtual void initializeAsset(void); + virtual void onAssetRefresh(void); +}; + +DefineConsoleType(TypeScriptAssetPtr, ScriptAsset) + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/ShapeAnimationAsset.cpp b/Engine/source/T3D/assets/ShapeAnimationAsset.cpp new file mode 100644 index 000000000..ee10bbe40 --- /dev/null +++ b/Engine/source/T3D/assets/ShapeAnimationAsset.cpp @@ -0,0 +1,131 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef SHAPE_ANIMATION_ASSET_H +#include "ShapeAnimationAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +#include "core/resourceManager.h" + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(ShapeAnimationAsset); + +ConsoleType(ShapeAnimationAssetPtr, TypeShapeAnimationAssetPtr, ShapeAnimationAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeShapeAnimationAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeShapeAnimationAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeShapeAnimationAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeShapeAnimationAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +ShapeAnimationAsset::ShapeAnimationAsset() +{ +} + +//----------------------------------------------------------------------------- + +ShapeAnimationAsset::~ShapeAnimationAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void ShapeAnimationAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("animationFile", TypeFilename, Offset(mFileName, ShapeAnimationAsset), "Path to the file name containing the animation"); + addField("animationName", TypeString, Offset(mAnimationName, ShapeAnimationAsset), "Name of the animation"); + + addField("startFrame", TypeS32, Offset(mStartFrame, ShapeAnimationAsset), "What frame does this animation clip start on"); + addField("endFrame", TypeS32, Offset(mEndFrame, ShapeAnimationAsset), "What fram does this animation clip end on"); + addField("padRotation", TypeBool, Offset(mPadRotation, ShapeAnimationAsset), "Are the rotation values padded"); + addField("padTransforms", TypeBool, Offset(mPadTransforms, ShapeAnimationAsset), "Are the transform values padded"); +} + +//------------------------------------------------------------------------------ + +void ShapeAnimationAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/ShapeAnimationAsset.h b/Engine/source/T3D/assets/ShapeAnimationAsset.h new file mode 100644 index 000000000..673607d53 --- /dev/null +++ b/Engine/source/T3D/assets/ShapeAnimationAsset.h @@ -0,0 +1,102 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef SHAPE_ANIMATION_ASSET_H +#define SHAPE_ANIMATION_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +//----------------------------------------------------------------------------- +class ShapeAnimationAsset : public AssetBase +{ + typedef AssetBase Parent; + +protected: + StringTableEntry mFileName; + + // + StringTableEntry mAnimationName; + S32 mStartFrame; + S32 mEndFrame; + bool mPadRotation; + bool mPadTransforms; + +public: + ShapeAnimationAsset(); + virtual ~ShapeAnimationAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(ShapeAnimationAsset); + +protected: + virtual void initializeAsset(void) {} + virtual void onAssetRefresh(void) {} + +public: + StringTableEntry getAnimationFilename() { return mFileName; } + StringTableEntry getAnimationName() { return mAnimationName; } + + S32 getStartFrame() { return mStartFrame; } + S32 getEndFrame() { return mEndFrame; } + + bool getPadRotation() { return mPadRotation; } + bool getPadTransforms() { return mPadTransforms; } +}; + +DefineConsoleType(TypeShapeAnimationAssetPtr, ShapeAnimationAsset) + +//----------------------------------------------------------------------------- +// TypeAssetId GuiInspectorField Class +//----------------------------------------------------------------------------- +/*class GuiInspectorTypeShapeAnimationAssetPtr : public GuiInspectorTypeFileName +{ + typedef GuiInspectorTypeFileName Parent; +public: + + GuiBitmapButtonCtrl *mShapeEdButton; + + DECLARE_CONOBJECT(GuiInspectorTypeShapeAnimationAssetPtr); + static void consoleInit(); + + virtual GuiControl* constructEditControl(); + virtual bool updateRects(); +};*/ + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/ShapeAsset.cpp b/Engine/source/T3D/assets/ShapeAsset.cpp index d8cbce453..099c3c117 100644 --- a/Engine/source/T3D/assets/ShapeAsset.cpp +++ b/Engine/source/T3D/assets/ShapeAsset.cpp @@ -49,14 +49,14 @@ IMPLEMENT_CONOBJECT(ShapeAsset); -ConsoleType(TestAssetPtr, TypeShapeAssetPtr, ShapeAsset, ASSET_ID_FIELD_PREFIX) +ConsoleType(assetIdString, TypeShapeAssetPtr, String, ASSET_ID_FIELD_PREFIX) //----------------------------------------------------------------------------- ConsoleGetType(TypeShapeAssetPtr) { // Fetch asset Id. - return (*((AssetPtr*)dptr)).getAssetId(); + return *((StringTableEntry*)dptr); } //----------------------------------------------------------------------------- @@ -69,33 +69,22 @@ ConsoleSetType(TypeShapeAssetPtr) // Yes, so fetch field value. const char* pFieldValue = argv[0]; - // Fetch asset pointer. - AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + // Fetch asset Id. + StringTableEntry* assetId = (StringTableEntry*)(dptr); - // Is the asset pointer the correct type? - if (pAssetPtr == NULL) - { - // No, so fail. - //Con::warnf("(TypeTextureAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); - return; - } - - // Set asset. - pAssetPtr->setAssetId(pFieldValue); + // Update asset value. + *assetId = StringTable->insert(pFieldValue); return; } // Warn. - Con::warnf("(TypeTextureAssetPtr) - Cannot set multiple args to a single asset."); + Con::warnf("(TypeAssetId) - Cannot set multiple args to a single asset."); } //----------------------------------------------------------------------------- -ShapeAsset::ShapeAsset() : -mpOwningAssetManager(NULL), -mAssetInitialized(false), -mAcquireReferenceCount(0) +ShapeAsset::ShapeAsset() { } @@ -116,7 +105,21 @@ void ShapeAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("fileName", TypeFilename, Offset(mFileName, ShapeAsset), "Path to the script file we want to execute"); + addField("fileName", TypeFilename, Offset(mFileName, ShapeAsset), "Path to the shape file we want to render"); +} + +void ShapeAsset::setDataField(StringTableEntry slotName, const char *array, const char *value) +{ + Parent::setDataField(slotName, array, value); + + //Now, if it's a material slot of some fashion, set it up + StringTableEntry matSlotName = StringTable->insert("materialAsset"); + if (String(slotName).startsWith(matSlotName)) + { + StringTableEntry matId = StringTable->insert(value); + + mMaterialAssetIds.push_back(matId); + } } void ShapeAsset::initializeAsset() @@ -132,6 +135,45 @@ void ShapeAsset::initializeAsset() bool ShapeAsset::loadShape() { + mMaterialAssets.clear(); + mMaterialAssetIds.clear(); + + //First, load any material, animation, etc assets we may be referencing in our asset + // Find any asset dependencies. + AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId); + + // Does the asset have any dependencies? + if (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end()) + { + // Iterate all dependencies. + while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId) + { + StringTableEntry assetType = mpOwningAssetManager->getAssetType(assetDependenciesItr->value); + + if (assetType == StringTable->insert("MaterialAsset")) + { + mMaterialAssetIds.push_back(assetDependenciesItr->value); + + //Force the asset to become initialized if it hasn't been already + AssetPtr matAsset = assetDependenciesItr->value; + + mMaterialAssets.push_back(matAsset); + } + else if (assetType == StringTable->insert("ShapeAnimationAsset")) + { + mAnimationAssetIds.push_back(assetDependenciesItr->value); + + //Force the asset to become initialized if it hasn't been already + AssetPtr animAsset = assetDependenciesItr->value; + + mAnimationAssets.push_back(animAsset); + } + + // Next dependency. + assetDependenciesItr++; + } + } + mShape = ResourceManager::get().load(mFileName); if (!mShape) @@ -140,6 +182,19 @@ bool ShapeAsset::loadShape() return false; //if it failed to load, bail out } + //Now that we've successfully loaded our shape and have any materials and animations loaded + //we need to set up the animations we're using on our shape + for (U32 i = 0; i < mAnimationAssets.size(); i++) + { + String srcName; + String srcPath(mAnimationAssets[i]->getAnimationFilename()); + SplitSequencePathAndName(srcPath, srcName); + + if (!mShape->addSequence(srcPath, srcName, mAnimationAssets[i]->getAnimationName(), + mAnimationAssets[i]->getStartFrame(), mAnimationAssets[i]->getEndFrame(), mAnimationAssets[i]->getPadRotation(), mAnimationAssets[i]->getPadTransforms())) + return false; + } + return true; } @@ -153,4 +208,141 @@ void ShapeAsset::copyTo(SimObject* object) void ShapeAsset::onAssetRefresh(void) { + if (dStrcmp(mFileName, "") == 0) + return; + + loadShape(); +} + +void ShapeAsset::SplitSequencePathAndName(String& srcPath, String& srcName) +{ + srcName = ""; + + // Determine if there is a sequence name at the end of the source string, and + // if so, split the filename from the sequence name + S32 split = srcPath.find(' ', 0, String::Right); + S32 split2 = srcPath.find('\t', 0, String::Right); + if ((split == String::NPos) || (split2 > split)) + split = split2; + if (split != String::NPos) + { + split2 = split + 1; + while ((srcPath[split2] != '\0') && dIsspace(srcPath[split2])) + split2++; + + // now 'split' is at the end of the path, and 'split2' is at the start of the sequence name + srcName = srcPath.substr(split2); + srcPath = srcPath.erase(split, srcPath.length() - split); + } +} + +ShapeAnimationAsset* ShapeAsset::getAnimation(S32 index) +{ + if (index < mAnimationAssets.size()) + { + return mAnimationAssets[index]; + } + + return nullptr; +} + +DefineEngineMethod(ShapeAsset, getMaterialCount, S32, (), , + "Gets the number of materials for this shape asset.\n" + "@return Material count.\n") +{ + return object->getMaterialCount(); +} + +DefineEngineMethod(ShapeAsset, getAnimationCount, S32, (), , + "Gets the number of animations for this shape asset.\n" + "@return Animation count.\n") +{ + return object->getAnimationCount(); +} + +DefineEngineMethod(ShapeAsset, getAnimation, ShapeAnimationAsset*, (S32 index), (0), + "Gets a particular shape animation asset for this shape.\n" + "@param animation asset index.\n" + "@return Shape Animation Asset.\n") +{ + return object->getAnimation(index); +} +//----------------------------------------------------------------------------- +// GuiInspectorTypeAssetId +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(GuiInspectorTypeShapeAssetPtr); + +ConsoleDocClass(GuiInspectorTypeShapeAssetPtr, + "@brief Inspector field type for Shapes\n\n" + "Editor use only.\n\n" + "@internal" + ); + +void GuiInspectorTypeShapeAssetPtr::consoleInit() +{ + Parent::consoleInit(); + + ConsoleBaseType::getType(TypeShapeAssetPtr)->setInspectorFieldType("GuiInspectorTypeShapeAssetPtr"); +} + +GuiControl* GuiInspectorTypeShapeAssetPtr::constructEditControl() +{ + // Create base filename edit controls + GuiControl *retCtrl = Parent::constructEditControl(); + if (retCtrl == NULL) + return retCtrl; + + // Change filespec + char szBuffer[512]; + dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"ShapeAsset\", \"AssetBrowser.changeAsset\", %d, %s);", + mInspector->getComponentGroupTargetId(), mCaption); + mBrowseButton->setField("Command", szBuffer); + + setDataField(StringTable->insert("ComponentOwner"), NULL, String::ToString(mInspector->getComponentGroupTargetId()).c_str()); + + // Create "Open in ShapeEditor" button + mShapeEdButton = new GuiBitmapButtonCtrl(); + + dSprintf(szBuffer, sizeof(szBuffer), "ShapeEditorPlugin.openShapeAsset(%d.getText());", retCtrl->getId()); + mShapeEdButton->setField("Command", szBuffer); + + char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; + mShapeEdButton->setBitmap(bitmapName); + + mShapeEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mShapeEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mShapeEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); + mShapeEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the Shape Editor"); + + mShapeEdButton->registerObject(); + addObject(mShapeEdButton); + + return retCtrl; +} + +bool GuiInspectorTypeShapeAssetPtr::updateRects() +{ + S32 dividerPos, dividerMargin; + mInspector->getDivider(dividerPos, dividerMargin); + Point2I fieldExtent = getExtent(); + Point2I fieldPos = getPosition(); + + mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); + mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); + + bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); + if (mBrowseButton != NULL) + { + mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); + resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); + } + + if (mShapeEdButton != NULL) + { + RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); + resized |= mShapeEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + } + + return resized; } \ No newline at end of file diff --git a/Engine/source/T3D/assets/ShapeAsset.h b/Engine/source/T3D/assets/ShapeAsset.h index d727d0a1c..45fca7e86 100644 --- a/Engine/source/T3D/assets/ShapeAsset.h +++ b/Engine/source/T3D/assets/ShapeAsset.h @@ -44,21 +44,35 @@ #ifndef __RESOURCE_H__ #include "core/resource.h" #endif +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif +#ifndef MATERIALASSET_H +#include "MaterialAsset.h" +#endif +#ifndef SHAPE_ANIMATION_ASSET_H +#include "ShapeAnimationAsset.h" +#endif + +#include "gui/editor/guiInspectorTypes.h" //----------------------------------------------------------------------------- class ShapeAsset : public AssetBase { typedef AssetBase Parent; - AssetManager* mpOwningAssetManager; - bool mAssetInitialized; - AssetDefinition* mpAssetDefinition; - U32 mAcquireReferenceCount; - protected: StringTableEntry mFileName; Resource mShape; + //Material assets we're dependent on and use + Vector mMaterialAssetIds; + Vector> mMaterialAssets; + + //Animation assets we're dependent on and use + Vector mAnimationAssetIds; + Vector> mAnimationAssets; + public: ShapeAsset(); virtual ~ShapeAsset(); @@ -67,6 +81,8 @@ public: static void initPersistFields(); virtual void copyTo(SimObject* object); + virtual void setDataField(StringTableEntry slotName, const char *array, const char *value); + virtual void initializeAsset(); /// Declare Console Object. @@ -78,11 +94,37 @@ public: Resource getShapeResource() { return mShape; } + void SplitSequencePathAndName(String& srcPath, String& srcName); + String getShapeFilename() { return mFileName; } + + U32 getShapeFilenameHash() { return _StringTable::hashString(mFileName); } + + S32 getMaterialCount() { return mMaterialAssets.size(); } + S32 getAnimationCount() { return mAnimationAssets.size(); } + ShapeAnimationAsset* getAnimation(S32 index); + protected: virtual void onAssetRefresh(void); }; -DefineConsoleType(TypeShapeAssetPtr, ShapeAsset) +DefineConsoleType(TypeShapeAssetPtr, S32) + +//----------------------------------------------------------------------------- +// TypeAssetId GuiInspectorField Class +//----------------------------------------------------------------------------- +class GuiInspectorTypeShapeAssetPtr : public GuiInspectorTypeFileName +{ + typedef GuiInspectorTypeFileName Parent; +public: + + GuiBitmapButtonCtrl *mShapeEdButton; + + DECLARE_CONOBJECT(GuiInspectorTypeShapeAssetPtr); + static void consoleInit(); + + virtual GuiControl* constructEditControl(); + virtual bool updateRects(); +}; #endif diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp new file mode 100644 index 000000000..f2978aa38 --- /dev/null +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -0,0 +1,141 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef SOUND_ASSET_H +#include "SoundAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(SoundAsset); + +ConsoleType(SoundAssetPtr, TypeSoundAssetPtr, SoundAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeSoundAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeSoundAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeSoundAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeSoundAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +SoundAsset::SoundAsset() +{ + mSoundFilePath = StringTable->EmptyString(); + + mPitchAdjust = 0; + mVolumeAdjust = 0; + + //mSound = nullptr; +} + +//----------------------------------------------------------------------------- + +SoundAsset::~SoundAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void SoundAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("soundFilePath", TypeFilename, Offset(mSoundFilePath, SoundAsset), "Path to the sound file."); + + addField("pitchAdjust", TypeF32, Offset(mPitchAdjust, SoundAsset), "Adjustment of the pitch value"); + addField("volumeAdjust", TypeF32, Offset(mVolumeAdjust, SoundAsset), "Adjustment to the volume."); +} + +//------------------------------------------------------------------------------ + +void SoundAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +void SoundAsset::initializeAsset(void) +{ +} + +void SoundAsset::onAssetRefresh(void) +{ + +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/SoundAsset.h b/Engine/source/T3D/assets/SoundAsset.h new file mode 100644 index 000000000..bfe582823 --- /dev/null +++ b/Engine/source/T3D/assets/SoundAsset.h @@ -0,0 +1,75 @@ +#pragma once +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef SOUND_ASSET_H +#define SOUND_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +class SFXTrack; + +//----------------------------------------------------------------------------- +class SoundAsset : public AssetBase +{ + typedef AssetBase Parent; + +protected: + StringTableEntry mSoundFilePath; + F32 mPitchAdjust; + F32 mVolumeAdjust; + +public: + SoundAsset(); + virtual ~SoundAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(SoundAsset); + + StringTableEntry getSoundFilePath() { return mSoundFilePath; } + +protected: + virtual void initializeAsset(void); + virtual void onAssetRefresh(void); +}; + +DefineConsoleType(TypeSoundAssetPtr, SoundAsset) + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/stateMachineAsset.cpp b/Engine/source/T3D/assets/stateMachineAsset.cpp new file mode 100644 index 000000000..99ba956a4 --- /dev/null +++ b/Engine/source/T3D/assets/stateMachineAsset.cpp @@ -0,0 +1,207 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#ifndef STATE_MACHINE_ASSET_H +#include "stateMachineAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(StateMachineAsset); + +ConsoleType(StateMachineAssetPtr, TypeStateMachineAssetPtr, StateMachineAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeStateMachineAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeStateMachineAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeStateMachineAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeStateMachineAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +StateMachineAsset::StateMachineAsset() +{ + mStateMachineFileName = StringTable->EmptyString(); +} + +//----------------------------------------------------------------------------- + +StateMachineAsset::~StateMachineAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void StateMachineAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addField("stateMachineFile", TypeString, Offset(mStateMachineFileName, StateMachineAsset), "Path to the state machine file."); +} + +//------------------------------------------------------------------------------ + +void StateMachineAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +DefineEngineMethod(StateMachineAsset, notifyAssetChanged, void, (),,"") +{ + ResourceManager::get().getChangedSignal().trigger(object->getStateMachineFileName()); +} + +//----------------------------------------------------------------------------- +// GuiInspectorTypeAssetId +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(GuiInspectorTypeStateMachineAssetPtr); + +ConsoleDocClass(GuiInspectorTypeStateMachineAssetPtr, + "@brief Inspector field type for State Machines\n\n" + "Editor use only.\n\n" + "@internal" +); + +void GuiInspectorTypeStateMachineAssetPtr::consoleInit() +{ + Parent::consoleInit(); + + ConsoleBaseType::getType(TypeStateMachineAssetPtr)->setInspectorFieldType("GuiInspectorTypeStateMachineAssetPtr"); +} + +GuiControl* GuiInspectorTypeStateMachineAssetPtr::constructEditControl() +{ + // Create base filename edit controls + GuiControl *retCtrl = Parent::constructEditControl(); + if (retCtrl == NULL) + return retCtrl; + + // Change filespec + char szBuffer[512]; + dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"StateMachineAsset\", \"AssetBrowser.changeAsset\", %d, %s);", + mInspector->getComponentGroupTargetId(), mCaption); + mBrowseButton->setField("Command", szBuffer); + + // Create "Open in ShapeEditor" button + mSMEdButton = new GuiBitmapButtonCtrl(); + + dSprintf(szBuffer, sizeof(szBuffer), "StateMachineEditor.loadStateMachineAsset(%d.getText()); Canvas.pushDialog(StateMachineEditor);", retCtrl->getId()); + mSMEdButton->setField("Command", szBuffer); + + char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; + mSMEdButton->setBitmap(bitmapName); + + mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); + mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor"); + + mSMEdButton->registerObject(); + addObject(mSMEdButton); + + return retCtrl; +} + +bool GuiInspectorTypeStateMachineAssetPtr::updateRects() +{ + S32 dividerPos, dividerMargin; + mInspector->getDivider(dividerPos, dividerMargin); + Point2I fieldExtent = getExtent(); + Point2I fieldPos = getPosition(); + + mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); + mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); + + bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); + if (mBrowseButton != NULL) + { + mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); + resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); + } + + if (mSMEdButton != NULL) + { + RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); + resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + } + + return resized; +} \ No newline at end of file diff --git a/Engine/source/T3D/assets/stateMachineAsset.h b/Engine/source/T3D/assets/stateMachineAsset.h new file mode 100644 index 000000000..6452a6e6f --- /dev/null +++ b/Engine/source/T3D/assets/stateMachineAsset.h @@ -0,0 +1,89 @@ +#pragma once +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef STATE_MACHINE_ASSET_H +#define STATE_MACHINE_ASSET_H + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +#include "gui/editor/guiInspectorTypes.h" + +//----------------------------------------------------------------------------- +class StateMachineAsset : public AssetBase +{ + typedef AssetBase Parent; + + StringTableEntry mStateMachineFileName; + +public: + StateMachineAsset(); + virtual ~StateMachineAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(StateMachineAsset); + + StringTableEntry getStateMachineFileName() { return mStateMachineFileName; } + +protected: + virtual void initializeAsset(void) {} + virtual void onAssetRefresh(void) {} +}; + +DefineConsoleType(TypeStateMachineAssetPtr, StateMachineAsset) + +//----------------------------------------------------------------------------- +// TypeAssetId GuiInspectorField Class +//----------------------------------------------------------------------------- +class GuiInspectorTypeStateMachineAssetPtr : public GuiInspectorTypeFileName +{ + typedef GuiInspectorTypeFileName Parent; +public: + + GuiBitmapButtonCtrl *mSMEdButton; + + DECLARE_CONOBJECT(GuiInspectorTypeStateMachineAssetPtr); + static void consoleInit(); + + virtual GuiControl* constructEditControl(); + virtual bool updateRects(); +}; + +#endif + diff --git a/Engine/source/assets/assetBase.cpp b/Engine/source/assets/assetBase.cpp index 85ec18834..39cd4115f 100644 --- a/Engine/source/assets/assetBase.cpp +++ b/Engine/source/assets/assetBase.cpp @@ -69,7 +69,7 @@ AssetBase::~AssetBase() // If the asset manager does not own the asset then we own the // asset definition so delete it. if (!getOwned()) - delete mpAssetDefinition; + SAFE_DELETE(mpAssetDefinition); } //----------------------------------------------------------------------------- diff --git a/Engine/source/assets/assetBase.h b/Engine/source/assets/assetBase.h index 8709c5474..73c6df1c0 100644 --- a/Engine/source/assets/assetBase.h +++ b/Engine/source/assets/assetBase.h @@ -62,6 +62,7 @@ class AssetBase : public SimObject typedef SimObject Parent; +protected: AssetManager* mpOwningAssetManager; bool mAssetInitialized; AssetDefinition* mpAssetDefinition; diff --git a/Engine/source/assets/assetManager.cpp b/Engine/source/assets/assetManager.cpp index 805c52c01..da610a895 100644 --- a/Engine/source/assets/assetManager.cpp +++ b/Engine/source/assets/assetManager.cpp @@ -61,6 +61,15 @@ #ifndef COMPONENTASSET_H #include "T3D/assets/ComponentAsset.h" #endif +#ifndef GUI_ASSET_H +#include "T3D/assets/GUIAsset.h" +#endif +#ifndef SCRIPT_ASSET_H +#include "T3D/assets/ScriptAsset.h" +#endif +#ifndef MATERIALASSET_H +#include "T3D/assets/MaterialAsset.h" +#endif // Script bindings. #include "assetManager_ScriptBinding.h" @@ -251,6 +260,18 @@ bool AssetManager::loadModuleAutoLoadAssets(ModuleDefinition* pModuleDefinition) { assetBase = mTaml.read(assetDef->mAssetBaseFilePath); } + else if (assetDef->mAssetType == StringTable->insert("GUIAsset")) + { + assetBase = mTaml.read(assetDef->mAssetBaseFilePath); + } + else if (assetDef->mAssetType == StringTable->insert("ScriptAsset")) + { + assetBase = mTaml.read(assetDef->mAssetBaseFilePath); + } + else if (assetDef->mAssetType == StringTable->insert("MaterialAsset")) + { + assetBase = mTaml.read(assetDef->mAssetBaseFilePath); + } //load the asset now if valid if (assetBase) @@ -2369,6 +2390,13 @@ S32 AssetManager::findAssetLooseFile( AssetQuery* pAssetQuery, const char* pLoos //----------------------------------------------------------------------------- +AssetManager::typeAssetDependsOnHash* AssetManager::getDependedOnAssets() +{ + // Find any asset dependencies. + return &mAssetDependsOn; +} +//----------------------------------------------------------------------------- + bool AssetManager::scanDeclaredAssets( const char* pPath, const char* pExtension, const bool recurse, ModuleDefinition* pModuleDefinition ) { // Debug Profiling. diff --git a/Engine/source/assets/assetManager.h b/Engine/source/assets/assetManager.h index a8ac792a2..9271ea534 100644 --- a/Engine/source/assets/assetManager.h +++ b/Engine/source/assets/assetManager.h @@ -73,15 +73,18 @@ class AssetManager : public SimObject, public ModuleCallbacks { private: typedef SimObject Parent; - typedef StringTableEntry typeAssetId; - typedef StringTableEntry typeAssetName; - typedef StringTableEntry typeReferenceFilePath; - typedef HashMap typeDeclaredAssetsHash; - typedef HashTable typeReferencedAssetsHash; - typedef HashTable typeAssetDependsOnHash; - typedef HashTable typeAssetIsDependedOnHash; - typedef HashMap typeAssetPtrRefreshHash; +public: + typedef StringTableEntry typeAssetId; + typedef StringTableEntry typeAssetName; + typedef StringTableEntry typeReferenceFilePath; + typedef HashMap typeDeclaredAssetsHash; + typedef HashTable typeReferencedAssetsHash; + typedef HashTable typeAssetDependsOnHash; + typedef HashTable typeAssetIsDependedOnHash; + typedef HashMap typeAssetPtrRefreshHash; + +private: /// Declared assets. typeDeclaredAssetsHash mDeclaredAssets; @@ -368,6 +371,8 @@ public: S32 findTaggedAssets( AssetQuery* pAssetQuery, const char* pAssetTagNames, const bool assetQueryAsSource = false ); S32 findAssetLooseFile( AssetQuery* pAssetQuery, const char* pLooseFile, const bool assetQueryAsSource = false ); + typeAssetDependsOnHash* getDependedOnAssets(); + /// Declare Console Object. DECLARE_CONOBJECT( AssetManager ); diff --git a/Engine/source/module/moduleDefinition.cpp b/Engine/source/module/moduleDefinition.cpp index 795186aef..c8dae30d8 100644 --- a/Engine/source/module/moduleDefinition.cpp +++ b/Engine/source/module/moduleDefinition.cpp @@ -82,6 +82,8 @@ void ModuleDefinition::initPersistFields() // Call parent. Parent::initPersistFields(); + addProtectedField("ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &defaultProtectedSetFn, &defaultProtectedGetFn, ""); + /// Module configuration. addProtectedField( "ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &setModuleId, &defaultProtectedGetFn, "A unique string Id for the module. It can contain any characters except a comma or semi-colon (the asset scope character)." ); addProtectedField( "VersionId", TypeS32, Offset(mVersionId, ModuleDefinition), &setVersionId, &defaultProtectedGetFn, "The version Id. Breaking changes to a module should use a higher version Id." ); diff --git a/Engine/source/module/moduleManager.cpp b/Engine/source/module/moduleManager.cpp index 67a89e3e1..fa53728b7 100644 --- a/Engine/source/module/moduleManager.cpp +++ b/Engine/source/module/moduleManager.cpp @@ -70,7 +70,8 @@ S32 QSORT_CALLBACK moduleDefinitionVersionIdSort( const void* a, const void* b ) ModuleManager::ModuleManager() : mEnforceDependencies(true), mEchoInfo(true), - mDatabaseLocks( 0 ) + mDatabaseLocks( 0 ), + mIgnoreLoadedGroups(false) { // Set module extension. dStrcpy( mModuleExtension, MODULE_MANAGER_MODULE_DEFINITION_EXTENSION ); @@ -1300,6 +1301,106 @@ StringTableEntry ModuleManager::copyModule( ModuleDefinition* pSourceModuleDefin //----------------------------------------------------------------------------- +bool ModuleManager::renameModule(ModuleDefinition* pSourceModuleDefinition, const char* pNewModuleName) +{ + // Sanity! + AssertFatal(pSourceModuleDefinition != NULL, "Cannot copy module using a NULL source module definition."); + AssertFatal(pNewModuleName != NULL, "Cannot rename a module using a NULL module name."); + + // Fetch the source module Id. + StringTableEntry sourceModuleId = pSourceModuleDefinition->getModuleId(); + + // Is the source module definition registered with this module manager? + if (pSourceModuleDefinition->getModuleManager() != this) + { + // No, so warn. + Con::warnf("Module Manager: Cannot rename module Id '%s' as it is not registered with this module manager.", sourceModuleId); + return StringTable->EmptyString(); + } + + TamlModuleIdUpdateVisitor moduleIdUpdateVisitor; + moduleIdUpdateVisitor.setModuleIdFrom(sourceModuleId); + moduleIdUpdateVisitor.setModuleIdTo(pNewModuleName); + + Vector files; + + const char* pExtension = (const char*)"Taml"; + const U32 extensionLength = dStrlen(pExtension); + + Vector directories; + + StringTableEntry modulePath = pSourceModuleDefinition->getModulePath(); + + // Find directories. + if (!Platform::dumpDirectories(modulePath, directories, -1)) + { + // Warn. + Con::warnf("Module Manager: Cannot rename module Id '%s' in directory '%s' as sub-folder scanning/renaming failed.", + sourceModuleId, modulePath); + return false; + } + + // Iterate directories. + for (Vector::iterator basePathItr = directories.begin(); basePathItr != directories.end(); ++basePathItr) + { + // Fetch base path. + StringTableEntry basePath = *basePathItr; + + // Find files. + files.clear(); + if (!Platform::dumpPath(basePath, files, 0)) + { + // Warn. + Con::warnf("Module Manager: Cannot rename module Id '%s' in directory '%s' as sub-folder scanning/renaming failed.", + sourceModuleId, modulePath); + return false; + } + + // Iterate files. + for (Vector::iterator fileItr = files.begin(); fileItr != files.end(); ++fileItr) + { + // Fetch file info. + Platform::FileInfo* pFileInfo = fileItr; + + // Fetch filename. + const char* pFilename = pFileInfo->pFileName; + + // Find filename length. + const U32 filenameLength = dStrlen(pFilename); + + // Skip if extension is longer than filename. + if (extensionLength >= filenameLength) + continue; + + // Skip if extension not found. + if (dStricmp(pFilename + filenameLength - extensionLength, pExtension) != 0) + continue; + + char parseFileBuffer[1024]; + dSprintf(parseFileBuffer, sizeof(parseFileBuffer), "%s/%s", pFileInfo->pFullPath, pFilename); + + // Parse file. + if (!mTaml.parse(parseFileBuffer, moduleIdUpdateVisitor)) + { + // Warn. + Con::warnf("Module Manager: Failed to parse file '%s' whilst renaming module Id '%s' in directory '%s'.", + parseFileBuffer, sourceModuleId, modulePath); + return false; + } + } + } + + // Info. + if (mEchoInfo) + { + Con::printf("Module Manager: Finished renaming module Id '%s' to '%s'.", sourceModuleId, pNewModuleName); + } + + return true; +} + +//----------------------------------------------------------------------------- + bool ModuleManager::synchronizeDependencies( ModuleDefinition* pRootModuleDefinition, const char* pTargetDependencyPath ) { // Sanity! @@ -1986,7 +2087,7 @@ bool ModuleManager::registerModule( const char* pModulePath, const char* pModule } // Is the module group already loaded? - if ( findGroupLoaded( moduleGroup ) != NULL ) + if ( findGroupLoaded( moduleGroup ) != NULL && !mIgnoreLoadedGroups) { // Yes, so warn. Con::warnf( "Module Manager: Found module: '%s' but it is in a module group '%s' which has already been loaded.", diff --git a/Engine/source/module/moduleManager.h b/Engine/source/module/moduleManager.h index 9c7125610..60b81a5f3 100644 --- a/Engine/source/module/moduleManager.h +++ b/Engine/source/module/moduleManager.h @@ -120,6 +120,7 @@ private: char mModuleExtension[256]; Taml mTaml; SimSet mNotificationListeners; + bool mIgnoreLoadedGroups; // Module definition entry. struct ModuleDefinitionEntry : public typeModuleDefinitionVector @@ -161,6 +162,7 @@ public: bool scanModules( const char* pPath, const bool rootOnly = false ); /// Module unregister. + bool registerModule(const char* pModulePath, const char* pModuleFile); bool unregisterModule( const char* pModuleId, const U32 versionId ); /// Module (un)loading. @@ -179,6 +181,9 @@ public: StringTableEntry copyModule( ModuleDefinition* pSourceModuleDefinition, const char* pTargetModuleId, const char* pTargetPath, const bool useVersionPathing ); bool synchronizeDependencies( ModuleDefinition* pRootModuleDefinition, const char* pTargetDependencyPath ); + /// Editing modules + bool renameModule(ModuleDefinition* pSourceModuleDefinition, const char* pNewModuleName); + /// Module updates. inline bool isModuleMergeAvailable( void ) const { return Platform::isFile( getModuleMergeFilePath() ); } bool canMergeModules( const char* pMergeSourcePath ); @@ -188,10 +193,11 @@ public: void addListener( SimObject* pListener ); void removeListener( SimObject* pListener ); + void setIgnoreLoadedGroups(bool doIgnore) { mIgnoreLoadedGroups = doIgnore; } + private: void clearDatabase( void ); bool removeModuleDefinition( ModuleDefinition* pModuleDefinition ); - bool registerModule( const char* pModulePath, const char* pModuleFile ); void raiseModulePreLoadNotifications( ModuleDefinition* pModuleDefinition ); void raiseModulePostLoadNotifications( ModuleDefinition* pModuleDefinition ); diff --git a/Engine/source/module/moduleManager_ScriptBinding.h b/Engine/source/module/moduleManager_ScriptBinding.h index dc560d29a..8abc8aab5 100644 --- a/Engine/source/module/moduleManager_ScriptBinding.h +++ b/Engine/source/module/moduleManager_ScriptBinding.h @@ -46,6 +46,16 @@ DefineEngineMethod(ModuleManager, scanModules, bool, (const char* pRootPath, boo //----------------------------------------------------------------------------- +DefineEngineMethod(ModuleManager, registerModule, bool, (const char* pModulePath, const char* pModuleFile), ("", ""), + "Register the specified module.\n" + "@param moduleId The module Id to register.\n" + "@param versionId The version Id to register.\n" + "@return Whether the module was registered or not.\n") +{ + // Unregister the module. + return object->registerModule(pModulePath, pModuleFile); +} + DefineEngineMethod(ModuleManager, unregisterModule, bool, (const char* pModuleId, bool versionId), ("", false), "Unregister the specified module.\n" "@param moduleId The module Id to unregister.\n" @@ -246,6 +256,30 @@ DefineEngineMethod(ModuleManager, copyModule, String, (const char* sourceModuleD //----------------------------------------------------------------------------- +DefineEngineMethod(ModuleManager, renameModule, bool, (const char* sourceModuleDefinition, const char* pNewModuleName), +("", ""), +"Rename a module.\n" +"@param sourceModuleDefinition The module definition to rename.\n" +"@param pNewModuleName The new name the module should have.\n" +"@return Weither the rename was successful or not.\n") +{ + // Find the source module definition. + ModuleDefinition* pSourceModuleDefinition = dynamic_cast(Sim::findObject(sourceModuleDefinition)); + + // Was the module definition found? + if (pSourceModuleDefinition == NULL) + { + // No, so warn. + Con::warnf("ModuleManager::renameModule() - Could not find source module definition '%s'.", sourceModuleDefinition); + return ""; + } + + // Copy module. + return object->renameModule(pSourceModuleDefinition, pNewModuleName); +} + +//----------------------------------------------------------------------------- + DefineEngineMethod(ModuleManager, synchronizeDependencies, bool, (const char* rootModuleDefinition, const char* pTargetDependencyFolder), ("", ""), "Synchronize the module dependencies of a module definition to a target dependency folder.\n" "@param rootModuleDefinition The module definition used to determine dependencies.\n" @@ -342,3 +376,14 @@ DefineEngineMethod(ModuleManager, removeListener, void, (const char* listenerObj object->removeListener( pListener ); } + +//----------------------------------------------------------------------------- + +DefineEngineMethod(ModuleManager, ignoreLoadedGroups, void, (bool doIgnore), (false), + "Sets if the Module Manager should ingore laoded groups.\n" + "@param doIgnore Whether we should or should not ignore loaded groups.\n" + "@return No return value.\n") +{ + // Check whether the merge modules can current happen or not. + return object->setIgnoreLoadedGroups(doIgnore); +} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/CoreComponents.module b/Templates/BaseGame/game/core/CoreComponents.module index 7ca29196a..0636e3bb5 100644 --- a/Templates/BaseGame/game/core/CoreComponents.module +++ b/Templates/BaseGame/game/core/CoreComponents.module @@ -2,6 +2,9 @@ ModuleId="CoreComponentsModule" VersionId="1" Description="Module that implements the core engine-level components for the game." + ScriptFile="CoreComponents.cs" + CreateFunction="onCreate" + DestroyFunction="onDestroy" Group="Game"> + description="Allows the component owner to operate as a camera." + scriptFile="core/components/game/camera.cs" /> diff --git a/Templates/BaseGame/game/core/components/game/controlObject.asset.taml b/Templates/BaseGame/game/core/components/game/controlObject.asset.taml index 93f58119f..19515e833 100644 --- a/Templates/BaseGame/game/core/components/game/controlObject.asset.taml +++ b/Templates/BaseGame/game/core/components/game/controlObject.asset.taml @@ -6,5 +6,5 @@ componentClass="Component" friendlyName="Control Object" componentType="Game" - scriptFile="core/components/game/controlObject.cs" - description="Allows the component owner to be controlled by a client." /> + description="Allows the component owner to be controlled by a client." + scriptFile="core/components/game/controlObject.cs" /> diff --git a/Templates/BaseGame/game/core/components/game/itemRotate.asset.taml b/Templates/BaseGame/game/core/components/game/itemRotate.asset.taml index 806d0db19..4c0c1bec4 100644 --- a/Templates/BaseGame/game/core/components/game/itemRotate.asset.taml +++ b/Templates/BaseGame/game/core/components/game/itemRotate.asset.taml @@ -6,5 +6,5 @@ componentClass="Component" friendlyName="Item Rotation" componentType="Game" - scriptFile="core/components/game/itemRotate.cs" - description="Rotates the entity around an axis, like an item pickup." /> + description="Rotates the entity around an axis, like an item pickup." + scriptFile="core/components/game/itemRotate.cs" /> diff --git a/Templates/BaseGame/game/core/components/game/playerSpawner.asset.taml b/Templates/BaseGame/game/core/components/game/playerSpawner.asset.taml index bf2b872ef..8a597aca4 100644 --- a/Templates/BaseGame/game/core/components/game/playerSpawner.asset.taml +++ b/Templates/BaseGame/game/core/components/game/playerSpawner.asset.taml @@ -6,5 +6,5 @@ componentClass="Component" friendlyName="Player Spawner" componentType="Game" - scriptFile="core/components/game/playerSpawner.cs" - description="When a client connects, it spawns a player object for them and attaches them to it." /> + description="When a client connects, it spawns a player object for them and attaches them to it." + scriptFile="core/components/game/playerSpawner.cs" />