Пример #1
0
 /// <summary>
 /// Destroys the internal Texture2D
 /// </summary>
 public void ClearTexture()
 {
     if (m_Texture != null)
     {
         m_Texture.Clear();
         m_Texture = null;
     }
 }
Пример #2
0
        /// <summary>
        /// Downloads the panorama image using the known PanoID
        /// </summary>
        /// <param name="panoID">The PanoID to be downloaded</param>
        /// <param name="size">The <see cref="PanoSize"/> of the image to be downloaded.</param>
        /// <param name="onResult">Callback containing the Texture2D of the pano image</param>
        /// <param name="onException">Callback containing the exception when the download fails</param>
        public void Download(string panoID, PanoSize size, TextureFormat format, Action <Texture32> onResult = null, Action <Exception> onException = null)
        {
            var    width = PanoUtility.GetUserPanoWidth(size);
            string url   = "https://lh5.googleusercontent.com/p/" + panoID + "=w" + width;

            m_Running = true;

            OnStarted.TryInvoke();
            new RestClient().ExecuteAsync(new RestRequest(url, Method.GET), out m_Handle)
            .Then(response => {
                if (!m_Running)
                {
                    return;
                }
                Dispatcher.Enqueue(() => {
                    if (response.IsSuccess())
                    {
                        var texture = new Texture2D(1, 1, format, true);
                        texture.LoadImage(response.RawBytes);
                        var result = Texture32.FromTexture2D(texture);
                        MonoBehaviour.Destroy(texture);
                        texture = null;

                        onResult.TryInvoke(result);
                        OnLoaded.TryInvoke(result);
                    }
                    else
                    {
                        OnFailed.TryInvoke(response.GetException());
                        onException.TryInvoke(response.GetException());
                    }
                });
            })
            .Catch(exception => {
                if (!m_Running)
                {
                    return;
                }
                onException.TryInvoke(exception);
            });
        }
Пример #3
0
        public static Vector2 DetectBlankBands(Texture32 texture)
        {
            Color32 first;

            int height = texture.Height;

            for (int i = 0; i < texture.Height; i++)
            {
                first = texture.GetPixel(0, i);
                for (int j = 1; j < 10; j++)
                {
                    var curr = texture.GetPixel(j, i);
                    if (!first.SimilarTo(curr, 3))
                    {
                        height = texture.Height - i;
                        goto width;
                    }
                }
            }

width:

            int width = texture.Width;

            for (int i = texture.Width - 1; i > 0; i--)
            {
                first = texture.GetPixel(i, 0);
                for (int j = 1; j < 10; j++)
                {
                    var curr = texture.GetPixel(i, texture.Height - j);
                    if (!first.SimilarTo(curr, 3))
                    {
                        width = i;
                        goto done;
                    }
                }
            }

done:
            return(new Vector2(width, height));
        }
Пример #4
0
        public static int DetectWidth(Texture32 texture)
        {
            int          width  = texture.Width;
            List <float> deltas = new List <float>();

            for (int i = texture.Width - 1; i > texture.Width / 2; i--)
            {
                float sum = 0;
                for (int j = 0; j < texture.Height; j += 8)
                {
                    var reff = texture.GetPixel(0, texture.Height - 1 - j);
                    var curr = texture.GetPixel(i, texture.Height - 1 - j);
                    sum += reff.Minus(curr).Magnitude();
                }
                deltas.Add(sum);
            }

            float min = deltas[0];

            for (int i = 1; i < deltas.Count; i++)
            {
                if (min > deltas[i])
                {
                    min = deltas[i];
                }
            }

            for (int i = 0; i < deltas.Count; i++)
            {
                var f = deltas[i];
                if (f.Approximately(min))
                {
                    return(texture.Width - i);
                }
            }
            return(width);
        }
