mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
Merge branch 'development' into issue_2115
This commit is contained in:
commit
c8e9b85ed3
520 changed files with 30537 additions and 151323 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -43,11 +43,6 @@ class ExampleAsset : public AssetBase
|
|||
{
|
||||
typedef AssetBase Parent;
|
||||
|
||||
AssetManager* mpOwningAssetManager;
|
||||
bool mAssetInitialized;
|
||||
AssetDefinition* mpAssetDefinition;
|
||||
U32 mAcquireReferenceCount;
|
||||
|
||||
public:
|
||||
ExampleAsset();
|
||||
virtual ~ExampleAsset();
|
||||
|
|
|
|||
222
Engine/source/T3D/assets/GUIAsset.cpp
Normal file
222
Engine/source/T3D/assets/GUIAsset.cpp
Normal file
|
|
@ -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<GUIAsset>*)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<GUIAsset>* pAssetPtr = dynamic_cast<AssetPtr<GUIAsset>*>((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;
|
||||
}
|
||||
89
Engine/source/T3D/assets/GUIAsset.h
Normal file
89
Engine/source/T3D/assets/GUIAsset.h
Normal file
|
|
@ -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_
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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_
|
||||
|
||||
|
|
|
|||
161
Engine/source/T3D/assets/ImageAsset.cpp
Normal file
161
Engine/source/T3D/assets/ImageAsset.cpp
Normal file
|
|
@ -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<ImageAsset>*)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<ImageAsset>* pAssetPtr = dynamic_cast<AssetPtr<ImageAsset>*>((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();
|
||||
}
|
||||
90
Engine/source/T3D/assets/ImageAsset.h
Normal file
90
Engine/source/T3D/assets/ImageAsset.h
Normal file
|
|
@ -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
|
||||
|
||||
126
Engine/source/T3D/assets/LevelAsset.cpp
Normal file
126
Engine/source/T3D/assets/LevelAsset.cpp
Normal file
|
|
@ -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<LevelAsset>*)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<LevelAsset>* pAssetPtr = dynamic_cast<AssetPtr<LevelAsset>*>((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);
|
||||
}
|
||||
72
Engine/source/T3D/assets/LevelAsset.h
Normal file
72
Engine/source/T3D/assets/LevelAsset.h
Normal file
|
|
@ -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_
|
||||
|
||||
241
Engine/source/T3D/assets/MaterialAsset.cpp
Normal file
241
Engine/source/T3D/assets/MaterialAsset.cpp
Normal file
|
|
@ -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<MaterialAsset>*)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<MaterialAsset>* pAssetPtr = dynamic_cast<AssetPtr<MaterialAsset>*>((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;
|
||||
}
|
||||
101
Engine/source/T3D/assets/MaterialAsset.h
Normal file
101
Engine/source/T3D/assets/MaterialAsset.h
Normal file
|
|
@ -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_
|
||||
|
||||
205
Engine/source/T3D/assets/ParticleAsset.cpp
Normal file
205
Engine/source/T3D/assets/ParticleAsset.cpp
Normal file
|
|
@ -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<ParticleAsset>*)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<ParticleAsset>* pAssetPtr = dynamic_cast<AssetPtr<ParticleAsset>*>((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;
|
||||
}
|
||||
89
Engine/source/T3D/assets/ParticleAsset.h
Normal file
89
Engine/source/T3D/assets/ParticleAsset.h
Normal file
|
|
@ -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_
|
||||
|
||||
129
Engine/source/T3D/assets/PostEffectAsset.cpp
Normal file
129
Engine/source/T3D/assets/PostEffectAsset.cpp
Normal file
|
|
@ -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<PostEffectAsset>*)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<PostEffectAsset>* pAssetPtr = dynamic_cast<AssetPtr<PostEffectAsset>*>((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();
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
// 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
|
||||
|
|
@ -19,53 +20,52 @@
|
|||
// 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
|
||||
|
||||
#include "console/simBase.h"
|
||||
#ifndef _ASSET_BASE_H_
|
||||
#include "assets/assetBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MENUBAR_H_
|
||||
#define _MENUBAR_H_
|
||||
#ifndef _ASSET_DEFINITION_H_
|
||||
#include "assets/assetDefinition.h"
|
||||
#endif
|
||||
|
||||
// Forward Refs
|
||||
class PlatformMenuBarData;
|
||||
class PopupMenu;
|
||||
class GuiCanvas;
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "string/stringUnit.h"
|
||||
#endif
|
||||
|
||||
class MenuBar : public SimSet
|
||||
#ifndef _ASSET_FIELD_TYPES_H_
|
||||
#include "assets/assetFieldTypes.h"
|
||||
#endif
|
||||
|
||||
#include "postFx/postEffect.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
class PostEffectAsset : public AssetBase
|
||||
{
|
||||
typedef SimSet Parent;
|
||||
typedef AssetBase Parent;
|
||||
|
||||
protected:
|
||||
PlatformMenuBarData *mData;
|
||||
GuiCanvas *mCanvas;
|
||||
|
||||
/// Update the native menu bar to ensure consistency with the set
|
||||
void updateMenuBar(PopupMenu *menu = NULL);
|
||||
|
||||
void createPlatformPopupMenuData();
|
||||
void deletePlatformPopupMenuData();
|
||||
StringTableEntry mScriptFile;
|
||||
|
||||
public:
|
||||
MenuBar();
|
||||
virtual ~MenuBar();
|
||||
DECLARE_CONOBJECT(MenuBar);
|
||||
PostEffectAsset();
|
||||
virtual ~PostEffectAsset();
|
||||
|
||||
/// Attach this menu bar to the native menu bar
|
||||
void attachToCanvas(GuiCanvas *owner, S32 pos);
|
||||
/// Remove this menu bar from the native menu bar
|
||||
void removeFromCanvas();
|
||||
/// Engine.
|
||||
static void initPersistFields();
|
||||
virtual void copyTo(SimObject* object);
|
||||
|
||||
/// Returns true if this menu is attached to the menu bar
|
||||
bool isAttachedToCanvas() { return mCanvas != NULL; }
|
||||
virtual void initializeAsset();
|
||||
|
||||
virtual void insertObject(SimObject *obj, S32 pos);
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(PostEffectAsset);
|
||||
|
||||
// Overridden SimSet methods to ensure menu bar consistency when attached
|
||||
virtual void addObject(SimObject *obj);
|
||||
virtual void removeObject(SimObject *obj);
|
||||
virtual void pushObject(SimObject *obj);
|
||||
virtual void popObject();
|
||||
|
||||
virtual bool reOrder(SimObject *obj, SimObject *target = 0);
|
||||
protected:
|
||||
virtual void onAssetRefresh(void) {}
|
||||
};
|
||||
|
||||
#endif // _MENUBAR_H_
|
||||
DefineConsoleType(TypePostEffectAssetPtr, PostEffectAsset)
|
||||
|
||||
#endif // _ASSET_BASE_H_
|
||||
|
||||
137
Engine/source/T3D/assets/ScriptAsset.cpp
Normal file
137
Engine/source/T3D/assets/ScriptAsset.cpp
Normal file
|
|
@ -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<ScriptAsset>*)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<ScriptAsset>* pAssetPtr = dynamic_cast<AssetPtr<ScriptAsset>*>((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);
|
||||
}
|
||||
69
Engine/source/T3D/assets/ScriptAsset.h
Normal file
69
Engine/source/T3D/assets/ScriptAsset.h
Normal file
|
|
@ -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_
|
||||
|
||||
131
Engine/source/T3D/assets/ShapeAnimationAsset.cpp
Normal file
131
Engine/source/T3D/assets/ShapeAnimationAsset.cpp
Normal file
|
|
@ -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<ShapeAnimationAsset>*)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<ShapeAnimationAsset>* pAssetPtr = dynamic_cast<AssetPtr<ShapeAnimationAsset>*>((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);
|
||||
}
|
||||
102
Engine/source/T3D/assets/ShapeAnimationAsset.h
Normal file
102
Engine/source/T3D/assets/ShapeAnimationAsset.h
Normal file
|
|
@ -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_
|
||||
|
||||
|
|
@ -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<ShapeAsset>*)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<ShapeAsset>* pAssetPtr = dynamic_cast<AssetPtr<ShapeAsset>*>((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<MaterialAsset> 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<ShapeAnimationAsset> 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;
|
||||
}
|
||||
|
|
@ -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<TSShape> mShape;
|
||||
|
||||
//Material assets we're dependent on and use
|
||||
Vector<StringTableEntry> mMaterialAssetIds;
|
||||
Vector<AssetPtr<MaterialAsset>> mMaterialAssets;
|
||||
|
||||
//Animation assets we're dependent on and use
|
||||
Vector<StringTableEntry> mAnimationAssetIds;
|
||||
Vector<AssetPtr<ShapeAnimationAsset>> 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<TSShape> 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
|
||||
|
||||
|
|
|
|||
141
Engine/source/T3D/assets/SoundAsset.cpp
Normal file
141
Engine/source/T3D/assets/SoundAsset.cpp
Normal file
|
|
@ -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<SoundAsset>*)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<SoundAsset>* pAssetPtr = dynamic_cast<AssetPtr<SoundAsset>*>((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)
|
||||
{
|
||||
|
||||
}
|
||||
75
Engine/source/T3D/assets/SoundAsset.h
Normal file
75
Engine/source/T3D/assets/SoundAsset.h
Normal file
|
|
@ -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_
|
||||
|
||||
207
Engine/source/T3D/assets/stateMachineAsset.cpp
Normal file
207
Engine/source/T3D/assets/stateMachineAsset.cpp
Normal file
|
|
@ -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<StateMachineAsset>*)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<StateMachineAsset>* pAssetPtr = dynamic_cast<AssetPtr<StateMachineAsset>*>((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;
|
||||
}
|
||||
89
Engine/source/T3D/assets/stateMachineAsset.h
Normal file
89
Engine/source/T3D/assets/stateMachineAsset.h
Normal file
|
|
@ -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
|
||||
|
||||
|
|
@ -72,7 +72,6 @@ IMPLEMENT_CALLBACK(AnimationComponent, onAnimationTrigger, void, (Component* obj
|
|||
AnimationComponent::AnimationComponent() : Component()
|
||||
{
|
||||
mNetworked = true;
|
||||
mNetFlags.set(Ghostable | ScopeAlways);
|
||||
|
||||
mFriendlyName = "Animation(Component)";
|
||||
mComponentType = "Render";
|
||||
|
|
@ -223,31 +222,19 @@ U32 AnimationComponent::packUpdate(NetConnection *con, U32 mask, BitStream *stre
|
|||
{
|
||||
U32 retMask = Parent::packUpdate(con, mask, stream);
|
||||
|
||||
//early test if we lack an owner, ghost-wise
|
||||
//no point in trying, just re-queue the mask and go
|
||||
if (!mOwner || con->getGhostIndex(mOwner) == -1)
|
||||
/*for (int i = 0; i < MaxScriptThreads; i++)
|
||||
{
|
||||
stream->writeFlag(false);
|
||||
return retMask |= ThreadMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
stream->writeFlag(true);
|
||||
|
||||
for (int i = 0; i < MaxScriptThreads; i++)
|
||||
Thread& st = mAnimationThreads[i];
|
||||
if (stream->writeFlag((st.sequence != -1 || st.state == Thread::Destroy) && (mask & (ThreadMaskN << i))))
|
||||
{
|
||||
Thread& st = mAnimationThreads[i];
|
||||
if (stream->writeFlag( (st.sequence != -1 || st.state == Thread::Destroy) && (mask & (ThreadMaskN << i)) ) )
|
||||
{
|
||||
stream->writeInt(st.sequence,ThreadSequenceBits);
|
||||
stream->writeInt(st.state,2);
|
||||
stream->write(st.timescale);
|
||||
stream->write(st.position);
|
||||
stream->writeFlag(st.atEnd);
|
||||
stream->writeFlag(st.transition);
|
||||
}
|
||||
stream->writeInt(st.sequence, ThreadSequenceBits);
|
||||
stream->writeInt(st.state, 2);
|
||||
stream->write(st.timescale);
|
||||
stream->write(st.position);
|
||||
stream->writeFlag(st.atEnd);
|
||||
stream->writeFlag(st.transition);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return retMask;
|
||||
}
|
||||
|
|
@ -256,29 +243,26 @@ void AnimationComponent::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
{
|
||||
Parent::unpackUpdate(con, stream);
|
||||
|
||||
if (stream->readFlag())
|
||||
/*for (S32 i = 0; i < MaxScriptThreads; i++)
|
||||
{
|
||||
for (S32 i = 0; i < MaxScriptThreads; i++)
|
||||
if (stream->readFlag())
|
||||
{
|
||||
if (stream->readFlag())
|
||||
{
|
||||
Thread& st = mAnimationThreads[i];
|
||||
U32 seq = stream->readInt(ThreadSequenceBits);
|
||||
st.state = stream->readInt(2);
|
||||
stream->read( &st.timescale );
|
||||
stream->read( &st.position );
|
||||
st.atEnd = stream->readFlag();
|
||||
bool transition = stream->readFlag();
|
||||
Thread& st = mAnimationThreads[i];
|
||||
U32 seq = stream->readInt(ThreadSequenceBits);
|
||||
st.state = stream->readInt(2);
|
||||
stream->read( &st.timescale );
|
||||
stream->read( &st.position );
|
||||
st.atEnd = stream->readFlag();
|
||||
bool transition = stream->readFlag();
|
||||
|
||||
if (!st.thread || st.sequence != seq && st.state != Thread::Destroy)
|
||||
setThreadSequence(i, seq, false, transition);
|
||||
else
|
||||
updateThread(st);
|
||||
|
||||
}
|
||||
if (!st.thread || st.sequence != seq && st.state != Thread::Destroy)
|
||||
setThreadSequence(i, seq, false, transition);
|
||||
else
|
||||
updateThread(st);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void AnimationComponent::processTick()
|
||||
{
|
||||
Parent::processTick();
|
||||
|
|
@ -327,9 +311,6 @@ const char *AnimationComponent::getThreadSequenceName(U32 slot)
|
|||
|
||||
bool AnimationComponent::setThreadSequence(U32 slot, S32 seq, bool reset, bool transition, F32 transTime)
|
||||
{
|
||||
if (!mOwnerShapeInstance)
|
||||
return false;
|
||||
|
||||
Thread& st = mAnimationThreads[slot];
|
||||
if (st.thread && st.sequence == seq && st.state == Thread::Play && !reset)
|
||||
return true;
|
||||
|
|
@ -340,7 +321,6 @@ bool AnimationComponent::setThreadSequence(U32 slot, S32 seq, bool reset, bool t
|
|||
|
||||
if (seq < MaxSequenceIndex)
|
||||
{
|
||||
setMaskBits(-1);
|
||||
setMaskBits(ThreadMaskN << slot);
|
||||
st.sequence = seq;
|
||||
st.transition = transition;
|
||||
|
|
@ -647,7 +627,7 @@ void AnimationComponent::advanceThreads(F32 dt)
|
|||
st.atEnd = true;
|
||||
updateThread(st);
|
||||
|
||||
if (!isGhost())
|
||||
if (!isClientObject())
|
||||
{
|
||||
Con::executef(this, "onAnimationEnd", st.thread->getSequenceName());
|
||||
}
|
||||
|
|
@ -660,7 +640,7 @@ void AnimationComponent::advanceThreads(F32 dt)
|
|||
mOwnerShapeInstance->advanceTime(dt, st.thread);
|
||||
}
|
||||
|
||||
if (mOwnerShapeInstance && !isGhost())
|
||||
if (mOwnerShapeInstance && !isClientObject())
|
||||
{
|
||||
for (U32 i = 1; i < 32; i++)
|
||||
{
|
||||
|
|
@ -672,8 +652,16 @@ void AnimationComponent::advanceThreads(F32 dt)
|
|||
}
|
||||
}
|
||||
|
||||
if (isGhost())
|
||||
if (isClientObject())
|
||||
{
|
||||
mOwnerShapeInstance->animate();
|
||||
/*mOwnerShapeInstance->animateGround();
|
||||
MatrixF groundTransform = mOwnerShapeInstance->getGroundTransform();
|
||||
if (groundTransform != MatrixF::Identity)
|
||||
{
|
||||
mOwner->setPosition(groundTransform.getPosition());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
422
Engine/source/T3D/components/audio/SoundComponent.cpp
Normal file
422
Engine/source/T3D/components/audio/SoundComponent.cpp
Normal file
|
|
@ -0,0 +1,422 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "T3D/components/audio/SoundComponent.h"
|
||||
#include "core/stream/bitStream.h"
|
||||
#include "sim/netConnection.h"
|
||||
|
||||
#include "sfx/sfxSystem.h"
|
||||
#include "sfx/sfxSource.h"
|
||||
#include "sfx/sfxTrack.h"
|
||||
#include "sfx/sfxDescription.h"
|
||||
#include "T3D/sfx/sfx3DWorld.h"
|
||||
|
||||
#include "sfx/sfxTrack.h"
|
||||
#include "sfx/sfxTypes.h"
|
||||
|
||||
#include "renderInstance/renderPassManager.h"
|
||||
#include "gfx/gfxDrawUtil.h"
|
||||
|
||||
// Timeout for non-looping sounds on a channel
|
||||
static SimTime sAudioTimeout = 500;
|
||||
|
||||
extern bool gEditingMission;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Constructor/Destructor
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
SoundComponent::SoundComponent() : Component()
|
||||
{
|
||||
//These flags inform that, in this particular component, we network down to the client, which enables the pack/unpackData functions to operate
|
||||
mNetworked = true;
|
||||
|
||||
mFriendlyName = "Sound(Component)";
|
||||
mComponentType = "Sound";
|
||||
mDescription = getDescriptionText("Stores up to 4 sounds for playback.");
|
||||
|
||||
for (U32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++) {
|
||||
mSoundThread[slotNum].play = false;
|
||||
mSoundThread[slotNum].profile = 0;
|
||||
mSoundThread[slotNum].sound = 0;
|
||||
|
||||
mSoundFile[slotNum] = NULL;
|
||||
mPreviewSound[slotNum] = false;
|
||||
mPlay[slotNum] = false;
|
||||
}
|
||||
}
|
||||
|
||||
SoundComponent::~SoundComponent()
|
||||
{
|
||||
}
|
||||
|
||||
IMPLEMENT_CO_NETOBJECT_V1(SoundComponent);
|
||||
|
||||
//Standard onAdd function, for when the component is created
|
||||
bool SoundComponent::onAdd()
|
||||
{
|
||||
if (!Parent::onAdd())
|
||||
return false;
|
||||
|
||||
for (U32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
mPreviewSound[slotNum] = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Standard onRemove function, when the component object is deleted
|
||||
void SoundComponent::onRemove()
|
||||
{
|
||||
Parent::onRemove();
|
||||
}
|
||||
|
||||
//This is called when the component has been added to an entity
|
||||
void SoundComponent::onComponentAdd()
|
||||
{
|
||||
Parent::onComponentAdd();
|
||||
|
||||
Con::printf("We were added to an entity! SoundComponent reporting in for owner entity %i", mOwner->getId());
|
||||
}
|
||||
|
||||
//This is called when the component has been removed from an entity
|
||||
void SoundComponent::onComponentRemove()
|
||||
{
|
||||
Con::printf("We were removed from our entity! SoundComponent signing off for owner entity %i", mOwner->getId());
|
||||
Parent::onComponentRemove();
|
||||
}
|
||||
|
||||
//This is called any time a component is added to an entity. Every component currently owned by the entity is informed of the event.
|
||||
//This allows you to do dependency behavior, like collisions being aware of a mesh component, etc
|
||||
void SoundComponent::componentAddedToOwner(Component *comp)
|
||||
{
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
{
|
||||
if (mPlay[slotNum])
|
||||
{
|
||||
playAudio(slotNum, mSoundFile[slotNum]);
|
||||
}
|
||||
}
|
||||
Con::printf("Our owner entity has a new component being added! SoundComponent welcomes component %i of type %s", comp->getId(), comp->getClassRep()->getNameSpace());
|
||||
}
|
||||
|
||||
//This is called any time a component is removed from an entity. Every component current owned by the entity is informed of the event.
|
||||
//This allows cleanup and dependency management.
|
||||
void SoundComponent::componentRemovedFromOwner(Component *comp)
|
||||
{
|
||||
Con::printf("Our owner entity has a removed a component! SoundComponent waves farewell to component %i of type %s", comp->getId(), comp->getClassRep()->getNameSpace());
|
||||
}
|
||||
|
||||
//Regular init persist fields function to set up static fields.
|
||||
void SoundComponent::initPersistFields()
|
||||
{
|
||||
//addArray("Sounds", MaxSoundThreads);
|
||||
addField("mSoundFile", TypeSFXTrackName, Offset(mSoundFile, SoundComponent), MaxSoundThreads, "If the text will not fit in the control, the deniedSound is played.");
|
||||
addProtectedField("mPreviewSound", TypeBool, Offset(mPreviewSound, SoundComponent),
|
||||
&_previewSound, &defaultProtectedGetFn, MaxSoundThreads, "Preview Sound", AbstractClassRep::FieldFlags::FIELD_ComponentInspectors);
|
||||
addProtectedField("play", TypeBool, Offset(mPlay, SoundComponent),
|
||||
&_autoplay, &defaultProtectedGetFn, MaxSoundThreads, "Whether playback of the emitter's sound should start as soon as the emitter object is added to the level.\n"
|
||||
"If this is true, the emitter will immediately start to play when the level is loaded.");
|
||||
//endArray("Sounds");
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
||||
bool SoundComponent::_previewSound(void *object, const char *index, const char *data)
|
||||
{
|
||||
U32 slotNum = (index != NULL) ? dAtoui(index) : 0;
|
||||
SoundComponent* component = reinterpret_cast< SoundComponent* >(object);
|
||||
if (!component->mPreviewSound[slotNum])
|
||||
component->playAudio(slotNum, component->mSoundFile[slotNum]);
|
||||
else
|
||||
component->stopAudio(slotNum);
|
||||
component->mPreviewSound[slotNum] = !component->mPreviewSound[slotNum];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SoundComponent::_autoplay(void *object, const char *index, const char *data)
|
||||
{
|
||||
U32 slotNum = (index != NULL) ? dAtoui(index) : 0;
|
||||
SoundComponent* component = reinterpret_cast< SoundComponent* >(object);
|
||||
component->mPlay[slotNum] = dAtoui(data);
|
||||
if (component->mPlay[slotNum])
|
||||
component->playAudio(slotNum, component->mSoundFile[slotNum]);
|
||||
else
|
||||
component->stopAudio(slotNum);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
U32 SoundComponent::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
||||
{
|
||||
U32 retMask = Parent::packUpdate(con, mask, stream);
|
||||
|
||||
if (mask & InitialUpdateMask)
|
||||
{
|
||||
// mask off sounds that aren't playing
|
||||
S32 slotNum;
|
||||
for (slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
if (!mSoundThread[slotNum].play)
|
||||
mask &= ~(SoundMaskN << slotNum);
|
||||
}
|
||||
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
stream->writeFlag(mPreviewSound[slotNum]);
|
||||
|
||||
if (stream->writeFlag(mask & SoundMask))
|
||||
{
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
{
|
||||
Sound& st = mSoundThread[slotNum];
|
||||
|
||||
if (stream->writeFlag(mask & (SoundMaskN << slotNum)))
|
||||
{
|
||||
if (stream->writeFlag(st.play))
|
||||
//stream->writeRangedU32(st.profile->getId(), DataBlockObjectIdFirst,
|
||||
// DataBlockObjectIdLast);
|
||||
stream->writeString(st.profile->getName());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retMask;
|
||||
}
|
||||
|
||||
void SoundComponent::unpackUpdate(NetConnection *con, BitStream *stream)
|
||||
{
|
||||
Parent::unpackUpdate(con, stream);
|
||||
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
mPreviewSound[slotNum] = stream->readFlag();
|
||||
|
||||
if (stream->readFlag())
|
||||
{
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
{
|
||||
if (stream->readFlag())
|
||||
{
|
||||
Sound& st = mSoundThread[slotNum];
|
||||
st.play = stream->readFlag();
|
||||
if (st.play)
|
||||
{
|
||||
//st.profile = (SFXTrack*)stream->readRangedU32(DataBlockObjectIdFirst,
|
||||
// DataBlockObjectIdLast);
|
||||
char profileName[255];
|
||||
stream->readString(profileName);
|
||||
|
||||
if (!Sim::findObject(profileName, st.profile))
|
||||
Con::errorf("Could not find SFXTrack");
|
||||
}
|
||||
|
||||
//if (isProperlyAdded())
|
||||
updateAudioState(st);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//This allows custom behavior in the event the owner is being edited
|
||||
void SoundComponent::onInspect()
|
||||
{
|
||||
}
|
||||
|
||||
//This allows cleanup of the custom editor behavior if our owner stopped being edited
|
||||
void SoundComponent::onEndInspect()
|
||||
{
|
||||
}
|
||||
|
||||
//Process tick update function, natch
|
||||
void SoundComponent::processTick()
|
||||
{
|
||||
Parent::processTick();
|
||||
}
|
||||
|
||||
//Client-side advance function
|
||||
void SoundComponent::advanceTime(F32 dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Client-side interpolation function
|
||||
void SoundComponent::interpolateTick(F32 delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SoundComponent::prepRenderImage(SceneRenderState *state)
|
||||
{
|
||||
if (!mEnabled || !mOwner || !gEditingMission)
|
||||
return;
|
||||
ObjectRenderInst* ri = state->getRenderPass()->allocInst< ObjectRenderInst >();
|
||||
|
||||
ri->renderDelegate.bind(this, &SoundComponent::_renderObject);
|
||||
ri->type = RenderPassManager::RIT_Editor;
|
||||
ri->defaultKey = 0;
|
||||
ri->defaultKey2 = 0;
|
||||
|
||||
state->getRenderPass()->addInst(ri);
|
||||
}
|
||||
|
||||
void SoundComponent::_renderObject(ObjectRenderInst *ri,
|
||||
SceneRenderState *state,
|
||||
BaseMatInstance *overrideMat)
|
||||
{
|
||||
if (overrideMat)
|
||||
return;
|
||||
|
||||
GFXStateBlockDesc desc;
|
||||
desc.setBlend(true);
|
||||
|
||||
MatrixF camera = GFX->getWorldMatrix();
|
||||
camera.inverse();
|
||||
Point3F pos = mOwner->getPosition();
|
||||
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
{
|
||||
if (mPreviewSound[slotNum])
|
||||
{
|
||||
Sound& st = mSoundThread[slotNum];
|
||||
if (st.sound && st.sound->getDescription())
|
||||
{
|
||||
F32 minRad = st.sound->getDescription()->mMinDistance;
|
||||
F32 falloffRad = st.sound->getDescription()->mMaxDistance;
|
||||
SphereF sphere(pos, falloffRad);
|
||||
if (sphere.isContained(camera.getPosition()))
|
||||
desc.setCullMode(GFXCullNone);
|
||||
|
||||
GFX->getDrawUtil()->drawSphere(desc, minRad, pos, ColorI(255, 0, 255, 64));
|
||||
GFX->getDrawUtil()->drawSphere(desc, falloffRad, pos, ColorI(128, 0, 128, 64));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SoundComponent::playAudio(U32 slotNum, SFXTrack* _profile)
|
||||
{
|
||||
AssertFatal(slotNum < MaxSoundThreads, "ShapeBase::playAudio() bad slot index");
|
||||
SFXTrack* profile = (_profile != NULL) ? _profile : mSoundFile[slotNum];
|
||||
Sound& st = mSoundThread[slotNum];
|
||||
if (profile && (!st.play || st.profile != profile))
|
||||
{
|
||||
setMaskBits(SoundMaskN << slotNum);
|
||||
st.play = true;
|
||||
st.profile = profile;
|
||||
updateAudioState(st);
|
||||
}
|
||||
}
|
||||
|
||||
void SoundComponent::stopAudio(U32 slotNum)
|
||||
{
|
||||
AssertFatal(slotNum < MaxSoundThreads, "ShapeBase::stopAudio() bad slot index");
|
||||
|
||||
Sound& st = mSoundThread[slotNum];
|
||||
if (st.play)
|
||||
{
|
||||
st.play = false;
|
||||
setMaskBits(SoundMaskN << slotNum);
|
||||
updateAudioState(st);
|
||||
}
|
||||
}
|
||||
|
||||
void SoundComponent::updateServerAudio()
|
||||
{
|
||||
// Timeout non-looping sounds
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
{
|
||||
Sound& st = mSoundThread[slotNum];
|
||||
if (st.play && st.timeout && st.timeout < Sim::getCurrentTime())
|
||||
{
|
||||
//clearMaskBits(SoundMaskN << slotNum);
|
||||
st.play = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SoundComponent::updateAudioState(Sound& st)
|
||||
{
|
||||
SFX_DELETE(st.sound);
|
||||
|
||||
if (st.play && st.profile)
|
||||
{
|
||||
if (isClientObject())
|
||||
{
|
||||
//if (Sim::findObject(SimObjectId((uintptr_t)st.profile), st.profile))
|
||||
// {
|
||||
MatrixF transform = mOwner->getTransform();
|
||||
st.sound = SFX->createSource(st.profile, &transform);
|
||||
if (st.sound)
|
||||
st.sound->play();
|
||||
//}
|
||||
else
|
||||
st.play = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-looping sounds timeout on the server
|
||||
st.timeout = 0;
|
||||
if (!st.profile->getDescription()->mIsLooping)
|
||||
st.timeout = Sim::getCurrentTime() + sAudioTimeout;
|
||||
}
|
||||
}
|
||||
else
|
||||
st.play = false;
|
||||
}
|
||||
|
||||
void SoundComponent::updateAudioPos()
|
||||
{
|
||||
for (S32 slotNum = 0; slotNum < MaxSoundThreads; slotNum++)
|
||||
{
|
||||
SFXSource* source = mSoundThread[slotNum].sound;
|
||||
if (source)
|
||||
source->setTransform(mOwner->getTransform());
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
DefineEngineMethod(SoundComponent, playAudio, bool, (S32 slot, SFXTrack* track), (0, nullAsType<SFXTrack*>()),
|
||||
"@brief Attach a sound to this shape and start playing it.\n\n"
|
||||
|
||||
"@param slot Audio slot index for the sound (valid range is 0 - 3)\n" // 3 = ShapeBase::MaxSoundThreads-1
|
||||
"@param track SFXTrack to play\n"
|
||||
"@return true if the sound was attached successfully, false if failed\n\n"
|
||||
|
||||
"@see stopAudio()\n")
|
||||
{
|
||||
if (track && slot >= 0 && slot < SoundComponent::MaxSoundThreads) {
|
||||
object->playAudio(slot, track);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DefineEngineMethod(SoundComponent, stopAudio, bool, (S32 slot), ,
|
||||
"@brief Stop a sound started with playAudio.\n\n"
|
||||
|
||||
"@param slot audio slot index (started with playAudio)\n"
|
||||
"@return true if the sound was stopped successfully, false if failed\n\n"
|
||||
|
||||
"@see playAudio()\n")
|
||||
{
|
||||
if (slot >= 0 && slot < SoundComponent::MaxSoundThreads) {
|
||||
object->stopAudio(slot);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
129
Engine/source/T3D/components/audio/SoundComponent.h
Normal file
129
Engine/source/T3D/components/audio/SoundComponent.h
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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 EXAMPLE_COMPONENT_H
|
||||
#define EXAMPLE_COMPONENT_H
|
||||
#pragma once
|
||||
|
||||
#ifndef COMPONENT_H
|
||||
#include "T3D/components/component.h"
|
||||
#endif
|
||||
#ifndef RENDER_COMPONENT_INTERFACE_H
|
||||
#include "T3D/components/render/renderComponentInterface.h"
|
||||
#endif
|
||||
|
||||
class SFXSource;
|
||||
|
||||
//SoundComponent
|
||||
//A basic example of the various functions you can utilize to make your own component!
|
||||
//This example doesn't really DO anything, persay, but you can readily copy it as a base
|
||||
//and use it as a starting point for your own.
|
||||
class SoundComponent : public Component, public RenderComponentInterface, public EditorInspectInterface
|
||||
{
|
||||
typedef Component Parent;
|
||||
|
||||
public:
|
||||
enum PublicConstants
|
||||
{
|
||||
MaxSoundThreads = 4, ///< Should be a power of 2
|
||||
};
|
||||
|
||||
/// @name Network state masks
|
||||
/// @{
|
||||
|
||||
///
|
||||
enum SoundComponentMasks
|
||||
{
|
||||
SoundMaskN = Parent::NextFreeMask << 6, ///< Extends + MaxSoundThreads bits
|
||||
};
|
||||
|
||||
enum BaseMaskConstants
|
||||
{
|
||||
SoundMask = (SoundMaskN << MaxSoundThreads) - SoundMaskN,
|
||||
};
|
||||
/// @name Scripted Sound
|
||||
/// @{
|
||||
struct Sound {
|
||||
bool play; ///< Are we playing this sound?
|
||||
SimTime timeout; ///< Time until we stop playing this sound.
|
||||
SFXTrack* profile; ///< Profile on server
|
||||
SFXSource* sound; ///< Sound on client
|
||||
Sound()
|
||||
{
|
||||
play = false;
|
||||
timeout = 0;
|
||||
profile = NULL;
|
||||
sound = NULL;
|
||||
}
|
||||
};
|
||||
Sound mSoundThread[MaxSoundThreads];
|
||||
SFXTrack* mSoundFile[MaxSoundThreads];
|
||||
bool mPreviewSound[MaxSoundThreads];
|
||||
bool mPlay[MaxSoundThreads];
|
||||
/// @}
|
||||
|
||||
SoundComponent();
|
||||
virtual ~SoundComponent();
|
||||
DECLARE_CONOBJECT(SoundComponent);
|
||||
|
||||
virtual bool onAdd();
|
||||
virtual void onRemove();
|
||||
static void initPersistFields();
|
||||
static bool _previewSound(void *object, const char *index, const char *data);
|
||||
static bool _autoplay(void *object, const char *index, const char *data);
|
||||
|
||||
virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
|
||||
virtual void unpackUpdate(NetConnection *con, BitStream *stream);
|
||||
|
||||
virtual void onComponentRemove();
|
||||
virtual void onComponentAdd();
|
||||
|
||||
virtual void componentAddedToOwner(Component *comp);
|
||||
virtual void componentRemovedFromOwner(Component *comp);
|
||||
|
||||
virtual void onInspect();
|
||||
virtual void onEndInspect();
|
||||
|
||||
virtual void processTick();
|
||||
virtual void advanceTime(F32 dt);
|
||||
virtual void interpolateTick(F32 delta);
|
||||
|
||||
void prepRenderImage(SceneRenderState* state);
|
||||
void _renderObject(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
|
||||
|
||||
virtual void playAudio(U32 slotNum, SFXTrack* profile = NULL);
|
||||
virtual void stopAudio(U32 slot);
|
||||
virtual void updateServerAudio();
|
||||
virtual void updateAudioState(Sound& st);
|
||||
virtual void updateAudioPos();
|
||||
|
||||
//why god why
|
||||
virtual TSShape* getShape() { return NULL; };
|
||||
Signal< void(RenderComponentInterface*) > onShapeChanged;
|
||||
virtual TSShapeInstance* getShapeInstance() { return NULL; };
|
||||
Signal< void(RenderComponentInterface*) > onShapeInstanceChanged;
|
||||
virtual MatrixF getNodeTransform(S32 nodeIdx) { return MatrixF::Identity; };
|
||||
virtual Vector<MatrixF> getNodeTransforms() { return NULL; };
|
||||
virtual void setNodeTransforms(Vector<MatrixF> transforms) {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -79,6 +79,7 @@ CameraComponent::CameraComponent() : Component()
|
|||
mTargetNode = "";
|
||||
|
||||
mUseParentTransform = true;
|
||||
mNetworked = true;
|
||||
|
||||
mFriendlyName = "Camera(Component)";
|
||||
}
|
||||
|
|
@ -202,7 +203,7 @@ void CameraComponent::setCameraFov(F32 fov)
|
|||
void CameraComponent::onCameraScopeQuery(NetConnection *cr, CameraScopeQuery * query)
|
||||
{
|
||||
// update the camera query
|
||||
query->camera = this;
|
||||
query->camera = mOwner;//this;
|
||||
|
||||
if(GameConnection * con = dynamic_cast<GameConnection*>(cr))
|
||||
{
|
||||
|
|
@ -357,7 +358,8 @@ U32 CameraComponent::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
|||
mTargetNodeIdx = nodeIndex;
|
||||
}
|
||||
|
||||
stream->writeInt(mTargetNodeIdx, 32);
|
||||
if(stream->writeFlag(mTargetNodeIdx > -1))
|
||||
stream->writeInt(mTargetNodeIdx, 32);
|
||||
//send offsets here
|
||||
|
||||
stream->writeCompressedPoint(mPosOffset);
|
||||
|
|
@ -382,7 +384,10 @@ void CameraComponent::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
|
||||
if(stream->readFlag())
|
||||
{
|
||||
mTargetNodeIdx = stream->readInt(32);
|
||||
if (stream->readFlag())
|
||||
mTargetNodeIdx = stream->readInt(32);
|
||||
else
|
||||
mTargetNodeIdx = -1;
|
||||
|
||||
stream->readCompressedPoint(&mPosOffset);
|
||||
|
||||
|
|
|
|||
|
|
@ -125,8 +125,6 @@ EndImplementEnumType;
|
|||
//
|
||||
CollisionComponent::CollisionComponent() : Component()
|
||||
{
|
||||
mNetFlags.set(Ghostable | ScopeAlways);
|
||||
|
||||
mFriendlyName = "Collision(Component)";
|
||||
|
||||
mOwnerRenderInterface = NULL;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "console/engineAPI.h"
|
||||
#include "sim/netConnection.h"
|
||||
#include "console/consoleInternal.h"
|
||||
#include "T3D/assets/MaterialAsset.h"
|
||||
|
||||
#define DECLARE_NATIVE_COMPONENT( ComponentType ) \
|
||||
Component* staticComponentTemplate = new ComponentType; \
|
||||
|
|
@ -42,17 +43,16 @@
|
|||
|
||||
Component::Component()
|
||||
{
|
||||
mFriendlyName = StringTable->lookup("");
|
||||
mFromResource = StringTable->lookup("");
|
||||
mComponentType = StringTable->lookup("");
|
||||
mComponentGroup = StringTable->lookup("");
|
||||
mNetworkType = StringTable->lookup("");
|
||||
mTemplateName = StringTable->lookup("");
|
||||
//mDependency = StringTable->lookup("");
|
||||
mFriendlyName = StringTable->EmptyString();
|
||||
mFromResource = StringTable->EmptyString();
|
||||
mComponentType = StringTable->EmptyString();
|
||||
mComponentGroup = StringTable->EmptyString();
|
||||
mNetworkType = StringTable->EmptyString();
|
||||
mTemplateName = StringTable->EmptyString();
|
||||
//mDependency = StringTable->EmptyString();
|
||||
|
||||
mNetworked = false;
|
||||
|
||||
|
||||
// [tom, 1/12/2007] We manage the memory for the description since it
|
||||
// could be loaded from a file and thus massive. This is accomplished with
|
||||
// protected fields, but since they still call Con::getData() the field
|
||||
|
|
@ -64,7 +64,9 @@ Component::Component()
|
|||
|
||||
mCanSaveFieldDictionary = false;
|
||||
|
||||
mNetFlags.set(Ghostable);
|
||||
mOriginatingAssetId = StringTable->EmptyString();
|
||||
|
||||
mIsServerObject = true;
|
||||
}
|
||||
|
||||
Component::~Component()
|
||||
|
|
@ -97,6 +99,10 @@ void Component::initPersistFields()
|
|||
|
||||
//addField("hidden", TypeBool, Offset(mHidden, Component), "Flags if this behavior is shown in the editor or not", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
|
||||
addProtectedField("enabled", TypeBool, Offset(mEnabled, Component), &_setEnabled, &defaultProtectedGetFn, "");
|
||||
|
||||
addField("originatingAsset", TypeComponentAssetPtr, Offset(mOriginatingAsset, Component),
|
||||
"Asset that spawned this component, used for tracking/housekeeping", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
|
||||
|
||||
endGroup("Component");
|
||||
|
||||
Parent::initPersistFields();
|
||||
|
|
@ -149,6 +155,7 @@ bool Component::onAdd()
|
|||
return false;
|
||||
|
||||
setMaskBits(UpdateMask);
|
||||
setMaskBits(NamespaceMask);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -191,7 +198,6 @@ void Component::onComponentRemove()
|
|||
{
|
||||
mOwner->onComponentAdded.remove(this, &Component::componentAddedToOwner);
|
||||
mOwner->onComponentRemoved.remove(this, &Component::componentRemovedFromOwner);
|
||||
mOwner->onTransformSet.remove(this, &Component::ownerTransformSet);
|
||||
}
|
||||
|
||||
mOwner = NULL;
|
||||
|
|
@ -205,7 +211,6 @@ void Component::setOwner(Entity* owner)
|
|||
{
|
||||
mOwner->onComponentAdded.remove(this, &Component::componentAddedToOwner);
|
||||
mOwner->onComponentRemoved.remove(this, &Component::componentRemovedFromOwner);
|
||||
mOwner->onTransformSet.remove(this, &Component::ownerTransformSet);
|
||||
|
||||
mOwner->removeComponent(this, false);
|
||||
}
|
||||
|
|
@ -216,11 +221,18 @@ void Component::setOwner(Entity* owner)
|
|||
{
|
||||
mOwner->onComponentAdded.notify(this, &Component::componentAddedToOwner);
|
||||
mOwner->onComponentRemoved.notify(this, &Component::componentRemovedFromOwner);
|
||||
mOwner->onTransformSet.notify(this, &Component::ownerTransformSet);
|
||||
}
|
||||
|
||||
if (isServerObject())
|
||||
{
|
||||
setMaskBits(OwnerMask);
|
||||
|
||||
//if we have any outstanding maskbits, push them along to have the network update happen on the entity
|
||||
if (mDirtyMaskBits != 0 && mOwner)
|
||||
{
|
||||
mOwner->setMaskBits(Entity::ComponentsUpdateMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Component::componentAddedToOwner(Component *comp)
|
||||
|
|
@ -233,16 +245,19 @@ void Component::componentRemovedFromOwner(Component *comp)
|
|||
return;
|
||||
}
|
||||
|
||||
void Component::ownerTransformSet(MatrixF *mat)
|
||||
void Component::setMaskBits(U32 orMask)
|
||||
{
|
||||
return;
|
||||
AssertFatal(orMask != 0, "Invalid net mask bits set.");
|
||||
|
||||
if (mOwner)
|
||||
mOwner->setComponentNetMask(this, orMask);
|
||||
}
|
||||
|
||||
U32 Component::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
||||
{
|
||||
U32 retMask = Parent::packUpdate(con, mask, stream);
|
||||
U32 retMask = 0;
|
||||
|
||||
if (mask & OwnerMask)
|
||||
/*if (mask & OwnerMask)
|
||||
{
|
||||
if (mOwner != NULL)
|
||||
{
|
||||
|
|
@ -267,21 +282,32 @@ U32 Component::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
|||
}
|
||||
}
|
||||
else
|
||||
stream->writeFlag(false);
|
||||
stream->writeFlag(false);*/
|
||||
|
||||
if (stream->writeFlag(mask & EnableMask))
|
||||
{
|
||||
stream->writeFlag(mEnabled);
|
||||
}
|
||||
|
||||
/*if (stream->writeFlag(mask & NamespaceMask))
|
||||
{
|
||||
const char* name = getName();
|
||||
if (stream->writeFlag(name && name[0]))
|
||||
stream->writeString(String(name));
|
||||
|
||||
if (stream->writeFlag(mSuperClassName && mSuperClassName[0]))
|
||||
stream->writeString(String(mSuperClassName));
|
||||
|
||||
if (stream->writeFlag(mClassName && mClassName[0]))
|
||||
stream->writeString(String(mClassName));
|
||||
}*/
|
||||
|
||||
return retMask;
|
||||
}
|
||||
|
||||
void Component::unpackUpdate(NetConnection *con, BitStream *stream)
|
||||
{
|
||||
Parent::unpackUpdate(con, stream);
|
||||
|
||||
if (stream->readFlag())
|
||||
/*if (stream->readFlag())
|
||||
{
|
||||
if (stream->readFlag())
|
||||
{
|
||||
|
|
@ -297,12 +323,38 @@ void Component::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
//it's being nulled out
|
||||
setOwner(NULL);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (stream->readFlag())
|
||||
{
|
||||
mEnabled = stream->readFlag();
|
||||
}
|
||||
|
||||
/*if (stream->readFlag())
|
||||
{
|
||||
if (stream->readFlag())
|
||||
{
|
||||
char name[256];
|
||||
stream->readString(name);
|
||||
assignName(name);
|
||||
}
|
||||
|
||||
if (stream->readFlag())
|
||||
{
|
||||
char superClassname[256];
|
||||
stream->readString(superClassname);
|
||||
mSuperClassName = superClassname;
|
||||
}
|
||||
|
||||
if (stream->readFlag())
|
||||
{
|
||||
char classname[256];
|
||||
stream->readString(classname);
|
||||
mClassName = classname;
|
||||
}
|
||||
|
||||
linkNamespaces();
|
||||
}*/
|
||||
}
|
||||
|
||||
void Component::packToStream(Stream &stream, U32 tabStop, S32 behaviorID, U32 flags /* = 0 */)
|
||||
|
|
@ -346,6 +398,10 @@ void Component::setDataField(StringTableEntry slotName, const char *array, const
|
|||
onDataSet.trigger(this, slotName, value);
|
||||
}
|
||||
|
||||
StringTableEntry Component::getComponentName()
|
||||
{
|
||||
return getNamespace()->getName();
|
||||
}
|
||||
|
||||
//catch any behavior field updates
|
||||
void Component::onStaticModified(const char* slotName, const char* newValue)
|
||||
|
|
@ -417,7 +473,7 @@ void Component::addComponentField(const char *fieldName, const char *desc, const
|
|||
else if (fieldType == StringTable->insert("vector"))
|
||||
fieldTypeMask = TypePoint3F;
|
||||
else if (fieldType == StringTable->insert("material"))
|
||||
fieldTypeMask = TypeMaterialName;
|
||||
fieldTypeMask = TypeMaterialAssetPtr;
|
||||
else if (fieldType == StringTable->insert("image"))
|
||||
fieldTypeMask = TypeImageFilename;
|
||||
else if (fieldType == StringTable->insert("shape"))
|
||||
|
|
@ -426,8 +482,19 @@ void Component::addComponentField(const char *fieldName, const char *desc, const
|
|||
fieldTypeMask = TypeBool;
|
||||
else if (fieldType == StringTable->insert("object"))
|
||||
fieldTypeMask = TypeSimObjectPtr;
|
||||
else if (fieldType == StringTable->insert("string"))
|
||||
fieldTypeMask = TypeString;
|
||||
else if (fieldType == StringTable->insert("colorI"))
|
||||
fieldTypeMask = TypeColorI;
|
||||
else if (fieldType == StringTable->insert("colorF"))
|
||||
fieldTypeMask = TypeColorF;
|
||||
else if (fieldType == StringTable->insert("ease"))
|
||||
fieldTypeMask = TypeEaseF;
|
||||
else if (fieldType == StringTable->insert("gameObject"))
|
||||
fieldTypeMask = TypeGameObjectAssetPtr;
|
||||
else
|
||||
fieldTypeMask = TypeString;
|
||||
field.mFieldTypeName = fieldType;
|
||||
|
||||
field.mFieldType = fieldTypeMask;
|
||||
|
||||
|
|
@ -603,6 +670,17 @@ ConsoleMethod(Component, setComponentield, const char *, 3, 3, "(int index) - Ge
|
|||
return buf;
|
||||
}
|
||||
|
||||
DefineConsoleMethod(Component, getComponentFieldType, const char *, (String fieldName), ,
|
||||
"Get the number of static fields on the object.\n"
|
||||
"@return The number of static fields defined on the object.")
|
||||
{
|
||||
ComponentField *field = object->getComponentField(fieldName);
|
||||
if (field == NULL)
|
||||
return "";
|
||||
|
||||
return field->mFieldTypeName;;
|
||||
}
|
||||
|
||||
ConsoleMethod(Component, getBehaviorFieldUserData, const char *, 3, 3, "(int index) - Gets the UserData associated with a field by index in the field list\n"
|
||||
"@param index The index of the behavior\n"
|
||||
"@return Returns a string representing the user data of this field\n")
|
||||
|
|
|
|||
|
|
@ -32,14 +32,22 @@
|
|||
#ifndef CORE_INTERFACES_H
|
||||
#include "T3D/components/coreInterfaces.h"
|
||||
#endif
|
||||
#ifndef _ASSET_PTR_H_
|
||||
#include "assets/assetPtr.h"
|
||||
#endif
|
||||
#ifndef COMPONENT_ASSET_H
|
||||
#include "T3D/assets/ComponentAsset.h"
|
||||
#endif
|
||||
|
||||
class Entity;
|
||||
class Namespace;
|
||||
|
||||
struct ComponentField
|
||||
{
|
||||
StringTableEntry mFieldName;
|
||||
StringTableEntry mFieldDescription;
|
||||
|
||||
StringTableEntry mFieldTypeName;
|
||||
S32 mFieldType;
|
||||
StringTableEntry mUserData;
|
||||
|
||||
|
|
@ -56,9 +64,9 @@ struct ComponentField
|
|||
///
|
||||
///
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class Component : public NetObject, public UpdateInterface
|
||||
class Component : public SimObject, public UpdateInterface
|
||||
{
|
||||
typedef NetObject Parent;
|
||||
typedef SimObject Parent;
|
||||
|
||||
protected:
|
||||
StringTableEntry mFriendlyName;
|
||||
|
|
@ -81,6 +89,13 @@ protected:
|
|||
bool mHidden;
|
||||
bool mEnabled;
|
||||
|
||||
StringTableEntry mOriginatingAssetId;
|
||||
AssetPtr<ComponentAsset> mOriginatingAsset;
|
||||
|
||||
U32 mDirtyMaskBits;
|
||||
|
||||
bool mIsServerObject;
|
||||
|
||||
public:
|
||||
Component();
|
||||
virtual ~Component();
|
||||
|
|
@ -102,7 +117,8 @@ public:
|
|||
//This is called when a different component is removed from our owner entity
|
||||
virtual void componentRemovedFromOwner(Component *comp);
|
||||
|
||||
virtual void ownerTransformSet(MatrixF *mat);
|
||||
//Overridden by components that actually care
|
||||
virtual void ownerTransformSet(MatrixF *mat) {}
|
||||
|
||||
void setOwner(Entity* pOwner);
|
||||
inline Entity *getOwner() { return mOwner ? mOwner : NULL; }
|
||||
|
|
@ -175,9 +191,20 @@ public:
|
|||
OwnerMask = BIT(1),
|
||||
UpdateMask = BIT(2),
|
||||
EnableMask = BIT(3),
|
||||
NextFreeMask = BIT(4)
|
||||
NamespaceMask = BIT(4),
|
||||
NextFreeMask = BIT(5)
|
||||
};
|
||||
|
||||
virtual void setMaskBits(U32 orMask);
|
||||
virtual void clearMaskBits() {
|
||||
mDirtyMaskBits = 0;
|
||||
}
|
||||
|
||||
bool isServerObject() { return mIsServerObject; }
|
||||
bool isClientObject() { return !mIsServerObject; }
|
||||
|
||||
void setIsServerObject(bool isServerObj) { mIsServerObject = isServerObj; }
|
||||
|
||||
virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
|
||||
virtual void unpackUpdate(NetConnection *con, BitStream *stream);
|
||||
/// @}
|
||||
|
|
@ -192,6 +219,8 @@ public:
|
|||
void checkComponentFieldModified(const char* slotName, const char* newValue);
|
||||
|
||||
virtual void checkDependencies(){}
|
||||
|
||||
StringTableEntry getComponentName();
|
||||
};
|
||||
|
||||
#endif // COMPONENT_H
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ StateMachineComponent::StateMachineComponent() : Component()
|
|||
|
||||
//doesn't need to be networked
|
||||
mNetworked = false;
|
||||
mNetFlags.clear();
|
||||
}
|
||||
|
||||
StateMachineComponent::~StateMachineComponent()
|
||||
|
|
|
|||
|
|
@ -330,93 +330,6 @@ void PlayerControllerComponent::updateMove()
|
|||
bool doStandardMove = true;
|
||||
GameConnection* con = mOwner->getControllingClient();
|
||||
|
||||
#ifdef TORQUE_EXTENDED_MOVE
|
||||
// Work with an absolute rotation from the ExtendedMove class?
|
||||
if (con && con->getControlSchemeAbsoluteRotation())
|
||||
{
|
||||
doStandardMove = false;
|
||||
const ExtendedMove* emove = dynamic_cast<const ExtendedMove*>(move);
|
||||
U32 emoveIndex = smExtendedMoveHeadPosRotIndex;
|
||||
if (emoveIndex >= ExtendedMove::MaxPositionsRotations)
|
||||
emoveIndex = 0;
|
||||
|
||||
if (emove->EulerBasedRotation[emoveIndex])
|
||||
{
|
||||
// Head pitch
|
||||
mHead.x += (emove->rotX[emoveIndex] - mLastAbsolutePitch);
|
||||
|
||||
// Do we also include the relative yaw value?
|
||||
if (con->getControlSchemeAddPitchToAbsRot())
|
||||
{
|
||||
F32 x = move->pitch;
|
||||
if (x > M_PI_F)
|
||||
x -= M_2PI_F;
|
||||
|
||||
mHead.x += x;
|
||||
}
|
||||
|
||||
// Constrain the range of mHead.x
|
||||
while (mHead.x < -M_PI_F)
|
||||
mHead.x += M_2PI_F;
|
||||
while (mHead.x > M_PI_F)
|
||||
mHead.x -= M_2PI_F;
|
||||
|
||||
// Rotate (heading) head or body?
|
||||
if (move->freeLook && ((isMounted() && getMountNode() == 0) || (con && !con->isFirstPerson())))
|
||||
{
|
||||
// Rotate head
|
||||
mHead.z += (emove->rotZ[emoveIndex] - mLastAbsoluteYaw);
|
||||
|
||||
// Do we also include the relative yaw value?
|
||||
if (con->getControlSchemeAddYawToAbsRot())
|
||||
{
|
||||
F32 z = move->yaw;
|
||||
if (z > M_PI_F)
|
||||
z -= M_2PI_F;
|
||||
|
||||
mHead.z += z;
|
||||
}
|
||||
|
||||
// Constrain the range of mHead.z
|
||||
while (mHead.z < 0.0f)
|
||||
mHead.z += M_2PI_F;
|
||||
while (mHead.z > M_2PI_F)
|
||||
mHead.z -= M_2PI_F;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rotate body
|
||||
mRot.z += (emove->rotZ[emoveIndex] - mLastAbsoluteYaw);
|
||||
|
||||
// Do we also include the relative yaw value?
|
||||
if (con->getControlSchemeAddYawToAbsRot())
|
||||
{
|
||||
F32 z = move->yaw;
|
||||
if (z > M_PI_F)
|
||||
z -= M_2PI_F;
|
||||
|
||||
mRot.z += z;
|
||||
}
|
||||
|
||||
// Constrain the range of mRot.z
|
||||
while (mRot.z < 0.0f)
|
||||
mRot.z += M_2PI_F;
|
||||
while (mRot.z > M_2PI_F)
|
||||
mRot.z -= M_2PI_F;
|
||||
}
|
||||
mLastAbsoluteYaw = emove->rotZ[emoveIndex];
|
||||
mLastAbsolutePitch = emove->rotX[emoveIndex];
|
||||
|
||||
// Head bank
|
||||
mHead.y = emove->rotY[emoveIndex];
|
||||
|
||||
// Constrain the range of mHead.y
|
||||
while (mHead.y > M_PI_F)
|
||||
mHead.y -= M_2PI_F;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
MatrixF zRot;
|
||||
zRot.set(EulerF(0.0f, 0.0f, mOwner->getRotation().asEulerF().z));
|
||||
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ void RigidBodyComponent::processTick()
|
|||
return;
|
||||
|
||||
// SINGLE PLAYER HACK!!!!
|
||||
if (PHYSICSMGR->isSinglePlayer() && isClientObject() && getServerObject())
|
||||
/*if (PHYSICSMGR->isSinglePlayer() && isClientObject() && getServerObject())
|
||||
{
|
||||
RigidBodyComponent *servObj = (RigidBodyComponent*)getServerObject();
|
||||
mOwner->setTransform(servObj->mState.getTransform());
|
||||
|
|
@ -296,7 +296,7 @@ void RigidBodyComponent::processTick()
|
|||
mRenderState[1] = servObj->mRenderState[1];
|
||||
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Store the last render state.
|
||||
mRenderState[0] = mRenderState[1];
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
#include "lighting/lightQuery.h"
|
||||
#include "scene/sceneManager.h"
|
||||
#include "gfx/bitmap/ddsFile.h"
|
||||
#include "gfx/bitmap/ddsUtils.h"
|
||||
#include "gfx/gfxTextureManager.h"
|
||||
#include "materials/materialFeatureTypes.h"
|
||||
#include "renderInstance/renderImposterMgr.h"
|
||||
|
|
@ -46,52 +45,49 @@
|
|||
#include "core/strings/findMatch.h"
|
||||
#include "T3D/components/render/meshComponent_ScriptBinding.h"
|
||||
|
||||
ImplementEnumType(BatchingMode,
|
||||
"Type of mesh data available in a shape.\n"
|
||||
"@ingroup gameObjects")
|
||||
{
|
||||
MeshComponent::Individual, "Individual", "This mesh is rendered indivudally, wthout batching or instancing."
|
||||
},
|
||||
{ MeshComponent::StaticBatch, "Static Batching", "Statically batches this mesh together with others to reduce drawcalls." },
|
||||
//{ MeshComponent::DynamicBatch, "Dynamic Batching", "Dynamical batches this mesh together with others to reduce drawcalls each frame." },
|
||||
// { MeshComponent::Instanced, "Instanced", "This mesh is rendered as an instance, reducing draw overhead with others that share the same mesh and material." },
|
||||
EndImplementEnumType;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Constructor/Destructor
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
MeshComponent::MeshComponent() : Component()
|
||||
{
|
||||
mShapeName = StringTable->insert("");
|
||||
mShapeAsset = StringTable->insert("");
|
||||
mShapeInstance = NULL;
|
||||
|
||||
mChangingMaterials.clear();
|
||||
|
||||
mMaterials.clear();
|
||||
|
||||
mFriendlyName = "Mesh Component";
|
||||
mComponentType = "Render";
|
||||
|
||||
mDescription = getDescriptionText("Causes the object to render a non-animating 3d shape using the file provided.");
|
||||
|
||||
mNetworked = true;
|
||||
mNetFlags.set(Ghostable | ScopeAlways);
|
||||
|
||||
mShapeName = StringTable->EmptyString();
|
||||
mShapeAsset = StringTable->EmptyString();
|
||||
|
||||
mMeshAsset = StringTable->EmptyString();
|
||||
mMeshAssetId = StringTable->EmptyString();
|
||||
|
||||
mInterfaceData = new MeshRenderSystemInterface();
|
||||
|
||||
mRenderMode = Individual;
|
||||
}
|
||||
|
||||
MeshComponent::~MeshComponent(){}
|
||||
MeshComponent::~MeshComponent()
|
||||
{
|
||||
if (mInterfaceData)
|
||||
SAFE_DELETE(mInterfaceData);
|
||||
}
|
||||
|
||||
IMPLEMENT_CO_NETOBJECT_V1(MeshComponent);
|
||||
|
||||
//==========================================================================================
|
||||
void MeshComponent::boneObject::addObject(SimObject* object)
|
||||
{
|
||||
SceneObject* sc = dynamic_cast<SceneObject*>(object);
|
||||
|
||||
if(sc && mOwner)
|
||||
{
|
||||
if(TSShape* shape = mOwner->getShape())
|
||||
{
|
||||
S32 nodeID = shape->findNode(mBoneName);
|
||||
|
||||
//we may have a offset on the shape's center
|
||||
//so make sure we accomodate for that when setting up the mount offsets
|
||||
MatrixF mat = mOwner->getNodeTransform(nodeID);
|
||||
|
||||
mOwner->getOwner()->mountObject(sc, nodeID, mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MeshComponent::onAdd()
|
||||
{
|
||||
if(! Parent::onAdd())
|
||||
|
|
@ -107,6 +103,12 @@ void MeshComponent::onComponentAdd()
|
|||
{
|
||||
Parent::onComponentAdd();
|
||||
|
||||
if (isClientObject())
|
||||
mInterfaceData->mIsClient = true;
|
||||
|
||||
// if (mInterfaceData != nullptr)
|
||||
// mInterfaceData->mIsClient = isClientObject();
|
||||
|
||||
//get the default shape, if any
|
||||
updateShape();
|
||||
}
|
||||
|
|
@ -114,10 +116,6 @@ void MeshComponent::onComponentAdd()
|
|||
void MeshComponent::onRemove()
|
||||
{
|
||||
Parent::onRemove();
|
||||
|
||||
mMeshAsset.clear();
|
||||
|
||||
SAFE_DELETE(mShapeInstance);
|
||||
}
|
||||
|
||||
void MeshComponent::onComponentRemove()
|
||||
|
|
@ -136,9 +134,14 @@ void MeshComponent::initPersistFields()
|
|||
{
|
||||
Parent::initPersistFields();
|
||||
|
||||
addGroup("Rendering");
|
||||
addField("BatchingMode", TypeBatchingMode, Offset(mRenderMode, MeshComponent),
|
||||
"The mode of batching this shape should be rendered with.");
|
||||
endGroup("Rendering");
|
||||
|
||||
//create a hook to our internal variables
|
||||
addGroup("Model");
|
||||
addProtectedField("MeshAsset", TypeAssetId, Offset(mShapeAsset, MeshComponent), &_setMesh, &defaultProtectedGetFn,
|
||||
addProtectedField("MeshAsset", TypeShapeAssetPtr, Offset(mShapeAsset, MeshComponent), &_setMesh, &defaultProtectedGetFn,
|
||||
"The asset Id used for the mesh.", AbstractClassRep::FieldFlags::FIELD_ComponentInspectors);
|
||||
endGroup("Model");
|
||||
}
|
||||
|
|
@ -166,6 +169,9 @@ bool MeshComponent::_setShape( void *object, const char *index, const char *data
|
|||
bool MeshComponent::setMeshAsset(const char* assetName)
|
||||
{
|
||||
// Fetch the asset Id.
|
||||
if (mInterfaceData == nullptr)
|
||||
return false;
|
||||
|
||||
mMeshAssetId = StringTable->insert(assetName);
|
||||
|
||||
mMeshAsset = mMeshAssetId;
|
||||
|
|
@ -184,9 +190,129 @@ bool MeshComponent::setMeshAsset(const char* assetName)
|
|||
return true;
|
||||
}
|
||||
|
||||
void MeshComponent::updateShape()
|
||||
{
|
||||
if (mInterfaceData == nullptr)
|
||||
return;
|
||||
|
||||
//if ((mShapeName && mShapeName[0] != '\0') || (mShapeAsset && mShapeAsset[0] != '\0'))
|
||||
if ((mShapeName && mShapeName[0] != '\0') || (mMeshAssetId && mMeshAssetId[0] != '\0'))
|
||||
|
||||
{
|
||||
if (mMeshAsset == NULL)
|
||||
return;
|
||||
|
||||
mShape = mMeshAsset->getShape();
|
||||
|
||||
if (!mMeshAsset->getShape())
|
||||
return;
|
||||
|
||||
setupShape();
|
||||
|
||||
//Do this on both the server and client
|
||||
S32 materialCount = mMeshAsset->getShape()->materialList->getMaterialNameList().size();
|
||||
|
||||
if (isServerObject())
|
||||
{
|
||||
//we need to update the editor
|
||||
for (U32 i = 0; i < mFields.size(); i++)
|
||||
{
|
||||
//find any with the materialslot title and clear them out
|
||||
if (FindMatch::isMatch("MaterialSlot*", mFields[i].mFieldName, false))
|
||||
{
|
||||
setDataField(mFields[i].mFieldName, NULL, "");
|
||||
mFields.erase(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//next, get a listing of our materials in the shape, and build our field list for them
|
||||
char matFieldName[128];
|
||||
|
||||
if (materialCount > 0)
|
||||
mComponentGroup = StringTable->insert("Materials");
|
||||
|
||||
for (U32 i = 0; i < materialCount; i++)
|
||||
{
|
||||
String materialname = mMeshAsset->getShape()->materialList->getMaterialName(i);
|
||||
if (materialname == String("ShapeBounds"))
|
||||
continue;
|
||||
|
||||
dSprintf(matFieldName, 128, "MaterialSlot%d", i);
|
||||
|
||||
addComponentField(matFieldName, "A material used in the shape file", "Material", materialname, "");
|
||||
}
|
||||
|
||||
if (materialCount > 0)
|
||||
mComponentGroup = "";
|
||||
}
|
||||
|
||||
if (mOwner != NULL)
|
||||
{
|
||||
Point3F min, max, pos;
|
||||
pos = mOwner->getPosition();
|
||||
|
||||
mOwner->getWorldToObj().mulP(pos);
|
||||
|
||||
min = mMeshAsset->getShape()->bounds.minExtents;
|
||||
max = mMeshAsset->getShape()->bounds.maxExtents;
|
||||
|
||||
if (mInterfaceData)
|
||||
{
|
||||
mInterfaceData->mBounds.set(min, max);
|
||||
mInterfaceData->mScale = mOwner->getScale();
|
||||
mInterfaceData->mTransform = mOwner->getRenderTransform();
|
||||
}
|
||||
|
||||
mOwner->setObjectBox(Box3F(min, max));
|
||||
|
||||
mOwner->resetWorldBox();
|
||||
|
||||
if (mOwner->getSceneManager() != NULL)
|
||||
mOwner->getSceneManager()->notifyObjectDirty(mOwner);
|
||||
}
|
||||
|
||||
if (isClientObject() && mInterfaceData)
|
||||
{
|
||||
if (mRenderMode == StaticBatch)
|
||||
{
|
||||
mInterfaceData->mStatic = true;
|
||||
|
||||
OptimizedPolyList geom;
|
||||
MatrixF transform = mInterfaceData->mTransform;
|
||||
mInterfaceData->mGeometry.setTransform(&transform, mInterfaceData->mScale);
|
||||
mInterfaceData->mGeometry.setObject(mOwner);
|
||||
|
||||
mInterfaceData->mShapeInstance->buildPolyList(&mInterfaceData->mGeometry, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
mInterfaceData->mStatic = false;
|
||||
}
|
||||
|
||||
MeshRenderSystem::rebuildBuffers();
|
||||
}
|
||||
|
||||
//finally, notify that our shape was changed
|
||||
onShapeInstanceChanged.trigger(this);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshComponent::setupShape()
|
||||
{
|
||||
mInterfaceData->mShapeInstance = new TSShapeInstance(mMeshAsset->getShape(), true);
|
||||
}
|
||||
|
||||
void MeshComponent::_onResourceChanged( const Torque::Path &path )
|
||||
{
|
||||
if ( path != Torque::Path( mShapeName ) )
|
||||
if (mInterfaceData == nullptr)
|
||||
return;
|
||||
|
||||
String filePath;
|
||||
if (mMeshAsset)
|
||||
filePath = Torque::Path(mMeshAsset->getShapeFilename());
|
||||
|
||||
if (!mMeshAsset || path != Torque::Path(mMeshAsset->getShapeFilename()) )
|
||||
return;
|
||||
|
||||
updateShape();
|
||||
|
|
@ -217,6 +343,8 @@ U32 MeshComponent::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
|||
if (stream->writeFlag(mask & ShapeMask))
|
||||
{
|
||||
stream->writeString(mShapeName);
|
||||
|
||||
stream->writeInt(mRenderMode, 8);
|
||||
}
|
||||
|
||||
if (stream->writeFlag( mask & MaterialMask ))
|
||||
|
|
@ -227,7 +355,7 @@ U32 MeshComponent::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
|||
{
|
||||
stream->writeInt(mChangingMaterials[i].slot, 16);
|
||||
|
||||
NetStringHandle matNameStr = mChangingMaterials[i].matName.c_str();
|
||||
NetStringHandle matNameStr = mChangingMaterials[i].assetId.c_str();
|
||||
con->packNetStringHandleU(stream, matNameStr);
|
||||
}
|
||||
|
||||
|
|
@ -244,6 +372,8 @@ void MeshComponent::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
if(stream->readFlag())
|
||||
{
|
||||
mShapeName = stream->readSTString();
|
||||
|
||||
mRenderMode = (RenderMode)stream->readInt(8);
|
||||
setMeshAsset(mShapeName);
|
||||
updateShape();
|
||||
}
|
||||
|
|
@ -257,7 +387,10 @@ void MeshComponent::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
{
|
||||
matMap newMatMap;
|
||||
newMatMap.slot = stream->readInt(16);
|
||||
newMatMap.matName = String(con->unpackNetStringHandleU(stream).getString());
|
||||
newMatMap.assetId = String(con->unpackNetStringHandleU(stream).getString());
|
||||
|
||||
//do the lookup, now
|
||||
newMatMap.matAsset = AssetDatabase.acquireAsset<MaterialAsset>(newMatMap.assetId);
|
||||
|
||||
mChangingMaterials.push_back(newMatMap);
|
||||
}
|
||||
|
|
@ -268,7 +401,7 @@ void MeshComponent::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
|
||||
void MeshComponent::prepRenderImage( SceneRenderState *state )
|
||||
{
|
||||
if (!mEnabled || !mOwner || !mShapeInstance)
|
||||
/*if (!mEnabled || !mOwner || !mShapeInstance)
|
||||
return;
|
||||
|
||||
Point3F cameraOffset;
|
||||
|
|
@ -301,114 +434,41 @@ void MeshComponent::prepRenderImage( SceneRenderState *state )
|
|||
rdata.setLightQuery(&query);
|
||||
|
||||
MatrixF mat = mOwner->getRenderTransform();
|
||||
Point3F renderPos = mat.getPosition();
|
||||
EulerF renderRot = mat.toEuler();
|
||||
|
||||
if (mOwner->isMounted())
|
||||
{
|
||||
MatrixF wrldPos = mOwner->getWorldTransform();
|
||||
Point3F wrldPosPos = wrldPos.getPosition();
|
||||
|
||||
Point3F mntPs = mat.getPosition();
|
||||
EulerF mntRt = RotationF(mat).asEulerF();
|
||||
|
||||
bool tr = true;
|
||||
}
|
||||
|
||||
mat.scale(objScale);
|
||||
GFX->setWorldMatrix(mat);
|
||||
|
||||
mShapeInstance->render(rdata);
|
||||
}
|
||||
|
||||
void MeshComponent::updateShape()
|
||||
{
|
||||
bool isServer = isServerObject();
|
||||
|
||||
if ((mShapeName && mShapeName[0] != '\0') || (mShapeAsset && mShapeAsset[0] != '\0'))
|
||||
{
|
||||
if (mMeshAsset == NULL)
|
||||
return;
|
||||
|
||||
mShape = mMeshAsset->getShape();
|
||||
|
||||
if (!mShape)
|
||||
return;
|
||||
|
||||
setupShape();
|
||||
|
||||
//Do this on both the server and client
|
||||
S32 materialCount = mShape->materialList->getMaterialNameList().size();
|
||||
|
||||
if(isServerObject())
|
||||
{
|
||||
//we need to update the editor
|
||||
for (U32 i = 0; i < mFields.size(); i++)
|
||||
{
|
||||
//find any with the materialslot title and clear them out
|
||||
if (FindMatch::isMatch("MaterialSlot*", mFields[i].mFieldName, false))
|
||||
{
|
||||
setDataField(mFields[i].mFieldName, NULL, "");
|
||||
mFields.erase(i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//next, get a listing of our materials in the shape, and build our field list for them
|
||||
char matFieldName[128];
|
||||
|
||||
if(materialCount > 0)
|
||||
mComponentGroup = StringTable->insert("Materials");
|
||||
|
||||
for(U32 i=0; i < materialCount; i++)
|
||||
{
|
||||
String materialname = mShape->materialList->getMaterialName(i);
|
||||
if(materialname == String("ShapeBounds"))
|
||||
continue;
|
||||
|
||||
dSprintf(matFieldName, 128, "MaterialSlot%d", i);
|
||||
|
||||
addComponentField(matFieldName, "A material used in the shape file", "TypeAssetId", materialname, "");
|
||||
}
|
||||
|
||||
if(materialCount > 0)
|
||||
mComponentGroup = "";
|
||||
}
|
||||
|
||||
if(mOwner != NULL)
|
||||
{
|
||||
Point3F min, max, pos;
|
||||
pos = mOwner->getPosition();
|
||||
|
||||
mOwner->getWorldToObj().mulP(pos);
|
||||
|
||||
min = mShape->bounds.minExtents;
|
||||
max = mShape->bounds.maxExtents;
|
||||
|
||||
mShapeBounds.set(min, max);
|
||||
|
||||
mOwner->setObjectBox(Box3F(min, max));
|
||||
|
||||
if( mOwner->getSceneManager() != NULL )
|
||||
mOwner->getSceneManager()->notifyObjectDirty( mOwner );
|
||||
}
|
||||
|
||||
//finally, notify that our shape was changed
|
||||
onShapeInstanceChanged.trigger(this);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshComponent::setupShape()
|
||||
{
|
||||
mShapeInstance = new TSShapeInstance(mShape, true);
|
||||
mShapeInstance->render(rdata);*/
|
||||
}
|
||||
|
||||
void MeshComponent::updateMaterials()
|
||||
{
|
||||
if (mChangingMaterials.empty() || !mShape)
|
||||
if (mChangingMaterials.empty() || !mMeshAsset->getShape())
|
||||
return;
|
||||
|
||||
TSMaterialList* pMatList = mShapeInstance->getMaterialList();
|
||||
TSMaterialList* pMatList = mInterfaceData->mShapeInstance->getMaterialList();
|
||||
pMatList->setTextureLookupPath(getShapeResource().getPath().getPath());
|
||||
|
||||
const Vector<String> &materialNames = pMatList->getMaterialNameList();
|
||||
for ( S32 i = 0; i < materialNames.size(); i++ )
|
||||
{
|
||||
const String &pName = materialNames[i];
|
||||
|
||||
for(U32 m=0; m < mChangingMaterials.size(); m++)
|
||||
{
|
||||
if(mChangingMaterials[m].slot == i)
|
||||
{
|
||||
pMatList->renameMaterial( i, mChangingMaterials[m].matName );
|
||||
//Fetch the actual material asset
|
||||
pMatList->renameMaterial( i, mChangingMaterials[m].matAsset->getMaterialDefinitionName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -416,22 +476,31 @@ void MeshComponent::updateMaterials()
|
|||
}
|
||||
|
||||
// Initialize the material instances
|
||||
mShapeInstance->initMaterialList();
|
||||
mInterfaceData->mShapeInstance->initMaterialList();
|
||||
}
|
||||
|
||||
MatrixF MeshComponent::getNodeTransform(S32 nodeIdx)
|
||||
{
|
||||
if (mShape)
|
||||
if (mInterfaceData != nullptr && mMeshAsset->getShape())
|
||||
{
|
||||
S32 nodeCount = getShape()->nodes.size();
|
||||
|
||||
if(nodeIdx >= 0 && nodeIdx < nodeCount)
|
||||
{
|
||||
//animate();
|
||||
MatrixF mountTransform = mShapeInstance->mNodeTransforms[nodeIdx];
|
||||
mountTransform.mul(mOwner->getRenderTransform());
|
||||
MatrixF nodeTransform = mInterfaceData->mShapeInstance->mNodeTransforms[nodeIdx];
|
||||
const Point3F& scale = mOwner->getScale();
|
||||
|
||||
return mountTransform;
|
||||
// The position of the node needs to be scaled.
|
||||
Point3F position = nodeTransform.getPosition();
|
||||
position.convolve(scale);
|
||||
nodeTransform.setPosition(position);
|
||||
|
||||
MatrixF finalTransform = MatrixF::Identity;
|
||||
|
||||
finalTransform.mul(mOwner->getRenderTransform(), nodeTransform);
|
||||
|
||||
return finalTransform;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -440,7 +509,7 @@ MatrixF MeshComponent::getNodeTransform(S32 nodeIdx)
|
|||
|
||||
S32 MeshComponent::getNodeByName(String nodeName)
|
||||
{
|
||||
if (mShape)
|
||||
if (mMeshAsset->getShape())
|
||||
{
|
||||
S32 nodeIdx = getShape()->findNode(nodeName);
|
||||
|
||||
|
|
@ -486,12 +555,18 @@ void MeshComponent::onDynamicModified(const char* slotName, const char* newValue
|
|||
if(slot == -1)
|
||||
return;
|
||||
|
||||
//Safe to assume the inbound value for the material will be a MaterialAsset, so lets do a lookup on the name
|
||||
MaterialAsset* matAsset = AssetDatabase.acquireAsset<MaterialAsset>(newValue);
|
||||
if (!matAsset)
|
||||
return;
|
||||
|
||||
bool found = false;
|
||||
for(U32 i=0; i < mChangingMaterials.size(); i++)
|
||||
{
|
||||
if(mChangingMaterials[i].slot == slot)
|
||||
{
|
||||
mChangingMaterials[i].matName = String(newValue);
|
||||
mChangingMaterials[i].matAsset = matAsset;
|
||||
mChangingMaterials[i].assetId = newValue;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -500,7 +575,8 @@ void MeshComponent::onDynamicModified(const char* slotName, const char* newValue
|
|||
{
|
||||
matMap newMatMap;
|
||||
newMatMap.slot = slot;
|
||||
newMatMap.matName = String(newValue);
|
||||
newMatMap.matAsset = matAsset;
|
||||
newMatMap.assetId = newValue;
|
||||
|
||||
mChangingMaterials.push_back(newMatMap);
|
||||
}
|
||||
|
|
@ -511,14 +587,31 @@ void MeshComponent::onDynamicModified(const char* slotName, const char* newValue
|
|||
Parent::onDynamicModified(slotName, newValue);
|
||||
}
|
||||
|
||||
void MeshComponent::changeMaterial(U32 slot, const char* newMat)
|
||||
void MeshComponent::changeMaterial(U32 slot, MaterialAsset* newMat)
|
||||
{
|
||||
|
||||
char fieldName[512];
|
||||
|
||||
//update our respective field
|
||||
dSprintf(fieldName, 512, "materialSlot%d", slot);
|
||||
setDataField(fieldName, NULL, newMat);
|
||||
setDataField(fieldName, NULL, newMat->getAssetId());
|
||||
}
|
||||
|
||||
bool MeshComponent::setMatInstField(U32 slot, const char* field, const char* value)
|
||||
{
|
||||
TSMaterialList* pMatList = mInterfaceData->mShapeInstance->getMaterialList();
|
||||
pMatList->setTextureLookupPath(getShapeResource().getPath().getPath());
|
||||
|
||||
MaterialParameters* params = pMatList->getMaterialInst(slot)->getMaterialParameters();
|
||||
|
||||
if (pMatList->getMaterialInst(slot)->getFeatures().hasFeature(MFT_DiffuseColor))
|
||||
{
|
||||
MaterialParameterHandle* handle = pMatList->getMaterialInst(slot)->getMaterialParameterHandle("DiffuseColor");
|
||||
|
||||
params->set(handle, LinearColorF(0, 0, 0));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MeshComponent::onInspect()
|
||||
|
|
@ -527,4 +620,13 @@ void MeshComponent::onInspect()
|
|||
|
||||
void MeshComponent::onEndInspect()
|
||||
{
|
||||
}
|
||||
|
||||
void MeshComponent::ownerTransformSet(MatrixF *mat)
|
||||
{
|
||||
if (mInterfaceData != nullptr)
|
||||
{
|
||||
MatrixF newTransform = *mat;
|
||||
mInterfaceData->mTransform = newTransform;
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +60,8 @@
|
|||
#include "gfx/gfxVertexFormat.h"
|
||||
#endif
|
||||
|
||||
#include "T3D/systems/render/meshRenderSystem.h"
|
||||
|
||||
class TSShapeInstance;
|
||||
class SceneRenderState;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -84,37 +86,38 @@ protected:
|
|||
StringTableEntry mShapeName;
|
||||
StringTableEntry mShapeAsset;
|
||||
TSShape* mShape;
|
||||
Box3F mShapeBounds;
|
||||
//Box3F mShapeBounds;
|
||||
Point3F mCenterOffset;
|
||||
|
||||
MeshRenderSystemInterface* mInterfaceData;
|
||||
|
||||
struct matMap
|
||||
{
|
||||
String matName;
|
||||
MaterialAsset* matAsset;
|
||||
String assetId;
|
||||
U32 slot;
|
||||
};
|
||||
|
||||
Vector<matMap> mChangingMaterials;
|
||||
Vector<matMap> mMaterials;
|
||||
|
||||
class boneObject : public SimGroup
|
||||
public:
|
||||
enum RenderMode
|
||||
{
|
||||
MeshComponent *mOwner;
|
||||
public:
|
||||
boneObject(MeshComponent *owner){ mOwner = owner; }
|
||||
|
||||
StringTableEntry mBoneName;
|
||||
S32 mItemID;
|
||||
|
||||
virtual void addObject(SimObject *obj);
|
||||
Individual = 0,
|
||||
DynamicBatch,
|
||||
StaticBatch,
|
||||
Instanced
|
||||
};
|
||||
|
||||
Vector<boneObject*> mNodesList;
|
||||
protected:
|
||||
RenderMode mRenderMode;
|
||||
|
||||
public:
|
||||
StringTableEntry mMeshAssetId;
|
||||
AssetPtr<ShapeAsset> mMeshAsset;
|
||||
|
||||
TSShapeInstance* mShapeInstance;
|
||||
//TSShapeInstance* mShapeInstance;
|
||||
|
||||
public:
|
||||
MeshComponent();
|
||||
|
|
@ -132,7 +135,7 @@ public:
|
|||
virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
|
||||
virtual void unpackUpdate(NetConnection *con, BitStream *stream);
|
||||
|
||||
Box3F getShapeBounds() { return mShapeBounds; }
|
||||
Box3F getShapeBounds() { return mInterfaceData->mBounds; }
|
||||
|
||||
virtual MatrixF getNodeTransform(S32 nodeIdx);
|
||||
S32 getNodeByName(String nodeName);
|
||||
|
|
@ -144,6 +147,8 @@ public:
|
|||
virtual void onComponentRemove();
|
||||
virtual void onComponentAdd();
|
||||
|
||||
virtual void ownerTransformSet(MatrixF *mat);
|
||||
|
||||
static bool _setMesh(void *object, const char *index, const char *data);
|
||||
static bool _setShape(void *object, const char *index, const char *data);
|
||||
const char* _getShape(void *object, const char *data);
|
||||
|
|
@ -151,7 +156,7 @@ public:
|
|||
bool setMeshAsset(const char* assetName);
|
||||
|
||||
virtual TSShape* getShape() { if (mMeshAsset) return mMeshAsset->getShape(); else return NULL; }
|
||||
virtual TSShapeInstance* getShapeInstance() { return mShapeInstance; }
|
||||
virtual TSShapeInstance* getShapeInstance() { return mInterfaceData->mShapeInstance; }
|
||||
|
||||
Resource<TSShape> getShapeResource() { return mMeshAsset->getShapeResource(); }
|
||||
|
||||
|
|
@ -163,7 +168,8 @@ public:
|
|||
|
||||
virtual void onDynamicModified(const char* slotName, const char* newValue);
|
||||
|
||||
void changeMaterial(U32 slot, const char* newMat);
|
||||
void changeMaterial(U32 slot, MaterialAsset* newMat);
|
||||
bool setMatInstField(U32 slot, const char* field, const char* value);
|
||||
|
||||
virtual void onInspect();
|
||||
virtual void onEndInspect();
|
||||
|
|
@ -180,4 +186,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
typedef MeshComponent::RenderMode BatchingMode;
|
||||
DefineEnumType(BatchingMode);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -126,6 +126,28 @@ DefineEngineMethod(MeshComponent, getNodePosition, Point3F,
|
|||
return Point3F(0, 0, 0);
|
||||
}
|
||||
|
||||
DefineEngineMethod(MeshComponent, getNodeRotation, EulerF,
|
||||
(S32 node), (-1),
|
||||
"@brief Mount objB to this object at the desired slot with optional transform.\n\n"
|
||||
|
||||
"@param objB Object to mount onto us\n"
|
||||
"@param slot Mount slot ID\n"
|
||||
"@param txfm (optional) mount offset transform\n"
|
||||
"@return true if successful, false if failed (objB is not valid)")
|
||||
{
|
||||
if (node != -1)
|
||||
{
|
||||
//BUG: Unsure how it broke, but atm the default transform passed in here is rotated 180 degrees. This doesn't happen
|
||||
//for the SceneObject mountobject method. Hackish, but for now, just default to a clean MatrixF::Identity
|
||||
//object->mountObjectToNode( objB, node, /*MatrixF::Identity*/txfm.getMatrix() );
|
||||
RotationF mat = object->getNodeTransform(node);
|
||||
|
||||
return mat.asEulerF(RotationF::Degrees);
|
||||
}
|
||||
|
||||
return EulerF(0, 0, 0);
|
||||
}
|
||||
|
||||
DefineEngineMethod(MeshComponent, getNodeByName, S32,
|
||||
(String nodeName), ,
|
||||
"@brief Mount objB to this object at the desired slot with optional transform.\n\n"
|
||||
|
|
@ -148,8 +170,14 @@ DefineEngineMethod(MeshComponent, getNodeByName, S32,
|
|||
return -1;
|
||||
}
|
||||
|
||||
DefineEngineMethod(MeshComponent, changeMaterial, void, (U32 slot, const char* newMat), (0, ""),
|
||||
DefineEngineMethod(MeshComponent, changeMaterial, void, (U32 slot, MaterialAsset* newMat), (0, nullAsType<MaterialAsset*>()),
|
||||
"@brief Change one of the materials on the shape.\n\n")
|
||||
{
|
||||
object->changeMaterial(slot, newMat);
|
||||
}
|
||||
|
||||
DefineEngineMethod(MeshComponent, setMatInstField, bool, (U32 slot, const char* field, const char* value), (0, "", ""),
|
||||
"@brief Change one of the materials on the shape.\n\n")
|
||||
{
|
||||
return object->setMatInstField(slot, field, value);
|
||||
}
|
||||
|
|
@ -47,10 +47,13 @@
|
|||
#include "T3D/gameBase/std/stdMoveList.h"
|
||||
|
||||
#include "T3D/prefab.h"
|
||||
#include "T3D/gameBase/gameConnection.h"
|
||||
|
||||
#include <thread>
|
||||
//
|
||||
#include "gfx/sim/debugDraw.h"
|
||||
//
|
||||
#include "T3D/sfx/sfx3DWorld.h"
|
||||
|
||||
extern bool gEditingMission;
|
||||
|
||||
|
|
@ -117,6 +120,10 @@ Entity::Entity()
|
|||
|
||||
mInitialized = false;
|
||||
|
||||
mLifetimeMS = 0;
|
||||
|
||||
mGameObjectAssetId = StringTable->insert("");
|
||||
|
||||
}
|
||||
|
||||
Entity::~Entity()
|
||||
|
|
@ -143,6 +150,15 @@ void Entity::initPersistFields()
|
|||
addField("LocalRotation", TypeMatrixRotation, Offset(mMount.xfm, Entity), "Rotation we are mounted at ( object space of our mount object ).");
|
||||
|
||||
endGroup("Transform");
|
||||
|
||||
addGroup("Misc");
|
||||
addField("LifetimeMS", TypeS32, Offset(mLifetimeMS, Entity), "Object world orientation.");
|
||||
endGroup("Misc");
|
||||
|
||||
addGroup("GameObject");
|
||||
addProtectedField("gameObjectName", TypeGameObjectAssetPtr, Offset(mGameObjectAsset, Entity), &_setGameObject, &defaultProtectedGetFn,
|
||||
"The asset Id used for the game object this entity is based on.");
|
||||
endGroup("GameObject");
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -215,15 +231,27 @@ bool Entity::onAdd()
|
|||
if (!Parent::onAdd())
|
||||
return false;
|
||||
|
||||
mObjBox = Box3F(Point3F(-1, -1, -1), Point3F(1, 1, 1));
|
||||
|
||||
mObjBox = Box3F(Point3F(-0.5, -0.5, -0.5), Point3F(0.5, 0.5, 0.5));
|
||||
|
||||
resetWorldBox();
|
||||
setObjectBox(mObjBox);
|
||||
|
||||
addToScene();
|
||||
|
||||
//Make sure we get positioned
|
||||
setMaskBits(TransformMask);
|
||||
if (isServerObject())
|
||||
{
|
||||
setMaskBits(TransformMask);
|
||||
setMaskBits(NamespaceMask);
|
||||
}
|
||||
else
|
||||
{
|
||||
//We can shortcut the initialization here because stuff generally ghosts down in order, and onPostAdd isn't called on ghosts.
|
||||
onPostAdd();
|
||||
}
|
||||
|
||||
if (mLifetimeMS != 0)
|
||||
mStartTimeMS = Platform::getRealMilliseconds();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -236,6 +264,8 @@ void Entity::onRemove()
|
|||
|
||||
onDataSet.removeAll();
|
||||
|
||||
mGameObjectAsset.clear();
|
||||
|
||||
Parent::onRemove();
|
||||
}
|
||||
|
||||
|
|
@ -249,10 +279,41 @@ void Entity::onPostAdd()
|
|||
mComponents[i]->onComponentAdd();
|
||||
}
|
||||
|
||||
//Set up the networked components
|
||||
mNetworkedComponents.clear();
|
||||
for (U32 i = 0; i < mComponents.size(); i++)
|
||||
{
|
||||
if (mComponents[i]->isNetworked())
|
||||
{
|
||||
NetworkedComponent netComp;
|
||||
netComp.componentIndex = i;
|
||||
netComp.updateState = NetworkedComponent::Adding;
|
||||
netComp.updateMaskBits = -1;
|
||||
|
||||
mNetworkedComponents.push_back(netComp);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mNetworkedComponents.empty())
|
||||
{
|
||||
setMaskBits(AddComponentsMask);
|
||||
setMaskBits(ComponentsUpdateMask);
|
||||
}
|
||||
|
||||
if (isMethod("onAdd"))
|
||||
Con::executef(this, "onAdd");
|
||||
}
|
||||
|
||||
bool Entity::_setGameObject(void *object, const char *index, const char *data)
|
||||
{
|
||||
Entity *e = static_cast<Entity*>(object);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(data != NULL, "Cannot use a NULL asset Id.");
|
||||
|
||||
return true; //rbI->setMeshAsset(data);
|
||||
}
|
||||
|
||||
void Entity::setDataField(StringTableEntry slotName, const char *array, const char *value)
|
||||
{
|
||||
Parent::setDataField(slotName, array, value);
|
||||
|
|
@ -363,8 +424,28 @@ void Entity::processTick(const Move* move)
|
|||
}
|
||||
}
|
||||
|
||||
if (isMethod("processTick"))
|
||||
// Save current rigid state interpolation
|
||||
mDelta.posVec = getPosition();
|
||||
mDelta.rot[0] = mRot.asQuatF();
|
||||
|
||||
//Handle any script updates, which can include physics stuff
|
||||
if (isServerObject() && isMethod("processTick"))
|
||||
Con::executef(this, "processTick");
|
||||
|
||||
// Wrap up interpolation info
|
||||
mDelta.pos = getPosition();
|
||||
mDelta.posVec -= getPosition();
|
||||
mDelta.rot[1] = mRot.asQuatF();
|
||||
|
||||
setTransform(getPosition(), mRot);
|
||||
|
||||
//Lifetime test
|
||||
if (mLifetimeMS != 0)
|
||||
{
|
||||
S32 currentTime = Platform::getRealMilliseconds();
|
||||
if (currentTime - mStartTimeMS >= mLifetimeMS)
|
||||
deleteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -402,11 +483,6 @@ U32 Entity::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
|||
|
||||
if (stream->writeFlag(mask & TransformMask))
|
||||
{
|
||||
//mathWrite( *stream, getScale() );
|
||||
//stream->writeAffineTransform(mObjToWorld);
|
||||
//mathWrite(*stream, getPosition());
|
||||
//mathWrite(*stream, mPos);
|
||||
|
||||
stream->writeCompressedPoint(mPos);
|
||||
mathWrite(*stream, getRotation());
|
||||
|
||||
|
|
@ -415,73 +491,125 @@ U32 Entity::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
|
|||
stream->writeFlag(!(mask & NoWarpMask));
|
||||
}
|
||||
|
||||
/*if (stream->writeFlag(mask & MountedMask))
|
||||
{
|
||||
mathWrite(*stream, mMount.xfm.getPosition());
|
||||
mathWrite(*stream, mMount.xfm.toEuler());
|
||||
}*/
|
||||
|
||||
if (stream->writeFlag(mask & BoundsMask))
|
||||
{
|
||||
mathWrite(*stream, mObjBox);
|
||||
}
|
||||
|
||||
//pass our behaviors around
|
||||
if (mask & ComponentsMask || mask & InitialUpdateMask)
|
||||
if (stream->writeFlag(mask & AddComponentsMask))
|
||||
{
|
||||
stream->writeFlag(true);
|
||||
//now, we run through a list of our to-be-sent behaviors and begin sending them
|
||||
//if any fail, we keep our list and re-queue the mask
|
||||
S32 componentCount = mToLoadComponents.size();
|
||||
U32 toAddComponentCount = 0;
|
||||
|
||||
//build our 'ready' list
|
||||
//This requires both the instance and the instances' template to be prepped(if the template hasn't been ghosted,
|
||||
//then we know we shouldn't be passing the instance's ghosts around yet)
|
||||
U32 ghostedCompCnt = 0;
|
||||
for (U32 i = 0; i < componentCount; i++)
|
||||
for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
if (con->getGhostIndex(mToLoadComponents[i]) != -1)
|
||||
ghostedCompCnt++;
|
||||
}
|
||||
|
||||
if (ghostedCompCnt != 0)
|
||||
{
|
||||
stream->writeFlag(true);
|
||||
|
||||
stream->writeFlag(mStartComponentUpdate);
|
||||
|
||||
//if not all the behaviors have been ghosted, we'll need another pass
|
||||
if (ghostedCompCnt != componentCount)
|
||||
retMask |= ComponentsMask;
|
||||
|
||||
//write the currently ghosted behavior count
|
||||
stream->writeInt(ghostedCompCnt, 16);
|
||||
|
||||
for (U32 i = 0; i < mToLoadComponents.size(); i++)
|
||||
if (mNetworkedComponents[i].updateState == NetworkedComponent::Adding)
|
||||
{
|
||||
//now fetch them and pass the ghost
|
||||
S32 ghostIndex = con->getGhostIndex(mToLoadComponents[i]);
|
||||
if (ghostIndex != -1)
|
||||
{
|
||||
stream->writeInt(ghostIndex, NetConnection::GhostIdBitSize);
|
||||
mToLoadComponents.erase(i);
|
||||
i--;
|
||||
|
||||
mStartComponentUpdate = false;
|
||||
}
|
||||
toAddComponentCount++;
|
||||
}
|
||||
}
|
||||
else if (componentCount)
|
||||
|
||||
//you reaaaaally shouldn't have >255 networked components on a single entity
|
||||
stream->writeInt(toAddComponentCount, 8);
|
||||
|
||||
for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
//on the odd chance we have behaviors to ghost, but NONE of them have been yet, just set the flag now
|
||||
stream->writeFlag(false);
|
||||
retMask |= ComponentsMask;
|
||||
NetworkedComponent::UpdateState state = mNetworkedComponents[i].updateState;
|
||||
|
||||
if (mNetworkedComponents[i].updateState == NetworkedComponent::Adding)
|
||||
{
|
||||
const char* className = mComponents[mNetworkedComponents[i].componentIndex]->getClassName();
|
||||
stream->writeString(className, strlen(className));
|
||||
|
||||
mNetworkedComponents[i].updateState = NetworkedComponent::Updating;
|
||||
}
|
||||
}
|
||||
else
|
||||
stream->writeFlag(false);
|
||||
}
|
||||
else
|
||||
stream->writeFlag(false);
|
||||
|
||||
if (stream->writeFlag(mask & RemoveComponentsMask))
|
||||
{
|
||||
/*U32 toRemoveComponentCount = 0;
|
||||
|
||||
for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
if (mNetworkedComponents[i].updateState == NetworkedComponent::Adding)
|
||||
{
|
||||
toRemoveComponentCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//you reaaaaally shouldn't have >255 networked components on a single entity
|
||||
stream->writeInt(toRemoveComponentCount, 8);
|
||||
|
||||
for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
if (mNetworkedComponents[i].updateState == NetworkedComponent::Removing)
|
||||
{
|
||||
stream->writeInt(i, 16);
|
||||
}
|
||||
}*/
|
||||
|
||||
/*for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
if (mNetworkedComponents[i].updateState == NetworkedComponent::UpdateState::Removing)
|
||||
{
|
||||
removeComponent(mComponents[mNetworkedComponents[i].componentIndex], true);
|
||||
mNetworkedComponents.erase(i);
|
||||
i--;
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//Update our components
|
||||
if (stream->writeFlag(mask & ComponentsUpdateMask))
|
||||
{
|
||||
U32 toUpdateComponentCount = 0;
|
||||
|
||||
for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
if (mNetworkedComponents[i].updateState == NetworkedComponent::Updating)
|
||||
{
|
||||
toUpdateComponentCount++;
|
||||
}
|
||||
}
|
||||
|
||||
//you reaaaaally shouldn't have >255 networked components on a single entity
|
||||
stream->writeInt(toUpdateComponentCount, 8);
|
||||
|
||||
bool forceUpdate = false;
|
||||
|
||||
for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
if (mNetworkedComponents[i].updateState == NetworkedComponent::Updating)
|
||||
{
|
||||
stream->writeInt(i, 8);
|
||||
|
||||
mNetworkedComponents[i].updateMaskBits = mComponents[mNetworkedComponents[i].componentIndex]->packUpdate(con, mNetworkedComponents[i].updateMaskBits, stream);
|
||||
|
||||
if (mNetworkedComponents[i].updateMaskBits != 0)
|
||||
forceUpdate = true;
|
||||
else
|
||||
mNetworkedComponents[i].updateState = NetworkedComponent::None;
|
||||
}
|
||||
}
|
||||
|
||||
//If we have leftover, we need to re-iterate our packing
|
||||
if (forceUpdate)
|
||||
setMaskBits(ComponentsUpdateMask);
|
||||
}
|
||||
|
||||
/*if (stream->writeFlag(mask & NamespaceMask))
|
||||
{
|
||||
const char* name = getName();
|
||||
if (stream->writeFlag(name && name[0]))
|
||||
stream->writeString(String(name));
|
||||
|
||||
if (stream->writeFlag(mSuperClassName && mSuperClassName[0]))
|
||||
stream->writeString(String(mSuperClassName));
|
||||
|
||||
if (stream->writeFlag(mClassName && mClassName[0]))
|
||||
stream->writeString(String(mClassName));
|
||||
}*/
|
||||
|
||||
return retMask;
|
||||
}
|
||||
|
|
@ -492,20 +620,10 @@ void Entity::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
|
||||
if (stream->readFlag())
|
||||
{
|
||||
/*Point3F scale;
|
||||
mathRead( *stream, &scale );
|
||||
setScale( scale);*/
|
||||
|
||||
//MatrixF objToWorld;
|
||||
//stream->readAffineTransform(&objToWorld);
|
||||
|
||||
Point3F pos;
|
||||
|
||||
stream->readCompressedPoint(&pos);
|
||||
//mathRead(*stream, &pos);
|
||||
|
||||
RotationF rot;
|
||||
|
||||
mathRead(*stream, &rot);
|
||||
|
||||
mDelta.move.unpack(stream);
|
||||
|
|
@ -514,72 +632,6 @@ void Entity::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
{
|
||||
// Determine number of ticks to warp based on the average
|
||||
// of the client and server velocities.
|
||||
/*mDelta.warpOffset = pos - mDelta.pos;
|
||||
|
||||
F32 dt = mDelta.warpOffset.len() / (0.5f * TickSec);
|
||||
|
||||
mDelta.warpTicks = (S32)((dt > sMinWarpTicks) ? getMax(mFloor(dt + 0.5f), 1.0f) : 0.0f);
|
||||
|
||||
//F32 as = (speed + mVelocity.len()) * 0.5f * TickSec;
|
||||
//F32 dt = (as > 0.00001f) ? mDelta.warpOffset.len() / as : sMaxWarpTicks;
|
||||
//mDelta.warpTicks = (S32)((dt > sMinWarpTicks) ? getMax(mFloor(dt + 0.5f), 1.0f) : 0.0f);
|
||||
|
||||
//mDelta.warpTicks = (S32)((dt > sMinWarpTicks) ? getMax(mFloor(dt + 0.5f), 1.0f) : 0.0f);
|
||||
|
||||
//mDelta.warpTicks = sMaxWarpTicks;
|
||||
|
||||
mDelta.warpTicks = 0;
|
||||
|
||||
if (mDelta.warpTicks)
|
||||
{
|
||||
// Setup the warp to start on the next tick.
|
||||
if (mDelta.warpTicks > sMaxWarpTicks)
|
||||
mDelta.warpTicks = sMaxWarpTicks;
|
||||
mDelta.warpOffset /= (F32)mDelta.warpTicks;
|
||||
|
||||
mDelta.rot[0] = rot.asQuatF();
|
||||
mDelta.rot[1] = rot.asQuatF();
|
||||
|
||||
mDelta.rotOffset = rot.asEulerF() - mDelta.rot.asEulerF();
|
||||
|
||||
// Ignore small rotation differences
|
||||
if (mFabs(mDelta.rotOffset.x) < 0.001f)
|
||||
mDelta.rotOffset.x = 0;
|
||||
|
||||
if (mFabs(mDelta.rotOffset.y) < 0.001f)
|
||||
mDelta.rotOffset.y = 0;
|
||||
|
||||
if (mFabs(mDelta.rotOffset.z) < 0.001f)
|
||||
mDelta.rotOffset.z = 0;
|
||||
|
||||
mDelta.rotOffset /= (F32)mDelta.warpTicks;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Going to skip the warp, server and client are real close.
|
||||
// Adjust the frame interpolation to move smoothly to the
|
||||
// new position within the current tick.
|
||||
Point3F cp = mDelta.pos + mDelta.posVec * mDelta.dt;
|
||||
if (mDelta.dt == 0)
|
||||
{
|
||||
mDelta.posVec.set(0.0f, 0.0f, 0.0f);
|
||||
mDelta.rotVec.set(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
F32 dti = 1.0f / mDelta.dt;
|
||||
mDelta.posVec = (cp - pos) * dti;
|
||||
mDelta.rotVec.z = mRot.z - rot.z;
|
||||
|
||||
mDelta.rotVec.z *= dti;
|
||||
}
|
||||
|
||||
mDelta.pos = pos;
|
||||
mDelta.rot = rot;
|
||||
|
||||
setTransform(pos, rot);
|
||||
}*/
|
||||
|
||||
Point3F cp = mDelta.pos + mDelta.posVec * mDelta.dt;
|
||||
mDelta.warpOffset = pos - cp;
|
||||
|
||||
|
|
@ -631,42 +683,101 @@ void Entity::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
}
|
||||
}
|
||||
|
||||
/*if (stream->readFlag())
|
||||
{
|
||||
Point3F mountOffset;
|
||||
EulerF mountRot;
|
||||
mathRead(*stream, &mountOffset);
|
||||
mathRead(*stream, &mountRot);
|
||||
|
||||
RotationF rot = RotationF(mountRot);
|
||||
mountRot = rot.asEulerF(RotationF::Degrees);
|
||||
|
||||
setMountOffset(mountOffset);
|
||||
setMountRotation(mountRot);
|
||||
}*/
|
||||
|
||||
if (stream->readFlag())
|
||||
{
|
||||
mathRead(*stream, &mObjBox);
|
||||
resetWorldBox();
|
||||
}
|
||||
|
||||
//AddComponentMask
|
||||
if (stream->readFlag())
|
||||
{
|
||||
//are we passing any behaviors currently?
|
||||
U32 addedComponentCount = stream->readInt(8);
|
||||
|
||||
for (U32 i = 0; i < addedComponentCount; i++)
|
||||
{
|
||||
char className[256] = "";
|
||||
stream->readString(className);
|
||||
|
||||
//Change to components, so iterate our list and create any new components
|
||||
// Well, looks like we have to create a new object.
|
||||
const char* componentType = className;
|
||||
|
||||
ConsoleObject *object = ConsoleObject::create(componentType);
|
||||
|
||||
// Finally, set currentNewObject to point to the new one.
|
||||
Component* newComponent = dynamic_cast<Component *>(object);
|
||||
|
||||
if (newComponent)
|
||||
{
|
||||
addComponent(newComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//RemoveComponentMask
|
||||
if (stream->readFlag())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//ComponentUpdateMask
|
||||
if (stream->readFlag())
|
||||
{
|
||||
U32 updatingComponents = stream->readInt(8);
|
||||
|
||||
for (U32 i = 0; i < updatingComponents; i++)
|
||||
{
|
||||
U32 updateComponentIndex = stream->readInt(8);
|
||||
|
||||
Component* comp = mComponents[updateComponentIndex];
|
||||
comp->unpackUpdate(con, stream);
|
||||
}
|
||||
}
|
||||
|
||||
/*if (stream->readFlag())
|
||||
{
|
||||
if (stream->readFlag())
|
||||
{
|
||||
//if we've just started the update, clear our behaviors
|
||||
if (stream->readFlag())
|
||||
clearComponents(false);
|
||||
char name[256];
|
||||
stream->readString(name);
|
||||
assignName(name);
|
||||
}
|
||||
|
||||
S32 componentCount = stream->readInt(16);
|
||||
if (stream->readFlag())
|
||||
{
|
||||
char superClassname[256];
|
||||
stream->readString(superClassname);
|
||||
mSuperClassName = superClassname;
|
||||
}
|
||||
|
||||
for (U32 i = 0; i < componentCount; i++)
|
||||
{
|
||||
S32 gIndex = stream->readInt(NetConnection::GhostIdBitSize);
|
||||
addComponent(dynamic_cast<Component*>(con->resolveGhost(gIndex)));
|
||||
}
|
||||
if (stream->readFlag())
|
||||
{
|
||||
char classname[256];
|
||||
stream->readString(classname);
|
||||
mClassName = classname;
|
||||
}
|
||||
|
||||
linkNamespaces();
|
||||
}*/
|
||||
}
|
||||
|
||||
void Entity::setComponentNetMask(Component* comp, U32 mask)
|
||||
{
|
||||
setMaskBits(Entity::ComponentsUpdateMask);
|
||||
|
||||
for (U32 i = 0; i < mNetworkedComponents.size(); i++)
|
||||
{
|
||||
U32 netCompId = mComponents[mNetworkedComponents[i].componentIndex]->getId();
|
||||
U32 compId = comp->getId();
|
||||
|
||||
if (netCompId == compId &&
|
||||
(mNetworkedComponents[i].updateState == NetworkedComponent::None || mNetworkedComponents[i].updateState == NetworkedComponent::Updating))
|
||||
{
|
||||
mNetworkedComponents[i].updateState = NetworkedComponent::Updating;
|
||||
mNetworkedComponents[i].updateMaskBits |= mask;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -674,8 +785,7 @@ void Entity::unpackUpdate(NetConnection *con, BitStream *stream)
|
|||
//Manipulation
|
||||
void Entity::setTransform(const MatrixF &mat)
|
||||
{
|
||||
//setMaskBits(TransformMask);
|
||||
setMaskBits(TransformMask | NoWarpMask);
|
||||
MatrixF oldTransform = getTransform();
|
||||
|
||||
if (isMounted())
|
||||
{
|
||||
|
|
@ -687,25 +797,20 @@ void Entity::setTransform(const MatrixF &mat)
|
|||
|
||||
if (!newOffset.isZero())
|
||||
{
|
||||
//setMountOffset(newOffset);
|
||||
mPos = newOffset;
|
||||
}
|
||||
|
||||
Point3F matEul = mat.toEuler();
|
||||
|
||||
//mRot = Point3F(mRadToDeg(matEul.x), mRadToDeg(matEul.y), mRadToDeg(matEul.z));
|
||||
|
||||
if (matEul != Point3F(0, 0, 0))
|
||||
{
|
||||
Point3F mountEul = mMount.object->getTransform().toEuler();
|
||||
Point3F diff = matEul - mountEul;
|
||||
|
||||
//setMountRotation(Point3F(mRadToDeg(diff.x), mRadToDeg(diff.y), mRadToDeg(diff.z)));
|
||||
mRot = diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
//setMountRotation(Point3F(0, 0, 0));
|
||||
mRot = Point3F(0, 0, 0);
|
||||
}
|
||||
|
||||
|
|
@ -714,6 +819,9 @@ void Entity::setTransform(const MatrixF &mat)
|
|||
transf.setPosition(mPos + mMount.object->getPosition());
|
||||
|
||||
Parent::setTransform(transf);
|
||||
|
||||
if (transf != oldTransform)
|
||||
setMaskBits(TransformMask);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -744,6 +852,8 @@ void Entity::setTransform(const MatrixF &mat)
|
|||
|
||||
void Entity::setTransform(Point3F position, RotationF rotation)
|
||||
{
|
||||
MatrixF oldTransform = getTransform();
|
||||
|
||||
if (isMounted())
|
||||
{
|
||||
mPos = position;
|
||||
|
|
@ -755,7 +865,8 @@ void Entity::setTransform(Point3F position, RotationF rotation)
|
|||
|
||||
Parent::setTransform(transf);
|
||||
|
||||
setMaskBits(TransformMask);
|
||||
if (transf != oldTransform)
|
||||
setMaskBits(TransformMask);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -774,7 +885,6 @@ void Entity::setTransform(Point3F position, RotationF rotation)
|
|||
mPos = position;
|
||||
mRot = rotation;
|
||||
|
||||
setMaskBits(TransformMask);
|
||||
//if (isServerObject())
|
||||
// setMaskBits(TransformMask);
|
||||
|
||||
|
|
@ -788,19 +898,22 @@ void Entity::setTransform(Point3F position, RotationF rotation)
|
|||
//PROFILE_SCOPE(Entity_setTransform);
|
||||
|
||||
// Update the transforms.
|
||||
|
||||
Parent::setTransform(newMat);
|
||||
|
||||
onTransformSet.trigger(&newMat);
|
||||
U32 compCount = mComponents.size();
|
||||
for (U32 i = 0; i < compCount; ++i)
|
||||
{
|
||||
mComponents[i]->ownerTransformSet(&newMat);
|
||||
}
|
||||
|
||||
/*mObjToWorld = mWorldToObj = newMat;
|
||||
mWorldToObj.affineInverse();
|
||||
// Update the world-space AABB.
|
||||
resetWorldBox();
|
||||
// If we're in a SceneManager, sync our scene state.
|
||||
if (mSceneManager != NULL)
|
||||
mSceneManager->notifyObjectDirty(this);
|
||||
setRenderTransform(newMat);*/
|
||||
Point3F newPos = newMat.getPosition();
|
||||
RotationF newRot = newMat;
|
||||
|
||||
Point3F oldPos = oldTransform.getPosition();
|
||||
RotationF oldRot = oldTransform;
|
||||
|
||||
if (newPos != oldPos || newRot != oldRot)
|
||||
setMaskBits(TransformMask);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -833,7 +946,11 @@ void Entity::setRenderTransform(Point3F position, RotationF rotation)
|
|||
|
||||
Parent::setRenderTransform(newMat);
|
||||
|
||||
onTransformSet.trigger(&newMat);
|
||||
U32 compCount = mComponents.size();
|
||||
for (U32 i = 0; i < compCount; ++i)
|
||||
{
|
||||
mComponents[i]->ownerTransformSet(&newMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -887,7 +1004,7 @@ void Entity::setMountRotation(EulerF rotOffset)
|
|||
temp.setColumn(3, mMount.xfm.getPosition());
|
||||
|
||||
mMount.xfm = temp;
|
||||
//mRot = RotationF(temp);
|
||||
|
||||
setMaskBits(MountedMask);
|
||||
}
|
||||
}
|
||||
|
|
@ -964,63 +1081,6 @@ void Entity::getRenderMountTransform(F32 delta, S32 index, const MatrixF &xfm, M
|
|||
Parent::getMountTransform(index, xfm, outMat);
|
||||
}
|
||||
|
||||
void Entity::setForwardVector(VectorF newForward, VectorF upVector)
|
||||
{
|
||||
MatrixF mat = getTransform();
|
||||
|
||||
VectorF up(0.0f, 0.0f, 1.0f);
|
||||
VectorF axisX;
|
||||
VectorF axisY = newForward;
|
||||
VectorF axisZ;
|
||||
|
||||
if (upVector != VectorF::Zero)
|
||||
up = upVector;
|
||||
|
||||
// Validate and normalize input:
|
||||
F32 lenSq;
|
||||
lenSq = axisY.lenSquared();
|
||||
if (lenSq < 0.000001f)
|
||||
{
|
||||
axisY.set(0.0f, 1.0f, 0.0f);
|
||||
Con::errorf("Entity::setForwardVector() - degenerate forward vector");
|
||||
}
|
||||
else
|
||||
{
|
||||
axisY /= mSqrt(lenSq);
|
||||
}
|
||||
|
||||
|
||||
lenSq = up.lenSquared();
|
||||
if (lenSq < 0.000001f)
|
||||
{
|
||||
up.set(0.0f, 0.0f, 1.0f);
|
||||
Con::errorf("SceneObject::setForwardVector() - degenerate up vector - too small");
|
||||
}
|
||||
else
|
||||
{
|
||||
up /= mSqrt(lenSq);
|
||||
}
|
||||
|
||||
if (fabsf(mDot(up, axisY)) > 0.9999f)
|
||||
{
|
||||
Con::errorf("SceneObject::setForwardVector() - degenerate up vector - same as forward");
|
||||
// i haven't really tested this, but i think it generates something which should be not parallel to the previous vector:
|
||||
F32 tmp = up.x;
|
||||
up.x = -up.y;
|
||||
up.y = up.z;
|
||||
up.z = tmp;
|
||||
}
|
||||
|
||||
// construct the remaining axes:
|
||||
mCross(axisY, up, &axisX);
|
||||
mCross(axisX, axisY, &axisZ);
|
||||
|
||||
mat.setColumn(0, axisX);
|
||||
mat.setColumn(1, axisY);
|
||||
mat.setColumn(2, axisZ);
|
||||
|
||||
setTransform(mat);
|
||||
}
|
||||
//
|
||||
//These basically just redirect to any collision behaviors we have
|
||||
bool Entity::castRay(const Point3F &start, const Point3F &end, RayInfo* info)
|
||||
|
|
@ -1117,6 +1177,28 @@ void Entity::onUnmount(SceneObject *obj, S32 node)
|
|||
}
|
||||
}
|
||||
|
||||
void Entity::setControllingClient(GameConnection* client)
|
||||
{
|
||||
if (isGhost() && gSFX3DWorld)
|
||||
{
|
||||
if (gSFX3DWorld->getListener() == this && !client && getControllingClient() && getControllingClient()->isConnectionToServer())
|
||||
{
|
||||
// We are the current listener and are no longer a controller object on the
|
||||
// connection, so clear our listener status.
|
||||
|
||||
gSFX3DWorld->setListener(NULL);
|
||||
}
|
||||
else if (client && client->isConnectionToServer() && !getControllingObject())
|
||||
{
|
||||
// We're on the local client and not controlled by another object, so make
|
||||
// us the current SFX listener.
|
||||
|
||||
gSFX3DWorld->setListener(this);
|
||||
}
|
||||
}
|
||||
Parent::setControllingClient(client);
|
||||
}
|
||||
|
||||
//Heirarchy stuff
|
||||
void Entity::addObject(SimObject* object)
|
||||
{
|
||||
|
|
@ -1223,11 +1305,28 @@ bool Entity::addComponent(Component *comp)
|
|||
// Register the component with this owner.
|
||||
comp->setOwner(this);
|
||||
|
||||
comp->setIsServerObject(isServerObject());
|
||||
|
||||
//if we've already been added and this is being added after the fact(at runtime),
|
||||
//then just go ahead and call it's onComponentAdd so it can get to work
|
||||
if (mInitialized)
|
||||
//if (mInitialized)
|
||||
{
|
||||
comp->onComponentAdd();
|
||||
|
||||
if (comp->isNetworked())
|
||||
{
|
||||
NetworkedComponent netComp;
|
||||
netComp.componentIndex = mComponents.size() - 1;
|
||||
netComp.updateState = NetworkedComponent::Adding;
|
||||
netComp.updateMaskBits = -1;
|
||||
|
||||
mNetworkedComponents.push_back(netComp);
|
||||
|
||||
setMaskBits(AddComponentsMask);
|
||||
setMaskBits(ComponentsUpdateMask);
|
||||
}
|
||||
}
|
||||
|
||||
onComponentAdded.trigger(comp);
|
||||
|
||||
return true;
|
||||
|
|
@ -1261,9 +1360,8 @@ bool Entity::removeComponent(Component *comp, bool deleteComponent)
|
|||
|
||||
onComponentRemoved.trigger(comp);
|
||||
|
||||
comp->setOwner(NULL);
|
||||
|
||||
comp->onComponentRemove(); //in case the behavior needs to do cleanup on the owner
|
||||
comp->setOwner(NULL);
|
||||
|
||||
if (deleteComponent)
|
||||
comp->safeDeleteObject();
|
||||
|
|
@ -1338,7 +1436,7 @@ Component *Entity::getComponent(String componentType)
|
|||
Namespace *NS = comp->getNamespace();
|
||||
|
||||
//we shouldn't ever go past Component into net object, as we're no longer dealing with component classes
|
||||
while (dStrcmp(NS->getName(), "NetObject"))
|
||||
while (dStrcmp(NS->getName(), "SimObject"))
|
||||
{
|
||||
String namespaceName = NS->getName();
|
||||
|
||||
|
|
@ -1364,72 +1462,6 @@ void Entity::onInspect()
|
|||
{
|
||||
(*it)->onInspect();
|
||||
}
|
||||
|
||||
GuiTreeViewCtrl *editorTree = dynamic_cast<GuiTreeViewCtrl*>(Sim::findObject("EditorTree"));
|
||||
if (!editorTree)
|
||||
return;
|
||||
|
||||
GuiTreeViewCtrl::Item *newItem, *parentItem;
|
||||
|
||||
parentItem = editorTree->getItem(editorTree->findItemByObjectId(getId()));
|
||||
|
||||
S32 componentID = editorTree->insertItem(parentItem->getID(), "Components");
|
||||
|
||||
newItem = editorTree->getItem(componentID);
|
||||
newItem->mState.set(GuiTreeViewCtrl::Item::VirtualParent);
|
||||
newItem->mState.set(GuiTreeViewCtrl::Item::DenyDrag);
|
||||
//newItem->mState.set(GuiTreeViewCtrl::Item::InspectorData);
|
||||
newItem->mState.set(GuiTreeViewCtrl::Item::ForceItemName);
|
||||
//newItem->mInspectorInfo.mObject = this;
|
||||
|
||||
AssetManager *assetDB = dynamic_cast<AssetManager*>(Sim::findObject("AssetDatabase"));
|
||||
if (!assetDB)
|
||||
return;
|
||||
|
||||
//This is used in the event of script-created assets, which likely only have
|
||||
//the name and other 'friendly' properties stored in a ComponentAsset.
|
||||
//So we'll do a query for those assets and find the asset based on the component's
|
||||
//class name
|
||||
AssetQuery* qry = new AssetQuery();
|
||||
qry->registerObject();
|
||||
|
||||
assetDB->findAssetType(qry, "ComponentAsset");
|
||||
|
||||
for (U32 i = 0; i < mComponents.size(); ++i)
|
||||
{
|
||||
String compName = mComponents[i]->getFriendlyName();
|
||||
|
||||
if (compName == String(""))
|
||||
{
|
||||
String componentClass = mComponents[i]->getClassNamespace();
|
||||
|
||||
//Means that it's a script-derived component and we should consult the asset to try
|
||||
//to get the info for it
|
||||
S32 compAssetCount = qry->mAssetList.size();
|
||||
for (U32 c = 0; c < compAssetCount; ++c)
|
||||
{
|
||||
StringTableEntry assetID = qry->mAssetList[c];
|
||||
|
||||
ComponentAsset* compAsset = assetDB->acquireAsset<ComponentAsset>(assetID);
|
||||
|
||||
String compAssetClass = compAsset->getComponentName();
|
||||
if (componentClass == compAssetClass)
|
||||
{
|
||||
compName = compAsset->getFriendlyName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
S32 compID = editorTree->insertItem(componentID, compName);
|
||||
newItem = editorTree->getItem(compID);
|
||||
newItem->mInspectorInfo.mObject = mComponents[i];
|
||||
newItem->mState.set(GuiTreeViewCtrl::Item::ForceItemName);
|
||||
newItem->mState.set(GuiTreeViewCtrl::Item::DenyDrag);
|
||||
newItem->mState.set(GuiTreeViewCtrl::Item::InspectorData);
|
||||
}
|
||||
|
||||
editorTree->buildVisibleTree(true);
|
||||
}
|
||||
|
||||
void Entity::onEndInspect()
|
||||
|
|
@ -1615,9 +1647,25 @@ void Entity::updateContainer()
|
|||
}
|
||||
//
|
||||
|
||||
void Entity::notifyComponents(String signalFunction, String argA, String argB, String argC, String argD, String argE)
|
||||
{
|
||||
for (U32 i = 0; i < mComponents.size(); i++)
|
||||
{
|
||||
// We can do this because both are in the string table
|
||||
Component *comp = mComponents[i];
|
||||
|
||||
if (comp->isActive())
|
||||
{
|
||||
if (comp->isMethod(signalFunction))
|
||||
Con::executef(comp, signalFunction, argA, argB, argC, argD, argE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::setComponentsDirty()
|
||||
{
|
||||
if (mToLoadComponents.empty())
|
||||
bool tmp = true;
|
||||
/*if (mToLoadComponents.empty())
|
||||
mStartComponentUpdate = true;
|
||||
|
||||
//we need to build a list of behaviors that need to be pushed across the network
|
||||
|
|
@ -1642,7 +1690,7 @@ void Entity::setComponentsDirty()
|
|||
}
|
||||
}
|
||||
|
||||
setMaskBits(ComponentsMask);
|
||||
setMaskBits(ComponentsMask);*/
|
||||
}
|
||||
|
||||
void Entity::setComponentDirty(Component *comp, bool forceUpdate)
|
||||
|
|
@ -1833,7 +1881,6 @@ DefineConsoleMethod(Entity, getComponent, S32, (String componentName), (""),
|
|||
Component *comp = object->getComponent(componentName);
|
||||
|
||||
return (comp != NULL) ? comp->getId() : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*ConsoleMethod(Entity, getBehaviorByType, S32, 3, 3, "(string BehaviorTemplateName) - gets a behavior\n"
|
||||
|
|
@ -1917,6 +1964,15 @@ DefineConsoleMethod(Entity, getMoveTrigger, bool, (S32 triggerNum), (0),
|
|||
return false;
|
||||
}
|
||||
|
||||
DefineEngineMethod(Entity, getForwardVector, VectorF, (), ,
|
||||
"Get the direction this object is facing.\n"
|
||||
"@return a vector indicating the direction this object is facing.\n"
|
||||
"@note This is the object's y axis.")
|
||||
{
|
||||
VectorF forVec = object->getTransform().getForwardVector();
|
||||
return forVec;
|
||||
}
|
||||
|
||||
DefineConsoleMethod(Entity, setForwardVector, void, (VectorF newForward), (VectorF(0,0,0)),
|
||||
"Get the number of static fields on the object.\n"
|
||||
"@return The number of static fields defined on the object.")
|
||||
|
|
@ -1936,4 +1992,53 @@ DefineConsoleMethod(Entity, rotateTo, void, (Point3F lookPosition, F32 degreePer
|
|||
"@return The number of static fields defined on the object.")
|
||||
{
|
||||
//object->setForwardVector(newForward);
|
||||
}
|
||||
|
||||
DefineConsoleMethod(Entity, notify, void, (String signalFunction, String argA, String argB, String argC, String argD, String argE),
|
||||
("", "", "", "", "", ""),
|
||||
"Triggers a signal call to all components for a certain function.")
|
||||
{
|
||||
if (signalFunction == String(""))
|
||||
return;
|
||||
|
||||
object->notifyComponents(signalFunction, argA, argB, argC, argD, argE);
|
||||
}
|
||||
|
||||
DefineConsoleFunction(findEntitiesByTag, const char*, (SimGroup* searchingGroup, String tags), (nullAsType<SimGroup*>(), ""),
|
||||
"Finds all entities that have the provided tags.\n"
|
||||
"@param searchingGroup The SimGroup to search inside. If null, we'll search the entire dictionary(this can be slow!).\n"
|
||||
"@param tags Word delimited list of tags to search for. If multiple tags are included, the list is eclusively parsed, requiring all tags provided to be found on an entity for a match.\n"
|
||||
"@return A word list of IDs of entities that match the tag search terms.")
|
||||
{
|
||||
//if (tags.isEmpty())
|
||||
return "";
|
||||
|
||||
/*if (searchingGroup == nullptr)
|
||||
{
|
||||
searchingGroup = Sim::getRootGroup();
|
||||
}
|
||||
|
||||
StringTableEntry entityStr = StringTable->insert("Entity");
|
||||
|
||||
std::thread threadBob;
|
||||
|
||||
std::thread::id a = threadBob.get_id();
|
||||
std::thread::id b = std::this_thread::get_id().;
|
||||
|
||||
if (a == b)
|
||||
{
|
||||
//do
|
||||
}
|
||||
|
||||
for (SimGroup::iterator itr = searchingGroup->begin(); itr != searchingGroup->end(); itr++)
|
||||
{
|
||||
Entity* ent = dynamic_cast<Entity*>((*itr));
|
||||
|
||||
if (ent != nullptr)
|
||||
{
|
||||
ent->mTags.
|
||||
}
|
||||
}
|
||||
|
||||
object->notifyComponents(signalFunction, argA, argB, argC, argD, argE);*/
|
||||
}
|
||||
|
|
@ -35,6 +35,12 @@
|
|||
#ifndef _CONTAINERQUERY_H_
|
||||
#include "T3D/containerQuery.h"
|
||||
#endif
|
||||
#ifndef _ASSET_PTR_H_
|
||||
#include "assets/assetPtr.h"
|
||||
#endif
|
||||
#ifndef GAME_OBJECT_ASSET_H
|
||||
#include "T3D/assets/GameObjectAsset.h"
|
||||
#endif
|
||||
|
||||
class Component;
|
||||
|
||||
|
|
@ -52,18 +58,43 @@ private:
|
|||
|
||||
Vector<Component*> mComponents;
|
||||
|
||||
Vector<Component*> mToLoadComponents;
|
||||
//Bit of helper data to let us track and manage the adding, removal and updating of networked components
|
||||
struct NetworkedComponent
|
||||
{
|
||||
U32 componentIndex;
|
||||
|
||||
enum UpdateState
|
||||
{
|
||||
None,
|
||||
Adding,
|
||||
Removing,
|
||||
Updating
|
||||
};
|
||||
|
||||
UpdateState updateState;
|
||||
|
||||
U32 updateMaskBits;
|
||||
};
|
||||
|
||||
Vector<NetworkedComponent> mNetworkedComponents;
|
||||
|
||||
U32 mComponentNetMask;
|
||||
|
||||
bool mStartComponentUpdate;
|
||||
|
||||
StringTableEntry mGameObjectAssetId;
|
||||
AssetPtr<GameObjectAsset> mGameObjectAsset;
|
||||
|
||||
ContainerQueryInfo containerInfo;
|
||||
|
||||
bool mInitialized;
|
||||
|
||||
String mTags;
|
||||
|
||||
Signal< void(Component*) > onComponentAdded;
|
||||
Signal< void(Component*) > onComponentRemoved;
|
||||
|
||||
Signal< void(MatrixF*) > onTransformSet;
|
||||
S32 mLifetimeMS;
|
||||
|
||||
protected:
|
||||
|
||||
|
|
@ -96,9 +127,12 @@ public:
|
|||
{
|
||||
TransformMask = Parent::NextFreeMask << 0,
|
||||
BoundsMask = Parent::NextFreeMask << 1,
|
||||
ComponentsMask = Parent::NextFreeMask << 2,
|
||||
NoWarpMask = Parent::NextFreeMask << 3,
|
||||
NextFreeMask = Parent::NextFreeMask << 4
|
||||
ComponentsUpdateMask = Parent::NextFreeMask << 2,
|
||||
AddComponentsMask = Parent::NextFreeMask << 3,
|
||||
RemoveComponentsMask = Parent::NextFreeMask << 4,
|
||||
NoWarpMask = Parent::NextFreeMask << 5,
|
||||
NamespaceMask = Parent::NextFreeMask << 6,
|
||||
NextFreeMask = Parent::NextFreeMask << 7
|
||||
};
|
||||
|
||||
StateDelta mDelta;
|
||||
|
|
@ -106,6 +140,8 @@ public:
|
|||
|
||||
Move lastMove;
|
||||
|
||||
S32 mStartTimeMS;
|
||||
|
||||
//
|
||||
Entity();
|
||||
~Entity();
|
||||
|
|
@ -123,16 +159,14 @@ public:
|
|||
virtual MatrixF getTransform();
|
||||
virtual Point3F getPosition() const { return mPos; }
|
||||
|
||||
//void setTransform(Point3F position, RotationF rot);
|
||||
|
||||
//void setRotation(RotationF rotation);
|
||||
|
||||
void setRotation(RotationF rotation) {
|
||||
mRot = rotation;
|
||||
setMaskBits(TransformMask);
|
||||
};
|
||||
RotationF getRotation() { return mRot; }
|
||||
|
||||
static bool _setGameObject(void *object, const char *index, const char *data);
|
||||
|
||||
void setMountOffset(Point3F posOffset);
|
||||
void setMountRotation(EulerF rotOffset);
|
||||
|
||||
|
|
@ -146,13 +180,18 @@ public:
|
|||
virtual void getMountTransform(S32 index, const MatrixF &xfm, MatrixF *outMat);
|
||||
virtual void getRenderMountTransform(F32 delta, S32 index, const MatrixF &xfm, MatrixF *outMat);
|
||||
|
||||
void setForwardVector(VectorF newForward, VectorF upVector = VectorF::Zero);
|
||||
|
||||
virtual void mountObject(SceneObject *obj, S32 node, const MatrixF &xfm = MatrixF::Identity);
|
||||
void mountObject(SceneObject* objB, MatrixF txfm);
|
||||
void onMount(SceneObject *obj, S32 node);
|
||||
void onUnmount(SceneObject *obj, S32 node);
|
||||
|
||||
/// Sets the client controlling this object
|
||||
/// @param client Client that is now controlling this object
|
||||
virtual void setControllingClient(GameConnection *client);
|
||||
|
||||
//
|
||||
//Networking
|
||||
//
|
||||
// NetObject
|
||||
U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
|
||||
void unpackUpdate(NetConnection *conn, BitStream *stream);
|
||||
|
|
@ -160,9 +199,13 @@ public:
|
|||
void setComponentsDirty();
|
||||
void setComponentDirty(Component *comp, bool forceUpdate = false);
|
||||
|
||||
void setComponentNetMask(Component* comp, U32 mask);
|
||||
|
||||
//Components
|
||||
virtual bool deferAddingComponents() const { return true; }
|
||||
|
||||
void notifyComponents(String signalFunction, String argA, String argB, String argC, String argD, String argE);
|
||||
|
||||
template <class T>
|
||||
T* getComponent();
|
||||
template <class T>
|
||||
|
|
|
|||
|
|
@ -44,10 +44,8 @@
|
|||
#include "console/engineAPI.h"
|
||||
#include "math/mTransform.h"
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
#include "T3D/entity.h"
|
||||
#include "T3D/components/coreInterfaces.h"
|
||||
#endif
|
||||
|
||||
#ifdef TORQUE_HIFI_NET
|
||||
#include "T3D/gameBase/hifi/hifiMoveList.h"
|
||||
|
|
@ -789,7 +787,6 @@ bool GameConnection::getControlCameraFov(F32 * fov)
|
|||
}
|
||||
if (cObj)
|
||||
{
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
if (Entity* ent = dynamic_cast<Entity*>(cObj))
|
||||
{
|
||||
if (CameraInterface* camInterface = ent->getComponent<CameraInterface>())
|
||||
|
|
@ -799,11 +796,9 @@ bool GameConnection::getControlCameraFov(F32 * fov)
|
|||
}
|
||||
else
|
||||
{
|
||||
*fov = cObj->getCameraFov();
|
||||
*fov = cObj->getCameraFov();
|
||||
}
|
||||
#else
|
||||
*fov = cObj->getCameraFov();
|
||||
#endif
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
|
@ -823,7 +818,6 @@ bool GameConnection::isValidControlCameraFov(F32 fov)
|
|||
|
||||
if (cObj)
|
||||
{
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
if (Entity* ent = dynamic_cast<Entity*>(cObj))
|
||||
{
|
||||
if (CameraInterface* camInterface = ent->getComponent<CameraInterface>())
|
||||
|
|
@ -835,9 +829,6 @@ bool GameConnection::isValidControlCameraFov(F32 fov)
|
|||
{
|
||||
return cObj->isValidCameraFov(fov);
|
||||
}
|
||||
#else
|
||||
return cObj->isValidCameraFov(fov);
|
||||
#endif
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
@ -855,8 +846,6 @@ bool GameConnection::setControlCameraFov(F32 fov)
|
|||
}
|
||||
if (cObj)
|
||||
{
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
F32 newFov = 90.f;
|
||||
if (Entity* ent = dynamic_cast<Entity*>(cObj))
|
||||
{
|
||||
|
|
@ -876,11 +865,6 @@ bool GameConnection::setControlCameraFov(F32 fov)
|
|||
cObj->setCameraFov(mClampF(fov, MinCameraFov, MaxCameraFov));
|
||||
newFov = cObj->getCameraFov();
|
||||
}
|
||||
#else
|
||||
// allow shapebase to clamp fov to its datablock values
|
||||
cObj->setCameraFov(mClampF(fov, MinCameraFov, MaxCameraFov));
|
||||
F32 newFov = cObj->getCameraFov();
|
||||
#endif
|
||||
|
||||
// server fov of client has 1degree resolution
|
||||
if( S32(newFov) != S32(mCameraFov) || newFov != fov )
|
||||
|
|
|
|||
|
|
@ -32,10 +32,8 @@
|
|||
#include "platform/profiler.h"
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
#include "T3D/components/coreInterfaces.h"
|
||||
#include "T3D/components/component.h"
|
||||
#endif
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
ProcessObject::ProcessObject()
|
||||
|
|
@ -277,12 +275,10 @@ void ProcessList::advanceObjects()
|
|||
onTickObject(pobj);
|
||||
}
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
for (U32 i = 0; i < UpdateInterface::all.size(); i++)
|
||||
{
|
||||
UpdateInterface::all[i]->processTick();
|
||||
}
|
||||
#endif
|
||||
|
||||
mTotalTicks++;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,10 +37,8 @@
|
|||
#include "T3D/gameBase/std/stdMoveList.h"
|
||||
#include "T3D/fx/cameraFXMgr.h"
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
#include "T3D/components/coreInterfaces.h"
|
||||
#include "T3D/components/component.h"
|
||||
#endif
|
||||
|
||||
MODULE_BEGIN( ProcessList )
|
||||
|
||||
|
|
@ -137,7 +135,6 @@ bool StdClientProcessList::advanceTime( SimTime timeDelta )
|
|||
obj = obj->mProcessLink.next;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
for (U32 i = 0; i < UpdateInterface::all.size(); i++)
|
||||
{
|
||||
Component *comp = dynamic_cast<Component*>(UpdateInterface::all[i]);
|
||||
|
|
@ -147,7 +144,6 @@ bool StdClientProcessList::advanceTime( SimTime timeDelta )
|
|||
|
||||
UpdateInterface::all[i]->interpolateTick(mLastDelta);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Inform objects of total elapsed delta so they can advance
|
||||
// client side animations.
|
||||
|
|
@ -163,7 +159,6 @@ bool StdClientProcessList::advanceTime( SimTime timeDelta )
|
|||
obj = obj->mProcessLink.next;
|
||||
}
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
for (U32 i = 0; i < UpdateInterface::all.size(); i++)
|
||||
{
|
||||
Component *comp = dynamic_cast<Component*>(UpdateInterface::all[i]);
|
||||
|
|
@ -176,7 +171,6 @@ bool StdClientProcessList::advanceTime( SimTime timeDelta )
|
|||
|
||||
UpdateInterface::all[i]->advanceTime(dt);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1209,7 +1209,7 @@ DefineEngineMethod( Item, isRotating, bool, (),,
|
|||
return object->isRotating();
|
||||
}
|
||||
|
||||
DefineEngineMethod( Item, setCollisionTimeout, bool, (S32 ignoreColObj),(NULL),
|
||||
DefineEngineMethod( Item, setCollisionTimeout, bool, (S32 ignoreColObj),,
|
||||
"@brief Temporarily disable collisions against a specific ShapeBase object.\n\n"
|
||||
|
||||
"This is useful to prevent a player from immediately picking up an Item they have "
|
||||
|
|
|
|||
|
|
@ -4405,7 +4405,7 @@ DefineEngineMethod( ShapeBase, getEyeTransform, TransformF, (),,
|
|||
return mat;
|
||||
}
|
||||
|
||||
DefineEngineMethod( ShapeBase, getLookAtPoint, const char*, ( F32 distance, S32 typeMask ), ( 2000, 0xFFFFFFFF ),
|
||||
DefineEngineMethod( ShapeBase, getLookAtPoint, const char*, ( F32 distance, U32 typeMask ), ( 2000, 0xFFFFFFFF ),
|
||||
"@brief Get the world position this object is looking at.\n\n"
|
||||
|
||||
"Casts a ray from the eye and returns information about what the ray hits.\n"
|
||||
|
|
|
|||
30
Engine/source/T3D/systems/componentSystem.h
Normal file
30
Engine/source/T3D/systems/componentSystem.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
template<typename T>
|
||||
class SystemInterface
|
||||
{
|
||||
public:
|
||||
bool mIsEnabled;
|
||||
bool mIsServer;
|
||||
|
||||
static Vector<T*> all;
|
||||
|
||||
SystemInterface()
|
||||
{
|
||||
all.push_back((T*)this);
|
||||
}
|
||||
|
||||
virtual ~SystemInterface()
|
||||
{
|
||||
for (U32 i = 0; i < all.size(); i++)
|
||||
{
|
||||
if (all[i] == (T*)this)
|
||||
{
|
||||
all.erase(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
template<typename T> Vector<T*> SystemInterface<T>::all(0);
|
||||
375
Engine/source/T3D/systems/render/meshRenderSystem.cpp
Normal file
375
Engine/source/T3D/systems/render/meshRenderSystem.cpp
Normal file
|
|
@ -0,0 +1,375 @@
|
|||
#include "T3D/systems/render/meshRenderSystem.h"
|
||||
#include "gfx/gfxTransformSaver.h"
|
||||
#include "lighting/lightQuery.h"
|
||||
|
||||
#include "renderInstance/renderPassManager.h"
|
||||
#include "materials/materialManager.h"
|
||||
#include "materials/baseMatInstance.h"
|
||||
|
||||
Vector<MeshRenderSystem::BufferMaterials> MeshRenderSystem::mBufferMaterials(0);
|
||||
Vector<MeshRenderSystem::BufferSet> MeshRenderSystem::mStaticBuffers(0);
|
||||
|
||||
void MeshRenderSystem::render(SceneManager *sceneManager, SceneRenderState* state)
|
||||
{
|
||||
Frustum viewFrustum = state->getCullingFrustum();
|
||||
MatrixF camTransform = state->getCameraTransform();
|
||||
|
||||
U32 count = MeshRenderSystemInterface::all.size();
|
||||
for (U32 i = 0; i < count; i++)
|
||||
{
|
||||
//Server side items exist for data, but we don't actually render them
|
||||
bool isClient = MeshRenderSystemInterface::all[i]->mIsClient;
|
||||
if (!MeshRenderSystemInterface::all[i]->mIsClient)
|
||||
continue;
|
||||
|
||||
bool isStatic = MeshRenderSystemInterface::all[i]->mStatic;
|
||||
if (MeshRenderSystemInterface::all[i]->mStatic)
|
||||
continue;
|
||||
|
||||
//First, do frustum culling
|
||||
if (viewFrustum.isCulled(MeshRenderSystemInterface::all[i]->mBounds))
|
||||
continue;
|
||||
|
||||
// Set the query box for the container query. Never
|
||||
// make it larger than the frustum's AABB. In the editor,
|
||||
// always query the full frustum as that gives objects
|
||||
// the opportunity to render editor visualizations even if
|
||||
// they are otherwise not in view.
|
||||
if (!state->getCullingFrustum().getBounds().isOverlapped(state->getRenderArea()))
|
||||
{
|
||||
// This handles fringe cases like flying backwards into a zone where you
|
||||
// end up pretty much standing on a zone border and looking directly into
|
||||
// its "walls". In that case the traversal area will be behind the frustum
|
||||
// (remember that the camera isn't where visibility starts, it's the near
|
||||
// distance).
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//We can then sort our objects by range since we have it already, so we can do occlusion culling be rendering front-to-back
|
||||
|
||||
//if we've made it this far, call down to the render function to actually display our stuff
|
||||
renderInterface(i, state);
|
||||
}
|
||||
|
||||
//Static Batch rendering
|
||||
if ( /*!mMaterialInst ||*/ !state)
|
||||
return;
|
||||
|
||||
BaseMatInstance *matInst = MATMGR->getWarningMatInstance();
|
||||
|
||||
// Get a handy pointer to our RenderPassmanager
|
||||
RenderPassManager *renderPass = state->getRenderPass();
|
||||
|
||||
for (U32 i = 0; i < mStaticBuffers.size(); i++)
|
||||
{
|
||||
for (U32 b = 0; b < mStaticBuffers[i].buffers.size(); b++)
|
||||
{
|
||||
if (mStaticBuffers[i].buffers[b].vertData.empty())
|
||||
continue;
|
||||
|
||||
MeshRenderInst *ri = renderPass->allocInst<MeshRenderInst>();
|
||||
|
||||
// Set our RenderInst as a standard mesh render
|
||||
ri->type = RenderPassManager::RIT_Mesh;
|
||||
|
||||
//If our material has transparency set on this will redirect it to proper render bin
|
||||
if (matInst->getMaterial()->isTranslucent())
|
||||
{
|
||||
ri->type = RenderPassManager::RIT_Translucent;
|
||||
ri->translucentSort = true;
|
||||
}
|
||||
|
||||
// Calculate our sorting point
|
||||
if (state)
|
||||
{
|
||||
// Calculate our sort point manually.
|
||||
const Box3F& rBox = Box3F(1000);// getRenderWorldBox();
|
||||
ri->sortDistSq = rBox.getSqDistanceToPoint(state->getCameraPosition());
|
||||
}
|
||||
else
|
||||
ri->sortDistSq = 0.0f;
|
||||
|
||||
// Set up our transforms
|
||||
MatrixF objectToWorld = MatrixF::Identity;//getRenderTransform();
|
||||
//objectToWorld.scale(getScale());
|
||||
|
||||
ri->objectToWorld = renderPass->allocUniqueXform(objectToWorld);
|
||||
ri->worldToCamera = renderPass->allocSharedXform(RenderPassManager::View);
|
||||
ri->projection = renderPass->allocSharedXform(RenderPassManager::Projection);
|
||||
|
||||
// If our material needs lights then fill the RIs
|
||||
// light vector with the best lights.
|
||||
/*if (matInst->isForwardLit())
|
||||
{
|
||||
LightQuery query;
|
||||
query.init(getWorldSphere());
|
||||
query.getLights(ri->lights, 8);
|
||||
}*/
|
||||
|
||||
// Make sure we have an up-to-date backbuffer in case
|
||||
// our Material would like to make use of it
|
||||
// NOTICE: SFXBB is removed and refraction is disabled!
|
||||
//ri->backBuffTex = GFX->getSfxBackBuffer();
|
||||
|
||||
// Set our Material
|
||||
ri->matInst = matInst;
|
||||
|
||||
// Set up our vertex buffer and primitive buffer
|
||||
ri->vertBuff = &mStaticBuffers[i].buffers[b].vertexBuffer;
|
||||
ri->primBuff = &mStaticBuffers[i].buffers[b].primitiveBuffer;
|
||||
|
||||
ri->prim = renderPass->allocPrim();
|
||||
ri->prim->type = GFXTriangleList;
|
||||
ri->prim->minIndex = 0;
|
||||
ri->prim->startIndex = 0;
|
||||
ri->prim->numPrimitives = mStaticBuffers[i].buffers[b].primData.size();
|
||||
ri->prim->startVertex = 0;
|
||||
ri->prim->numVertices = mStaticBuffers[i].buffers[b].vertData.size();
|
||||
|
||||
// We sort by the material then vertex buffer
|
||||
ri->defaultKey = matInst->getStateHint();
|
||||
ri->defaultKey2 = (uintptr_t)ri->vertBuff; // Not 64bit safe!
|
||||
|
||||
// Submit our RenderInst to the RenderPassManager
|
||||
state->getRenderPass()->addInst(ri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MeshRenderSystem::renderInterface(U32 interfaceIndex, SceneRenderState* state)
|
||||
{
|
||||
//Fetch
|
||||
MeshRenderSystemInterface* interface = MeshRenderSystemInterface::all[interfaceIndex];
|
||||
|
||||
if (interface->mShapeInstance == nullptr)
|
||||
return;
|
||||
|
||||
Point3F cameraOffset;
|
||||
interface->mTransform.getColumn(3, &cameraOffset);
|
||||
cameraOffset -= state->getDiffuseCameraPosition();
|
||||
F32 dist = cameraOffset.len();
|
||||
if (dist < 0.01f)
|
||||
dist = 0.01f;
|
||||
|
||||
Point3F objScale = interface->mScale;
|
||||
F32 invScale = (1.0f / getMax(getMax(objScale.x, objScale.y), objScale.z));
|
||||
|
||||
interface->mShapeInstance->setDetailFromDistance(state, dist * invScale);
|
||||
|
||||
if (interface->mShapeInstance->getCurrentDetail() < 0)
|
||||
return;
|
||||
|
||||
GFXTransformSaver saver;
|
||||
|
||||
// Set up our TS render state.
|
||||
TSRenderState rdata;
|
||||
rdata.setSceneState(state);
|
||||
rdata.setFadeOverride(1.0f);
|
||||
rdata.setOriginSort(false);
|
||||
|
||||
// We might have some forward lit materials
|
||||
// so pass down a query to gather lights.
|
||||
LightQuery query;
|
||||
query.init(interface->mSphere);
|
||||
rdata.setLightQuery(&query);
|
||||
|
||||
MatrixF mat = interface->mTransform;
|
||||
|
||||
mat.scale(objScale);
|
||||
GFX->setWorldMatrix(mat);
|
||||
|
||||
interface->mShapeInstance->render(rdata);
|
||||
}
|
||||
|
||||
void MeshRenderSystem::rebuildBuffers()
|
||||
{
|
||||
U32 BUFFER_SIZE = 65000;
|
||||
Vector<U32> tempIndices;
|
||||
tempIndices.reserve(4);
|
||||
|
||||
Box3F newBounds = Box3F::Zero;
|
||||
|
||||
mStaticBuffers.clear();
|
||||
|
||||
for (U32 i = 0; i < MeshRenderSystemInterface::all.size(); i++)
|
||||
{
|
||||
if (!MeshRenderSystemInterface::all[i]->mIsEnabled)
|
||||
continue;
|
||||
|
||||
if (!MeshRenderSystemInterface::all[i]->mIsClient || !MeshRenderSystemInterface::all[i]->mStatic)
|
||||
continue;
|
||||
|
||||
//TODO: Properly re-implement StaticElements to container owner interfaces and buffer sets
|
||||
for (U32 j = 0; j < MeshRenderSystemInterface::all[i]->mGeometry.mPolyList.size(); j++)
|
||||
{
|
||||
const OptimizedPolyList::Poly& poly = MeshRenderSystemInterface::all[i]->mGeometry.mPolyList[j];
|
||||
|
||||
if (poly.vertexCount < 3)
|
||||
continue;
|
||||
|
||||
tempIndices.setSize(poly.vertexCount);
|
||||
dMemset(tempIndices.address(), 0, poly.vertexCount);
|
||||
|
||||
if (poly.type == OptimizedPolyList::TriangleStrip ||
|
||||
poly.type == OptimizedPolyList::TriangleFan)
|
||||
{
|
||||
tempIndices[0] = 0;
|
||||
U32 idx = 1;
|
||||
|
||||
for (U32 k = 1; k < poly.vertexCount; k += 2)
|
||||
tempIndices[idx++] = k;
|
||||
|
||||
for (U32 k = ((poly.vertexCount - 1) & (~0x1)); k > 0; k -= 2)
|
||||
tempIndices[idx++] = k;
|
||||
}
|
||||
else if (poly.type == OptimizedPolyList::TriangleList)
|
||||
{
|
||||
for (U32 k = 0; k < poly.vertexCount; k++)
|
||||
tempIndices[k] = k;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
//got our data, now insert it into the correct buffer!
|
||||
S32 bufferId = findBufferSetByMaterial(poly.material);
|
||||
|
||||
if (bufferId == -1)
|
||||
{
|
||||
//add a new buffer set if we didn't get a match!
|
||||
BufferSet newSet;
|
||||
newSet.surfaceMaterialId = poly.material;
|
||||
|
||||
mStaticBuffers.push_back(newSet);
|
||||
|
||||
bufferId = mStaticBuffers.size() - 1;
|
||||
}
|
||||
|
||||
//see if this would push us over our buffer size limit, if it is, make a new buffer for this set
|
||||
if (mStaticBuffers[bufferId].buffers.last().vertData.size() + 3 > BUFFER_SIZE
|
||||
|| mStaticBuffers[bufferId].buffers.last().primData.size() + 1 > BUFFER_SIZE)
|
||||
{
|
||||
//yep, we'll overstep with this, so spool up a new buffer in this set
|
||||
BufferSet::Buffers newBuffer = BufferSet::Buffers();
|
||||
mStaticBuffers[bufferId].buffers.push_back(newBuffer);
|
||||
}
|
||||
|
||||
const U32& firstIdx = MeshRenderSystemInterface::all[i]->mGeometry.mIndexList[poly.vertexStart];
|
||||
const OptimizedPolyList::VertIndex& firstVertIdx = MeshRenderSystemInterface::all[i]->mGeometry.mVertexList[firstIdx];
|
||||
|
||||
//Vector<Point3F> geomPoints = MeshRenderSystemInterface::all[i]->mGeometry.mPoints;
|
||||
//Vector<Point3F> geomNormals = MeshRenderSystemInterface::all[i]->mGeometry.mNormals;
|
||||
//Vector<Point2F> geoUVs = MeshRenderSystemInterface::all[i]->mGeometry.mUV0s;
|
||||
|
||||
for (U32 k = 1; k < poly.vertexCount - 1; k++)
|
||||
{
|
||||
const U32& secondIdx = MeshRenderSystemInterface::all[i]->mGeometry.mIndexList[poly.vertexStart + tempIndices[k]];
|
||||
const U32& thirdIdx = MeshRenderSystemInterface::all[i]->mGeometry.mIndexList[poly.vertexStart + tempIndices[k + 1]];
|
||||
|
||||
const OptimizedPolyList::VertIndex& secondVertIdx = MeshRenderSystemInterface::all[i]->mGeometry.mVertexList[secondIdx];
|
||||
const OptimizedPolyList::VertIndex& thirdVertIdx = MeshRenderSystemInterface::all[i]->mGeometry.mVertexList[thirdIdx];
|
||||
|
||||
Point3F points[3];
|
||||
points[0] = MeshRenderSystemInterface::all[i]->mGeometry.mPoints[firstVertIdx.vertIdx];
|
||||
points[1] = MeshRenderSystemInterface::all[i]->mGeometry.mPoints[secondVertIdx.vertIdx];
|
||||
points[2] = MeshRenderSystemInterface::all[i]->mGeometry.mPoints[thirdVertIdx.vertIdx];
|
||||
|
||||
Point3F normals[3];
|
||||
normals[0] = MeshRenderSystemInterface::all[i]->mGeometry.mNormals[firstVertIdx.normalIdx];
|
||||
normals[1] = MeshRenderSystemInterface::all[i]->mGeometry.mNormals[secondVertIdx.normalIdx];
|
||||
normals[2] = MeshRenderSystemInterface::all[i]->mGeometry.mNormals[thirdVertIdx.normalIdx];
|
||||
|
||||
Point3F tangents[3];
|
||||
tangents[0] = mCross(points[1] - points[0], normals[0]);
|
||||
tangents[1] = mCross(points[2] - points[1], normals[1]);
|
||||
tangents[2] = mCross(points[0] - points[2], normals[2]);
|
||||
|
||||
Point2F uvs[3];
|
||||
uvs[0] = MeshRenderSystemInterface::all[i]->mGeometry.mUV0s[firstVertIdx.uv0Idx];
|
||||
uvs[1] = MeshRenderSystemInterface::all[i]->mGeometry.mUV0s[secondVertIdx.uv0Idx];
|
||||
uvs[2] = MeshRenderSystemInterface::all[i]->mGeometry.mUV0s[thirdVertIdx.uv0Idx];
|
||||
|
||||
mStaticBuffers[bufferId].vertCount += 3;
|
||||
mStaticBuffers[bufferId].primCount += 1;
|
||||
|
||||
for (U32 v = 0; v < 3; ++v)
|
||||
{
|
||||
//Build the vert and store it to the buffers!
|
||||
GFXVertexPNTT bufVert;
|
||||
bufVert.point = points[v];
|
||||
bufVert.normal = normals[v];
|
||||
bufVert.tangent = tangents[v];
|
||||
bufVert.texCoord = uvs[v];
|
||||
|
||||
newBounds.extend(points[v]);
|
||||
|
||||
mStaticBuffers[bufferId].buffers.last().vertData.push_back(bufVert);
|
||||
|
||||
U32 vertPrimId = mStaticBuffers[bufferId].buffers.last().vertData.size() - 1;
|
||||
mStaticBuffers[bufferId].buffers.last().primData.push_back(vertPrimId);
|
||||
|
||||
mStaticBuffers[bufferId].center += points[v];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Now, iterate through the organized data and turn them into renderable buffers
|
||||
for (U32 i = 0; i < mStaticBuffers.size(); i++)
|
||||
{
|
||||
for (U32 b = 0; b < mStaticBuffers[i].buffers.size(); b++)
|
||||
{
|
||||
BufferSet::Buffers& buffers = mStaticBuffers[i].buffers[b];
|
||||
|
||||
//if there's no data to be had in this buffer, just skip it
|
||||
if (buffers.vertData.empty())
|
||||
continue;
|
||||
|
||||
buffers.vertexBuffer.set(GFX, buffers.vertData.size(), GFXBufferTypeStatic);
|
||||
GFXVertexPNTT *pVert = buffers.vertexBuffer.lock();
|
||||
|
||||
for (U32 v = 0; v < buffers.vertData.size(); v++)
|
||||
{
|
||||
pVert->normal = buffers.vertData[v].normal;
|
||||
pVert->tangent = buffers.vertData[v].tangent;
|
||||
//pVert->color = buffers.vertData[v].color;
|
||||
pVert->point = buffers.vertData[v].point;
|
||||
pVert->texCoord = buffers.vertData[v].texCoord;
|
||||
|
||||
pVert++;
|
||||
}
|
||||
|
||||
buffers.vertexBuffer.unlock();
|
||||
|
||||
// Allocate PB
|
||||
buffers.primitiveBuffer.set(GFX, buffers.primData.size(), buffers.primData.size() / 3, GFXBufferTypeStatic);
|
||||
|
||||
U16 *pIndex;
|
||||
buffers.primitiveBuffer.lock(&pIndex);
|
||||
|
||||
for (U16 i = 0; i < buffers.primData.size(); i++)
|
||||
{
|
||||
*pIndex = i;
|
||||
pIndex++;
|
||||
}
|
||||
|
||||
buffers.primitiveBuffer.unlock();
|
||||
}
|
||||
|
||||
mStaticBuffers[i].center /= mStaticBuffers[i].vertCount;
|
||||
}
|
||||
|
||||
//mObjBox = newBounds;
|
||||
//resetWorldBox();
|
||||
}
|
||||
|
||||
U32 MeshRenderSystem::findBufferSetByMaterial(U32 matId)
|
||||
{
|
||||
for (U32 i = 0; i < mStaticBuffers.size(); i++)
|
||||
{
|
||||
if (mStaticBuffers[i].surfaceMaterialId == matId)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
207
Engine/source/T3D/systems/render/meshRenderSystem.h
Normal file
207
Engine/source/T3D/systems/render/meshRenderSystem.h
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
#pragma once
|
||||
#include "scene/sceneRenderState.h"
|
||||
#include "T3D/systems/componentSystem.h"
|
||||
#include "ts/tsShape.h"
|
||||
#include "ts/tsShapeInstance.h"
|
||||
#include "T3D/assets/ShapeAsset.h"
|
||||
#include "T3D/assets/MaterialAsset.h"
|
||||
|
||||
#ifndef _GFXVERTEXBUFFER_H_
|
||||
#include "gfx/gfxVertexBuffer.h"
|
||||
#endif
|
||||
#ifndef _GFXPRIMITIVEBUFFER_H_
|
||||
#include "gfx/gfxPrimitiveBuffer.h"
|
||||
#endif
|
||||
#ifndef _OPTIMIZEDPOLYLIST_H_
|
||||
#include "collision/optimizedPolyList.h"
|
||||
#endif
|
||||
|
||||
class MeshRenderSystemInterface : public SystemInterface<MeshRenderSystemInterface>
|
||||
{
|
||||
public:
|
||||
TSShapeInstance * mShapeInstance;
|
||||
|
||||
MatrixF mTransform;
|
||||
Point3F mScale;
|
||||
Box3F mBounds;
|
||||
SphereF mSphere;
|
||||
|
||||
bool mIsClient;
|
||||
|
||||
struct matMap
|
||||
{
|
||||
//MaterialAsset* matAsset;
|
||||
String assetId;
|
||||
U32 slot;
|
||||
};
|
||||
|
||||
Vector<matMap> mChangingMaterials;
|
||||
Vector<matMap> mMaterials;
|
||||
|
||||
//Static geometry stuff
|
||||
bool mStatic;
|
||||
|
||||
OptimizedPolyList mGeometry;
|
||||
|
||||
MeshRenderSystemInterface() : SystemInterface(), mShapeInstance(nullptr), mTransform(MatrixF::Identity), mScale(Point3F::One), mIsClient(false), mStatic(false)
|
||||
{
|
||||
mBounds = Box3F(1);
|
||||
mSphere = SphereF();
|
||||
}
|
||||
|
||||
~MeshRenderSystemInterface()
|
||||
{
|
||||
//SAFE_DELETE(mShape);
|
||||
SAFE_DELETE(mShapeInstance);
|
||||
}
|
||||
};
|
||||
|
||||
class MeshRenderSystem
|
||||
{
|
||||
protected:
|
||||
/*struct StaticBatchElement
|
||||
{
|
||||
SimObject* owner;
|
||||
OptimizedPolyList geometry;
|
||||
String batchName;
|
||||
};
|
||||
|
||||
static Vector<StaticBatchElement> mStaticElements;*/
|
||||
|
||||
//We retain the pushed geometry data for rendering here. It's static(unless forced to change through editing or whatnot)
|
||||
//so rendering the batches is real fast
|
||||
struct BufferMaterials
|
||||
{
|
||||
// The name of the Material we will use for rendering
|
||||
String mMaterialName;
|
||||
// The actual Material instance
|
||||
BaseMatInstance* mMaterialInst;
|
||||
|
||||
BufferMaterials()
|
||||
{
|
||||
mMaterialName = "";
|
||||
mMaterialInst = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
static Vector<BufferMaterials> mBufferMaterials;
|
||||
|
||||
struct BufferSet
|
||||
{
|
||||
U32 surfaceMaterialId;
|
||||
|
||||
U32 vertCount;
|
||||
U32 primCount;
|
||||
|
||||
Point3F center;
|
||||
|
||||
struct Buffers
|
||||
{
|
||||
U32 vertStart;
|
||||
U32 primStart;
|
||||
U32 vertCount;
|
||||
U32 primCount;
|
||||
|
||||
Vector<GFXVertexPNTT> vertData;
|
||||
Vector<U32> primData;
|
||||
|
||||
GFXVertexBufferHandle< GFXVertexPNTT > vertexBuffer;
|
||||
GFXPrimitiveBufferHandle primitiveBuffer;
|
||||
|
||||
Buffers()
|
||||
{
|
||||
vertStart = 0;
|
||||
primStart = 0;
|
||||
vertCount = 0;
|
||||
primCount = 0;
|
||||
|
||||
vertexBuffer = NULL;
|
||||
primitiveBuffer = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
Vector<Buffers> buffers;
|
||||
|
||||
BufferSet()
|
||||
{
|
||||
Buffers newBuffer;
|
||||
buffers.push_back(newBuffer);
|
||||
|
||||
surfaceMaterialId = 0;
|
||||
|
||||
vertCount = 0;
|
||||
primCount = 0;
|
||||
|
||||
center = Point3F::Zero;
|
||||
}
|
||||
};
|
||||
|
||||
static Vector<BufferSet> mStaticBuffers;
|
||||
|
||||
public:
|
||||
/*virtual void prepRenderImage(SceneRenderState *state);
|
||||
|
||||
bool setMeshAsset(const char* assetName);
|
||||
|
||||
virtual TSShape* getShape() { if (mMeshAsset) return mMeshAsset->getShape(); else return NULL; }
|
||||
virtual TSShapeInstance* getShapeInstance() { return mShapeInstance; }
|
||||
|
||||
Resource<TSShape> getShapeResource() { return mMeshAsset->getShapeResource(); }
|
||||
|
||||
void _onResourceChanged(const Torque::Path &path);
|
||||
|
||||
virtual bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo *info);
|
||||
|
||||
void mountObjectToNode(SceneObject* objB, String node, MatrixF txfm);
|
||||
|
||||
virtual void onDynamicModified(const char* slotName, const char* newValue);
|
||||
|
||||
void changeMaterial(U32 slot, MaterialAsset* newMat);
|
||||
bool setMatInstField(U32 slot, const char* field, const char* value);
|
||||
|
||||
virtual void onInspect();
|
||||
virtual void onEndInspect();
|
||||
|
||||
virtual Vector<MatrixF> getNodeTransforms()
|
||||
{
|
||||
Vector<MatrixF> bob;
|
||||
return bob;
|
||||
}
|
||||
|
||||
virtual void setNodeTransforms(Vector<MatrixF> transforms)
|
||||
{
|
||||
return;
|
||||
}*/
|
||||
|
||||
/*MeshRenderSystem()
|
||||
{
|
||||
|
||||
}
|
||||
virtual ~MeshRenderSystem()
|
||||
{
|
||||
smInterfaceList.clear();
|
||||
}
|
||||
|
||||
static MeshComponentInterface* GetNewInterface()
|
||||
{
|
||||
smInterfaceList.increment();
|
||||
|
||||
return &smInterfaceList.last();
|
||||
}
|
||||
|
||||
static void RemoveInterface(T* q)
|
||||
{
|
||||
smInterfaceList.erase(q);
|
||||
}*/
|
||||
|
||||
//Core render function, which does all the real work
|
||||
static void render(SceneManager *sceneManager, SceneRenderState* state);
|
||||
|
||||
//Render our particular interface's data
|
||||
static void renderInterface(U32 interfaceIndex, SceneRenderState* state);
|
||||
|
||||
//Static Batch rendering
|
||||
static void rebuildBuffers();
|
||||
|
||||
static U32 findBufferSetByMaterial(U32 matId);
|
||||
};
|
||||
34
Engine/source/T3D/systems/updateSystem.cpp
Normal file
34
Engine/source/T3D/systems/updateSystem.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "T3D/systems/updateSystem.h"
|
||||
|
||||
void UpdateSystem::processTick()
|
||||
{
|
||||
for (U32 i = 0; i < UpdateSystemInterface::all.size(); i++)
|
||||
{
|
||||
if (UpdateSystemInterface::all[i]->mIsEnabled)
|
||||
{
|
||||
//do work
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSystem::advanceTime(U32 _tickMS)
|
||||
{
|
||||
for (U32 i = 0; i < UpdateSystemInterface::all.size(); i++)
|
||||
{
|
||||
if (UpdateSystemInterface::all[i]->mIsEnabled)
|
||||
{
|
||||
//do work
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSystem::interpolateTick(U32 _deltaMS)
|
||||
{
|
||||
for (U32 i = 0; i < UpdateSystemInterface::all.size(); i++)
|
||||
{
|
||||
if (UpdateSystemInterface::all[i]->mIsEnabled)
|
||||
{
|
||||
//do work
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Engine/source/T3D/systems/updateSystem.h
Normal file
16
Engine/source/T3D/systems/updateSystem.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
#include "componentSystem.h"
|
||||
|
||||
class UpdateSystemInterface : public SystemInterface<UpdateSystemInterface>
|
||||
{
|
||||
public:
|
||||
bool mIsEnabled;
|
||||
};
|
||||
|
||||
class UpdateSystem
|
||||
{
|
||||
public:
|
||||
static void processTick();
|
||||
static void advanceTime(U32 _tickMS);
|
||||
static void interpolateTick(U32 _deltaMS);
|
||||
};
|
||||
|
|
@ -453,7 +453,7 @@ const char* afxCamera::getMode()
|
|||
static char buffer[100];
|
||||
|
||||
ConsoleMethod(afxCamera, setOrbitMode, void, 7, 8,
|
||||
"(GameBase orbitObject, transform mat, float minDistance, float maxDistance, float curDistance, bool ownClientObject)"
|
||||
"(GameBase orbitObject, TransformF mat, float minDistance, float maxDistance, float curDistance, bool ownClientObject)"
|
||||
"Set the camera to orbit around some given object.\n\n"
|
||||
"@param orbitObject Object we want to orbit.\n"
|
||||
"@param mat A set of fields: posX posY posZ aaX aaY aaZ aaTheta\n"
|
||||
|
|
@ -541,7 +541,7 @@ ConsoleMethod(afxCamera, getThirdPersonAngle, F32, 2, 2, "")
|
|||
return object->getThirdPersonAngle();
|
||||
}
|
||||
|
||||
ConsoleMethod(afxCamera, setThirdPersonOffset, void, 3, 4, "(Point3F offset [, Point3f coi_offset])")
|
||||
ConsoleMethod(afxCamera, setThirdPersonOffset, void, 3, 4, "(Point3F offset [, Point3F coi_offset])")
|
||||
{
|
||||
Point3F offset;
|
||||
dSscanf(argv[2], "%f %f %f", &offset.x, &offset.y, &offset.z);
|
||||
|
|
|
|||
|
|
@ -848,13 +848,13 @@ void afxChoreographer::unregisterParticlePool(afxParticlePool* pool)
|
|||
|
||||
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
|
||||
|
||||
DefineEngineMethod( afxChoreographer, setRanking, void, ( unsigned int ranking ),,
|
||||
DefineEngineMethod( afxChoreographer, setRanking, void, ( U32 ranking ),,
|
||||
"Set a ranking value (0-255) for the choreographer.\n" )
|
||||
{
|
||||
object->setRanking((U8)ranking);
|
||||
}
|
||||
|
||||
DefineEngineMethod( afxChoreographer, setLevelOfDetail, void, ( unsigned int lod ),,
|
||||
DefineEngineMethod( afxChoreographer, setLevelOfDetail, void, ( U32 lod ),,
|
||||
"Set a level-of-detail value (0-255) for the choreographer.\n" )
|
||||
{
|
||||
object->setLevelOfDetail((U8)lod);
|
||||
|
|
|
|||
|
|
@ -343,13 +343,13 @@ afxRPGMagicSpellData* afxSpellButton::getSpellRPGDataBlock() const
|
|||
|
||||
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
|
||||
|
||||
DefineEngineMethod( afxSpellButton, onSpellbookChange, void, ( afxSpellBook* spellbook, unsigned int page ),,
|
||||
DefineEngineMethod( afxSpellButton, onSpellbookChange, void, ( afxSpellBook* spellbook, U32 page ),,
|
||||
"Notify an afxSpellButton when its associated spellbook has changed.\n" )
|
||||
{
|
||||
object->setSpellBook(spellbook, (U8)page);
|
||||
}
|
||||
|
||||
DefineEngineMethod( afxSpellButton, onTurnPage, void, ( unsigned int page ),,
|
||||
DefineEngineMethod( afxSpellButton, onTurnPage, void, (U32 page ),,
|
||||
"Notify an afxSpellButton when the spellbook turns to a new page.\n" )
|
||||
{
|
||||
object->setPage((U8)page);
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ DefineEngineMethod(afxTSCtrl, setSpellBook, void, (afxSpellBook* spellbook),,
|
|||
object->setSpellBook(spellbook);
|
||||
}
|
||||
|
||||
DefineEngineMethod(afxTSCtrl, pushTargetingMode, void, (unsigned int mode, unsigned int checkMethod), ((U32)arcaneFX::TARGETING_OFF, (U32)arcaneFX::TARGET_CHECK_POLL),
|
||||
DefineEngineMethod(afxTSCtrl, pushTargetingMode, void, (U32 mode, U32 checkMethod), ((U32)arcaneFX::TARGETING_OFF, (U32)arcaneFX::TARGET_CHECK_POLL),
|
||||
"Push a new targeting-mode onto a statck of modes.\n\n"
|
||||
"@ingroup AFX")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ afxParticlePoolData::afxParticlePoolData(const afxParticlePoolData& other, bool
|
|||
ImplementEnumType( afxParticlePool_PoolType, "Possible particle pool types.\n" "@ingroup afxParticlePool\n\n" )
|
||||
{ afxParticlePoolData::POOL_NORMAL, "normal", "..." },
|
||||
{ afxParticlePoolData::POOL_TWOPASS, "two-pass", "..." },
|
||||
// Alias...
|
||||
{ afxParticlePoolData::POOL_TWOPASS, "twopass", "..." },
|
||||
EndImplementEnumType;
|
||||
|
||||
afxParticlePoolData::~afxParticlePoolData()
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#include "scene/sceneRenderState.h"
|
||||
#include "T3D/fx/particleEmitter.h"
|
||||
#include "renderInstance/renderPassManager.h"
|
||||
#include "lighting/lightinfo.h"
|
||||
#include "lighting/lightInfo.h"
|
||||
#include "lighting/lightManager.h"
|
||||
|
||||
#include "afx/util/afxParticlePool.h"
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
#include "console/debugOutputConsumer.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "console/engineAPI.h"
|
||||
#include "console/codeInterpreter.h"
|
||||
|
||||
#include "gfx/bitmap/gBitmap.h"
|
||||
#include "gfx/gFont.h"
|
||||
|
|
@ -227,6 +228,9 @@ void StandardMainLoop::init()
|
|||
ManagedSingleton< ThreadManager >::createSingleton();
|
||||
FrameAllocator::init(TORQUE_FRAME_SIZE); // See comments in torqueConfig.h
|
||||
|
||||
// Initialize the TorqueScript interpreter.
|
||||
CodeInterpreter::init();
|
||||
|
||||
// Yell if we can't initialize the network.
|
||||
if(!Net::init())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ class AssetBase : public SimObject
|
|||
|
||||
typedef SimObject Parent;
|
||||
|
||||
protected:
|
||||
AssetManager* mpOwningAssetManager;
|
||||
bool mAssetInitialized;
|
||||
AssetDefinition* mpAssetDefinition;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,23 @@
|
|||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _AUTOLOAD_ASSETS_H_
|
||||
#include "assets/autoloadAssets.h"
|
||||
#endif
|
||||
|
||||
#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"
|
||||
|
||||
|
|
@ -202,6 +219,69 @@ bool AssetManager::addModuleDeclaredAssets( ModuleDefinition* pModuleDefinition
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AssetManager::loadModuleAutoLoadAssets(ModuleDefinition* pModuleDefinition)
|
||||
{
|
||||
// Debug Profiling.
|
||||
PROFILE_SCOPE(AssetManager_loadModuleAutoLoadAssets);
|
||||
|
||||
// Sanity!
|
||||
AssertFatal(pModuleDefinition != NULL, "Cannot auto load assets using a NULL module definition");
|
||||
|
||||
// Does the module have any assets associated with it?
|
||||
if (pModuleDefinition->getModuleAssets().empty())
|
||||
{
|
||||
// Yes, so warn.
|
||||
Con::warnf("Asset Manager: Cannot auto load assets to module '%s' as it has no existing assets.", pModuleDefinition->getSignature());
|
||||
return false;
|
||||
}
|
||||
|
||||
U32 assetCount = pModuleDefinition->getModuleAssets().size();
|
||||
|
||||
// Iterate the module definition children.
|
||||
for (SimSet::iterator itr = pModuleDefinition->begin(); itr != pModuleDefinition->end(); ++itr)
|
||||
{
|
||||
// Fetch the declared assets.
|
||||
AutoloadAssets* pAutoloadAssets = dynamic_cast<AutoloadAssets*>(*itr);
|
||||
|
||||
// Skip if it's not a declared assets location.
|
||||
if (pAutoloadAssets == NULL)
|
||||
continue;
|
||||
|
||||
for (U32 i = 0; i < assetCount; ++i)
|
||||
{
|
||||
AssetDefinition* assetDef = pModuleDefinition->getModuleAssets()[i];
|
||||
|
||||
if (assetDef->mAssetType == pAutoloadAssets->getAssetType())
|
||||
{
|
||||
//TODO: this is stupid and ugly, need to properly automagically parse the class for registration
|
||||
AssetBase* assetBase = nullptr;
|
||||
|
||||
if (assetDef->mAssetType == StringTable->insert("ComponentAsset"))
|
||||
{
|
||||
assetBase = mTaml.read<ComponentAsset>(assetDef->mAssetBaseFilePath);
|
||||
}
|
||||
else if (assetDef->mAssetType == StringTable->insert("GUIAsset"))
|
||||
{
|
||||
assetBase = mTaml.read<GUIAsset>(assetDef->mAssetBaseFilePath);
|
||||
}
|
||||
else if (assetDef->mAssetType == StringTable->insert("ScriptAsset"))
|
||||
{
|
||||
assetBase = mTaml.read<ScriptAsset>(assetDef->mAssetBaseFilePath);
|
||||
}
|
||||
else if (assetDef->mAssetType == StringTable->insert("MaterialAsset"))
|
||||
{
|
||||
assetBase = mTaml.read<MaterialAsset>(assetDef->mAssetBaseFilePath);
|
||||
}
|
||||
|
||||
//load the asset now if valid
|
||||
if (assetBase)
|
||||
addPrivateAsset(assetBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool AssetManager::addDeclaredAsset( ModuleDefinition* pModuleDefinition, const char* pAssetFilePath )
|
||||
|
|
@ -2310,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.
|
||||
|
|
@ -2974,6 +3061,9 @@ void AssetManager::onModulePreLoad( ModuleDefinition* pModuleDefinition )
|
|||
// Add module declared assets.
|
||||
addModuleDeclaredAssets( pModuleDefinition );
|
||||
|
||||
// Load any auto-loaded asset types
|
||||
loadModuleAutoLoadAssets(pModuleDefinition);
|
||||
|
||||
// Is an asset tags manifest specified?
|
||||
if ( pModuleDefinition->getAssetTagsManifest() != StringTable->EmptyString() )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<typeAssetId, AssetDefinition*> typeDeclaredAssetsHash;
|
||||
typedef HashTable<typeAssetId, typeReferenceFilePath> typeReferencedAssetsHash;
|
||||
typedef HashTable<typeAssetId, typeAssetId> typeAssetDependsOnHash;
|
||||
typedef HashTable<typeAssetId, typeAssetId> typeAssetIsDependedOnHash;
|
||||
typedef HashMap<AssetPtrBase*, AssetPtrCallback*> typeAssetPtrRefreshHash;
|
||||
|
||||
public:
|
||||
typedef StringTableEntry typeAssetId;
|
||||
typedef StringTableEntry typeAssetName;
|
||||
typedef StringTableEntry typeReferenceFilePath;
|
||||
typedef HashMap<typeAssetId, AssetDefinition*> typeDeclaredAssetsHash;
|
||||
typedef HashTable<typeAssetId, typeReferenceFilePath> typeReferencedAssetsHash;
|
||||
typedef HashTable<typeAssetId, typeAssetId> typeAssetDependsOnHash;
|
||||
typedef HashTable<typeAssetId, typeAssetId> typeAssetIsDependedOnHash;
|
||||
typedef HashMap<AssetPtrBase*, AssetPtrCallback*> typeAssetPtrRefreshHash;
|
||||
|
||||
private:
|
||||
/// Declared assets.
|
||||
typeDeclaredAssetsHash mDeclaredAssets;
|
||||
|
||||
|
|
@ -127,6 +130,7 @@ public:
|
|||
bool removeDeclaredAssets( ModuleDefinition* pModuleDefinition );
|
||||
bool removeDeclaredAsset( const char* pAssetId );
|
||||
bool renameDeclaredAsset( const char* pAssetIdFrom, const char* pAssetIdTo );
|
||||
bool loadModuleAutoLoadAssets(ModuleDefinition* pModuleDefinition);
|
||||
StringTableEntry getAssetName( const char* pAssetId );
|
||||
StringTableEntry getAssetDescription( const char* pAssetId );
|
||||
StringTableEntry getAssetCategory( const char* pAssetId );
|
||||
|
|
@ -367,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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
// 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
|
||||
|
|
@ -20,32 +20,26 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
#ifndef _AUTOLOAD_ASSETS_H_
|
||||
#include "assets/autoloadAssets.h"
|
||||
#endif
|
||||
|
||||
#include "gui/editor/guiMenuBar.h"
|
||||
#include "platformSDL/menus/PlatformSDLPopupMenuData.h"
|
||||
#include "platform/menus/popupMenu.h"
|
||||
#ifndef _CONSOLETYPES_H_
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
|
||||
class GuiPlatformGenericMenuBar : public GuiMenuBar
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CONOBJECT(AutoloadAssets);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AutoloadAssets::initPersistFields()
|
||||
{
|
||||
typedef GuiMenuBar Parent;
|
||||
public:
|
||||
DECLARE_CONOBJECT(GuiPlatformGenericMenuBar);
|
||||
// Call Parent.
|
||||
Parent::initPersistFields();
|
||||
|
||||
virtual void menuItemSelected(Menu *menu, MenuItem *item)
|
||||
{
|
||||
AssertFatal(menu && item, "");
|
||||
|
||||
PopupMenu *popupMenu = PlatformPopupMenuData::mMenuMap[menu];
|
||||
AssertFatal(popupMenu, "");
|
||||
|
||||
popupMenu->handleSelect(item->id);
|
||||
|
||||
Parent::menuItemSelected(menu, item);
|
||||
}
|
||||
|
||||
protected:
|
||||
/// menu id / item id
|
||||
Map<CompoundKey<U32, U32>, String> mCmds;
|
||||
|
||||
};
|
||||
addField("Path", TypeString, Offset(mPath, AutoloadAssets), "");
|
||||
addField("AssetType", TypeString, Offset(mAssetType, AutoloadAssets), "");
|
||||
addField("Recurse", TypeBool, Offset(mRecurse, AutoloadAssets), "");
|
||||
}
|
||||
74
Engine/source/assets/autoloadAssets.h
Normal file
74
Engine/source/assets/autoloadAssets.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 _AUTOLOAD_ASSETS_H_
|
||||
#define _AUTOLOAD_ASSETS_H_
|
||||
|
||||
#ifndef _SIM_H_
|
||||
#include "console/sim.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SIMOBJECT_H_
|
||||
#include "console/simObject.h"
|
||||
#endif
|
||||
|
||||
#ifndef _CONSOLEOBJECT_H_
|
||||
#include "console/consoleObject.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class AutoloadAssets : public SimObject
|
||||
{
|
||||
friend class AssetManager;
|
||||
|
||||
private:
|
||||
typedef SimObject Parent;
|
||||
|
||||
StringTableEntry mPath;
|
||||
StringTableEntry mAssetType;
|
||||
bool mRecurse;
|
||||
|
||||
public:
|
||||
AutoloadAssets() :
|
||||
mPath(StringTable->EmptyString()),
|
||||
mAssetType(StringTable->EmptyString()),
|
||||
mRecurse(false)
|
||||
{}
|
||||
virtual ~AutoloadAssets() {}
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
inline void setPath(const char* pPath) { mPath = StringTable->insert(pPath); }
|
||||
inline StringTableEntry getPath(void) const { return mPath; }
|
||||
inline void setAssetType(const char* pPath) { mAssetType = StringTable->insert(pPath); }
|
||||
inline StringTableEntry getAssetType(void) const { return mAssetType; }
|
||||
inline void setRecurse(const bool recurse) { mRecurse = recurse; }
|
||||
inline bool getRecurse(void) const { return mRecurse; }
|
||||
|
||||
/// Declare Console Object.
|
||||
DECLARE_CONOBJECT(AutoloadAssets);
|
||||
};
|
||||
|
||||
#endif // _DECLARED_ASSETS_H_
|
||||
|
||||
#pragma once
|
||||
|
|
@ -496,9 +496,9 @@ class_name_expr
|
|||
|
||||
assign_op_struct
|
||||
: opPLUSPLUS
|
||||
{ $$.lineNumber = $1.lineNumber; $$.token = '+'; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
|
||||
{ $$.lineNumber = $1.lineNumber; $$.token = opPLUSPLUS; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
|
||||
| opMINUSMINUS
|
||||
{ $$.lineNumber = $1.lineNumber; $$.token = '-'; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
|
||||
{ $$.lineNumber = $1.lineNumber; $$.token = opMINUSMINUS; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
|
||||
| opPLASN expr
|
||||
{ $$.lineNumber = $1.lineNumber; $$.token = '+'; $$.expr = $2; }
|
||||
| opMIASN expr
|
||||
|
|
@ -551,6 +551,8 @@ funcall_expr
|
|||
{ $$ = FuncCallExprNode::alloc( $1.lineNumber, $3.value, $1.value, $5, false); }
|
||||
| expr '.' IDENT '(' expr_list_decl ')'
|
||||
{ $1->append($5); $$ = FuncCallExprNode::alloc( $1->dbgLineNumber, $3.value, NULL, $1, true); }
|
||||
| expr '(' expr_list_decl ')'
|
||||
{ $$ = FuncPointerCallExprNode::alloc( $1->dbgLineNumber, $1, $3); }
|
||||
;
|
||||
|
||||
assert_expr
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -56,7 +56,7 @@ struct StmtNode
|
|||
|
||||
StmtNode();
|
||||
virtual ~StmtNode() {}
|
||||
|
||||
|
||||
/// @name next Accessors
|
||||
/// @{
|
||||
|
||||
|
|
@ -99,17 +99,17 @@ struct StmtNode
|
|||
|
||||
struct BreakStmtNode : StmtNode
|
||||
{
|
||||
static BreakStmtNode *alloc( S32 lineNumber );
|
||||
static BreakStmtNode *alloc(S32 lineNumber);
|
||||
|
||||
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
DBG_STMT_TYPE(BreakStmtNode);
|
||||
};
|
||||
|
||||
struct ContinueStmtNode : StmtNode
|
||||
{
|
||||
static ContinueStmtNode *alloc( S32 lineNumber );
|
||||
|
||||
static ContinueStmtNode *alloc(S32 lineNumber);
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
DBG_STMT_TYPE(ContinueStmtNode);
|
||||
};
|
||||
|
|
@ -117,7 +117,7 @@ struct ContinueStmtNode : StmtNode
|
|||
/// A mathematical expression.
|
||||
struct ExprNode : StmtNode
|
||||
{
|
||||
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
|
||||
virtual U32 compile(CodeStream &codeStream, U32 ip, TypeReq type) = 0;
|
||||
|
|
@ -128,8 +128,8 @@ struct ReturnStmtNode : StmtNode
|
|||
{
|
||||
ExprNode *expr;
|
||||
|
||||
static ReturnStmtNode *alloc( S32 lineNumber, ExprNode *expr );
|
||||
|
||||
static ReturnStmtNode *alloc(S32 lineNumber, ExprNode *expr);
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
DBG_STMT_TYPE(ReturnStmtNode);
|
||||
};
|
||||
|
|
@ -143,10 +143,10 @@ struct IfStmtNode : StmtNode
|
|||
bool integer;
|
||||
bool propagate;
|
||||
|
||||
static IfStmtNode *alloc( S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagateThrough );
|
||||
static IfStmtNode *alloc(S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagateThrough);
|
||||
void propagateSwitchExpr(ExprNode *left, bool string);
|
||||
ExprNode *getSwitchOR(ExprNode *left, ExprNode *list, bool string);
|
||||
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
DBG_STMT_TYPE(IfStmtNode);
|
||||
};
|
||||
|
|
@ -163,8 +163,8 @@ struct LoopStmtNode : StmtNode
|
|||
U32 loopBlockStartOffset;
|
||||
bool integer;
|
||||
|
||||
static LoopStmtNode *alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *initExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop );
|
||||
|
||||
static LoopStmtNode *alloc(S32 lineNumber, ExprNode *testExpr, ExprNode *initExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop);
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
DBG_STMT_TYPE(LoopStmtNode);
|
||||
};
|
||||
|
|
@ -174,22 +174,22 @@ struct IterStmtNode : StmtNode
|
|||
{
|
||||
/// Local variable name to use for the container element.
|
||||
StringTableEntry varName;
|
||||
|
||||
|
||||
/// Expression evaluating to a SimSet object.
|
||||
ExprNode* containerExpr;
|
||||
|
||||
|
||||
/// The statement body.
|
||||
StmtNode* body;
|
||||
|
||||
|
||||
/// If true, this is a 'foreach$'.
|
||||
bool isStringIter;
|
||||
|
||||
|
||||
/// Bytecode size of body statement. Set by precompileStmt.
|
||||
U32 bodySize;
|
||||
|
||||
static IterStmtNode* alloc( S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter );
|
||||
|
||||
U32 compileStmt( CodeStream &codeStream, U32 ip );
|
||||
|
||||
static IterStmtNode* alloc(S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter);
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
};
|
||||
|
||||
/// A binary mathematical expression (ie, left op right).
|
||||
|
|
@ -202,8 +202,8 @@ struct BinaryExprNode : ExprNode
|
|||
|
||||
struct FloatBinaryExprNode : BinaryExprNode
|
||||
{
|
||||
static FloatBinaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right );
|
||||
|
||||
static FloatBinaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(FloatBinaryExprNode);
|
||||
|
|
@ -215,8 +215,8 @@ struct ConditionalExprNode : ExprNode
|
|||
ExprNode *trueExpr;
|
||||
ExprNode *falseExpr;
|
||||
bool integer;
|
||||
static ConditionalExprNode *alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr );
|
||||
|
||||
static ConditionalExprNode *alloc(S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr);
|
||||
|
||||
virtual U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
virtual TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(ConditionalExprNode);
|
||||
|
|
@ -227,10 +227,10 @@ struct IntBinaryExprNode : BinaryExprNode
|
|||
TypeReq subType;
|
||||
U32 operand;
|
||||
|
||||
static IntBinaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right );
|
||||
static IntBinaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right);
|
||||
|
||||
void getSubTypeOperand();
|
||||
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(IntBinaryExprNode);
|
||||
|
|
@ -239,8 +239,8 @@ struct IntBinaryExprNode : BinaryExprNode
|
|||
struct StreqExprNode : BinaryExprNode
|
||||
{
|
||||
bool eq;
|
||||
static StreqExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right, bool eq );
|
||||
|
||||
static StreqExprNode *alloc(S32 lineNumber, ExprNode *left, ExprNode *right, bool eq);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(StreqExprNode);
|
||||
|
|
@ -249,8 +249,8 @@ struct StreqExprNode : BinaryExprNode
|
|||
struct StrcatExprNode : BinaryExprNode
|
||||
{
|
||||
S32 appendChar;
|
||||
static StrcatExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar );
|
||||
|
||||
static StrcatExprNode *alloc(S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(StrcatExprNode);
|
||||
|
|
@ -258,9 +258,9 @@ struct StrcatExprNode : BinaryExprNode
|
|||
|
||||
struct CommaCatExprNode : BinaryExprNode
|
||||
{
|
||||
static CommaCatExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right );
|
||||
static CommaCatExprNode *alloc(S32 lineNumber, ExprNode *left, ExprNode *right);
|
||||
|
||||
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(CommaCatExprNode);
|
||||
|
|
@ -272,8 +272,8 @@ struct IntUnaryExprNode : ExprNode
|
|||
ExprNode *expr;
|
||||
bool integer;
|
||||
|
||||
static IntUnaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *expr );
|
||||
|
||||
static IntUnaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *expr);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(IntUnaryExprNode);
|
||||
|
|
@ -284,8 +284,8 @@ struct FloatUnaryExprNode : ExprNode
|
|||
S32 op;
|
||||
ExprNode *expr;
|
||||
|
||||
static FloatUnaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *expr );
|
||||
|
||||
static FloatUnaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *expr);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(FloatUnaryExprNode);
|
||||
|
|
@ -296,8 +296,8 @@ struct VarNode : ExprNode
|
|||
StringTableEntry varName;
|
||||
ExprNode *arrayIndex;
|
||||
|
||||
static VarNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex );
|
||||
|
||||
static VarNode *alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(VarNode);
|
||||
|
|
@ -308,8 +308,8 @@ struct IntNode : ExprNode
|
|||
S32 value;
|
||||
U32 index; // if it's converted to float/string
|
||||
|
||||
static IntNode *alloc( S32 lineNumber, S32 value );
|
||||
|
||||
static IntNode *alloc(S32 lineNumber, S32 value);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(IntNode);
|
||||
|
|
@ -320,8 +320,8 @@ struct FloatNode : ExprNode
|
|||
F64 value;
|
||||
U32 index;
|
||||
|
||||
static FloatNode *alloc( S32 lineNumber, F64 value );
|
||||
|
||||
static FloatNode *alloc(S32 lineNumber, F64 value);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(FloatNode);
|
||||
|
|
@ -335,8 +335,8 @@ struct StrConstNode : ExprNode
|
|||
bool tag;
|
||||
bool doc; // Specifies that this string is a documentation block.
|
||||
|
||||
static StrConstNode *alloc( S32 lineNumber, char *str, bool tag, bool doc = false );
|
||||
|
||||
static StrConstNode *alloc(S32 lineNumber, char *str, bool tag, bool doc = false);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(StrConstNode);
|
||||
|
|
@ -348,8 +348,8 @@ struct ConstantNode : ExprNode
|
|||
F64 fVal;
|
||||
U32 index;
|
||||
|
||||
static ConstantNode *alloc( S32 lineNumber, StringTableEntry value );
|
||||
|
||||
static ConstantNode *alloc(S32 lineNumber, StringTableEntry value);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(ConstantNode);
|
||||
|
|
@ -362,8 +362,8 @@ struct AssignExprNode : ExprNode
|
|||
ExprNode *arrayIndex;
|
||||
TypeReq subType;
|
||||
|
||||
static AssignExprNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr );
|
||||
|
||||
static AssignExprNode *alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(AssignExprNode);
|
||||
|
|
@ -386,8 +386,8 @@ struct AssignOpExprNode : ExprNode
|
|||
U32 operand;
|
||||
TypeReq subType;
|
||||
|
||||
static AssignOpExprNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op );
|
||||
|
||||
static AssignOpExprNode *alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(AssignOpExprNode);
|
||||
|
|
@ -399,8 +399,8 @@ struct TTagSetStmtNode : StmtNode
|
|||
ExprNode *valueExpr;
|
||||
ExprNode *stringExpr;
|
||||
|
||||
static TTagSetStmtNode *alloc( S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr );
|
||||
|
||||
static TTagSetStmtNode *alloc(S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr);
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
DBG_STMT_TYPE(TTagSetStmtNode);
|
||||
};
|
||||
|
|
@ -409,8 +409,8 @@ struct TTagDerefNode : ExprNode
|
|||
{
|
||||
ExprNode *expr;
|
||||
|
||||
static TTagDerefNode *alloc( S32 lineNumber, ExprNode *expr );
|
||||
|
||||
static TTagDerefNode *alloc(S32 lineNumber, ExprNode *expr);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(TTagDerefNode);
|
||||
|
|
@ -420,8 +420,8 @@ struct TTagExprNode : ExprNode
|
|||
{
|
||||
StringTableEntry tag;
|
||||
|
||||
static TTagExprNode *alloc( S32 lineNumber, StringTableEntry tag );
|
||||
|
||||
static TTagExprNode *alloc(S32 lineNumber, StringTableEntry tag);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(TTagExprNode);
|
||||
|
|
@ -439,21 +439,33 @@ struct FuncCallExprNode : ExprNode
|
|||
ParentCall
|
||||
};
|
||||
|
||||
static FuncCallExprNode *alloc( S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot );
|
||||
|
||||
static FuncCallExprNode *alloc(S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(FuncCallExprNode);
|
||||
};
|
||||
|
||||
struct FuncPointerCallExprNode : ExprNode
|
||||
{
|
||||
ExprNode *funcPointer;
|
||||
ExprNode *args;
|
||||
|
||||
static FuncPointerCallExprNode *alloc(S32 lineNumber, ExprNode *stmt, ExprNode *args);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(FuncPointerCallExprNode);
|
||||
};
|
||||
|
||||
struct AssertCallExprNode : ExprNode
|
||||
{
|
||||
ExprNode *testExpr;
|
||||
const char *message;
|
||||
U32 messageIndex;
|
||||
|
||||
static AssertCallExprNode *alloc( S32 lineNumber, ExprNode *testExpr, const char *message );
|
||||
|
||||
static AssertCallExprNode *alloc(S32 lineNumber, ExprNode *testExpr, const char *message);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(AssertCallExprNode);
|
||||
|
|
@ -472,8 +484,8 @@ struct SlotAccessNode : ExprNode
|
|||
ExprNode *objectExpr, *arrayExpr;
|
||||
StringTableEntry slotName;
|
||||
|
||||
static SlotAccessNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName );
|
||||
|
||||
static SlotAccessNode *alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(SlotAccessNode);
|
||||
|
|
@ -492,8 +504,8 @@ struct InternalSlotAccessNode : ExprNode
|
|||
ExprNode *objectExpr, *slotExpr;
|
||||
bool recurse;
|
||||
|
||||
static InternalSlotAccessNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse );
|
||||
|
||||
static InternalSlotAccessNode *alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(InternalSlotAccessNode);
|
||||
|
|
@ -506,8 +518,8 @@ struct SlotAssignNode : ExprNode
|
|||
ExprNode *valueExpr;
|
||||
U32 typeID;
|
||||
|
||||
static SlotAssignNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID = -1 );
|
||||
|
||||
static SlotAssignNode *alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID = -1);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(SlotAssignNode);
|
||||
|
|
@ -522,8 +534,8 @@ struct SlotAssignOpNode : ExprNode
|
|||
U32 operand;
|
||||
TypeReq subType;
|
||||
|
||||
static SlotAssignOpNode *alloc( S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr );
|
||||
|
||||
static SlotAssignOpNode *alloc(S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr);
|
||||
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
TypeReq getPreferredType();
|
||||
DBG_STMT_TYPE(SlotAssignOpNode);
|
||||
|
|
@ -542,8 +554,8 @@ struct ObjectDeclNode : ExprNode
|
|||
bool isClassNameInternal;
|
||||
bool isSingleton;
|
||||
|
||||
static ObjectDeclNode *alloc( S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton );
|
||||
|
||||
static ObjectDeclNode *alloc(S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton);
|
||||
|
||||
U32 precompileSubObject(bool);
|
||||
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
|
||||
U32 compileSubObject(CodeStream &codeStream, U32 ip, bool);
|
||||
|
|
@ -567,8 +579,8 @@ struct FunctionDeclStmtNode : StmtNode
|
|||
U32 endOffset;
|
||||
U32 argc;
|
||||
|
||||
static FunctionDeclStmtNode *alloc( S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts );
|
||||
|
||||
static FunctionDeclStmtNode *alloc(S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts);
|
||||
|
||||
U32 compileStmt(CodeStream &codeStream, U32 ip);
|
||||
void setPackage(StringTableEntry packageName);
|
||||
DBG_STMT_TYPE(FunctionDeclStmtNode);
|
||||
|
|
|
|||
|
|
@ -38,25 +38,25 @@ using namespace Compiler;
|
|||
|
||||
//------------------------------------------------------------
|
||||
|
||||
BreakStmtNode *BreakStmtNode::alloc( S32 lineNumber )
|
||||
BreakStmtNode *BreakStmtNode::alloc(S32 lineNumber)
|
||||
{
|
||||
BreakStmtNode *ret = (BreakStmtNode *) consoleAlloc(sizeof(BreakStmtNode));
|
||||
BreakStmtNode *ret = (BreakStmtNode *)consoleAlloc(sizeof(BreakStmtNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ContinueStmtNode *ContinueStmtNode::alloc( S32 lineNumber )
|
||||
ContinueStmtNode *ContinueStmtNode::alloc(S32 lineNumber)
|
||||
{
|
||||
ContinueStmtNode *ret = (ContinueStmtNode *) consoleAlloc(sizeof(ContinueStmtNode));
|
||||
ContinueStmtNode *ret = (ContinueStmtNode *)consoleAlloc(sizeof(ContinueStmtNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ReturnStmtNode *ReturnStmtNode::alloc( S32 lineNumber, ExprNode *expr)
|
||||
ReturnStmtNode *ReturnStmtNode::alloc(S32 lineNumber, ExprNode *expr)
|
||||
{
|
||||
ReturnStmtNode *ret = (ReturnStmtNode *) consoleAlloc(sizeof(ReturnStmtNode));
|
||||
ReturnStmtNode *ret = (ReturnStmtNode *)consoleAlloc(sizeof(ReturnStmtNode));
|
||||
constructInPlace(ret);
|
||||
ret->expr = expr;
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
|
|
@ -64,9 +64,9 @@ ReturnStmtNode *ReturnStmtNode::alloc( S32 lineNumber, ExprNode *expr)
|
|||
return ret;
|
||||
}
|
||||
|
||||
IfStmtNode *IfStmtNode::alloc( S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagate )
|
||||
IfStmtNode *IfStmtNode::alloc(S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagate)
|
||||
{
|
||||
IfStmtNode *ret = (IfStmtNode *) consoleAlloc(sizeof(IfStmtNode));
|
||||
IfStmtNode *ret = (IfStmtNode *)consoleAlloc(sizeof(IfStmtNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
|
||||
|
|
@ -78,9 +78,9 @@ IfStmtNode *IfStmtNode::alloc( S32 lineNumber, ExprNode *testExpr, StmtNode *ifB
|
|||
return ret;
|
||||
}
|
||||
|
||||
LoopStmtNode *LoopStmtNode::alloc( S32 lineNumber, ExprNode *initExpr, ExprNode *testExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop )
|
||||
LoopStmtNode *LoopStmtNode::alloc(S32 lineNumber, ExprNode *initExpr, ExprNode *testExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop)
|
||||
{
|
||||
LoopStmtNode *ret = (LoopStmtNode *) consoleAlloc(sizeof(LoopStmtNode));
|
||||
LoopStmtNode *ret = (LoopStmtNode *)consoleAlloc(sizeof(LoopStmtNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->testExpr = testExpr;
|
||||
|
|
@ -92,28 +92,28 @@ LoopStmtNode *LoopStmtNode::alloc( S32 lineNumber, ExprNode *initExpr, ExprNode
|
|||
// Deal with setting some dummy constant nodes if we weren't provided with
|
||||
// info... This allows us to play nice with missing parts of for(;;) for
|
||||
// instance.
|
||||
if(!ret->testExpr) ret->testExpr = IntNode::alloc( lineNumber, 1 );
|
||||
if (!ret->testExpr) ret->testExpr = IntNode::alloc(lineNumber, 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
IterStmtNode* IterStmtNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter )
|
||||
IterStmtNode* IterStmtNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter)
|
||||
{
|
||||
IterStmtNode* ret = ( IterStmtNode* ) consoleAlloc( sizeof( IterStmtNode ) );
|
||||
constructInPlace( ret );
|
||||
|
||||
IterStmtNode* ret = (IterStmtNode*)consoleAlloc(sizeof(IterStmtNode));
|
||||
constructInPlace(ret);
|
||||
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->varName = varName;
|
||||
ret->containerExpr = containerExpr;
|
||||
ret->body = body;
|
||||
ret->isStringIter = isStringIter;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
FloatBinaryExprNode *FloatBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right )
|
||||
FloatBinaryExprNode *FloatBinaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right)
|
||||
{
|
||||
FloatBinaryExprNode *ret = (FloatBinaryExprNode *) consoleAlloc(sizeof(FloatBinaryExprNode));
|
||||
FloatBinaryExprNode *ret = (FloatBinaryExprNode *)consoleAlloc(sizeof(FloatBinaryExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
|
||||
|
|
@ -124,9 +124,9 @@ FloatBinaryExprNode *FloatBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNod
|
|||
return ret;
|
||||
}
|
||||
|
||||
IntBinaryExprNode *IntBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right )
|
||||
IntBinaryExprNode *IntBinaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right)
|
||||
{
|
||||
IntBinaryExprNode *ret = (IntBinaryExprNode *) consoleAlloc(sizeof(IntBinaryExprNode));
|
||||
IntBinaryExprNode *ret = (IntBinaryExprNode *)consoleAlloc(sizeof(IntBinaryExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
|
||||
|
|
@ -137,9 +137,9 @@ IntBinaryExprNode *IntBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *l
|
|||
return ret;
|
||||
}
|
||||
|
||||
StreqExprNode *StreqExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right, bool eq )
|
||||
StreqExprNode *StreqExprNode::alloc(S32 lineNumber, ExprNode *left, ExprNode *right, bool eq)
|
||||
{
|
||||
StreqExprNode *ret = (StreqExprNode *) consoleAlloc(sizeof(StreqExprNode));
|
||||
StreqExprNode *ret = (StreqExprNode *)consoleAlloc(sizeof(StreqExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->left = left;
|
||||
|
|
@ -149,9 +149,9 @@ StreqExprNode *StreqExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *r
|
|||
return ret;
|
||||
}
|
||||
|
||||
StrcatExprNode *StrcatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar )
|
||||
StrcatExprNode *StrcatExprNode::alloc(S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar)
|
||||
{
|
||||
StrcatExprNode *ret = (StrcatExprNode *) consoleAlloc(sizeof(StrcatExprNode));
|
||||
StrcatExprNode *ret = (StrcatExprNode *)consoleAlloc(sizeof(StrcatExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->left = left;
|
||||
|
|
@ -161,9 +161,9 @@ StrcatExprNode *StrcatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode
|
|||
return ret;
|
||||
}
|
||||
|
||||
CommaCatExprNode *CommaCatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right )
|
||||
CommaCatExprNode *CommaCatExprNode::alloc(S32 lineNumber, ExprNode *left, ExprNode *right)
|
||||
{
|
||||
CommaCatExprNode *ret = (CommaCatExprNode *) consoleAlloc(sizeof(CommaCatExprNode));
|
||||
CommaCatExprNode *ret = (CommaCatExprNode *)consoleAlloc(sizeof(CommaCatExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->left = left;
|
||||
|
|
@ -172,9 +172,9 @@ CommaCatExprNode *CommaCatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprN
|
|||
return ret;
|
||||
}
|
||||
|
||||
IntUnaryExprNode *IntUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *expr )
|
||||
IntUnaryExprNode *IntUnaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *expr)
|
||||
{
|
||||
IntUnaryExprNode *ret = (IntUnaryExprNode *) consoleAlloc(sizeof(IntUnaryExprNode));
|
||||
IntUnaryExprNode *ret = (IntUnaryExprNode *)consoleAlloc(sizeof(IntUnaryExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->op = op;
|
||||
|
|
@ -182,9 +182,9 @@ IntUnaryExprNode *IntUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *exp
|
|||
return ret;
|
||||
}
|
||||
|
||||
FloatUnaryExprNode *FloatUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *expr )
|
||||
FloatUnaryExprNode *FloatUnaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *expr)
|
||||
{
|
||||
FloatUnaryExprNode *ret = (FloatUnaryExprNode *) consoleAlloc(sizeof(FloatUnaryExprNode));
|
||||
FloatUnaryExprNode *ret = (FloatUnaryExprNode *)consoleAlloc(sizeof(FloatUnaryExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->op = op;
|
||||
|
|
@ -192,9 +192,9 @@ FloatUnaryExprNode *FloatUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode
|
|||
return ret;
|
||||
}
|
||||
|
||||
VarNode *VarNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex )
|
||||
VarNode *VarNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex)
|
||||
{
|
||||
VarNode *ret = (VarNode *) consoleAlloc(sizeof(VarNode));
|
||||
VarNode *ret = (VarNode *)consoleAlloc(sizeof(VarNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->varName = varName;
|
||||
|
|
@ -202,18 +202,18 @@ VarNode *VarNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arr
|
|||
return ret;
|
||||
}
|
||||
|
||||
IntNode *IntNode::alloc( S32 lineNumber, S32 value )
|
||||
IntNode *IntNode::alloc(S32 lineNumber, S32 value)
|
||||
{
|
||||
IntNode *ret = (IntNode *) consoleAlloc(sizeof(IntNode));
|
||||
IntNode *ret = (IntNode *)consoleAlloc(sizeof(IntNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->value = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ConditionalExprNode *ConditionalExprNode::alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr )
|
||||
ConditionalExprNode *ConditionalExprNode::alloc(S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr)
|
||||
{
|
||||
ConditionalExprNode *ret = (ConditionalExprNode *) consoleAlloc(sizeof(ConditionalExprNode));
|
||||
ConditionalExprNode *ret = (ConditionalExprNode *)consoleAlloc(sizeof(ConditionalExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->testExpr = testExpr;
|
||||
|
|
@ -223,22 +223,22 @@ ConditionalExprNode *ConditionalExprNode::alloc( S32 lineNumber, ExprNode *testE
|
|||
return ret;
|
||||
}
|
||||
|
||||
FloatNode *FloatNode::alloc( S32 lineNumber, F64 value )
|
||||
FloatNode *FloatNode::alloc(S32 lineNumber, F64 value)
|
||||
{
|
||||
FloatNode *ret = (FloatNode *) consoleAlloc(sizeof(FloatNode));
|
||||
FloatNode *ret = (FloatNode *)consoleAlloc(sizeof(FloatNode));
|
||||
constructInPlace(ret);
|
||||
|
||||
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->value = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
StrConstNode *StrConstNode::alloc( S32 lineNumber, char *str, bool tag, bool doc )
|
||||
StrConstNode *StrConstNode::alloc(S32 lineNumber, char *str, bool tag, bool doc)
|
||||
{
|
||||
StrConstNode *ret = (StrConstNode *) consoleAlloc(sizeof(StrConstNode));
|
||||
StrConstNode *ret = (StrConstNode *)consoleAlloc(sizeof(StrConstNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->str = (char *) consoleAlloc(dStrlen(str) + 1);
|
||||
ret->str = (char *)consoleAlloc(dStrlen(str) + 1);
|
||||
ret->tag = tag;
|
||||
ret->doc = doc;
|
||||
dStrcpy(ret->str, str);
|
||||
|
|
@ -246,18 +246,18 @@ StrConstNode *StrConstNode::alloc( S32 lineNumber, char *str, bool tag, bool doc
|
|||
return ret;
|
||||
}
|
||||
|
||||
ConstantNode *ConstantNode::alloc( S32 lineNumber, StringTableEntry value )
|
||||
ConstantNode *ConstantNode::alloc(S32 lineNumber, StringTableEntry value)
|
||||
{
|
||||
ConstantNode *ret = (ConstantNode *) consoleAlloc(sizeof(ConstantNode));
|
||||
ConstantNode *ret = (ConstantNode *)consoleAlloc(sizeof(ConstantNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->value = value;
|
||||
return ret;
|
||||
}
|
||||
|
||||
AssignExprNode *AssignExprNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr )
|
||||
AssignExprNode *AssignExprNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr)
|
||||
{
|
||||
AssignExprNode *ret = (AssignExprNode *) consoleAlloc(sizeof(AssignExprNode));
|
||||
AssignExprNode *ret = (AssignExprNode *)consoleAlloc(sizeof(AssignExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->varName = varName;
|
||||
|
|
@ -267,9 +267,9 @@ AssignExprNode *AssignExprNode::alloc( S32 lineNumber, StringTableEntry varName,
|
|||
return ret;
|
||||
}
|
||||
|
||||
AssignOpExprNode *AssignOpExprNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op )
|
||||
AssignOpExprNode *AssignOpExprNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op)
|
||||
{
|
||||
AssignOpExprNode *ret = (AssignOpExprNode *) consoleAlloc(sizeof(AssignOpExprNode));
|
||||
AssignOpExprNode *ret = (AssignOpExprNode *)consoleAlloc(sizeof(AssignOpExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->varName = varName;
|
||||
|
|
@ -279,9 +279,9 @@ AssignOpExprNode *AssignOpExprNode::alloc( S32 lineNumber, StringTableEntry varN
|
|||
return ret;
|
||||
}
|
||||
|
||||
TTagSetStmtNode *TTagSetStmtNode::alloc( S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr )
|
||||
TTagSetStmtNode *TTagSetStmtNode::alloc(S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr)
|
||||
{
|
||||
TTagSetStmtNode *ret = (TTagSetStmtNode *) consoleAlloc(sizeof(TTagSetStmtNode));
|
||||
TTagSetStmtNode *ret = (TTagSetStmtNode *)consoleAlloc(sizeof(TTagSetStmtNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->tag = tag;
|
||||
|
|
@ -290,37 +290,37 @@ TTagSetStmtNode *TTagSetStmtNode::alloc( S32 lineNumber, StringTableEntry tag, E
|
|||
return ret;
|
||||
}
|
||||
|
||||
TTagDerefNode *TTagDerefNode::alloc( S32 lineNumber, ExprNode *expr )
|
||||
TTagDerefNode *TTagDerefNode::alloc(S32 lineNumber, ExprNode *expr)
|
||||
{
|
||||
TTagDerefNode *ret = (TTagDerefNode *) consoleAlloc(sizeof(TTagDerefNode));
|
||||
TTagDerefNode *ret = (TTagDerefNode *)consoleAlloc(sizeof(TTagDerefNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->expr = expr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
TTagExprNode *TTagExprNode::alloc( S32 lineNumber, StringTableEntry tag )
|
||||
TTagExprNode *TTagExprNode::alloc(S32 lineNumber, StringTableEntry tag)
|
||||
{
|
||||
TTagExprNode *ret = (TTagExprNode *) consoleAlloc(sizeof(TTagExprNode));
|
||||
TTagExprNode *ret = (TTagExprNode *)consoleAlloc(sizeof(TTagExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->tag = tag;
|
||||
return ret;
|
||||
}
|
||||
|
||||
FuncCallExprNode *FuncCallExprNode::alloc( S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot )
|
||||
FuncCallExprNode *FuncCallExprNode::alloc(S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot)
|
||||
{
|
||||
FuncCallExprNode *ret = (FuncCallExprNode *) consoleAlloc(sizeof(FuncCallExprNode));
|
||||
FuncCallExprNode *ret = (FuncCallExprNode *)consoleAlloc(sizeof(FuncCallExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->funcName = funcName;
|
||||
ret->nameSpace = nameSpace;
|
||||
ret->args = args;
|
||||
if(dot)
|
||||
if (dot)
|
||||
ret->callType = MethodCall;
|
||||
else
|
||||
{
|
||||
if(nameSpace && !dStricmp(nameSpace, "Parent"))
|
||||
if (nameSpace && !dStricmp(nameSpace, "Parent"))
|
||||
ret->callType = ParentCall;
|
||||
else
|
||||
ret->callType = FunctionCall;
|
||||
|
|
@ -328,27 +328,37 @@ FuncCallExprNode *FuncCallExprNode::alloc( S32 lineNumber, StringTableEntry func
|
|||
return ret;
|
||||
}
|
||||
|
||||
AssertCallExprNode *AssertCallExprNode::alloc( S32 lineNumber, ExprNode *testExpr, const char *message )
|
||||
FuncPointerCallExprNode *FuncPointerCallExprNode::alloc(S32 lineNumber, ExprNode *funcPointer, ExprNode *args)
|
||||
{
|
||||
#ifdef TORQUE_ENABLE_SCRIPTASSERTS
|
||||
|
||||
AssertCallExprNode *ret = (AssertCallExprNode *) consoleAlloc(sizeof(FuncCallExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->testExpr = testExpr;
|
||||
ret->message = message ? message : "TorqueScript assert!";
|
||||
return ret;
|
||||
|
||||
#else
|
||||
|
||||
return NULL;
|
||||
|
||||
#endif
|
||||
FuncPointerCallExprNode *ret = (FuncPointerCallExprNode *)consoleAlloc(sizeof(FuncPointerCallExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->funcPointer = funcPointer;
|
||||
ret->args = args;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SlotAccessNode *SlotAccessNode::alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName )
|
||||
AssertCallExprNode *AssertCallExprNode::alloc(S32 lineNumber, ExprNode *testExpr, const char *message)
|
||||
{
|
||||
SlotAccessNode *ret = (SlotAccessNode *) consoleAlloc(sizeof(SlotAccessNode));
|
||||
#ifdef TORQUE_ENABLE_SCRIPTASSERTS
|
||||
|
||||
AssertCallExprNode *ret = (AssertCallExprNode *)consoleAlloc(sizeof(FuncCallExprNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->testExpr = testExpr;
|
||||
ret->message = message ? message : "TorqueScript assert!";
|
||||
return ret;
|
||||
|
||||
#else
|
||||
|
||||
return NULL;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
SlotAccessNode *SlotAccessNode::alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName)
|
||||
{
|
||||
SlotAccessNode *ret = (SlotAccessNode *)consoleAlloc(sizeof(SlotAccessNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->objectExpr = objectExpr;
|
||||
|
|
@ -357,9 +367,9 @@ SlotAccessNode *SlotAccessNode::alloc( S32 lineNumber, ExprNode *objectExpr, Exp
|
|||
return ret;
|
||||
}
|
||||
|
||||
InternalSlotAccessNode *InternalSlotAccessNode::alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse )
|
||||
InternalSlotAccessNode *InternalSlotAccessNode::alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse)
|
||||
{
|
||||
InternalSlotAccessNode *ret = (InternalSlotAccessNode *) consoleAlloc(sizeof(InternalSlotAccessNode));
|
||||
InternalSlotAccessNode *ret = (InternalSlotAccessNode *)consoleAlloc(sizeof(InternalSlotAccessNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->objectExpr = objectExpr;
|
||||
|
|
@ -368,9 +378,9 @@ InternalSlotAccessNode *InternalSlotAccessNode::alloc( S32 lineNumber, ExprNode
|
|||
return ret;
|
||||
}
|
||||
|
||||
SlotAssignNode *SlotAssignNode::alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID /* = -1 */ )
|
||||
SlotAssignNode *SlotAssignNode::alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID /* = -1 */)
|
||||
{
|
||||
SlotAssignNode *ret = (SlotAssignNode *) consoleAlloc(sizeof(SlotAssignNode));
|
||||
SlotAssignNode *ret = (SlotAssignNode *)consoleAlloc(sizeof(SlotAssignNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->objectExpr = objectExpr;
|
||||
|
|
@ -381,9 +391,9 @@ SlotAssignNode *SlotAssignNode::alloc( S32 lineNumber, ExprNode *objectExpr, Exp
|
|||
return ret;
|
||||
}
|
||||
|
||||
SlotAssignOpNode *SlotAssignOpNode::alloc( S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr )
|
||||
SlotAssignOpNode *SlotAssignOpNode::alloc(S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr)
|
||||
{
|
||||
SlotAssignOpNode *ret = (SlotAssignOpNode *) consoleAlloc(sizeof(SlotAssignOpNode));
|
||||
SlotAssignOpNode *ret = (SlotAssignOpNode *)consoleAlloc(sizeof(SlotAssignOpNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->objectExpr = objectExpr;
|
||||
|
|
@ -394,9 +404,9 @@ SlotAssignOpNode *SlotAssignOpNode::alloc( S32 lineNumber, ExprNode *objectExpr,
|
|||
return ret;
|
||||
}
|
||||
|
||||
ObjectDeclNode *ObjectDeclNode::alloc( S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton )
|
||||
ObjectDeclNode *ObjectDeclNode::alloc(S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton)
|
||||
{
|
||||
ObjectDeclNode *ret = (ObjectDeclNode *) consoleAlloc(sizeof(ObjectDeclNode));
|
||||
ObjectDeclNode *ret = (ObjectDeclNode *)consoleAlloc(sizeof(ObjectDeclNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->classNameExpr = classNameExpr;
|
||||
|
|
@ -408,16 +418,16 @@ ObjectDeclNode *ObjectDeclNode::alloc( S32 lineNumber, ExprNode *classNameExpr,
|
|||
ret->isClassNameInternal = classNameInternal;
|
||||
ret->isSingleton = isSingleton;
|
||||
ret->failOffset = 0;
|
||||
if(parentObject)
|
||||
if (parentObject)
|
||||
ret->parentObject = parentObject;
|
||||
else
|
||||
ret->parentObject = StringTable->EmptyString();
|
||||
return ret;
|
||||
}
|
||||
|
||||
FunctionDeclStmtNode *FunctionDeclStmtNode::alloc( S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts )
|
||||
FunctionDeclStmtNode *FunctionDeclStmtNode::alloc(S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts)
|
||||
{
|
||||
FunctionDeclStmtNode *ret = (FunctionDeclStmtNode *) consoleAlloc(sizeof(FunctionDeclStmtNode));
|
||||
FunctionDeclStmtNode *ret = (FunctionDeclStmtNode *)consoleAlloc(sizeof(FunctionDeclStmtNode));
|
||||
constructInPlace(ret);
|
||||
ret->dbgLineNumber = lineNumber;
|
||||
ret->fnName = fnName;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -15,78 +15,78 @@ typedef union {
|
|||
AssignDecl asn;
|
||||
IfStmtNode* ifnode;
|
||||
} YYSTYPE;
|
||||
#define rwDEFINE 258
|
||||
#define rwENDDEF 259
|
||||
#define rwDECLARE 260
|
||||
#define rwDECLARESINGLETON 261
|
||||
#define rwBREAK 262
|
||||
#define rwELSE 263
|
||||
#define rwCONTINUE 264
|
||||
#define rwGLOBAL 265
|
||||
#define rwIF 266
|
||||
#define rwNIL 267
|
||||
#define rwRETURN 268
|
||||
#define rwWHILE 269
|
||||
#define rwDO 270
|
||||
#define rwENDIF 271
|
||||
#define rwENDWHILE 272
|
||||
#define rwENDFOR 273
|
||||
#define rwDEFAULT 274
|
||||
#define rwFOR 275
|
||||
#define rwFOREACH 276
|
||||
#define rwFOREACHSTR 277
|
||||
#define rwIN 278
|
||||
#define rwDATABLOCK 279
|
||||
#define rwSWITCH 280
|
||||
#define rwCASE 281
|
||||
#define rwSWITCHSTR 282
|
||||
#define rwCASEOR 283
|
||||
#define rwPACKAGE 284
|
||||
#define rwNAMESPACE 285
|
||||
#define rwCLASS 286
|
||||
#define rwASSERT 287
|
||||
#define ILLEGAL_TOKEN 288
|
||||
#define CHRCONST 289
|
||||
#define INTCONST 290
|
||||
#define TTAG 291
|
||||
#define VAR 292
|
||||
#define IDENT 293
|
||||
#define TYPEIDENT 294
|
||||
#define DOCBLOCK 295
|
||||
#define STRATOM 296
|
||||
#define TAGATOM 297
|
||||
#define FLTCONST 298
|
||||
#define opINTNAME 299
|
||||
#define opINTNAMER 300
|
||||
#define opMINUSMINUS 301
|
||||
#define opPLUSPLUS 302
|
||||
#define STMT_SEP 303
|
||||
#define opSHL 304
|
||||
#define opSHR 305
|
||||
#define opPLASN 306
|
||||
#define opMIASN 307
|
||||
#define opMLASN 308
|
||||
#define opDVASN 309
|
||||
#define opMODASN 310
|
||||
#define opANDASN 311
|
||||
#define opXORASN 312
|
||||
#define opORASN 313
|
||||
#define opSLASN 314
|
||||
#define opSRASN 315
|
||||
#define opCAT 316
|
||||
#define opEQ 317
|
||||
#define opNE 318
|
||||
#define opGE 319
|
||||
#define opLE 320
|
||||
#define opAND 321
|
||||
#define opOR 322
|
||||
#define opSTREQ 323
|
||||
#define opCOLONCOLON 324
|
||||
#define opMDASN 325
|
||||
#define opNDASN 326
|
||||
#define opNTASN 327
|
||||
#define opSTRNE 328
|
||||
#define UNARY 329
|
||||
#define rwDEFINE 258
|
||||
#define rwENDDEF 259
|
||||
#define rwDECLARE 260
|
||||
#define rwDECLARESINGLETON 261
|
||||
#define rwBREAK 262
|
||||
#define rwELSE 263
|
||||
#define rwCONTINUE 264
|
||||
#define rwGLOBAL 265
|
||||
#define rwIF 266
|
||||
#define rwNIL 267
|
||||
#define rwRETURN 268
|
||||
#define rwWHILE 269
|
||||
#define rwDO 270
|
||||
#define rwENDIF 271
|
||||
#define rwENDWHILE 272
|
||||
#define rwENDFOR 273
|
||||
#define rwDEFAULT 274
|
||||
#define rwFOR 275
|
||||
#define rwFOREACH 276
|
||||
#define rwFOREACHSTR 277
|
||||
#define rwIN 278
|
||||
#define rwDATABLOCK 279
|
||||
#define rwSWITCH 280
|
||||
#define rwCASE 281
|
||||
#define rwSWITCHSTR 282
|
||||
#define rwCASEOR 283
|
||||
#define rwPACKAGE 284
|
||||
#define rwNAMESPACE 285
|
||||
#define rwCLASS 286
|
||||
#define rwASSERT 287
|
||||
#define ILLEGAL_TOKEN 288
|
||||
#define CHRCONST 289
|
||||
#define INTCONST 290
|
||||
#define TTAG 291
|
||||
#define VAR 292
|
||||
#define IDENT 293
|
||||
#define TYPEIDENT 294
|
||||
#define DOCBLOCK 295
|
||||
#define STRATOM 296
|
||||
#define TAGATOM 297
|
||||
#define FLTCONST 298
|
||||
#define opINTNAME 299
|
||||
#define opINTNAMER 300
|
||||
#define opMINUSMINUS 301
|
||||
#define opPLUSPLUS 302
|
||||
#define STMT_SEP 303
|
||||
#define opSHL 304
|
||||
#define opSHR 305
|
||||
#define opPLASN 306
|
||||
#define opMIASN 307
|
||||
#define opMLASN 308
|
||||
#define opDVASN 309
|
||||
#define opMODASN 310
|
||||
#define opANDASN 311
|
||||
#define opXORASN 312
|
||||
#define opORASN 313
|
||||
#define opSLASN 314
|
||||
#define opSRASN 315
|
||||
#define opCAT 316
|
||||
#define opEQ 317
|
||||
#define opNE 318
|
||||
#define opGE 319
|
||||
#define opLE 320
|
||||
#define opAND 321
|
||||
#define opOR 322
|
||||
#define opSTREQ 323
|
||||
#define opCOLONCOLON 324
|
||||
#define opMDASN 325
|
||||
#define opNDASN 326
|
||||
#define opNTASN 327
|
||||
#define opSTRNE 328
|
||||
#define UNARY 329
|
||||
|
||||
|
||||
extern YYSTYPE CMDlval;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -35,10 +35,11 @@ class ConsoleValueRef;
|
|||
/// This class represents a block of code, usually mapped directly to a file.
|
||||
class CodeBlock
|
||||
{
|
||||
friend class CodeInterpreter;
|
||||
private:
|
||||
static CodeBlock* smCodeBlockList;
|
||||
static CodeBlock* smCurrentCodeBlock;
|
||||
|
||||
|
||||
public:
|
||||
static bool smInFunction;
|
||||
static Compiler::ConsoleParser * smCurrentParser;
|
||||
|
|
@ -89,7 +90,7 @@ public:
|
|||
void calcBreakList();
|
||||
void clearAllBreaks();
|
||||
void setAllBreaks();
|
||||
void dumpInstructions( U32 startIp = 0, bool upToReturn = false );
|
||||
void dumpInstructions(U32 startIp = 0, bool upToReturn = false);
|
||||
|
||||
/// Returns the first breakable line or 0 if none was found.
|
||||
/// @param lineNumber The one based line number.
|
||||
|
|
@ -106,7 +107,7 @@ public:
|
|||
const char *getFileLine(U32 ip);
|
||||
|
||||
///
|
||||
String getFunctionArgs( U32 offset );
|
||||
String getFunctionArgs(U32 offset);
|
||||
|
||||
bool read(StringTableEntry fileName, Stream &st);
|
||||
bool compile(const char *dsoName, StringTableEntry fileName, const char *script, bool overrideNoDso = false);
|
||||
|
|
@ -129,8 +130,8 @@ public:
|
|||
/// with, zero being the top of the stack. If the the index is
|
||||
/// -1 a new frame is created. If the index is out of range the
|
||||
/// top stack frame is used.
|
||||
ConsoleValueRef compileExec(StringTableEntry fileName, const char *script,
|
||||
bool noCalls, S32 setFrame = -1 );
|
||||
ConsoleValueRef compileExec(StringTableEntry fileName, const char *script,
|
||||
bool noCalls, S32 setFrame = -1);
|
||||
|
||||
/// Executes the existing code in the CodeBlock. The return string is any
|
||||
/// result of the code executed, if any, or an empty string.
|
||||
|
|
@ -147,7 +148,7 @@ public:
|
|||
/// -1 a new frame is created. If the index is out of range the
|
||||
/// top stack frame is used.
|
||||
/// @param packageName The code package name or null.
|
||||
ConsoleValueRef exec(U32 offset, const char *fnName, Namespace *ns, U32 argc,
|
||||
ConsoleValueRef exec(U32 offset, const char *fnName, Namespace *ns, U32 argc,
|
||||
ConsoleValueRef *argv, bool noCalls, StringTableEntry packageName,
|
||||
S32 setFrame = -1);
|
||||
};
|
||||
|
|
|
|||
2979
Engine/source/console/codeInterpreter.cpp
Normal file
2979
Engine/source/console/codeInterpreter.cpp
Normal file
File diff suppressed because it is too large
Load diff
262
Engine/source/console/codeInterpreter.h
Normal file
262
Engine/source/console/codeInterpreter.h
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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 _CODEINTERPRETER_H_
|
||||
#define _CODEINTERPRETER_H_
|
||||
|
||||
#include "console/codeBlock.h"
|
||||
#include "console/console.h"
|
||||
#include "console/consoleInternal.h"
|
||||
|
||||
/// Frame data for a foreach/foreach$ loop.
|
||||
struct IterStackRecord
|
||||
{
|
||||
/// If true, this is a foreach$ loop; if not, it's a foreach loop.
|
||||
bool mIsStringIter;
|
||||
|
||||
/// The iterator variable.
|
||||
Dictionary::Entry* mVariable;
|
||||
|
||||
/// Information for an object iterator loop.
|
||||
struct ObjectPos
|
||||
{
|
||||
/// The set being iterated over.
|
||||
SimSet* mSet;
|
||||
|
||||
/// Current index in the set.
|
||||
U32 mIndex;
|
||||
};
|
||||
|
||||
/// Information for a string iterator loop.
|
||||
struct StringPos
|
||||
{
|
||||
/// The raw string data on the string stack.
|
||||
StringStackPtr mString;
|
||||
|
||||
/// Current parsing position.
|
||||
U32 mIndex;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
ObjectPos mObj;
|
||||
StringPos mStr;
|
||||
} mData;
|
||||
};
|
||||
|
||||
enum OPCodeReturn
|
||||
{
|
||||
exitCode = -1,
|
||||
success = 0,
|
||||
breakContinue = 1
|
||||
};
|
||||
|
||||
class CodeInterpreter
|
||||
{
|
||||
public:
|
||||
CodeInterpreter(CodeBlock *cb);
|
||||
~CodeInterpreter();
|
||||
|
||||
ConsoleValueRef exec(U32 ip,
|
||||
StringTableEntry functionName,
|
||||
Namespace *thisNamespace,
|
||||
U32 argc,
|
||||
ConsoleValueRef *argv,
|
||||
bool noCalls,
|
||||
StringTableEntry packageName,
|
||||
S32 setFrame);
|
||||
|
||||
static void init();
|
||||
|
||||
// Methods
|
||||
private:
|
||||
void parseArgs(U32 &ip);
|
||||
|
||||
/// Group op codes
|
||||
/// @{
|
||||
|
||||
OPCodeReturn op_func_decl(U32 &ip);
|
||||
OPCodeReturn op_create_object(U32 &ip);
|
||||
OPCodeReturn op_add_object(U32 &ip);
|
||||
OPCodeReturn op_end_object(U32 &ip);
|
||||
OPCodeReturn op_finish_object(U32 &ip);
|
||||
OPCodeReturn op_jmpiffnot(U32 &ip);
|
||||
OPCodeReturn op_jmpifnot(U32 &ip);
|
||||
OPCodeReturn op_jmpiff(U32 &ip);
|
||||
OPCodeReturn op_jmpif(U32 &ip);
|
||||
OPCodeReturn op_jmpifnot_np(U32 &ip);
|
||||
OPCodeReturn op_jmpif_np(U32 &ip);
|
||||
OPCodeReturn op_jmp(U32 &ip);
|
||||
OPCodeReturn op_return_void(U32 &ip);
|
||||
OPCodeReturn op_return(U32 &ip);
|
||||
OPCodeReturn op_return_flt(U32 &ip);
|
||||
OPCodeReturn op_return_uint(U32 &ip);
|
||||
OPCodeReturn op_cmpeq(U32 &ip);
|
||||
OPCodeReturn op_cmpgr(U32 &ip);
|
||||
OPCodeReturn op_cmpge(U32 &ip);
|
||||
OPCodeReturn op_cmplt(U32 &ip);
|
||||
OPCodeReturn op_cmple(U32 &ip);
|
||||
OPCodeReturn op_cmpne(U32 &ip);
|
||||
OPCodeReturn op_xor(U32 &ip);
|
||||
OPCodeReturn op_mod(U32 &ip);
|
||||
OPCodeReturn op_bitand(U32 &ip);
|
||||
OPCodeReturn op_bitor(U32 &ip);
|
||||
OPCodeReturn op_not(U32 &ip);
|
||||
OPCodeReturn op_notf(U32 &ip);
|
||||
OPCodeReturn op_onescomplement(U32 &ip);
|
||||
OPCodeReturn op_shr(U32 &ip);
|
||||
OPCodeReturn op_shl(U32 &ip);
|
||||
OPCodeReturn op_and(U32 &ip);
|
||||
OPCodeReturn op_or(U32 &ip);
|
||||
OPCodeReturn op_add(U32 &ip);
|
||||
OPCodeReturn op_sub(U32 &ip);
|
||||
OPCodeReturn op_mul(U32 &ip);
|
||||
OPCodeReturn op_div(U32 &ip);
|
||||
OPCodeReturn op_neg(U32 &ip);
|
||||
OPCodeReturn op_inc(U32 &ip);
|
||||
OPCodeReturn op_dec(U32 &ip);
|
||||
OPCodeReturn op_setcurvar(U32 &ip);
|
||||
OPCodeReturn op_setcurvar_create(U32 &ip);
|
||||
OPCodeReturn op_setcurvar_array(U32 &ip);
|
||||
OPCodeReturn op_setcurvar_array_varlookup(U32 &ip);
|
||||
OPCodeReturn op_setcurvar_array_create(U32 &ip);
|
||||
OPCodeReturn op_setcurvar_array_create_varlookup(U32 &ip);
|
||||
OPCodeReturn op_loadvar_uint(U32 &ip);
|
||||
OPCodeReturn op_loadvar_flt(U32 &ip);
|
||||
OPCodeReturn op_loadvar_str(U32 &ip);
|
||||
OPCodeReturn op_loadvar_var(U32 &ip);
|
||||
OPCodeReturn op_savevar_uint(U32 &ip);
|
||||
OPCodeReturn op_savevar_flt(U32 &ip);
|
||||
OPCodeReturn op_savevar_str(U32 &ip);
|
||||
OPCodeReturn op_savevar_var(U32 &ip);
|
||||
OPCodeReturn op_setcurobject(U32 &ip);
|
||||
OPCodeReturn op_setcurobject_internal(U32 &ip);
|
||||
OPCodeReturn op_setcurobject_new(U32 &ip);
|
||||
OPCodeReturn op_setcurfield(U32 &ip);
|
||||
OPCodeReturn op_setcurfield_array(U32 &ip);
|
||||
OPCodeReturn op_setcurfield_type(U32 &ip);
|
||||
OPCodeReturn op_setcurfield_this(U32 &ip);
|
||||
OPCodeReturn op_setcurfield_array_var(U32 &ip);
|
||||
OPCodeReturn op_loadfield_uint(U32 &ip);
|
||||
OPCodeReturn op_loadfield_flt(U32 &ip);
|
||||
OPCodeReturn op_loadfield_str(U32 &ip);
|
||||
OPCodeReturn op_savefield_uint(U32 &ip);
|
||||
OPCodeReturn op_savefield_flt(U32 &ip);
|
||||
OPCodeReturn op_savefield_str(U32 &ip);
|
||||
OPCodeReturn op_str_to_uint(U32 &ip);
|
||||
OPCodeReturn op_str_to_flt(U32 &ip);
|
||||
OPCodeReturn op_str_to_none(U32 &ip);
|
||||
OPCodeReturn op_flt_to_uint(U32 &ip);
|
||||
OPCodeReturn op_flt_to_str(U32 &ip);
|
||||
OPCodeReturn op_flt_to_none(U32 &ip);
|
||||
OPCodeReturn op_uint_to_flt(U32 &ip);
|
||||
OPCodeReturn op_uint_to_str(U32 &ip);
|
||||
OPCodeReturn op_uint_to_none(U32 &ip);
|
||||
OPCodeReturn op_copyvar_to_none(U32 &ip);
|
||||
OPCodeReturn op_loadimmed_uint(U32 &ip);
|
||||
OPCodeReturn op_loadimmed_flt(U32 &ip);
|
||||
OPCodeReturn op_tag_to_str(U32 &ip);
|
||||
OPCodeReturn op_loadimmed_str(U32 &ip);
|
||||
OPCodeReturn op_docblock_str(U32 &ip);
|
||||
OPCodeReturn op_loadimmed_ident(U32 &ip);
|
||||
OPCodeReturn op_callfunc_resolve(U32 &ip);
|
||||
OPCodeReturn op_callfunc(U32 &ip);
|
||||
OPCodeReturn op_callfunc_pointer(U32 &ip);
|
||||
OPCodeReturn op_callfunc_this(U32 &ip);
|
||||
OPCodeReturn op_advance_str(U32 &ip);
|
||||
OPCodeReturn op_advance_str_appendchar(U32 &ip);
|
||||
OPCodeReturn op_advance_str_comma(U32 &ip);
|
||||
OPCodeReturn op_advance_str_nul(U32 &ip);
|
||||
OPCodeReturn op_rewind_str(U32 &ip);
|
||||
OPCodeReturn op_terminate_rewind_str(U32 &ip);
|
||||
OPCodeReturn op_compare_str(U32 &ip);
|
||||
OPCodeReturn op_push(U32 &ip);
|
||||
OPCodeReturn op_push_uint(U32 &ip);
|
||||
OPCodeReturn op_push_flt(U32 &ip);
|
||||
OPCodeReturn op_push_var(U32 &ip);
|
||||
OPCodeReturn op_push_this(U32 &ip);
|
||||
OPCodeReturn op_push_frame(U32 &ip);
|
||||
OPCodeReturn op_assert(U32 &ip);
|
||||
OPCodeReturn op_break(U32 &ip);
|
||||
OPCodeReturn op_iter_begin_str(U32 &ip);
|
||||
OPCodeReturn op_iter_begin(U32 &ip);
|
||||
OPCodeReturn op_iter(U32 &ip);
|
||||
OPCodeReturn op_iter_end(U32 &ip);
|
||||
OPCodeReturn op_invalid(U32 &ip);
|
||||
|
||||
/// @}
|
||||
|
||||
private:
|
||||
CodeBlock *mCodeBlock;
|
||||
|
||||
/// Group exec arguments.
|
||||
struct
|
||||
{
|
||||
StringTableEntry functionName;
|
||||
Namespace *thisNamespace;
|
||||
U32 argc;
|
||||
ConsoleValueRef *argv;
|
||||
bool noCalls;
|
||||
StringTableEntry packageName;
|
||||
S32 setFrame;
|
||||
} mExec;
|
||||
|
||||
U32 mIterDepth;
|
||||
F64 *mCurFloatTable;
|
||||
char *mCurStringTable;
|
||||
StringTableEntry mThisFunctionName;
|
||||
bool mPopFrame;
|
||||
|
||||
// Add local object creation stack [7/9/2007 Black]
|
||||
static const U32 objectCreationStackSize = 32;
|
||||
U32 mObjectCreationStackIndex;
|
||||
struct
|
||||
{
|
||||
SimObject *newObject;
|
||||
U32 failJump;
|
||||
} mObjectCreationStack[objectCreationStackSize];
|
||||
|
||||
SimObject *mCurrentNewObject;
|
||||
U32 mFailJump;
|
||||
StringTableEntry mPrevField;
|
||||
StringTableEntry mCurField;
|
||||
SimObject *mPrevObject;
|
||||
SimObject *mCurObject;
|
||||
SimObject *mSaveObject;
|
||||
SimObject *mThisObject;
|
||||
Namespace::Entry *mNSEntry;
|
||||
StringTableEntry mCurFNDocBlock;
|
||||
StringTableEntry mCurNSDocBlock;
|
||||
U32 mCallArgc;
|
||||
ConsoleValueRef *mCallArgv;
|
||||
CodeBlock *mSaveCodeBlock;
|
||||
|
||||
// note: anything returned is pushed to CSTK and will be invalidated on the next exec()
|
||||
ConsoleValueRef mReturnValue;
|
||||
|
||||
U32 mCurrentInstruction;
|
||||
|
||||
static const S32 nsDocLength = 128;
|
||||
char mNSDocBlockClass[nsDocLength];
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -40,13 +40,13 @@ namespace Compiler
|
|||
F64 consoleStringToNumber(const char *str, StringTableEntry file, U32 line)
|
||||
{
|
||||
F64 val = dAtof(str);
|
||||
if(val != 0)
|
||||
if (val != 0)
|
||||
return val;
|
||||
else if(!dStricmp(str, "true"))
|
||||
else if (!dStricmp(str, "true"))
|
||||
return 1;
|
||||
else if(!dStricmp(str, "false"))
|
||||
else if (!dStricmp(str, "false"))
|
||||
return 0;
|
||||
else if(file)
|
||||
else if (file)
|
||||
{
|
||||
Con::warnf(ConsoleLogEntry::General, "%s (%d): string always evaluates to 0.", file, line);
|
||||
return 0;
|
||||
|
|
@ -57,7 +57,7 @@ namespace Compiler
|
|||
//------------------------------------------------------------
|
||||
|
||||
CompilerStringTable *gCurrentStringTable, gGlobalStringTable, gFunctionStringTable;
|
||||
CompilerFloatTable *gCurrentFloatTable, gGlobalFloatTable, gFunctionFloatTable;
|
||||
CompilerFloatTable *gCurrentFloatTable, gGlobalFloatTable, gFunctionFloatTable;
|
||||
DataChunker gConsoleAllocator;
|
||||
CompilerIdentTable gIdentTable;
|
||||
|
||||
|
|
@ -71,16 +71,16 @@ namespace Compiler
|
|||
*ptr = (U32)ste;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void compileSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr)
|
||||
{
|
||||
if(ste)
|
||||
if (ste)
|
||||
getIdentTable().add(ste, ip);
|
||||
*ptr = 0;
|
||||
*(ptr+1) = 0;
|
||||
*(ptr + 1) = 0;
|
||||
}
|
||||
|
||||
void (*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr) = evalSTEtoCode;
|
||||
|
||||
void(*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr) = evalSTEtoCode;
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
|
|
@ -88,23 +88,23 @@ namespace Compiler
|
|||
|
||||
//------------------------------------------------------------
|
||||
|
||||
CompilerStringTable *getCurrentStringTable() { return gCurrentStringTable; }
|
||||
CompilerStringTable &getGlobalStringTable() { return gGlobalStringTable; }
|
||||
CompilerStringTable *getCurrentStringTable() { return gCurrentStringTable; }
|
||||
CompilerStringTable &getGlobalStringTable() { return gGlobalStringTable; }
|
||||
CompilerStringTable &getFunctionStringTable() { return gFunctionStringTable; }
|
||||
|
||||
void setCurrentStringTable (CompilerStringTable* cst) { gCurrentStringTable = cst; }
|
||||
void setCurrentStringTable(CompilerStringTable* cst) { gCurrentStringTable = cst; }
|
||||
|
||||
CompilerFloatTable *getCurrentFloatTable() { return gCurrentFloatTable; }
|
||||
CompilerFloatTable &getGlobalFloatTable() { return gGlobalFloatTable; }
|
||||
CompilerFloatTable &getFunctionFloatTable() { return gFunctionFloatTable; }
|
||||
CompilerFloatTable *getCurrentFloatTable() { return gCurrentFloatTable; }
|
||||
CompilerFloatTable &getGlobalFloatTable() { return gGlobalFloatTable; }
|
||||
CompilerFloatTable &getFunctionFloatTable() { return gFunctionFloatTable; }
|
||||
|
||||
void setCurrentFloatTable (CompilerFloatTable* cst) { gCurrentFloatTable = cst; }
|
||||
void setCurrentFloatTable(CompilerFloatTable* cst) { gCurrentFloatTable = cst; }
|
||||
|
||||
CompilerIdentTable &getIdentTable() { return gIdentTable; }
|
||||
|
||||
void precompileIdent(StringTableEntry ident)
|
||||
{
|
||||
if(ident)
|
||||
if (ident)
|
||||
gGlobalStringTable.add(ident);
|
||||
}
|
||||
|
||||
|
|
@ -119,8 +119,8 @@ namespace Compiler
|
|||
getIdentTable().reset();
|
||||
}
|
||||
|
||||
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
|
||||
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
|
||||
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
|
||||
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -135,36 +135,40 @@ U32 CompilerStringTable::add(const char *str, bool caseSens, bool tag)
|
|||
{
|
||||
// Is it already in?
|
||||
Entry **walk;
|
||||
for(walk = &list; *walk; walk = &((*walk)->next))
|
||||
for (walk = &list; *walk; walk = &((*walk)->next))
|
||||
{
|
||||
if((*walk)->tag != tag)
|
||||
if ((*walk)->tag != tag)
|
||||
continue;
|
||||
|
||||
if(caseSens)
|
||||
if (caseSens)
|
||||
{
|
||||
if(!dStrcmp((*walk)->string, str))
|
||||
if (!dStrcmp((*walk)->string, str))
|
||||
return (*walk)->start;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!dStricmp((*walk)->string, str))
|
||||
if (!dStricmp((*walk)->string, str))
|
||||
return (*walk)->start;
|
||||
}
|
||||
}
|
||||
|
||||
// Write it out.
|
||||
Entry *newStr = (Entry *) consoleAlloc(sizeof(Entry));
|
||||
Entry *newStr = (Entry *)consoleAlloc(sizeof(Entry));
|
||||
*walk = newStr;
|
||||
newStr->next = NULL;
|
||||
newStr->start = totalLen;
|
||||
U32 len = dStrlen(str) + 1;
|
||||
if(tag && len < 7) // alloc space for the numeric tag 1 for tag, 5 for # and 1 for nul
|
||||
if (tag && len < 7) // alloc space for the numeric tag 1 for tag, 5 for # and 1 for nul
|
||||
len = 7;
|
||||
totalLen += len;
|
||||
newStr->string = (char *) consoleAlloc(len);
|
||||
newStr->string = (char *)consoleAlloc(len);
|
||||
newStr->len = len;
|
||||
newStr->tag = tag;
|
||||
dStrcpy(newStr->string, str);
|
||||
|
||||
// Put into the hash table.
|
||||
hashTable[str] = newStr;
|
||||
|
||||
return newStr->start;
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +193,8 @@ void CompilerStringTable::reset()
|
|||
char *CompilerStringTable::build()
|
||||
{
|
||||
char *ret = new char[totalLen];
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
dMemset(ret, 0, totalLen);
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
dStrcpy(ret + walk->start, walk->string);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -197,7 +202,7 @@ char *CompilerStringTable::build()
|
|||
void CompilerStringTable::write(Stream &st)
|
||||
{
|
||||
st.write(totalLen);
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
st.write(walk->len, walk->string);
|
||||
}
|
||||
|
||||
|
|
@ -207,15 +212,15 @@ U32 CompilerFloatTable::add(F64 value)
|
|||
{
|
||||
Entry **walk;
|
||||
U32 i = 0;
|
||||
for(walk = &list; *walk; walk = &((*walk)->next), i++)
|
||||
if(value == (*walk)->val)
|
||||
for (walk = &list; *walk; walk = &((*walk)->next), i++)
|
||||
if (value == (*walk)->val)
|
||||
return i;
|
||||
Entry *newFloat = (Entry *) consoleAlloc(sizeof(Entry));
|
||||
Entry *newFloat = (Entry *)consoleAlloc(sizeof(Entry));
|
||||
newFloat->val = value;
|
||||
newFloat->next = NULL;
|
||||
count++;
|
||||
*walk = newFloat;
|
||||
return count-1;
|
||||
return count - 1;
|
||||
}
|
||||
void CompilerFloatTable::reset()
|
||||
{
|
||||
|
|
@ -226,7 +231,7 @@ F64 *CompilerFloatTable::build()
|
|||
{
|
||||
F64 *ret = new F64[count];
|
||||
U32 i = 0;
|
||||
for(Entry *walk = list; walk; walk = walk->next, i++)
|
||||
for (Entry *walk = list; walk; walk = walk->next, i++)
|
||||
ret[i] = walk->val;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -234,7 +239,7 @@ F64 *CompilerFloatTable::build()
|
|||
void CompilerFloatTable::write(Stream &st)
|
||||
{
|
||||
st.write(count);
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
st.write(walk->val);
|
||||
}
|
||||
|
||||
|
|
@ -248,12 +253,12 @@ void CompilerIdentTable::reset()
|
|||
void CompilerIdentTable::add(StringTableEntry ste, U32 ip)
|
||||
{
|
||||
U32 index = gGlobalStringTable.add(ste, false);
|
||||
Entry *newEntry = (Entry *) consoleAlloc(sizeof(Entry));
|
||||
Entry *newEntry = (Entry *)consoleAlloc(sizeof(Entry));
|
||||
newEntry->offset = index;
|
||||
newEntry->ip = ip;
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
{
|
||||
if(walk->offset == index)
|
||||
if (walk->offset == index)
|
||||
{
|
||||
newEntry->nextIdent = walk->nextIdent;
|
||||
walk->nextIdent = newEntry;
|
||||
|
|
@ -269,24 +274,24 @@ void CompilerIdentTable::write(Stream &st)
|
|||
{
|
||||
U32 count = 0;
|
||||
Entry * walk;
|
||||
for(walk = list; walk; walk = walk->next)
|
||||
for (walk = list; walk; walk = walk->next)
|
||||
count++;
|
||||
st.write(count);
|
||||
for(walk = list; walk; walk = walk->next)
|
||||
for (walk = list; walk; walk = walk->next)
|
||||
{
|
||||
U32 ec = 0;
|
||||
Entry * el;
|
||||
for(el = walk; el; el = el->nextIdent)
|
||||
for (el = walk; el; el = el->nextIdent)
|
||||
ec++;
|
||||
st.write(walk->offset);
|
||||
st.write(ec);
|
||||
for(el = walk; el; el = el->nextIdent)
|
||||
for (el = walk; el; el = el->nextIdent)
|
||||
st.write(el->ip);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
U8 *CodeStream::allocCode(U32 sz)
|
||||
{
|
||||
U8 *ptr = NULL;
|
||||
|
|
@ -300,12 +305,12 @@ U8 *CodeStream::allocCode(U32 sz)
|
|||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CodeData *data = new CodeData;
|
||||
data->data = (U8*)dMalloc(BlockSize);
|
||||
data->size = sz;
|
||||
data->next = NULL;
|
||||
|
||||
|
||||
if (mCodeHead)
|
||||
mCodeHead->next = data;
|
||||
mCodeHead = data;
|
||||
|
|
@ -313,21 +318,21 @@ U8 *CodeStream::allocCode(U32 sz)
|
|||
mCode = data;
|
||||
return data->data;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
|
||||
{
|
||||
AssertFatal(mFixStack.size() > 0, "Fix stack mismatch");
|
||||
|
||||
U32 fixStart = mFixStack[mFixStack.size()-1];
|
||||
for (U32 i=fixStart; i<mFixList.size(); i += 2)
|
||||
|
||||
U32 fixStart = mFixStack[mFixStack.size() - 1];
|
||||
for (U32 i = fixStart; i<mFixList.size(); i += 2)
|
||||
{
|
||||
FixType type = (FixType)mFixList[i+1];
|
||||
|
||||
FixType type = (FixType)mFixList[i + 1];
|
||||
|
||||
U32 fixedIp = 0;
|
||||
bool valid = true;
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case FIXTYPE_LOOPBLOCKSTART:
|
||||
|
|
@ -344,7 +349,7 @@ void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
|
|||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (valid)
|
||||
{
|
||||
patch(mFixList[i], fixedIp);
|
||||
|
|
@ -353,7 +358,7 @@ void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
|
||||
{
|
||||
// Alloc stream
|
||||
|
|
@ -361,7 +366,7 @@ void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
|
|||
*stream = new U32[mCodePos + (numLineBreaks * 2)];
|
||||
dMemset(*stream, '\0', mCodePos + (numLineBreaks * 2));
|
||||
*size = mCodePos;
|
||||
|
||||
|
||||
// Dump chunks & line breaks
|
||||
U32 outBytes = mCodePos * sizeof(U32);
|
||||
U8 *outPtr = *((U8**)stream);
|
||||
|
|
@ -372,20 +377,20 @@ void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
|
|||
outPtr += bytesToCopy;
|
||||
outBytes -= bytesToCopy;
|
||||
}
|
||||
|
||||
|
||||
*lineBreaks = *stream + mCodePos;
|
||||
dMemcpy(*lineBreaks, mBreakLines.address(), sizeof(U32) * mBreakLines.size());
|
||||
|
||||
|
||||
// Apply patches on top
|
||||
for (U32 i=0; i<mPatchList.size(); i++)
|
||||
for (U32 i = 0; i<mPatchList.size(); i++)
|
||||
{
|
||||
PatchEntry &e = mPatchList[i];
|
||||
(*stream)[e.addr] = e.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
void CodeStream::reset()
|
||||
{
|
||||
mCodePos = 0;
|
||||
|
|
@ -393,7 +398,7 @@ void CodeStream::reset()
|
|||
mFixLoopStack.clear();
|
||||
mFixList.clear();
|
||||
mBreakLines.clear();
|
||||
|
||||
|
||||
// Pop down to one code block
|
||||
CodeData *itr = mCode ? mCode->next : NULL;
|
||||
while (itr != NULL)
|
||||
|
|
@ -403,7 +408,7 @@ void CodeStream::reset()
|
|||
delete(itr);
|
||||
itr = next;
|
||||
}
|
||||
|
||||
|
||||
if (mCode)
|
||||
{
|
||||
mCode->size = 0;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@
|
|||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class Stream;
|
||||
class DataChunker;
|
||||
|
||||
|
|
@ -91,10 +94,15 @@ namespace Compiler
|
|||
OP_DIV,
|
||||
OP_NEG,
|
||||
|
||||
OP_INC,
|
||||
OP_DEC,
|
||||
|
||||
OP_SETCURVAR,
|
||||
OP_SETCURVAR_CREATE,
|
||||
OP_SETCURVAR_ARRAY,
|
||||
OP_SETCURVAR_ARRAY_VARLOOKUP,
|
||||
OP_SETCURVAR_ARRAY_CREATE,
|
||||
OP_SETCURVAR_ARRAY_CREATE_VARLOOKUP,
|
||||
|
||||
OP_LOADVAR_UINT,// 40
|
||||
OP_LOADVAR_FLT,
|
||||
|
|
@ -113,6 +121,8 @@ namespace Compiler
|
|||
OP_SETCURFIELD,
|
||||
OP_SETCURFIELD_ARRAY, // 50
|
||||
OP_SETCURFIELD_TYPE,
|
||||
OP_SETCURFIELD_ARRAY_VAR,
|
||||
OP_SETCURFIELD_THIS,
|
||||
|
||||
OP_LOADFIELD_UINT,
|
||||
OP_LOADFIELD_FLT,
|
||||
|
|
@ -142,6 +152,8 @@ namespace Compiler
|
|||
|
||||
OP_CALLFUNC_RESOLVE,
|
||||
OP_CALLFUNC,
|
||||
OP_CALLFUNC_POINTER,
|
||||
OP_CALLFUNC_THIS,
|
||||
|
||||
OP_ADVANCE_STR,
|
||||
OP_ADVANCE_STR_APPENDCHAR,
|
||||
|
|
@ -155,23 +167,26 @@ namespace Compiler
|
|||
OP_PUSH_UINT, // Integer
|
||||
OP_PUSH_FLT, // Float
|
||||
OP_PUSH_VAR, // Variable
|
||||
OP_PUSH_THIS, // This pointer
|
||||
OP_PUSH_FRAME, // Frame
|
||||
|
||||
OP_ASSERT,
|
||||
OP_BREAK,
|
||||
|
||||
|
||||
OP_ITER_BEGIN, ///< Prepare foreach iterator.
|
||||
OP_ITER_BEGIN_STR, ///< Prepare foreach$ iterator.
|
||||
OP_ITER, ///< Enter foreach loop.
|
||||
OP_ITER_END, ///< End foreach loop.
|
||||
|
||||
OP_INVALID // 90
|
||||
OP_INVALID, // 90
|
||||
|
||||
MAX_OP_CODELEN ///< The amount of op codes.
|
||||
};
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
F64 consoleStringToNumber(const char *str, StringTableEntry file = 0, U32 line = 0);
|
||||
|
||||
|
||||
U32 compileBlock(StmtNode *block, CodeStream &codeStream, U32 ip);
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
|
@ -207,6 +222,7 @@ namespace Compiler
|
|||
Entry *list;
|
||||
|
||||
char buf[256];
|
||||
std::unordered_map<std::string, Entry*> hashTable;
|
||||
|
||||
U32 add(const char *str, bool caseSens = true, bool tag = false);
|
||||
U32 addIntString(U32 value);
|
||||
|
|
@ -239,14 +255,14 @@ namespace Compiler
|
|||
inline StringTableEntry CodeToSTE(U32 *code, U32 ip)
|
||||
{
|
||||
#ifdef TORQUE_CPU_X64
|
||||
return (StringTableEntry)(*((U64*)(code+ip)));
|
||||
return (StringTableEntry)(*((U64*)(code + ip)));
|
||||
#else
|
||||
return (StringTableEntry)(*(code+ip));
|
||||
return (StringTableEntry)(*(code + ip));
|
||||
#endif
|
||||
}
|
||||
|
||||
extern void (*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr);
|
||||
|
||||
extern void(*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr);
|
||||
|
||||
void evalSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr);
|
||||
void compileSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr);
|
||||
|
||||
|
|
@ -254,13 +270,13 @@ namespace Compiler
|
|||
CompilerStringTable &getGlobalStringTable();
|
||||
CompilerStringTable &getFunctionStringTable();
|
||||
|
||||
void setCurrentStringTable (CompilerStringTable* cst);
|
||||
void setCurrentStringTable(CompilerStringTable* cst);
|
||||
|
||||
CompilerFloatTable *getCurrentFloatTable();
|
||||
CompilerFloatTable &getGlobalFloatTable();
|
||||
CompilerFloatTable &getFunctionFloatTable();
|
||||
|
||||
void setCurrentFloatTable (CompilerFloatTable* cst);
|
||||
void setCurrentFloatTable(CompilerFloatTable* cst);
|
||||
|
||||
CompilerIdentTable &getIdentTable();
|
||||
|
||||
|
|
@ -280,7 +296,7 @@ namespace Compiler
|
|||
class CodeStream
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
enum FixType
|
||||
{
|
||||
// For loops
|
||||
|
|
@ -288,37 +304,37 @@ public:
|
|||
FIXTYPE_BREAK,
|
||||
FIXTYPE_CONTINUE
|
||||
};
|
||||
|
||||
|
||||
enum Constants
|
||||
{
|
||||
BlockSize = 16384,
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
typedef struct PatchEntry
|
||||
{
|
||||
U32 addr; ///< Address to patch
|
||||
U32 value; ///< Value to place at addr
|
||||
|
||||
PatchEntry() {;}
|
||||
PatchEntry(U32 a, U32 v) : addr(a), value(v) {;}
|
||||
|
||||
PatchEntry() { ; }
|
||||
PatchEntry(U32 a, U32 v) : addr(a), value(v) { ; }
|
||||
} PatchEntry;
|
||||
|
||||
|
||||
typedef struct CodeData
|
||||
{
|
||||
U8 *data; ///< Allocated data (size is BlockSize)
|
||||
U32 size; ///< Bytes used in data
|
||||
CodeData *next; ///< Next block
|
||||
} CodeData;
|
||||
|
||||
|
||||
/// @name Emitted code
|
||||
/// {
|
||||
CodeData *mCode;
|
||||
CodeData *mCodeHead;
|
||||
U32 mCodePos;
|
||||
/// }
|
||||
|
||||
|
||||
/// @name Code fixing stacks
|
||||
/// {
|
||||
Vector<U32> mFixList;
|
||||
|
|
@ -326,28 +342,28 @@ protected:
|
|||
Vector<bool> mFixLoopStack;
|
||||
Vector<PatchEntry> mPatchList;
|
||||
/// }
|
||||
|
||||
|
||||
Vector<U32> mBreakLines; ///< Line numbers
|
||||
|
||||
|
||||
public:
|
||||
|
||||
CodeStream() : mCode(0), mCodeHead(NULL), mCodePos(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~CodeStream()
|
||||
{
|
||||
reset();
|
||||
|
||||
|
||||
if (mCode)
|
||||
{
|
||||
dFree(mCode->data);
|
||||
delete mCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U8 *allocCode(U32 sz);
|
||||
|
||||
|
||||
inline U32 emit(U32 code)
|
||||
{
|
||||
U32 *ptr = (U32*)allocCode(4);
|
||||
|
|
@ -357,7 +373,7 @@ public:
|
|||
#endif
|
||||
return mCodePos++;
|
||||
}
|
||||
|
||||
|
||||
inline void patch(U32 addr, U32 code)
|
||||
{
|
||||
#ifdef DEBUG_CODESTREAM
|
||||
|
|
@ -365,7 +381,7 @@ public:
|
|||
#endif
|
||||
mPatchList.push_back(PatchEntry(addr, code));
|
||||
}
|
||||
|
||||
|
||||
inline U32 emitSTE(const char *code)
|
||||
{
|
||||
U64 *ptr = (U64*)allocCode(8);
|
||||
|
|
@ -375,70 +391,70 @@ public:
|
|||
printf("code[%u] = %s\n", mCodePos, code);
|
||||
#endif
|
||||
mCodePos += 2;
|
||||
return mCodePos-2;
|
||||
return mCodePos - 2;
|
||||
}
|
||||
|
||||
|
||||
inline U32 tell()
|
||||
{
|
||||
return mCodePos;
|
||||
}
|
||||
|
||||
|
||||
inline bool inLoop()
|
||||
{
|
||||
for (U32 i=0; i<mFixLoopStack.size(); i++)
|
||||
for (U32 i = 0; i<mFixLoopStack.size(); i++)
|
||||
{
|
||||
if (mFixLoopStack[i])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
inline U32 emitFix(FixType type)
|
||||
{
|
||||
U32 *ptr = (U32*)allocCode(4);
|
||||
*ptr = (U32)type;
|
||||
|
||||
|
||||
#ifdef DEBUG_CODESTREAM
|
||||
printf("code[%u] = [FIX:%u]\n", mCodePos, (U32)type);
|
||||
#endif
|
||||
|
||||
|
||||
mFixList.push_back(mCodePos);
|
||||
mFixList.push_back((U32)type);
|
||||
return mCodePos++;
|
||||
}
|
||||
|
||||
|
||||
inline void pushFixScope(bool isLoop)
|
||||
{
|
||||
mFixStack.push_back(mFixList.size());
|
||||
mFixLoopStack.push_back(isLoop);
|
||||
}
|
||||
|
||||
|
||||
inline void popFixScope()
|
||||
{
|
||||
AssertFatal(mFixStack.size() > 0, "Fix stack mismatch");
|
||||
|
||||
U32 newSize = mFixStack[mFixStack.size()-1];
|
||||
|
||||
U32 newSize = mFixStack[mFixStack.size() - 1];
|
||||
while (mFixList.size() > newSize)
|
||||
mFixList.pop_back();
|
||||
mFixStack.pop_back();
|
||||
mFixLoopStack.pop_back();
|
||||
}
|
||||
|
||||
|
||||
void fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint);
|
||||
|
||||
|
||||
inline void addBreakLine(U32 lineNumber, U32 ip)
|
||||
{
|
||||
mBreakLines.push_back(lineNumber);
|
||||
mBreakLines.push_back(ip);
|
||||
}
|
||||
|
||||
|
||||
inline U32 getNumLineBreaks()
|
||||
{
|
||||
return mBreakLines.size() / 2;
|
||||
}
|
||||
|
||||
|
||||
void emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks);
|
||||
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@
|
|||
#define _CONSOLE_H_
|
||||
|
||||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
#ifndef _BITSET_H_
|
||||
#include "core/bitSet.h"
|
||||
#include "core/bitSet.h"
|
||||
#endif
|
||||
#ifndef _REFBASE_H_
|
||||
#include "core/util/refBase.h"
|
||||
#include "core/util/refBase.h"
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
@ -95,8 +95,8 @@ struct ConsoleLogEntry
|
|||
Script,
|
||||
GUI,
|
||||
Network,
|
||||
GGConnect,
|
||||
NUM_TYPE
|
||||
GGConnect,
|
||||
NUM_TYPE
|
||||
} mType;
|
||||
|
||||
/// Indicates the actual log entry.
|
||||
|
|
@ -120,7 +120,7 @@ extern char *typeValueEmpty;
|
|||
class ConsoleValue
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
TypeInternalInt = -5,
|
||||
|
|
@ -129,17 +129,17 @@ public:
|
|||
TypeInternalStackString = -2,
|
||||
TypeInternalString = -1,
|
||||
};
|
||||
|
||||
|
||||
S32 type;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// NOTE: This is protected to ensure no one outside
|
||||
// of this structure is messing with it.
|
||||
|
||||
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4201 ) // warning C4201: nonstandard extension used : nameless struct/union
|
||||
|
||||
|
||||
// An variable is either a real dynamic type or
|
||||
// its one exposed from C++ using a data pointer.
|
||||
//
|
||||
|
|
@ -154,24 +154,24 @@ public:
|
|||
F32 fval;
|
||||
U32 bufferLen;
|
||||
};
|
||||
|
||||
|
||||
struct
|
||||
{
|
||||
/// The real data pointer.
|
||||
void *dataPtr;
|
||||
|
||||
|
||||
/// The enum lookup table for enumerated types.
|
||||
const EnumTable *enumTable;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
U32 getIntValue();
|
||||
S32 getSignedIntValue();
|
||||
F32 getFloatValue();
|
||||
const char *getStringValue();
|
||||
StringStackPtr getStringStackPtr();
|
||||
bool getBoolValue();
|
||||
|
||||
|
||||
void setIntValue(U32 val);
|
||||
void setIntValue(S32 val);
|
||||
void setFloatValue(F32 val);
|
||||
|
|
@ -179,7 +179,7 @@ public:
|
|||
void setStackStringValue(const char *value);
|
||||
void setStringStackPtrValue(StringStackPtr ptr);
|
||||
void setBoolValue(bool val);
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
ival = 0;
|
||||
|
|
@ -188,7 +188,7 @@ public:
|
|||
bufferLen = 0;
|
||||
type = TypeInternalString;
|
||||
}
|
||||
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
if ((type <= TypeInternalString) && (bufferLen > 0))
|
||||
|
|
@ -201,8 +201,8 @@ public:
|
|||
ival = 0;
|
||||
fval = 0;
|
||||
}
|
||||
ConsoleValue(){ init(); };
|
||||
~ConsoleValue(){ cleanup(); };
|
||||
ConsoleValue() { init(); };
|
||||
~ConsoleValue() { cleanup(); };
|
||||
};
|
||||
|
||||
// Proxy class for console variables
|
||||
|
|
@ -234,7 +234,7 @@ public:
|
|||
inline operator S32() { return getSignedIntValue(); }
|
||||
inline operator F32() { return getFloatValue(); }
|
||||
inline operator bool() { return getBoolValue(); }
|
||||
|
||||
|
||||
inline bool isStringStackPtr() { return value ? value->type == ConsoleValue::TypeInternalStringStackPtr : false; }
|
||||
inline bool isString() { return value ? value->type >= ConsoleValue::TypeInternalStringStackPtr : true; }
|
||||
inline bool isInt() { return value ? value->type == ConsoleValue::TypeInternalInt : false; }
|
||||
|
|
@ -320,12 +320,12 @@ public:
|
|||
|
||||
///
|
||||
typedef const char * (*StringCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
|
||||
typedef S32 (*IntCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
|
||||
typedef F32 (*FloatCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
|
||||
typedef void (*VoidCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]); // We have it return a value so things don't break..
|
||||
typedef bool (*BoolCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
|
||||
typedef S32(*IntCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
|
||||
typedef F32(*FloatCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
|
||||
typedef void(*VoidCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]); // We have it return a value so things don't break..
|
||||
typedef bool(*BoolCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
|
||||
|
||||
typedef void (*ConsumerCallback)(U32 level, const char *consoleLine);
|
||||
typedef void(*ConsumerCallback)(U32 level, const char *consoleLine);
|
||||
/// @}
|
||||
|
||||
/// @defgroup console_types Scripting Engine Type Functions
|
||||
|
|
@ -333,7 +333,7 @@ typedef void (*ConsumerCallback)(U32 level, const char *consoleLine);
|
|||
/// @see Con::registerType
|
||||
/// @{
|
||||
typedef const char* (*GetDataFunction)(void *dptr, EnumTable *tbl, BitSet32 flag);
|
||||
typedef void (*SetDataFunction)(void *dptr, S32 argc, const char **argv, EnumTable *tbl, BitSet32 flag);
|
||||
typedef void(*SetDataFunction)(void *dptr, S32 argc, const char **argv, EnumTable *tbl, BitSet32 flag);
|
||||
/// @}
|
||||
|
||||
/// This namespace contains the core of the console functionality.
|
||||
|
|
@ -347,7 +347,7 @@ typedef void (*SetDataFunction)(void *dptr, S32 argc, const char **argv,
|
|||
namespace Con
|
||||
{
|
||||
/// Various configuration constants.
|
||||
enum Constants
|
||||
enum Constants
|
||||
{
|
||||
/// This is the version number associated with DSO files.
|
||||
///
|
||||
|
|
@ -361,20 +361,22 @@ namespace Con
|
|||
/// 12/29/04 - BJG - 33->34 Removed some opcodes, part of namespace upgrade.
|
||||
/// 12/30/04 - BJG - 34->35 Reordered some things, further general shuffling.
|
||||
/// 11/03/05 - BJG - 35->36 Integrated new debugger code.
|
||||
// 09/08/06 - THB - 36->37 New opcode for internal names
|
||||
// 09/15/06 - THB - 37->38 Added unit conversions
|
||||
// 11/23/06 - THB - 38->39 Added recursive internal name operator
|
||||
// 02/15/07 - THB - 39->40 Bumping to 40 for TGB since the console has been
|
||||
// majorly hacked without the version number being bumped
|
||||
// 02/16/07 - THB - 40->41 newmsg operator
|
||||
// 06/15/07 - THB - 41->42 script types
|
||||
/// 09/08/06 - THB - 36->37 New opcode for internal names
|
||||
/// 09/15/06 - THB - 37->38 Added unit conversions
|
||||
/// 11/23/06 - THB - 38->39 Added recursive internal name operator
|
||||
/// 02/15/07 - THB - 39->40 Bumping to 40 for TGB since the console has been
|
||||
/// majorly hacked without the version number being bumped
|
||||
/// 02/16/07 - THB - 40->41 newmsg operator
|
||||
/// 06/15/07 - THB - 41->42 script types
|
||||
/// 07/31/07 - THB - 42->43 Patch from Andreas Kirsch: Added opcode to support nested new declarations.
|
||||
/// 09/12/07 - CAF - 43->44 remove newmsg operator
|
||||
/// 09/27/07 - RDB - 44->45 Patch from Andreas Kirsch: Added opcode to support correct void return
|
||||
/// 01/13/09 - TMS - 45->46 Added script assert
|
||||
/// 09/07/14 - jamesu - 46->47 64bit support
|
||||
/// 10/14/14 - jamesu - 47->48 Added opcodes to reduce reliance on strings in function calls
|
||||
DSOVersion = 48,
|
||||
/// 10/07/17 - JTH - 48->49 Added opcode for function pointers and revamp of interpreter
|
||||
/// from switch to function calls.
|
||||
DSOVersion = 49,
|
||||
|
||||
MaxLineLength = 512, ///< Maximum length of a line of console input.
|
||||
MaxDataTypes = 256 ///< Maximum number of registered data types.
|
||||
|
|
@ -552,11 +554,11 @@ namespace Con
|
|||
/// @param usage Documentation string.
|
||||
///
|
||||
/// @see ConsoleDynamicTypes
|
||||
void addVariable( const char *name,
|
||||
S32 type,
|
||||
void *pointer,
|
||||
const char* usage = NULL );
|
||||
|
||||
void addVariable(const char *name,
|
||||
S32 type,
|
||||
void *pointer,
|
||||
const char* usage = NULL);
|
||||
|
||||
/// Add a console constant that references the value of a constant in C++ code.
|
||||
///
|
||||
/// @param name Global console constant name to create.
|
||||
|
|
@ -565,11 +567,11 @@ namespace Con
|
|||
/// @param usage Documentation string.
|
||||
///
|
||||
/// @see ConsoleDynamicTypes
|
||||
void addConstant( const char *name,
|
||||
S32 type,
|
||||
const void *pointer,
|
||||
const char* usage = NULL );
|
||||
|
||||
void addConstant(const char *name,
|
||||
S32 type,
|
||||
const void *pointer,
|
||||
const char* usage = NULL);
|
||||
|
||||
/// Remove a console variable.
|
||||
///
|
||||
/// @param name Global console variable name to remove
|
||||
|
|
@ -582,14 +584,14 @@ namespace Con
|
|||
/// @param name An existing global console variable name.
|
||||
/// @param callback The notification delegate function.
|
||||
///
|
||||
void addVariableNotify( const char *name, const NotifyDelegate &callback );
|
||||
void addVariableNotify(const char *name, const NotifyDelegate &callback);
|
||||
|
||||
/// Remove an existing variable assignment notification callback.
|
||||
///
|
||||
/// @param name An existing global console variable name.
|
||||
/// @param callback The notification delegate function.
|
||||
///
|
||||
void removeVariableNotify( const char *name, const NotifyDelegate &callback );
|
||||
void removeVariableNotify(const char *name, const NotifyDelegate &callback);
|
||||
|
||||
/// Assign a string value to a locally scoped console variable
|
||||
///
|
||||
|
|
@ -628,31 +630,31 @@ namespace Con
|
|||
const char* getObjectField(const char* name);
|
||||
|
||||
/// Same as setVariable(), but for bools.
|
||||
void setBoolVariable (const char* name,bool var);
|
||||
void setBoolVariable(const char* name, bool var);
|
||||
|
||||
/// Same as getVariable(), but for bools.
|
||||
///
|
||||
/// @param name Name of the variable.
|
||||
/// @param def Default value to supply if no matching variable is found.
|
||||
bool getBoolVariable (const char* name,bool def = false);
|
||||
bool getBoolVariable(const char* name, bool def = false);
|
||||
|
||||
/// Same as setVariable(), but for ints.
|
||||
void setIntVariable (const char* name,S32 var);
|
||||
void setIntVariable(const char* name, S32 var);
|
||||
|
||||
/// Same as getVariable(), but for ints.
|
||||
///
|
||||
/// @param name Name of the variable.
|
||||
/// @param def Default value to supply if no matching variable is found.
|
||||
S32 getIntVariable (const char* name,S32 def = 0);
|
||||
S32 getIntVariable(const char* name, S32 def = 0);
|
||||
|
||||
/// Same as setVariable(), but for floats.
|
||||
void setFloatVariable(const char* name,F32 var);
|
||||
void setFloatVariable(const char* name, F32 var);
|
||||
|
||||
/// Same as getVariable(), but for floats.
|
||||
///
|
||||
/// @param name Name of the variable.
|
||||
/// @param def Default value to supply if no matching variable is found.
|
||||
F32 getFloatVariable(const char* name,F32 def = .0f);
|
||||
F32 getFloatVariable(const char* name, F32 def = .0f);
|
||||
|
||||
/// @}
|
||||
|
||||
|
|
@ -668,52 +670,52 @@ namespace Con
|
|||
/// @param maxArgs Maximum number of arguments this function accepts
|
||||
/// @param toolOnly Wether this is a TORQUE_TOOLS only function.
|
||||
/// @param header The extended function header.
|
||||
void addCommand( const char* name, StringCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
void addCommand(const char* name, StringCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
|
||||
void addCommand( const char* name, IntCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand( const char* name, FloatCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand( const char* name, VoidCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand( const char* name, BoolCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
|
||||
/// @}
|
||||
void addCommand(const char* name, IntCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char* name, FloatCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char* name, VoidCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char* name, BoolCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
|
||||
/// @name Namespace Function Registration
|
||||
/// @{
|
||||
/// @}
|
||||
|
||||
/// Register a C++ function with the console making it callable
|
||||
/// as a method of the given namespace from the scripting engine.
|
||||
///
|
||||
/// @param nameSpace Name of the namespace to associate the new function with; this is usually the name of a class.
|
||||
/// @param name Name of the new function.
|
||||
/// @param cb Pointer to the function implementing the scripting call; a console callback function returning a specific type value.
|
||||
/// @param usage Documentation for this function. @ref console_autodoc
|
||||
/// @param minArgs Minimum number of arguments this function accepts
|
||||
/// @param maxArgs Maximum number of arguments this function accepts
|
||||
/// @param toolOnly Wether this is a TORQUE_TOOLS only function.
|
||||
/// @param header The extended function header.
|
||||
void addCommand(const char *nameSpace, const char *name,StringCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
/// @name Namespace Function Registration
|
||||
/// @{
|
||||
|
||||
void addCommand(const char *nameSpace, const char *name,IntCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char *nameSpace, const char *name,FloatCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char *nameSpace, const char *name,VoidCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char *nameSpace, const char *name,BoolCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
/// Register a C++ function with the console making it callable
|
||||
/// as a method of the given namespace from the scripting engine.
|
||||
///
|
||||
/// @param nameSpace Name of the namespace to associate the new function with; this is usually the name of a class.
|
||||
/// @param name Name of the new function.
|
||||
/// @param cb Pointer to the function implementing the scripting call; a console callback function returning a specific type value.
|
||||
/// @param usage Documentation for this function. @ref console_autodoc
|
||||
/// @param minArgs Minimum number of arguments this function accepts
|
||||
/// @param maxArgs Maximum number of arguments this function accepts
|
||||
/// @param toolOnly Wether this is a TORQUE_TOOLS only function.
|
||||
/// @param header The extended function header.
|
||||
void addCommand(const char *nameSpace, const char *name, StringCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
|
||||
/// @}
|
||||
void addCommand(const char *nameSpace, const char *name, IntCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char *nameSpace, const char *name, FloatCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char *nameSpace, const char *name, VoidCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
void addCommand(const char *nameSpace, const char *name, BoolCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
|
||||
|
||||
/// @name Special Purpose Registration
|
||||
///
|
||||
/// These are special-purpose functions that exist to allow commands to be grouped, so
|
||||
/// that when we generate console docs, they can be more meaningfully presented.
|
||||
///
|
||||
/// @ref console_autodoc "Click here for more information about console docs and grouping."
|
||||
///
|
||||
/// @{
|
||||
/// @}
|
||||
|
||||
void markCommandGroup (const char * nsName, const char *name, const char* usage=NULL);
|
||||
/// @name Special Purpose Registration
|
||||
///
|
||||
/// These are special-purpose functions that exist to allow commands to be grouped, so
|
||||
/// that when we generate console docs, they can be more meaningfully presented.
|
||||
///
|
||||
/// @ref console_autodoc "Click here for more information about console docs and grouping."
|
||||
///
|
||||
/// @{
|
||||
|
||||
void markCommandGroup(const char * nsName, const char *name, const char* usage = NULL);
|
||||
void beginCommandGroup(const char * nsName, const char *name, const char* usage);
|
||||
void endCommandGroup (const char * nsName, const char *name);
|
||||
void endCommandGroup(const char * nsName, const char *name);
|
||||
|
||||
void noteScriptCallback( const char *className, const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL );
|
||||
void noteScriptCallback(const char *className, const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL);
|
||||
|
||||
/// @}
|
||||
|
||||
|
|
@ -841,15 +843,15 @@ namespace Con
|
|||
///
|
||||
char* getReturnBuffer(U32 bufferSize);
|
||||
char* getReturnBuffer(const char *stringToCopy);
|
||||
char* getReturnBuffer( const String& str );
|
||||
char* getReturnBuffer( const StringBuilder& str );
|
||||
char* getReturnBuffer(const String& str);
|
||||
char* getReturnBuffer(const StringBuilder& str);
|
||||
|
||||
char* getArgBuffer(U32 bufferSize);
|
||||
char* getFloatArg(F64 arg);
|
||||
char* getIntArg (S32 arg);
|
||||
char* getIntArg(S32 arg);
|
||||
char* getBoolArg(bool arg);
|
||||
char* getStringArg( const char* arg );
|
||||
char* getStringArg( const String& arg );
|
||||
char* getStringArg(const char* arg);
|
||||
char* getStringArg(const String& arg);
|
||||
/// @}
|
||||
|
||||
/// @name Namespaces
|
||||
|
|
@ -877,7 +879,7 @@ namespace Con
|
|||
/// @name Instant Group
|
||||
/// @{
|
||||
|
||||
void pushInstantGroup( String name = String() );
|
||||
void pushInstantGroup(String name = String());
|
||||
void popInstantGroup();
|
||||
|
||||
/// @}
|
||||
|
|
@ -915,7 +917,7 @@ namespace Con
|
|||
template<typename R, typename ...ArgTs>
|
||||
ConsoleValueRef executef(R r, ArgTs ...argTs)
|
||||
{
|
||||
_EngineConsoleExecCallbackHelper<R> callback( r );
|
||||
_EngineConsoleExecCallbackHelper<R> callback(r);
|
||||
return callback.template call<ConsoleValueRef>(argTs...);
|
||||
}
|
||||
/// }
|
||||
|
|
@ -931,25 +933,25 @@ struct ConsoleFunctionHeader
|
|||
{
|
||||
/// Return type string.
|
||||
const char* mReturnString;
|
||||
|
||||
|
||||
/// List of arguments taken by the function. Used for documentation.
|
||||
const char* mArgString;
|
||||
|
||||
|
||||
/// List of default argument values. Used for documentation.
|
||||
const char* mDefaultArgString;
|
||||
|
||||
|
||||
/// Whether this is a static method in a class.
|
||||
bool mIsStatic;
|
||||
|
||||
|
||||
ConsoleFunctionHeader(
|
||||
const char* returnString,
|
||||
const char* argString,
|
||||
const char* defaultArgString,
|
||||
bool isStatic = false )
|
||||
: mReturnString( returnString ),
|
||||
mArgString( argString ),
|
||||
mDefaultArgString( defaultArgString ),
|
||||
mIsStatic( isStatic ) {}
|
||||
bool isStatic = false)
|
||||
: mReturnString(returnString),
|
||||
mArgString(argString),
|
||||
mDefaultArgString(defaultArgString),
|
||||
mIsStatic(isStatic) {}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -969,7 +971,7 @@ public:
|
|||
///
|
||||
/// @ref console_autodoc
|
||||
/// @{
|
||||
|
||||
|
||||
StringCallback sc; ///< A function/method that returns a string.
|
||||
IntCallback ic; ///< A function/method that returns an int.
|
||||
FloatCallback fc; ///< A function/method that returns a float.
|
||||
|
|
@ -979,18 +981,18 @@ public:
|
|||
bool ns; ///< Indicates that this is a namespace marker.
|
||||
/// @deprecated Unused.
|
||||
bool callback; ///< Is this a callback into script?
|
||||
|
||||
/// @}
|
||||
|
||||
/// Minimum number of arguments expected by the function.
|
||||
/// @}
|
||||
|
||||
/// Minimum number of arguments expected by the function.
|
||||
S32 mina;
|
||||
|
||||
|
||||
/// Maximum number of arguments accepted by the funtion. Zero for varargs.
|
||||
S32 maxa;
|
||||
|
||||
|
||||
/// Name of the function/method.
|
||||
const char* funcName;
|
||||
|
||||
|
||||
/// Name of the class namespace to which to add the method.
|
||||
const char* className;
|
||||
|
||||
|
|
@ -999,10 +1001,10 @@ public:
|
|||
|
||||
/// Whether this is a TORQUE_TOOLS only function.
|
||||
bool toolOnly;
|
||||
|
||||
|
||||
/// The extended function header.
|
||||
ConsoleFunctionHeader* header;
|
||||
|
||||
|
||||
/// @name ConsoleConstructor Innards
|
||||
///
|
||||
/// The ConsoleConstructor class is used as the backend for the ConsoleFunction() and
|
||||
|
|
@ -1067,7 +1069,7 @@ public:
|
|||
ConsoleConstructor *next;
|
||||
static ConsoleConstructor *first;
|
||||
|
||||
void init( const char* cName, const char* fName, const char *usg, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
void init(const char* cName, const char* fName, const char *usg, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
|
||||
static void setup();
|
||||
|
||||
|
|
@ -1079,12 +1081,12 @@ public:
|
|||
/// @name Basic Console Constructors
|
||||
/// @{
|
||||
|
||||
ConsoleConstructor( const char* className, const char* funcName, StringCallback sfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
ConsoleConstructor( const char* className, const char* funcName, IntCallback ifunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
ConsoleConstructor( const char* className, const char* funcName, FloatCallback ffunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
ConsoleConstructor( const char* className, const char* funcName, VoidCallback vfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
ConsoleConstructor( const char* className, const char* funcName, BoolCallback bfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
|
||||
ConsoleConstructor(const char* className, const char* funcName, StringCallback sfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
ConsoleConstructor(const char* className, const char* funcName, IntCallback ifunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
ConsoleConstructor(const char* className, const char* funcName, FloatCallback ffunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
ConsoleConstructor(const char* className, const char* funcName, VoidCallback vfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
ConsoleConstructor(const char* className, const char* funcName, BoolCallback bfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
|
||||
/// @}
|
||||
|
||||
/// @name Magic Console Constructors
|
||||
|
|
@ -1097,10 +1099,10 @@ public:
|
|||
///
|
||||
/// @see Con::markCommandGroup
|
||||
/// @ref console_autodoc
|
||||
ConsoleConstructor( const char *className, const char *groupName, const char* usage );
|
||||
ConsoleConstructor(const char *className, const char *groupName, const char* usage);
|
||||
|
||||
/// Indicates a callback declared with the DECLARE_SCRIPT_CALLBACK macro and friends.
|
||||
ConsoleConstructor( const char *className, const char *callbackName, const char *usage, ConsoleFunctionHeader* header );
|
||||
ConsoleConstructor(const char *className, const char *callbackName, const char *usage, ConsoleFunctionHeader* header);
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
|
@ -1112,25 +1114,25 @@ struct ConsoleDocFragment
|
|||
/// The class in which to put the fragment. If NULL, the fragment
|
||||
/// will be placed globally.
|
||||
const char* mClass;
|
||||
|
||||
|
||||
/// The definition to output for this fragment. NULL for fragments
|
||||
/// not associated with a definition.
|
||||
const char* mDefinition;
|
||||
|
||||
|
||||
/// The documentation text.
|
||||
const char* mText;
|
||||
|
||||
|
||||
/// Next fragment in the global link chain.
|
||||
ConsoleDocFragment* mNext;
|
||||
|
||||
|
||||
/// First fragment in the global link chain.
|
||||
static ConsoleDocFragment* smFirst;
|
||||
|
||||
ConsoleDocFragment( const char* text, const char* inClass = NULL, const char* definition = NULL )
|
||||
: mClass( inClass ),
|
||||
mDefinition( definition ),
|
||||
mText( text ),
|
||||
mNext( smFirst )
|
||||
|
||||
ConsoleDocFragment(const char* text, const char* inClass = NULL, const char* definition = NULL)
|
||||
: mClass(inClass),
|
||||
mDefinition(definition),
|
||||
mText(text),
|
||||
mNext(smFirst)
|
||||
{
|
||||
smFirst = this;
|
||||
}
|
||||
|
|
@ -1229,7 +1231,7 @@ public:
|
|||
|
||||
# define ConsoleMethodGroupEnd(className, groupName) \
|
||||
static ConsoleConstructor cc_##className##_##groupName##_GroupEnd(#className,#groupName,NULL)
|
||||
|
||||
|
||||
/// Add a fragment of auto-doc text to the console API reference.
|
||||
/// @note There can only be one ConsoleDoc per source file.
|
||||
# define ConsoleDoc( text ) \
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ void printGroupStart(const char * aName, const char * aDocs)
|
|||
Con::printf(" /*! */");
|
||||
}
|
||||
|
||||
void printClassMember(const bool isDeprec, const char * aType, const char * aName, const char * aDocs)
|
||||
void printClassMember(const bool isDeprec, const char * aType, const char * aName, const char * aDocs, S32 aElementCount)
|
||||
{
|
||||
Con::printf(" /*!");
|
||||
|
||||
|
|
@ -200,7 +200,14 @@ void printClassMember(const bool isDeprec, const char * aType, const char * aNam
|
|||
|
||||
Con::printf(" */");
|
||||
|
||||
Con::printf(" %s %s;", isDeprec ? "deprecated" : aType, aName);
|
||||
if (aElementCount == 1)
|
||||
{
|
||||
Con::printf(" %s %s;", isDeprec ? "deprecated" : aType, aName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Con::printf(" %s %s[%i];", isDeprec ? "deprecated" : aType, aName, aElementCount);
|
||||
}
|
||||
}
|
||||
|
||||
void printGroupEnd()
|
||||
|
|
@ -235,8 +242,17 @@ void Namespace::printNamespaceEntries(Namespace * g, bool dumpScript, bool dumpE
|
|||
// If it's a function
|
||||
if( eType >= Entry::ConsoleFunctionType )
|
||||
{
|
||||
printClassMethod(true, typeNames[eType], funcName, ewalk->getArgumentsString().c_str(),
|
||||
ewalk->getDocString().c_str());
|
||||
if (ewalk->mHeader != NULL)
|
||||
{
|
||||
// The function was defined with types, so we can print out the actual return type
|
||||
printClassMethod(true, ewalk->mHeader->mReturnString, funcName, ewalk->getArgumentsString().c_str(),
|
||||
ewalk->getDocString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
printClassMethod(true, typeNames[eType], funcName, (ewalk->getArgumentsString() + "...").c_str(),
|
||||
ewalk->getDocString().c_str());
|
||||
}
|
||||
}
|
||||
else if(ewalk->mType == Entry::GroupMarker)
|
||||
{
|
||||
|
|
@ -416,7 +432,8 @@ void Namespace::dumpClasses( bool dumpScript, bool dumpEngine )
|
|||
true,
|
||||
"<deprecated>",
|
||||
(*fieldList)[j].pFieldname,
|
||||
(*fieldList)[j].pFieldDocs
|
||||
(*fieldList)[j].pFieldDocs,
|
||||
(*fieldList)[j].elementCount
|
||||
);
|
||||
}
|
||||
else
|
||||
|
|
@ -427,7 +444,8 @@ void Namespace::dumpClasses( bool dumpScript, bool dumpEngine )
|
|||
false,
|
||||
cbt ? cbt->getTypeClassName() : "<unknown>",
|
||||
(*fieldList)[j].pFieldname,
|
||||
(*fieldList)[j].pFieldDocs
|
||||
(*fieldList)[j].pFieldDocs,
|
||||
(*fieldList)[j].elementCount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -24,22 +24,21 @@
|
|||
#define _CONSOLEINTERNAL_H_
|
||||
|
||||
#ifndef _STRINGFUNCTIONS_H_
|
||||
#include "core/strings/stringFunctions.h"
|
||||
#include "core/strings/stringFunctions.h"
|
||||
#endif
|
||||
#ifndef _STRINGTABLE_H_
|
||||
#include "core/stringTable.h"
|
||||
#include "core/stringTable.h"
|
||||
#endif
|
||||
#ifndef _CONSOLETYPES_H
|
||||
#include "console/consoleTypes.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#endif
|
||||
#ifndef _CONSOLEOBJECT_H_
|
||||
#include "console/simObject.h"
|
||||
#include "console/simObject.h"
|
||||
#endif
|
||||
#ifndef _DATACHUNKER_H_
|
||||
#include "core/dataChunker.h"
|
||||
#include "core/dataChunker.h"
|
||||
#endif
|
||||
|
||||
|
||||
/// @ingroup console_system Console System
|
||||
/// @{
|
||||
|
||||
|
|
@ -55,222 +54,222 @@ class AbstractClassRep;
|
|||
/// Namespaces are used for dispatching calls in the console system.
|
||||
class Namespace
|
||||
{
|
||||
enum {
|
||||
MaxActivePackages = 512,
|
||||
enum {
|
||||
MaxActivePackages = 512,
|
||||
};
|
||||
|
||||
static U32 mNumActivePackages;
|
||||
static U32 mOldNumActivePackages;
|
||||
static StringTableEntry mActivePackages[MaxActivePackages];
|
||||
|
||||
public:
|
||||
StringTableEntry mName;
|
||||
StringTableEntry mPackage;
|
||||
|
||||
Namespace *mParent;
|
||||
Namespace *mNext;
|
||||
AbstractClassRep *mClassRep;
|
||||
U32 mRefCountToParent;
|
||||
|
||||
const char* mUsage;
|
||||
|
||||
/// Script defined usage strings need to be cleaned up. This
|
||||
/// field indicates whether or not the usage was set from script.
|
||||
bool mCleanUpUsage;
|
||||
|
||||
/// A function entry in the namespace.
|
||||
struct Entry
|
||||
{
|
||||
enum
|
||||
{
|
||||
ScriptCallbackType = -3,
|
||||
GroupMarker = -2,
|
||||
InvalidFunctionType = -1,
|
||||
ConsoleFunctionType,
|
||||
StringCallbackType,
|
||||
IntCallbackType,
|
||||
FloatCallbackType,
|
||||
VoidCallbackType,
|
||||
BoolCallbackType
|
||||
};
|
||||
|
||||
static U32 mNumActivePackages;
|
||||
static U32 mOldNumActivePackages;
|
||||
static StringTableEntry mActivePackages[MaxActivePackages];
|
||||
/// Link back to the namespace to which the entry belongs.
|
||||
Namespace* mNamespace;
|
||||
|
||||
public:
|
||||
StringTableEntry mName;
|
||||
/// Next function entry in the hashtable link chain of the namespace.
|
||||
Entry* mNext;
|
||||
|
||||
/// Name of this function.
|
||||
StringTableEntry mFunctionName;
|
||||
|
||||
///
|
||||
S32 mType;
|
||||
|
||||
/// Min number of arguments expected by this function.
|
||||
S32 mMinArgs;
|
||||
|
||||
/// Max number of arguments expected by this function. If zero,
|
||||
/// function takes an arbitrary number of arguments.
|
||||
S32 mMaxArgs;
|
||||
|
||||
/// Name of the package to which this function belongs.
|
||||
StringTableEntry mPackage;
|
||||
|
||||
Namespace *mParent;
|
||||
Namespace *mNext;
|
||||
AbstractClassRep *mClassRep;
|
||||
U32 mRefCountToParent;
|
||||
|
||||
/// Whether this function is included only in TORQUE_TOOLS builds.
|
||||
bool mToolOnly;
|
||||
|
||||
/// Usage string for documentation.
|
||||
const char* mUsage;
|
||||
|
||||
/// Script defined usage strings need to be cleaned up. This
|
||||
/// field indicates whether or not the usage was set from script.
|
||||
bool mCleanUpUsage;
|
||||
|
||||
/// A function entry in the namespace.
|
||||
struct Entry
|
||||
{
|
||||
enum
|
||||
{
|
||||
ScriptCallbackType = -3,
|
||||
GroupMarker = -2,
|
||||
InvalidFunctionType = -1,
|
||||
ConsoleFunctionType,
|
||||
StringCallbackType,
|
||||
IntCallbackType,
|
||||
FloatCallbackType,
|
||||
VoidCallbackType,
|
||||
BoolCallbackType
|
||||
};
|
||||
/// Extended console function information.
|
||||
ConsoleFunctionHeader* mHeader;
|
||||
|
||||
/// Link back to the namespace to which the entry belongs.
|
||||
Namespace* mNamespace;
|
||||
|
||||
/// Next function entry in the hashtable link chain of the namespace.
|
||||
Entry* mNext;
|
||||
|
||||
/// Name of this function.
|
||||
StringTableEntry mFunctionName;
|
||||
|
||||
///
|
||||
S32 mType;
|
||||
|
||||
/// Min number of arguments expected by this function.
|
||||
S32 mMinArgs;
|
||||
|
||||
/// Max number of arguments expected by this function. If zero,
|
||||
/// function takes an arbitrary number of arguments.
|
||||
S32 mMaxArgs;
|
||||
|
||||
/// Name of the package to which this function belongs.
|
||||
StringTableEntry mPackage;
|
||||
|
||||
/// Whether this function is included only in TORQUE_TOOLS builds.
|
||||
bool mToolOnly;
|
||||
/// The compiled script code if this is a script function.
|
||||
CodeBlock* mCode;
|
||||
|
||||
/// Usage string for documentation.
|
||||
const char* mUsage;
|
||||
|
||||
/// Extended console function information.
|
||||
ConsoleFunctionHeader* mHeader;
|
||||
/// The offset in the compiled script code at which this function begins.
|
||||
U32 mFunctionOffset;
|
||||
|
||||
/// The compiled script code if this is a script function.
|
||||
CodeBlock* mCode;
|
||||
|
||||
/// The offset in the compiled script code at which this function begins.
|
||||
U32 mFunctionOffset;
|
||||
/// If it's a script function, this is the line of the declaration in code.
|
||||
/// @note 0 for functions read from legacy DSOs that have no line number information.
|
||||
U32 mFunctionLineNumber;
|
||||
|
||||
/// If it's a script function, this is the line of the declaration in code.
|
||||
/// @note 0 for functions read from legacy DSOs that have no line number information.
|
||||
U32 mFunctionLineNumber;
|
||||
|
||||
union CallbackUnion {
|
||||
StringCallback mStringCallbackFunc;
|
||||
IntCallback mIntCallbackFunc;
|
||||
VoidCallback mVoidCallbackFunc;
|
||||
FloatCallback mFloatCallbackFunc;
|
||||
BoolCallback mBoolCallbackFunc;
|
||||
const char *mGroupName;
|
||||
const char *mCallbackName;
|
||||
} cb;
|
||||
|
||||
Entry();
|
||||
|
||||
///
|
||||
void clear();
|
||||
union CallbackUnion {
|
||||
StringCallback mStringCallbackFunc;
|
||||
IntCallback mIntCallbackFunc;
|
||||
VoidCallback mVoidCallbackFunc;
|
||||
FloatCallback mFloatCallbackFunc;
|
||||
BoolCallback mBoolCallbackFunc;
|
||||
const char *mGroupName;
|
||||
const char *mCallbackName;
|
||||
} cb;
|
||||
|
||||
///
|
||||
ConsoleValueRef execute( S32 argc, ConsoleValueRef* argv, ExprEvalState* state );
|
||||
|
||||
/// Return a one-line documentation text string for the function.
|
||||
String getBriefDescription( String* outRemainingDocText = NULL ) const;
|
||||
|
||||
/// Get the auto-doc string for this function. This string does not included prototype information.
|
||||
String getDocString() const;
|
||||
|
||||
/// Return a string describing the arguments the function takes including default argument values.
|
||||
String getArgumentsString() const;
|
||||
Entry();
|
||||
|
||||
/// Return a full prototype string for the function including return type, function name,
|
||||
/// and arguments.
|
||||
String getPrototypeString() const;
|
||||
};
|
||||
|
||||
Entry* mEntryList;
|
||||
///
|
||||
void clear();
|
||||
|
||||
Entry** mHashTable;
|
||||
|
||||
U32 mHashSize;
|
||||
U32 mHashSequence; ///< @note The hash sequence is used by the autodoc console facility
|
||||
/// as a means of testing reference state.
|
||||
///
|
||||
ConsoleValueRef execute(S32 argc, ConsoleValueRef* argv, ExprEvalState* state);
|
||||
|
||||
Namespace();
|
||||
~Namespace();
|
||||
/// Return a one-line documentation text string for the function.
|
||||
String getBriefDescription(String* outRemainingDocText = NULL) const;
|
||||
|
||||
void addFunction( StringTableEntry name, CodeBlock* cb, U32 functionOffset, const char* usage = NULL, U32 lineNumber = 0 );
|
||||
void addCommand( StringTableEntry name, StringCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
void addCommand( StringTableEntry name, IntCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
void addCommand( StringTableEntry name, FloatCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
void addCommand( StringTableEntry name, VoidCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
void addCommand( StringTableEntry name, BoolCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
|
||||
/// Get the auto-doc string for this function. This string does not included prototype information.
|
||||
String getDocString() const;
|
||||
|
||||
void addScriptCallback( const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL );
|
||||
/// Return a string describing the arguments the function takes including default argument values.
|
||||
String getArgumentsString() const;
|
||||
|
||||
void markGroup(const char* name, const char* usage);
|
||||
char * lastUsage;
|
||||
/// Return a full prototype string for the function including return type, function name,
|
||||
/// and arguments.
|
||||
String getPrototypeString() const;
|
||||
};
|
||||
|
||||
/// Returns true if this namespace represents an engine defined
|
||||
/// class and is not just a script defined class namespace.
|
||||
bool isClass() const { return mClassRep && mClassRep->getNameSpace() == this; }
|
||||
Entry* mEntryList;
|
||||
|
||||
void getEntryList(VectorPtr<Entry *> *);
|
||||
Entry** mHashTable;
|
||||
|
||||
/// Return the name of this namespace.
|
||||
StringTableEntry getName() const { return mName; }
|
||||
U32 mHashSize;
|
||||
U32 mHashSequence; ///< @note The hash sequence is used by the autodoc console facility
|
||||
/// as a means of testing reference state.
|
||||
|
||||
/// Return the superordinate namespace to this namespace. Symbols are inherited from
|
||||
/// this namespace.
|
||||
Namespace* getParent() const { return mParent; }
|
||||
Namespace();
|
||||
~Namespace();
|
||||
|
||||
/// Return the topmost package in the parent hierarchy of this namespace
|
||||
/// that still refers to the same namespace. If packages are active and
|
||||
/// adding to this namespace, then they will be linked in-between the namespace
|
||||
/// they are adding to and its real parent namespace.
|
||||
Namespace* getPackageRoot()
|
||||
{
|
||||
Namespace* walk = this;
|
||||
while( walk->mParent && walk->mParent->mName == mName )
|
||||
walk = walk->mParent;
|
||||
void addFunction(StringTableEntry name, CodeBlock* cb, U32 functionOffset, const char* usage = NULL, U32 lineNumber = 0);
|
||||
void addCommand(StringTableEntry name, StringCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
void addCommand(StringTableEntry name, IntCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
void addCommand(StringTableEntry name, FloatCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
void addCommand(StringTableEntry name, VoidCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
void addCommand(StringTableEntry name, BoolCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
|
||||
return walk;
|
||||
}
|
||||
void addScriptCallback(const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL);
|
||||
|
||||
/// Return the package in which this namespace is defined.
|
||||
StringTableEntry getPackage() const { return mPackage; }
|
||||
void markGroup(const char* name, const char* usage);
|
||||
char * lastUsage;
|
||||
|
||||
/// Increase the count on the reference that this namespace
|
||||
/// holds to its parent.
|
||||
/// @note Must not be called on namespaces coming from packages.
|
||||
void incRefCountToParent()
|
||||
{
|
||||
AssertFatal( mPackage == NULL, "Namespace::incRefCountToParent - Must not be called on a namespace coming from a package!" );
|
||||
mRefCountToParent ++;
|
||||
}
|
||||
/// Returns true if this namespace represents an engine defined
|
||||
/// class and is not just a script defined class namespace.
|
||||
bool isClass() const { return mClassRep && mClassRep->getNameSpace() == this; }
|
||||
|
||||
/// Decrease the count on the reference that this namespace
|
||||
/// holds to its parent.
|
||||
/// @note Must not be called on namespaces coming from packages.
|
||||
void decRefCountToParent()
|
||||
{
|
||||
unlinkClass( NULL );
|
||||
}
|
||||
void getEntryList(VectorPtr<Entry *> *);
|
||||
|
||||
Entry *lookup(StringTableEntry name);
|
||||
Entry *lookupRecursive(StringTableEntry name);
|
||||
Entry *createLocalEntry(StringTableEntry name);
|
||||
void buildHashTable();
|
||||
void clearEntries();
|
||||
bool classLinkTo(Namespace *parent);
|
||||
bool unlinkClass(Namespace *parent);
|
||||
void getUniqueEntryLists( Namespace *other, VectorPtr<Entry *> *outThisList, VectorPtr<Entry *> *outOtherList );
|
||||
/// Return the name of this namespace.
|
||||
StringTableEntry getName() const { return mName; }
|
||||
|
||||
const char *tabComplete(const char *prevText, S32 baseLen, bool fForward);
|
||||
/// Return the superordinate namespace to this namespace. Symbols are inherited from
|
||||
/// this namespace.
|
||||
Namespace* getParent() const { return mParent; }
|
||||
|
||||
static U32 mCacheSequence;
|
||||
static DataChunker mCacheAllocator;
|
||||
static DataChunker mAllocator;
|
||||
static void trashCache();
|
||||
static Namespace *mNamespaceList;
|
||||
static Namespace *mGlobalNamespace;
|
||||
/// Return the topmost package in the parent hierarchy of this namespace
|
||||
/// that still refers to the same namespace. If packages are active and
|
||||
/// adding to this namespace, then they will be linked in-between the namespace
|
||||
/// they are adding to and its real parent namespace.
|
||||
Namespace* getPackageRoot()
|
||||
{
|
||||
Namespace* walk = this;
|
||||
while (walk->mParent && walk->mParent->mName == mName)
|
||||
walk = walk->mParent;
|
||||
|
||||
static void init();
|
||||
static void shutdown();
|
||||
static Namespace *global();
|
||||
return walk;
|
||||
}
|
||||
|
||||
static Namespace *find(StringTableEntry name, StringTableEntry package=NULL);
|
||||
/// Return the package in which this namespace is defined.
|
||||
StringTableEntry getPackage() const { return mPackage; }
|
||||
|
||||
static void activatePackage(StringTableEntry name);
|
||||
static void deactivatePackage(StringTableEntry name);
|
||||
static void deactivatePackageStack(StringTableEntry name);
|
||||
static void dumpClasses( bool dumpScript = true, bool dumpEngine = true );
|
||||
static void dumpFunctions( bool dumpScript = true, bool dumpEngine = true );
|
||||
static void printNamespaceEntries(Namespace * g, bool dumpScript = true, bool dumpEngine = true);
|
||||
static void unlinkPackages();
|
||||
static void relinkPackages();
|
||||
static bool isPackage(StringTableEntry name);
|
||||
static U32 getActivePackagesCount();
|
||||
static StringTableEntry getActivePackage(U32 index);
|
||||
/// Increase the count on the reference that this namespace
|
||||
/// holds to its parent.
|
||||
/// @note Must not be called on namespaces coming from packages.
|
||||
void incRefCountToParent()
|
||||
{
|
||||
AssertFatal(mPackage == NULL, "Namespace::incRefCountToParent - Must not be called on a namespace coming from a package!");
|
||||
mRefCountToParent++;
|
||||
}
|
||||
|
||||
/// Decrease the count on the reference that this namespace
|
||||
/// holds to its parent.
|
||||
/// @note Must not be called on namespaces coming from packages.
|
||||
void decRefCountToParent()
|
||||
{
|
||||
unlinkClass(NULL);
|
||||
}
|
||||
|
||||
Entry *lookup(StringTableEntry name);
|
||||
Entry *lookupRecursive(StringTableEntry name);
|
||||
Entry *createLocalEntry(StringTableEntry name);
|
||||
void buildHashTable();
|
||||
void clearEntries();
|
||||
bool classLinkTo(Namespace *parent);
|
||||
bool unlinkClass(Namespace *parent);
|
||||
void getUniqueEntryLists(Namespace *other, VectorPtr<Entry *> *outThisList, VectorPtr<Entry *> *outOtherList);
|
||||
|
||||
const char *tabComplete(const char *prevText, S32 baseLen, bool fForward);
|
||||
|
||||
static U32 mCacheSequence;
|
||||
static DataChunker mCacheAllocator;
|
||||
static DataChunker mAllocator;
|
||||
static void trashCache();
|
||||
static Namespace *mNamespaceList;
|
||||
static Namespace *mGlobalNamespace;
|
||||
|
||||
static void init();
|
||||
static void shutdown();
|
||||
static Namespace *global();
|
||||
|
||||
static Namespace *find(StringTableEntry name, StringTableEntry package = NULL);
|
||||
|
||||
static void activatePackage(StringTableEntry name);
|
||||
static void deactivatePackage(StringTableEntry name);
|
||||
static void deactivatePackageStack(StringTableEntry name);
|
||||
static void dumpClasses(bool dumpScript = true, bool dumpEngine = true);
|
||||
static void dumpFunctions(bool dumpScript = true, bool dumpEngine = true);
|
||||
static void printNamespaceEntries(Namespace * g, bool dumpScript = true, bool dumpEngine = true);
|
||||
static void unlinkPackages();
|
||||
static void relinkPackages();
|
||||
static bool isPackage(StringTableEntry name);
|
||||
static U32 getActivePackagesCount();
|
||||
static StringTableEntry getActivePackage(U32 index);
|
||||
};
|
||||
|
||||
typedef VectorPtr<Namespace::Entry *>::iterator NamespaceEntryListIterator;
|
||||
|
|
@ -292,10 +291,10 @@ public:
|
|||
/// The optional notification signal called when
|
||||
/// a value is assigned to this variable.
|
||||
NotifySignal *notify;
|
||||
|
||||
|
||||
/// Usage doc string.
|
||||
const char* mUsage;
|
||||
|
||||
|
||||
/// Whether this is a constant that cannot be assigned to.
|
||||
bool mIsConstant;
|
||||
|
||||
|
|
@ -309,16 +308,16 @@ public:
|
|||
mIsConstant = false;
|
||||
value.init();
|
||||
}
|
||||
|
||||
|
||||
Entry(StringTableEntry name);
|
||||
~Entry();
|
||||
|
||||
|
||||
Entry *mNext;
|
||||
|
||||
|
||||
void reset() {
|
||||
name = NULL;
|
||||
value.cleanup();
|
||||
if ( notify )
|
||||
if (notify)
|
||||
delete notify;
|
||||
}
|
||||
|
||||
|
|
@ -339,63 +338,63 @@ public:
|
|||
|
||||
void setIntValue(U32 val)
|
||||
{
|
||||
if( mIsConstant )
|
||||
if (mIsConstant)
|
||||
{
|
||||
Con::errorf( "Cannot assign value to constant '%s'.", name );
|
||||
Con::errorf("Cannot assign value to constant '%s'.", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
value.setIntValue(val);
|
||||
|
||||
// Fire off the notification if we have one.
|
||||
if ( notify )
|
||||
if (notify)
|
||||
notify->trigger();
|
||||
}
|
||||
|
||||
void setFloatValue(F32 val)
|
||||
{
|
||||
if( mIsConstant )
|
||||
if (mIsConstant)
|
||||
{
|
||||
Con::errorf( "Cannot assign value to constant '%s'.", name );
|
||||
Con::errorf("Cannot assign value to constant '%s'.", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
value.setFloatValue(val);
|
||||
|
||||
// Fire off the notification if we have one.
|
||||
if ( notify )
|
||||
if (notify)
|
||||
notify->trigger();
|
||||
}
|
||||
|
||||
void setStringStackPtrValue(StringStackPtr newValue)
|
||||
{
|
||||
if( mIsConstant )
|
||||
if (mIsConstant)
|
||||
{
|
||||
Con::errorf( "Cannot assign value to constant '%s'.", name );
|
||||
Con::errorf("Cannot assign value to constant '%s'.", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
value.setStringStackPtrValue(newValue);
|
||||
|
||||
|
||||
|
||||
|
||||
// Fire off the notification if we have one.
|
||||
if ( notify )
|
||||
if (notify)
|
||||
notify->trigger();
|
||||
}
|
||||
|
||||
void setStringValue(const char *newValue)
|
||||
{
|
||||
if( mIsConstant )
|
||||
if (mIsConstant)
|
||||
{
|
||||
Con::errorf( "Cannot assign value to constant '%s'.", name );
|
||||
Con::errorf("Cannot assign value to constant '%s'.", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
value.setStringValue(newValue);
|
||||
|
||||
|
||||
|
||||
|
||||
// Fire off the notification if we have one.
|
||||
if ( notify )
|
||||
if (notify)
|
||||
notify->trigger();
|
||||
}
|
||||
};
|
||||
|
|
@ -407,9 +406,9 @@ public:
|
|||
S32 count;
|
||||
Entry **data;
|
||||
FreeListChunker< Entry > mChunker;
|
||||
|
||||
HashTableData( Dictionary* owner )
|
||||
: owner( owner ), size( 0 ), count( 0 ), data( NULL ) {}
|
||||
|
||||
HashTableData(Dictionary* owner)
|
||||
: owner(owner), size(0), count(0), data(NULL) {}
|
||||
};
|
||||
|
||||
HashTableData* hashTable;
|
||||
|
|
@ -426,13 +425,13 @@ public:
|
|||
|
||||
Entry *lookup(StringTableEntry name);
|
||||
Entry *add(StringTableEntry name);
|
||||
void setState(ExprEvalState *state, Dictionary* ref=NULL);
|
||||
void setState(ExprEvalState *state, Dictionary* ref = NULL);
|
||||
void remove(Entry *);
|
||||
void reset();
|
||||
|
||||
void exportVariables( const char *varString, const char *fileName, bool append );
|
||||
void exportVariables( const char *varString, Vector<String> *names, Vector<String> *values );
|
||||
void deleteVariables( const char *varString );
|
||||
void exportVariables(const char *varString, const char *fileName, bool append);
|
||||
void exportVariables(const char *varString, Vector<String> *names, Vector<String> *values);
|
||||
void deleteVariables(const char *varString);
|
||||
|
||||
void setVariable(StringTableEntry name, const char *value);
|
||||
const char *getVariable(StringTableEntry name, bool *valid = NULL);
|
||||
|
|
@ -449,19 +448,19 @@ public:
|
|||
}
|
||||
|
||||
/// @see Con::addVariable
|
||||
Entry* addVariable( const char *name,
|
||||
S32 type,
|
||||
void *dataPtr,
|
||||
const char* usage );
|
||||
Entry* addVariable(const char *name,
|
||||
S32 type,
|
||||
void *dataPtr,
|
||||
const char* usage);
|
||||
|
||||
/// @see Con::removeVariable
|
||||
bool removeVariable(StringTableEntry name);
|
||||
|
||||
/// @see Con::addVariableNotify
|
||||
void addVariableNotify( const char *name, const Con::NotifyDelegate &callback );
|
||||
void addVariableNotify(const char *name, const Con::NotifyDelegate &callback);
|
||||
|
||||
/// @see Con::removeVariableNotify
|
||||
void removeVariableNotify( const char *name, const Con::NotifyDelegate &callback );
|
||||
void removeVariableNotify(const char *name, const Con::NotifyDelegate &callback);
|
||||
|
||||
/// Return the best tab completion for prevText, with the length
|
||||
/// of the pre-tab string in baseLen.
|
||||
|
|
@ -520,15 +519,15 @@ public:
|
|||
/// Puts a reference to an existing stack frame
|
||||
/// on the top of the stack.
|
||||
void pushFrameRef(S32 stackIndex);
|
||||
|
||||
|
||||
U32 getStackDepth() const
|
||||
{
|
||||
return mStackDepth;
|
||||
}
|
||||
|
||||
|
||||
Dictionary& getCurrentFrame()
|
||||
{
|
||||
return *( stack[ mStackDepth - 1 ] );
|
||||
return *(stack[mStackDepth - 1]);
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ SimNameDictionary::~SimNameDictionary()
|
|||
|
||||
void SimNameDictionary::insert(SimObject* obj)
|
||||
{
|
||||
if(!obj || !obj->objectName)
|
||||
if (!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
SimObject* checkForDup = find(obj->objectName);
|
||||
|
|
@ -55,47 +55,47 @@ void SimNameDictionary::insert(SimObject* obj)
|
|||
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
if(!hashTable)
|
||||
if (!hashTable)
|
||||
{
|
||||
hashTable = new SimObject *[DefaultTableSize];
|
||||
hashTableSize = DefaultTableSize;
|
||||
hashEntryCount = 0;
|
||||
|
||||
dMemset( hashTable, 0, sizeof( *hashTable ) * DefaultTableSize );
|
||||
|
||||
dMemset(hashTable, 0, sizeof(*hashTable) * DefaultTableSize);
|
||||
}
|
||||
|
||||
|
||||
S32 idx = HashPointer(obj->objectName) % hashTableSize;
|
||||
obj->nextNameObject = hashTable[idx];
|
||||
hashTable[idx] = obj;
|
||||
hashEntryCount++;
|
||||
|
||||
|
||||
// Rehash if necessary.
|
||||
|
||||
if( hashEntryCount > hashTableSize )
|
||||
if (hashEntryCount > hashTableSize)
|
||||
{
|
||||
// Allocate new table.
|
||||
|
||||
|
||||
U32 newHashTableSize = hashTableSize * 2 + 1;
|
||||
SimObject** newHashTable = new SimObject *[ newHashTableSize ];
|
||||
dMemset( newHashTable, 0, sizeof( newHashTable[ 0 ] ) * newHashTableSize );
|
||||
|
||||
SimObject** newHashTable = new SimObject *[newHashTableSize];
|
||||
dMemset(newHashTable, 0, sizeof(newHashTable[0]) * newHashTableSize);
|
||||
|
||||
// Move entries over.
|
||||
|
||||
for( U32 i = 0; i < hashTableSize; ++ i )
|
||||
for( SimObject* object = hashTable[ i ]; object != NULL; )
|
||||
for (U32 i = 0; i < hashTableSize; ++i)
|
||||
for (SimObject* object = hashTable[i]; object != NULL; )
|
||||
{
|
||||
SimObject* next = object->nextNameObject;
|
||||
|
||||
idx = HashPointer( object->objectName ) % newHashTableSize;
|
||||
object->nextNameObject = newHashTable[ idx ];
|
||||
newHashTable[ idx ] = object;
|
||||
|
||||
idx = HashPointer(object->objectName) % newHashTableSize;
|
||||
object->nextNameObject = newHashTable[idx];
|
||||
newHashTable[idx] = object;
|
||||
|
||||
object = next;
|
||||
}
|
||||
|
||||
|
||||
// Switch tables.
|
||||
|
||||
delete [] hashTable;
|
||||
|
||||
delete[] hashTable;
|
||||
hashTable = newHashTable;
|
||||
hashTableSize = newHashTableSize;
|
||||
}
|
||||
|
|
@ -109,16 +109,16 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
|
|||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
// NULL is a valid lookup - it will always return NULL
|
||||
if(!hashTable)
|
||||
if (!hashTable)
|
||||
return NULL;
|
||||
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
S32 idx = HashPointer(name) % hashTableSize;
|
||||
SimObject *walk = hashTable[idx];
|
||||
while(walk)
|
||||
while (walk)
|
||||
{
|
||||
if(walk->objectName == name)
|
||||
if (walk->objectName == name)
|
||||
{
|
||||
Mutex::unlockMutex(mutex);
|
||||
return walk;
|
||||
|
|
@ -129,28 +129,28 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
|
|||
Mutex::unlockMutex(mutex);
|
||||
return NULL;
|
||||
#else
|
||||
Mutex::lockMutex(mutex);
|
||||
StringDictDef::iterator it = root.find(name);
|
||||
SimObject* f = (it == root.end() ? NULL : it->second);
|
||||
Mutex::unlockMutex(mutex);
|
||||
return f;
|
||||
Mutex::lockMutex(mutex);
|
||||
StringDictDef::iterator it = root.find(name);
|
||||
SimObject* f = (it == root.end() ? NULL : it->second);
|
||||
Mutex::unlockMutex(mutex);
|
||||
return f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimNameDictionary::remove(SimObject* obj)
|
||||
{
|
||||
if(!obj || !obj->objectName)
|
||||
if (!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||
while(*walk)
|
||||
while (*walk)
|
||||
{
|
||||
if(*walk == obj)
|
||||
if (*walk == obj)
|
||||
{
|
||||
*walk = obj->nextNameObject;
|
||||
obj->nextNameObject = (SimObject*)-1;
|
||||
obj->nextNameObject = nullptr;
|
||||
hashEntryCount--;
|
||||
|
||||
Mutex::unlockMutex(mutex);
|
||||
|
|
@ -164,7 +164,7 @@ void SimNameDictionary::remove(SimObject* obj)
|
|||
root.erase(name);
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -174,8 +174,8 @@ SimManagerNameDictionary::SimManagerNameDictionary()
|
|||
hashTable = new SimObject *[DefaultTableSize];
|
||||
hashTableSize = DefaultTableSize;
|
||||
hashEntryCount = 0;
|
||||
|
||||
dMemset( hashTable, 0, sizeof( hashTable[ 0 ] ) * hashTableSize );
|
||||
|
||||
dMemset(hashTable, 0, sizeof(hashTable[0]) * hashTableSize);
|
||||
#endif
|
||||
mutex = Mutex::createMutex();
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ SimManagerNameDictionary::~SimManagerNameDictionary()
|
|||
|
||||
void SimManagerNameDictionary::insert(SimObject* obj)
|
||||
{
|
||||
if(!obj || !obj->objectName)
|
||||
if (!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
|
|
@ -199,34 +199,34 @@ void SimManagerNameDictionary::insert(SimObject* obj)
|
|||
obj->nextManagerNameObject = hashTable[idx];
|
||||
hashTable[idx] = obj;
|
||||
hashEntryCount++;
|
||||
|
||||
|
||||
// Rehash if necessary.
|
||||
|
||||
if( hashEntryCount > hashTableSize )
|
||||
if (hashEntryCount > hashTableSize)
|
||||
{
|
||||
// Allocate new table.
|
||||
|
||||
|
||||
U32 newHashTableSize = hashTableSize * 2 + 1;
|
||||
SimObject** newHashTable = new SimObject *[ newHashTableSize ];
|
||||
dMemset( newHashTable, 0, sizeof( newHashTable[ 0 ] ) * newHashTableSize );
|
||||
|
||||
SimObject** newHashTable = new SimObject *[newHashTableSize];
|
||||
dMemset(newHashTable, 0, sizeof(newHashTable[0]) * newHashTableSize);
|
||||
|
||||
// Move entries over.
|
||||
|
||||
for( U32 i = 0; i < hashTableSize; ++ i )
|
||||
for( SimObject* object = hashTable[ i ]; object != NULL; )
|
||||
for (U32 i = 0; i < hashTableSize; ++i)
|
||||
for (SimObject* object = hashTable[i]; object != NULL; )
|
||||
{
|
||||
SimObject* next = object->nextManagerNameObject;
|
||||
|
||||
idx = HashPointer( object->objectName ) % newHashTableSize;
|
||||
object->nextManagerNameObject = newHashTable[ idx ];
|
||||
newHashTable[ idx ] = object;
|
||||
|
||||
idx = HashPointer(object->objectName) % newHashTableSize;
|
||||
object->nextManagerNameObject = newHashTable[idx];
|
||||
newHashTable[idx] = object;
|
||||
|
||||
object = next;
|
||||
}
|
||||
|
||||
|
||||
// Switch tables.
|
||||
|
||||
delete [] hashTable;
|
||||
|
||||
delete[] hashTable;
|
||||
hashTable = newHashTable;
|
||||
hashTableSize = newHashTableSize;
|
||||
}
|
||||
|
|
@ -245,9 +245,9 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
|||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = HashPointer(name) % hashTableSize;
|
||||
SimObject *walk = hashTable[idx];
|
||||
while(walk)
|
||||
while (walk)
|
||||
{
|
||||
if(walk->objectName == name)
|
||||
if (walk->objectName == name)
|
||||
{
|
||||
Mutex::unlockMutex(mutex);
|
||||
return walk;
|
||||
|
|
@ -267,19 +267,19 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
|||
|
||||
void SimManagerNameDictionary::remove(SimObject* obj)
|
||||
{
|
||||
if(!obj || !obj->objectName)
|
||||
if (!obj || !obj->objectName)
|
||||
return;
|
||||
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||
while(*walk)
|
||||
while (*walk)
|
||||
{
|
||||
if(*walk == obj)
|
||||
if (*walk == obj)
|
||||
{
|
||||
*walk = obj->nextManagerNameObject;
|
||||
obj->nextManagerNameObject = (SimObject*)-1;
|
||||
obj->nextManagerNameObject = nullptr;
|
||||
hashEntryCount--;
|
||||
|
||||
Mutex::unlockMutex(mutex);
|
||||
|
|
@ -293,7 +293,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
|||
root.erase(name);
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
@ -301,7 +301,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
|||
SimIdDictionary::SimIdDictionary()
|
||||
{
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
dMemset( table, 0, sizeof( table[ 0 ] ) * DefaultTableSize );
|
||||
dMemset(table, 0, sizeof(table[0]) * DefaultTableSize);
|
||||
#endif
|
||||
mutex = Mutex::createMutex();
|
||||
}
|
||||
|
|
@ -322,7 +322,7 @@ void SimIdDictionary::insert(SimObject* obj)
|
|||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = obj->getId() & TableBitMask;
|
||||
obj->nextIdObject = table[idx];
|
||||
AssertFatal( obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!" );
|
||||
AssertFatal(obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!");
|
||||
table[idx] = obj;
|
||||
#else
|
||||
root[obj->getId()] = obj;
|
||||
|
|
@ -336,9 +336,9 @@ SimObject* SimIdDictionary::find(S32 id)
|
|||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = id & TableBitMask;
|
||||
SimObject *walk = table[idx];
|
||||
while(walk)
|
||||
while (walk)
|
||||
{
|
||||
if(walk->getId() == U32(id))
|
||||
if (walk->getId() == U32(id))
|
||||
{
|
||||
Mutex::unlockMutex(mutex);
|
||||
return walk;
|
||||
|
|
@ -364,9 +364,9 @@ void SimIdDictionary::remove(SimObject* obj)
|
|||
Mutex::lockMutex(mutex);
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
SimObject **walk = &table[obj->getId() & TableBitMask];
|
||||
while(*walk && *walk != obj)
|
||||
while (*walk && *walk != obj)
|
||||
walk = &((*walk)->nextIdObject);
|
||||
if(*walk)
|
||||
if (*walk)
|
||||
*walk = obj->nextIdObject;
|
||||
#else
|
||||
root.erase(obj->getId());
|
||||
|
|
|
|||
|
|
@ -36,20 +36,20 @@ SimFieldDictionary::Entry *SimFieldDictionary::smFreeList = NULL;
|
|||
|
||||
static Chunker<SimFieldDictionary::Entry> fieldChunker;
|
||||
|
||||
U32 SimFieldDictionary::getHashValue( StringTableEntry slotName )
|
||||
U32 SimFieldDictionary::getHashValue(StringTableEntry slotName)
|
||||
{
|
||||
return HashPointer( slotName ) % HashTableSize;
|
||||
return HashPointer(slotName) % HashTableSize;
|
||||
}
|
||||
|
||||
U32 SimFieldDictionary::getHashValue( const String& fieldName )
|
||||
U32 SimFieldDictionary::getHashValue(const String& fieldName)
|
||||
{
|
||||
return getHashValue( StringTable->insert( fieldName ) );
|
||||
return getHashValue(StringTable->insert(fieldName));
|
||||
}
|
||||
|
||||
SimFieldDictionary::Entry *SimFieldDictionary::addEntry( U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value )
|
||||
SimFieldDictionary::Entry *SimFieldDictionary::addEntry(U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value)
|
||||
{
|
||||
Entry* ret;
|
||||
if(smFreeList)
|
||||
if (smFreeList)
|
||||
{
|
||||
ret = smFreeList;
|
||||
smFreeList = ret->next;
|
||||
|
|
@ -57,14 +57,14 @@ SimFieldDictionary::Entry *SimFieldDictionary::addEntry( U32 bucket, StringTable
|
|||
else
|
||||
ret = fieldChunker.alloc();
|
||||
|
||||
ret->next = mHashTable[ bucket ];
|
||||
ret->slotName = slotName;
|
||||
ret->type = type;
|
||||
ret->value = value;
|
||||
ret->next = mHashTable[bucket];
|
||||
ret->slotName = slotName;
|
||||
ret->type = type;
|
||||
ret->value = value;
|
||||
|
||||
mHashTable[ bucket ] = ret;
|
||||
mNumFields ++;
|
||||
mVersion ++;
|
||||
mHashTable[bucket] = ret;
|
||||
mNumFields++;
|
||||
mVersion++;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -74,37 +74,37 @@ void SimFieldDictionary::freeEntry(SimFieldDictionary::Entry *ent)
|
|||
ent->next = smFreeList;
|
||||
smFreeList = ent;
|
||||
|
||||
mNumFields --;
|
||||
mNumFields--;
|
||||
}
|
||||
|
||||
SimFieldDictionary::SimFieldDictionary()
|
||||
: mNumFields( 0 ),
|
||||
mVersion( 0 )
|
||||
: mNumFields(0),
|
||||
mVersion(0)
|
||||
{
|
||||
dMemset( mHashTable, 0, sizeof( mHashTable ) );
|
||||
dMemset(mHashTable, 0, sizeof(mHashTable));
|
||||
}
|
||||
|
||||
SimFieldDictionary::~SimFieldDictionary()
|
||||
{
|
||||
for(U32 i = 0; i < HashTableSize; i++)
|
||||
for (U32 i = 0; i < HashTableSize; i++)
|
||||
{
|
||||
for(Entry *walk = mHashTable[i]; walk;)
|
||||
for (Entry *walk = mHashTable[i]; walk;)
|
||||
{
|
||||
Entry *temp = walk;
|
||||
walk = temp->next;
|
||||
|
||||
if( temp->value )
|
||||
if (temp->value)
|
||||
dFree(temp->value);
|
||||
freeEntry(temp);
|
||||
}
|
||||
}
|
||||
|
||||
AssertFatal( mNumFields == 0, "Incorrect count on field dictionary" );
|
||||
AssertFatal(mNumFields == 0, "Incorrect count on field dictionary");
|
||||
}
|
||||
|
||||
void SimFieldDictionary::setFieldType(StringTableEntry slotName, const char *typeString)
|
||||
{
|
||||
ConsoleBaseType *cbt = ConsoleBaseType::getTypeByName( typeString );
|
||||
ConsoleBaseType *cbt = ConsoleBaseType::getTypeByName(typeString);
|
||||
setFieldType(slotName, cbt);
|
||||
}
|
||||
|
||||
|
|
@ -117,11 +117,11 @@ void SimFieldDictionary::setFieldType(StringTableEntry slotName, const U32 typeI
|
|||
void SimFieldDictionary::setFieldType(StringTableEntry slotName, ConsoleBaseType *type)
|
||||
{
|
||||
// If the field exists on the object, set the type
|
||||
U32 bucket = getHashValue( slotName );
|
||||
U32 bucket = getHashValue(slotName);
|
||||
|
||||
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
|
||||
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
|
||||
{
|
||||
if( walk->slotName == slotName )
|
||||
if (walk->slotName == slotName)
|
||||
{
|
||||
// Found and type assigned, let's bail
|
||||
walk->type = type;
|
||||
|
|
@ -130,15 +130,15 @@ void SimFieldDictionary::setFieldType(StringTableEntry slotName, ConsoleBaseType
|
|||
}
|
||||
|
||||
// Otherwise create the field, and set the type. Assign a null value.
|
||||
addEntry( bucket, slotName, type );
|
||||
addEntry(bucket, slotName, type);
|
||||
}
|
||||
|
||||
U32 SimFieldDictionary::getFieldType(StringTableEntry slotName) const
|
||||
{
|
||||
U32 bucket = getHashValue( slotName );
|
||||
U32 bucket = getHashValue(slotName);
|
||||
|
||||
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
|
||||
if( walk->slotName == slotName )
|
||||
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
|
||||
if (walk->slotName == slotName)
|
||||
return walk->type ? walk->type->getTypeID() : TypeString;
|
||||
|
||||
return TypeString;
|
||||
|
|
@ -146,27 +146,27 @@ U32 SimFieldDictionary::getFieldType(StringTableEntry slotName) const
|
|||
|
||||
SimFieldDictionary::Entry *SimFieldDictionary::findDynamicField(const String &fieldName) const
|
||||
{
|
||||
U32 bucket = getHashValue( fieldName );
|
||||
U32 bucket = getHashValue(fieldName);
|
||||
|
||||
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
|
||||
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
|
||||
{
|
||||
if( fieldName.equal(walk->slotName, String::NoCase) )
|
||||
if (fieldName.equal(walk->slotName, String::NoCase))
|
||||
return walk;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SimFieldDictionary::Entry *SimFieldDictionary::findDynamicField( StringTableEntry fieldName) const
|
||||
SimFieldDictionary::Entry *SimFieldDictionary::findDynamicField(StringTableEntry fieldName) const
|
||||
{
|
||||
U32 bucket = getHashValue( fieldName );
|
||||
U32 bucket = getHashValue(fieldName);
|
||||
|
||||
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
|
||||
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
|
||||
{
|
||||
if( walk->slotName == fieldName )
|
||||
{
|
||||
return walk;
|
||||
}
|
||||
if (walk->slotName == fieldName)
|
||||
{
|
||||
return walk;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
@ -177,17 +177,17 @@ void SimFieldDictionary::setFieldValue(StringTableEntry slotName, const char *va
|
|||
{
|
||||
U32 bucket = getHashValue(slotName);
|
||||
Entry **walk = &mHashTable[bucket];
|
||||
while(*walk && (*walk)->slotName != slotName)
|
||||
while (*walk && (*walk)->slotName != slotName)
|
||||
walk = &((*walk)->next);
|
||||
|
||||
Entry *field = *walk;
|
||||
if( !value || !*value )
|
||||
if (!value || !*value)
|
||||
{
|
||||
if(field)
|
||||
if (field)
|
||||
{
|
||||
mVersion++;
|
||||
|
||||
if( field->value )
|
||||
if (field->value)
|
||||
dFree(field->value);
|
||||
|
||||
*walk = field->next;
|
||||
|
|
@ -196,15 +196,15 @@ void SimFieldDictionary::setFieldValue(StringTableEntry slotName, const char *va
|
|||
}
|
||||
else
|
||||
{
|
||||
if(field)
|
||||
if (field)
|
||||
{
|
||||
if( field->value )
|
||||
if (field->value)
|
||||
dFree(field->value);
|
||||
|
||||
field->value = dStrdup(value);
|
||||
}
|
||||
else
|
||||
addEntry( bucket, slotName, 0, dStrdup( value ) );
|
||||
addEntry(bucket, slotName, 0, dStrdup(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -212,8 +212,8 @@ const char *SimFieldDictionary::getFieldValue(StringTableEntry slotName)
|
|||
{
|
||||
U32 bucket = getHashValue(slotName);
|
||||
|
||||
for(Entry *walk = mHashTable[bucket];walk;walk = walk->next)
|
||||
if(walk->slotName == slotName)
|
||||
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
|
||||
if (walk->slotName == slotName)
|
||||
return walk->value;
|
||||
|
||||
return NULL;
|
||||
|
|
@ -223,9 +223,9 @@ void SimFieldDictionary::assignFrom(SimFieldDictionary *dict)
|
|||
{
|
||||
mVersion++;
|
||||
|
||||
for(U32 i = 0; i < HashTableSize; i++)
|
||||
for (U32 i = 0; i < HashTableSize; i++)
|
||||
{
|
||||
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
|
||||
for (Entry *walk = dict->mHashTable[i]; walk; walk = walk->next)
|
||||
{
|
||||
setFieldValue(walk->slotName, walk->value);
|
||||
setFieldType(walk->slotName, walk->type);
|
||||
|
|
@ -233,7 +233,7 @@ void SimFieldDictionary::assignFrom(SimFieldDictionary *dict)
|
|||
}
|
||||
}
|
||||
|
||||
static S32 QSORT_CALLBACK compareEntries(const void* a,const void* b)
|
||||
static S32 QSORT_CALLBACK compareEntries(const void* a, const void* b)
|
||||
{
|
||||
SimFieldDictionary::Entry *fa = *((SimFieldDictionary::Entry **)a);
|
||||
SimFieldDictionary::Entry *fb = *((SimFieldDictionary::Entry **)b);
|
||||
|
|
@ -245,17 +245,17 @@ void SimFieldDictionary::writeFields(SimObject *obj, Stream &stream, U32 tabStop
|
|||
const AbstractClassRep::FieldList &list = obj->getFieldList();
|
||||
Vector<Entry *> flist(__FILE__, __LINE__);
|
||||
|
||||
for(U32 i = 0; i < HashTableSize; i++)
|
||||
for (U32 i = 0; i < HashTableSize; i++)
|
||||
{
|
||||
for(Entry *walk = mHashTable[i];walk; walk = walk->next)
|
||||
for (Entry *walk = mHashTable[i]; walk; walk = walk->next)
|
||||
{
|
||||
// make sure we haven't written this out yet:
|
||||
U32 i;
|
||||
for(i = 0; i < list.size(); i++)
|
||||
if(list[i].pFieldname == walk->slotName)
|
||||
for (i = 0; i < list.size(); i++)
|
||||
if (list[i].pFieldname == walk->slotName)
|
||||
break;
|
||||
|
||||
if(i != list.size())
|
||||
if (i != list.size())
|
||||
continue;
|
||||
|
||||
|
||||
|
|
@ -267,23 +267,23 @@ void SimFieldDictionary::writeFields(SimObject *obj, Stream &stream, U32 tabStop
|
|||
}
|
||||
|
||||
// Sort Entries to prevent version control conflicts
|
||||
dQsort(flist.address(),flist.size(),sizeof(Entry *),compareEntries);
|
||||
dQsort(flist.address(), flist.size(), sizeof(Entry *), compareEntries);
|
||||
|
||||
// Save them out
|
||||
for(Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
|
||||
for (Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
|
||||
{
|
||||
U32 nBufferSize = (dStrlen( (*itr)->value ) * 2) + dStrlen( (*itr)->slotName ) + 16;
|
||||
FrameTemp<char> expandedBuffer( nBufferSize );
|
||||
U32 nBufferSize = (dStrlen((*itr)->value) * 2) + dStrlen((*itr)->slotName) + 16;
|
||||
FrameTemp<char> expandedBuffer(nBufferSize);
|
||||
|
||||
stream.writeTabs(tabStop+1);
|
||||
stream.writeTabs(tabStop + 1);
|
||||
|
||||
const char *typeName = (*itr)->type && (*itr)->type->getTypeID() != TypeString ? (*itr)->type->getTypeName() : "";
|
||||
dSprintf(expandedBuffer, nBufferSize, "%s%s%s = \"", typeName, *typeName ? " " : "", (*itr)->slotName);
|
||||
if ( (*itr)->value )
|
||||
if ((*itr)->value)
|
||||
expandEscape((char*)expandedBuffer + dStrlen(expandedBuffer), (*itr)->value);
|
||||
dStrcat(expandedBuffer, "\";\r\n");
|
||||
|
||||
stream.write(dStrlen(expandedBuffer),expandedBuffer);
|
||||
stream.write(dStrlen(expandedBuffer), expandedBuffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -293,32 +293,32 @@ void SimFieldDictionary::printFields(SimObject *obj)
|
|||
char expandedBuffer[4096];
|
||||
Vector<Entry *> flist(__FILE__, __LINE__);
|
||||
|
||||
for(U32 i = 0; i < HashTableSize; i++)
|
||||
for (U32 i = 0; i < HashTableSize; i++)
|
||||
{
|
||||
for(Entry *walk = mHashTable[i];walk; walk = walk->next)
|
||||
for (Entry *walk = mHashTable[i]; walk; walk = walk->next)
|
||||
{
|
||||
// make sure we haven't written this out yet:
|
||||
U32 i;
|
||||
for(i = 0; i < list.size(); i++)
|
||||
if(list[i].pFieldname == walk->slotName)
|
||||
for (i = 0; i < list.size(); i++)
|
||||
if (list[i].pFieldname == walk->slotName)
|
||||
break;
|
||||
|
||||
if(i != list.size())
|
||||
if (i != list.size())
|
||||
continue;
|
||||
|
||||
flist.push_back(walk);
|
||||
}
|
||||
}
|
||||
dQsort(flist.address(),flist.size(),sizeof(Entry *),compareEntries);
|
||||
dQsort(flist.address(), flist.size(), sizeof(Entry *), compareEntries);
|
||||
|
||||
for(Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
|
||||
for (Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
|
||||
{
|
||||
const char* type = "string";
|
||||
if( ( *itr )->type )
|
||||
type = ( *itr )->type->getTypeClassName();
|
||||
|
||||
dSprintf( expandedBuffer, sizeof( expandedBuffer ), " %s %s = \"", type, ( *itr )->slotName );
|
||||
if ( (*itr)->value )
|
||||
if ((*itr)->type)
|
||||
type = (*itr)->type->getTypeClassName();
|
||||
|
||||
dSprintf(expandedBuffer, sizeof(expandedBuffer), " %s %s = \"", type, (*itr)->slotName);
|
||||
if ((*itr)->value)
|
||||
expandEscape(expandedBuffer + dStrlen(expandedBuffer), (*itr)->value);
|
||||
Con::printf("%s\"", expandedBuffer);
|
||||
}
|
||||
|
|
@ -326,9 +326,9 @@ void SimFieldDictionary::printFields(SimObject *obj)
|
|||
|
||||
SimFieldDictionary::Entry *SimFieldDictionary::operator[](U32 index)
|
||||
{
|
||||
AssertFatal ( index < mNumFields, "out of range" );
|
||||
AssertFatal(index < mNumFields, "out of range");
|
||||
|
||||
if ( index > mNumFields )
|
||||
if (index > mNumFields)
|
||||
return NULL;
|
||||
|
||||
SimFieldDictionaryIterator itr(this);
|
||||
|
|
@ -350,13 +350,13 @@ SimFieldDictionaryIterator::SimFieldDictionaryIterator(SimFieldDictionary * dict
|
|||
|
||||
SimFieldDictionary::Entry* SimFieldDictionaryIterator::operator++()
|
||||
{
|
||||
if(!mDictionary)
|
||||
if (!mDictionary)
|
||||
return(mEntry);
|
||||
|
||||
if(mEntry)
|
||||
if (mEntry)
|
||||
mEntry = mEntry->next;
|
||||
|
||||
while(!mEntry && (mHashIndex < (SimFieldDictionary::HashTableSize-1)))
|
||||
while (!mEntry && (mHashIndex < (SimFieldDictionary::HashTableSize - 1)))
|
||||
mEntry = mDictionary->mHashTable[++mHashIndex];
|
||||
|
||||
return(mEntry);
|
||||
|
|
@ -386,14 +386,14 @@ void SimFieldDictionary::setFieldValue(StringTableEntry slotName, const char *va
|
|||
|
||||
U32 bucket = getHashValue(slotName);
|
||||
Entry **walk = &mHashTable[bucket];
|
||||
while(*walk && (*walk)->slotName != slotName)
|
||||
while (*walk && (*walk)->slotName != slotName)
|
||||
walk = &((*walk)->next);
|
||||
|
||||
Entry *field = *walk;
|
||||
if (field)
|
||||
return;
|
||||
|
||||
addEntry( bucket, slotName, type, dStrdup( value ) );
|
||||
addEntry(bucket, slotName, type, dStrdup(value));
|
||||
}
|
||||
// A variation of the stock SimFieldDictionary::assignFrom(), this method adds <no_replace>
|
||||
// and <filter> arguments. When true, <no_replace> prohibits the replacement of fields that already
|
||||
|
|
@ -412,15 +412,15 @@ void SimFieldDictionary::assignFrom(SimFieldDictionary *dict, const char* filter
|
|||
|
||||
if (filter_len == 0)
|
||||
{
|
||||
for(U32 i = 0; i < HashTableSize; i++)
|
||||
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
|
||||
for (U32 i = 0; i < HashTableSize; i++)
|
||||
for (Entry *walk = dict->mHashTable[i]; walk; walk = walk->next)
|
||||
setFieldValue(walk->slotName, walk->value, walk->type, no_replace);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(U32 i = 0; i < HashTableSize; i++)
|
||||
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
|
||||
for (U32 i = 0; i < HashTableSize; i++)
|
||||
for (Entry *walk = dict->mHashTable[i]; walk; walk = walk->next)
|
||||
if (dStrncmp(walk->slotName, filter, filter_len) == 0)
|
||||
setFieldValue(walk->slotName, walk->value, walk->type, no_replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ class SimFieldDictionary
|
|||
public:
|
||||
struct Entry
|
||||
{
|
||||
Entry() : type( NULL ) {};
|
||||
Entry() : type(NULL) {};
|
||||
|
||||
StringTableEntry slotName;
|
||||
char *value;
|
||||
|
|
@ -64,10 +64,10 @@ private:
|
|||
static Entry *smFreeList;
|
||||
|
||||
void freeEntry(Entry *entry);
|
||||
Entry* addEntry( U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value = 0 );
|
||||
Entry* addEntry(U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value = 0);
|
||||
|
||||
static U32 getHashValue( StringTableEntry slotName );
|
||||
static U32 getHashValue( const String& fieldName );
|
||||
static U32 getHashValue(StringTableEntry slotName);
|
||||
static U32 getHashValue(const String& fieldName);
|
||||
|
||||
U32 mNumFields;
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ public:
|
|||
const char *getFieldValue(StringTableEntry slotName);
|
||||
U32 getFieldType(StringTableEntry slotName) const;
|
||||
Entry *findDynamicField(const String &fieldName) const;
|
||||
Entry *findDynamicField( StringTableEntry fieldName) const;
|
||||
Entry *findDynamicField(StringTableEntry fieldName) const;
|
||||
void writeFields(SimObject *obj, Stream &strem, U32 tabStop);
|
||||
void printFields(SimObject *obj);
|
||||
void assignFrom(SimFieldDictionary *dict);
|
||||
|
|
@ -112,4 +112,4 @@ public:
|
|||
};
|
||||
|
||||
|
||||
#endif // _SIMFIELDDICTIONARY_H_
|
||||
#endif // _SIMFIELDDICTIONARY_H_
|
||||
|
|
@ -72,8 +72,8 @@ SimObject::SimObject()
|
|||
objectName = NULL;
|
||||
mOriginalName = NULL;
|
||||
mInternalName = NULL;
|
||||
nextNameObject = (SimObject*)-1;
|
||||
nextManagerNameObject = (SimObject*)-1;
|
||||
nextNameObject = nullptr;
|
||||
nextManagerNameObject = nullptr;
|
||||
nextIdObject = NULL;
|
||||
|
||||
mFilename = NULL;
|
||||
|
|
@ -86,6 +86,8 @@ SimObject::SimObject()
|
|||
mNotifyList = NULL;
|
||||
mFlags.set( ModStaticFields | ModDynamicFields );
|
||||
|
||||
mProgenitorFile = StringTable->EmptyString();
|
||||
|
||||
mFieldDictionary = NULL;
|
||||
mCanSaveFieldDictionary = true;
|
||||
|
||||
|
|
@ -122,10 +124,10 @@ SimObject::~SimObject()
|
|||
if( mCopySource )
|
||||
mCopySource->unregisterReference( &mCopySource );
|
||||
|
||||
AssertFatal(nextNameObject == (SimObject*)-1,avar(
|
||||
AssertFatal(nextNameObject == nullptr,avar(
|
||||
"SimObject::~SimObject: Not removed from dictionary: name %s, id %i",
|
||||
objectName, mId));
|
||||
AssertFatal(nextManagerNameObject == (SimObject*)-1,avar(
|
||||
AssertFatal(nextManagerNameObject == nullptr,avar(
|
||||
"SimObject::~SimObject: Not removed from manager dictionary: name %s, id %i",
|
||||
objectName,mId));
|
||||
AssertFatal(mFlags.test(Added) == 0, "SimObject::object "
|
||||
|
|
|
|||
|
|
@ -1,232 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
|
||||
#include "core/stream/fileStream.h"
|
||||
#include "core/util/path.h"
|
||||
|
||||
#include "gfx/bitmap/gBitmap.h"
|
||||
|
||||
// This must come after our headers due to a conflicting definition of VoidPtr
|
||||
#include "lungif/gif_lib.h"
|
||||
|
||||
|
||||
using namespace Torque;
|
||||
|
||||
static bool sReadGIF(Stream &stream, GBitmap *bitmap);
|
||||
static bool sWriteGIF(GBitmap *bitmap, Stream &stream, U32 compressionLevel);
|
||||
|
||||
static struct _privateRegisterGIF
|
||||
{
|
||||
_privateRegisterGIF()
|
||||
{
|
||||
GBitmap::Registration reg;
|
||||
|
||||
reg.extensions.push_back( "gif" );
|
||||
|
||||
reg.readFunc = sReadGIF;
|
||||
reg.writeFunc = sWriteGIF;
|
||||
|
||||
GBitmap::sRegisterFormat( reg );
|
||||
}
|
||||
} sStaticRegisterGIF;
|
||||
|
||||
//-------------------------------------- Replacement I/O for standard LIBjpeg
|
||||
// functions. we don't wanna use
|
||||
// FILE*'s...
|
||||
static S32 gifReadDataFn(GifFileType *gifinfo, GifByteType *data, S32 length)
|
||||
{
|
||||
Stream *stream = (Stream*)gifinfo->UserData;
|
||||
AssertFatal(stream != NULL, "gifReadDataFn::No stream.");
|
||||
int pos = stream->getPosition();
|
||||
if (stream->read(length, data))
|
||||
return length;
|
||||
|
||||
if (stream->getStatus() == Stream::EOS)
|
||||
return (stream->getPosition()-pos);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
#if 0
|
||||
// CodeReview - until we can write these, get rid of warning by disabling method.
|
||||
static S32 gifWriteDataFn(GifFileType *gifinfo, GifByteType *data, S32 length)
|
||||
{
|
||||
Stream *stream = (Stream*)gifinfo->UserData;
|
||||
AssertFatal(stream != NULL, "gifWriteDataFn::No stream.");
|
||||
if (stream->write(length, data))
|
||||
return length;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------
|
||||
static bool sReadGIF( Stream &stream, GBitmap *bitmap )
|
||||
{
|
||||
PROFILE_SCOPE(sReadGIF);
|
||||
GifFileType *gifinfo = DGifOpen( (void*)&stream, gifReadDataFn);
|
||||
if (!gifinfo)
|
||||
return false;
|
||||
|
||||
GifRecordType recordType;
|
||||
do
|
||||
{
|
||||
if (DGifGetRecordType(gifinfo, &recordType) == GIF_ERROR)
|
||||
break;
|
||||
|
||||
if (recordType == IMAGE_DESC_RECORD_TYPE)
|
||||
{
|
||||
if (DGifGetImageDesc(gifinfo) == GIF_ERROR)
|
||||
break;
|
||||
|
||||
GFXFormat format = (gifinfo->SBackGroundColor == 0 ) ? GFXFormatR8G8B8 : GFXFormatR8G8B8A8;
|
||||
bitmap->allocateBitmap(gifinfo->SWidth, gifinfo->SHeight, false, format);
|
||||
|
||||
// Assume no transparency until proven otherwise
|
||||
bitmap->setHasTransparency(false);
|
||||
|
||||
U32 gwidth = gifinfo->Image.Width ? gifinfo->Image.Width : bitmap->getWidth();
|
||||
U32 gheight= gifinfo->Image.Height ? gifinfo->Image.Height : bitmap->getHeight();
|
||||
U32 gifSize = gwidth * gheight;
|
||||
U8 *data = new U8[gifSize];
|
||||
|
||||
if (DGifGetLine(gifinfo, data, gifSize) != GIF_ERROR)
|
||||
{
|
||||
// use the global or local color table ?
|
||||
GifColorType *color = NULL;
|
||||
if (gifinfo->Image.ColorMap)
|
||||
color = gifinfo->Image.ColorMap->Colors;
|
||||
else if (gifinfo->SColorMap)
|
||||
color = gifinfo->SColorMap->Colors;
|
||||
|
||||
if (color)
|
||||
{
|
||||
U8 *dst = bitmap->getAddress(gifinfo->Image.Left, gifinfo->Image.Top);
|
||||
U8 *src = data;
|
||||
U32 right = gifinfo->Image.Left + gwidth;
|
||||
U32 bottom = gifinfo->Image.Top + gheight;
|
||||
U32 next = (bitmap->getWidth() - gwidth) * bitmap->getBytesPerPixel();
|
||||
|
||||
if (format == GFXFormatR8G8B8A8)
|
||||
{
|
||||
for (U32 y=gifinfo->Image.Top; y<bottom; y++)
|
||||
{
|
||||
for (U32 x=gifinfo->Image.Left; x<right; x++, src++)
|
||||
{
|
||||
if (*src == gifinfo->SBackGroundColor)
|
||||
{
|
||||
// this is a transparent pixel
|
||||
dst[0] = 0; // red
|
||||
dst[1] = 0; // green
|
||||
dst[2] = 0; // blue
|
||||
dst[3] = 0; // alpha
|
||||
|
||||
bitmap->setHasTransparency(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
dst[0] = color[*src].Red;
|
||||
dst[1] = color[*src].Green;
|
||||
dst[2] = color[*src].Blue;
|
||||
dst[3] = 0; // alpha
|
||||
}
|
||||
dst += bitmap->getBytesPerPixel();
|
||||
}
|
||||
dst += next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (U32 y=gifinfo->Image.Top; y<bottom; y++)
|
||||
{
|
||||
for (U32 x=gifinfo->Image.Left; x<right; x++, src++)
|
||||
{
|
||||
dst[0] = color[*src].Red;
|
||||
dst[1] = color[*src].Green;
|
||||
dst[2] = color[*src].Blue;
|
||||
dst += bitmap->getBytesPerPixel();
|
||||
}
|
||||
dst += next;
|
||||
}
|
||||
}
|
||||
delete [] data;
|
||||
DGifCloseFile(gifinfo);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// failure
|
||||
delete [] data;
|
||||
break;
|
||||
}
|
||||
else if (recordType == EXTENSION_RECORD_TYPE)
|
||||
{
|
||||
GifByteType *extension;
|
||||
S32 extCode;
|
||||
|
||||
// Skip any extension blocks in file
|
||||
if (DGifGetExtension(gifinfo, &extCode, &extension) != GIF_ERROR)
|
||||
{
|
||||
while (extension != NULL)
|
||||
{
|
||||
if (DGifGetExtensionNext(gifinfo, &extension) == GIF_ERROR)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// There used to be a break right here. This caused the while condition to
|
||||
// never get processed, and so it never looped through all the records in
|
||||
// the GIF. I took a quick peek back at TGB and TGE histories and I am not
|
||||
// sure where this change got made, but I can't figure out why the loading
|
||||
// worked at all, ever, with that break in there. The only case I can think
|
||||
// of is if the first record in the GIF was the bitmap data.
|
||||
// [6/6/2007 Pat]
|
||||
|
||||
}while (recordType != TERMINATE_RECORD_TYPE);
|
||||
|
||||
|
||||
DGifCloseFile(gifinfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
static bool sWriteGIF(GBitmap *bitmap, Stream &stream, U32 compressionLevel)
|
||||
{
|
||||
TORQUE_UNUSED( bitmap );
|
||||
TORQUE_UNUSED( stream );
|
||||
TORQUE_UNUSED( compressionLevel );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,422 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "core/stream/stream.h"
|
||||
|
||||
#include "gfx/bitmap/gBitmap.h"
|
||||
|
||||
#include "core/color.h"
|
||||
|
||||
#define MNG_NO_CMS
|
||||
#define MNG_SUPPORT_READ
|
||||
#define MNG_SUPPORT_WRITE
|
||||
#define MNG_SUPPORT_DISPLAY
|
||||
#define MNG_STORE_CHUNKS
|
||||
#define MNG_ACCESS_CHUNKS
|
||||
|
||||
#include "lmng/libmng.h"
|
||||
|
||||
|
||||
|
||||
static bool sReadMNG(Stream &stream, GBitmap *bitmap);
|
||||
static bool sWriteMNG(GBitmap *bitmap, Stream &stream, U32 compressionLevel);
|
||||
|
||||
static struct _privateRegisterMNG
|
||||
{
|
||||
_privateRegisterMNG()
|
||||
{
|
||||
GBitmap::Registration reg;
|
||||
|
||||
reg.extensions.push_back( "jng" );
|
||||
reg.extensions.push_back( "mng" );
|
||||
|
||||
reg.readFunc = sReadMNG;
|
||||
reg.writeFunc = sWriteMNG;
|
||||
|
||||
GBitmap::sRegisterFormat( reg );
|
||||
}
|
||||
} sStaticRegisterMNG;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GBitmap* image;
|
||||
Stream* stream;
|
||||
} mngstuff;
|
||||
|
||||
static mng_ptr mngMallocFn(mng_size_t size)
|
||||
{
|
||||
mng_ptr data = dMalloc(size);
|
||||
return dMemset(data, 0, size);
|
||||
}
|
||||
|
||||
static void mngFreeFn(mng_ptr p, mng_size_t size)
|
||||
{
|
||||
dFree(p);
|
||||
}
|
||||
|
||||
static mng_bool mngOpenDataFn(mng_handle mng)
|
||||
{
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool mngCloseDataFn(mng_handle mng)
|
||||
{
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool mngReadDataFn(mng_handle mng, mng_ptr data, mng_uint32 length, mng_uint32 *bytesread)
|
||||
{
|
||||
mngstuff *mymng = (mngstuff *)mng_get_userdata(mng);
|
||||
AssertFatal(mymng->stream != NULL, "No stream?");
|
||||
|
||||
bool success = mymng->stream->read(length, data);
|
||||
*bytesread = length; // stupid hack
|
||||
|
||||
AssertFatal(success, "MNG read catastrophic error!");
|
||||
if(success)
|
||||
return MNG_TRUE;
|
||||
else
|
||||
return MNG_FALSE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// CodeReview - until we can write these, get rid of warning by disabling method.
|
||||
static mng_bool mngWriteDataFn(mng_handle mng, mng_ptr data, mng_uint32 length, mng_uint32 *iWritten)
|
||||
{
|
||||
mngstuff *mymng = (mngstuff *)mng_get_userdata(mng);
|
||||
AssertFatal(mymng->stream != NULL, "No stream?");
|
||||
|
||||
bool success = mymng->stream->write(length, data);
|
||||
*iWritten = length; // stupid hack
|
||||
|
||||
AssertFatal(success, "MNG write catastrophic error!");
|
||||
if(success)
|
||||
return MNG_TRUE;
|
||||
else
|
||||
return MNG_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static mng_bool mngProcessHeaderFn(mng_handle mng, mng_uint32 width, mng_uint32 height)
|
||||
{
|
||||
mngstuff *mymng = (mngstuff *)mng_get_userdata(mng);
|
||||
|
||||
GFXFormat format;
|
||||
mng_uint8 colorType = mng_get_colortype(mng);
|
||||
mng_uint8 alphaDepth = mng_get_alphadepth(mng);
|
||||
switch(colorType)
|
||||
{
|
||||
case MNG_COLORTYPE_GRAY:
|
||||
case MNG_COLORTYPE_JPEGGRAY:
|
||||
format = GFXFormatR8G8B8;
|
||||
mng_set_canvasstyle(mng, MNG_CANVAS_RGB8);
|
||||
break;
|
||||
|
||||
case MNG_COLORTYPE_INDEXED:
|
||||
if(alphaDepth >= 1)
|
||||
{
|
||||
format = GFXFormatR8G8B8A8;
|
||||
mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8);
|
||||
}
|
||||
else
|
||||
{
|
||||
format = GFXFormatR8G8B8;
|
||||
mng_set_canvasstyle(mng, MNG_CANVAS_RGB8);
|
||||
}
|
||||
|
||||
case MNG_COLORTYPE_RGB:
|
||||
case MNG_COLORTYPE_JPEGCOLOR:
|
||||
if(alphaDepth >= 1)
|
||||
{
|
||||
format = GFXFormatR8G8B8A8;
|
||||
mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8);
|
||||
}
|
||||
else
|
||||
{
|
||||
format = GFXFormatR8G8B8;
|
||||
mng_set_canvasstyle(mng, MNG_CANVAS_RGB8);
|
||||
}
|
||||
break;
|
||||
|
||||
case MNG_COLORTYPE_RGBA:
|
||||
case MNG_COLORTYPE_JPEGCOLORA:
|
||||
format = GFXFormatR8G8B8A8;
|
||||
mng_set_canvasstyle(mng, MNG_CANVAS_RGBA8);
|
||||
break;
|
||||
|
||||
default:
|
||||
// This case should never get hit, however it resolves a compiler
|
||||
// warning
|
||||
format = GFXFormat_FIRST;
|
||||
AssertISV( false, "Unknown color format in bitmap MNG Loading" );
|
||||
}
|
||||
|
||||
mymng->image->allocateBitmap(width, height, false, format);
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_ptr mngCanvasLineFn(mng_handle mng, mng_uint32 line)
|
||||
{
|
||||
mngstuff *mymng = (mngstuff *)mng_get_userdata(mng);
|
||||
return (mng_ptr) mymng->image->getAddress(0, line);
|
||||
}
|
||||
|
||||
static mng_bool mngRefreshFn(mng_handle mng, mng_uint32 x, mng_uint32 y, mng_uint32 w, mng_uint32 h)
|
||||
{
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_uint32 mngGetTicksFn(mng_handle mng)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static mng_bool mngSetTimerFn(mng_handle mng, mng_uint32 msecs)
|
||||
{
|
||||
return MNG_TRUE;
|
||||
}
|
||||
|
||||
static mng_bool mngFatalErrorFn(mng_handle mng, mng_int32 code, mng_int8 severity, mng_chunkid chunktype, mng_uint32 chunkseq, mng_int32 extra1, mng_int32 extra2, mng_pchar text)
|
||||
{
|
||||
mng_cleanup(&mng);
|
||||
|
||||
AssertISV(false, avar("Error reading MNG file:\n %s", (const char*)text));
|
||||
return MNG_FALSE;
|
||||
}
|
||||
|
||||
static bool sReadMNG(Stream &stream, GBitmap *bitmap)
|
||||
{
|
||||
PROFILE_SCOPE(sReadMNG);
|
||||
mngstuff mnginfo;
|
||||
dMemset(&mnginfo, 0, sizeof(mngstuff));
|
||||
|
||||
mng_handle mng = mng_initialize(&mnginfo, mngMallocFn, mngFreeFn, MNG_NULL);
|
||||
if(mng == NULL)
|
||||
return false;
|
||||
|
||||
// setup the callbacks
|
||||
mng_setcb_errorproc(mng, mngFatalErrorFn);
|
||||
mng_setcb_openstream(mng, mngOpenDataFn);
|
||||
mng_setcb_closestream(mng, mngCloseDataFn);
|
||||
mng_setcb_readdata(mng, mngReadDataFn);
|
||||
mng_setcb_processheader(mng, mngProcessHeaderFn);
|
||||
mng_setcb_getcanvasline(mng, mngCanvasLineFn);
|
||||
mng_setcb_refresh(mng, mngRefreshFn);
|
||||
mng_setcb_gettickcount(mng, mngGetTicksFn);
|
||||
mng_setcb_settimer(mng, mngSetTimerFn);
|
||||
|
||||
mnginfo.image = bitmap;
|
||||
mnginfo.stream = &stream;
|
||||
|
||||
mng_read(mng);
|
||||
mng_display(mng);
|
||||
|
||||
// hacks :(
|
||||
// libmng doesn't support returning data in gray/gray alpha format,
|
||||
// so we grab as RGB/RGBA and just cut off the g and b
|
||||
mng_uint8 colorType = mng_get_colortype(mng);
|
||||
switch(colorType)
|
||||
{
|
||||
case MNG_COLORTYPE_GRAY:
|
||||
case MNG_COLORTYPE_JPEGGRAY:
|
||||
{
|
||||
GBitmap temp(*bitmap);
|
||||
bitmap->deleteImage();
|
||||
bitmap->allocateBitmap(temp.getWidth(), temp.getHeight(), false, GFXFormatA8);
|
||||
|
||||
// force getColor to read in in the same color value for each channel
|
||||
// since the gray colortype has the real alpha in the first channel
|
||||
temp.setFormat( GFXFormatA8 );
|
||||
|
||||
ColorI color;
|
||||
for(U32 row = 0; row < bitmap->getHeight(); row++)
|
||||
{
|
||||
for(U32 col = 0; col < bitmap->getWidth(); col++)
|
||||
{
|
||||
temp.getColor(col, row, color);
|
||||
bitmap->setColor(col, row, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
mng_cleanup(&mng);
|
||||
|
||||
// Check this bitmap for transparency
|
||||
bitmap->checkForTransparency();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool sWriteMNG(GBitmap *bitmap, Stream &stream, U32 compressionLevel)
|
||||
{
|
||||
TORQUE_UNUSED( bitmap );
|
||||
TORQUE_UNUSED( stream );
|
||||
TORQUE_UNUSED( compressionLevel );
|
||||
|
||||
return false;
|
||||
#if 0
|
||||
// ONLY RGB bitmap writing supported at this time!
|
||||
AssertFatal(getFormat() == GFXFormatR8G8B8 || getFormat() == GFXFormatR8G8B8A8 || getFormat() == GFXFormatA8, "GBitmap::writeMNG: ONLY RGB bitmap writing supported at this time.");
|
||||
if(getFormat() != GFXFormatR8G8B8 && getFormat() != GFXFormatR8G8B8A8 && getFormat() != GFXFormatA8)
|
||||
return (false);
|
||||
|
||||
// maximum image size allowed
|
||||
#define MAX_HEIGHT 4096
|
||||
if(getHeight() >= MAX_HEIGHT)
|
||||
return false;
|
||||
|
||||
mngstuff mnginfo;
|
||||
dMemset(&mnginfo, 0, sizeof(mngstuff));
|
||||
mng_handle mng = mng_initialize(&mnginfo, mngMallocFn, mngFreeFn, MNG_NULL);
|
||||
if(mng == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// setup the callbacks
|
||||
mng_setcb_openstream(mng, mngOpenDataFn);
|
||||
mng_setcb_closestream(mng, mngCloseDataFn);
|
||||
mng_setcb_writedata(mng, mngWriteDataFn);
|
||||
|
||||
// create the file in memory
|
||||
mng_create(mng);
|
||||
|
||||
mng_putchunk_defi(mng, 0, 0, 0, MNG_FALSE, 0, 0, MNG_FALSE, 0, getWidth(), 0, getHeight());
|
||||
|
||||
mnginfo.image = (GBitmap*)this;
|
||||
mnginfo.stream = &stream;
|
||||
|
||||
switch(getFormat()) {
|
||||
case GFXFormatA8:
|
||||
mng_putchunk_ihdr(mng, getWidth(), getHeight(),
|
||||
MNG_BITDEPTH_8,
|
||||
MNG_COLORTYPE_GRAY,
|
||||
MNG_COMPRESSION_DEFLATE,
|
||||
MNG_FILTER_ADAPTIVE,
|
||||
MNG_INTERLACE_NONE);
|
||||
|
||||
// not implemented in lib yet
|
||||
//mng_putimgdata_ihdr(mng, getWidth(), getHeight(),
|
||||
// MNG_COLORTYPE_GRAY,
|
||||
// MNG_BITDEPTH_8,
|
||||
// MNG_COMPRESSION_DEFLATE,
|
||||
// MNG_FILTER_ADAPTIVE,
|
||||
// MNG_INTERLACE_NONE,
|
||||
// MNG_CANVAS_GRAY8, mngCanvasLineFn);
|
||||
break;
|
||||
case GFXFormatR8G8B8:
|
||||
mng_putchunk_ihdr(mng, getWidth(), getHeight(),
|
||||
MNG_BITDEPTH_8,
|
||||
MNG_COLORTYPE_RGB,
|
||||
MNG_COMPRESSION_DEFLATE,
|
||||
MNG_FILTER_ADAPTIVE,
|
||||
MNG_INTERLACE_NONE);
|
||||
|
||||
// not implemented in lib yet
|
||||
//mng_putimgdata_ihdr(mng, getWidth(), getHeight(),
|
||||
// MNG_COLORTYPE_RGB,
|
||||
// MNG_BITDEPTH_8,
|
||||
// MNG_COMPRESSION_DEFLATE,
|
||||
// MNG_FILTER_ADAPTIVE,
|
||||
// MNG_INTERLACE_NONE,
|
||||
// MNG_CANVAS_RGB8, mngCanvasLineFn);
|
||||
break;
|
||||
case GFXFormatR8G8B8A8:
|
||||
mng_putchunk_ihdr(mng, getWidth(), getHeight(),
|
||||
MNG_BITDEPTH_8,
|
||||
MNG_COLORTYPE_RGBA,
|
||||
MNG_COMPRESSION_DEFLATE,
|
||||
MNG_FILTER_ADAPTIVE,
|
||||
MNG_INTERLACE_NONE);
|
||||
|
||||
// not implemented in lib yet
|
||||
//mng_putimgdata_ihdr(mng, getWidth(), getHeight(),
|
||||
// MNG_COLORTYPE_RGBA,
|
||||
// MNG_BITDEPTH_8,
|
||||
// MNG_COMPRESSION_DEFLATE,
|
||||
// MNG_FILTER_ADAPTIVE,
|
||||
// MNG_INTERLACE_NONE,
|
||||
// MNG_CANVAS_RGBA8, mngCanvasLineFn);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// below is a hack until libmng is mature enough to handle this itself
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
U8 *tmpbuffer = new U8[this->byteSize + getHeight()];
|
||||
if(tmpbuffer == 0)
|
||||
{
|
||||
mng_cleanup(&mng);
|
||||
return false;
|
||||
}
|
||||
|
||||
// transfer data, add filterbyte
|
||||
U32 effwdt = getWidth() * this->bytesPerPixel;
|
||||
for(U32 Row = 0; Row < getHeight(); Row++)
|
||||
{
|
||||
// first Byte in each scanline is filterbyte: currently 0 -> no filter
|
||||
tmpbuffer[Row * (effwdt + 1)] = 0;
|
||||
|
||||
// copy the scanline
|
||||
dMemcpy(tmpbuffer + Row * (effwdt + 1) + 1, getAddress(0, Row), effwdt);
|
||||
}
|
||||
|
||||
// compress data with zlib
|
||||
U8 *dstbuffer = new U8[this->byteSize + getHeight()];
|
||||
if(dstbuffer == 0)
|
||||
{
|
||||
delete [] tmpbuffer;
|
||||
mng_cleanup(&mng);
|
||||
return false;
|
||||
}
|
||||
|
||||
U32 dstbufferSize = this->byteSize + getHeight();
|
||||
if(Z_OK != compress2((Bytef*)dstbuffer,(uLongf*)&dstbufferSize, (const Bytef*)tmpbuffer, dstbufferSize, 9))
|
||||
{
|
||||
delete [] tmpbuffer;
|
||||
delete [] dstbuffer;
|
||||
mng_cleanup(&mng);
|
||||
return false;
|
||||
}
|
||||
|
||||
mng_putchunk_idat(mng, dstbufferSize, (mng_ptr*)dstbuffer);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
mng_putchunk_iend(mng);
|
||||
|
||||
delete [] tmpbuffer;
|
||||
delete [] dstbuffer;
|
||||
|
||||
mng_write(mng);
|
||||
mng_cleanup(&mng);
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -152,14 +152,24 @@ ConsoleDocClass( GuiDragAndDropControl,
|
|||
"@ingroup GuiUtil"
|
||||
);
|
||||
|
||||
IMPLEMENT_CALLBACK(GuiDragAndDropControl, onControlDragCancelled, void, (), (),
|
||||
"Called when the we cancel out of the drag and drop action.\n"
|
||||
"@see GuiDragAndDropControl::onControlDragCancelled");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
GuiDragAndDropControl::GuiDragAndDropControl() : mDeleteOnMouseUp(true), mUseWholeCanvas(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GuiDragAndDropControl::initPersistFields()
|
||||
{
|
||||
addField( "deleteOnMouseUp", TypeBool, Offset( mDeleteOnMouseUp, GuiDragAndDropControl ),
|
||||
"If true, the control deletes itself when the left mouse button is released.\n\n"
|
||||
"If at this point, the drag&drop control still contains its payload, it will be deleted along with the control." );
|
||||
|
||||
addField("useWholeCanvas", TypeBool, Offset(mUseWholeCanvas, GuiDragAndDropControl),
|
||||
"If true, the control can be tested against ANY control active on the canvas instead of just the direct parent.\n\n");
|
||||
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
|
@ -226,8 +236,10 @@ void GuiDragAndDropControl::onMouseUp(const GuiEvent& event)
|
|||
mouseUnlock();
|
||||
|
||||
GuiControl* target = findDragTarget( event.mousePoint, "onControlDropped" );
|
||||
if( target )
|
||||
target->onControlDropped_callback( dynamic_cast< GuiControl* >( at( 0 ) ), getDropPoint() );
|
||||
if (target)
|
||||
target->onControlDropped_callback(dynamic_cast<GuiControl*>(at(0)), getDropPoint());
|
||||
else
|
||||
onControlDragCancelled_callback();
|
||||
|
||||
if( mDeleteOnMouseUp )
|
||||
deleteObject();
|
||||
|
|
@ -239,6 +251,13 @@ GuiControl* GuiDragAndDropControl::findDragTarget( Point2I mousePoint, const cha
|
|||
{
|
||||
// If there are any children and we have a parent.
|
||||
GuiControl* parent = getParent();
|
||||
|
||||
if (mUseWholeCanvas)
|
||||
{
|
||||
parent->setVisible(false);
|
||||
parent = getRoot();
|
||||
}
|
||||
|
||||
if (size() && parent)
|
||||
{
|
||||
mVisible = false;
|
||||
|
|
@ -252,6 +271,10 @@ GuiControl* GuiDragAndDropControl::findDragTarget( Point2I mousePoint, const cha
|
|||
dropControl = dropControl->getParent();
|
||||
}
|
||||
}
|
||||
|
||||
if(mUseWholeCanvas)
|
||||
parent->setVisible(true);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ class GuiDragAndDropControl : public GuiControl
|
|||
/// If true, the control deletes itself when the left mouse button is released.
|
||||
bool mDeleteOnMouseUp;
|
||||
|
||||
bool mUseWholeCanvas;
|
||||
|
||||
/// Controls may want to react when they are dragged over, entered or exited.
|
||||
SimObjectPtr<GuiControl> mLastTarget;
|
||||
|
||||
|
|
@ -65,7 +67,7 @@ class GuiDragAndDropControl : public GuiControl
|
|||
|
||||
public:
|
||||
|
||||
GuiDragAndDropControl() {}
|
||||
GuiDragAndDropControl();
|
||||
|
||||
void startDragging(Point2I offset = Point2I(0, 0));
|
||||
|
||||
|
|
@ -81,6 +83,8 @@ class GuiDragAndDropControl : public GuiControl
|
|||
DECLARE_DESCRIPTION( "A special control that implements drag&drop behavior.\n"
|
||||
"The control will notify other controls as it moves across the canvas.\n"
|
||||
"Content can be attached through dynamic fields or child objects." );
|
||||
|
||||
DECLARE_CALLBACK(void, onControlDragCancelled, ());
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -36,9 +36,7 @@
|
|||
#include "gui/editor/editorFunctions.h"
|
||||
#endif
|
||||
#include "console/engineAPI.h"
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
#include "T3D/entity.h"
|
||||
#endif
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiTreeViewCtrl);
|
||||
|
||||
|
|
@ -647,20 +645,6 @@ void GuiTreeViewCtrl::Item::getTooltipText(U32 bufLen, char *buf)
|
|||
|
||||
bool GuiTreeViewCtrl::Item::isParent() const
|
||||
{
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
//We might have a special case with entities
|
||||
//So if our entity either has children, or has some component with the EditorInspect interface, we return true
|
||||
if (mInspectorInfo.mObject)
|
||||
{
|
||||
Entity* e = dynamic_cast<Entity*>(mInspectorInfo.mObject.getObject());
|
||||
if (e)
|
||||
{
|
||||
if (e->size() > 0 || e->getComponentCount() != 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(mState.test(VirtualParent))
|
||||
{
|
||||
if( !isInspectorData() )
|
||||
|
|
@ -2517,6 +2501,19 @@ const char * GuiTreeViewCtrl::getItemValue(S32 itemId)
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
S32 GuiTreeViewCtrl::getItemAtPosition(Point2I position)
|
||||
{
|
||||
BitSet32 hitFlags = 0;
|
||||
Item* item;
|
||||
|
||||
if (_hitTest(position, item, hitFlags))
|
||||
return item->mId;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool GuiTreeViewCtrl::editItem( S32 itemId, const char* newText, const char* newValue )
|
||||
{
|
||||
Item* item = getItem( itemId );
|
||||
|
|
@ -3790,7 +3787,6 @@ void GuiTreeViewCtrl::onMouseDown(const GuiEvent & event)
|
|||
if( !item->isInspectorData() && item->mState.test(Item::VirtualParent) )
|
||||
onVirtualParentExpand(item);
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
//Slightly hacky, but I'm not sure of a better setup until we get major update to the editors
|
||||
//We check if our object is an entity, and if it is, we call a 'onInspect' function.
|
||||
//This function is pretty much a special notifier to the entity so if it has any behaviors that do special
|
||||
|
|
@ -3810,7 +3806,6 @@ void GuiTreeViewCtrl::onMouseDown(const GuiEvent & event)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
mFlags.set( RebuildVisible );
|
||||
scrollVisible(item);
|
||||
|
|
@ -4558,12 +4553,10 @@ bool GuiTreeViewCtrl::objectSearch( const SimObject *object, Item **item )
|
|||
if ( !pItem )
|
||||
continue;
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
//A bit hackish, but we make a special exception here for items that are named 'Components', as they're merely
|
||||
//virtual parents to act as a container to an Entity's components
|
||||
if (pItem->mScriptInfo.mText == StringTable->insert("Components"))
|
||||
continue;
|
||||
#endif
|
||||
|
||||
SimObject *pObj = pItem->getObject();
|
||||
|
||||
|
|
@ -4628,11 +4621,10 @@ bool GuiTreeViewCtrl::onVirtualParentBuild(Item *item, bool bForceFullUpdate)
|
|||
|
||||
// Go through our items and purge those that have disappeared from
|
||||
// the set.
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
|
||||
//Entities will be a special case here, if we're an entity, skip this step
|
||||
if (dynamic_cast<Entity*>(srcObj))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
for( Item* ptr = item->mChild; ptr != NULL; )
|
||||
{
|
||||
|
|
@ -5571,3 +5563,11 @@ DefineEngineMethod( GuiTreeViewCtrl, clearFilterText, void, (),,
|
|||
{
|
||||
object->clearFilterText();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiTreeViewCtrl, getItemAtPosition, S32, (Point2I position), (Point2I::Zero),
|
||||
"Get the tree item at the passed in position.\n\n"
|
||||
"@param position The position to check for what item is below it.\n"
|
||||
"@return The id of the item under the position.")
|
||||
{
|
||||
return object->getItemAtPosition(position);
|
||||
}
|
||||
|
|
@ -513,6 +513,8 @@ class GuiTreeViewCtrl : public GuiArrayCtrl
|
|||
bool editItem( S32 itemId, const char* newText, const char* newValue );
|
||||
|
||||
bool markItem( S32 itemId, bool mark );
|
||||
|
||||
S32 getItemAtPosition(Point2I position);
|
||||
|
||||
bool isItemSelected( S32 itemId );
|
||||
|
||||
|
|
|
|||
|
|
@ -276,8 +276,6 @@ bool GuiCanvas::onAdd()
|
|||
// Define the menu bar for this canvas (if any)
|
||||
Con::executef(this, "onCreateMenu");
|
||||
|
||||
Sim::findObject("PlatformGenericMenubar", mMenuBarCtrl);
|
||||
|
||||
return parentRet;
|
||||
}
|
||||
|
||||
|
|
@ -302,21 +300,39 @@ void GuiCanvas::setMenuBar(SimObject *obj)
|
|||
Parent::removeObject( oldMenuBar );
|
||||
|
||||
// set new menubar
|
||||
if( mMenuBarCtrl )
|
||||
Parent::addObject(mMenuBarCtrl);
|
||||
if (mMenuBarCtrl)
|
||||
{
|
||||
//Add a wrapper control so that the menubar sizes correctly
|
||||
GuiControlProfile* profile;
|
||||
Sim::findObject("GuiModelessDialogProfile", profile);
|
||||
|
||||
if (!profile)
|
||||
{
|
||||
Con::errorf("GuiCanvas::setMenuBar: Unable to find the GuiModelessDialogProfile profile!");
|
||||
return;
|
||||
}
|
||||
|
||||
GuiControl* menuBackground = new GuiControl();
|
||||
menuBackground->registerObject();
|
||||
|
||||
menuBackground->setControlProfile(profile);
|
||||
|
||||
menuBackground->addObject(mMenuBarCtrl);
|
||||
|
||||
Parent::addObject(menuBackground);
|
||||
}
|
||||
|
||||
// update window accelerator keys
|
||||
if( oldMenuBar != mMenuBarCtrl )
|
||||
{
|
||||
StringTableEntry ste = StringTable->insert("menubar");
|
||||
GuiMenuBar* menu = NULL;
|
||||
menu = !oldMenuBar ? NULL : dynamic_cast<GuiMenuBar*>(oldMenuBar->findObjectByInternalName( ste, true));
|
||||
if( menu )
|
||||
menu->removeWindowAcceleratorMap( *getPlatformWindow()->getInputGenerator() );
|
||||
GuiMenuBar* oldMenu = dynamic_cast<GuiMenuBar*>(oldMenuBar);
|
||||
GuiMenuBar* newMenu = dynamic_cast<GuiMenuBar*>(mMenuBarCtrl);
|
||||
|
||||
menu = !mMenuBarCtrl ? NULL : dynamic_cast<GuiMenuBar*>(mMenuBarCtrl->findObjectByInternalName( ste, true));
|
||||
if( menu )
|
||||
menu->buildWindowAcceleratorMap( *getPlatformWindow()->getInputGenerator() );
|
||||
if(oldMenu)
|
||||
oldMenu->removeWindowAcceleratorMap(*getPlatformWindow()->getInputGenerator());
|
||||
|
||||
if(newMenu)
|
||||
newMenu->buildWindowAcceleratorMap(*getPlatformWindow()->getInputGenerator());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1633,27 +1649,26 @@ void GuiCanvas::maintainSizing()
|
|||
Point2I newPos = screenRect.point;
|
||||
|
||||
// if menubar is active displace content gui control
|
||||
if( mMenuBarCtrl && (ctrl == getContentControl()) )
|
||||
{
|
||||
const SimObject *menu = mMenuBarCtrl->findObjectByInternalName( StringTable->insert("menubar"), true);
|
||||
if (mMenuBarCtrl && (ctrl == getContentControl()))
|
||||
{
|
||||
/*const SimObject *menu = mMenuBarCtrl->findObjectByInternalName( StringTable->insert("menubar"), true);
|
||||
|
||||
if( !menu )
|
||||
continue;
|
||||
if( !menu )
|
||||
continue;
|
||||
|
||||
AssertFatal( dynamic_cast<const GuiControl*>(menu), "");
|
||||
AssertFatal( dynamic_cast<const GuiControl*>(menu), "");*/
|
||||
|
||||
const U32 yOffset = static_cast<const GuiControl*>(menu)->getExtent().y;
|
||||
newPos.y += yOffset;
|
||||
newExt.y -= yOffset;
|
||||
const U32 yOffset = static_cast<const GuiMenuBar*>(mMenuBarCtrl)->mMenubarHeight;
|
||||
newPos.y += yOffset;
|
||||
newExt.y -= yOffset;
|
||||
}
|
||||
|
||||
if(pos != newPos || ext != newExt)
|
||||
if (pos != newPos || ext != newExt)
|
||||
{
|
||||
ctrl->resize(newPos, newExt);
|
||||
resetUpdateRegions();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GuiCanvas::setupFences()
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@ public:
|
|||
virtual void onRemove();
|
||||
|
||||
void setMenuBar(SimObject *obj);
|
||||
SimObject* getMenuBar() { return mMenuBarCtrl; }
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
|
|
@ -334,6 +335,9 @@ public:
|
|||
/// Returns the point, in screenspace, at which the cursor is located.
|
||||
virtual Point2I getCursorPos();
|
||||
|
||||
/// Returns the point, in local coordinates, at which the cursor is located
|
||||
virtual Point2I getCursorPosLocal() { return Point2I(S32(mCursorPt.x), S32(mCursorPt.y)); }
|
||||
|
||||
/// Enable/disable rendering of the cursor.
|
||||
/// @param state True if we should render cursor
|
||||
virtual void showCursor(bool state);
|
||||
|
|
|
|||
|
|
@ -29,11 +29,10 @@
|
|||
#include "gui/containers/guiScrollCtrl.h"
|
||||
#include "gui/editor/inspector/customField.h"
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
#include "gui/editor/inspector/entityGroup.h"
|
||||
#include "gui/editor/inspector/mountingGroup.h"
|
||||
#include "gui/editor/inspector/componentGroup.h"
|
||||
#endif
|
||||
#include "T3D/components/component.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT(GuiInspector);
|
||||
|
||||
|
|
@ -55,7 +54,8 @@ GuiInspector::GuiInspector()
|
|||
mOverDivider( false ),
|
||||
mMovingDivider( false ),
|
||||
mHLField( NULL ),
|
||||
mShowCustomFields( true )
|
||||
mShowCustomFields( true ),
|
||||
mComponentGroupTargetId(-1)
|
||||
{
|
||||
mPadding = 1;
|
||||
}
|
||||
|
|
@ -589,10 +589,16 @@ void GuiInspector::refresh()
|
|||
mGroups.push_back(general);
|
||||
addObject(general);
|
||||
|
||||
#ifdef TORQUE_EXPERIMENTAL_EC
|
||||
//Entity inspector group
|
||||
if (mTargets.first()->getClassRep()->isSubclassOf("Entity"))
|
||||
{
|
||||
//Put the GameObject group before everything that'd be gameobject-effecting, for orginazational purposes
|
||||
GuiInspectorGroup *gameObject = new GuiInspectorGroup("GameObject", this);
|
||||
|
||||
gameObject->registerObject();
|
||||
mGroups.push_back(gameObject);
|
||||
addObject(gameObject);
|
||||
|
||||
GuiInspectorEntityGroup *components = new GuiInspectorEntityGroup("Components", this);
|
||||
if (components != NULL)
|
||||
{
|
||||
|
|
@ -601,6 +607,32 @@ void GuiInspector::refresh()
|
|||
addObject(components);
|
||||
}
|
||||
|
||||
Entity* selectedEntity = dynamic_cast<Entity*>(mTargets.first().getObject());
|
||||
|
||||
U32 compCount = selectedEntity->getComponentCount();
|
||||
//Now, add the component groups
|
||||
for (U32 c = 0; c < compCount; ++c)
|
||||
{
|
||||
Component* comp = selectedEntity->getComponent(c);
|
||||
|
||||
String compName;
|
||||
if (comp->getFriendlyName() != StringTable->EmptyString())
|
||||
compName = comp->getFriendlyName();
|
||||
else
|
||||
compName = comp->getComponentName();
|
||||
|
||||
StringBuilder captionString;
|
||||
captionString.format("%s [%i]", compName.c_str(), comp->getId());
|
||||
|
||||
GuiInspectorGroup *compGroup = new GuiInspectorComponentGroup(captionString.data(), this, comp);
|
||||
if (compGroup != NULL)
|
||||
{
|
||||
compGroup->registerObject();
|
||||
mGroups.push_back(compGroup);
|
||||
addObject(compGroup);
|
||||
}
|
||||
}
|
||||
|
||||
//Mounting group override
|
||||
GuiInspectorGroup *mounting = new GuiInspectorMountingGroup("Mounting", this);
|
||||
if (mounting != NULL)
|
||||
|
|
@ -611,21 +643,6 @@ void GuiInspector::refresh()
|
|||
}
|
||||
}
|
||||
|
||||
if (mTargets.first()->getClassRep()->isSubclassOf("Component"))
|
||||
{
|
||||
//Build the component field groups as the component describes it
|
||||
Component* comp = dynamic_cast<Component*>(mTargets.first().getPointer());
|
||||
|
||||
if (comp->getComponentFieldCount() > 0)
|
||||
{
|
||||
GuiInspectorComponentGroup *compGroup = new GuiInspectorComponentGroup("Component Fields", this);
|
||||
compGroup->registerObject();
|
||||
mGroups.push_back(compGroup);
|
||||
addObject(compGroup);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create the inspector groups for static fields.
|
||||
|
||||
for( TargetVector::iterator iter = mTargets.begin(); iter != mTargets.end(); ++ iter )
|
||||
|
|
|
|||
|
|
@ -89,6 +89,9 @@ public:
|
|||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
S32 getComponentGroupTargetId() { return mComponentGroupTargetId; }
|
||||
void setComponentGroupTargetId(S32 compId) { mComponentGroupTargetId = compId; }
|
||||
|
||||
/// Return the number of objects being inspected by this GuiInspector.
|
||||
U32 getNumInspectObjects() const { return mTargets.size(); }
|
||||
|
|
@ -146,6 +149,8 @@ protected:
|
|||
|
||||
/// Objects being inspected by this GuiInspector.
|
||||
TargetVector mTargets;
|
||||
|
||||
S32 mComponentGroupTargetId;
|
||||
|
||||
F32 mDividerPos;
|
||||
S32 mDividerMargin;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -23,119 +23,43 @@
|
|||
#ifndef _GUIMENUBAR_H_
|
||||
#define _GUIMENUBAR_H_
|
||||
|
||||
#ifndef _GUITEXTLISTCTRL_H_
|
||||
#include "gui/controls/guiTextListCtrl.h"
|
||||
#endif
|
||||
#ifndef _GUITICKCTRL_H_
|
||||
#include "gui/shiny/guiTickCtrl.h"
|
||||
#endif
|
||||
|
||||
#ifndef _POPUPMENU_H_
|
||||
#include "gui/editor/popupMenu.h"
|
||||
#endif
|
||||
|
||||
class GuiMenuBar;
|
||||
class GuiMenuTextListCtrl;
|
||||
class WindowInputGenerator;
|
||||
|
||||
class GuiMenuBackgroundCtrl : public GuiControl
|
||||
{
|
||||
typedef GuiControl Parent;
|
||||
|
||||
protected:
|
||||
GuiMenuBar *mMenuBarCtrl;
|
||||
GuiMenuTextListCtrl *mTextList;
|
||||
public:
|
||||
GuiMenuBackgroundCtrl(GuiMenuBar *ctrl, GuiMenuTextListCtrl* textList);
|
||||
void onMouseDown(const GuiEvent &event);
|
||||
void onMouseMove(const GuiEvent &event);
|
||||
void onMouseDragged(const GuiEvent &event);
|
||||
};
|
||||
|
||||
class GuiSubmenuBackgroundCtrl : public GuiMenuBackgroundCtrl
|
||||
{
|
||||
typedef GuiMenuBackgroundCtrl Parent;
|
||||
|
||||
public:
|
||||
GuiSubmenuBackgroundCtrl(GuiMenuBar *ctrl, GuiMenuTextListCtrl* textList);
|
||||
bool pointInControl(const Point2I & parentCoordPoint);
|
||||
void onMouseDown(const GuiEvent &event);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class GuiMenuTextListCtrl : public GuiTextListCtrl
|
||||
{
|
||||
private:
|
||||
typedef GuiTextListCtrl Parent;
|
||||
|
||||
protected:
|
||||
GuiMenuBar *mMenuBarCtrl;
|
||||
|
||||
public:
|
||||
bool isSubMenu; // Indicates that this text list is in a submenu
|
||||
|
||||
GuiMenuTextListCtrl(); // for inheritance
|
||||
GuiMenuTextListCtrl(GuiMenuBar *ctrl);
|
||||
|
||||
// GuiControl overloads:
|
||||
bool onKeyDown(const GuiEvent &event);
|
||||
void onMouseDown(const GuiEvent &event);
|
||||
void onMouseUp(const GuiEvent &event);
|
||||
void onRenderCell(Point2I offset, Point2I cell, bool selected, bool mouseOver);
|
||||
|
||||
virtual void onCellHighlighted(Point2I cell); // Added
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class GuiMenuBar : public GuiTickCtrl // Was: GuiControl
|
||||
{
|
||||
typedef GuiTickCtrl Parent; // Was: GuiControl Parent;
|
||||
public:
|
||||
|
||||
struct Menu;
|
||||
struct MenuEntry
|
||||
{
|
||||
U32 pos;
|
||||
RectI bounds;
|
||||
|
||||
struct MenuItem // an individual item in a pull-down menu
|
||||
{
|
||||
char *text; // the text of the menu item
|
||||
U32 id; // a script-assigned identifier
|
||||
char *accelerator; // the keyboard accelerator shortcut for the menu item
|
||||
U32 acceleratorIndex; // index of this accelerator
|
||||
bool enabled; // true if the menu item is selectable
|
||||
bool visible; // true if the menu item is visible
|
||||
S32 bitmapIndex; // index of the bitmap in the bitmap array
|
||||
S32 checkGroup; // the group index of the item visa vi check marks -
|
||||
// only one item in the group can be checked.
|
||||
MenuItem *nextMenuItem; // next menu item in the linked list
|
||||
|
||||
bool isSubmenu; // This menu item has a submenu that will be displayed
|
||||
|
||||
Menu* submenuParentMenu; // For a submenu, this is the parent menu
|
||||
Menu* submenu;
|
||||
String cmd;
|
||||
};
|
||||
|
||||
struct Menu
|
||||
{
|
||||
char *text;
|
||||
U32 id;
|
||||
RectI bounds;
|
||||
bool visible;
|
||||
|
||||
S32 bitmapIndex; // Index of the bitmap in the bitmap array (-1 = no bitmap)
|
||||
bool drawBitmapOnly; // Draw only the bitmap and not the text
|
||||
bool drawBorder; // Should a border be drawn around this menu (usually if we only have a bitmap, we don't want a border)
|
||||
S32 bitmapIndex;
|
||||
bool drawBitmapOnly;
|
||||
|
||||
Menu *nextMenu;
|
||||
MenuItem *firstMenuItem;
|
||||
};
|
||||
|
||||
GuiMenuBackgroundCtrl *mBackground;
|
||||
GuiMenuTextListCtrl *mTextList;
|
||||
|
||||
GuiSubmenuBackgroundCtrl *mSubmenuBackground; // Background for a submenu
|
||||
GuiMenuTextListCtrl *mSubmenuTextList; // Text list for a submenu
|
||||
bool drawBorder;
|
||||
|
||||
Vector<Menu*> mMenuList;
|
||||
Menu *mouseDownMenu;
|
||||
Menu *mouseOverMenu;
|
||||
StringTableEntry text;
|
||||
PopupMenu* popupMenu;
|
||||
};
|
||||
|
||||
Vector<MenuEntry> mMenuList;
|
||||
|
||||
MenuEntry *mouseDownMenu;
|
||||
MenuEntry *mouseOverMenu;
|
||||
|
||||
MenuItem* mouseDownSubmenu; // Stores the menu item that is a submenu that has been selected
|
||||
MenuItem* mouseOverSubmenu; // Stores the menu item that is a submenu that has been highlighted
|
||||
|
|
@ -151,59 +75,26 @@ public:
|
|||
S32 mVerticalMargin; // Top and bottom margin around the text of each menu
|
||||
S32 mBitmapMargin; // Margin between a menu's bitmap and text
|
||||
|
||||
// Used to keep track of the amount of ticks that the mouse is hovering
|
||||
// over a menu.
|
||||
S32 mMouseOverCounter;
|
||||
bool mCountMouseOver;
|
||||
S32 mMouseHoverAmount;
|
||||
U32 mMenubarHeight;
|
||||
|
||||
bool mMouseInMenu;
|
||||
|
||||
GuiMenuBar();
|
||||
|
||||
void onRemove();
|
||||
bool onWake();
|
||||
void onSleep();
|
||||
|
||||
// internal menu handling functions
|
||||
// these are used by the script manipulation functions to add/remove/change menu items
|
||||
static Menu* sCreateMenu(const char *menuText, U32 menuId);
|
||||
void addMenu(Menu *menu, S32 pos = -1);
|
||||
void addMenu(const char *menuText, U32 menuId);
|
||||
Menu *findMenu(const char *menu); // takes either a menu text or a string id
|
||||
static MenuItem *findMenuItem(Menu *menu, const char *menuItem); // takes either a menu text or a string id
|
||||
void removeMenu(Menu *menu);
|
||||
static void removeMenuItem(Menu *menu, MenuItem *menuItem);
|
||||
static MenuItem* addMenuItem(Menu *menu, const char *text, U32 id, const char *accelerator, S32 checkGroup, const char *cmd);
|
||||
static MenuItem* addMenuItem(Menu *menu, MenuItem *menuItem);
|
||||
static void clearMenuItems(Menu *menu);
|
||||
void clearMenus();
|
||||
virtual void addObject(SimObject* object);
|
||||
|
||||
void attachToMenuBar(Menu* menu, S32 pos = -1);
|
||||
void removeFromMenuBar(Menu* menu);
|
||||
|
||||
// Methods to deal with submenus
|
||||
static MenuItem* findSubmenuItem(Menu *menu, const char *menuItem, const char *submenuItem);
|
||||
static MenuItem* findSubmenuItem(MenuItem *menuItem, const char *submenuItem);
|
||||
static void addSubmenuItem(Menu *menu, MenuItem *submenu, const char *text, U32 id, const char *accelerator, S32 checkGroup);
|
||||
static void addSubmenuItem(Menu *menu, MenuItem *submenu, MenuItem *newMenuItem );
|
||||
static void removeSubmenuItem(MenuItem *menuItem, MenuItem *submenuItem);
|
||||
static void clearSubmenuItems(MenuItem *menuitem);
|
||||
void onSubmenuAction(S32 selectionIndex, const RectI& bounds, Point2I cellSize);
|
||||
void closeSubmenu();
|
||||
void checkSubmenuMouseMove(const GuiEvent &event);
|
||||
MenuItem *findHitMenuItem(Point2I mousePoint);
|
||||
|
||||
void highlightedMenuItem(S32 selectionIndex, const RectI& bounds, Point2I cellSize); // Called whenever a menu item is highlighted by the mouse
|
||||
|
||||
// display/mouse functions
|
||||
|
||||
Menu *findHitMenu(Point2I mousePoint);
|
||||
|
||||
// Called when the GUI theme changes and a bitmap arrary may need updating
|
||||
// void onThemeChange();
|
||||
MenuEntry *findHitMenu(Point2I mousePoint);
|
||||
|
||||
void onPreRender();
|
||||
void onRender(Point2I offset, const RectI &updateRect);
|
||||
|
||||
void checkMenuMouseMove(const GuiEvent &event);
|
||||
void onMouseMove(const GuiEvent &event);
|
||||
void onMouseEnter(const GuiEvent &event);
|
||||
void onMouseLeave(const GuiEvent &event);
|
||||
void onMouseDown(const GuiEvent &event);
|
||||
void onMouseDragged(const GuiEvent &event);
|
||||
|
|
@ -215,18 +106,22 @@ public:
|
|||
void removeWindowAcceleratorMap( WindowInputGenerator &inputGenerator );
|
||||
void acceleratorKeyPress(U32 index);
|
||||
|
||||
virtual void menuItemSelected(Menu *menu, MenuItem *item);
|
||||
|
||||
// Added to support 'ticks'
|
||||
void processTick();
|
||||
|
||||
void insert(SimObject* pObject, S32 pos);
|
||||
|
||||
static void initPersistFields();
|
||||
|
||||
U32 getMenuListCount() { return mMenuList.size(); }
|
||||
|
||||
PopupMenu* getMenu(U32 index);
|
||||
PopupMenu* findMenu(StringTableEntry barTitle);
|
||||
|
||||
DECLARE_CONOBJECT(GuiMenuBar);
|
||||
DECLARE_CALLBACK( void, onMouseInMenu, ( bool hasLeftMenu ));
|
||||
DECLARE_CALLBACK( void, onMenuSelect, ( S32 menuId, const char* menuText ));
|
||||
DECLARE_CALLBACK( void, onMenuItemSelect, ( S32 menuId, const char* menuText, S32 menuItemId, const char* menuItemText ));
|
||||
DECLARE_CALLBACK( void, onSubmenuSelect, ( S32 submenuId, const char* submenuText ));
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue