public static void Destroy()
 {
     mContentManagerName = null;
     mScreenListReference = null;
     mPool.Clear();
     EntitySpawned = null;
 }
示例#2
0
        public void SaveEmitters(PositionedObjectList<Emitter> emitters, string fileName)
        {


            EmitterSaveList emitterSaveList = EmitterSaveList.FromEmitterList(EditorData.Emitters);

            emitterSaveList.Save(fileName);

#if FRB_MDX


            FlatRedBallServices.Owner.Text = "ParticleEditor - Currently editing " + fileName;
#else
            FlatRedBallServices.Game.Window.Title = "ParticleEditor - Currently editing " + fileName;
#endif
            fileName = FileManager.RemoveExtension(fileName);
            EditorData.CurrentEmixFileName = fileName;


            EmitterEditorSettingsSave settings = new EmitterEditorSettingsSave();
            settings.Camera = CameraSave.FromCamera(Camera.Main);

            if (Camera.Main.Orthogonal && Camera.Main.OrthogonalHeight == Camera.Main.DestinationRectangle.Height)
            {
                settings.Camera.OrthogonalWidth = -1;
                settings.Camera.OrthogonalHeight = -1;
            }


            settings.Save(FileManager.RemoveExtension( fileName ) + ".ess");

        }
示例#3
0
 internal ModelLayer(Camera camera, Layer layer, PositionedObjectList<PositionedModel> models)
 {
     CurrentItem = 0;
     Camera = camera;
     Layer = layer;
     Models = models;
     DrawnThisFrame = false;
 }
 public void AddAxisAlignedCubeList(PositionedObjectList<FlatRedBall.Math.Geometry.AxisAlignedCube> axisAlignedCubesToAdd)
 {
     foreach (FlatRedBall.Math.Geometry.AxisAlignedCube cube in axisAlignedCubesToAdd)
     {
         AxisAlignedCubeSave cubeSave = AxisAlignedCubeSave.FromAxisAlignedCube(cube);
         AxisAlignedCubeSaves.Add(cubeSave);
     }
 }
 public void AddPolygonList(PositionedObjectList<FlatRedBall.Math.Geometry.Polygon> polygonsToAdd)
 {
     foreach (FlatRedBall.Math.Geometry.Polygon polygon in polygonsToAdd)
     {
         PolygonSave polygonSave = PolygonSave.FromPolygon(polygon);
         PolygonSaves.Add(polygonSave);
     }
 }
 public void AddSphereList(PositionedObjectList<Sphere> spheresToAdd)
 {
     foreach (Sphere sphere in spheresToAdd)
     {
         SphereSave sphereSave = SphereSave.FromSphere(sphere);
         SphereSaves.Add(sphereSave);
     }
 }
 public void AddCircleList(PositionedObjectList<Circle> circlesToAdd)
 {
     foreach (Circle circle in circlesToAdd)
     {
         CircleSave circleSave = CircleSave.FromCircle(circle);
         CircleSaves.Add(circleSave);
     }
 }
 public void AddAxisAlignedRectangleList(PositionedObjectList<FlatRedBall.Math.Geometry.AxisAlignedRectangle> axisAlignedRectanglesToAdd)
 {
     foreach (FlatRedBall.Math.Geometry.AxisAlignedRectangle rectangle in axisAlignedRectanglesToAdd)
     {
         AxisAlignedRectangleSave rectangleSave = AxisAlignedRectangleSave.FromAxisAlignedRectangle(rectangle);
         AxisAlignedRectangleSaves.Add(rectangleSave);
     }
 }
        /// <summary>
        /// Tests if two vector positions are within line of sight given a collision map.
        /// </summary>
        /// <param name="position1">The first world-coordinate position.</param>
        /// <param name="position2">The second world-coordinate position.</param>
        /// <param name="collisionThreshold">Distance from position2 to the polygon it's colliding against.
        /// If a polygon is within this threshold, this will return false.</param>
        /// <param name="collisionMap">The list of polygons used to test if the two positions are within line of sight.</param>
        /// <returns></returns>
        #endregion
        public static bool IsInLineOfSight(Vector3 position1, Vector3 position2, float collisionThreshold, PositionedObjectList<Polygon> collisionMap)
        {
            Segment segment = new Segment(new FlatRedBall.Math.Geometry.Point(ref position1),
                new FlatRedBall.Math.Geometry.Point(ref position2));

            foreach (Polygon polygon in collisionMap)
            {
                if (polygon.CollideAgainst(segment) ||
                    (collisionThreshold > 0 && segment.DistanceTo(polygon) < collisionThreshold))
                {
                    return false;
                }
            }
            
            return true;
        }
        public static bool TryAssignAttackUnit(bool replace, Unit owner,
                                               PositionedObjectList <Unit> allUnits, float aggroRadius)
        {
            bool didAssignAttack = false;

            float aggroSquared        = aggroRadius * aggroRadius;
            bool  isTargetAnEnemyUnit = !owner.UnitData.IsEnemy;

            var foundUnit = allUnits.FirstOrDefault(item =>
                                                    (item.Position - owner.Position).LengthSquared() < aggroSquared &&
                                                    item.UnitData.IsEnemy == isTargetAnEnemyUnit &&
                                                    item.CurrentHealth > 0
                                                    );

            if (foundUnit != null)
            {
                owner.AssignAttackGoal(foundUnit, replace);
                didAssignAttack = true;
            }

            return(didAssignAttack);
        }
示例#11
0
        public static object LoadObjectForNos <T>(NamedObjectSave namedObjectSave, IElement elementSave, Layer layerToPutOn,
                                                  PositionedObjectList <ElementRuntime> listToPopulate, ElementRuntime elementRuntime) where T : new()
        {
            if (string.IsNullOrEmpty(namedObjectSave.SourceName) ||
                namedObjectSave.SourceName == "<NONE>" ||
                namedObjectSave.SetByDerived)
            {
                return(null);
            }
            else
            {
                Type typeOfT = typeof(T);

                object toReturn = null;

                if (typeOfT == typeof(Scene) || typeOfT == typeof(ShapeCollection) || typeOfT == typeof(EmitterList) || typeOfT == typeof(SplineList))
                {
                    toReturn = LoadObject <T>(namedObjectSave, elementSave, layerToPutOn, listToPopulate, elementRuntime);
                }

                return(toReturn);
            }
        }
        /// <summary>
        /// Calculates the closest visible point to outOfSightPosition given the currentPosition.
        /// </summary>
        /// <param name="currentPosition">The position with which to test Line Of Sight</param>
        /// <param name="inSightPosition">The connector to the outOfSightPosition with which to find midpoint optimizations.</param>
        /// <param name="outOfSightPosition">The guide to find the optimal in sight position.</param>
        /// <param name="numberOfOptimizations">The number of times we will midpoint optimize, higher means closer to optimal.</param>
        /// <param name="collisionThreshold">Usually the object using the path will be larger than 0, use the size of the collision for testing line of sight.</param>
        /// <param name="collisionMap">Polygon list which we will use for collision (without it, everything is straight line of sight).</param>
        /// <returns></returns>
        #endregion
        public static Vector3 OptimalVisiblePoint(Vector3 currentPosition,
                                                  Vector3 inSightPosition, Vector3 outOfSightPosition, int numberOfOptimizations,
                                                  float collisionThreshold, PositionedObjectList <Polygon> collisionMap)
        {
            Vector3 midpoint = Midpoint(inSightPosition, outOfSightPosition);

            while (numberOfOptimizations > 0)
            {
                if (IsInLineOfSight(currentPosition, midpoint, collisionThreshold, collisionMap))
                { //We see the midpoint
                    inSightPosition = new Vector3(midpoint.X, midpoint.Y, midpoint.Z);
                    midpoint        = Midpoint(midpoint, outOfSightPosition);
                }
                else
                { //We can't see the midpoint
                    outOfSightPosition = new Vector3(midpoint.X, midpoint.Y, midpoint.Z);
                    midpoint           = Midpoint(inSightPosition, outOfSightPosition);
                }
                numberOfOptimizations--;
            }

            return(inSightPosition);
        }
示例#13
0
        public PositionedObjectList <Polygon> LoadPolygonList(string name, bool addToShapeManager, bool makeVisible)
        {
            PolygonSaveList psl = PolygonSaveList.FromFile(name);

            PositionedObjectList <Polygon> loadedPolygons = psl.ToPolygonList();

            if (addToShapeManager)
            {
                foreach (Polygon polygon in loadedPolygons)
                {
                    ShapeManager.AddPolygon(polygon);
                }
            }

            foreach (Polygon polygon in loadedPolygons)
            {
                polygon.Visible = makeVisible;
            }

            mPolygons.AddRange(loadedPolygons);

            return(loadedPolygons);
        }
示例#14
0
        public override void Initialize(bool addToManagers)
        {
            // Generated Initialize
            LoadStaticContent(ContentManagerName);
            EnemyInstance             = new Pokamen.Entities.Enemy(ContentManagerName, false);
            EnemyInstance.Name        = "EnemyInstance";
            PlayerInstance            = new Pokamen.Entities.Player(ContentManagerName, false);
            PlayerInstance.Name       = "PlayerInstance";
            AttackEnemyList           = new PositionedObjectList <Pokamen.Entities.AttackEnemy>();
            AttackEnemyList.Name      = "AttackEnemyList";
            AttackPlayerList          = new PositionedObjectList <Pokamen.Entities.AttackPlayer>();
            AttackPlayerList.Name     = "AttackPlayerList";
            CursorEntityInstance      = new Pokamen.Entities.CursorEntity(ContentManagerName, false);
            CursorEntityInstance.Name = "CursorEntityInstance";
            LastEnemyMoveText         = GameScreenGum.GetGraphicalUiElementByName("LastEnemyMoveText") as Pokamen.GumRuntimes.TextRuntime;


            PostInitialize();
            base.Initialize(addToManagers);
            if (addToManagers)
            {
                AddToManagers();
            }
        }
示例#15
0
        private bool GetIfIsBlocked(TileShapeCollection collision, PositionedObjectList <Character> characters)
        {
            var isBlocked = collision.CollideAgainst(ForwardCollision);

            if (!isBlocked)
            {
                // If not blocked, check against NPCs
                foreach (var npc in characters)
                {
                    // If the NPC is standing still - tests to see if where 'this' is trying to go to
                    // is already occupied by the NPC
                    // If the NPC is walking - tests to see if where 'this' is trying to go is where
                    // the NPC is already going.

                    if (npc != this && ForwardCollision.CollideAgainst(npc.ForwardCollision))
                    {
                        isBlocked = true;
                        break;
                    }
                }
            }

            return(isBlocked);
        }
示例#16
0
        public ListBoxBase(GuiSkin guiSkin, Cursor cursor)
            : base(guiSkin, cursor)
        {
            mTexts = new PositionedObjectList<Text>();
            mHighlight = new Sprite();
            mHighlight.Z = AbsoluteWorldUnitZ - .0001f *
                FlatRedBall.Math.MathFunctions.ForwardVector3.Z;
            mScrollBar = new ScrollBar(guiSkin, cursor);
            AddWindow(mScrollBar);
            Initialize();
            mScrollBar.SpriteFrame.RelativeZ = -.01f * FlatRedBall.Math.MathFunctions.ForwardVector3.Z;


            // Even though the base constructor calls SetSkin, the mTexts are not
            // created yet so their font is never set.  This set the fonts once again.

            mHighlightBar = new SpriteFrame(
                guiSkin.WindowSkin.Texture, guiSkin.WindowSkin.BorderSides);
            SpriteManager.AddSpriteFrame(mHighlightBar);
            mHighlightBar.AttachTo(SpriteFrame, false);
            mHighlightBar.RelativeZ = -HighlightBarOffset * Math.MathFunctions.ForwardVector3.Z;
            mHighlightBar.Visible = false;

            SetSkin(guiSkin);
        }
