/// <returns>TRUE on completion, or false if there are no remaining tasks.</returns> /// <remarks>This method is not thread safe. renderInProgress is not a thread-safe /// re-entry protection.</remarks> public bool RenderNextScreen() { if (renderInProgress) { return(false); } renderInProgress = true; try { LayoutIndex index; if (queue.Count > 0) { index = queue.Dequeue(); } else if (!allScreens.Finished) { index = allScreens.Current; allScreens.MoveNext(); } else { return(false); } DrawScreen(index, index.AltPalette); RenderedLayout = index; OnLayoutRendered(); return(true); } finally { renderInProgress = false; } }
private void DrawScreen(LayoutIndex index, bool altPalette) { Level levelData = Rom.GetLevel(index.Level); if (levelData.Screens.Count <= index.ScreenIndex) { return; } Screen screenData = levelData.Screens[index.ScreenIndex]; renderer.Level = levelData; renderer.SelectedEnemy = -1; renderer.ApplyPalette(screenBitmap, altPalette); //screenData.ApplyLevelPalette(screenBitmap); renderer.DefaultPalette = screenData.ColorAttributeTable; renderer.Clear(); renderer.DrawScreen(index.ScreenIndex); var enemies = ShowEnemies ? screenData.Enemies : null; renderer.Render(b, screenBitmap, enemies, screenData.Doors, ShowPhysics); }
public void Enqueue(LevelIndex level) { for (int i = 0; i < Rom.GetLevel(level).Screens.Count; i++) { LayoutIndex id = new LayoutIndex(level, i, false); if (!queue.Contains(id)) { queue.Enqueue(id); } } // Todo: One way or another the map will need to be scanned to figure out so we can enqueue only the combinations of screen index, palette, and animation that are actually used for (int i = 0; i < Rom.GetLevel(level).Screens.Count; i++) { LayoutIndex id = new LayoutIndex(level, i, true); if (!queue.Contains(id)) { queue.Enqueue(id); } } }
void OnLayoutRendered(object sender, EventArgs e) { if (!useScreenImages) { return; } Rectangle src = new Rectangle(0, 0, 256, 240); LayoutIndex index = renderer.RenderedLayout; for (int x = 0; x < 32; x++) { for (int y = 0; y < 32; y++) { if (GetLevel(x, y) == index.Level && rom.GetScreenIndex(x, y) == index.ScreenIndex && GetAltPal(x, y) == index.AltPalette) { Rectangle dest = new Rectangle(x * mapTileWidth, y * mapTileHeight, mapTileWidth, mapTileHeight); _gMapImage.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; _gMapImage.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; _gMapImage.DrawImage(renderer.RenderedImage, dest, src, GraphicsUnit.Pixel); if (PerformingInitialRender) { if ((index.ScreenIndex % 5) == 0 || index.ScreenIndex == rom.GetLevel(index.Level).Screens.Count - 1) { Invalidate(); } } else { Invalidate(); } } } } }