nimsforestviewer

package module
v0.0.0-...-6d4b782 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package nimsforestviewer provides a unified visualization viewer for Smart TVs and web browsers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ViewStateToJSONBytes

func ViewStateToJSONBytes(state *ViewState) ([]byte, error)

ViewStateToJSONBytes converts a ViewState to JSON bytes.

Types

type CallbackStateProvider

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

CallbackStateProvider calls a function to get state.

func NewCallbackStateProvider

func NewCallbackStateProvider(fn func() (*ViewState, error)) *CallbackStateProvider

NewCallbackStateProvider creates a StateProvider from a callback function.

func (*CallbackStateProvider) GetViewState

func (p *CallbackStateProvider) GetViewState() (*ViewState, error)

GetViewState implements StateProvider.

type LandJSON

type LandJSON struct {
	ID           string        `json:"id"`
	Hostname     string        `json:"hostname"`
	RAMTotal     uint64        `json:"ram_total"`
	RAMAllocated uint64        `json:"ram_allocated"`
	CPUCores     int           `json:"cpu_cores,omitempty"`
	CPUFreqGHz   float64       `json:"cpu_freq_ghz,omitempty"`
	GPUVram      uint64        `json:"gpu_vram,omitempty"`
	GPUTflops    float64       `json:"gpu_tflops,omitempty"`
	Occupancy    float64       `json:"occupancy"`
	IsManaland   bool          `json:"is_manaland"`
	GridX        int           `json:"grid_x"`
	GridY        int           `json:"grid_y"`
	Trees        []ProcessJSON `json:"trees"`
	Treehouses   []ProcessJSON `json:"treehouses"`
	Nims         []ProcessJSON `json:"nims"`
}

LandJSON is the JSON representation of a Land tile.

type LandView

type LandView struct {
	ID           string
	Hostname     string
	GridX, GridY int
	IsManaland   bool
	Occupancy    float64
	RAMTotal     uint64
	RAMAllocated uint64
	Trees        []ProcessView
	Treehouses   []ProcessView
	Nims         []ProcessView
}

LandView represents a single land/node in the visualization.

func (*LandView) AllProcesses

func (l *LandView) AllProcesses() []ProcessView

AllProcesses returns all processes on this land.

type Option

type Option func(*Viewer)

Option configures the Viewer.

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval sets the update interval for periodic updates.

type ProcessJSON

type ProcessJSON struct {
	ID           string   `json:"id"`
	Name         string   `json:"name"`
	RAMAllocated uint64   `json:"ram_allocated"`
	Type         string   `json:"type"`
	Progress     float64  `json:"progress,omitempty"`
	Subjects     []string `json:"subjects,omitempty"`
	ScriptPath   string   `json:"script_path,omitempty"`
	AIEnabled    bool     `json:"ai_enabled,omitempty"`
	Model        string   `json:"model,omitempty"`
}

ProcessJSON is the JSON representation of a process.

type ProcessView

type ProcessView struct {
	ID           string
	Name         string
	Type         string // "tree", "treehouse", "nim"
	RAMAllocated uint64
	Progress     float64
}

ProcessView represents a process running on a land.

type SmartTVTarget

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

SmartTVTarget displays static images on Smart TVs via DLNA. Uses nimsforestsprites for passive rendering and nimsforestsmarttv for transport.

func NewSmartTVTarget

func NewSmartTVTarget(tv *smarttv.TV, opts ...TVOption) (*SmartTVTarget, error)

NewSmartTVTarget creates a target that displays images on a Smart TV.

func (*SmartTVTarget) Close

func (t *SmartTVTarget) Close() error

Close implements Target.

func (*SmartTVTarget) Name

func (t *SmartTVTarget) Name() string

Name implements Target.

func (*SmartTVTarget) Stop

func (t *SmartTVTarget) Stop(ctx context.Context) error

Stop stops playback on the TV.

func (*SmartTVTarget) Update

func (t *SmartTVTarget) Update(ctx context.Context, state *ViewState) error

Update implements Target.

type SpritesStateAdapter

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

SpritesStateAdapter adapts ViewState to sprites.State interface.

func NewSpritesStateAdapter

func NewSpritesStateAdapter(state *ViewState) *SpritesStateAdapter

NewSpritesStateAdapter creates an adapter for sprites rendering.

func (*SpritesStateAdapter) Lands

func (a *SpritesStateAdapter) Lands() []sprites.Land

Lands implements sprites.State.

func (*SpritesStateAdapter) Processes

func (a *SpritesStateAdapter) Processes() []sprites.Process

Processes implements sprites.State.

type StateProvider

type StateProvider interface {
	// GetViewState returns the current visualization state.
	GetViewState() (*ViewState, error)
}

StateProvider provides the current ViewState for visualization.

type StaticStateProvider

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

StaticStateProvider wraps a fixed ViewState.

func NewStaticStateProvider

func NewStaticStateProvider(state *ViewState) *StaticStateProvider

NewStaticStateProvider creates a StateProvider from a fixed ViewState.

func (*StaticStateProvider) GetViewState

func (p *StaticStateProvider) GetViewState() (*ViewState, error)

GetViewState implements StateProvider.

type SummaryJSON

type SummaryJSON struct {
	LandCount      int     `json:"land_count"`
	ManalandCount  int     `json:"manaland_count"`
	TreeCount      int     `json:"tree_count"`
	TreehouseCount int     `json:"treehouse_count"`
	NimCount       int     `json:"nim_count"`
	TotalRAM       uint64  `json:"total_ram"`
	RAMAllocated   uint64  `json:"ram_allocated"`
	Occupancy      float64 `json:"occupancy"`
}

