Merge remote-tracking branch 'main/Preview4_0' into adjustment-unix-platform

This commit is contained in:
Robert MacGregor 2021-11-17 21:38:48 -05:00
commit b986589804
33 changed files with 363 additions and 478 deletions

View file

@ -549,7 +549,20 @@ bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const
if (!filename || !filename[0])
return false;
GFXTexHandle texture(filename, &GFXStaticTextureSRGBProfile, avar("%s() - tooltip texture (line %d)", __FUNCTION__, __LINE__));
StringTableEntry previewFilename = filename;
if (Con::isFunction("getAssetPreviewImage"))
{
ConsoleValue consoleRet = Con::executef("getAssetPreviewImage", filename);
previewFilename = StringTable->insert(consoleRet.getString());
if (AssetDatabase.isDeclaredAsset(previewFilename))
{
ImageAsset* previewAsset = AssetDatabase.acquireAsset<ImageAsset>(previewFilename);
previewFilename = previewAsset->getImagePath();
}
}
GFXTexHandle texture(previewFilename, &GFXStaticTextureSRGBProfile, avar("%s() - tooltip texture (line %d)", __FUNCTION__, __LINE__));
if (texture.isNull())
return false;

View file

@ -1158,12 +1158,76 @@ static bool enumColladaForImport(const char* shapePath, GuiTreeViewCtrl* tree, b
{
domImage* img = libraryImages->getImage_array()[j];
S32 materialID = tree->findItemByName(_GetNameOrId(img));
String imageName = _GetNameOrId(img);
S32 materialID = tree->findItemByName(imageName.c_str());
if (materialID == 0)
continue;
{
bool materialFound = false;
String matName = "";
tree->setItemValue(materialID, img->getInit_from()->getValue().str().c_str());
//If we don't have an immediate name match, we'll have to actually go look it up
for (S32 e = 0; e < root->getLibrary_effects_array().getCount(); e++)
{
const domLibrary_effects* libraryEffects = root->getLibrary_effects_array()[e];
for (S32 f = 0; f < libraryEffects->getEffect_array().getCount(); f++)
{
domEffect* efct = libraryEffects->getEffect_array()[f];
String effectName = efct->getID();
for (S32 p = 0; p < efct->getFx_profile_abstract_array().getCount(); p++)
{
domProfile_COMMON* profile = daeSafeCast<domProfile_COMMON>(efct->getFx_profile_abstract_array()[p]);
for (S32 n = 0; n < profile->getNewparam_array().getCount(); n++)
{
domCommon_newparam_typeRef param = profile->getNewparam_array()[n];
String paramName = param->getSid();
if (paramName.endsWith("-surface"))
{
//ok it's surface data, parse out the name
String surfaceName = paramName.substr(0, paramName.length() - 8);
if (surfaceName == imageName)
{
//got a match!
matName = effectName;
if (matName.endsWith("-effect"))
{
matName = matName.substr(0, matName.length() - 7);
materialFound = true;
break;
}
}
}
}
if (materialFound)
break;
}
if (materialFound)
{
materialID = tree->findItemByName(matName.c_str());
}
if (materialID != 0)
break;
}
}
//if we STILL haven't found a match, then yes, we've failed
if (materialID == 0)
continue;
}
String imagePath = img->getInit_from()->getValue().str().c_str();
if (imagePath.startsWith("/"))
imagePath = imagePath.substr(1, imagePath.length() - 1);
tree->setItemValue(materialID, StringTable->insert(imagePath.c_str()));
}
}
@ -2317,6 +2381,9 @@ void AssetImporter::resetImportConfig()
Settings* importConfigs;
if (Sim::findObject("AssetImportSettings", importConfigs))
{
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Loading import config: %s!", defaultImportConfig.c_str());
activityLog.push_back(importLogBuffer);
//Now load the editor setting-deigned config!
activeImportConfig->loadImportConfig(importConfigs, defaultImportConfig.c_str());
}
@ -2734,7 +2801,7 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
}
else if (imageType == ImageAsset::ImageTypes::Metalness)
{
mapFieldName = "MetalnessMap";
mapFieldName = "MetalMap";
}
else if (imageType == ImageAsset::ImageTypes::AO)
{
@ -2742,7 +2809,7 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
}
else if (imageType == ImageAsset::ImageTypes::Roughness)
{
mapFieldName = "RoughnessMap";
mapFieldName = "RoughMap";
}
assetFieldName = mapFieldName + "Asset[0]";
@ -2810,7 +2877,7 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
}
else if (imageType == ImageAsset::ImageTypes::Metalness)
{
mapFieldName = "MetalnessMap";
mapFieldName = "MetalMap";
}
else if (imageType == ImageAsset::ImageTypes::AO)
{
@ -2818,7 +2885,7 @@ Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
}
else if (imageType == ImageAsset::ImageTypes::Roughness)
{
mapFieldName = "RoughnessMap";
mapFieldName = "RoughMap";
hasRoughness = true;
}

