Esempio n. 1
0
 private VectorInt3?AllocateTexture(RenderingTexture texture)
 {
     if (texture.To.X < texture.From.X || texture.To.Y < texture.From.Y)
     {
         throw new ArgumentOutOfRangeException(); // Avoid totally currupted texture allocator state.
     }
     for (int i = 0; i < Pages.Length; ++i)
     {
         VectorInt2?allocatedPos = Pages[i].Packer.TryAdd(VectorInt2.Max((texture.To - texture.From) + new VectorInt2(2), VectorInt2.One));
         if (allocatedPos != null)
         {
             VectorInt3 pos = new VectorInt3(allocatedPos.Value.X, allocatedPos.Value.Y, i);
             if (texture.To.X == texture.From.X || texture.To.Y == texture.From.Y)
             {
                 UploadTexture(ImageC.CreateNew(1, 1), pos); // Attempt to handle this situation
             }
             else
             {
                 UploadTexture(texture, pos);
             }
             AvailableTextures.Add(texture, pos + new VectorInt3(1, 1, 0));
             return(pos + new VectorInt3(1, 1, 0));
         }
     }
     return(null);
 }
Esempio n. 2
0
        public RectangleInt2 TransformRect(RectangleInt2 area, VectorInt2 oldSize)
        {
            VectorInt2 first  = Transform(area.Start, oldSize);
            VectorInt2 second = Transform(area.End, oldSize);

            return(new RectangleInt2(VectorInt2.Min(first, second), VectorInt2.Max(first, second)));
        }
Esempio n. 3
0
 protected virtual VectorInt2 GetGridDimensions()
 {
     return(VectorInt2.Max(RoomSize, new VectorInt2(Room.DefaultRoomDimensions, Room.DefaultRoomDimensions)));
 }
Esempio n. 4
0
        private static TextureArea[] ConvertTrLevelTexturesToWadTexture(TrLevel oldLevel)
        {
            var    objectTextures = new TextureArea[oldLevel.ObjectTextures.Count];
            ImageC tiles          = ImageC.FromByteArray(oldLevel.TextureMap32, 256, oldLevel.TextureMap32.Length / 1024);

            tiles.ReplaceColor(new ColorC(255, 0, 255, 255), new ColorC(0, 0, 0, 0));

            // for (int i = 0; i < oldLevel.ObjectTextures.Count; ++i)
            Parallel.For(0, oldLevel.ObjectTextures.Count, i =>
            {
                var oldTexture = oldLevel.ObjectTextures[i];

                int textureTileIndex = oldTexture.TileAndFlags & 0x7fff;
                bool isTriangle      = (oldTexture.TileAndFlags & 0x8000) != 0; // Exists only in TR4+

                if (oldLevel.Version == TRVersion.Game.TR1 || oldLevel.Version == TRVersion.Game.TR2 || oldLevel.Version == TRVersion.Game.TR3)
                {
                    isTriangle = (oldTexture.Vertices[3].X == 0) && (oldTexture.Vertices[3].Y == 0);
                }

                // Calculate UV coordinates...
                Vector2[] coords = new Vector2[isTriangle ? 3 : 4];
                for (int j = 0; j < coords.Length; ++j)
                {
                    coords[j] = new Vector2(oldTexture.Vertices[j].X, oldTexture.Vertices[j].Y) * (1.0f / 256.0f);
                }

                // Find the corners of the texture
                Vector2 min = coords[0], max = coords[0];
                for (int j = 1; j < coords.Length; ++j)
                {
                    min = Vector2.Min(min, coords[j]);
                    max = Vector2.Max(max, coords[j]);
                }

                VectorInt2 start = VectorInt2.FromFloor(min);
                VectorInt2 end   = VectorInt2.FromCeiling(max);
                start            = VectorInt2.Min(VectorInt2.Max(start, new VectorInt2()), new VectorInt2(256, 256));
                end = VectorInt2.Min(VectorInt2.Max(end, new VectorInt2()), new VectorInt2(256, 256));

                // Create image
                ImageC image = ImageC.CreateNew(end.X - start.X, end.Y - start.Y);
                image.CopyFrom(0, 0, tiles, start.X, start.Y + textureTileIndex * 256, end.X - start.X, end.Y - start.Y);

                // Replace black with transparent color
                //image.ReplaceColor(new ColorC(0, 0, 0, 255), new ColorC(0, 0, 0, 0));

                WadTexture texture = new WadTexture(image);

                // Create texture area
                TextureArea textureArea = new TextureArea();
                textureArea.DoubleSided = false;
                textureArea.BlendMode   = (BlendMode)(oldTexture.Attributes);
                textureArea.TexCoord0   = coords[0] - start;
                textureArea.TexCoord1   = coords[1] - start;
                textureArea.TexCoord2   = coords[2] - start;
                textureArea.TexCoord3   = isTriangle ? textureArea.TexCoord2 : (coords[3] - start);
                textureArea.Texture     = texture;

                objectTextures[i] = textureArea;
            });

            return(objectTextures);
        }