| 1 | /* Copyright (C) 2023 Wildfire Games.
|
|---|
| 2 | * This file is part of 0 A.D.
|
|---|
| 3 | *
|
|---|
| 4 | * 0 A.D. is free software: you can redistribute it and/or modify
|
|---|
| 5 | * it under the terms of the GNU General Public License as published by
|
|---|
| 6 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 7 | * (at your option) any later version.
|
|---|
| 8 | *
|
|---|
| 9 | * 0 A.D. is distributed in the hope that it will be useful,
|
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | * GNU General Public License for more details.
|
|---|
| 13 | *
|
|---|
| 14 | * You should have received a copy of the GNU General Public License
|
|---|
| 15 | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 16 | */
|
|---|
| 17 |
|
|---|
| 18 | #include "simulation2/system/ComponentTest.h"
|
|---|
| 19 |
|
|---|
| 20 | #include "simulation2/components/ICmpCinemaManager.h"
|
|---|
| 21 |
|
|---|
| 22 | class TestCmpCinemaManager : public CxxTest::TestSuite
|
|---|
| 23 | {
|
|---|
| 24 | public:
|
|---|
| 25 | void setUp()
|
|---|
| 26 | {
|
|---|
| 27 | CXeromyces::Startup();
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | void tearDown()
|
|---|
| 31 | {
|
|---|
| 32 | CXeromyces::Terminate();
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | void test_basic()
|
|---|
| 36 | {
|
|---|
| 37 | ComponentTestHelper test(*g_ScriptContext);
|
|---|
| 38 |
|
|---|
| 39 | ICmpCinemaManager* cmp = test.Add<ICmpCinemaManager>(CID_CinemaManager, "", SYSTEM_ENTITY);
|
|---|
| 40 |
|
|---|
| 41 | TS_ASSERT_EQUALS(cmp->HasPath(L"test"), false);
|
|---|
| 42 | cmp->AddPath(generatePath(L"test"));
|
|---|
| 43 | TS_ASSERT_EQUALS(cmp->HasPath(L"test"), true);
|
|---|
| 44 | cmp->DeletePath(L"test");
|
|---|
| 45 | TS_ASSERT_EQUALS(cmp->HasPath(L"test"), false);
|
|---|
| 46 |
|
|---|
| 47 | cmp->AddPath(generatePath(L"long_path", fixed::FromInt(3600)));
|
|---|
| 48 | TS_ASSERT_EQUALS(cmp->HasPath(L"long_path"), true);
|
|---|
| 49 |
|
|---|
| 50 | TS_ASSERT_EQUALS(cmp->IsEnabled(), false);
|
|---|
| 51 | cmp->AddCinemaPathToQueue(L"long_path");
|
|---|
| 52 | cmp->Play();
|
|---|
| 53 | size_t number_of_turns = 0;
|
|---|
| 54 | while (cmp->IsEnabled())
|
|---|
| 55 | {
|
|---|
| 56 | CMessageUpdate msg(fixed::FromInt(36));
|
|---|
| 57 | cmp->HandleMessage(msg, true);
|
|---|
| 58 | ++number_of_turns;
|
|---|
| 59 | }
|
|---|
| 60 | TS_ASSERT_EQUALS(number_of_turns, 100);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | private:
|
|---|
| 64 | // Generates a simple cinema path with two position and two target nodes.
|
|---|
| 65 | CCinemaPath generatePath(const CStrW& name, const fixed& duration = fixed::FromInt(1))
|
|---|
| 66 | {
|
|---|
| 67 | // Helper nodes
|
|---|
| 68 | CFixedVector3D nodeA(fixed::FromInt(1), fixed::FromInt(0), fixed::FromInt(1));
|
|---|
| 69 | CFixedVector3D nodeB(fixed::FromInt(9), fixed::FromInt(0), fixed::FromInt(9));
|
|---|
| 70 | CFixedVector3D shift(fixed::FromInt(3), fixed::FromInt(3), fixed::FromInt(3));
|
|---|
| 71 |
|
|---|
| 72 | // Constructs the default cinema path data
|
|---|
| 73 | CCinemaData pathData;
|
|---|
| 74 | pathData.m_Name = name;
|
|---|
| 75 | pathData.m_Timescale = fixed::FromInt(1);
|
|---|
| 76 | pathData.m_Orientation = L"target";
|
|---|
| 77 | pathData.m_Mode = L"ease_inout";
|
|---|
| 78 | pathData.m_Style = L"default";
|
|---|
| 79 |
|
|---|
| 80 | // Creates two parallel segments from the A node to the B node
|
|---|
| 81 | TNSpline positionSpline, targetSpline;
|
|---|
| 82 | positionSpline.AddNode(nodeA, CFixedVector3D(), fixed::FromInt(0));
|
|---|
| 83 | positionSpline.AddNode(nodeB, CFixedVector3D(), duration);
|
|---|
| 84 | targetSpline.AddNode(nodeA + shift, CFixedVector3D(), fixed::FromInt(0));
|
|---|
| 85 | targetSpline.AddNode(nodeB + shift, CFixedVector3D(), duration);
|
|---|
| 86 |
|
|---|
| 87 | return CCinemaPath(pathData, positionSpline, targetSpline);
|
|---|
| 88 | }
|
|---|
| 89 | };
|
|---|