Example #1
0
        void CustomInitialize()
        {
            // Just to make sure the syntax works:
            FactoryEntityFactory.ScreenListReference = FactoryEntityFactory.ScreenListReference;


            if (PooledDontInheritFromThisInstance.AxisAlignedRectangleInstance.RelativeX != 5)
            {
                throw new Exception("Pooled values aren't getting proper relative values set.");
            }

            this.ContainerOfFactoryEntityListInstance.Destroy();

            try
            {
                FactoryEntity factoryEntity = FactoryEntityFactory.CreateNew();
            }
            catch (Exception e)
            {
                throw new Exception("Destroying Entities also destroys factories if the Entity contains a list of a pooled type.  This shouldn't happen.");
            }


            FactoryEntityDerived instance = FactoryEntityDerivedFactory.CreateNew();

            if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f)
            {
                throw new Exception("Pooled values aren't getting proper relative values set on derived.");
            }

            instance.AxisAlignedRectangleInstance.RelativeX = 10;

            instance.Destroy();

            instance = FactoryEntityDerivedFactory.CreateNew();
            if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f)
            {
                throw new Exception("Reset varaibles aren't working");
            }

            // Let's try addition/removal:
            RecyclableEntity recyclableInstance = new RecyclableEntity();

            recyclableInstance.Destroy();
            recyclableInstance.ReAddToManagers(null);

            recyclableInstance.Destroy();

            BaseNotPooledFactory.Initialize(null, ContentManagerName);
            BaseNotPooled notPooled = BaseNotPooledFactory.CreateNew();

            notPooled.Destroy();


            // According this bug:
            // http://www.hostedredmine.com/issues/413966
            // This may break:
            DerivedPooledFromNotPooledFactory.Initialize((PositionedObjectList <DerivedPooledFromNotPooled>)null, ContentManagerName);
            var pooled = DerivedPooledFromNotPooledFactory.CreateNew();

            if (!SpriteManager.ManagedPositionedObjects.Contains(pooled))
            {
                throw new Exception("Derived entities with pooling from base entities without are not being added to the engine on creation");
            }
            // Now try to destroy:
            pooled.Destroy();
            if (SpriteManager.ManagedPositionedObjects.Contains(pooled))
            {
                throw new Exception("Derived entities with pooling from base entities without are not being removed from the engine on destroy");
            }
        }
        void CustomInitialize()
        {
            if (PooledDontInheritFromThisInstance.AxisAlignedRectangleInstance.RelativeX != 5)
            {
                throw new Exception("Pooled values aren't getting proper relative values set.");
            }

            this.ContainerOfFactoryEntityListInstance.Destroy();

            try
            {
                FactoryEntity factoryEntity = FactoryEntityFactory.CreateNew();
            }
            catch (Exception e)
            {
                throw new Exception("Destroying Entities also destroys factories if the Entity contains a list of a pooled type.  This shouldn't happen.");
            }

            FactoryEntityDerivedFactory.Initialize(ContentManagerName);
            FactoryEntityDerived instance = FactoryEntityDerivedFactory.CreateNew();

            if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f)
            {
                throw new Exception("Pooled values aren't getting proper relative values set on derived.");
            }

            instance.AxisAlignedRectangleInstance.RelativeX = 10;

            instance.Destroy();

            instance = FactoryEntityDerivedFactory.CreateNew();
            if (instance.AxisAlignedRectangleInstance.RelativeX != 5.0f)
            {
                throw new Exception("Reset varaibles aren't working");
            }
            instance.Destroy();

            // Let's try addition/removal:
            RecyclableEntity recyclableInstance = new RecyclableEntity();

            recyclableInstance.Destroy();
            recyclableInstance.ReAddToManagers(null);

            recyclableInstance.Destroy();

            BaseNotPooledFactory.Initialize(ContentManagerName);
            BaseNotPooled notPooled = BaseNotPooledFactory.CreateNew();

            notPooled.Destroy();


            // According this bug:
            // http://www.hostedredmine.com/issues/413966
            // This may break:
            DerivedPooledFromNotPooledFactory.Initialize(ContentManagerName);
            var pooled = DerivedPooledFromNotPooledFactory.CreateNew();

            if (!SpriteManager.ManagedPositionedObjects.Contains(pooled))
            {
                throw new Exception("Derived entities with pooling from base entities without are not being added to the engine on creation");
            }
            // Now try to destroy:
            pooled.Destroy();
            if (SpriteManager.ManagedPositionedObjects.Contains(pooled))
            {
                throw new Exception("Derived entities with pooling from base entities without are not being removed from the engine on destroy");
            }


            BasePooledEntityFactory.CreateNew();
            DerivedPooledFromPooledFactory.CreateNew().Destroy();
            // If this throws an exception, that means that the derived Destroy method is modifying the base entity factory.
            // This should run in debug to throw:
            BasePooledEntityFactory.CreateNew();

            TestPooledAttachment();

            TestPooledSpriteInheritingCollisionAttachment();

            TestBaseChildGrandchildListAdditions();

            TestFactoriesNotRequiringInitialize();
        }