Пример #5
0
        private void CreateMapFromMaze()
        {
            var Map = new Texture32();


            #region safe map
            for (int i = 0; i < 32; i++)
            {
                for (int j = 0; j < 32; j++)
                {
                    Map[i, j] = bluewall;
                }
            }
            #endregion

            maze = new BlockMaze(new MazeGenerator(MazeSize, MazeSize, null));

            #region write walls to map
            var wall_counter = 0;

            for (int x = 1; x < maze.Width - 1; x++)
            {
                for (int y = 1; y < maze.Height - 1; y++)
                {
                    if (maze.Walls[x][y])
                    {
                        wall_counter++;

                        var variant = graywall;

                        if (y > maze.Height / 2)
                        {
                            variant = woodwall;

                            if (wall_counter % 7 == 0)
                            {
                                variant = woodwall_books;
                            }
                            if (wall_counter % 11 == 0)
                            {
                                variant = woodwall_achtung;
                            }
                            else if (wall_counter % 13 == 0)
                            {
                                variant = woodwall_verboten;
                            }
                        }
                        else
                        {
                            variant = graywall;

                            if (wall_counter % 8 == 0)
                            {
                                variant = graywall_achtung;
                            }
                            else if (wall_counter % 9 == 0)
                            {
                                variant = graywall_verboten;
                            }
                        }

                        Map[x, y] = variant;
                    }
                    else
                    {
                        Map[x, y] = 0;
                    }
                }
            }
            #endregion


            #region maze is smaller than 31
            for (int x = 1; x < maze.Width - 1; x++)
            {
                Map[x, maze.Height - 1] = greenwall;
            }

            for (int y = 1; y < maze.Height - 1; y++)
            {
                Map[maze.Width - 1, y] = greenwall;
            }
            #endregion


            EgoView.Map.WorldMap = Map;
        }
Пример #6
0
        private void ReadSync(int[] bytestream)
        {
            Map.WriteLine("sync ReadSync " + bytestream.Length);

            // we need to
            Map.RemoveAllEntities();

            var wm = new Texture32();

            var MemoryStream_UInt8 = bytestream.Select(i => (byte)i).ToArray();
            var ms = new MemoryStream(MemoryStream_UInt8);
            var mr = new BinaryReader(ms);

            #region read map
            var Values = mr.ReadInt32();

            if (Values != wm.Values.Length)
            {
                Map.WriteLine("wrong length");
                return;
            }
            uint xor = 0;

            for (int i = 0; i < Values; i++)
            {
                var v = mr.ReadUInt32();

                xor ^= v;

                wm[i] = v;
            }

            var xor_Expected = mr.ReadUInt32();

            if (xor != xor_Expected)
            {
                Map.WriteLine("xor failed " + new { xor, xor_Expected });
                return;
            }

            //Map.WriteLine("xor ok " + new { xor, xor_Expected });
            #endregion

            Map.EgoView.Map.WorldMap = wm;
            Map.ResetEgoPosition();

            this.Map.CurrentLevel     = mr.ReadInt32();
            this.Map.GoldTotal        = mr.ReadInt32();
            this.Map.AmmoTotal        = mr.ReadInt32();
            this.Map.NonblockingTotal = mr.ReadInt32();

            this.Map.GoldTotalCollected = 0;

            #region write goal pos

            this.Map.TheGoldStack.Position.x = mr.ReadDouble();
            this.Map.TheGoldStack.Position.y = mr.ReadDouble();

            // you can pick up the end goal, once it ise revealed
            this.Map.TheGoldStack.AddTo(this.Map.GoldSprites);
            #endregion


            #region read gold

            var GoldSprites_Count = mr.ReadInt32();

            //Map.WriteLine("gold: " + GoldSprites_Count);

            for (int i = 0; i < GoldSprites_Count; i++)
            {
                var ConstructorIndexForSync = mr.ReadInt32();

                var GoldSprite_x = mr.ReadDouble();
                var GoldSprite_y = mr.ReadDouble();

                Map.InsertGoldSprite(ConstructorIndexForSync, GoldSprite_x, GoldSprite_y);
            }

            #endregion


            #region read ammo

            var AmmoSprites_Count = mr.ReadInt32();

            //Map.WriteLine("ammo: " + AmmoSprites_Count);

            for (int i = 0; i < AmmoSprites_Count; i++)
            {
                var ConstructorIndexForSync = mr.ReadInt32();

                var AmmoSprite_x = mr.ReadDouble();
                var AmmoSprite_y = mr.ReadDouble();

                Map.InsertAmmoSprite(ConstructorIndexForSync, AmmoSprite_x, AmmoSprite_y);
            }

            #endregion


            #region read nonblock

            var NonblockSprites_Count = mr.ReadInt32();

            //Map.WriteLine("nonblock: " + NonblockSprites_Count);

            for (int i = 0; i < NonblockSprites_Count; i++)
            {
                var ConstructorIndexForSync = mr.ReadInt32();

                var NonblockSprite_x = mr.ReadDouble();
                var NonblockSprite_y = mr.ReadDouble();

                Map.InsertNonblockSprite(ConstructorIndexForSync, NonblockSprite_x, NonblockSprite_y);
            }

            #endregion

            #region read portals
            var Portals           = mr.ReadInt32();
            var Portals_Positions = new List <Point>();

            for (int i = 0; i < Portals; i++)
            {
                Portals_Positions.Add(new Point(mr.ReadDouble(), mr.ReadDouble()));
                Portals_Positions.Add(new Point(mr.ReadDouble(), mr.ReadDouble()));

                Map.AddNextDualPortal();
            }



            Map.UpdatePortalPositions(Portals_Positions.GetEnumerator());
            Map.UpdatePortalTextures();
            #endregion

            #region read guards
            var GuardSpritesCount = mr.ReadInt32();

            this.Map.WriteLine("guards: " + GuardSpritesCount);

            var GuardPositions = new List <Point>();
            var GuardSetup     = new List <Action <SpriteInfoExtended> >();

            for (int i = 0; i < GuardSpritesCount; i++)
            {
                var _i        = i;
                var Index     = mr.ReadInt32();
                var Health    = mr.ReadDouble();
                var Direction = mr.ReadDouble();
                var Position  = new Point(mr.ReadDouble(), mr.ReadDouble());

                GuardPositions.Add(Position);
                GuardSetup.Add(
                    k =>
                {
                    Map.WriteLine("init: guard # " + _i + " " + Index);

                    k.Health    = Health;
                    k.Direction = Direction;
                    k.ConstructorIndexForSync = Index;
                }
                    );
                //...
            }

            if (GuardSpritesCount > 0)
            {
                this.Map.CreateGuards(GuardPositions.GetEnumerator(), GuardSpritesCount, false).ForEach(GuardSetup);
            }
            #endregion

            #region end of stream
            var Found_SyncEndOfStream    = mr.ReadUInt32();
            var Expected_SyncEndOfStream = SyncEndOfStream;

            // TODO: fix compiler bug while comparing (var uint) vs (literal uint)

            if (Found_SyncEndOfStream != Expected_SyncEndOfStream)
            {
                Map.WriteLine("invalid SyncEndOfStream: " + new { Found_SyncEndOfStream, Expected_SyncEndOfStream });

                return;
            }
            #endregion



            RestoreCoPlayers();


            PlayerAdvertise();
        }