示例#17
0
        public T LoadFromFile <T>(string assetName)
        {
            string extension = FileManager.GetExtension(assetName);

            if (FileManager.IsRelative(assetName))
            {
                // get the absolute path using the current relative directory
                assetName = FileManager.RelativeDirectory + assetName;
            }



            string fullNameWithType = assetName + typeof(T).Name;


            // get the dictionary by the contentManagerName.  If it doesn't exist, GetDisposableDictionaryByName
            // will create it.

            if (mDisposableDictionary.ContainsKey(fullNameWithType))
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime, typeof(T).Name, fullNameWithType, ContentLoadDetail.Cached));
#endif

                return((T)mDisposableDictionary[fullNameWithType]);
            }
            else if (mNonDisposableDictionary.ContainsKey(fullNameWithType))
            {
                return((T)mNonDisposableDictionary[fullNameWithType]);
            }
            else
            {
#if PROFILE
                mHistory.Add(new ContentLoadHistory(
                                 TimeManager.CurrentTime,
                                 typeof(T).Name,
                                 fullNameWithType,
                                 ContentLoadDetail.HddFromFile));
#endif
#if DEBUG
                // The ThrowExceptionIfFileDoesntExist
                // call used to be done before the checks
                // in the dictionaries.  But whatever is held
                // in there may not really be a file so let's check
                // if the file exists after we check the dictionaries.
                FileManager.ThrowExceptionIfFileDoesntExist(assetName);
#endif

                IDisposable loadedAsset = null;

                if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Microsoft.Xna.Framework.Graphics.Texture2D))
                {
                    // for now we'll create it here, eventually have it in a dictionary:
                    loadedAsset = textureContentLoader.Load(assetName);
                }

                #region Scene

                else if (typeof(T) == typeof(FlatRedBall.Scene))
                {
                    FlatRedBall.Scene scene = FlatRedBall.Content.Scene.SceneSave.FromFile(assetName).ToScene(mName);

                    object sceneAsObject = scene;

                    lock (mNonDisposableDictionary)
                    {
                        if (!mNonDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mNonDisposableDictionary.Add(fullNameWithType, scene);
                        }
                    }
                    return((T)sceneAsObject);
                }

                #endregion

                #region EmitterList

                else if (typeof(T) == typeof(EmitterList))
                {
                    EmitterList emitterList = EmitterSaveList.FromFile(assetName).ToEmitterList(mName);


                    mNonDisposableDictionary.Add(fullNameWithType, emitterList);


                    return((T)((object)emitterList));
                }

                #endregion

                #region Image
#if !MONOGAME
                else if (typeof(T) == typeof(Image))
                {
                    switch (extension.ToLowerInvariant())
                    {
                    case "gif":
                        Image image = Image.FromFile(assetName);
                        loadedAsset = image;
                        break;
                    }
                }
#endif
                #endregion

                #region BitmapList
#if !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !MONOGAME
                else if (typeof(T) == typeof(BitmapList))
                {
                    loadedAsset = BitmapList.FromFile(assetName);
                }
#endif

                #endregion

                #region NodeNetwork
                else if (typeof(T) == typeof(NodeNetwork))
                {
                    NodeNetwork nodeNetwork = NodeNetworkSave.FromFile(assetName).ToNodeNetwork();

                    mNonDisposableDictionary.Add(fullNameWithType, nodeNetwork);

                    return((T)((object)nodeNetwork));
                }
                #endregion

                #region ShapeCollection

                else if (typeof(T) == typeof(ShapeCollection))
                {
                    ShapeCollection shapeCollection =
                        ShapeCollectionSave.FromFile(assetName).ToShapeCollection();

                    mNonDisposableDictionary.Add(fullNameWithType, shapeCollection);

                    return((T)((object)shapeCollection));
                }
                #endregion

                #region PositionedObjectList<Polygon>

                else if (typeof(T) == typeof(PositionedObjectList <FlatRedBall.Math.Geometry.Polygon>))
                {
                    PositionedObjectList <FlatRedBall.Math.Geometry.Polygon> polygons =
                        PolygonSaveList.FromFile(assetName).ToPolygonList();
                    mNonDisposableDictionary.Add(fullNameWithType, polygons);
                    return((T)((object)polygons));
                }

                #endregion

                #region AnimationChainList

                else if (typeof(T) == typeof(AnimationChainList))
                {
                    if (assetName.EndsWith("gif"))
                    {
#if WINDOWS_8 || UWP || DESKTOP_GL
                        throw new NotImplementedException();
#else
                        AnimationChainList acl = new AnimationChainList();
                        acl.Add(FlatRedBall.Graphics.Animation.AnimationChain.FromGif(assetName, this.mName));
                        acl[0].ParentGifFileName = assetName;
                        loadedAsset = acl;
#endif
                    }
                    else
                    {
                        loadedAsset =
                            AnimationChainListSave.FromFile(assetName).ToAnimationChainList(mName);
                    }

                    mNonDisposableDictionary.Add(fullNameWithType, loadedAsset);
                }

                #endregion

                else if (typeof(T) == typeof(Song))
                {
                    var loader = new SongLoader();
                    return((T)(object)loader.Load(assetName));
                }
#if MONOGAME
                else if (typeof(T) == typeof(SoundEffect))
                {
                    T soundEffect;

                    if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./"))
                    {
                        soundEffect = base.Load <T>(assetName.Substring(2));
                    }
                    else
                    {
                        soundEffect = base.Load <T>(assetName);
                    }

                    return(soundEffect);
                }
#endif

                #region RuntimeCsvRepresentation

#if !SILVERLIGHT
                else if (typeof(T) == typeof(RuntimeCsvRepresentation))
                {
#if XBOX360
                    throw new NotImplementedException("Can't load CSV from file.  Try instead to use the content pipeline.");
#else
                    return((T)((object)CsvFileManager.CsvDeserializeToRuntime(assetName)));
#endif
                }
#endif


                #endregion

                #region SplineList

                else if (typeof(T) == typeof(List <Spline>))
                {
                    List <Spline> splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                else if (typeof(T) == typeof(SplineList))
                {
                    SplineList splineList = SplineSaveList.FromFile(assetName).ToSplineList();
                    mNonDisposableDictionary.Add(fullNameWithType, splineList);
                    object asObject = splineList;

                    return((T)asObject);
                }

                #endregion

                #region BitmapFont

                else if (typeof(T) == typeof(BitmapFont))
                {
                    // We used to assume the texture is named the same as the font file
                    // But now FRB understands the .fnt file and gets the PNG from the font file
                    //string pngFile = FileManager.RemoveExtension(assetName) + ".png";
                    string fntFile = FileManager.RemoveExtension(assetName) + ".fnt";

                    BitmapFont bitmapFont = new BitmapFont(fntFile, this.mName);

                    object bitmapFontAsObject = bitmapFont;

                    return((T)bitmapFontAsObject);
                }

                #endregion


                #region Text

                else if (typeof(T) == typeof(string))
                {
                    return((T)((object)FileManager.FromFileText(assetName)));
                }

                #endregion

                #region Catch mistakes

#if DEBUG
                else if (typeof(T) == typeof(Spline))
                {
                    throw new Exception("Cannot load Splines.  Try using the List<Spline> type instead.");
                }
                else if (typeof(T) == typeof(Emitter))
                {
                    throw new Exception("Cannot load Emitters.  Try using the EmitterList type instead.");
                }
#endif

                #endregion

                #region else, exception!

                else
                {
                    throw new NotImplementedException("Cannot load content of type " +
                                                      typeof(T).AssemblyQualifiedName + " from file.  If you are loading " +
                                                      "through the content pipeline be sure to remove the extension of the file " +
                                                      "name.");
                }

                #endregion

                if (loadedAsset != null)
                {
                    lock (mDisposableDictionary)
                    {
                        // Multiple threads could try to load this content simultaneously
                        if (!mDisposableDictionary.ContainsKey(fullNameWithType))
                        {
                            mDisposableDictionary.Add(fullNameWithType, loadedAsset);
                        }
                    }
                }

                return((T)loadedAsset);
            }
        }
示例#18
0
        protected virtual void InitializeEntity(bool addToManagers)
        {
            // Generated Initialize
            LoadStaticContent(ContentManagerName);
            HealthBarList = new PositionedObjectList<HealthBar>();
            TextObject = new FlatRedBall.Graphics.Text();

            PostInitialize();
            if (addToManagers)
            {
                AddToManagers(null);
            }
        }
示例#19
0
        public bool Transfering; //if true client will reject all messages

        public Client() : base(null)
        {
            Mobs = new PositionedObjectList<Mob>();
            WelcomeMessageTimeout = 2;
            Transfering = false;
        }
示例#20
0
        static AudioManager()
        {
            AreSoundEffectsEnabled = true;
            AreSongsEnabled = true;
#if !WINDOWS_PHONE && !MONOGAME && !SILVERLIGHT
            SoundListener = new PositionedSoundListener();
            PositionedSounds = new PositionedObjectList<PositionedSound>();
#endif
            Microsoft.Xna.Framework.Media.MediaPlayer.MediaStateChanged += HandleMediaStateChanged;


        }
示例#21
0
        // List vs. ShapeCollection
        public ListVsShapeCollectionRelationship <FirstCollidableT> CreateRelationship <FirstCollidableT>(PositionedObjectList <FirstCollidableT> first, ShapeCollection shapeCollection)
            where FirstCollidableT : PositionedObject, ICollidable
        {
            var relationship = new ListVsShapeCollectionRelationship <FirstCollidableT>(first, shapeCollection);

            relationship.Partitions = Partitions;
            this.Relationships.Add(relationship);
            return(relationship);
        }
示例#22
0
        public static void DeleteCurrentSprites()
        {
            SpriteList spritesToRemove = new SpriteList();

            /*
             * May need to delete more Sprites if the selected Sprite is part of a group.  But this all depends on whether
             * we are in group or hierarchy control mode.
             */

            // need to detach the axes, cursorOverBox, targetBox
            ClearAttachedMarkers();

            #region find out which Sprites are being removed depending on alt and group/hierarchy edit mode
            if (GuiData.ToolsWindow.groupHierarchyControlButton.IsPressed) // hierarchy control
            {
                foreach (Sprite s in mEditorLogic.CurrentSprites)
                {
                    if (spritesToRemove.Contains(s) == false)
                    {
                        spritesToRemove.AddOneWay(s);
                    }

                    SpriteList tempSpriteArray = new SpriteList();

                    s.GetAllDescendantsOneWay(tempSpriteArray);

                    foreach (Sprite childSprite in tempSpriteArray)
                    {
                        if (spritesToRemove.Contains(childSprite) == false)
                        {
                            spritesToRemove.AddOneWay(childSprite);
                        }
                    }
                }
            }
            else
            {
                PositionedObjectList <Sprite> parentSprites = mEditorLogic.CurrentSprites.GetTopParents();

                foreach (Sprite s in parentSprites)
                {
                    if (spritesToRemove.Contains(s) == false)
                    {
                        spritesToRemove.AddOneWay(s);
                    }

                    SpriteList tempSpriteArray = new SpriteList();

                    s.GetAllDescendantsOneWay(tempSpriteArray);

                    foreach (Sprite childSprite in tempSpriteArray)
                    {
                        if (spritesToRemove.Contains(childSprite) == false)
                        {
                            spritesToRemove.AddOneWay(childSprite);
                        }
                    }
                }
            }
            #endregion

            DeleteSprites(spritesToRemove, InputManager.Keyboard.KeyDown(Key.LeftAlt) || InputManager.Keyboard.KeyDown(Key.Right));
        }
