Example #1
0
        public virtual void Setup()
        {
            // Redirect Log messages in NUnit which get swallowed (from GC invoking destructor in some cases)
            // System.Console.SetOut(NUnit.Framework.TestContext.Out);

            m_PreviousWorld = World.DefaultGameObjectInjectionWorld;
#if !UNITY_DOTSPLAYER
            World = World.DefaultGameObjectInjectionWorld = new World("Test World");
#else
            Unity.Burst.DotsRuntimeInitStatics.Init();
            World = DefaultTinyWorldInitialization.Initialize("Test World");
#endif

            m_Manager      = World.EntityManager;
            m_ManagerDebug = new EntityManager.EntityManagerDebug(m_Manager);

            _systems.Clear();

#if !UNITY_DOTSPLAYER
#if !UNITY_2019_2_OR_NEWER
            // Not raising exceptions can easily bring unity down with massive logging when tests fail.
            // From Unity 2019.2 on this field is always implicitly true and therefore removed.

            UnityEngine.Assertions.Assert.raiseExceptions = true;
#endif  // #if !UNITY_2019_2_OR_NEWER
#endif  // #if !UNITY_DOTSPLAYER
        }
Example #2
0
        public void Test1()
        {
#if !UNITY_DOTSPLAYER
            World w = new World("TestWorld");
#else
            World w = DefaultTinyWorldInitialization.Initialize("TestWorld");
#endif
            World.DefaultGameObjectInjectionWorld = w;
            EntityManager em       = World.DefaultGameObjectInjectionWorld.EntityManager;
            List <Entity> remember = new List <Entity>();
            for (int i = 0; i < 5; i++)
            {
                remember.Add(em.CreateEntity());
            }

            var allEnt = em.GetAllEntities(Allocator.Temp);
            allEnt.Dispose();
            foreach (Entity e in remember)
            {
                Assert.IsTrue(em.Exists(e));
            }

            foreach (Entity e in remember)
            {
                em.DestroyEntity(e);
            }

            w.Dispose();
        }
Example #3
0
        // NOTE: The boot up flow is inside the MainLoop as we want to be able to load configuration files
        // before executing any systems, however for web builds we must do such loading inside the mainloop to ensure
        // the browser doesn't hang while we wait on async work to complete
        private static void Main()
        {
            // Create main world
            m_World       = DefaultTinyWorldInitialization.InitializeWorld("main");
            m_Environment = m_World.GetOrCreateSystem <TinyEnvironment>();
            m_BootPhase   = BootPhase.Booting;

            // Setup systems
            DefaultTinyWorldInitialization.InitializeSystems(m_World);

            // Run program
            NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;
            var windowSystem = m_World.GetExistingSystem <WindowSystem>();

            if (windowSystem != null)
            {
                windowSystem.InfiniteMainLoop(MainLoop);
            }
            else
            {
                Debug.Log("No window system found.");
            }

            // Free world and all systems/managers in it
            m_World.Dispose();
        }
Example #4
0
 private UnityInstance()
 {
     BurstInit();
     m_World = DefaultTinyWorldInitialization.InitializeWorld("main");
     DefaultTinyWorldInitialization.InitializeSystems(m_World);
     m_BootPhase            = BootPhase.Booting;
     m_Environment          = m_World.GetOrCreateSystem <TinyEnvironment>();
     m_EntityManager        = m_World.EntityManager;
     m_SceneStreamingSystem = m_World.GetExistingSystem <SceneStreamingSystem>();
 }
Example #5
0
        static public void Initialize(int width, int height, RenderMode renderMode = RenderMode.Auto, bool DisableSwitchRenderingSystem = false)
        {
            NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;

            world   = DefaultTinyWorldInitialization.InitializeWorld("main");
            tinyEnv = world.TinyEnvironment();

            SetDisplaySize(width, height, renderMode);

            DefaultTinyWorldInitialization.InitializeSystems(world);

            entityManager = world.EntityManager;
            var srs = World.Active.GetExistingSystem <SwitchRenderingSystem>();

            srs.Disable = DisableSwitchRenderingSystem;
        }
Example #6
0
        public void Test2()
        {
#if !UNITY_DOTSPLAYER
            World w = new World("TestWorld");
#else
            World w = DefaultTinyWorldInitialization.Initialize("TestWorld");
#endif
            World.DefaultGameObjectInjectionWorld = w;
            EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;

            List <Entity> remember = new List <Entity>();
            for (int i = 0; i < 5; i++)
            {
                remember.Add(em.CreateEntity());
            }

            w.Dispose();
            w = null;

#if !UNITY_DOTSPLAYER
            w = new World("TestWorld2");
#else
            w = DefaultTinyWorldInitialization.Initialize("TestWorld");
#endif
            World.DefaultGameObjectInjectionWorld = w;
            em = World.DefaultGameObjectInjectionWorld.EntityManager;
            var allEnt = em.GetAllEntities(Allocator.Temp);
            Assert.AreEqual(0, allEnt.Length);
            allEnt.Dispose();

            foreach (Entity e in remember)
            {
                bool exists = em.Exists(e);
                Assert.IsFalse(exists);
            }

            foreach (Entity e in remember)
            {
                if (em.Exists(e))
                {
                    em.DestroyEntity(e);
                }
            }

            w.Dispose();
        }
Example #7
0
        public virtual void Setup()
        {
            m_PreviousWorld = World.Active;
#if !UNITY_DOTSPLAYER
            World = World.Active = new World("Test World");
#else
            World = DefaultTinyWorldInitialization.Initialize("Test World");
#endif

            m_Manager      = World.EntityManager;
            m_ManagerDebug = new EntityManager.EntityManagerDebug(m_Manager);

#if !UNITY_DOTSPLAYER
#if !UNITY_2019_2_OR_NEWER
            // Not raising exceptions can easily bring unity down with massive logging when tests fail.
            // From Unity 2019.2 on this field is always implicitly true and therefore removed.

            UnityEngine.Assertions.Assert.raiseExceptions = true;
#endif  // #if !UNITY_2019_2_OR_NEWER
#endif  // #if !UNITY_DOTSPLAYER
        }