Пример #7
0
        private void Initialize()
        {
            txtMain = new TextField
            {
                defaultTextFormat = new TextFormat
                {
                    font  = "Verdana",
                    align = TextFormatAlign.LEFT,
                    size  = 10,
                    color = 0xffffff
                },
                autoSize = TextFieldAutoSize.LEFT,
                text     = "0"
            };

            AddFullscreenMenu();



            EgoView = new ViewEngineBase(DefaultWidth, DefaultHeight)
            {
                FloorAndCeilingVisible = false,

                ViewPosition = new Point {
                    x = 4, y = 22
                },
                ViewDirection = 90.DegreesToRadians(),
            };

            var Portals = new List <PortalInfo>();

            EgoView.ViewDirectionChanged += () => Portals.ForEach(Portal => Portal.View.ViewDirection = EgoView.ViewDirection);

            #region create a dual portal
            var PortalA = new PortalInfo
            {
                Color      = 0xFF6A00,
                ViewVector = new Vector {
                    Direction = EgoView.ViewDirection, Position = new Point {
                        x = 4.5, y = 14
                    }
                },
                SpriteVector = new Vector {
                    Direction = EgoView.ViewDirection, Position = new Point {
                        x = 3.5, y = 20
                    }
                },
            }.AddTo(Portals);


            EgoView.Sprites.Add(PortalA.Sprite);


            var PortalB = new PortalInfo
            {
                Color        = 0xff00,
                ViewVector   = PortalA.SpriteVector,
                SpriteVector = PortalA.ViewVector,
            }.AddTo(Portals);


            EgoView.Sprites.Add(PortalB.Sprite);
            #endregion



            var Ego = default(SpriteInfo);


            EgoView.ViewPositionChanged +=
                delegate
            {
                foreach (var Portal in Portals)
                {
                    var p = EgoView.SpritesFromPointOfView.SingleOrDefault(i => i.Sprite == Portal.Sprite);

                    if (p != null)
                    {
                        if (p.Distance < Portal.Sprite.Range)
                        {
                            // we are going thro the portal, show it

                            new Bitmap(EgoView.Buffer.clone())
                            {
                                scaleX = DefaultScale,
                                scaleY = DefaultScale
                            }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);

                            Assets.SoundFiles.teleport.ToSoundAsset().play();

                            // fixme: should use Ego.MovementDirection instead
                            // currently stepping backwards into the portal will behave recursivly
                            EgoView.ViewPosition = Portal.View.ViewPosition.MoveToArc(EgoView.ViewDirection, Portal.Sprite.Range + p.Distance);

                            break;
                        }
                    }
                }
            };

            var CameraView = new ViewEngineBase(64, 48)
            {
            };


            EgoView.RenderOverlay          += DrawMinimap;
            EgoView.FramesPerSecondChanged += () => txtMain.text = EgoView.FramesPerSecond + " fps " + new { EgoView.ViewPositionX, EgoView.ViewPositionY };

            EgoView.Image.AttachTo(this);

            txtMain.AttachTo(this);



            EgoView.Image.scaleX = DefaultScale;
            EgoView.Image.scaleY = DefaultScale;
            //this.filters = new[] { new BlurFilter() };


            KeyboardButton fKeyTurnLeft  = new uint[] { Keyboard.LEFT, 'j', 'J', };
            KeyboardButton fKeyTurnRight = new uint[] { Keyboard.RIGHT, 'l', 'L', };

            KeyboardButton fKeyStrafeLeft  = new uint[] { 'a', 'A' };
            KeyboardButton fKeyStrafeRight = new uint[] { 'd', 'D' };

            KeyboardButton fKeyUp   = new uint[] { Keyboard.UP, 'i', 'I', 'w', 'W' };
            KeyboardButton fKeyDown = new uint[] { Keyboard.DOWN, 'k', 'K', 's', 'S' };


            stage.keyDown +=
                e =>
            {
                var key = e.keyCode;

                fKeyStrafeLeft.ProcessKeyDown(key);
                fKeyStrafeRight.ProcessKeyDown(key);
                fKeyTurnLeft.ProcessKeyDown(key);
                fKeyTurnRight.ProcessKeyDown(key);

                fKeyUp.ProcessKeyDown(key);
                fKeyDown.ProcessKeyDown(key);
            };

            stage.keyUp +=
                e =>
            {
                var key = e.keyCode;


                fKeyStrafeLeft.ProcessKeyUp(key);
                fKeyStrafeRight.ProcessKeyUp(key);

                fKeyTurnLeft.ProcessKeyUp(key);
                fKeyTurnRight.ProcessKeyUp(key);

                fKeyUp.ProcessKeyUp(key);
                fKeyDown.ProcessKeyUp(key);
            };


            Action UpdateEgoPosition =
                delegate
            {
                if (Ego != null)
                {
                    Ego.Position  = EgoView.ViewPosition;
                    Ego.Direction = EgoView.ViewDirection;
                }
            };

            EgoView.ViewPositionChanged +=
                delegate
            {
                UpdateEgoPosition();
            };

            (1000 / 30).AtInterval(
                delegate
            {
                if (fKeyTurnRight.IsPressed)
                {
                    EgoView.ViewDirection += 10.DegreesToRadians();
                }
                else if (fKeyTurnLeft.IsPressed)
                {
                    EgoView.ViewDirection -= 10.DegreesToRadians();
                }

                if (fKeyUp.IsPressed || fKeyStrafeLeft.IsPressed || fKeyStrafeRight.IsPressed)
                {
                    var d = EgoView.ViewDirection;



                    if (fKeyStrafeLeft.IsPressed)
                    {
                        d -= 90.DegreesToRadians();
                    }
                    else if (fKeyStrafeRight.IsPressed)
                    {
                        d += 90.DegreesToRadians();
                    }


                    EgoView.MoveTo(
                        EgoView.ViewPositionX + Math.Cos(d) * 0.2,
                        EgoView.ViewPositionY + Math.Sin(d) * 0.2
                        );
                }
                else if (fKeyDown.IsPressed)
                {
                    EgoView.MoveTo(
                        EgoView.ViewPositionX + Math.Cos(EgoView.ViewDirection) * -0.2,
                        EgoView.ViewPositionY + Math.Sin(EgoView.ViewDirection) * -0.2
                        );
                }
            }
                );

            var UpdatePortals = true;

            stage.keyUp +=
                e =>
            {
                if (e.keyCode == Keyboard.V)
                {
                    UpdatePortals = !UpdatePortals;
                }

                if (e.keyCode == Keyboard.N)
                {
                    EgoView.RenderLowQualityWalls = !EgoView.RenderLowQualityWalls;
                }

                if (e.keyCode == Keyboard.M)
                {
                    DrawMinimapEnabled = !DrawMinimapEnabled;
                }

                if (e.keyCode == Keyboard.B)
                {
                    EgoView.SpritesVisible = !EgoView.SpritesVisible;
                }

                if (e.keyCode == Keyboard.F)
                {
                    EgoView.FloorAndCeilingVisible = !EgoView.FloorAndCeilingVisible;
                }

                if (e.keyCode == Keyboard.DELETE)
                {
                    EgoView.Sprites.RemoveAll(p => p != Ego);
                }
            };


            Action <Bitmap[]> BitmapsLoadedAction =
                Bitmaps =>
            {
                if (Bitmaps == null)
                {
                    throw new Exception("No bitmaps");
                }

                Func <Texture64[], Texture64[]> Reorder8 =
                    p =>
                    Enumerable.ToArray(
                        from i in Enumerable.Range(0, 8)
                        select p[(i + 6) % 8]
                        );

                var BitmapStream = Bitmaps.Select(i => (Texture64)i).GetEnumerator();

                Func <Texture64[]> Next8 =
                    delegate
                {
                    // keeping compiler happy with full delegate form

                    if (BitmapStream == null)
                    {
                        throw new Exception("BitmapStream is null");
                    }

                    return(Reorder8(BitmapStream.Take(8)));
                };


                var Stand = Next8();
                var Spawn = default(Func <SpriteInfo>);

                if (Bitmaps.Length == 8)
                {
                    Spawn = () => CreateWalkingDummy(Stand);
                }
                else
                {
                    var Walk = new[]
                    {
                        Next8(),
                        Next8(),
                        Next8(),
                        Next8(),
                    };



                    Spawn = () => CreateWalkingDummy(Stand, Walk);
                }

                Ego = Spawn();


                UpdateEgoPosition();



                stage.keyUp +=
                    e =>
                {
                    if (e.keyCode == Keyboard.SPACE)
                    {
                        var s = Spawn();

                        //s.Direction += 180.DegreesToRadians();

                        CameraView.ViewPosition  = s.Position;
                        CameraView.ViewDirection = s.Direction;
                    }

                    if (e.keyCode == Keyboard.INSERT)
                    {
                        var s = Spawn();

                        s.Direction += 180.DegreesToRadians();
                        s.Position   = Ego.Position.MoveToArc(Ego.Direction, 0.5);
                    }

                    if (e.keyCode == Keyboard.ENTER)
                    {
                        EgoView.ViewPosition = new Point {
                            x = 4, y = 22
                        };
                        EgoView.ViewDirection = 270.DegreesToRadians();
                    }



                    if (e.keyCode == Keyboard.BACKSPACE)
                    {
                        (1000 / 30).AtInterval(
                            t =>
                        {
                            EgoView.ViewDirection += 18.DegreesToRadians();

                            if (t.currentCount == 10)
                            {
                                t.stop();
                            }
                        }
                            );
                    }
                };
            };


            Assets.ZipFiles.MyZipFile
            .ToFiles()
            .Where(f => f.FileName.EndsWith(".png"))
            .ToBitmapArray(BitmapsLoadedAction);



            Assets.ZipFiles.MyStuff.ToFiles().ToBitmapDictionary(
                f =>
            {
                // ! important
                // ----------------------------------------------------
                // ! loading png via bytes affects pixel values
                // ! this is why map is in gif format

                EgoView.Map.WorldMap = Texture32.Of(f["Map1.gif"], false);

                Action <IEnumerator <Texture64.Entry>, Texture64, Action <SpriteInfo> > AddSpriteByTexture =
                    (SpaceForStuff, tex, handler) => SpaceForStuff.Take().Do(p => CreateDummy(tex).Do(handler).Position.To(p.XIndex + 0.5, p.YIndex + 0.5));

                var FreeSpaceForStuff = EgoView.Map.WorldMap.Entries.Where(i => i.Value == 0).Randomize().GetEnumerator();

                Action <Bitmap> AddSprite =
                    e => AddSpriteByTexture(FreeSpaceForStuff, e, null);

                Assets.ZipFiles.MySprites.ToFiles().ToBitmapArray(
                    sprites =>
                {
                    foreach (var s in sprites)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            AddSprite(s);
                        }
                    }
                }
                    );
                #region gold

                Assets.ZipFiles.MyGold.ToFiles().ToBitmapArray(
                    sprites =>
                {
                    var GoldSprites = new List <SpriteInfo>();

                    foreach (var s in sprites)
                    {
                        for (int i = 0; i < 20; i++)
                        {
                            // compiler bug: get a delegate to BCL class
                            //AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

                            AddSpriteByTexture(FreeSpaceForStuff, s,
                                               k =>
                            {
                                k.Range = 0.5;
                                GoldSprites.Add(k);
                            }
                                               );
                        }
                    }

                    var LastPosition = new Point();

                    EgoView.ViewPositionChanged +=
                        delegate
                    {
                        // only check for items each 0.5 distance travelled
                        if ((EgoView.ViewPosition - LastPosition).length < 0.5)
                        {
                            return;
                        }

                        Action Later = delegate { };


                        foreach (var Item in EgoView.SpritesFromPointOfView)
                        {
                            var Item_Sprite = Item.Sprite;

                            if (Item.Distance < Item_Sprite.Range)
                            {
                                if (GoldSprites.Contains(Item_Sprite))
                                {
                                    // ding-ding-ding!

                                    new Bitmap(new BitmapData(DefaultWidth, DefaultHeight, false, 0xffff00))
                                    {
                                        scaleX = DefaultScale,
                                        scaleY = DefaultScale
                                    }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);

                                    InternalGotGold();
                                    Later += () => EgoView.Sprites.Remove(Item_Sprite);
                                }
                            }
                        }

                        Later();

                        LastPosition = EgoView.ViewPosition;
                    };
                }
                    );
                #endregion

                #region ammo

                Assets.ZipFiles.ammo.ToFiles().ToBitmapArray(
                    sprites =>
                {
                    var AmmoSprites = new List <SpriteInfo>();

                    foreach (var s in sprites)
                    {
                        for (int i = 0; i < 20; i++)
                        {
                            // compiler bug: get a delegate to BCL class
                            //AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

                            AddSpriteByTexture(FreeSpaceForStuff, s,
                                               k =>
                            {
                                k.Range = 0.5;
                                AmmoSprites.Add(k);
                            }
                                               );
                        }
                    }

                    var LastPosition = new Point();

                    EgoView.ViewPositionChanged +=
                        delegate
                    {
                        // only check for items each 0.5 distance travelled
                        if ((EgoView.ViewPosition - LastPosition).length < 0.5)
                        {
                            return;
                        }

                        Action Later = delegate { };


                        foreach (var Item in EgoView.SpritesFromPointOfView)
                        {
                            var Item_Sprite = Item.Sprite;

                            if (Item.Distance < Item_Sprite.Range)
                            {
                                if (AmmoSprites.Contains(Item_Sprite))
                                {
                                    // ding-ding-ding!

                                    new Bitmap(new BitmapData(DefaultWidth, DefaultHeight, false, 0x8080ff))
                                    {
                                        scaleX = DefaultScale,
                                        scaleY = DefaultScale
                                    }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);


                                    InternalGotAmmo();


                                    Later += () => EgoView.Sprites.Remove(Item_Sprite);
                                }
                            }
                        }

                        Later();

                        LastPosition = EgoView.ViewPosition;
                    };
                }
                    );
                #endregion

                Func <string, Texture64> t =
                    texname => f[texname + ".png"];

                EgoView.FloorTexture   = t("floor");
                EgoView.CeilingTexture = t("roof");



                var DynamicTextureBitmap = new Bitmap(new BitmapData(Texture64.SizeConstant, Texture64.SizeConstant, false, 0));
                Texture64 DynamicTexture = DynamicTextureBitmap;
                uint DynamicTextureKey   = 0xffffff;

                EgoView.Map.WorldMap[2, 22] = DynamicTextureKey;
                EgoView.Map.WorldMap[3, 15] = DynamicTextureKey;


                EgoView.Map.Textures = new Dictionary <uint, Texture64>
                {
                    { 0xff0000, t("graywall") },
                    { 0x0000ff, t("bluewall") },
                    { 0x00ff00, t("greenwall") },
                    { 0x7F3300, t("woodwall") },

                    { DynamicTextureKey, DynamicTexture }
                };


                if (EgoView.CurrentTile != 0)
                {
                    throw new Exception("bad start position: " + new { EgoView.ViewPositionX, EgoView.ViewPositionY, EgoView.CurrentTile }.ToString());
                }



                CameraView.Map.WorldMap = EgoView.Map.WorldMap;
                CameraView.Map.Textures = EgoView.Map.Textures;
                CameraView.Sprites      = EgoView.Sprites;
                CameraView.ViewPosition = EgoView.ViewPosition;

                foreach (var Portal in Portals)
                {
                    Portal.View.Map.WorldMap = EgoView.Map.WorldMap;
                    Portal.View.Map.Textures = EgoView.Map.Textures;
                    Portal.View.Sprites      = EgoView.Sprites;
                    Portal.AlphaMask         = f["portalmask.png"];
                }


                EgoView.RenderScene();


                var MirrorFrame = f["mirror.png"];
                var counter     = 0;

                stage.enterFrame += e =>
                {
                    counter++;

                    if (UpdatePortals)
                    {
                        // updateing it too often causes framerate to drop

                        foreach (var Portal in Portals)
                        {
                            Portal.Update();
                        }

                        DynamicTextureBitmap.bitmapData.fillRect(DynamicTextureBitmap.bitmapData.rect, (uint)(counter * 8 % 256));
                        var m = new Matrix();

                        // to center
                        m.translate(0, 10);
                        // m.scale(0.3, 0.3);

                        CameraView.RenderScene();

                        DynamicTextureBitmap.bitmapData.draw(CameraView.Image.bitmapData, m);
                        DynamicTextureBitmap.bitmapData.draw(MirrorFrame.bitmapData);

                        DynamicTexture.Update();
                    }

                    EgoView.RenderScene();
                };
            }
                );

            AttachMovementInput(EgoView);
        }
