asset

package
v0.0.0-...-24e800f Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: ISC Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeFont = iota
	TypeTexture
	TypeFile
)

Variables

This section is empty.

Functions

func Wait

func Wait(rc <-chan Result) error

Wait waits for completion of a previous Preload and returns any load errors.

Types

type Asset

type Asset struct {
	Type
	Name string
}

Asset uniquely describes an asset.

func File

func File(name string) Asset

func Font

func Font(name string) Asset

func Texture

func Texture(name string) Asset

func (Asset) String

func (a Asset) String() string

type FileSystem

type FileSystem interface {
	Open(filename string) (io.Reader, error)
}

A FileSystem implements access to named resources. Names are file paths using '/' as a path separator.

type Manager

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

A Manager manages asynchronous (pre)loading and caching of textures, fonts an raw files.

func NewManager

func NewManager(fs FileSystem, options ...Option) *Manager

NewManager returns a new asset Manager.

func (*Manager) Close

func (m *Manager) Close() error

Close discards all assets.

func (*Manager) Discard

func (m *Manager) Discard(a Asset) (err error)

Discard removes the given asset from the cache.

func (*Manager) File

func (m *Manager) File(name string) ([]byte, error)

func (*Manager) Font

func (m *Manager) Font(name string) (*truetype.Font, error)

Font returns the named font asset.

func (*Manager) Preload

func (m *Manager) Preload(assets []Asset, flush bool) (rc <-chan Result, n int)

Preload bulk preloads assets. If the flush argument is true, cached assets not present in the asset list will be removed from the cache. It returns a channel to read preload results from as well as the number of items that will actually be preloaded. This item count is informational only and callers should rely on the rc channel being closed to ensure that the operation is complete.

While preload starts immediately, it will stall after a few assets have been preloaded until the rc channel is read from (or Wait is called).

Calling Preload concurrently may result in unexpected side effects, like flushing assets that should not be. An alternative is to build the assets slice concurrently and have a single goroutine call Preload and Wait.

func (*Manager) TextDrawer

func (m *Manager) TextDrawer(name string, size float64, hinting grog.Hinting, magFilter grog.TextureFilter) (*grog.TextDrawer, error)

TextDrawer returns a new grog.TextDrawer configured for the given font face (with a default DPI of 72).

Note that this function caches any grog.TextDrawer created. The only way to clean the cache is to Dispose() the corresponding font asset. If an application needs to be able to discard drawers, it should use Font() instead and manage font.Face and grog.Drawer creation and caching manually.

func (*Manager) Texture

func (m *Manager) Texture(name string, params ...grog.TextureParameter) (*grog.Texture, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is implemented by option functions passed as arguments to NewManager.

func FilePath

func FilePath(name string) Option

FilePath returns an Option that sets the default path for raw files.

func FontPath

func FontPath(name string) Option

FontPath returns an Option that sets the default font path.

func TexturePath

func TexturePath(name string) Option

TexturePath returns an Option that sets the default texture path.

type Result

type Result struct {
	Asset
	Err error
}

Result wraps the result from preloading an asset.

type Type

type Type int

Type designates the type of an asset.

Jump to

Keyboard shortcuts

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