Ejemplo n.º 1
0
        public WorldRenderer(GraphicsAccessor graphicsAccessor, WorldDataAccessor worldDataAccessor, PalettesService paletteService, List <MapTileInteraction> terrain) : base(graphicsAccessor)
        {
            _worldDataAccessor = worldDataAccessor;
            _paletteService    = paletteService;
            _terrain           = terrain;
            _buffer            = new byte[BITMAP_WIDTH * BITMAP_HEIGHT * 4];

            BYTE_STRIDE = BYTES_PER_PIXEL * PIXELS_PER_BLOCK_ROW * BLOCKS_PER_SCREEN * 4;
        }
Ejemplo n.º 2
0
        public byte[] CompressWorld(World world)
        {
            WorldDataAccessor worldDataAccessor = new WorldDataAccessor(world);

            byte[] data    = new byte[9 * 16 * world.ScreenLength];
            int    counter = 0;

            for (int p = 0; p < world.ScreenLength; p++)
            {
                for (int y = 0; y < World.BLOCK_HEIGHT; y++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        data[counter++] = (byte)worldDataAccessor.GetData((p * 16) + x, y);
                    }
                }
            }

            return(data);
        }
Ejemplo n.º 3
0
        public WorldPanel(GraphicsService graphicsService, PalettesService palettesService, TextService textService, TileService tileService, WorldService worldService, LevelService levelService, GameObjectService gameObjectService, WorldInfo worldInfo)
        {
            InitializeComponent();

            _worldInfo         = worldInfo;
            _textService       = textService;
            _graphicsService   = graphicsService;
            _tileService       = tileService;
            _palettesService   = palettesService;
            _worldService      = worldService;
            _gameObjectService = gameObjectService;

            _historyService     = new HistoryService();
            _interactions       = _tileService.GetMapTileInteractions();
            _world              = _worldService.LoadWorld(_worldInfo);
            _compressionService = new CompressionService();
            Tile[] bottomTableSet = _graphicsService.GetTileSection(_world.TileTableIndex);
            Tile[] topTableSet    = _graphicsService.GetTileSection(_world.AnimationTileTableIndex);
            _graphicsAccessor  = new GraphicsAccessor(topTableSet, bottomTableSet, _graphicsService.GetGlobalTiles(), _graphicsService.GetExtraTiles());
            _worldDataAccessor = new WorldDataAccessor(_world);

            _bitmap        = new WriteableBitmap(WorldRenderer.BITMAP_WIDTH, WorldRenderer.BITMAP_HEIGHT, 96, 96, PixelFormats.Bgra32, null);
            _worldRenderer = new WorldRenderer(_graphicsAccessor, _worldDataAccessor, _palettesService, _tileService.GetMapTileInteractions());
            _worldRenderer.Initializing();

            _tileSet = _tileService.GetTileSet(_world.TileSetIndex);

            Palette palette = _palettesService.GetPalette(_world.PaletteId);

            _worldRenderer.Update(tileSet: _tileSet, palette: palette);

            WorldRenderSource.Source = _bitmap;
            WorldRenderSource.Width  = _bitmap.PixelWidth;
            WorldRenderSource.Height = _bitmap.PixelHeight;
            CanvasContainer.Width    = RenderContainer.Width = _world.ScreenLength * 16 * 16;

            SelectedEditMode.SelectedIndex = 0;
            SelectedDrawMode.SelectedIndex = 0;

            TileSelector.Initialize(_graphicsAccessor, _tileService, _tileSet, palette);
            ObjectSelector.Initialize(_gameObjectService, _palettesService, _graphicsAccessor, palette);
            PointerEditor.Initialize(levelService, _worldInfo);

            _world.ObjectData.ForEach(o => o.GameObject = gameObjectService.GetObject(o.GameObjectId));


            UpdateTextTables();

            _graphicsService.GraphicsUpdated      += _graphicsService_GraphicsUpdated;
            _graphicsService.ExtraGraphicsUpdated += _graphicsService_GraphicsUpdated;
            _palettesService.PalettesChanged      += _palettesService_PalettesChanged;
            _tileService.TileSetUpdated           += _tileService_TileSetUpdated;
            _worldService.WorldUpdated            += _worldService_WorldUpdated;
            gameObjectService.GameObjectUpdated   += GameObjectService_GameObjectsUpdated;


            _world.ObjectData.ForEach(o =>
            {
                o.CalcBoundBox();
                o.CalcVisualBox(true);
            });

            _initializing = false;
            _worldRenderer.Ready();
            Update();
        }