Beispiel #1
0
        public void Deduplicate(string remappingPath)
        {
            using (TexturePacker levelPacker = new TexturePacker(Level))
            {
                Dictionary <TexturedTile, List <TexturedTileSegment> > allTextures = new Dictionary <TexturedTile, List <TexturedTileSegment> >();
                foreach (TexturedTile tile in levelPacker.Tiles)
                {
                    allTextures[tile] = new List <TexturedTileSegment>(tile.Rectangles);
                }

                TextureRemapGroup remapGroup = JsonConvert.DeserializeObject <TextureRemapGroup>(File.ReadAllText(remappingPath));

                _deduplicator.SegmentMap           = allTextures;
                _deduplicator.PrecompiledRemapping = remapGroup.Remapping;
                _deduplicator.Deduplicate();

                levelPacker.AllowEmptyPacking = true;
                levelPacker.Pack(true);

                // Now we want to go through every IndexedTexture and see if it's
                // pointing to the same thing - so tile, position, and point direction
                // have to be equal. See IndexedTRObjectTexture
                Dictionary <int, int> indexMap = new Dictionary <int, int>();
                foreach (TexturedTile tile in allTextures.Keys)
                {
                    foreach (TexturedTileSegment segment in allTextures[tile])
                    {
                        TidySegment(segment, indexMap);
                    }
                }

                Level.ReindexTextures(indexMap);
                Level.ResetUnusedTextures();
            }
        }
Beispiel #2
0
        private void SegmentRepositioned(object sender, TRTextureRemapEventArgs e)
        {
            if (!_levelRemap.ContainsKey(_currentLevel))
            {
                _levelRemap[_currentLevel] = new TextureRemapGroup();
            }

            _levelRemap[_currentLevel].Remapping.Add(new TextureRemap
            {
                OriginalTile    = e.OldTile.Index,
                OriginalIndex   = e.OldFirstTextureIndex,
                OriginalBounds  = e.OldBounds,
                NewBounds       = e.NewBounds,
                NewTile         = e.NewTile.Index,
                NewIndex        = e.NewSegment.FirstTextureIndex,
                AdjustmentPoint = e.AdjustmentPoint
            });

            _currentSave += e.OldArea;

            Console.WriteLine(_currentLevel + ": " + _currentSave);
        }
Beispiel #3
0
        public void RemoveModelSegments(IEnumerable <TR2Entities> modelEntitiesToRemove, TextureRemapGroup remapGroup)
        {
            if (remapGroup == null)
            {
                RemoveModelSegmentsChecked(modelEntitiesToRemove);
                return;
            }

            // TextureRemapGroup will have been precompiled to determine shared textures between entities, so we know
            // in advance which we cannot remove.
            foreach (TR2Entities modelEntity in modelEntitiesToRemove)
            {
                Dictionary <TexturedTile, List <TexturedTileSegment> > modelSegments = GetModelSegments(modelEntity);
                foreach (TexturedTile tile in modelSegments.Keys)
                {
                    List <TexturedTileSegment> segments = modelSegments[tile];
                    for (int i = 0; i < segments.Count; i++)
                    {
                        TexturedTileSegment segment = segments[i];
                        if (remapGroup.CanRemoveRectangle(tile.Index, segment.Bounds, modelEntitiesToRemove))
                        {
                            tile.Remove(segment);
                        }
                    }
                }
            }
        }