| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Rendering; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.Assertions; |
| | 8 | | using UnityEngine.TestTools; |
| | 9 | | using Environment = DCL.Environment; |
| | 10 | |
|
| | 11 | | namespace CullingControllerTests |
| | 12 | | { |
| | 13 | | public class CullingControllerAndScenesShould : IntegrationTestSuite_Legacy |
| | 14 | | { |
| | 15 | | protected override IEnumerator SetUp() |
| | 16 | | { |
| 3 | 17 | | yield return base.SetUp(); |
| | 18 | |
|
| 3 | 19 | | Assert.IsFalse(Environment.i.platform.cullingController.IsRunning()); |
| | 20 | |
|
| | 21 | | // If we get the settings copy here, it can be overriden with unwanted values |
| | 22 | | // by QualitySettingsController, breaking this test!!. |
| 3 | 23 | | var settings = new CullingControllerSettings(); |
| 3 | 24 | | settings.maxTimeBudget = 99999; |
| 3 | 25 | | Environment.i.platform.cullingController.SetSettings(settings); |
| 3 | 26 | | Environment.i.platform.cullingController.Start(); |
| | 27 | |
|
| 3 | 28 | | Assert.IsTrue(Environment.i.platform.cullingController.IsRunning()); |
| 3 | 29 | | Assert.IsTrue(settings.enableObjectCulling); |
| 3 | 30 | | } |
| | 31 | |
|
| | 32 | | [UnityTest] |
| | 33 | | public IEnumerator CullMovingEntities() |
| | 34 | | { |
| 1 | 35 | | var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, Vector3.one * 1000, true); |
| 1 | 36 | | var entity = boxShape.attachedEntities.First(); |
| | 37 | |
|
| 1 | 38 | | Assert.IsTrue(Environment.i.platform.cullingController.IsDirty(), "culling controller not dirty"); |
| 1 | 39 | | Assert.IsTrue(Environment.i.platform.cullingController.objectsTracker.IsDirty(), "object tracker not dirty") |
| | 40 | |
|
| 1 | 41 | | yield return boxShape.routine; |
| | 42 | |
|
| 1 | 43 | | yield return |
| 7 | 44 | | new DCL.WaitUntil(() => entity.meshesInfo.renderers[0].forceRenderingOff, 0.3f); |
| | 45 | |
|
| 1 | 46 | | Assert.IsTrue(entity.meshesInfo.renderers[0].forceRenderingOff, "renderer wasn't hidden!"); |
| | 47 | |
|
| 1 | 48 | | TestHelpers.SetEntityTransform(scene, entity, Vector3.zero, Quaternion.identity, Vector3.one); |
| | 49 | |
|
| 1 | 50 | | yield return |
| 6 | 51 | | new DCL.WaitUntil(() => !entity.meshesInfo.renderers[0].forceRenderingOff, 0.3f); |
| | 52 | |
|
| 1 | 53 | | Assert.IsFalse(entity.meshesInfo.renderers[0].forceRenderingOff, "renderer wasn't brought back!"); |
| 1 | 54 | | } |
| | 55 | |
|
| | 56 | | [UnityTest] |
| | 57 | | public IEnumerator TogglingOnAndOffSetRenderersCorrectly() |
| | 58 | | { |
| 1 | 59 | | var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, Vector3.one * 1000, true); |
| 1 | 60 | | var entity = boxShape.attachedEntities.First(); |
| | 61 | |
|
| 1 | 62 | | Assert.IsTrue(Environment.i.platform.cullingController.IsDirty(), "culling controller not dirty"); |
| 1 | 63 | | Assert.IsTrue(Environment.i.platform.cullingController.objectsTracker.IsDirty(), "object tracker not dirty") |
| | 64 | |
|
| 1 | 65 | | yield return boxShape.routine; |
| | 66 | |
|
| 1 | 67 | | yield return |
| 7 | 68 | | new DCL.WaitUntil(() => entity.meshesInfo.renderers[0].forceRenderingOff, 0.3f); |
| | 69 | |
|
| 1 | 70 | | Assert.IsTrue(entity.meshesInfo.renderers[0].forceRenderingOff, "renderer wasn't hidden!"); |
| | 71 | |
|
| 1 | 72 | | TestHelpers.SetEntityTransform(scene, entity, Vector3.zero, Quaternion.identity, Vector3.one); |
| | 73 | |
|
| 1 | 74 | | var settings = Environment.i.platform.cullingController.GetSettingsCopy(); |
| 1 | 75 | | settings.enableObjectCulling = false; |
| 1 | 76 | | Environment.i.platform.cullingController.SetSettings(settings); |
| | 77 | |
|
| 1 | 78 | | yield return |
| 6 | 79 | | new DCL.WaitUntil(() => !entity.meshesInfo.renderers[0].forceRenderingOff, 0.3f); |
| | 80 | |
|
| 1 | 81 | | Assert.IsFalse(entity.meshesInfo.renderers[0].forceRenderingOff, "renderer wasn't brought back!"); |
| 1 | 82 | | } |
| | 83 | |
|
| | 84 | | [UnityTest] |
| | 85 | | public IEnumerator StartStopCullingWithDisabledObjectsCorrectly() |
| | 86 | | { |
| 1 | 87 | | var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, Vector3.one * 1000, true); |
| 1 | 88 | | var entity = boxShape.attachedEntities.First(); |
| | 89 | |
|
| 1 | 90 | | Assert.IsTrue(Environment.i.platform.cullingController.IsDirty(), "culling controller not dirty"); |
| 1 | 91 | | Assert.IsTrue(Environment.i.platform.cullingController.objectsTracker.IsDirty(), "object tracker not dirty") |
| | 92 | |
|
| 1 | 93 | | yield return boxShape.routine; |
| | 94 | |
|
| 1 | 95 | | yield return |
| 7 | 96 | | new DCL.WaitUntil(() => entity.meshesInfo.renderers[0].forceRenderingOff, 0.3f); |
| | 97 | |
|
| 1 | 98 | | Assert.IsTrue(entity.meshesInfo.renderers[0].forceRenderingOff, "renderer wasn't hidden!"); |
| | 99 | |
|
| 1 | 100 | | entity.gameObject.SetActive(false); |
| 1 | 101 | | yield return null; |
| | 102 | |
|
| 1 | 103 | | Environment.i.platform.cullingController.Stop(); |
| 1 | 104 | | TestHelpers.SetEntityTransform(scene, entity, Vector3.zero, Quaternion.identity, Vector3.one); |
| | 105 | |
|
| 1 | 106 | | yield return |
| 1 | 107 | | new DCL.WaitUntil(() => !entity.meshesInfo.renderers[0].forceRenderingOff, 0.3f); |
| | 108 | |
|
| 1 | 109 | | Assert.IsFalse(entity.meshesInfo.renderers[0].forceRenderingOff, "renderer wasn't brought back!"); |
| 1 | 110 | | } |
| | 111 | | } |
| | 112 | | } |