示例#23
0
        private static void DrawMixed(SpriteList spriteListUnfiltered, SortType sortType,
            PositionedObjectList<Text> textListUnfiltered, List<IDrawableBatch> batches,
            bool relativeToCamera, Camera camera, Section section)
        {
            if (section != null)
            {
                Section.GetAndStartContextAndTime("Start of Draw Mixed");
            }
            DrawMixedStart(camera);

            

            int spriteIndex = 0;
            int textIndex = 0;
            int batchIndex = 0;

            // The sort values can represent different
            // things depending on the sortType argument.
            // They can either represent pure Z values or they
            // can represent distance from the camera (squared).
            // The problem is that a larger Z means closer to the
            // camera, but a larger distance means further from the
            // camera.  Therefore, to fix this problem if these values
            // represent distance from camera, they will be multiplied by
            // negative 1.
            float nextSpriteSortValue = float.PositiveInfinity;
            float nextTextSortValue = float.PositiveInfinity;
            float nextBatchSortValue = float.PositiveInfinity;




            if (section != null)
            {
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("Sort Lists");
            }

            SortAllLists(spriteListUnfiltered, sortType, textListUnfiltered, batches, relativeToCamera, camera);

            mVisibleSprites.Clear();
            mVisibleTexts.Clear();
            for (int i = 0; i < spriteListUnfiltered.Count; i++)
            {
                Sprite sprite = spriteListUnfiltered[i];
                bool isVisible = sprite.AbsoluteVisible && 
                    (sprite.ColorOperation == ColorOperation.InterpolateColor || sprite.Alpha > .0001) &&
                    camera.IsSpriteInView(sprite, false);

                if (isVisible)
                {
                    mVisibleSprites.Add(sprite);
                }
            }

            for (int i = 0; i < textListUnfiltered.Count; i++)
            {
                Text text = textListUnfiltered[i];
                if (text.AbsoluteVisible && text.Alpha > .0001 && camera.IsTextInView(text))
                {
                    mVisibleTexts.Add(text);
                }
            }
            int indexOfNextSpriteToReposition = 0;


            GetNextZValuesByCategory(mVisibleSprites, sortType, mVisibleTexts, batches, camera, ref spriteIndex, ref textIndex, ref nextSpriteSortValue, ref nextTextSortValue, ref nextBatchSortValue);

            int numberToDraw = 0;
            // This is used as a temporary variable for Z or distance from camera
            float sortingValue = 0;
            Section performDrawingSection = null;
            if (section != null)
            {
                Section.EndContextAndTime();
                performDrawingSection = Section.GetAndStartContextAndTime("Perform Drawing");
            }

            while (spriteIndex < mVisibleSprites.Count || textIndex < mVisibleTexts.Count ||
                (batches != null && batchIndex < batches.Count))
            {
                #region only 1 array remains to be drawn so finish it off completely
                
                #region Draw Texts
                if (spriteIndex >= mVisibleSprites.Count && (batches == null || batchIndex >= batches.Count) &&
                    textIndex < mVisibleTexts.Count)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Texts");
                    }

                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        int temporaryCount = mVisibleTexts.Count;
                        for (int i = textIndex; i < temporaryCount; i++)
                        {
                            mVisibleTexts[i].Position = mVisibleTexts[i].mOldPosition;
                        }
                    }
                    // TEXTS: draw all texts from textIndex to numberOfVisibleTexts - textIndex
                    DrawTexts(mVisibleTexts, textIndex, mVisibleTexts.Count - textIndex, camera, section);
                    break;
                }
                #endregion

                #region Draw Sprites
                else if (textIndex >= mVisibleTexts.Count && (batches == null || batchIndex >= batches.Count) &&
                    spriteIndex < mVisibleSprites.Count)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Sprites");
                    }

                    numberToDraw = mVisibleSprites.Count - spriteIndex;
                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        int temporaryCount = mVisibleSprites.Count;
                        for (int i = indexOfNextSpriteToReposition; i < temporaryCount; i++)
                        {
                            mVisibleSprites[i].Position = mVisibleSprites[i].mOldPosition;
                            indexOfNextSpriteToReposition++;
                        }
                    }


                    PrepareSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex, numberToDraw
                        );

                    DrawSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex,
                        numberToDraw, camera);

                    break;
                }

                #endregion

                #region Draw DrawableBatches
                else if (spriteIndex >= mVisibleSprites.Count && textIndex >= mVisibleTexts.Count &&
                    batches != null && batchIndex < batches.Count)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw IDrawableBatches");
                    }
                    // DRAWABLE BATCHES:  Only DrawableBatches remain so draw them all.
                    while (batchIndex < batches.Count)
                    {
                        IDrawableBatch batchAtIndex = batches[batchIndex];
                        if (batchAtIndex.UpdateEveryFrame)
                        {
                            batchAtIndex.Update();
                        }

                        if (Renderer.RecordRenderBreaks)
                        {
                            // Even though we aren't using a RenderBreak here, we should record a render break
                            // for this batch as it does cause rendering to be interrupted:
                            RenderBreak renderBreak = new RenderBreak();
#if DEBUG
                            renderBreak.ObjectCausingBreak = batchAtIndex;
#endif
                            renderBreak.LayerName = CurrentLayerName;
                            LastFrameRenderBreakList.Add(renderBreak);
                        }

                        batchAtIndex.Draw(camera);

                        batchIndex++;
                    }

                    FixRenderStatesAfterBatchDraw();
                    break;
                }
                #endregion

                #endregion

                #region more than 1 list remains so find which group of objects to render

                #region Sprites

                else if (nextSpriteSortValue <= nextTextSortValue && nextSpriteSortValue <= nextBatchSortValue)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Sprites");
                    }
                    // The next furthest object is a Sprite.  Find how many to draw.

                    #region Count how many Sprites to draw and store it in numberToDraw
                    numberToDraw = 0;

                    if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                        sortingValue = mVisibleSprites[spriteIndex + numberToDraw].Position.Z;
                    else
                        sortingValue = -(camera.Position - mVisibleSprites[spriteIndex + numberToDraw].Position).LengthSquared();

                    while (sortingValue <= nextTextSortValue &&
                           sortingValue <= nextBatchSortValue)
                    {
                        numberToDraw++;
                        if (spriteIndex + numberToDraw == mVisibleSprites.Count)
                        {
                            break;
                        }

                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                            sortingValue = mVisibleSprites[spriteIndex + numberToDraw].Position.Z;
                        else
                            sortingValue = -(camera.Position - mVisibleSprites[spriteIndex + numberToDraw].Position).LengthSquared();

                    }
                    #endregion

                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        for (int i = indexOfNextSpriteToReposition; i < numberToDraw + spriteIndex; i++)
                        {
                            mVisibleSprites[i].Position = mVisibleSprites[i].mOldPosition;
                            indexOfNextSpriteToReposition++;
                        }
                    }

                    PrepareSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex,
                        numberToDraw);

                    DrawSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex,
                        numberToDraw, camera);

                    // numberToDraw represents a range so increase spriteIndex by that amount.
                    spriteIndex += numberToDraw;

                    if (spriteIndex >= mVisibleSprites.Count)
                    {
                        nextSpriteSortValue = float.PositiveInfinity;
                    }
                    else
                    {
                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                            nextSpriteSortValue = mVisibleSprites[spriteIndex].Position.Z;
                        else
                            nextSpriteSortValue = -(camera.Position - mVisibleSprites[spriteIndex].Position).LengthSquared();
                    }
                }

                #endregion

                #region Texts


                else if (nextTextSortValue <= nextSpriteSortValue && nextTextSortValue <= nextBatchSortValue)// draw texts
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Texts");
                    }
                    numberToDraw = 0;

                    if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                        sortingValue = mVisibleTexts[textIndex + numberToDraw].Position.Z;
                    else
                        sortingValue = -(camera.Position - mVisibleTexts[textIndex + numberToDraw].Position).LengthSquared();


                    while (sortingValue <= nextSpriteSortValue &&
                           sortingValue <= nextBatchSortValue)
                    {
                        numberToDraw++;
                        if (textIndex + numberToDraw == mVisibleTexts.Count)
                        {
                            break;
                        }

                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                            sortingValue = mVisibleTexts[textIndex + numberToDraw].Position.Z;
                        else
                            sortingValue = -(camera.Position - mVisibleTexts[textIndex + numberToDraw].Position).LengthSquared();

                    }

                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        for (int i = textIndex; i < textIndex + numberToDraw; i++)
                        {
                            mVisibleTexts[i].Position = mVisibleTexts[i].mOldPosition;
                        }
                    }

                    DrawTexts(mVisibleTexts, textIndex, numberToDraw, camera, section);

                    textIndex += numberToDraw;

                    if (textIndex == mVisibleTexts.Count)
                        nextTextSortValue = float.PositiveInfinity;
                    else
                    {
                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                            nextTextSortValue = mVisibleTexts[textIndex].Position.Z;
                        else
                            nextTextSortValue = -(camera.Position - mVisibleTexts[textIndex].Position).LengthSquared();
                    }

                }

                #endregion

                #region Batches


                else if (nextBatchSortValue <= nextSpriteSortValue && nextBatchSortValue <= nextTextSortValue)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw IDrawableBatches");
                    }
                    while (nextBatchSortValue <= nextSpriteSortValue && nextBatchSortValue <= nextTextSortValue && batchIndex < batches.Count)
                    {
                        IDrawableBatch batchAtIndex = batches[batchIndex];

                        if (batchAtIndex.UpdateEveryFrame)
                        {
                            batchAtIndex.Update();
                        }

                        if(Renderer.RecordRenderBreaks)
                        {
                            // Even though we aren't using a RenderBreak here, we should record a render break
                            // for this batch as it does cause rendering to be interrupted:
                            RenderBreak renderBreak = new RenderBreak();
#if DEBUG
                            renderBreak.ObjectCausingBreak = batchAtIndex;
#endif
                            renderBreak.LayerName = CurrentLayerName;
                            LastFrameRenderBreakList.Add(renderBreak);
                        }

                        batchAtIndex.Draw(camera);

                        batchIndex++;

                        if (batchIndex == batches.Count)
                        {
                            nextBatchSortValue = float.PositiveInfinity;
                        }
                        else
                        {
                            batchAtIndex = batches[batchIndex];

                            if (sortType == SortType.Z)
                            {
                                nextBatchSortValue = batchAtIndex.Z;
                            }
                            else if (sortType == SortType.DistanceAlongForwardVector)
                            {
                                Vector3 vectorDifference = new Vector3(
                                batchAtIndex.X - camera.X,
                                batchAtIndex.Y - camera.Y,
                                batchAtIndex.Z - camera.Z);

                                float firstDistance;
                                Vector3 forwardVector = camera.RotationMatrix.Forward;

                                Vector3.Dot(ref vectorDifference, ref forwardVector, out firstDistance);

                                nextBatchSortValue = -firstDistance;
                            }
                            else
                            {
                                nextBatchSortValue = -(batchAtIndex.Z * batchAtIndex.Z);
                            }
                        }
                    }

                    FixRenderStatesAfterBatchDraw();
                }


                #endregion

                #endregion
            }

            if (section != null)
            {
                // Hop up a level
                if (Section.Context != performDrawingSection)
                {
                    Section.EndContextAndTime();
                }
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("End of Draw Mixed");
            }

            // return the position of any objects not drawn
            if (sortType == SortType.DistanceAlongForwardVector)
            {
                for (int i = indexOfNextSpriteToReposition; i < mVisibleSprites.Count; i++)
                {
                    mVisibleSprites[i].Position = mVisibleSprites[i].mOldPosition;
                }
            }

#if !SILVERLIGHT
            Renderer.Texture = null;
            Renderer.TextureOnDevice = null;