View file

@ -905,9 +905,15 @@ public:
/// </summary>
AssetImportConfig* getImportConfig() { return activeImportConfig; }
void setImportConfig(AssetImportConfig* importConfig) {
if(importConfig != nullptr)
void setImportConfig(AssetImportConfig* importConfig)
{
if (importConfig != nullptr)
{
dSprintf(importLogBuffer, sizeof(importLogBuffer), "Loading import config: %s!", importConfig->getName());
activityLog.push_back(importLogBuffer);
activeImportConfig = importConfig;
}
}
/// <summary>

View file

@ -57,11 +57,16 @@ namespace Compiler
using namespace Compiler;
FuncVars gEvalFuncVars;
FuncVars gGlobalScopeFuncVars;
FuncVars* gFuncVars = NULL;
inline FuncVars* getFuncVars(S32 lineNumber)
{
AssertISV(gFuncVars, avar("Attemping to use local variable in global scope. File: %s Line: %d", CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
if (gFuncVars == &gGlobalScopeFuncVars)
{
const char* str = avar("Attemping to use local variable in global scope. File: %s Line: %d", CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
scriptErrorHandler(str);
}
return gFuncVars;
}
@ -1552,8 +1557,7 @@ U32 FunctionDeclStmtNode::compileStmt(CodeStream& codeStream, U32 ip)
tbl->add(fnName, nameSpace, varName);
}
// In eval mode, global func vars are allowed.
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : NULL;
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : &gGlobalScopeFuncVars;
return ip;
}

View file

@ -38,6 +38,7 @@ CodeBlock * CodeBlock::smCurrentCodeBlock = NULL;
ConsoleParser *CodeBlock::smCurrentParser = NULL;
extern FuncVars gEvalFuncVars;
extern FuncVars gGlobalScopeFuncVars;
extern FuncVars* gFuncVars;
//-------------------------------------------------------------------------
@ -637,8 +638,7 @@ ConsoleValue CodeBlock::compileExec(StringTableEntry fileName, const char *inStr
// we are an eval compile if we don't have a file name associated (no exec)
gIsEvalCompile = fileName == NULL;
// In eval mode, global func vars are allowed.
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : NULL;
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : &gGlobalScopeFuncVars;
// Set up the parser.
smCurrentParser = getParserForFile(fileName);
@ -678,7 +678,7 @@ ConsoleValue CodeBlock::compileExec(StringTableEntry fileName, const char *inStr
codeStream.emit(OP_RETURN_VOID);
codeStream.emitCodeStream(&codeSize, &code, &lineBreakPairs);
S32 localRegisterCount = gIsEvalCompile ? gEvalFuncVars.count() : 0;
S32 localRegisterCount = gIsEvalCompile ? gEvalFuncVars.count() : gGlobalScopeFuncVars.count();
consoleAllocReset();

View file

@ -691,7 +691,8 @@ ConsoleValue CodeBlock::exec(U32 ip, const char* functionName, Namespace* thisNa
setFrame = -1;
// Do we want this code to execute using a new stack frame?
if (setFrame < 0)
// compiling a file will force setFrame to 0, forcing us to get a new frame.
if (setFrame <= 0)
{
// argc is the local count for eval
gEvalState.pushFrame(NULL, NULL, argc);

View file

@ -35,6 +35,13 @@
#include "console/simBase.h"
extern FuncVars gEvalFuncVars;
extern FuncVars gGlobalScopeFuncVars;
extern FuncVars *gFuncVars;
namespace Con
{
extern bool scriptWarningsAsAsserts;
};
namespace Compiler
{
@ -124,12 +131,24 @@ namespace Compiler
getFunctionStringTable().reset();
getIdentTable().reset();
getFunctionVariableMappingTable().reset();
gEvalFuncVars.clear();
gGlobalScopeFuncVars.clear();
gFuncVars = gIsEvalCompile ? &gEvalFuncVars : &gGlobalScopeFuncVars;
}
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
void scriptErrorHandler(const char* str)
{
if (Con::scriptWarningsAsAsserts)
{
AssertISV(false, str);
}
else
{
Con::warnf(ConsoleLogEntry::Type::Script, "%s", str);
}
}
}
//-------------------------------------------------------------------------
@ -141,7 +160,11 @@ S32 FuncVars::assign(StringTableEntry var, TypeReq currentType, S32 lineNumber,
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
if (found != vars.end())
{
AssertISV(!found->second.isConstant, avar("Reassigning variable %s when it is a constant. File: %s Line : %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
if (found->second.isConstant)
{
const char* str = avar("Script Warning: Reassigning variable %s when it is a constant. File: %s Line : %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
scriptErrorHandler(str);
}
return found->second.reg;
}
@ -155,7 +178,15 @@ S32 FuncVars::assign(StringTableEntry var, TypeReq currentType, S32 lineNumber,
S32 FuncVars::lookup(StringTableEntry var, S32 lineNumber)
{
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
AssertISV(found != vars.end(), avar("Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
if (found == vars.end())
{
const char* str = avar("Script Warning: Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
scriptErrorHandler(str);
return assign(var, TypeReqString, lineNumber, false);
}
return found->second.reg;
}
@ -163,7 +194,15 @@ TypeReq FuncVars::lookupType(StringTableEntry var, S32 lineNumber)
{
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
AssertISV(found != vars.end(), avar("Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
if (found == vars.end())
{
const char* str = avar("Script Warning: Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber);
scriptErrorHandler(str);
assign(var, TypeReqString, lineNumber, false);
return vars.find(var)->second.currentType;
}
return found->second.currentType;
}

View file

@ -275,6 +275,8 @@ namespace Compiler
void *consoleAlloc(U32 size);
void consoleAllocReset();
void scriptErrorHandler(const char* str);
extern bool gSyntaxError;
extern bool gIsEvalCompile;
};

View file

@ -274,6 +274,7 @@ static Vector< String > sInstantGroupStack( __FILE__, __LINE__ );
static DataChunker consoleLogChunker;
static Vector<ConsoleLogEntry> consoleLog(__FILE__, __LINE__);
static bool consoleLogLocked;
bool scriptWarningsAsAsserts = true;
static bool logBufferEnabled=true;
static S32 printLevel = 10;
static FileStream consoleLogFile;
@ -353,7 +354,7 @@ void init()
ConsoleConstructor::setup();
// Set up the parser(s)
CON_ADD_PARSER(CMD, TORQUE_SCRIPT_EXTENSION, true); // TorqueScript
CON_ADD_PARSER(CMD, (char*)TORQUE_SCRIPT_EXTENSION, true); // TorqueScript
// Setup the console types.
ConsoleBaseType::initialize();
@ -377,6 +378,7 @@ void init()
addVariable("Con::objectCopyFailures", TypeS32, &gObjectCopyFailures, "If greater than zero then it counts the number of object creation "
"failures based on a missing copy object and does not report an error..\n"
"@ingroup Console\n");
addVariable("Con::scriptWarningsAsAsserts", TypeBool, &scriptWarningsAsAsserts, "If true, script warnings (outside of syntax errors) will be treated as fatal asserts.");
// Current script file name and root
addVariable( "Con::File", TypeString, &gCurrentFile, "The currently executing script file.\n"

View file

@ -1644,7 +1644,7 @@ void PostEffect::setTexture( U32 index, const String &texFilePath )
void PostEffect::setTexture(U32 index, const GFXTexHandle& texHandle)
{
// Set the new texture name.
mTextureName[index] = "";
mTextureName[index] = StringTable->EmptyString();
mTexture[index].free();
// Skip empty stages or ones with variable or target names.

View file

@ -290,7 +290,7 @@ bool RenderProbeMgr::onAdd()
}
String brdfTexturePath = GFXTextureManager::getBRDFTexturePath();
if (!mBRDFTexture.set(brdfTexturePath, &GFXTexturePersistentSRGBProfile, "BRDFTexture"))
if (!mBRDFTexture.set(brdfTexturePath, &GFXTexturePersistentProfile, "BRDFTexture"))
{
Con::errorf("RenderProbeMgr::onAdd: Failed to load BRDF Texture");
return false;

View file

@ -179,7 +179,7 @@ void AssimpShapeLoader::enumerateScene()
String importFormat;
const aiImporterDesc* importerDescription = aiGetImporterDesc(shapePath.getExtension().c_str());
if (importerDescription->mName == "Autodesk FBX Importer")
if (StringTable->insert(importerDescription->mName) == StringTable->insert("Autodesk FBX Importer"))
{
ColladaUtils::getOptions().formatScaleFactor = 0.01f;
}