2020-12-27 18:18:13 +01:00
|
|
|
/* Copyright (C) 2020 Wildfire Games.
|
2010-01-09 20:20:14 +01:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lib/self_test.h"
|
|
|
|
|
|
|
|
#include "simulation2/system/ComponentManager.h"
|
|
|
|
|
|
|
|
#include "simulation2/MessageTypes.h"
|
|
|
|
#include "simulation2/system/ParamNode.h"
|
|
|
|
#include "simulation2/system/SimContext.h"
|
|
|
|
#include "simulation2/serialization/ISerializer.h"
|
|
|
|
#include "simulation2/components/ICmpTest.h"
|
|
|
|
#include "simulation2/components/ICmpTemplateManager.h"
|
|
|
|
|
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "ps/Filesystem.h"
|
|
|
|
#include "ps/XML/Xeromyces.h"
|
|
|
|
|
|
|
|
#define TS_ASSERT_STREAM(stream, len, buffer) \
|
|
|
|
TS_ASSERT_EQUALS(stream.str().length(), (size_t)len); \
|
|
|
|
TS_ASSERT_SAME_DATA(stream.str().data(), buffer, len)
|
|
|
|
|
|
|
|
|
|
|
|
#define TS_ASSERT_THROWS_PSERROR(e, t, s) \
|
|
|
|
TS_ASSERT_THROWS_EQUALS(e, const t& ex, std::string(ex.what()), s)
|
|
|
|
|
|
|
|
class TestComponentManager : public CxxTest::TestSuite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
2017-12-10 18:33:03 +01:00
|
|
|
g_VFS = CreateVfs();
|
2011-05-06 20:45:30 +02:00
|
|
|
TS_ASSERT_OK(g_VFS->Mount(L"", DataDir()/"mods"/"_test.sim", VFS_MOUNT_MUST_EXIST));
|
2011-03-23 14:36:20 +01:00
|
|
|
TS_ASSERT_OK(g_VFS->Mount(L"cache", DataDir()/"_testcache"));
|
2010-01-09 20:20:14 +01:00
|
|
|
CXeromyces::Startup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
CXeromyces::Terminate();
|
|
|
|
g_VFS.reset();
|
2011-03-23 14:36:20 +01:00
|
|
|
DeleteDirectory(DataDir()/"_testcache");
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_Load()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_LookupCID()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(man.LookupCID("Test1A"), (int)CID_Test1A);
|
|
|
|
TS_ASSERT_EQUALS(man.LookupCID("Test1B"), (int)CID_Test1B);
|
|
|
|
}
|
|
|
|
|
2010-01-14 21:36:29 +01:00
|
|
|
void test_AllocateNewEntity()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-14 21:36:29 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2);
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)3);
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)4);
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewEntity(100), (u32)100);
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)101);
|
|
|
|
// TODO:
|
|
|
|
// TS_ASSERT_EQUALS(man.AllocateNewEntity(3), (u32)102);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), (u32)FIRST_LOCAL_ENTITY);
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), (u32)FIRST_LOCAL_ENTITY+1);
|
|
|
|
|
|
|
|
man.ResetState();
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewEntity(), (u32)2);
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewEntity(3), (u32)3);
|
|
|
|
TS_ASSERT_EQUALS(man.AllocateNewLocalEntity(), (u32)FIRST_LOCAL_ENTITY);
|
|
|
|
}
|
|
|
|
|
2016-08-14 18:28:54 +02:00
|
|
|
void test_rng()
|
|
|
|
{
|
|
|
|
// Ensure we get the same random number with the same seed
|
|
|
|
double first;
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2016-08-14 18:28:54 +02:00
|
|
|
man.SetRNGSeed(123);
|
|
|
|
|
|
|
|
if (!man.m_ScriptInterface.MathRandom(first))
|
|
|
|
TS_FAIL("Couldn't get random number!");
|
|
|
|
}
|
|
|
|
|
|
|
|
double second;
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2016-08-14 18:28:54 +02:00
|
|
|
man.SetRNGSeed(123);
|
|
|
|
|
|
|
|
if (!man.m_ScriptInterface.MathRandom(second))
|
|
|
|
TS_FAIL("Couldn't get random number!");
|
|
|
|
}
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(first, second);
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
void test_AddComponent_errors()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(1);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
CParamNode noParam;
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(man.AddComponent(hnd1, CID_Test1A, noParam));
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
TestLogger log;
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(! man.AddComponent(hnd1, 12345, noParam));
|
2015-01-22 21:30:05 +01:00
|
|
|
TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Invalid component id 12345");
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
TestLogger log;
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(! man.AddComponent(hnd1, CID_Test1B, noParam));
|
2015-01-22 21:30:05 +01:00
|
|
|
TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: Multiple components for interface ");
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_QueryInterface()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, CID_Test1A, noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent1, IID_Test2) == NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) == NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd2, CID_Test1B, noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL);
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd2, CID_Test2A, noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_SendMessage()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
|
|
|
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3);
|
|
|
|
CEntityHandle hnd4 = man.AllocateEntityHandle(ent4);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, CID_Test1A, noParam);
|
|
|
|
man.AddComponent(hnd2, CID_Test1B, noParam);
|
|
|
|
man.AddComponent(hnd3, CID_Test2A, noParam);
|
|
|
|
man.AddComponent(hnd4, CID_Test1A, noParam);
|
|
|
|
man.AddComponent(hnd4, CID_Test2A, noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
CMessageTurnStart msg1;
|
2010-05-02 22:32:37 +02:00
|
|
|
CMessageUpdate msg2(fixed::FromInt(100));
|
2012-06-06 21:37:03 +02:00
|
|
|
CMessageInterpolate msg3(0, 0, 0);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21000);
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
// Test_1A subscribed locally to msg1, nothing subscribed globally
|
2010-01-09 20:20:14 +01:00
|
|
|
man.PostMessage(ent1, msg1);
|
|
|
|
man.PostMessage(ent1, msg2);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21000);
|
|
|
|
|
|
|
|
man.BroadcastMessage(msg1);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11002);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21050);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21050);
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
// Test_1B, Test_2A subscribed locally to msg2, nothing subscribed globally
|
2010-01-09 20:20:14 +01:00
|
|
|
man.BroadcastMessage(msg2);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11002);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12010);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21150);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21150);
|
2010-01-22 21:03:14 +01:00
|
|
|
|
|
|
|
// Test_1A subscribed locally to msg3, Test_1B subscribed globally
|
|
|
|
man.BroadcastMessage(msg3);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11004); // local
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12030); // global
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21150);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11003); // local
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21150);
|
|
|
|
|
|
|
|
man.PostMessage(ent1, msg3);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11006); // local
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12050); // global
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21150);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11003); // local - skipped
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21150);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_ParamNode()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
|
|
|
CParamNode testParam;
|
|
|
|
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>1234</x>"), PSRETURN_OK);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, CID_Test1A, noParam);
|
|
|
|
man.AddComponent(hnd2, CID_Test1A, testParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1234);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_basic()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test.js"));
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(man.LookupCID("TestScript1A"), (int)CID__LastNative);
|
|
|
|
TS_ASSERT_EQUALS(man.LookupCID("TestScript1B"), (int)CID__LastNative+1);
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
|
|
|
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, CID_Test1A, noParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam);
|
|
|
|
man.AddComponent(hnd3, man.LookupCID("TestScript1B"), noParam);
|
|
|
|
man.AddComponent(hnd3, man.LookupCID("TestScript2A"), noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 101000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 102000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 201000);
|
|
|
|
|
|
|
|
CMessageTurnStart msg1;
|
2010-05-02 22:32:37 +02:00
|
|
|
CMessageUpdate msg2(fixed::FromInt(25));
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
man.BroadcastMessage(msg1);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 101001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 102001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 201000);
|
|
|
|
|
|
|
|
man.BroadcastMessage(msg2);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 101001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 102001);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 201025);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_helper_basic()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-helper.js"));
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/helpers/test-helper.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1_Helper"), noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 3);
|
|
|
|
}
|
|
|
|
|
2012-07-03 04:16:45 +02:00
|
|
|
void test_script_global_helper()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2012-07-03 04:16:45 +02:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-global-helper.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
2012-07-03 04:16:45 +02:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1_GlobalHelper"), noParam);
|
2012-07-03 04:16:45 +02:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 2);
|
|
|
|
}
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
void test_script_interface()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-22 21:03:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/interfaces/test-interface.js"));
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-interface.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
2010-01-22 21:03:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1_Interface"), noParam);
|
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript2_Interface"), noParam);
|
2010-01-22 21:03:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000 + IID__LastNative);
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
void test_script_errors()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
ScriptTestSetup(man.m_ScriptInterface);
|
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 19:29:17 +01:00
|
|
|
TestLogger log;
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/error.js"));
|
|
|
|
// The following exception is caught and dropped by the JS script, and should not appear in the logs.
|
|
|
|
TS_ASSERT_STR_NOT_CONTAINS(log.GetOutput(), "ERROR: JavaScript error: simulation/components/error.js line 4\nInvalid interface id");
|
|
|
|
// The following exception is not caught by the JS script.
|
|
|
|
TS_ASSERT_STR_CONTAINS(log.GetOutput(), "ERROR: No script wrapper found for interface id 12345");
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_entityID()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-11-17 00:00:52 +01:00
|
|
|
ScriptTestSetup(man.m_ScriptInterface);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-entityid.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 234;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1A"), noParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), (int)ent1);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), (int)ent2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_QueryInterface()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-query.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1A"), noParam);
|
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript2A"), noParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam);
|
|
|
|
man.AddComponent(hnd2, CID_Test2A, noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 400);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 21000);
|
|
|
|
}
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
void test_script_AddEntity()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-22 21:03:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js"));
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js"));
|
2013-09-11 22:41:53 +02:00
|
|
|
man.InitSystemEntity();
|
2010-01-22 21:03:14 +01:00
|
|
|
|
|
|
|
entity_id_t ent1 = man.AllocateNewEntity();
|
|
|
|
entity_id_t ent2 = ent1 + 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
2010-01-22 21:03:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(man.AddComponent(man.GetSystemEntity(), CID_TemplateManager, noParam));
|
2010-01-22 21:03:14 +01:00
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(man.AddComponent(hnd1, man.LookupCID("TestScript1_AddEntity"), noParam));
|
2010-01-22 21:03:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) == NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL);
|
|
|
|
|
|
|
|
{
|
|
|
|
TestLogger logger; // ignore bogus-template warnings
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), (int)ent2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) != NULL);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 999);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 12345);
|
|
|
|
}
|
|
|
|
|
2010-01-24 18:24:35 +01:00
|
|
|
void test_script_AddLocalEntity()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-24 18:24:35 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-addentity.js"));
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/addentity/test-addentity.js"));
|
2013-09-11 22:41:53 +02:00
|
|
|
man.InitSystemEntity();
|
2010-01-24 18:24:35 +01:00
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
entity_id_t ent1 = man.AllocateNewEntity();
|
2010-01-24 18:24:35 +01:00
|
|
|
entity_id_t ent2 = man.AllocateNewLocalEntity() + 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
2010-01-24 18:24:35 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(man.AddComponent(man.GetSystemEntity(), CID_TemplateManager, noParam));
|
2010-01-24 18:24:35 +01:00
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(man.AddComponent(hnd1, man.LookupCID("TestScript1_AddLocalEntity"), noParam));
|
2010-01-24 18:24:35 +01:00
|
|
|
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) == NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) == NULL);
|
|
|
|
|
|
|
|
{
|
|
|
|
TestLogger logger; // ignore bogus-template warnings
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), (int)ent2);
|
|
|
|
}
|
|
|
|
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test1) != NULL);
|
|
|
|
TS_ASSERT(man.QueryInterface(ent2, IID_Test2) != NULL);
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 999);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 12345);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_DestroyEntity()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-24 18:24:35 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-destroyentity.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 10;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
2010-01-24 18:24:35 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(man.AddComponent(hnd1, man.LookupCID("TestScript1_DestroyEntity"), noParam));
|
2010-01-24 18:24:35 +01:00
|
|
|
|
|
|
|
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL);
|
|
|
|
static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX();
|
|
|
|
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) != NULL);
|
|
|
|
man.FlushDestroyedComponents();
|
|
|
|
TS_ASSERT(man.QueryInterface(ent1, IID_Test1) == NULL);
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
void test_script_messages()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-msg.js"));
|
|
|
|
|
2010-01-22 21:03:14 +01:00
|
|
|
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
|
|
|
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1A"), noParam);
|
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript2A"), noParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1A"), noParam);
|
|
|
|
man.AddComponent(hnd2, CID_Test2A, noParam);
|
|
|
|
man.AddComponent(hnd3, man.LookupCID("TestScript1B"), noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 100);
|
2010-01-22 21:03:14 +01:00
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 21000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 100);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
// This GetX broadcasts messages
|
2010-01-22 21:03:14 +01:00
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent1, IID_Test2))->GetX(), 200);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 650);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 5150);
|
2010-01-22 21:03:14 +01:00
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 26050);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 5650);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_template()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
|
|
|
CParamNode testParam;
|
|
|
|
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<node><x>1</x><y>1<z w='100'><a>1000</a></z>0</y></node>"), PSRETURN_OK);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1_Init"), noParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1_Init"), testParam.GetChild("node"));
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1+10+100+1000);
|
|
|
|
}
|
|
|
|
|
2011-01-12 13:29:00 +01:00
|
|
|
void test_script_template_readonly()
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-param.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
|
|
|
CParamNode testParam;
|
|
|
|
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1_readonly"), testParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1_readonly"), testParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 102);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 102);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_hotload()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-hotload1.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
|
|
|
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3);
|
|
|
|
CEntityHandle hnd4 = man.AllocateEntityHandle(ent4);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
CParamNode testParam;
|
|
|
|
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("HotloadA"), testParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("HotloadB"), testParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("HotloadC"), testParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 200);
|
|
|
|
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-hotload2.js", true));
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 200);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd3, man.LookupCID("HotloadA"), testParam);
|
|
|
|
man.AddComponent(hnd4, man.LookupCID("HotloadB"), testParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 1000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 200);
|
|
|
|
}
|
|
|
|
|
2019-07-19 17:41:27 +02:00
|
|
|
void test_script_modding()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2019-07-19 17:41:27 +02:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
|
|
|
CParamNode testParam;
|
|
|
|
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>100</x>"), PSRETURN_OK);
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1, ent2 = 2;
|
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
|
|
|
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-modding1.js"));
|
|
|
|
|
|
|
|
man.AddComponent(hnd1, man.LookupCID("Modding"), testParam);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100);
|
|
|
|
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-modding2.js"));
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1000);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("Modding"), testParam);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1000);
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
void test_serialization()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
2014-06-01 20:14:09 +02:00
|
|
|
entity_id_t ent1 = 10, ent2 = 20, ent3 = FIRST_LOCAL_ENTITY;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
|
|
|
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
|
|
|
CParamNode testParam;
|
|
|
|
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>1234</x>"), PSRETURN_OK);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, CID_Test1A, noParam);
|
|
|
|
man.AddComponent(hnd1, CID_Test2A, noParam);
|
|
|
|
man.AddComponent(hnd2, CID_Test1A, testParam);
|
|
|
|
man.AddComponent(hnd3, CID_Test2A, noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 11000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent1, IID_Test2))->GetX(), 21000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 1234);
|
2010-01-14 21:36:29 +01:00
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent3, IID_Test2))->GetX(), 21000);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
std::stringstream debugStream;
|
2011-10-24 16:31:05 +02:00
|
|
|
TS_ASSERT(man.DumpDebugState(debugStream, true));
|
2010-01-09 20:20:14 +01:00
|
|
|
TS_ASSERT_STR_EQUALS(debugStream.str(),
|
2010-05-22 03:32:11 +02:00
|
|
|
"rng: \"78606\"\n"
|
|
|
|
"entities:\n"
|
2014-06-01 20:14:09 +02:00
|
|
|
"- id: 10\n"
|
2010-01-09 20:20:14 +01:00
|
|
|
" Test1A:\n"
|
|
|
|
" x: 11000\n"
|
|
|
|
" Test2A:\n"
|
|
|
|
" x: 21000\n"
|
|
|
|
"\n"
|
2014-06-01 20:14:09 +02:00
|
|
|
"- id: 20\n"
|
2010-01-09 20:20:14 +01:00
|
|
|
" Test1A:\n"
|
|
|
|
" x: 1234\n"
|
|
|
|
"\n"
|
2010-01-14 21:36:29 +01:00
|
|
|
"- id: 536870912\n"
|
|
|
|
" type: local\n"
|
|
|
|
" Test2A:\n"
|
|
|
|
" x: 21000\n"
|
|
|
|
"\n"
|
2010-01-09 20:20:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
std::string hash;
|
2011-03-05 23:30:32 +01:00
|
|
|
TS_ASSERT(man.ComputeStateHash(hash, false));
|
2010-01-10 20:29:27 +01:00
|
|
|
TS_ASSERT_EQUALS(hash.length(), (size_t)16);
|
2014-06-01 20:14:09 +02:00
|
|
|
TS_ASSERT_SAME_DATA(hash.data(), "\x3c\x25\x6e\x22\x58\x23\x09\x58\x38\xca\xb2\x1e\x0b\x8c\xac\xcf", 16);
|
|
|
|
// echo -en "\x05\x00\x00\x0078606\x02\0\0\0\x01\0\0\0\x0a\0\0\0\xf8\x2a\0\0\x14\0\0\0\xd2\x04\0\0\x04\0\0\0\x0a\0\0\0\x08\x52\0\0" | md5sum | perl -pe 's/([0-9a-f]{2})/\\x$1/g'
|
|
|
|
// ^^^^^^^^ rng ^^^^^^^^ ^^next^^ ^^Test1A^^ ^^^ent1^^ ^^^11000^^^ ^^^ent2^^ ^^^1234^^^ ^^Test2A^^ ^^ent1^^ ^^^21000^^^
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
std::stringstream stateStream;
|
|
|
|
TS_ASSERT(man.SerializeState(stateStream));
|
2014-06-01 20:14:09 +02:00
|
|
|
TS_ASSERT_STREAM(stateStream, 73,
|
2010-05-22 03:32:11 +02:00
|
|
|
"\x05\x00\x00\x00\x37\x38\x36\x30\x36" // RNG
|
2010-01-14 21:36:29 +01:00
|
|
|
"\x02\x00\x00\x00" // next entity ID
|
2014-06-01 20:14:09 +02:00
|
|
|
"\x00\x00\x00\x00" // num system component types
|
2010-01-09 20:20:14 +01:00
|
|
|
"\x02\x00\x00\x00" // num component types
|
|
|
|
"\x06\x00\x00\x00Test1A"
|
|
|
|
"\x02\x00\x00\x00" // num ents
|
2014-06-01 20:14:09 +02:00
|
|
|
"\x0a\x00\x00\x00" // ent1
|
2010-01-09 20:20:14 +01:00
|
|
|
"\xf8\x2a\x00\x00" // 11000
|
2014-06-01 20:14:09 +02:00
|
|
|
"\x14\x00\x00\x00" // ent2
|
2010-01-09 20:20:14 +01:00
|
|
|
"\xd2\x04\x00\x00" // 1234
|
|
|
|
"\x06\x00\x00\x00Test2A"
|
|
|
|
"\x01\x00\x00\x00" // num ents
|
2014-06-01 20:14:09 +02:00
|
|
|
"\x0a\x00\x00\x00" // ent1
|
2010-01-09 20:20:14 +01:00
|
|
|
"\x08\x52\x00\x00" // 21000
|
|
|
|
);
|
|
|
|
|
|
|
|
CSimContext context2;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man2(context2, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man2.LoadComponentTypes();
|
|
|
|
|
|
|
|
TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL);
|
|
|
|
TS_ASSERT(man2.QueryInterface(ent1, IID_Test2) == NULL);
|
|
|
|
TS_ASSERT(man2.QueryInterface(ent2, IID_Test1) == NULL);
|
2010-01-14 21:36:29 +01:00
|
|
|
TS_ASSERT(man2.QueryInterface(ent3, IID_Test2) == NULL);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT(man2.DeserializeState(stateStream));
|
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent1, IID_Test1))->GetX(), 11000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man2.QueryInterface(ent1, IID_Test2))->GetX(), 21000);
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), 1234);
|
2010-01-14 21:36:29 +01:00
|
|
|
TS_ASSERT(man2.QueryInterface(ent3, IID_Test2) == NULL);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_serialization()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2014-03-28 21:26:32 +01:00
|
|
|
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-11-17 00:00:52 +01:00
|
|
|
ScriptTestSetup(man.m_ScriptInterface);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js"));
|
|
|
|
|
2010-05-23 01:02:07 +02:00
|
|
|
entity_id_t ent1 = 1, ent2 = 2, ent3 = 3, ent4 = 4;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
|
|
|
CEntityHandle hnd3 = man.AllocateEntityHandle(ent3);
|
|
|
|
CEntityHandle hnd4 = man.AllocateEntityHandle(ent4);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
|
|
|
CParamNode testParam;
|
|
|
|
TS_ASSERT_EQUALS(CParamNode::LoadXMLString(testParam, "<x>1234</x>"), PSRETURN_OK);
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1_values"), testParam);
|
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1_entity"), testParam);
|
2014-03-28 21:26:32 +01:00
|
|
|
|
|
|
|
// TODO: Since the upgrade to SpiderMonkey v24 this test won't be able to correctly represent
|
|
|
|
// non-tree structures because sharp variables were removed (bug 566700).
|
|
|
|
// This also affects the debug serializer and it could make sense to implement correct serialization again.
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd3, man.LookupCID("TestScript1_nontree"), testParam);
|
2014-03-28 21:26:32 +01:00
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd4, man.LookupCID("TestScript1_custom"), testParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 1234);
|
2010-05-10 11:52:35 +02:00
|
|
|
{
|
|
|
|
TestLogger log; // swallow warnings about this.entity being read-only
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), (int)ent2);
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 8);
|
|
|
|
|
|
|
|
std::stringstream debugStream;
|
2011-10-24 16:31:05 +02:00
|
|
|
TS_ASSERT(man.DumpDebugState(debugStream, true));
|
2010-01-09 20:20:14 +01:00
|
|
|
TS_ASSERT_STR_EQUALS(debugStream.str(),
|
2014-03-28 21:26:32 +01:00
|
|
|
"rng: \"78606\"\n\
|
|
|
|
entities:\n\
|
|
|
|
- id: 1\n\
|
|
|
|
TestScript1_values:\n\
|
2020-12-27 18:18:13 +01:00
|
|
|
comp: {\n\
|
2014-03-28 21:26:32 +01:00
|
|
|
\"x\": 1234,\n\
|
|
|
|
\"str\": \"this is a string\",\n\
|
|
|
|
\"things\": {\n\
|
|
|
|
\"a\": 1,\n\
|
|
|
|
\"b\": \"2\",\n\
|
|
|
|
\"c\": [\n\
|
|
|
|
3,\n\
|
|
|
|
\"4\",\n\
|
|
|
|
[\n\
|
|
|
|
5,\n\
|
|
|
|
[]\n\
|
|
|
|
]\n\
|
|
|
|
]\n\
|
|
|
|
}\n\
|
|
|
|
}\n\
|
|
|
|
\n\
|
|
|
|
- id: 2\n\
|
|
|
|
TestScript1_entity:\n\
|
2020-12-27 18:18:13 +01:00
|
|
|
comp: {}\n\
|
2014-03-28 21:26:32 +01:00
|
|
|
\n\
|
|
|
|
- id: 3\n\
|
|
|
|
TestScript1_nontree:\n\
|
2020-12-27 18:18:13 +01:00
|
|
|
comp: ({x:[[2], [2], [], {y:[2]}]})\n\
|
2014-03-28 21:26:32 +01:00
|
|
|
\n\
|
|
|
|
- id: 4\n\
|
|
|
|
TestScript1_custom:\n\
|
2020-12-27 18:18:13 +01:00
|
|
|
comp: {\n\
|
2014-03-28 21:26:32 +01:00
|
|
|
\"c\": 1\n\
|
2021-01-16 11:33:00 +01:00
|
|
|
}\n\
|
2014-03-28 21:26:32 +01:00
|
|
|
\n"
|
2010-01-09 20:20:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
std::stringstream stateStream;
|
|
|
|
TS_ASSERT(man.SerializeState(stateStream));
|
|
|
|
|
|
|
|
CSimContext context2;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man2(context2, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man2.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js"));
|
|
|
|
|
|
|
|
TS_ASSERT(man2.QueryInterface(ent1, IID_Test1) == NULL);
|
|
|
|
TS_ASSERT(man2.DeserializeState(stateStream));
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent1, IID_Test1))->GetX(), 1234);
|
2010-05-10 11:52:35 +02:00
|
|
|
{
|
|
|
|
TestLogger log; // swallow warnings about this.entity being read-only
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), (int)ent2);
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent3, IID_Test1))->GetX(), 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_serialization_errors()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js"));
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd1, man.LookupCID("TestScript1_getter"), noParam);
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
std::stringstream stateStream;
|
2016-01-11 21:03:33 +01:00
|
|
|
TS_ASSERT_THROWS_PSERROR(man.SerializeState(stateStream), PSERROR_Serialize_ScriptError, "Cannot serialize property getters");
|
2010-05-25 20:24:12 +02:00
|
|
|
// (The script will die if the getter is executed)
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_script_serialization_template()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2014-03-28 21:26:32 +01:00
|
|
|
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man.LoadScript(L"simulation/components/test-serialize.js"));
|
2013-09-11 22:41:53 +02:00
|
|
|
man.InitSystemEntity();
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
entity_id_t ent2 = 2;
|
2013-09-11 22:41:53 +02:00
|
|
|
CEntityHandle hnd2 = man.AllocateEntityHandle(ent2);
|
2010-01-09 20:20:14 +01:00
|
|
|
CParamNode noParam;
|
|
|
|
|
|
|
|
// The template manager takes care of reloading templates on deserialization,
|
|
|
|
// so we need to use it here
|
2013-09-11 22:41:53 +02:00
|
|
|
TS_ASSERT(man.AddComponent(man.GetSystemEntity(), CID_TemplateManager, noParam));
|
2010-01-09 20:20:14 +01:00
|
|
|
ICmpTemplateManager* tempMan = static_cast<ICmpTemplateManager*> (man.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager));
|
|
|
|
|
2017-01-15 19:41:53 +01:00
|
|
|
const CParamNode* testParam = tempMan->LoadTemplate(ent2, "template-serialize");
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2013-09-11 22:41:53 +02:00
|
|
|
man.AddComponent(hnd2, man.LookupCID("TestScript1_consts"), testParam->GetChild("TestScript1_consts"));
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 12347);
|
|
|
|
|
|
|
|
std::stringstream stateStream;
|
|
|
|
TS_ASSERT(man.SerializeState(stateStream));
|
|
|
|
|
|
|
|
CSimContext context2;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man2(context2, g_ScriptContext);
|
2010-01-09 20:20:14 +01:00
|
|
|
man2.LoadComponentTypes();
|
|
|
|
TS_ASSERT(man2.LoadScript(L"simulation/components/test-serialize.js"));
|
|
|
|
|
|
|
|
TS_ASSERT(man2.DeserializeState(stateStream));
|
|
|
|
TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man2.QueryInterface(ent2, IID_Test1))->GetX(), 12347);
|
|
|
|
}
|
2017-04-17 09:55:44 +02:00
|
|
|
|
|
|
|
void test_dynamic_subscription()
|
|
|
|
{
|
|
|
|
CSimContext context;
|
2020-11-14 11:57:50 +01:00
|
|
|
CComponentManager man(context, g_ScriptContext);
|
2017-04-17 09:55:44 +02:00
|
|
|
man.LoadComponentTypes();
|
|
|
|
|
|
|
|
entity_id_t ent1 = 1;
|
|
|
|
CEntityHandle hnd1 = man.AllocateEntityHandle(ent1);
|
|
|
|
|
|
|
|
CParamNode noParam;
|
|
|
|
|
|
|
|
man.AddComponent(hnd1, CID_Test1A, noParam);
|
|
|
|
man.AddComponent(hnd1, CID_Test2A, noParam);
|
|
|
|
|
|
|
|
man.DynamicSubscriptionNonsync(MT_RenderSubmit, man.QueryInterface(ent1, IID_Test1), true);
|
|
|
|
man.DynamicSubscriptionNonsync(MT_RenderSubmit, man.QueryInterface(ent1, IID_Test2), true);
|
|
|
|
|
|
|
|
man.DestroyComponentsSoon(ent1);
|
|
|
|
man.FlushDestroyedComponents();
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
};
|