#endif
            if (section != null)
            {
                Section.EndContextAndTime();
            }
        }
        public ResourceCollectHighLevelGoal(Unit owner, TileNodeNetwork nodeNetwork, Vector3 clickPosition, AxisAlignedRectangle targetResourceMergedTile, ResourceType targetResourceType, PositionedObjectList <Building> allBuildings)
        {
            Owner       = owner;
            NodeNetwork = nodeNetwork;
            TargetResourceMergedTile = targetResourceMergedTile;
            TargetResourceType       = targetResourceType;
            AllBuildings             = allBuildings;

            // TODO: Handle when we can't get to desired tile (e.g., tree in the middle of forest).
            SingleTargetResourceTileCenter = GetSingleTileCenterFromClickPosition(clickPosition);
            SingleTargetResourceTile       = GetSingleTile(SingleTargetResourceTileCenter);
        }
示例#25
0
 public static void Reset()
 {
     _potentialTargetList = null;
 }
示例#26
0
        private static LoadedFile LoadObject(NamedObjectSave namedObjectSave, IElement elementSave,
                                             Layer layerToPutOn,
                                             PositionedObjectList <ElementRuntime> listToPopulate, ElementRuntime elementRuntime)
        {
            int length = namedObjectSave.SourceName.Length;
            // need to use the last index of ( in case the name has a "(" in it)
            //int indexOfType = namedObjectSave.SourceName.IndexOf("(");
            // add 1 to not include the opening paren
            int indexOfType = namedObjectSave.SourceName.LastIndexOf("(") + 1;

            // subtract 1 to remove the last paren
            string objectType = namedObjectSave.SourceName.Substring(indexOfType, length - (indexOfType) - 1);
            string sourceFile = namedObjectSave.SourceFile;

            bool pullsFromEntireObject = false;
            ReferencedFileSave rfs     = elementSave.GetReferencedFileSaveRecursively(sourceFile);

            var rfsFilePath = ElementRuntime.ContentDirectory + rfs.Name;

            // This is the original file that contains the object that is going to be cloned from.
            var loadedObjectToPullFrom =
                elementRuntime.ReferencedFileRuntimeList.LoadedRfses.FirstOrDefault(item => item.FilePath ==
                                                                                    rfsFilePath);

            pullsFromEntireObject = loadedObjectToPullFrom != null;

            if (loadedObjectToPullFrom == null)
            {
                loadedObjectToPullFrom = elementRuntime.ReferencedFileRuntimeList.LoadReferencedFileSave(rfs, true, elementSave);
            }
            ElementRuntime newElementRuntime = CreateNewOrGetExistingElementRuntime(namedObjectSave, layerToPutOn,
                                                                                    listToPopulate, elementRuntime);

            object toAddTo = null;

            if (!namedObjectSave.IsEntireFile)
            {
                // we need to clone the container
                toAddTo = newElementRuntime.ReferencedFileRuntimeList.CreateAndAddEmptyCloneOf(loadedObjectToPullFrom);
            }

            Layer layerToAddTo = GetLayerToAddTo(namedObjectSave, layerToPutOn, elementRuntime);

            LoadedFile toReturn = null;

            if (loadedObjectToPullFrom != null)
            {
                // This might be null if the NOS references a file that doesn't exist.
                // This is usually not a valid circumstance but it's something that can
                // occur with tools modifying the .glux and not properly verifying that the
                // file exists.  GView should tolerate this invalid definition.

                toReturn = CreateRuntimeObjectForNamedObject(namedObjectSave, elementSave, elementRuntime,
                                                             objectType,
                                                             loadedObjectToPullFrom,
                                                             newElementRuntime,
                                                             toAddTo,
                                                             layerToAddTo, rfs, pullsFromEntireObject);

                if (toReturn != null)
                {
                    elementRuntime.ReferencedFileRuntimeList.Add(toReturn);
                }
            }
            newElementRuntime.DirectObjectReference = toReturn?.RuntimeObject;


            return(toReturn);
        }
