コード例 #1
0
 public LevelRenderer(GraphicsAccessor graphicsAccessor, LevelDataAccessor levelDataAccessor, PalettesService paletteService, GameObjectService gameObjectService, List <TileTerrain> terrain) : base(graphicsAccessor)
 {
     _levelDataAccessor = levelDataAccessor;
     _gameObjectService = gameObjectService;
     _paletteService    = paletteService;
     _terrain           = terrain;
     _buffer            = new byte[BITMAP_WIDTH * BITMAP_HEIGHT * 4];
 }
コード例 #2
0
        public byte[] CompressLevel(Level level)
        {
            List <byte>        returnBytes    = new List <byte>();
            CompressionPoint   restoreToPoint = new CompressionPoint();
            CompressionCommand currentCommand = null;
            CompressionCommand attemptCommand = null;
            CompressionCommand useCommand     = null;

            ResetPoint();
            _level             = level;
            _levelDataAccessor = new LevelDataAccessor(level);

            while (!currentPoint.EOD)
            {
                // we're assuming writeraw, if we find a better command, we'll stop writeraw and use the better command
                SavePoint();
                useCommand     = null;
                attemptCommand = TryPattern();
                if (attemptCommand != null)
                {
                    useCommand     = attemptCommand;
                    restoreToPoint = currentPoint;
                }

                RestorePoint();
                attemptCommand = TryRepeat();
                if (attemptCommand != null)
                {
                    if (useCommand != null)
                    {
                        if (useCommand.GetData().Length > attemptCommand.GetData().Length)
                        {
                            useCommand     = attemptCommand;
                            restoreToPoint = currentPoint;
                        }
                    }
                    else
                    {
                        useCommand     = attemptCommand;
                        restoreToPoint = currentPoint;
                    }
                }

                RestorePoint();
                attemptCommand = TrySkip();
                if (attemptCommand != null)
                {
                    if (useCommand != null)
                    {
                        if (useCommand.GetData().Length > attemptCommand.GetData().Length)
                        {
                            useCommand     = attemptCommand;
                            restoreToPoint = currentPoint;
                        }
                    }
                    else
                    {
                        useCommand     = attemptCommand;
                        restoreToPoint = currentPoint;
                    }
                }

                if (useCommand != null)
                {
                    if (currentCommand != null)
                    {
                        returnBytes.AddRange(currentCommand.GetData());
                        currentCommand = null;
                    }

                    returnBytes.AddRange(useCommand.GetData());
                    currentPoint = restoreToPoint;
                    continue;
                }

                // made it here, we need to write raw
                RestorePoint();
                if (currentCommand == null)
                {
                    currentCommand             = new CompressionCommand();
                    currentCommand.CommandType = CompressionCommandType.WriteRaw;
                }

                currentCommand.Data.Add(NextByte());
                SavePoint();

                if (currentCommand.Data.Count == 0x40)
                {
                    returnBytes.AddRange(currentCommand.GetData());
                    currentCommand = null;
                    SavePoint();
                }
            }

            if (currentCommand != null)
            {
                returnBytes.AddRange(currentCommand.GetData());
            }
            return(returnBytes.ToArray());
        }