SummaryJSON is the JSON representation of the world summary.

type SummaryView

type SummaryView struct {
	TotalLands      int
	TotalManalands  int
	TotalTrees      int
	TotalTreehouses int
	TotalNims       int
	TotalRAM        uint64
	AllocatedRAM    uint64
}

SummaryView contains aggregate statistics.

type TVOption

type TVOption func(*SmartTVTarget)

TVOption configures a SmartTVTarget.

func WithJFIF

func WithJFIF(enable bool) TVOption

WithJFIF enables JFIF conversion for better TV compatibility. Requires ffmpeg and imagemagick to be installed.

func WithSpriteOptions

func WithSpriteOptions(opts sprites.Options) TVOption

WithSpriteOptions sets the sprite renderer options.

type Target

type Target interface {
	// Update sends new state to the target.
	Update(ctx context.Context, state *ViewState) error

	// Close cleans up the target.
	Close() error

	// Name returns a descriptive name for logging.
	Name() string
}

Target represents a visualization output destination.

type VideoOption

type VideoOption func(*VideoTarget)

VideoOption configures a VideoTarget.

func WithVideoDuration

func WithVideoDuration(d time.Duration) VideoOption

WithVideoDuration sets the video duration.

func WithVideoFPS

func WithVideoFPS(fps int) VideoOption

WithVideoFPS sets the video frame rate.

func WithVideoSpriteOptions

func WithVideoSpriteOptions(opts sprites.Options) VideoOption

WithVideoSpriteOptions sets the sprite renderer options for video.

type VideoTarget

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

VideoTarget streams continuous video to Smart TVs. Uses nimsforestsprites for rendering and ffmpeg for encoding.

func NewVideoTarget

func NewVideoTarget(tv *smarttv.TV, opts ...VideoOption) (*VideoTarget, error)

NewVideoTarget creates a target that streams video to a Smart TV.

func (*VideoTarget) Close

func (t *VideoTarget) Close() error

Close implements Target.

func (*VideoTarget) Name

func (t *VideoTarget) Name() string

Name implements Target.

func (*VideoTarget) SetStateProvider

func (t *VideoTarget) SetStateProvider(p StateProvider)

SetStateProvider sets the state provider for continuous frame generation.

func (*VideoTarget) Start

func (t *VideoTarget) Start(ctx context.Context) error

Start begins video streaming to the TV. This pre-renders a video file and streams it.

func (*VideoTarget) Stop

func (t *VideoTarget) Stop(ctx context.Context) error

Stop stops video playback on the TV.

func (*VideoTarget) Update

func (t *VideoTarget) Update(ctx context.Context, state *ViewState) error

Update implements Target. For VideoTarget, this is a no-op during streaming - use Start() to begin streaming.

type ViewState

type ViewState struct {
	Lands   []LandView
	Summary SummaryView
}

ViewState represents the complete visualization state.

type Viewer

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

Viewer manages visualization output to multiple targets.

func New

func New(opts ...Option) *Viewer

New creates a new Viewer with the given options.

func (*Viewer) AddTarget

func (v *Viewer) AddTarget(t Target) error

AddTarget adds an output target.

func (*Viewer) Close

func (v *Viewer) Close() error

Close stops the viewer and closes all targets.

func (*Viewer) RemoveTarget

func (v *Viewer) RemoveTarget(t Target)

RemoveTarget removes a target by reference.

func (*Viewer) SetStateProvider

func (v *Viewer) SetStateProvider(p StateProvider)

SetStateProvider sets the source of ViewState.

func (*Viewer) Start

func (v *Viewer) Start(ctx context.Context) error

Start begins periodic updates to all targets.

func (*Viewer) Stop

func (v *Viewer) Stop()

Stop stops periodic updates.

func (*Viewer) Update

func (v *Viewer) Update() error

Update triggers an immediate update to all targets.

type WebOption

type WebOption func(*WebTarget)

WebOption configures a WebTarget.

func WithWebDir

func WithWebDir(dir string) WebOption

WithWebDir sets the directory containing static web assets.

type WebTarget

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

WebTarget serves the visualization via HTTP for web browsers. It provides a JSON API at /api/viewmodel and can serve static assets.

func NewWebTarget

func NewWebTarget(addr string, opts ...WebOption) (*WebTarget, error)

NewWebTarget creates a target that serves the visualization via HTTP.

func (*WebTarget) Close

func (t *WebTarget) Close() error

Close implements Target.

func (*WebTarget) Handler

func (t *WebTarget) Handler() http.Handler

Handler returns the HTTP handler for embedding in existing servers.

func (*WebTarget) Name

func (t *WebTarget) Name() string

Name implements Target.

func (*WebTarget) URL

func (t *WebTarget) URL() string

URL returns the URL where the web target is serving.

func (*WebTarget) Update

func (t *WebTarget) Update(ctx context.Context, state *ViewState) error

Update implements Target.

type WorldJSON

type WorldJSON struct {
	Lands   []LandJSON  `json:"lands"`
	Summary SummaryJSON `json:"summary"`
}

WorldJSON is the JSON representation of ViewState for the web frontend.

func ViewStateToJSON

func ViewStateToJSON(state *ViewState) WorldJSON

ViewStateToJSON converts a ViewState to WorldJSON for the web frontend.

Directories

Path Synopsis
examples
multi command
Example: Multi-target viewer
Example: Multi-target viewer
smarttv command
Example: Smart TV viewer
Example: Smart TV viewer
web command
Example: Web-only viewer
Example: Web-only viewer

Jump to

Keyboard shortcuts

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