示例#27
0
        private static ElementRuntime CreateNewOrGetExistingElementRuntime(NamedObjectSave namedObjectSave, Layer layerToPutOn, PositionedObjectList <ElementRuntime> listToPopulate, ElementRuntime parent)
        {
            ElementRuntime newOrExisting = null;

            for (int i = 0; i < listToPopulate.Count; i++)
            {
                if (listToPopulate[i].AssociatedNamedObjectSave == namedObjectSave)
                {
                    newOrExisting = listToPopulate[i];
                    break;
                }
            }

            if (newOrExisting == null)
            {
                newOrExisting = new ElementRuntime();
                newOrExisting.Initialize(null, layerToPutOn, namedObjectSave, parent.CreationOptions.OnBeforeVariableSet, parent.CreationOptions.OnAfterVariableSet);
                newOrExisting.Name = namedObjectSave.InstanceName;
                listToPopulate.Add(newOrExisting);
            }

            return(newOrExisting);
        }
        public override void Initialize(bool addToManagers)
        {
            // Generated Initialize
            LoadStaticContent(ContentManagerName);
            BackgroundFile = FlatRedBallServices.Load<Scene>("content/screens/gamescreen/backgroundfile.scnx", ContentManagerName);
            MoonInstance = new Ourobits.Entities.Moon(ContentManagerName, false);
            MoonInstance.Name = "MoonInstance";
            TrashList = new PositionedObjectList<Trash>();
            CannonBarrelInstance = new Ourobits.Entities.CannonBarrel(ContentManagerName, false);
            CannonBarrelInstance.Name = "CannonBarrelInstance";
            CannonBaseInstance = new Ourobits.Entities.CannonBase(ContentManagerName, false);
            CannonBaseInstance.Name = "CannonBaseInstance";
            TrashList2 = new PositionedObjectList<Trash2>();
            UserArrowInstance = new Ourobits.Entities.UserArrow(ContentManagerName, false);
            UserArrowInstance.Name = "UserArrowInstance";
            ConveyorInstance = new Ourobits.Entities.Conveyor(ContentManagerName, false);
            ConveyorInstance.Name = "ConveyorInstance";
            Orbit1Instance = new Ourobits.Entities.Orbit1(ContentManagerName, false);
            Orbit1Instance.Name = "Orbit1Instance";

            PostInitialize();
            base.Initialize(addToManagers);
            if (addToManagers)
            {
                AddToManagers();
            }
        }
        private LoadedFile CreateObjectBasedOnExtension(NamedObjectSave objectToLoad, IElement elementSave, Layer layerToPutOn, PositionedObjectList <ElementRuntime> listToPopulate, string extension)
        {
            LoadedFile returnObject = null;

            if (!string.IsNullOrEmpty(objectToLoad.SourceFile))
            {
                returnObject = NamedObjectManager.LoadObjectForNos(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                //ReferencedFileSave rfs = elementSave.GetReferencedFileSaveRecursively(
                //    objectToLoad.SourceFile);

                //if(rfs != null)
                //{
                //    returnObject = LoadReferencedFileSave(rfs, true, elementSave);
                //}
            }

            //switch (extension)
            //{
            //    case "scnx":
            //        returnObject = NamedObjectManager.LoadObjectForNos<Scene>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
            //        break;

            //    case "shcx":
            //        returnObject = NamedObjectManager.LoadObjectForNos<ShapeCollection>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
            //        break;
            //    case "nntx":
            //        //returnObject = NamedObjectManager.LoadNodeNetworkObject(objectToLoad, elementSave, layerToPutOn, listToPopulate, entireFileOnly);
            //        break;
            //    case "emix":
            //        returnObject = NamedObjectManager.LoadObjectForNos<EmitterList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
            //        break;
            //    case "splx":
            //        returnObject = NamedObjectManager.LoadObjectForNos<SplineList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
            //        break;
            //    default:
            //        // todo - loop through the custom object creators here:
            //        break;
            //}
            return(returnObject);
        }
示例#30
0
        private static void StoreOldPositionsForDistanceAlongForwardVectorSort(PositionedObjectList <Sprite> spriteList, SortType sortType, PositionedObjectList <Text> textList, List <IDrawableBatch> batches, Camera camera)
        {
            #region If DistanceAlongForwardVector store old values

            // If the objects are using SortType.DistanceAlongForwardVector
            // then store the old positions, then rotate the objects by the matrix that
            // moves the forward vector to the Z = -1 vector (the camera's inverse rotation
            // matrix)
            if (sortType == SortType.DistanceAlongForwardVector)
            {
                Matrix inverseRotationMatrix = camera.RotationMatrix;
                Matrix.Invert(ref inverseRotationMatrix, out inverseRotationMatrix);

                int temporaryCount = spriteList.Count;

                for (int i = 0; i < temporaryCount; i++)
                {
                    spriteList[i].mOldPosition = spriteList[i].Position;

                    spriteList[i].Position -= camera.Position;
                    Vector3.Transform(ref spriteList[i].Position,
                                      ref inverseRotationMatrix, out spriteList[i].Position);
                }

                temporaryCount = textList.Count;

                for (int i = 0; i < temporaryCount; i++)
                {
                    textList[i].mOldPosition = textList[i].Position;

                    textList[i].Position -= camera.Position;
                    Vector3.Transform(ref textList[i].Position,
                                      ref inverseRotationMatrix, out textList[i].Position);
                }

                temporaryCount = batches.Count;

                for (int i = 0; i < temporaryCount; i++)
                {
                }
            }
            #endregion
        }
示例#31
0
        private static void StoreOldPositionsForDistanceAlongForwardVectorSort(PositionedObjectList<Sprite> spriteList, SortType sortType, PositionedObjectList<Text> textList, List<IDrawableBatch> batches, Camera camera)
        {
            #region If DistanceAlongForwardVector store old values

            // If the objects are using SortType.DistanceAlongForwardVector
            // then store the old positions, then rotate the objects by the matrix that
            // moves the forward vector to the Z = -1 vector (the camera's inverse rotation
            // matrix)
            if (sortType == SortType.DistanceAlongForwardVector)
            {
                Matrix inverseRotationMatrix = camera.RotationMatrix;
                Matrix.Invert(ref inverseRotationMatrix, out inverseRotationMatrix);

                int temporaryCount = spriteList.Count;

                for (int i = 0; i < temporaryCount; i++)
                {
                    spriteList[i].mOldPosition = spriteList[i].Position;

                    spriteList[i].Position -= camera.Position;
                    Vector3.Transform(ref spriteList[i].Position,
                        ref inverseRotationMatrix, out spriteList[i].Position);
                }

                temporaryCount = textList.Count;

                for (int i = 0; i < temporaryCount; i++)
                {
                    textList[i].mOldPosition = textList[i].Position;

                    textList[i].Position -= camera.Position;
                    Vector3.Transform(ref textList[i].Position,
                        ref inverseRotationMatrix, out textList[i].Position);
                }

                temporaryCount = batches.Count;

                for (int i = 0; i < temporaryCount; i++)
                {


                }

            }
            #endregion
        }
示例#32
0
        private static void SortAllLists(SpriteList spriteList, SortType sortType, PositionedObjectList <Text> textList, List <IDrawableBatch> batches, bool relativeToCamera, Camera camera)
        {
            StoreOldPositionsForDistanceAlongForwardVectorSort(spriteList, sortType, textList, batches, camera);


            #region Sort the SpriteList and get the number of visible Sprites in numberOfVisibleSprites
            if (spriteList != null && spriteList.Count != 0)
            {
                lock (spriteList)
                {
                    switch (sortType)
                    {
                    case SortType.Z:
                    case SortType.DistanceAlongForwardVector:
                        // Sorting ascending means everything will be drawn back to front.  This
                        // is slower but necessary for translucent objects.
                        // Sorting descending means everything will be drawn back to front.  This
                        // is faster but will cause problems for translucency.
                        spriteList.SortZInsertionAscending();
                        break;

                    case SortType.DistanceFromCamera:
                        spriteList.SortCameraDistanceInsersionDescending(camera);
                        break;

                    case SortType.ZSecondaryParentY:
                        spriteList.SortZInsertionAscending();

                        spriteList.SortParentYInsertionDescendingOnZBreaks();

                        break;

                    case SortType.CustomComparer:

                        if (mSpriteComparer != null)
                        {
                            spriteList.Sort(mSpriteComparer);
                        }
                        else
                        {
                            spriteList.SortZInsertionAscending();
                        }

                        break;

                    case SortType.None:
                        // This will improve render times slightly...maybe?
                        spriteList.SortTextureInsertion();
                        break;

                    default:
                        break;
                    }
                }
            }
            #endregion

            #region Sort the TextList
            if (textList != null && textList.Count != 0)
            {
                switch (sortType)
                {
                case SortType.Z:
                case SortType.DistanceAlongForwardVector:
                    textList.SortZInsertionAscending();
                    break;

                case SortType.DistanceFromCamera:
                    textList.SortCameraDistanceInsersionDescending(camera);
                    break;

                case SortType.CustomComparer:
                    if (mTextComparer != null)
                    {
                        textList.Sort(mTextComparer);
                    }
                    else
                    {
                        textList.SortZInsertionAscending();
                    }


                    break;

                default:
                    break;
                }
            }
            #endregion

            #region Sort the Batches
            if (batches != null && batches.Count != 0)
            {
                switch (sortType)
                {
                case SortType.Z:
                    // Z serves as the radius if using SortType.DistanceFromCamera.
                    // If Z represents actual Z or radius, the larger the value the further
                    // away from the camera the object will be.
                    SortBatchesZInsertionAscending(batches);
                    break;

                case SortType.DistanceAlongForwardVector:
                    batches.Sort(new FlatRedBall.Graphics.BatchForwardVectorSorter(camera));
                    break;

                case SortType.ZSecondaryParentY:
                    SortBatchesZInsertionAscending(batches);

                    // Even though the sort type is by parent, IDB doesn't have a Parent object, so we'll just rely on Y.
                    // May need to revisit this if it causes problems
                    SortBatchesYInsertionDescendingOnZBreaks(batches);

                    break;

                case SortType.CustomComparer:

                    if (mDrawableBatchComparer != null)
                    {
                        batches.Sort(mDrawableBatchComparer);
                    }
                    else
                    {
                        SortBatchesZInsertionAscending(batches);
                    }

                    break;
                }
            }
            #endregion
        }
示例#33
0
        private static void SortAllLists(SpriteList spriteList, SortType sortType, PositionedObjectList<Text> textList, List<IDrawableBatch> batches, bool relativeToCamera, Camera camera)
        {
            StoreOldPositionsForDistanceAlongForwardVectorSort(spriteList, sortType, textList, batches, camera);


            #region Sort the SpriteList and get the number of visible Sprites in numberOfVisibleSprites
            if (spriteList != null && spriteList.Count != 0)
            {
                lock (spriteList)
                {
                    switch (sortType)
                    {
                        case SortType.Z:
                        case SortType.DistanceAlongForwardVector:
                            // Sorting ascending means everything will be drawn back to front.  This
                            // is slower but necessary for translucent objects.
                            // Sorting descending means everything will be drawn back to front.  This
                            // is faster but will cause problems for translucency.
                            spriteList.SortZInsertionAscending();
                            break;
                        case SortType.DistanceFromCamera:
                            spriteList.SortCameraDistanceInsersionDescending(camera);
                            break;
                        case SortType.ZSecondaryParentY:
                            spriteList.SortZInsertionAscending();

                            spriteList.SortParentYInsertionDescendingOnZBreaks();

                            break;
                        case SortType.CustomComparer:

                            if (mSpriteComparer != null)
                            {
                                spriteList.Sort(mSpriteComparer);
                            }
                            else
                            {
                                spriteList.SortZInsertionAscending();
                            }

                            break;
                        case SortType.None:
                            // This will improve render times slightly...maybe?
                            spriteList.SortTextureInsertion();
                            break;
                        default:
                            break;
                    }
                }
            }
            #endregion

            #region Sort the TextList
            if (textList != null && textList.Count != 0)
            {
                switch (sortType)
                {
                    case SortType.Z:
                    case SortType.DistanceAlongForwardVector:
                        textList.SortZInsertionAscending();
                        break;
                    case SortType.DistanceFromCamera:
                        textList.SortCameraDistanceInsersionDescending(camera);
                        break;
                    case SortType.CustomComparer:
                        if (mTextComparer != null)
                        {
                            textList.Sort(mTextComparer);
                        }
                        else
                        {
                            textList.SortZInsertionAscending();
                        }


                        break;
                    default:
                        break;
                }
            }
            #endregion

            #region Sort the Batches
            if (batches != null && batches.Count != 0)
            {
                switch (sortType)
                {
                    case SortType.Z:
                        // Z serves as the radius if using SortType.DistanceFromCamera.
                        // If Z represents actual Z or radius, the larger the value the further
                        // away from the camera the object will be.
                        SortBatchesZInsertionAscending(batches);
                        break;
                    case SortType.DistanceAlongForwardVector:
                        batches.Sort(new FlatRedBall.Graphics.BatchForwardVectorSorter(camera));
                        break;

                    case SortType.CustomComparer:

                        if (mDrawableBatchComparer != null)
                        {
                            batches.Sort(mDrawableBatchComparer);
                        }
                        else
                        {
                            SortBatchesZInsertionAscending(batches);
                        }

                        break;

                }
            }
            #endregion
        }
示例#34
0
 public MapRoom(MobMap map)
 {
     Map = map;
     Clients = new List<ServerClient>();
     Mobs = new PositionedObjectList<Mob>();
 }
示例#35
0
        private void UpdateRectangleCount <T>(List <ColoredRectangleRuntime> gumRectangles, PositionedObjectList <T> positionedObjects,
                                              int red = 255, int green = 255, int blue = 255) where T : PositionedObject
        {
            while (gumRectangles.Count < positionedObjects.Count)
            {
                var rectangle = CreateNewRectangle();
                rectangle.Red   = red;
                rectangle.Green = green;
                rectangle.Blue  = blue;

                gumRectangles.Add(rectangle);
            }
            while (gumRectangles.Count > positionedObjects.Count)
            {
                gumRectangles.Last().Parent = null;
                gumRectangles.RemoveAt(gumRectangles.Count - 1);
            }
        }
        /// <summary>
        /// Tests if two vector positions are within line of sight given a collision map.
        /// </summary>
        /// <param name="position1">The first world-coordinate position.</param>
        /// <param name="position2">The second world-coordinate position.</param>
        /// <param name="collisionThreshold">Distance from position2 to the polygon it's colliding against.
        /// If a polygon is within this threshold, this will return false.</param>
        /// <param name="collisionMap">The list of polygons used to test if the two positions are within line of sight.</param>
        /// <returns></returns>
        #endregion
        public static bool IsInLineOfSight(Vector3 position1, Vector3 position2, float collisionThreshold, PositionedObjectList <Polygon> collisionMap)
        {
            Segment segment = new Segment(new FlatRedBall.Math.Geometry.Point(ref position1),
                                          new FlatRedBall.Math.Geometry.Point(ref position2));

            foreach (Polygon polygon in collisionMap)
            {
                if (polygon.CollideAgainst(segment) ||
                    (collisionThreshold > 0 && segment.DistanceTo(polygon) < collisionThreshold))
                {
                    return(false);
                }
            }

            return(true);
        }
 public static void Initialize(PositionedObjectList<Rock> listFromScreen, string contentManager)
 {
     mContentManagerName = contentManager;
     mScreenListReference = listFromScreen;
 }
示例#38
0
 public DamageCircleManager()
 {
     NextId = 0;
     Circles = new PositionedObjectList<DamageCircle>();
 }
示例#39
0
        private static void DrawMixed(SpriteList spriteListUnfiltered, SortType sortType,
                                      PositionedObjectList <Text> textListUnfiltered, List <IDrawableBatch> batches,
                                      bool relativeToCamera, Camera camera, Section section)
        {
            if (section != null)
            {
                Section.GetAndStartContextAndTime("Start of Draw Mixed");
            }
            DrawMixedStart(camera);



            int spriteIndex = 0;
            int textIndex   = 0;
            int batchIndex  = 0;

            // The sort values can represent different
            // things depending on the sortType argument.
            // They can either represent pure Z values or they
            // can represent distance from the camera (squared).
            // The problem is that a larger Z means closer to the
            // camera, but a larger distance means further from the
            // camera.  Therefore, to fix this problem if these values
            // represent distance from camera, they will be multiplied by
            // negative 1.
            float nextSpriteSortValue = float.PositiveInfinity;
            float nextTextSortValue   = float.PositiveInfinity;
            float nextBatchSortValue  = float.PositiveInfinity;



            if (section != null)
            {
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("Sort Lists");
            }

            SortAllLists(spriteListUnfiltered, sortType, textListUnfiltered, batches, relativeToCamera, camera);

            mVisibleSprites.Clear();
            mVisibleTexts.Clear();
            for (int i = 0; i < spriteListUnfiltered.Count; i++)
            {
                Sprite sprite    = spriteListUnfiltered[i];
                bool   isVisible = sprite.AbsoluteVisible &&
                                   (sprite.ColorOperation == ColorOperation.InterpolateColor || sprite.Alpha > .0001) &&
                                   camera.IsSpriteInView(sprite, relativeToCamera);

                if (isVisible)
                {
                    mVisibleSprites.Add(sprite);
                }
            }

            for (int i = 0; i < textListUnfiltered.Count; i++)
            {
                Text text = textListUnfiltered[i];
                if (text.AbsoluteVisible && text.Alpha > .0001 && camera.IsTextInView(text, relativeToCamera))
                {
                    mVisibleTexts.Add(text);
                }
            }
            int indexOfNextSpriteToReposition = 0;


            GetNextZValuesByCategory(mVisibleSprites, sortType, mVisibleTexts, batches, camera, ref spriteIndex, ref textIndex, ref nextSpriteSortValue, ref nextTextSortValue, ref nextBatchSortValue);

            int numberToDraw = 0;
            // This is used as a temporary variable for Z or distance from camera
            float   sortingValue          = 0;
            Section performDrawingSection = null;

            if (section != null)
            {
                Section.EndContextAndTime();
                performDrawingSection = Section.GetAndStartContextAndTime("Perform Drawing");
            }

            while (spriteIndex < mVisibleSprites.Count || textIndex < mVisibleTexts.Count ||
                   (batches != null && batchIndex < batches.Count))
            {
                #region only 1 array remains to be drawn so finish it off completely

                #region Draw Texts
                if (spriteIndex >= mVisibleSprites.Count && (batches == null || batchIndex >= batches.Count) &&
                    textIndex < mVisibleTexts.Count)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Texts");
                    }

                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        int temporaryCount = mVisibleTexts.Count;
                        for (int i = textIndex; i < temporaryCount; i++)
                        {
                            mVisibleTexts[i].Position = mVisibleTexts[i].mOldPosition;
                        }
                    }
                    // TEXTS: draw all texts from textIndex to numberOfVisibleTexts - textIndex
                    DrawTexts(mVisibleTexts, textIndex, mVisibleTexts.Count - textIndex, camera, section);
                    break;
                }
                #endregion

                #region Draw Sprites
                else if (textIndex >= mVisibleTexts.Count && (batches == null || batchIndex >= batches.Count) &&
                         spriteIndex < mVisibleSprites.Count)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Sprites");
                    }

                    numberToDraw = mVisibleSprites.Count - spriteIndex;
                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        int temporaryCount = mVisibleSprites.Count;
                        for (int i = indexOfNextSpriteToReposition; i < temporaryCount; i++)
                        {
                            mVisibleSprites[i].Position = mVisibleSprites[i].mOldPosition;
                            indexOfNextSpriteToReposition++;
                        }
                    }


                    PrepareSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex, numberToDraw
                        );

                    DrawSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex,
                        numberToDraw, camera);

                    break;
                }

                #endregion

                #region Draw DrawableBatches
                else if (spriteIndex >= mVisibleSprites.Count && textIndex >= mVisibleTexts.Count &&
                         batches != null && batchIndex < batches.Count)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw IDrawableBatches");
                    }
                    // DRAWABLE BATCHES:  Only DrawableBatches remain so draw them all.
                    while (batchIndex < batches.Count)
                    {
                        IDrawableBatch batchAtIndex = batches[batchIndex];
                        if (batchAtIndex.UpdateEveryFrame)
                        {
                            batchAtIndex.Update();
                        }

                        if (Renderer.RecordRenderBreaks)
                        {
                            // Even though we aren't using a RenderBreak here, we should record a render break
                            // for this batch as it does cause rendering to be interrupted:
                            RenderBreak renderBreak = new RenderBreak();
#if DEBUG
                            renderBreak.ObjectCausingBreak = batchAtIndex;
#endif
                            renderBreak.LayerName = CurrentLayerName;
                            LastFrameRenderBreakList.Add(renderBreak);
                        }

                        batchAtIndex.Draw(camera);

                        batchIndex++;
                    }

                    FixRenderStatesAfterBatchDraw();
                    break;
                }
                #endregion

                #endregion

                #region more than 1 list remains so find which group of objects to render

                #region Sprites

                else if (nextSpriteSortValue <= nextTextSortValue && nextSpriteSortValue <= nextBatchSortValue)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Sprites");
                    }
                    // The next furthest object is a Sprite.  Find how many to draw.

                    #region Count how many Sprites to draw and store it in numberToDraw
                    numberToDraw = 0;

                    if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                    {
                        sortingValue = mVisibleSprites[spriteIndex + numberToDraw].Position.Z;
                    }
                    else
                    {
                        sortingValue = -(camera.Position - mVisibleSprites[spriteIndex + numberToDraw].Position).LengthSquared();
                    }

                    while (sortingValue <= nextTextSortValue &&
                           sortingValue <= nextBatchSortValue)
                    {
                        numberToDraw++;
                        if (spriteIndex + numberToDraw == mVisibleSprites.Count)
                        {
                            break;
                        }

                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                        {
                            sortingValue = mVisibleSprites[spriteIndex + numberToDraw].Position.Z;
                        }
                        else
                        {
                            sortingValue = -(camera.Position - mVisibleSprites[spriteIndex + numberToDraw].Position).LengthSquared();
                        }
                    }
                    #endregion

                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        for (int i = indexOfNextSpriteToReposition; i < numberToDraw + spriteIndex; i++)
                        {
                            mVisibleSprites[i].Position = mVisibleSprites[i].mOldPosition;
                            indexOfNextSpriteToReposition++;
                        }
                    }

                    PrepareSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex,
                        numberToDraw);

                    DrawSprites(
                        mSpriteVertices, mSpriteRenderBreaks,
                        mVisibleSprites, spriteIndex,
                        numberToDraw, camera);

                    // numberToDraw represents a range so increase spriteIndex by that amount.
                    spriteIndex += numberToDraw;

                    if (spriteIndex >= mVisibleSprites.Count)
                    {
                        nextSpriteSortValue = float.PositiveInfinity;
                    }
                    else
                    {
                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector || sortType == SortType.ZSecondaryParentY)
                        {
                            nextSpriteSortValue = mVisibleSprites[spriteIndex].Position.Z;
                        }
                        else
                        {
                            nextSpriteSortValue = -(camera.Position - mVisibleSprites[spriteIndex].Position).LengthSquared();
                        }
                    }
                }

                #endregion

                #region Texts


                else if (nextTextSortValue <= nextSpriteSortValue && nextTextSortValue <= nextBatchSortValue)// draw texts
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw Texts");
                    }
                    numberToDraw = 0;

                    if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                    {
                        sortingValue = mVisibleTexts[textIndex + numberToDraw].Position.Z;
                    }
                    else
                    {
                        sortingValue = -(camera.Position - mVisibleTexts[textIndex + numberToDraw].Position).LengthSquared();
                    }


                    while (sortingValue <= nextSpriteSortValue &&
                           sortingValue <= nextBatchSortValue)
                    {
                        numberToDraw++;
                        if (textIndex + numberToDraw == mVisibleTexts.Count)
                        {
                            break;
                        }

                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector)
                        {
                            sortingValue = mVisibleTexts[textIndex + numberToDraw].Position.Z;
                        }
                        else
                        {
                            sortingValue = -(camera.Position - mVisibleTexts[textIndex + numberToDraw].Position).LengthSquared();
                        }
                    }

                    if (sortType == SortType.DistanceAlongForwardVector)
                    {
                        for (int i = textIndex; i < textIndex + numberToDraw; i++)
                        {
                            mVisibleTexts[i].Position = mVisibleTexts[i].mOldPosition;
                        }
                    }

                    DrawTexts(mVisibleTexts, textIndex, numberToDraw, camera, section);

                    textIndex += numberToDraw;

                    if (textIndex == mVisibleTexts.Count)
                    {
                        nextTextSortValue = float.PositiveInfinity;
                    }
                    else
                    {
                        if (sortType == SortType.Z || sortType == SortType.DistanceAlongForwardVector || sortType == SortType.ZSecondaryParentY)
                        {
                            nextTextSortValue = mVisibleTexts[textIndex].Position.Z;
                        }
                        else
                        {
                            nextTextSortValue = -(camera.Position - mVisibleTexts[textIndex].Position).LengthSquared();
                        }
                    }
                }

                #endregion

                #region Batches


                else if (nextBatchSortValue <= nextSpriteSortValue && nextBatchSortValue <= nextTextSortValue)
                {
                    if (section != null)
                    {
                        if (Section.Context != performDrawingSection)
                        {
                            Section.EndContextAndTime();
                        }
                        Section.GetAndStartMergedContextAndTime("Draw IDrawableBatches");
                    }
                    while (nextBatchSortValue <= nextSpriteSortValue && nextBatchSortValue <= nextTextSortValue && batchIndex < batches.Count)
                    {
                        IDrawableBatch batchAtIndex = batches[batchIndex];

                        if (batchAtIndex.UpdateEveryFrame)
                        {
                            batchAtIndex.Update();
                        }

                        if (Renderer.RecordRenderBreaks)
                        {
                            // Even though we aren't using a RenderBreak here, we should record a render break
                            // for this batch as it does cause rendering to be interrupted:
                            RenderBreak renderBreak = new RenderBreak();
#if DEBUG
                            renderBreak.ObjectCausingBreak = batchAtIndex;
#endif
                            renderBreak.LayerName = CurrentLayerName;
                            LastFrameRenderBreakList.Add(renderBreak);
                        }

                        batchAtIndex.Draw(camera);

                        batchIndex++;

                        if (batchIndex == batches.Count)
                        {
                            nextBatchSortValue = float.PositiveInfinity;
                        }
                        else
                        {
                            batchAtIndex = batches[batchIndex];

                            if (sortType == SortType.Z || sortType == SortType.ZSecondaryParentY)
                            {
                                nextBatchSortValue = batchAtIndex.Z;
                            }
                            else if (sortType == SortType.DistanceAlongForwardVector)
                            {
                                Vector3 vectorDifference = new Vector3(
                                    batchAtIndex.X - camera.X,
                                    batchAtIndex.Y - camera.Y,
                                    batchAtIndex.Z - camera.Z);

                                float   firstDistance;
                                Vector3 forwardVector = camera.RotationMatrix.Forward;

                                Vector3.Dot(ref vectorDifference, ref forwardVector, out firstDistance);

                                nextBatchSortValue = -firstDistance;
                            }
                            else
                            {
                                nextBatchSortValue = -(batchAtIndex.Z * batchAtIndex.Z);
                            }
                        }
                    }

                    FixRenderStatesAfterBatchDraw();
                }


                #endregion

                #endregion
            }

            if (section != null)
            {
                // Hop up a level
                if (Section.Context != performDrawingSection)
                {
                    Section.EndContextAndTime();
                }
                Section.EndContextAndTime();
                Section.GetAndStartContextAndTime("End of Draw Mixed");
            }

            // return the position of any objects not drawn
            if (sortType == SortType.DistanceAlongForwardVector)
            {
                for (int i = indexOfNextSpriteToReposition; i < mVisibleSprites.Count; i++)
                {
                    mVisibleSprites[i].Position = mVisibleSprites[i].mOldPosition;
                }
            }

            Renderer.Texture         = null;
            Renderer.TextureOnDevice = null;

            if (section != null)
            {
                Section.EndContextAndTime();
            }
        }
