Ejemplo n.º 1
0
        /// <summary>
        /// Gets an object group's thumbnail provided an array of objects.
        /// </summary>
        /// <param name="objects">The object components to draw.</param>
        /// <param name="gd">GraphicsDevice instance.</param>
        /// <param name="state">WorldState instance.</param>
        /// <returns>Object's ID if the object was found at the given position.</returns>
        public Texture2D GetObjectThumb(ObjectComponent[] objects, Vector3[] positions, GraphicsDevice gd, WorldState state)
        {
            var oldZoom     = state.Zoom;
            var oldRotation = state.Rotation;
            /** Center average position **/
            Vector3 average = new Vector3();

            for (int i = 0; i < positions.Length; i++)
            {
                average += positions[i];
            }
            average /= positions.Length;

            state.SilentZoom     = WorldZoom.Near;
            state.SilentRotation = WorldRotation.BottomRight;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            state.TempDraw = true;
            var pxOffset = new Vector2(442, 275) - state.WorldSpace.GetScreenFromTile(average);

            var _2d = state._2D;
            Promise <Texture2D> bufferTexture = null;
            Promise <Texture2D> depthTexture  = null;

            state._2D.OBJIDMode = false;
            Rectangle bounds = new Rectangle();

            using (var buffer = state._2D.WithBuffer(BUFFER_THUMB, ref bufferTexture, BUFFER_THUMB_DEPTH, ref depthTexture))
            {
                _2d.SetScroll(new Vector2());
                while (buffer.NextPass())
                {
                    for (int i = 0; i < objects.Length; i++)
                    {
                        var obj          = objects[i];
                        var tilePosition = positions[i];

                        //we need to trick the object into believing it is in a set world state.
                        var oldObjRot = obj.Direction;
                        var oldRoom   = obj.Room;

                        obj.Direction        = Direction.NORTH;
                        obj.Room             = 65535;
                        state.SilentZoom     = WorldZoom.Near;
                        state.SilentRotation = WorldRotation.BottomRight;
                        obj.OnRotationChanged(state);
                        obj.OnZoomChanged(state);

                        _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition) + pxOffset);
                        _2d.OffsetTile(tilePosition);
                        _2d.SetObjID(obj.ObjectID);
                        obj.Draw(gd, state);

                        //return everything to normal
                        obj.Direction        = oldObjRot;
                        obj.Room             = oldRoom;
                        state.SilentZoom     = oldZoom;
                        state.SilentRotation = oldRotation;
                        obj.OnRotationChanged(state);
                        obj.OnZoomChanged(state);
                    }
                    bounds = _2d.GetSpriteListBounds();
                }
            }
            bounds.X = Math.Max(0, Math.Min(1023, bounds.X));
            bounds.Y = Math.Max(0, Math.Min(1023, bounds.Y));
            if (bounds.Width + bounds.X > 1024)
            {
                bounds.Width = 1024 - bounds.X;
            }
            if (bounds.Height + bounds.Y > 1024)
            {
                bounds.Height = 1024 - bounds.Y;
            }

            //return things to normal
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            state.TempDraw = false;

            var tex = bufferTexture.Get();

            return(TextureUtils.Clip(gd, tex, bounds));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the current lot's thumbnail.
        /// </summary>
        /// <param name="objects">The object components to draw.</param>
        /// <param name="gd">GraphicsDevice instance.</param>
        /// <param name="state">WorldState instance.</param>
        /// <returns>Object's ID if the object was found at the given position.</returns>
        public virtual Texture2D GetLotThumb(GraphicsDevice gd, WorldState state, Action <Texture2D> rooflessCallback)
        {
            if (!(state.Camera is WorldCamera))
            {
                return(new Texture2D(gd, 8, 8));
            }
            var oldZoom           = state.Zoom;
            var oldRotation       = state.Rotation;
            var oldLevel          = state.Level;
            var oldCutaway        = Blueprint.Cutaway;
            var wCam              = (WorldCamera)state.Camera;
            var oldViewDimensions = wCam.ViewDimensions;
            //wCam.ViewDimensions = new Vector2(-1, -1);
            var oldPreciseZoom = state.PreciseZoom;

            //full invalidation because we must recalculate all object sprites. slow but necessary!
            state.Zoom            = WorldZoom.Far;
            state.Rotation        = WorldRotation.TopLeft;
            state.Level           = Blueprint.Stories;
            state.PreciseZoom     = 1 / 4f;
            state._2D.PreciseZoom = state.PreciseZoom;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();

            var oldCenter = state.CenterTile;

            state.CenterTile -= state.WorldSpace.GetTileFromScreen(new Vector2((576 - state.WorldSpace.WorldPxWidth), (576 - state.WorldSpace.WorldPxHeight)) / 2);
            var pxOffset = -state.WorldSpace.GetScreenOffset();

            state.TempDraw    = true;
            Blueprint.Cutaway = new bool[Blueprint.Cutaway.Length];

            var _2d = state._2D;
            Promise <Texture2D> bufferTexture = null;
            var lastLight = state.OutsideColor;

            state.OutsideColor  = Color.White;
            state._2D.OBJIDMode = false;
            using (var buffer = state._2D.WithBuffer(BUFFER_THUMB_DEPTH, ref bufferTexture))
            {
                _2d.SetScroll(pxOffset);
                while (buffer.NextPass())
                {
                    _2d.Pause();
                    _2d.Resume();
                    //Blueprint.SetLightColor(WorldContent.GrassEffect, Color.White, Color.White);
                    Blueprint.Terrain.Draw(gd, state);
                    //Blueprint.Terrain.DrawMask(gd, state, state.Camera.View, state.Camera.Projection);
                    Blueprint.WallComp.Draw(gd, state);
                    _2d.Pause();
                    _2d.Resume();
                    foreach (var obj in Blueprint.Objects)
                    {
                        var renderInfo   = GetRenderInfo(obj);
                        var tilePosition = obj.Position;
                        _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition));
                        _2d.OffsetTile(tilePosition);
                        obj.Draw(gd, state);
                    }
                    _2d.Pause();
                    _2d.Resume();
                    rooflessCallback?.Invoke(bufferTexture.Get());
                    Blueprint.RoofComp.Draw(gd, state);
                }
            }

            Blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.LIGHTING_CHANGED));
            Blueprint.Damage.Add(new BlueprintDamage(BlueprintDamageType.FLOOR_CHANGED));
            //return things to normal
            //state.PrepareLighting();
            state.OutsideColor = lastLight;
            state.PreciseZoom  = oldPreciseZoom;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            wCam.ViewDimensions = oldViewDimensions;
            state.TempDraw      = false;
            state.CenterTile    = oldCenter;

            state.Zoom        = oldZoom;
            state.Rotation    = oldRotation;
            state.Level       = oldLevel;
            Blueprint.Cutaway = oldCutaway;

            var tex = bufferTexture.Get();

            return(tex); //TextureUtils.Clip(gd, tex, bounds);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the current lot's thumbnail.
        /// </summary>
        /// <param name="objects">The object components to draw.</param>
        /// <param name="gd">GraphicsDevice instance.</param>
        /// <param name="state">WorldState instance.</param>
        /// <returns>Object's ID if the object was found at the given position.</returns>
        public Texture2D GetLotThumb(GraphicsDevice gd, WorldState state)
        {
            var oldZoom     = state.Zoom;
            var oldRotation = state.Rotation;
            var oldLevel    = state.Level;

            //full invalidation because we must recalculate all object sprites. slow but necessary!
            state.Zoom     = WorldZoom.Far;
            state.Rotation = WorldRotation.TopLeft;
            state.Level    = Blueprint.Stories;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();

            var oldCenter = state.CenterTile;

            state.CenterTile  = new Vector2(Blueprint.Width / 2, Blueprint.Height / 2);
            state.CenterTile -= state.WorldSpace.GetTileFromScreen(new Vector2(1024 - state.WorldSpace.WorldPxWidth, 1024 - state.WorldSpace.WorldPxHeight) / 2);
            var pxOffset = -state.WorldSpace.GetScreenOffset();

            //pxOffset -=
            state.TempDraw = true;

            var _2d = state._2D;

            _2d.AmbientLight = TextureGenerator.GetPxWhite(gd);
            Promise <Texture2D> bufferTexture = null;

            state._2D.OBJIDMode = false;
            using (var buffer = state._2D.WithBuffer(BUFFER_LOTTHUMB, ref bufferTexture))
            {
                _2d.SetScroll(pxOffset);
                while (buffer.NextPass())
                {
                    _2d.Pause();
                    _2d.Resume();
                    Blueprint.FloorComp.DrawBound = new Rectangle(6, 6, Blueprint.Width - 13, Blueprint.Height - 13);
                    Blueprint.FloorComp.Draw(gd, state);
                    Blueprint.FloorComp.DrawBound = null;
                    Blueprint.Terrain.Draw(gd, state);
                    Blueprint.WallComp.Draw(gd, state);
                    _2d.Pause();

                    _2d.Resume();
                    foreach (var obj in Blueprint.Objects)
                    {
                        var renderInfo   = GetRenderInfo(obj);
                        var tilePosition = obj.Position;
                        _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition));
                        _2d.OffsetTile(tilePosition);
                        obj.Draw(gd, state);
                    }
                    _2d.Pause();
                    _2d.Resume();
                    Blueprint.RoofComp.Draw(gd, state);
                }
            }

            //return things to normal
            _2d.AmbientLight = state.AmbientLight;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            state.TempDraw   = false;
            state.CenterTile = oldCenter;

            state.Zoom     = oldZoom;
            state.Rotation = oldRotation;
            state.Level    = oldLevel;

            var tex = bufferTexture.Get();

            return(tex); //TextureUtils.Clip(gd, tex, bounds);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets an object group's thumbnail provided an array of objects.
        /// </summary>
        /// <param name="objects">The object components to draw.</param>
        /// <param name="gd">GraphicsDevice instance.</param>
        /// <param name="state">WorldState instance.</param>
        /// <returns>Object's ID if the object was found at the given position.</returns>
        public Texture2D GetObjectThumb(ObjectComponent[] objects, Vector3[] positions, GraphicsDevice gd, WorldState state)
        {
            var oldZoom = state.Zoom;
            var oldRotation = state.Rotation;
            /** Center average position **/
            Vector3 average = new Vector3();
            for (int i = 0; i < positions.Length; i++)
            {
                average += positions[i];
            }
            average /= positions.Length;

            state.SilentZoom = WorldZoom.Near;
            state.SilentRotation = WorldRotation.BottomRight;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            state.TempDraw = true;
            var pxOffset = new Vector2(442, 275) - state.WorldSpace.GetScreenFromTile(average);

            var _2d = state._2D;
            Promise<Texture2D> bufferTexture = null;
            state._2D.OBJIDMode = false;
            Rectangle bounds = new Rectangle();
            using (var buffer = state._2D.WithBuffer(BUFFER_THUMB, ref bufferTexture))
            {
                while (buffer.NextPass())
                {
                    for (int i=0; i<objects.Length; i++)
                    {
                        var obj = objects[i];
                        var tilePosition = positions[i];

                        //we need to trick the object into believing it is in a set world state.
                        var oldObjRot = obj.Direction;

                        obj.Direction = Direction.NORTH;
                        state.SilentZoom = WorldZoom.Near;
                        state.SilentRotation = WorldRotation.BottomRight;
                        obj.OnRotationChanged(state);
                        obj.OnZoomChanged(state);

                        _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition) + pxOffset);
                        _2d.OffsetTile(tilePosition);
                        _2d.SetObjID(obj.ObjectID);
                        obj.Draw(gd, state);

                        //return everything to normal
                        obj.Direction = oldObjRot;
                        state.SilentZoom = oldZoom;
                        state.SilentRotation = oldRotation;
                        obj.OnRotationChanged(state);
                        obj.OnZoomChanged(state);
                    }
                    bounds = _2d.GetSpriteListBounds();
                }
            }
            bounds.X = Math.Max(0, Math.Min(1023, bounds.X));
            bounds.Y = Math.Max(0, Math.Min(1023, bounds.Y));
            if (bounds.Width + bounds.X > 1024) bounds.Width = 1024 - bounds.X;
            if (bounds.Height + bounds.Y > 1024) bounds.Height = 1024 - bounds.Y;

            //return things to normal
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            state.TempDraw = false;

            var tex = bufferTexture.Get();
            return TextureUtils.Clip(gd, tex, bounds);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the current lot's thumbnail.
        /// </summary>
        /// <param name="objects">The object components to draw.</param>
        /// <param name="gd">GraphicsDevice instance.</param>
        /// <param name="state">WorldState instance.</param>
        /// <returns>Object's ID if the object was found at the given position.</returns>
        public Texture2D GetLotThumb(GraphicsDevice gd, WorldState state)
        {
            var oldZoom           = state.Zoom;
            var oldRotation       = state.Rotation;
            var oldLevel          = state.Level;
            var oldCutaway        = Blueprint.Cutaway;
            var wCam              = (WorldCamera)state.Camera;
            var oldViewDimensions = wCam.ViewDimensions;
            //wCam.ViewDimensions = new Vector2(-1, -1);
            var oldPreciseZoom = state.PreciseZoom;

            //full invalidation because we must recalculate all object sprites. slow but necessary!
            state.Zoom            = WorldZoom.Far;
            state.Rotation        = WorldRotation.TopLeft;
            state.Level           = Blueprint.Stories;
            state.PreciseZoom     = 1 / 4f;
            state._2D.PreciseZoom = state.PreciseZoom;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();

            var oldCenter = state.CenterTile;

            state.CenterTile  = new Vector2(Blueprint.Width / 2, Blueprint.Height / 2);
            state.CenterTile -= state.WorldSpace.GetTileFromScreen(new Vector2((576 - state.WorldSpace.WorldPxWidth) * 4, (576 - state.WorldSpace.WorldPxHeight) * 4) / 2);
            var pxOffset = -state.WorldSpace.GetScreenOffset();

            state.TempDraw    = true;
            Blueprint.Cutaway = new bool[Blueprint.Cutaway.Length];

            var _2d = state._2D;

            state.ClearLighting(false);
            Promise <Texture2D> bufferTexture = null;
            var lastLight = state.OutsideColor;

            state.OutsideColor  = Color.White;
            state._2D.OBJIDMode = false;
            using (var buffer = state._2D.WithBuffer(BUFFER_LOTTHUMB, ref bufferTexture))
            {
                _2d.SetScroll(pxOffset);
                while (buffer.NextPass())
                {
                    _2d.Pause();
                    _2d.Resume();
                    Blueprint.FloorComp.DrawBound = new Rectangle(6, 6, Blueprint.Width - 13, Blueprint.Height - 13);
                    Blueprint.FloorComp.Draw(gd, state);
                    Blueprint.FloorComp.DrawBound = null;
                    Blueprint.WallComp.Draw(gd, state);
                    _2d.Pause();

                    _2d.Resume();
                    foreach (var obj in Blueprint.Objects)
                    {
                        var renderInfo   = GetRenderInfo(obj);
                        var tilePosition = obj.Position;
                        _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition));
                        _2d.OffsetTile(tilePosition);
                        obj.Draw(gd, state);
                    }
                    Blueprint.RoofComp.Draw(gd, state);
                }
            }

            //return things to normal
            //state.PrepareLighting();
            state.OutsideColor = lastLight;
            state.PreciseZoom  = oldPreciseZoom;
            state.WorldSpace.Invalidate();
            state.InvalidateCamera();
            wCam.ViewDimensions = oldViewDimensions;
            state.TempDraw      = false;
            state.CenterTile    = oldCenter;

            state.Zoom        = oldZoom;
            state.Rotation    = oldRotation;
            state.Level       = oldLevel;
            Blueprint.Cutaway = oldCutaway;

            var tex = bufferTexture.Get();

            return(tex); //TextureUtils.Clip(gd, tex, bounds);
        }