Пример #8
0
        IEnumerator DownloadCo(string panoID, PanoSize size, TextureFormat format, Action <Texture32> onResult, Action <Exception> onException)
        {
            OnStarted?.Invoke();

            var uRes = PanoUtility.GetUntrimmedResolution(size);

            m_Texture = new Texture32((int)uRes.x, (int)uRes.y);
            var count = PanoUtility.GetTileCount(size);

            int xCount = (int)count.x;
            int yCount = (int)count.y;

            int  req     = xCount * yCount;
            int  success = 0;
            int  failed  = 0;
            bool done    = false;

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var x = i;
                    var y = j;

                    DownloadTile(panoID, x, y, size, format,
                                 tile => {
                        success++;
                        StitchTexture(tile, size, x, ((int)count.y - 1) - y);

                        if (success == req)
                        {
                            done = true;
                            CropTexture(size);

                            onResult?.Invoke(m_Texture);
                            OnLoaded?.Invoke(m_Texture);
                        }
                    },
                                 exception => {
                        if (x == 0 && yCount > y)
                        {
                            yCount = y;
                            req    = xCount * yCount;
                        }
                        if (y == 0 && xCount > x)
                        {
                            xCount = x;
                            req    = xCount * yCount;
                        }

                        failed++;
                        if (failed == req)
                        {
                            var thrown = new Exception("Could not download the pano image. ID or URL is incorrect.");
                            OnFailed?.Invoke(thrown);
                            onException?.Invoke(thrown);
                            return;
                        }
                        if (success == req && !done)
                        {
                            done = true;
                            CropTexture(size);
                            onResult?.Invoke(m_Texture);
                            OnLoaded?.Invoke(m_Texture);
                        }
                    }
                                 );
                    yield return(null);
                }
            }
        }
Пример #9
0
 // Copies the tile to the right place in the complete (large) texture
 // On Android devices, Graphics.CopyTexture results in the editor freezing
 // when the PanoSize is set to VeryLast. For this reason we use an extension method
 // called Texture2D.Copy. However Graphics.Copytexture is faster so we use that
 // wherever possible
 void StitchTexture(Texture2D tile, PanoSize size, int x, int y)
 {
     m_Texture.ReplaceBlock(x * tile.width, y * tile.height, Texture32.FromTexture2D(tile));
     MonoBehaviour.Destroy(tile);
     tile = null;
 }