示例#40
0
        private object CreateObjectBasedOnExtension(NamedObjectSave objectToLoad, IElement elementSave, Layer layerToPutOn, PositionedObjectList <ElementRuntime> listToPopulate, string extension)
        {
            object returnObject = null;

            switch (extension)
            {
            case "scnx":
                returnObject = NamedObjectManager.LoadObjectForNos <Scene>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                break;

            case "shcx":
                returnObject = NamedObjectManager.LoadObjectForNos <ShapeCollection>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                break;

            case "nntx":
                //returnObject = NamedObjectManager.LoadNodeNetworkObject(objectToLoad, elementSave, layerToPutOn, listToPopulate, entireFileOnly);
                break;

            case "emix":
                returnObject = NamedObjectManager.LoadObjectForNos <EmitterList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                break;

            case "splx":
                returnObject = NamedObjectManager.LoadObjectForNos <SplineList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                break;
            }
            return(returnObject);
        }
示例#41
0
 public static void Initialize(PositionedObjectList <EnemyBullet> listFromScreen, string contentManager)
 {
     mContentManagerName  = contentManager;
     mScreenListReference = listFromScreen;
 }
示例#42
0
 /// <summary>
 /// Find Trash from Conveyor
 /// </summary>
 /// <param name="trashList"></param>
 /// <returns></returns>
 private Trash GetTrashFromConveyor(PositionedObjectList<Trash> trashList)
 {
     var trash = (from t in trashList
                  where t.OnConveyor && t.X > -50 && t.X < 50
                  select t).FirstOrDefault();
     return trash;
 }
 /// <summary>
 /// Tests if two vector positions are within line of sight given a collision map.
 /// </summary>
 /// <param name="position1">The first world-coordinate position.</param>
 /// <param name="position2">The second world-coordinate position.</param>
 /// <param name="collisionMap">The list of polygons used to test if the two positions are within line of sight.</param>
 /// <returns></returns>
 #endregion
 public static bool IsInLineOfSight(Vector3 position1, Vector3 position2, PositionedObjectList <Polygon> collisionMap)
 {
     return(IsInLineOfSight(position1, position2, 0f, collisionMap));
 }
示例#44
0
 public List <Vector3> GetCollisionOptimizedPath(Vector3 startingPosition,
                                                 Vector3 destination, int numberOfOptimizations, float collisionThreshold, PositionedObjectList <Polygon> collisionMap)
 {
     return(GetCollisionOptimizedPath(startingPosition, destination, numberOfOptimizations, 2, collisionThreshold, collisionMap));
 }
示例#45
0
        public bool Transfering; //if true client will reject all messages

        public Client() : base(null)
        {
            Mobs = new PositionedObjectList <Mob>();
            WelcomeMessageTimeout = 2;
            Transfering           = false;
        }
