visual

package
v0.1.0-preview.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDissolveScaleFactor

func CalculateDissolveScaleFactor() float64

CalculateDissolveScaleFactor determines the scale factor for MessageDialog dissolve masks based on the current screen resolution.

The calculation matches the scaling used for map tiles:

  • Native map is 304×208 pixels (19×16 tiles, 13×16 tiles)
  • Scaled to fill game area (73.5% width, 96% height of screen)
  • Returns the scale factor: (targetScreenSize / nativeMapSize)

For a 1280×800 screen:

  • Game area: 940×768 pixels
  • Scale X: 940/304 ≈ 3.09
  • Scale Y: 768/208 ≈ 3.69
  • Average: ~3.4×

MessageDialog masks should be created at 1/scaleFactor size for memory efficiency.

func CalculateMaskSizeForDialog

func CalculateMaskSizeForDialog(dialogWidth, dialogHeight int) (int, int)

CalculateMaskSizeForDialog determines the optimal mask dimensions for a dialog based on the current screen scale factor.

Example:

Dialog size: 400×300 pixels (full display resolution)
Scale factor: 4.0× (high-res display)
Mask size: 100×75 pixels (1/4 scale - much more efficient!)

Returns:

maskWidth, maskHeight - dimensions for the dissolve effect mask

Types

type DissolveMode

type DissolveMode int

DissolveMode controls whether pixels are revealed or hidden during dissolve

const (
	// DissolveModeReveal starts transparent and progressively shows pixels (0 → 255 alpha)
	DissolveModeReveal DissolveMode = iota
	// DissolveModeHide starts opaque and progressively hides pixels (255 → 0 alpha)
	DissolveModeHide
)

type PixelDissolveEffect

type PixelDissolveEffect struct {
	// contains filtered or unexported fields
}

PixelDissolveEffect manages progressive random pixel reveal/conceal using GPU-accelerated masking.

This implementation uses Ebiten's BlendDestinationIn mode with a dynamically updated alpha mask, providing significant performance improvements over pixel-by-pixel Set() operations:

  • Persistent mask buffer (zero per-frame allocations)
  • CPU-side pixel updates (no GPU state changes during update)
  • Single GPU-accelerated DrawImage call per frame
  • Optional mask scaling for memory efficiency (e.g., 1/4 scale for large dialogs)

Usage:

effect := NewPixelDissolveEffect(800, 600, 200, 150, DissolveModeReveal, rng)
for progress := 0.0; progress <= 1.0; progress += 0.01 {
    effect.UpdateProgress(progress)
    mask := effect.GetMask()
    // Render with BlendDestinationIn...
}

func NewPixelDissolveEffect

func NewPixelDissolveEffect(
	targetWidth, targetHeight int,
	maskWidth, maskHeight int,
	mode DissolveMode,
	rng randomShuffler,
) *PixelDissolveEffect

NewPixelDissolveEffect creates a new dissolve effect with optional mask scaling.

Parameters:

  • targetWidth, targetHeight: Final display dimensions
  • maskWidth, maskHeight: Mask buffer dimensions (may be smaller for efficiency)
  • mode: Reveal (transparent→opaque) or Hide (opaque→transparent)
  • rng: Presentation-owned deterministic random source; never pass the gameplay source

For 1:1 rendering (sprites), use same values for target and mask dimensions. For scaled rendering (MessageDialog), use CalculateMaskSizeForDialog() for mask dimensions.

Example (sprite):

effect := NewPixelDissolveEffect(32, 32, 32, 32, DissolveModeReveal, gs.rng)

Example (scaled dialog):

maskW, maskH := CalculateMaskSizeForDialog(800, 600)
effect := NewPixelDissolveEffect(800, 600, maskW, maskH, DissolveModeReveal, rng)

func (*PixelDissolveEffect) Dispose

func (pde *PixelDissolveEffect) Dispose()

Dispose releases optional scaled and native mask images on every effect exit.

func (*PixelDissolveEffect) GetMask

func (pde *PixelDissolveEffect) GetMask() *ebiten.Image

GetMask returns the current alpha mask as an Ebiten image, scaled to target dimensions if needed.

The mask is cached and only regenerated when dirty (after UpdateProgress calls). If mask dimensions match target dimensions, returns mask directly. If mask is smaller, scales up using nearest-neighbor filtering for pixelated effect.

func (*PixelDissolveEffect) Reset

func (pde *PixelDissolveEffect) Reset()

Reset resets the effect to initial state, allowing reuse with the same dimensions.

This is more efficient than creating a new effect if dimensions haven't changed. The pixel shuffle order is preserved (same pattern will be used again).

func (*PixelDissolveEffect) UpdateProgress

func (pde *PixelDissolveEffect) UpdateProgress(progress float64) bool

UpdateProgress updates the dissolve effect based on progress (0.0 to 1.0).

Progress interpretation:

  • 0.0: Initial state (transparent for Reveal, opaque for Hide)
  • 1.0: Final state (opaque for Reveal, transparent for Hide)
  • Values outside 0.0-1.0 are clamped

Returns true if effect is complete (all pixels processed).

func (*PixelDissolveEffect) VisitLeadingPixels

func (pde *PixelDissolveEffect) VisitLeadingPixels(fraction float64, visit func(image.Rectangle))

VisitLeadingPixels optionally exposes the recently revealed portion of the deterministic mask, in target coordinates. Consumers clip highlights to their sprite before composing semantic overlays. Ordinary dissolve users are unchanged.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL