From 1bad377be1b1e1d2377dd17442181a436a42cbd1 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sun, 10 Jan 2021 15:59:51 -0600 Subject: [PATCH 01/13] add a %this.registerMissionObject( "SpawnSphere", "General Spawn Sphere", "GeneralDropPoint" ); to the level creator folder --- .../tools/worldEditor/gui/objectBuilderGui.ed.gui | 13 +++++++++++++ .../tools/worldEditor/scripts/editors/creator.ed.cs | 1 + 2 files changed, 14 insertions(+) diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui index 28117af2e..3533b4f41 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui @@ -1072,6 +1072,19 @@ function ObjectBuilderGui::buildObserverDropPoint(%this) %this.process(); } +function ObjectBuilderGui::buildGeneralDropPoint(%this) +{ + %this.objectClassName = "SpawnSphere"; + %this.addField("dataBlock", "TypeDataBlock", "dataBlock", "MissionMarkerData SpawnSphereMarker"); + %this.addField("radius", "TypeFloat", "Radius", 1); + %this.addField("sphereWeight", "TypeFloat", "Sphere Weight", 1); + + %this.addField("spawnClass", "TypeString", "Spawn Class", ""); + %this.addField("spawnDatablock", "TypeString", "Spawn Data", ""); + %this.addField("spawnTransform", "TypeBool", "Spawn Here", "true"); + %this.process(); +} + function ObjectBuilderGui::buildNotesObject(%this) { %this.objectClassName = "NotesObject"; diff --git a/Templates/BaseGame/game/tools/worldEditor/scripts/editors/creator.ed.cs b/Templates/BaseGame/game/tools/worldEditor/scripts/editors/creator.ed.cs index 8b5e706da..08bd46598 100644 --- a/Templates/BaseGame/game/tools/worldEditor/scripts/editors/creator.ed.cs +++ b/Templates/BaseGame/game/tools/worldEditor/scripts/editors/creator.ed.cs @@ -87,6 +87,7 @@ function EWCreatorWindow::init( %this ) %this.registerMissionObject( "Portal", "Zone Portal" ); %this.registerMissionObject( "SpawnSphere", "Player Spawn Sphere", "PlayerDropPoint" ); %this.registerMissionObject( "SpawnSphere", "Observer Spawn Sphere", "ObserverDropPoint" ); + %this.registerMissionObject( "SpawnSphere", "General Spawn Sphere", "GeneralDropPoint" ); %this.registerMissionObject( "SFXSpace", "Sound Space" ); %this.registerMissionObject( "OcclusionVolume", "Occlusion Volume" ); %this.registerMissionObject( "AccumulationVolume", "Accumulation Volume" ); From 7e3e1941c685c740e3f1762223d1741621e920db Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Wed, 27 Jan 2021 14:03:12 -0600 Subject: [PATCH 02/13] add a toggle for the standard canSaveDynamicFields flipped by default to off so folks can bolt variables on the fly onto the spawner (like thing spawned, how many ect) without it poluting level saves --- .../BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui | 1 + 1 file changed, 1 insertion(+) diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui index 3533b4f41..34fa23b8f 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/objectBuilderGui.ed.gui @@ -1082,6 +1082,7 @@ function ObjectBuilderGui::buildGeneralDropPoint(%this) %this.addField("spawnClass", "TypeString", "Spawn Class", ""); %this.addField("spawnDatablock", "TypeString", "Spawn Data", ""); %this.addField("spawnTransform", "TypeBool", "Spawn Here", "true"); + %this.addField("canSaveDynamicFields", "TypeBool", "Save metadata", "false"); %this.process(); } From 3d2f3bda64a63addf8a55b80806cc6ad3751d3a1 Mon Sep 17 00:00:00 2001 From: Marc Date: Thu, 18 Mar 2021 21:37:36 +0000 Subject: [PATCH 03/13] Fixes a resolution switching issue when the game uses **only** OpenGL as the renderer Canvas.tscript fixes provided by @OTHG_Mars --- Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp | 11 ++++++++- .../game/core/gui/scripts/canvas.tscript | 24 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp index 785c1c9c3..a74be76ca 100644 --- a/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp +++ b/Engine/source/gfx/gl/sdl/gfxGLDevice.sdl.cpp @@ -58,7 +58,16 @@ void EnumerateVideoModes(Vector& outModes) GFXVideoMode outMode; outMode.resolution.set( mode.w, mode.h ); outMode.refreshRate = mode.refresh_rate; - outMode.bitDepth = SDL_BYTESPERPIXEL( mode.format ); + + // BBP = 32 for some reason the engine knows it should be 32, but then we + // add some extra code to break what the engine knows. + //outMode.bitDepth = SDL_BYTESPERPIXEL( mode.format ); // sets bitdepths to 4 + //outMode.bitDepth = SDL_BITSPERPIXEL(mode.format); // sets bitdepth to 24 + + // hardcoded magic numbers ftw + // This value is hardcoded in DX, probably to avoid the shenanigans going on here + outMode.bitDepth = 32; + outMode.wideScreen = (mode.w / mode.h) > (4 / 3); outMode.fullScreen = true; diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 51a2cd55f..818447de5 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -155,6 +155,10 @@ function GuiCanvas::prefsToModeStr(%this) function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startup) { + // Toggle for selecting the borderless window allowed sizes. Set true to allow + // boderless windows to be less than the device res. + %allowSmallBorderless = true; + %resX = getWord(%mode, $WORD::RES_X); %resY = getWord(%mode, $WORD::RES_Y); @@ -175,6 +179,9 @@ function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startu if ((%resX > %deviceRect.x) || (%resY > %deviceRect.y)) return false; + if (!%allowSmallBorderless && ((%resX != %deviceRect.x) || (%resY != %deviceRect.y))) + return false; + return true; } @@ -202,7 +209,8 @@ function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startu return false; } -// Find the best video mode setting for the device and display mode +// Find the best video mode setting for the device and display mode. +// "Best" is the largest resolution that will fit at highest refresh rate. function GuiCanvas::getBestCanvasRes(%this, %deviceId, %deviceMode) { if (%deviceMode == $Video::ModeWindowed) @@ -210,19 +218,25 @@ function GuiCanvas::getBestCanvasRes(%this, %deviceId, %deviceMode) else %deviceRect = getWords(%this.getMonitorRect(%deviceId), 2); + %bestRes = ""; %resCount = %this.getModeCount(); for (%i = %resCount - 1; %i >= 0; %i--) { %testRes = %this.getMode(%i); %resX = getWord(%testRes, $WORD::RES_X); %resY = getWord(%testRes, $WORD::RES_Y); + %rate = getWord(%testRes, $WORD::REFRESH); - if ((%resX > %deviceRect.x) || (%resY > %deviceRect.y)) + if ((%resX > %deviceRect.x) || (%resY > %deviceRect.y) || + (%resX < $Video::minimumXResolution) || (%resY < $Video::minimumYResolution)) continue; - return %testRes; + if (((%bestRes $= "") || (%resX > getWord(%bestRes, $WORD::RES_X)) || + (%resY > getWord(%bestRes, $WORD::RES_Y))) || + ((%resX == getWord(%bestRes, $WORD::RES_X)) && (%resY == getWord(%bestRes, $WORD::RES_Y)) && + (%rate > getWord(%bestRes, $WORD::REFRESH)))) + %bestRes = %testRes; } - // Nothing found? return first mode - return %this.getMonitorMode(%deviceId, 0); + return %bestRes; } From b7b4ced8d6f14632ceb2012dabb8590ce7782fd2 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 2 Apr 2021 14:08:26 -0500 Subject: [PATCH 04/13] adds binary to decimal and vice versa methods --- Engine/source/math/mConsoleFunctions.cpp | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Engine/source/math/mConsoleFunctions.cpp b/Engine/source/math/mConsoleFunctions.cpp index 5252d2306..0113e9126 100644 --- a/Engine/source/math/mConsoleFunctions.cpp +++ b/Engine/source/math/mConsoleFunctions.cpp @@ -424,3 +424,32 @@ DefineEngineFunction(mGetSignedAngleBetweenVectors, F32, (VectorF vecA, VectorF return MathUtils::getSignedAngleBetweenVectors(vecA, vecB, norm); } + +DefineEngineFunction(mBinToDec, S32, (String n),,"convert a binary to decimal") +{ + String num = n; + int dec_value = 0; + + // Initializing base value to 1, i.e 2^0 + int base = 1; + + int len = num.length(); + for (int i = len - 1; i >= 0; i--) { + if (num[i] == '1')//pick out our 1s and concatenate + dec_value += base; + base = base * 2;//next power of 2 + } + + return dec_value; +} + +DefineEngineFunction(mDecToBin, const char*, (S32 n), , "convert decimal to a binary") +{ + String ret; + while (n > 0) { + int r = n % 2;//modulus aka remainder of 2. nets you a 0 or a 1 + n /= 2;//next power of 2 + ret = String::ToString("%i",r) + ret;//add to the front of the stack + } + return ret.c_str(); +} From ab878eb312b089275b92b9854d866dfa92ef0d2d Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 6 Apr 2021 14:54:53 -0500 Subject: [PATCH 05/13] report which profile usages are conflicting (was,is) --- Engine/source/gfx/gfxTextureManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/gfx/gfxTextureManager.cpp b/Engine/source/gfx/gfxTextureManager.cpp index db1a4135e..8341b1b6c 100644 --- a/Engine/source/gfx/gfxTextureManager.cpp +++ b/Engine/source/gfx/gfxTextureManager.cpp @@ -271,7 +271,7 @@ GFXTextureObject *GFXTextureManager::_lookupTexture( const char *hashName, const if (ret && (ret->mProfile->compareFlags(*profile))) return ret; else if (ret) - Con::warnf("GFXTextureManager::_lookupTexture: Cached texture %s has a different profile flag", hashName); + Con::warnf("GFXTextureManager::_lookupTexture: Cached texture %s has different profile flags: (%s,%s) ", hashName, ret->mProfile->getName().c_str(), profile->getName().c_str()); return NULL; } From ab1661a85103639a761e295f9186a97c13220d20 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 6 Apr 2021 15:17:06 -0500 Subject: [PATCH 06/13] add additional chars to the flatfile->asset->objectID name santization chain --- Engine/source/T3D/assets/assetImporter.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index f399fc108..ff7a76a45 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -599,7 +599,13 @@ AssetImportObject* AssetImporter::addImportingAsset(String assetType, Torque::Pa assetImportObj->registerObject(); //sanitize - assetName.replace(" ", "_"); + assetName.replace(' ', '_'); + assetName.replace('~', '_'); + assetName.replace('`', '_'); + assetName.replace('-', '_'); + assetName.replace('*', '_'); + assetName.replace('-', '_'); + assetName.replace('+', '_'); assetImportObj->assetType = assetType; assetImportObj->filePath = filePath; From 92abfb8ccf93f0fc19065ec40355dca9505a321c Mon Sep 17 00:00:00 2001 From: Areloch Date: Thu, 8 Apr 2021 20:31:48 -0500 Subject: [PATCH 07/13] Updates the masterserver domain referenced in the default scripts, pointing it to the new torque3d master server --- .../game/core/clientServer/scripts/server/defaults.tscript | 2 +- Templates/BaseGame/game/data/defaults.tscript | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.tscript b/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.tscript index ed213e99d..f33b4a4bb 100644 --- a/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.tscript +++ b/Templates/BaseGame/game/core/clientServer/scripts/server/defaults.tscript @@ -25,7 +25,7 @@ // List of master servers to query, each one is tried in order // until one responds $Pref::Server::RegionMask = 2; -$pref::Master[0] = "2:master.garagegames.com:28002"; +$pref::Master[0] = "2:master.torque3d.org:5664"; // Information about the server $Pref::Server::Name = "Torque 3D Server"; diff --git a/Templates/BaseGame/game/data/defaults.tscript b/Templates/BaseGame/game/data/defaults.tscript index eaea83a8d..6e6a2413c 100644 --- a/Templates/BaseGame/game/data/defaults.tscript +++ b/Templates/BaseGame/game/data/defaults.tscript @@ -5,6 +5,8 @@ $pref::Player::zoomSpeed = 0; $pref::Net::LagThreshold = 400; $pref::Net::Port = 28000; +$pref::Master[0] = "2:master.torque3d.org:5664"; + $pref::HudMessageLogSize = 40; $pref::ChatHudLength = 1; From fadafbfa1b85d59a64da70ef3069cde3a0b1a575 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sun, 11 Apr 2021 19:57:31 -0500 Subject: [PATCH 08/13] form steve yorkshire: mat editor save extension fix --- .../tools/materialEditor/scripts/materialEditor.ed.tscript | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript index bcb2b2c29..cf4ac6e40 100644 --- a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript +++ b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript @@ -2551,7 +2551,7 @@ function MaterialEditorGui::saveCompositeMap(%this) %saveAs = ""; %dlg = new SaveFileDialog() { - Filters = "png"; + Filters = "PNG File (*.png)|*.png|"; DefaultPath = EditorSettings.value("data/"); ChangePath = false; OverwritePrompt = true; @@ -2565,6 +2565,9 @@ function MaterialEditorGui::saveCompositeMap(%this) %saveAs = %dlg.FileName; } + if( fileExt( %saveAs ) !$= ".png" ) + %saveAs = %saveAs @ ".png"; + %material = %this.currentMaterial; %layer = %this.currentLayer; From ef34210fefeda51d5c85301fce37c5b6a3f2d334 Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Tue, 23 Mar 2021 21:30:54 -0400 Subject: [PATCH 09/13] Implement Unit Test Suite for TorqueScript. --- Engine/source/console/test/ScriptTest.cpp | 395 +++++++++++++++++++++ Engine/source/console/test/consoleTest.cpp | 34 +- Tools/CMake/torque3d.cmake | 1 + 3 files changed, 397 insertions(+), 33 deletions(-) create mode 100644 Engine/source/console/test/ScriptTest.cpp diff --git a/Engine/source/console/test/ScriptTest.cpp b/Engine/source/console/test/ScriptTest.cpp new file mode 100644 index 000000000..994606783 --- /dev/null +++ b/Engine/source/console/test/ScriptTest.cpp @@ -0,0 +1,395 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +#ifdef TORQUE_TESTS_ENABLED +#include "testing/unitTesting.h" +#include "platform/platform.h" +#include "console/simBase.h" +#include "console/consoleTypes.h" +#include "console/simBase.h" +#include "console/engineAPI.h" +#include "math/mMath.h" +#include "console/stringStack.h" + +template +inline T Convert(ConsoleValueRef); + +template<> +inline U32 Convert(ConsoleValueRef val) +{ + return val.getIntValue(); +} + +template<> +inline S32 Convert(ConsoleValueRef val) +{ + return val.getSignedIntValue(); +} + +template<> +inline bool Convert(ConsoleValueRef val) +{ + return val.getBoolValue(); +} + +template<> +inline F32 Convert(ConsoleValueRef val) +{ + return val.getFloatValue(); +} + +template<> +inline const char* Convert(ConsoleValueRef val) +{ + return val.getStringValue(); +} + +template<> +inline SimObject* Convert(ConsoleValueRef val) +{ + return Sim::findObject(val); +} + +template +inline T RunScript(const char* str) +{ + return Convert(Con::evaluate(str, false, NULL)); +} + +TEST(Script, Basic_Arithmetic) +{ + S32 add = RunScript(R"( + return 1.0 + 1; + )"); + + EXPECT_EQ(add, 2); + + S32 sub = RunScript(R"( + return 10 - 1.0; + )"); + + EXPECT_EQ(sub, 9); + + S32 mult = RunScript(R"( + return 10 * 2.5; + )"); + + EXPECT_EQ(mult, 25); + + S32 div = RunScript(R"( + return 10.0 / 2; + )"); + + EXPECT_EQ(div, 5); +} + +TEST(Script, Complex_Arithmetic) +{ + S32 result = RunScript(R"( + return 1 * 2 - (0.5 * 2); + )"); + + EXPECT_EQ(result, 1); + + S32 result2 = RunScript(R"( + return 1 * 2 * 3 % 2; + )"); + + EXPECT_EQ(result2, 0); +} + +TEST(Script, Basic_Concatination) +{ + const char* result1 = RunScript(R"( + return "a" @ "b"; + )"); + + EXPECT_STREQ(result1, "ab"); + + const char* result2 = RunScript(R"( + return "a" SPC "b"; + )"); + + EXPECT_STREQ(result2, "a b"); + + const char* result3 = RunScript(R"( + return "a" TAB "b"; + )"); + + EXPECT_STREQ(result3, "a\tb"); + + const char* result4 = RunScript(R"( + return "a" NL "b"; + )"); + + EXPECT_STREQ(result4, "a\nb"); + + const char* complex = RunScript(R"( + return "a" @ "b" @ "c" @ "d"; + )"); + + EXPECT_STREQ(complex, "abcd"); +} + +TEST(Script, Basic_Global_Variable_Tests) +{ + S32 value = RunScript(R"( + $a = 1; + return $a; + )"); + + EXPECT_EQ(value, 1); +} + +TEST(Script, Variable_Chaining_And_Usage) +{ + S32 value = RunScript(R"( + function t() + { + %a = %b = 2; + return %a; + } + return t(); + )"); + + EXPECT_EQ(value, 2); + + S32 valueGlobal = RunScript(R"( + function t() + { + $a = %b = 2; + } + t(); + return $a; + )"); + + EXPECT_EQ(valueGlobal, 2); + + S32 value2 = RunScript(R"( + function t(%a) + { + if ((%b = 2 * %a) != 5) + return %b; + return 5; + } + + return t(2); + )"); + + EXPECT_EQ(value2, 4); +} + +TEST(Script, Basic_Function_Call_And_Local_Variable_Testing) +{ + S32 value = RunScript(R"( + function t() { %a = 2; return %a; } + return t(); + )"); + + EXPECT_EQ(value, 2); + + S32 value2 = RunScript(R"( + function add(%a, %b) { return %a + %b; } + return add(2, 4); + )"); + + EXPECT_EQ(value2, 6); + + S32 value3 = RunScript(R"( + function fib(%a) { + if (%a == 0) + return 0; + if (%a == 1) + return 1; + return fib(%a - 1) + fib(%a - 2); + } + return fib(15); + )"); + + EXPECT_EQ(value3, 610); + + S32 staticCall = RunScript(R"( + function SimObject::bar(%a, %b) { + return %a + %b; + } + return SimObject::bar(1, 2); + )"); + + EXPECT_EQ(staticCall, 3); +} + +TEST(Script, Basic_Conditional_Statements) +{ + S32 value = RunScript(R"( + $a = "hello"; + if ($a $= "hello") + return 1; + return 2; + )"); + + EXPECT_EQ(value, 1); + + const char* ternaryValue = RunScript(R"( + return $a $= "hello" ? "World" : "No U"; + )"); + + EXPECT_STREQ(ternaryValue, "World"); +} + +TEST(Script, Basic_Loop_Statements) +{ + S32 whileValue = RunScript(R"( + $count = 0; + while ($count < 5) + $count++; + return $count; + )"); + + EXPECT_EQ(whileValue, 5); + + const char* forValue = RunScript(R"( + function t(%times) + { + %result = ""; + for (%i = 0; %i < %times; %i++) + %result = %result @ "a"; + return %result; + } + + return t(3); + )"); + + EXPECT_STREQ(forValue, "aaa"); + + const char* forIfValue = RunScript(R"( + function t() { + %str = ""; + for (%i = 0; %i < 5; %i++) { + + %loopValue = %i; + + if (%str $= "") + %str = %loopValue; + else + %str = %str @ "," SPC %loopValue; + } + return %str; + } + + return t(); + )"); + + EXPECT_STREQ(forIfValue, "0, 1, 2, 3, 4"); +} + +TEST(Script, TorqueScript_Array_Testing) +{ + S32 value = RunScript(R"( + function t(%idx) { %a[idx] = 2; return %a[idx]; } + return t(5); + )"); + + EXPECT_EQ(value, 2); + + S32 value2 = RunScript(R"( + function t(%idx) { %a[idx, 0] = 2; return %a[idx, 0]; } + return t(5); + )"); + + EXPECT_EQ(value2, 2); +} + +TEST(Script, Basic_SimObject) +{ + SimObject* object = RunScript(R"( + return new SimObject(FudgeCollector) { + fudge = "Chocolate"; + }; + )"); + + EXPECT_NE(object, (SimObject*)NULL); + + const char* propertyValue = RunScript(R"( + return FudgeCollector.fudge; + )"); + + EXPECT_STREQ(propertyValue, "Chocolate"); + + const char* funcReturn = RunScript(R"( + function SimObject::fooFunc(%this) + { + return "Bar"; + } + + return FudgeCollector.fooFunc(); + )"); + + EXPECT_STREQ(funcReturn, "Bar"); + + const char* parentFn = RunScript(R"( + new SimObject(Hello); + + function SimObject::fooFunc2(%this) + { + return "Bar"; + } + + function Hello::fooFunc2(%this) + { + %bar = Parent::fooFunc2(%this); + return "Foo" @ %bar; + } + + return Hello.fooFunc2(); + )"); + + EXPECT_STREQ(parentFn, "FooBar"); +} + +TEST(Script, Basic_Package) +{ + S32 value = RunScript(R"( + function a() { return 3; } + package overrides { + function a() { return 5; } + }; + return a(); + )"); + + EXPECT_EQ(value, 3); + + S32 overrideValue = RunScript(R"( + activatePackage(overrides); + return a(); + )"); + + EXPECT_EQ(overrideValue, 5); + + S32 deactivatedValue = RunScript(R"( + deactivatePackage(overrides); + return a(); + )"); + + EXPECT_EQ(deactivatedValue, 3); +} + +#endif diff --git a/Engine/source/console/test/consoleTest.cpp b/Engine/source/console/test/consoleTest.cpp index aa0b3970e..adea797a2 100644 --- a/Engine/source/console/test/consoleTest.cpp +++ b/Engine/source/console/test/consoleTest.cpp @@ -252,36 +252,4 @@ TEST(Con, execute) STR.popFrame(); } -static U32 gConsoleStackFrame = 0; - -ConsoleFunction(testConsoleStackFrame, S32, 1, 1, "") -{ - gConsoleStackFrame = CSTK.mFrame; - return (U32)Con::executef("testScriptEvalFunction"); // execute a sub function which manipulates the stack -} - -TEST(Con, evaluate) -{ - U32 startStackPos = CSTK.mStackPos; - U32 startStringStackPos = STR.mStart; - S32 returnValue = Con::evaluate("function testScriptEvalFunction() {return \"1\"@\"2\"@\"3\";}\nreturn testConsoleStackFrame();", false, "testEvaluate"); - U32 frame = CSTK.mFrame; - - EXPECT_TRUE(returnValue == 123) << - "Evaluate should return 123"; - - EXPECT_TRUE(gConsoleStackFrame == (frame+2)) << - "Console stack frame inside function should be +2"; - - EXPECT_TRUE(CSTK.mFrame == frame) << - "Console stack frame outside function should be the same as before"; - - EXPECT_TRUE(STR.mStart == startStringStackPos) << - "Console string stack should not be changed"; - - EXPECT_TRUE(CSTK.mStackPos == startStackPos) << - "Console stack should not be changed"; - -} - -#endif \ No newline at end of file +#endif diff --git a/Tools/CMake/torque3d.cmake b/Tools/CMake/torque3d.cmake index 0c1791a5d..c64a18986 100644 --- a/Tools/CMake/torque3d.cmake +++ b/Tools/CMake/torque3d.cmake @@ -247,6 +247,7 @@ addPath("${srcDir}/sfx/media") addPath("${srcDir}/sfx/null") addPath("${srcDir}/sfx") addPath("${srcDir}/console") +addPath("${srcDir}/console/test") addPath("${srcDir}/core") addPath("${srcDir}/core/stream") addPath("${srcDir}/core/strings") From 9323bac5ea76a82184f8d1d9e1147b36998bf607 Mon Sep 17 00:00:00 2001 From: Brian Roberts Date: Tue, 13 Apr 2021 16:53:31 -0500 Subject: [PATCH 10/13] Update Templates/BaseGame/game/core/gui/scripts/canvas.tscript Co-authored-by: Lukas Joergensen --- Templates/BaseGame/game/core/gui/scripts/canvas.tscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript index 818447de5..9f040f1e9 100644 --- a/Templates/BaseGame/game/core/gui/scripts/canvas.tscript +++ b/Templates/BaseGame/game/core/gui/scripts/canvas.tscript @@ -156,7 +156,7 @@ function GuiCanvas::prefsToModeStr(%this) function GuiCanvas::checkCanvasRes(%this, %mode, %deviceId, %deviceMode, %startup) { // Toggle for selecting the borderless window allowed sizes. Set true to allow - // boderless windows to be less than the device res. + // borderless windows to be less than the device res. %allowSmallBorderless = true; %resX = getWord(%mode, $WORD::RES_X); From 2e3e4228b21d761ef4b024f05630a656bab55abd Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Wed, 21 Apr 2021 14:45:10 -0500 Subject: [PATCH 11/13] make string to char* conversion automatic --- Engine/source/core/util/str.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/core/util/str.h b/Engine/source/core/util/str.h index 38523cc53..abd693dba 100644 --- a/Engine/source/core/util/str.h +++ b/Engine/source/core/util/str.h @@ -187,7 +187,7 @@ public: static inline String ToString( S32 v ) { return ToString( "%d", v ); } static inline String ToString( F32 v ) { return ToString( "%g", v ); } static inline String ToString( F64 v ) { return ToString( "%Lg", v ); } - + inline operator const char* () { return c_str(); } static String SpanToString(const char* start, const char* end); static String ToLower(const String &string); From 0289090c3496b65c6142ab9955db99f29740d1aa Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Thu, 22 Apr 2021 20:02:21 -0500 Subject: [PATCH 12/13] minor cleanup --- .../game/tools/materialEditor/scripts/materialEditor.ed.tscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript index cf4ac6e40..f0d99d579 100644 --- a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript +++ b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.tscript @@ -2551,7 +2551,7 @@ function MaterialEditorGui::saveCompositeMap(%this) %saveAs = ""; %dlg = new SaveFileDialog() { - Filters = "PNG File (*.png)|*.png|"; + Filters = "PNG File (*.png)|*.png"; DefaultPath = EditorSettings.value("data/"); ChangePath = false; OverwritePrompt = true; From 6f52b8736035244b9faff4a67b9b815c7847b019 Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 23 Apr 2021 07:05:09 +0100 Subject: [PATCH 13/13] Update TORQUE_GAME_ENGINE version number to reflect current version 4.0 --- Engine/source/app/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/app/version.h b/Engine/source/app/version.h index 1c6bb6805..d9d0a859d 100644 --- a/Engine/source/app/version.h +++ b/Engine/source/app/version.h @@ -41,7 +41,7 @@ /// code version, the game name, and which type of game it is (TGB, TGE, TGEA, etc.). /// /// Version number is major * 1000 + minor * 100 + revision * 10. -#define TORQUE_GAME_ENGINE 3900 +#define TORQUE_GAME_ENGINE 4000 /// Human readable engine version string. #define TORQUE_GAME_ENGINE_VERSION_STRING "3.9.0"