示例#46
0
        protected virtual void InitializeEntity(bool addToManagers)
        {
            // Generated Initialize
            LoadStaticContent(ContentManagerName);
            mCollisionBoxList = new PositionedObjectList<TileCollisionBoxEntity>();

            PostInitialize();
            if (addToManagers)
            {
                AddToManagers(null);
            }
        }
        public override void Initialize(bool addToManagers)
        {
            // Generated Initialize
            LoadStaticContent(ContentManagerName);
            Boundary = BoundaryShapeCollection;
            SkySceneInstance = SkySceneFile;
            for (int i = 0; i < SkySceneInstance.Texts.Count; i++)
            {
                SkySceneInstance.Texts[i].AdjustPositionForPixelPerfectDrawing = true;
            }
            BirdInstance = new FlatRedBird.Entities.Bird(ContentManagerName, false);
            BirdInstance.Name = "BirdInstance";
            ObstacleList = new PositionedObjectList<FlatRedBird.Entities.Obstacle>();
            GroundInstance = new FlatRedBird.Entities.Ground(ContentManagerName, false);
            GroundInstance.Name = "GroundInstance";

            PostInitialize();
            base.Initialize(addToManagers);
            if (addToManagers)
            {
                AddToManagers();
            }
        }
示例#48
0
 public MapRoom(MobMap map)
 {
     Map     = map;
     Clients = new List <ServerClient>();
     Mobs    = new PositionedObjectList <Mob>();
 }
示例#49
0
        private object CreateFlatRedBallTypeNos(NamedObjectSave namedObjectSave,
                                                PositionedObjectList <ElementRuntime> listToPopulate, Layer layerToPutOn)
        {
            object returnObject = null;

            ElementRuntime newElementRuntime = null;

            switch (namedObjectSave.SourceClassType)
            {
            case "Layer":
            case "FlatRedBall.Graphics.Layer":
                returnObject = CreateLayerObject(namedObjectSave, returnObject);
                break;

            case "AxisAlignedRectangle":
            case "FlatRedBall.Math.Geometry.AxisAlignedRectangle":
                AxisAlignedRectangle aaRectangle = ShapeManager.AddAxisAlignedRectangle();
                if (layerToPutOn != null)
                {
                    ShapeManager.AddToLayer(aaRectangle, layerToPutOn);
                }
                aaRectangle.Name = namedObjectSave.InstanceName;
                returnObject     = aaRectangle;
                break;

            case "Camera":
            case "FlatRedBall.Camera":
                if (namedObjectSave.IsNewCamera)
                {
                    returnObject = null;
                }
                else
                {
                    returnObject = SpriteManager.Camera;
                }
                break;

            case "Circle":
            case "FlatRedBall.Math.Geometry.Circle":
                Circle circle = ShapeManager.AddCircle();
                circle.Name = namedObjectSave.InstanceName;
                if (layerToPutOn != null)
                {
                    ShapeManager.AddToLayer(circle, layerToPutOn);
                }
                returnObject = circle;

                break;

            case "Polygon":
            case "FlatRedBall.Math.Geometry.Polygon":
                Polygon polygon = ShapeManager.AddPolygon();
                polygon.Name = namedObjectSave.InstanceName;

                if (layerToPutOn != null)
                {
                    ShapeManager.AddToLayer(polygon, layerToPutOn);
                }
                returnObject = polygon;

                break;

            case "Sprite":
            case "FlatRedBall.Sprite":
                Sprite sprite = SpriteManager.AddSprite((Texture2D)null);
                if (layerToPutOn != null)
                {
                    SpriteManager.AddToLayer(sprite, layerToPutOn);
                }
                sprite.Name  = namedObjectSave.InstanceName;
                returnObject = sprite;
                break;

            case "SpriteFrame":
            case "FlatRedBall.ManagedSpriteGroups.SpriteFrame":
                SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All);
                if (layerToPutOn != null)
                {
                    SpriteManager.AddToLayer(spriteFrame, layerToPutOn);
                }
                spriteFrame.Name = namedObjectSave.InstanceName;
                returnObject     = spriteFrame;
                break;

            case "Text":
            case "FlatRedBall.Graphics.Text":
                Text text = TextManager.AddText("");
                if (layerToPutOn != null)
                {
                    TextManager.AddToLayer(text, layerToPutOn);
                    text.SetPixelPerfectScale(layerToPutOn);
                }
                text.Name    = namedObjectSave.InstanceName;
                returnObject = text;
                break;

            case "Scene":
            case "FlatRedBall.Scene":
                Scene scene = new Scene();

                scene.Name   = namedObjectSave.InstanceName;
                returnObject = scene;
                break;

            default:
                // do nothing - need to add more types?
                break;
            }

            if (returnObject != null)
            {
                if (returnObject is IScalable)
                {
                    newElementRuntime = new ScalableElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                else
                {
                    newElementRuntime = new ElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                newElementRuntime.mDirectObjectReference = returnObject;

                if (returnObject is Camera && !namedObjectSave.IsNewCamera)
                {
                    SpriteManager.Camera.AttachTo(newElementRuntime, false);
                    SpriteManager.Camera.RelativePosition = Vector3.Zero;
                    newElementRuntime.Z    = 40;
                    newElementRuntime.Name = namedObjectSave.InstanceName;
                }
                else if (returnObject is FlatRedBall.Utilities.INameable)
                {
                    newElementRuntime.Name = ((FlatRedBall.Utilities.INameable)returnObject).Name;
                }
                else
                {
                    object nameValueAsObject;
                    if (LateBinder.TryGetValueStatic(returnObject, "Name", out nameValueAsObject))
                    {
                        newElementRuntime.Name = (string)nameValueAsObject;
                    }
                }

                listToPopulate.Add(newElementRuntime);
            }

            return(returnObject);
        }
示例#50
0
        public EditorHandles()
        {
            spritesAlreadyChanged = new PositionedObjectList<PositionedObject>();

			Layer axisLayer = SpriteManager.AddLayer();

			origin = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/Origin.png", GuiManager.InternalGuiContentManagerName), axisLayer);
			origin.Name = "OriginOfEditAxes";
			editAxisSpriteArray.Add(origin);
			
			xAxis = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/MoveX.png", GuiManager.InternalGuiContentManagerName), axisLayer);

			editAxisSpriteArray.Add(xAxis);

			yAxis = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/MoveY.png", GuiManager.InternalGuiContentManagerName), axisLayer);
			editAxisSpriteArray.Add(yAxis);

			zAxis = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/MoveZ.png", GuiManager.InternalGuiContentManagerName), axisLayer);
			editAxisSpriteArray.Add(zAxis);

			xScale = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/ScaleX.png", GuiManager.InternalGuiContentManagerName), axisLayer);
			editAxisSpriteArray.Add(xScale);

			yScale = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/ScaleY.png", GuiManager.InternalGuiContentManagerName), axisLayer);
			editAxisSpriteArray.Add(yScale);

			xRot = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/RotateX.png", GuiManager.InternalGuiContentManagerName), axisLayer);

			editAxisSpriteArray.Add(xRot);

			yRot = SpriteManager.AddSprite(
                FlatRedBallServices.Load<Texture2D>("Content/EditorHandles/RotateY.png", GuiManager.InternalGuiContentManagerName), axisLayer);
			

			
			editAxisSpriteArray.Add(yRot);

			xAxis.AttachTo(origin, true);
			yAxis.AttachTo(origin, true);
			zAxis.AttachTo(origin, true);
			xScale.AttachTo(origin, true);
			yScale.AttachTo(origin, true);
			xRot.AttachTo(origin, true);
			yRot.AttachTo(origin, true);

            Scale = 1;

            editAxisSpriteArray.Visible = false;
            mCursorOverAxis = false;
            mVisible = false;



        }
示例#51
0
 public static void Initialize(PositionedObjectList <BaseEnemy> potentialTargets)
 {
     _potentialTargetList = potentialTargets;
 }
        public override void Initialize(bool addToManagers)
        {
            // Generated Initialize
            LoadStaticContent(ContentManagerName);
            BulletList = new PositionedObjectList<Bullet>();
            RockList = new PositionedObjectList<Rock>();
            MainShipList = new PositionedObjectList<MainShip>();
            Player1Ship = new RockBlaster.Entities.MainShip(ContentManagerName, false);
            Player1Ship.Name = "Player1Ship";
            EndGameUiInstance = new RockBlaster.Entities.EndGameUi(ContentManagerName, false);
            EndGameUiInstance.Name = "EndGameUiInstance";
            HudInstance = new RockBlaster.Entities.Hud(ContentManagerName, false);
            HudInstance.Name = "HudInstance";
            RockSpawnerInstance = new RockBlaster.Entities.RockSpawner(ContentManagerName, false);
            RockSpawnerInstance.Name = "RockSpawnerInstance";
            MainShipList.Add(Player1Ship);

            PostInitialize();
            base.Initialize(addToManagers);
            if (addToManagers)
            {
                AddToManagers();
            }
        }
示例#53
0
 /// <summary>
 /// Returns a List of Vector3s that will be an optimized version of GetPath given the NodeNetwork and a Collision Map to test against.
 /// </summary>
 /// <remarks>
 /// This method will get the optimal path between the two vectors using GetPath, and then will optimize it by
 /// testing line of sight between the nodes to see if the path can be optimized further (for more optimized
 /// pathfinding). When optimizing the path between two nodes, it will check if the midpoint is in line of sight with the
 /// startingPosition, and if it is, change the path to the midpoint instead of the current target node. the numberOfOptimizations
 /// decides how many times it will take the midpoint and optimize further.
 ///
 /// This method assumes that the node network does NOT fall within collidable objects.
 /// </remarks>
 /// <param name="startingPosition">The world-coordinate of the starting position.</param>
 /// <param name="destination">The world-coordinate of the destination.</param>
 /// <param name="collisionMap">The collision map which will have the obstacles you are trying to path around.</param>
 /// <returns></returns>
 #endregion
 public List <Vector3> GetCollisionOptimizedPath(Vector3 startingPosition,
                                                 Vector3 destination, PositionedObjectList <Polygon> collisionMap)
 {
     return(GetCollisionOptimizedPath(startingPosition, destination, 2, 2, 0f, collisionMap));
 }
        private object CreateFlatRedBallTypeNos(NamedObjectSave namedObjectSave, 
            PositionedObjectList<ElementRuntime> listToPopulate, Layer layerToPutOn)
        {
            object returnObject = null;

            ElementRuntime newElementRuntime = null;

            switch (namedObjectSave.SourceClassType)
            {
                case "Layer":
                case "FlatRedBall.Graphics.Layer":
                    returnObject = CreateLayerObject(namedObjectSave, returnObject);
                    break;
                case "AxisAlignedRectangle":
                case "FlatRedBall.Math.Geometry.AxisAlignedRectangle":
                    AxisAlignedRectangle aaRectangle = ShapeManager.AddAxisAlignedRectangle();
                    if (layerToPutOn != null)
                    {
                        ShapeManager.AddToLayer(aaRectangle, layerToPutOn);
                    }
                    aaRectangle.Name = namedObjectSave.InstanceName;
                    returnObject = aaRectangle;
                    break;
                case "Camera":
                case "FlatRedBall.Camera":
                    if (namedObjectSave.IsNewCamera)
                    {
                        returnObject = null;
                    }
                    else
                    {
                        returnObject = SpriteManager.Camera;
                    }
                    break;
                case "Circle":
                case "FlatRedBall.Math.Geometry.Circle":
                    Circle circle = ShapeManager.AddCircle();
                    circle.Name = namedObjectSave.InstanceName;
                    if (layerToPutOn != null)
                    {
                        ShapeManager.AddToLayer(circle, layerToPutOn);
                    }
                    returnObject = circle;

                    break;
                case "Polygon":
                case "FlatRedBall.Math.Geometry.Polygon":
                    Polygon polygon = ShapeManager.AddPolygon();
                    polygon.Name = namedObjectSave.InstanceName;

                    if(layerToPutOn != null)
                    {
                        ShapeManager.AddToLayer(polygon, layerToPutOn);
                    }
                    returnObject = polygon;

                    break;
                case "Sprite":
                case "FlatRedBall.Sprite":
                    Sprite sprite = SpriteManager.AddSprite((Texture2D)null);
                    if (layerToPutOn != null)
                    {
                        SpriteManager.AddToLayer(sprite, layerToPutOn);
                    }
                    sprite.Name = namedObjectSave.InstanceName;
                    returnObject = sprite;
                    break;
                case "SpriteFrame":
                case "FlatRedBall.ManagedSpriteGroups.SpriteFrame":
                    SpriteFrame spriteFrame = SpriteManager.AddSpriteFrame(null, SpriteFrame.BorderSides.All);
                    if (layerToPutOn != null)
                    {
                        SpriteManager.AddToLayer(spriteFrame, layerToPutOn);
                    }
                    spriteFrame.Name = namedObjectSave.InstanceName;
                    returnObject = spriteFrame;
                    break;
                case "Text":
                case "FlatRedBall.Graphics.Text":
                    Text text = TextManager.AddText("");
                    if (layerToPutOn != null)
                    {
                        TextManager.AddToLayer(text, layerToPutOn);
                        text.SetPixelPerfectScale(layerToPutOn);
                    }
                    text.Name = namedObjectSave.InstanceName;
                    returnObject = text;
                    break;
                case "Scene":
                case "FlatRedBall.Scene":
                    Scene scene = new Scene();

                    scene.Name = namedObjectSave.InstanceName;
                    returnObject = scene;
                    break;
                default:
                    // do nothing - need to add more types?
                    break;
            }

            if (returnObject != null)
            {
                if (returnObject is IScalable)
                {
                    newElementRuntime = new ScalableElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                else
                {
                    newElementRuntime = new ElementRuntime(null, layerToPutOn, namedObjectSave, CreationOptions.OnBeforeVariableSet, CreationOptions.OnAfterVariableSet);
                }
                newElementRuntime.mDirectObjectReference = returnObject;

                if (returnObject is Camera && !namedObjectSave.IsNewCamera)
                {
                    SpriteManager.Camera.AttachTo(newElementRuntime, false);
                    SpriteManager.Camera.RelativePosition = Vector3.Zero;
                    newElementRuntime.Z = 40;
                    newElementRuntime.Name = namedObjectSave.InstanceName;
                }
                else if (returnObject is FlatRedBall.Utilities.INameable)
                {
                    newElementRuntime.Name = ((FlatRedBall.Utilities.INameable)returnObject).Name;
                }
                else
                {
                    object nameValueAsObject;
                    if (LateBinder.TryGetValueStatic(returnObject, "Name", out nameValueAsObject))
                    {

                        newElementRuntime.Name = (string)nameValueAsObject;

                    }
                }

                listToPopulate.Add(newElementRuntime);
            }

            return returnObject;
        }
示例#55
0
        /// <summary>
        /// Returns a List of Vector3s that will be an optimized version of GetPath given the NodeNetwork and a Collision Map to test against.
        /// </summary>
        /// <remarks>
        /// This method will get the optimal path between the two vectors using GetPath, and then will optimize it by
        /// testing line of sight between the nodes to see if the path can be optimized further (for more optimized
        /// pathfinding). When optimizing the path between two nodes, it will check if the midpoint is in line of sight with the
        /// startingPosition, and if it is, change the path to the midpoint instead of the current target node. the numberOfOptimizations
        /// decides how many times it will take the midpoint and optimize further.
        /// </remarks>
        /// <param name="startingPosition">The world-coordinate of the starting position.</param>
        /// <param name="destination">The world-coordinate of the destination.</param>
        /// <param name="numberOfOptimizations">The number of times the algorithm will take the midpoint between
        /// two nodes to test if they are within line of sight of each other (higher means nearer to optimal path).</param>
        /// <param name="optimizationsDeep"></param>
        /// <param name="collisionThreshold">Usually the object using the path will be larger than 0, use the size of the collision for testing line of sight.</param>
        /// <param name="collisionMap">The collision map which will have the obstacles you are trying to path around.</param>
        /// <returns></returns>
        #endregion
        public List <Vector3> GetCollisionOptimizedPath(Vector3 startingPosition,
                                                        Vector3 destination, int numberOfOptimizations, int optimizationsDeep, float collisionThreshold, PositionedObjectList <Polygon> collisionMap)
        {
            List <PositionedNode> nodePath = GetPath(ref startingPosition, ref destination);
            List <Vector3>        path     = new List <Vector3>();

            if (nodePath.Count == 0)
            {
                return(path);
            }
            else if (nodePath.Count == 1)
            {
                path.Add(nodePath[0].Position);
                path.Add(destination);
                return(path);
            }

            Vector3 currentPosition       = startingPosition;
            int     currentNodeIndex      = 0;
            int     indexOfOutOfSightNode = 0;

            while (currentNodeIndex < nodePath.Count)
            {
                for (indexOfOutOfSightNode = currentNodeIndex; indexOfOutOfSightNode < nodePath.Count; indexOfOutOfSightNode++)
                {
                    if (PathfindingFunctions.IsInLineOfSight(currentPosition, nodePath[indexOfOutOfSightNode].Position, collisionThreshold, collisionMap))
                    {
                        //Go until we find an out of sight node.
                        continue;
                    }
                    else
                    {
                        //We found our out of sight node.
                        currentNodeIndex = indexOfOutOfSightNode;
                        break;
                    }
                }

                if (indexOfOutOfSightNode == nodePath.Count)
                { //All of the nodes in the nodePath were in line of sight, the destination should be in line of sight too.
                    if (PathfindingFunctions.IsInLineOfSight(nodePath[indexOfOutOfSightNode - 1].Position, destination, collisionMap))
                    {
                        path.Add(nodePath[indexOfOutOfSightNode - 1].Position);
                        path.Add(destination);
                        return(path);
                    }
                    //If the destination isn't in line of sight, that means the end of the path can't see the destination!
                    throw new Exception("The last node in the generated path, " + nodePath[nodePath.Count - 1].Position + ", was not in line of sight with the destination, " + destination);
                    //throw new Exception("Could not find a path to the destination, did you give a CollisionThreshold that was too high for your NodeNetwork to handle?");
                }
                //else if (indexOfOutOfSightNode == 0)
                //{
                //    throw new Exception("Not enough Node Network coverage, startingPosition:" + startingPosition + " was not in line of sight with " + nodePath[0].Position + ", the first node in the generated path.");
                //}

                //#if DEBUG
                //This will only happen if there is a problem with the given NodeNetwork.
                if (indexOfOutOfSightNode == 0)
                { //If we can't see the first node, we'll trust GetPath and just go to that node.
                    path.Add(nodePath[0].Position);
                    currentPosition = nodePath[0].Position;
                    continue;
                }
                //#endif

                Vector3 pointToAdd;
                if (optimizationsDeep > 0)
                {
                    pointToAdd = PathfindingFunctions.OptimalVisiblePoint(currentPosition, nodePath[indexOfOutOfSightNode - 1].Position,
                                                                          nodePath[indexOfOutOfSightNode].Position, numberOfOptimizations, collisionThreshold, collisionMap);
                    optimizationsDeep--;
                }
                else
                {
                    pointToAdd = nodePath[indexOfOutOfSightNode].Position;
                }

                /*
                 * if (path.Count > 0 && pointToAdd == path[path.Count - 1])
                 * { //Protect against an infinite loop of the same point being added.
                 *  //This only occurs if there is the collisionThreshold is too high for the nodenetwork to handle,
                 *  //and will make the character bump into the collisionMap when taking the path here.
                 *  pointToAdd = nodePath[indexOfOutOfSightNode].Position;
                 * }
                 */

                path.Add(pointToAdd);

                if (PathfindingFunctions.IsInLineOfSight(pointToAdd, destination, collisionMap))
                {
                    path.Add(destination);
                    return(path);
                }
                currentPosition = pointToAdd;
            }
            //This should never happen.
            throw new Exception("Given path never found the destination.");
        }
        private object LoadFileObject(NamedObjectSave objectToLoad, IElement elementSave, Layer layerToPutOn,
            PositionedObjectList<ElementRuntime> listToPopulate)
        {
            string extension = FileManager.GetExtension(objectToLoad.SourceFile).ToLower();
            object returnObject = null;

            /////////////////////////////////EARLY OUT!//////////////////////////////////
            if (objectToLoad.SetByDerived)
            {
                return null;
            }
            //////////////////////////////END EARLY OUT//////////////////////////////////

            returnObject = CreateObjectBasedOnExtension(objectToLoad, elementSave, layerToPutOn, listToPopulate, extension);

            return returnObject;
        }
 public CollidableListVsTileShapeCollectionRelationship(PositionedObjectList <FirstCollidableT> list, TileShapeCollection tileShapeCollection)
 {
     data      = new CollidableVsTileShapeCollectionData <FirstCollidableT>(tileShapeCollection);
     this.list = list;
 }
        private object CreateObjectBasedOnExtension(NamedObjectSave objectToLoad, IElement elementSave, Layer layerToPutOn, PositionedObjectList<ElementRuntime> listToPopulate, string extension)
        {
            object returnObject = null;

            switch (extension)
            {
                case "scnx":
                    returnObject = NamedObjectManager.LoadObjectForNos<Scene>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                    break;

                case "shcx":
                    returnObject = NamedObjectManager.LoadObjectForNos<ShapeCollection>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                    break;
                case "nntx":
                    //returnObject = NamedObjectManager.LoadNodeNetworkObject(objectToLoad, elementSave, layerToPutOn, listToPopulate, entireFileOnly);
                    break;
                case "emix":
                    returnObject = NamedObjectManager.LoadObjectForNos<EmitterList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                    break;
                case "splx":
                    returnObject = NamedObjectManager.LoadObjectForNos<SplineList>(objectToLoad, elementSave, layerToPutOn, listToPopulate, this);
                    break;
            }
            return returnObject;
        }
 public static void Initialize(PositionedObjectList<TileEntity> listFromScreen, string contentManager)
 {
     mContentManagerName = contentManager;
     mScreenListReference = listFromScreen;
     FactoryInitialize();
 }
        private void CreateNamedObjectElementRuntime(IElement elementSave, Layer layerProvidedByContainer, List<NamedObjectSave> namedObjectSaveList,
            PositionedObjectList<ElementRuntime> listToPopulate, PositionedObject parentElementRuntime)
        {



            foreach (NamedObjectSave n in namedObjectSaveList)
            {
                Object newObject = null;

                if (ShouldElementRuntimeBeCreatedForNos(n, elementSave))
                {
                    Layer layerToPutOn = GetLayerForNos(layerProvidedByContainer, n);

                    switch (n.SourceType)
                    {

                        case SourceType.File:

                            newObject = LoadFileObject(n, elementSave, layerToPutOn, listToPopulate);
                            
                            break;


                        case SourceType.Entity:

                            newObject = LoadEntityObject(n, layerToPutOn, listToPopulate);

                            break;


                        case SourceType.FlatRedBallType:
                            newObject = CreateFlatRedBallTypeNos(n, listToPopulate, layerToPutOn);
                            break;
                    }
                }
                if (newObject != null && newObject is PositionedObject)
                {
                    PositionedObject attachTo;
                    float parentZToSet;
                    GetWhatToAttachToForNewNos(parentElementRuntime, n, newObject, out attachTo, out parentZToSet);

                    if (attachTo != null)
                    {
                        Vector3 oldPosition = attachTo.Position;
                        Matrix oldRotationMatrix = attachTo.RotationMatrix;

                        attachTo.Position = new Vector3();



                        attachTo.Z = parentZToSet;
                        attachTo.RotationMatrix = Matrix.Identity;

                        ((PositionedObject)newObject).AttachTo(attachTo, true);

                        attachTo.Position = oldPosition;
                        attachTo.RotationMatrix = oldRotationMatrix;
                    }
                }
            }
        }