engine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package engine provides functionality for the app engine.

Index

Constants

View Source
const (
	StateStopped   = 0
	StateStarted   = 1
	StateUpdating  = 2
	StateRendering = 3
)
View Source
const (
	//Deprecated
	EventUpdate = -1
	//Deprecated
	EventRender = -2
	//Deprecated
	EventCloseScene = -3

	EventMouseDown         = -4
	EventDoubleClick       = -5
	EventNavigate          = -6
	EventStop              = -7
	EventKeyDown           = -8
	EventMouseUp           = -9
	EventAppHide           = -10
	EventAppShow           = -11
	EventPaste             = -12
	EventCopy              = -13
	EventMouseIn           = -14
	EventMouseOut          = -15
	EventDropFile          = -16
	EventMouseMove         = -17
	EventAppLoaded         = -18
	EventFocusGain         = -19
	EventFocusLoose        = -20
	EventMouseScroll       = -21
	EventTouchDown         = -22
	EventTouchUp           = -23
	EventTouchMove         = -24
	EventKeyUp             = -25
	EventTextInput         = -26
	EventOrientationChange = -27
)
View Source
const (
	MessageRedraw = iota
	MessageBuiltinEvent
	MessageUpdate
	MessageUpdateStop
)
View Source
const (
	FeatureSetWindowTitle = iota
)
View Source
const MessageMaxDepth = -1
View Source
const (
	TargetFrameTime = 16
)
View Source
const Version = "0.2.0"

Variables

This section is empty.

Functions

func BindEventHandler added in v0.1.5

func BindEventHandler(eventCode int, handler EventHandler)

BindEventHandler - shortcut for (engine *AmphionEngine) BindEventHandler(code int, handler EventHandler). Binds an event handler for the specified event code. The handler will be invoked in the event Loop goroutine, when the event with the specified code is raised.

func CloseScene added in v0.2.3

func CloseScene(closeCallback func())

CloseScene closes the currently showing scene asynchronously. It will call the provided callback function as soon as the scene was closed. If no scene is showing calls the callback function immediately.

func ComponentNameMatches added in v0.2.1

func ComponentNameMatches(componentName, namePattern string) bool

ComponentNameMatches checks if namePattern matches the given componentName.

func ExecuteOnFrontendThread added in v0.1.7

func ExecuteOnFrontendThread(action func())

ExecuteOnFrontendThread - shortcut for (engine *AmphionEngine) ExecuteOnFrontendThread(action func()). Executes the specified action on frontend thread.

func ForceAllViewsRedraw added in v0.2.1

func ForceAllViewsRedraw()

ForceAllViewsRedraw will request all view in the scene to redraw on the next rendering cycle. It will not request rendering, you will need to call RequestRendering after that.

func GetCurrentApp added in v0.2.0

func GetCurrentApp() *frontend.App

GetCurrentApp returns the current loaded app or nil if no app is loaded.

func GetFrontendContext added in v0.2.0

func GetFrontendContext() frontend.Context

GetFrontendContext returns the global application context. See frontend.Context.

func GetNewLineString added in v0.2.1

func GetNewLineString() string

GetNewLineString returns the correct new line sequence for the current platform.

func GetResourceManager added in v0.2.0

func GetResourceManager() frontend.ResourceManager

GetResourceManager returns the current resource manager.

func GetScreenSize added in v0.2.0

func GetScreenSize() a.IntVector2

GetScreenSize returns the screen size as a.IntVector2. X and Y are the width and height of the screen.

func GetScreenSize3 added in v0.2.0

func GetScreenSize3() a.IntVector3

GetScreenSize3 returns the screen size as a.IntVector3. X and Y are the width and height of the screen. Z = 1.

func GetSpecialValueFromString added in v0.2.0

func GetSpecialValueFromString(i interface{}) interface{}

GetSpecialValueFromString returns the value corresponding to the given special string.

func IsForcedToRedraw added in v0.2.1

func IsForcedToRedraw() bool

IsForcedToRedraw checks if all views redraw was requested in the next rendering cycle by calling ForceAllViewsRedraw.

func IsInDebugMode added in v0.2.1

func IsInDebugMode() bool

IsInDebugMode checks if engine is currently in debug mode.

func IsSpecialTransformValue added in v0.2.0

func IsSpecialTransformValue(x float32) bool

IsSpecialTransformValue checks if the given float32 value is special(MatchParent, WrapContent or CenterInParent).

func IsSpecialTransformVector3 added in v0.2.0

func IsSpecialTransformVector3(pos a.Vector3) bool

IsSpecialTransformVector3 checks if the given vector contains special transform values.

func IsSpecialValueString added in v0.2.0

func IsSpecialValueString(i interface{}) bool

IsSpecialValueString checks if the provided values is a string and it is a special values string, e.g. "$MatchParent".

func IsStatefulComponent

func IsStatefulComponent(component Component) bool

IsStatefulComponent checks if the given component has state. A component becomes stateful if is implements StatefulComponent interface or contains fields with state tag.

func LoadScene added in v0.2.3

func LoadScene(sceneId a.ResId, show bool)

LoadScene loads scene from a resource file asynchronously. If show is true, after loading also shows this scene.

func LogDebug added in v0.1.1

func LogDebug(msg string, values ...interface{})

LogDebug is same as LogInfo, but prints only if app is in debug mode.

func LogError added in v0.1.1

func LogError(msg string, values ...interface{})

LogError prints an error to the log from the current component, formatting the msg using fmt.Sprintf.

func LogInfo added in v0.1.1

func LogInfo(msg string, values ...interface{})

LogInfo prints a message to the log from the current component, formatting the msg using fmt.Sprintf.

func LogWarning added in v0.1.1

func LogWarning(msg string, values ...interface{})

LogWarning prints a warning to the log from the current component, formatting the msg using fmt.Sprintf.

func NameOfComponent

func NameOfComponent(component interface{}) string

NameOfComponent return the name of the given component suitable for serialization.

func Navigate(path string, args a.SiMap) (err error)

Opens the scene corresponding to the specified path. Path "/" corresponds to the app's main scene. Other paths correspond to the scene path in the scene folder. For example "res/scenes/test.scene" corresponds to "/test", "res/scenes/hello/test.scene" to "/hello/test". Args can be passed, that can be later read from the scene.

func RaiseEvent added in v0.2.0

func RaiseEvent(event AmphionEvent)

RaiseEvent raises a new event to be processed in the event goroutine.

func RequestRendering added in v0.1.1

func RequestRendering()

RequestRendering - shortcut for (engine *AmphionEngine) RequestRendering().

func RequestUpdate added in v0.1.1

func RequestUpdate()

RequestUpdate - shortcut for (engine *AmphionEngine) RequestUpdate().

func RunTask added in v0.1.1

func RunTask(task *Task)

RunTask - shortcut for (engine *AmphionEngine) RunTask(task Task).

func SetWindowTitle added in v0.2.0

func SetWindowTitle(title string)

SetWindowTitle updates app's window title. On web sets the tab's title.

func ShowScene added in v0.2.3

func ShowScene(scene *SceneObject) error

ShowScene shows the specified scene object. Returns an error, if the engine is not yet ready or if another scene is already showing.

func SwapScenes added in v0.2.3

func SwapScenes()

SwapScenes hides the current showing scene and shows the currently loaded scene (using LoadScene). The previously showing scene will be properly stopped and the deleted. So, calling SwapScenes again will not swap the two scenes back. If no scene is loaded, will not do anything.

func UnbindEventHandler added in v0.1.5

func UnbindEventHandler(eventCode int, handler EventHandler)

UnbindEventHandler - shortcut for (engine *AmphionEngine) UnbindEventHandler(code int, handler EventHandler). Unbinds the event handler for the specified event code. The handler will no longer be invoked, when the event with the specified code is raised.

Types

type AmphionEngine

type AmphionEngine struct {
	*FeaturesManager
	// contains filtered or unexported fields
}

func GetInstance

func GetInstance() *AmphionEngine

GetInstance returns pointer to the engine instance.

func Initialize

func Initialize(front frontend.Frontend) *AmphionEngine

Initialize initializes a new instance of Amphion Engine and configures it to run with the specified frontend. Returns pointer to the created engine instance. The engine is a singleton, so calling Initialize more than once will have no effect.

func (*AmphionEngine) BindEventHandler

func (engine *AmphionEngine) BindEventHandler(code int, handler EventHandler)

BindEventHandler binds an event handler for the specified event code. The handler will be invoked in the event Loop goroutine, when the event with the specified code is raised.

func (*AmphionEngine) CloseScene

func (engine *AmphionEngine) CloseScene(callback func())

CloseScene closes the currently showing scene asynchronously. It will call the provided callback function as soon as the scene was closed. If no scene is showing calls the callback function immediately.

func (*AmphionEngine) ExecuteOnFrontendThread added in v0.1.7

func (engine *AmphionEngine) ExecuteOnFrontendThread(action func())

ExecuteOnFrontendThread executes the specified action on frontend thread. Can be used to execute UI related functions from another goroutine.

func (*AmphionEngine) ForceAllViewsRedraw added in v0.2.0

func (engine *AmphionEngine) ForceAllViewsRedraw()

ForceAllViewsRedraw will request all view in the scene to redraw on the next rendering cycle. It will not request rendering, you will need to call RequestRendering after that.

func (*AmphionEngine) GetAppContext added in v0.1.7

func (engine *AmphionEngine) GetAppContext() *AppContext

GetAppContext returns the current app's context.

func (*AmphionEngine) GetComponentsManager

func (engine *AmphionEngine) GetComponentsManager() *ComponentsManager

GetComponentsManager returns the current ComponentsManager.

func (*AmphionEngine) GetCurrentApp

func (engine *AmphionEngine) GetCurrentApp() *frontend.App

GetCurrentApp returns the current loaded app or nil if no app is loaded.

func (*AmphionEngine) GetCurrentScene

func (engine *AmphionEngine) GetCurrentScene() *SceneObject

GetCurrentScene returns the currently displaying scene object.

func (*AmphionEngine) GetFeaturesManager added in v0.2.0

func (engine *AmphionEngine) GetFeaturesManager() *FeaturesManager

GetFeaturesManager returns the current FeaturesManager.

func (*AmphionEngine) GetFrontend

func (engine *AmphionEngine) GetFrontend() frontend.Frontend

GetFrontend returns the current frontend.

func (*AmphionEngine) GetGlobalContext

func (engine *AmphionEngine) GetGlobalContext() frontend.Context

GetGlobalContext returns the global application context. See frontend.Context.

func (*AmphionEngine) GetInputManager

func (engine *AmphionEngine) GetInputManager() *InputManager

GetInputManager returns the current input manager.

func (*AmphionEngine) GetLogger

func (engine *AmphionEngine) GetLogger() *Logger

GetLogger returns the logger.

func (*AmphionEngine) GetMessageDispatcher

func (engine *AmphionEngine) GetMessageDispatcher() *MessageDispatcher

func (*AmphionEngine) GetName

func (engine *AmphionEngine) GetName() string

func (*AmphionEngine) GetRenderer

func (engine *AmphionEngine) GetRenderer() *rendering.ARenderer

GetRenderer returns the renderer.

func (*AmphionEngine) GetResourceManager

func (engine *AmphionEngine) GetResourceManager() frontend.ResourceManager

GetResourceManager returns the current resource manager.

func (*AmphionEngine) GetSceneContext added in v0.1.7

func (engine *AmphionEngine) GetSceneContext() *SceneContext

GetSceneContext returns the current scene's context.

func (*AmphionEngine) GetState

func (engine *AmphionEngine) GetState() byte

GetState returns the current engine state.

func (*AmphionEngine) GetStateString

func (engine *AmphionEngine) GetStateString() string

GetStateString returns the current engine state as string.

func (*AmphionEngine) GetTasksRoutine

func (engine *AmphionEngine) GetTasksRoutine() *TasksRoutine

func (*AmphionEngine) IsForcedToRedraw

func (engine *AmphionEngine) IsForcedToRedraw() bool

IsForcedToRedraw checks if all views redraw was requested in the next rendering cycle by calling ForceAllViewsRedraw.

func (*AmphionEngine) IsRenderingRequested

func (engine *AmphionEngine) IsRenderingRequested() bool

IsRenderingRequested returns whether rendering is requested for the next update cycle.

func (*AmphionEngine) IsUpdateRequested

func (engine *AmphionEngine) IsUpdateRequested() bool

IsUpdateRequested returns whether an update is requested for the next frame.

func (*AmphionEngine) LoadApp

func (engine *AmphionEngine) LoadApp(delegate ...AppDelegate)

LoadApp loads app data from well-known source and shows the main scene.

func (*AmphionEngine) LoadPrefab added in v0.1.1

func (engine *AmphionEngine) LoadPrefab(resId a.ResId) (*SceneObject, error)

LoadPrefab synchronously loads prefab from file.

func (*AmphionEngine) LoadScene

func (engine *AmphionEngine) LoadScene(scene a.ResId, show bool)

LoadScene loads scene from a resource file asynchronously. If show is true, after loading also shows this scene.

func (*AmphionEngine) OnMessage

func (engine *AmphionEngine) OnMessage(_ Message) bool

func (*AmphionEngine) RaiseEvent added in v0.1.7

func (engine *AmphionEngine) RaiseEvent(event AmphionEvent)

RaiseEvent raises a new event.

func (*AmphionEngine) RequestRendering

func (engine *AmphionEngine) RequestRendering()

RequestRendering tells the engine to schedule rendering in the next update cycle. It will also request an update, if it was not requested already.

func (*AmphionEngine) RequestUpdate

func (engine *AmphionEngine) RequestUpdate()

RequestUpdate tells the engine to schedule an update as soon as possible.

func (*AmphionEngine) RunTask

func (engine *AmphionEngine) RunTask(task *Task)

RunTask runs the given task in the background goroutine.

func (*AmphionEngine) SetWindowTitle added in v0.1.7

func (engine *AmphionEngine) SetWindowTitle(title string)

SetWindowTitle updates app's window title. On web sets the tab's title.

func (*AmphionEngine) ShowScene

func (engine *AmphionEngine) ShowScene(scene *SceneObject) error

ShowScene shows the specified scene object. Returns an error, if the engine is not yet ready or if another scene is already showing.

func (*AmphionEngine) Start

func (engine *AmphionEngine) Start()

Start starts the engine. Must be called, before any interaction with the engine.

func (*AmphionEngine) Stop

func (engine *AmphionEngine) Stop()

Stop closes the current scene if any, and stops the engine.

func (*AmphionEngine) SwapScenes

func (engine *AmphionEngine) SwapScenes()

SwapScenes hides the current showing scene and shows the currently loaded scene (using LoadScene). The previously showing scene will be properly stopped and the deleted. So, calling SwapScenes again will not swap the two scenes back. If no scene is loaded, will not do anything.

func (*AmphionEngine) UnbindEventHandler

func (engine *AmphionEngine) UnbindEventHandler(code int, handler EventHandler)

UnbindEventHandler unbinds the event handler for the specified event code. The handler will no longer be invoked, when the event with the specified code is raised.

func (*AmphionEngine) WaitForStop

func (engine *AmphionEngine) WaitForStop()

WaitForStop blocks the calling goroutine until the engine is stopped.

type AmphionEvent

type AmphionEvent struct {
	Sender interface{}
	Code   int
	Data   interface{}
}

func NewAmphionEvent

func NewAmphionEvent(from interface{}, code int, data interface{}) AmphionEvent

func (AmphionEvent) MouseEventData added in v0.2.5

func (e AmphionEvent) MouseEventData() MouseEventData

func (AmphionEvent) StringData added in v0.2.5

func (e AmphionEvent) StringData() string

type AppContext added in v0.1.7

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

AppContext holds app specific data.

func GetAppContext added in v0.2.0

func GetAppContext() *AppContext

GetAppContext returns the current app's context.

func (*AppContext) Orientation added in v0.3.4

func (c *AppContext) Orientation() ScreenOrientation

type AppDelegate added in v0.3.4

type AppDelegate interface {
	OnAppLoaded()
	OnAppStopping()
}

type AppDelegateImpl added in v0.3.4

type AppDelegateImpl struct {
}

func (*AppDelegateImpl) OnAppLoaded added in v0.3.4

func (d *AppDelegateImpl) OnAppLoaded()

func (*AppDelegateImpl) OnAppStopping added in v0.3.4

func (d *AppDelegateImpl) OnAppStopping()

type BoundaryComponent

type BoundaryComponent interface {
	Component
	common.Boundary
}

BoundaryComponent is a component, that determines the bounding box of an object in the scene. Used for mouse interactions.

type ClipboardData added in v0.1.1

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

Experimental Holds an entry of clipboard

func NewClipboardData added in v0.1.1

func NewClipboardData(kind, mime string, str string, bytes []byte) *ClipboardData

func (*ClipboardData) GetData added in v0.1.1

func (c *ClipboardData) GetData() []byte

func (*ClipboardData) GetKind added in v0.1.1

func (c *ClipboardData) GetKind() string

func (*ClipboardData) GetMime added in v0.1.1

func (c *ClipboardData) GetMime() string

func (*ClipboardData) GetString added in v0.1.1

func (c *ClipboardData) GetString() string

type Component

type Component interface {
	// OnInit is called only once when the component is first created.
	OnInit(ctx InitContext)

	// OnStart is called every time the component is being enabled.
	// If the scene object is enabled on component attachment this method will also be called.
	OnStart()

	// OnStop is called when the component is being disabled.
	OnStop()
}

Component is a basic component interface. A component is a piece of functionality, that can be attached to scene objects.

func FindComponentByName added in v0.2.0

func FindComponentByName(name string, includeDirty ...bool) Component

FindComponentByName searches for a component with the specified name through all the current scene object tree. See SceneObject.FindComponentByName.

type ComponentContainer

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

Wrap around container interface, that can be enabled or disabled

func NewComponentContainer

func NewComponentContainer(sceneObject *SceneObject, component Component) *ComponentContainer

func (*ComponentContainer) GetComponent

func (c *ComponentContainer) GetComponent() Component

func (*ComponentContainer) IsDirty added in v0.2.0

func (c *ComponentContainer) IsDirty() bool

func (*ComponentContainer) IsEnabled

func (c *ComponentContainer) IsEnabled() bool

func (*ComponentContainer) SetEnabled

func (c *ComponentContainer) SetEnabled(enabled bool)

type ComponentImpl

type ComponentImpl struct {
	Engine      *AmphionEngine
	SceneObject *SceneObject
	Logger      *Logger
}

ComponentImpl is a default component interface implementation

func (*ComponentImpl) OnInit

func (c *ComponentImpl) OnInit(ctx InitContext)

func (*ComponentImpl) OnStart

func (c *ComponentImpl) OnStart()

func (*ComponentImpl) OnStop

func (c *ComponentImpl) OnStop()

type ComponentsManager

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

ComponentsManager keeps track of types of components and event handlers. that are present in the application. It also allows getting and setting the state of a component.

func GetComponentsManager added in v0.3.4

func GetComponentsManager() *ComponentsManager

GetComponentsManager returns the current ComponentsManager.

func (*ComponentsManager) GetComponentState

func (m *ComponentsManager) GetComponentState(component Component) a.SiMap

GetComponentState retrieves component's state and returns it as string-interface map.

func (*ComponentsManager) GetEventHandler

func (m *ComponentsManager) GetEventHandler(name string) EventHandler

GetEventHandler retrieves the previously registered event handler by it's name.

func (*ComponentsManager) GetName

func (m *ComponentsManager) GetName() string

func (*ComponentsManager) MakeComponent

func (m *ComponentsManager) MakeComponent(name string) Component

MakeComponent creates an instance of a component with the specified name. Returns the new instance of component or nil if component with that name was not registered.

func (*ComponentsManager) NameOfComponent added in v0.3.4

func (m *ComponentsManager) NameOfComponent(component interface{}) string

NameOfComponent return the unique name of the given component suitable for serialization.

func (*ComponentsManager) RegisterComponentType

func (m *ComponentsManager) RegisterComponentType(component Component)

RegisterComponentType registers component, so an instance of it can be later created using MakeComponent.

func (*ComponentsManager) RegisterEventHandler

func (m *ComponentsManager) RegisterEventHandler(handler EventHandler)

RegisterEventHandler registers an event handler, so that it can be serialized and deserialized as a part of component's state.

func (*ComponentsManager) SetComponentState

func (m *ComponentsManager) SetComponentState(component Component, state a.SiMap)

SetComponentState sets the component's state from the given state map.

type ConsoleLogger

type ConsoleLogger struct{}

func (*ConsoleLogger) Log

func (logger *ConsoleLogger) Log(level LogLevel, subsystem string, message string)

type DrawingContext

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

func (DrawingContext) GetRenderer

func (c DrawingContext) GetRenderer() *rendering.ARenderer

func (DrawingContext) GetRenderingNode added in v0.2.4

func (c DrawingContext) GetRenderingNode() *rendering.Node

type EventBinder

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

func (*EventBinder) Bind

func (b *EventBinder) Bind(code int, handler EventHandler)

func (*EventBinder) GetHandlers

func (b *EventBinder) GetHandlers(code int) []EventHandler

func (*EventBinder) InvokeHandlers

func (b *EventBinder) InvokeHandlers(event AmphionEvent)

func (*EventBinder) Unbind

func (b *EventBinder) Unbind(code int, handler EventHandler)

type EventHandler

type EventHandler func(event AmphionEvent) bool

EventHandler handles event. Returns whether to continue event propagation or not.

type FeatureCode added in v0.2.0

type FeatureCode int

type FeaturesManager added in v0.2.0

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

FeaturesManager is responsible for keeping track of what frontend features are available and invoking them. Frontend should register all features that it provides. Then those features become available and can be invoked.

func GetFeaturesManager added in v0.2.0

func GetFeaturesManager() *FeaturesManager

GetFeaturesManager returns the current FeaturesManager.

func (*FeaturesManager) InvokeFeature added in v0.2.0

func (f *FeaturesManager) InvokeFeature(code FeatureCode, data interface{}) interface{}

InvokeFeature invokes the feature with the specified FeatureCode if is available. Passes the specified data to the feature delegate and returns the result.

func (*FeaturesManager) IsFeatureAvailable added in v0.2.0

func (f *FeaturesManager) IsFeatureAvailable(code FeatureCode) bool

IsFeatureAvailable checks if feature with the specified FeatureCode is available (provided by the frontend).

func (*FeaturesManager) RegisterFeatureDelegate added in v0.2.0

func (f *FeaturesManager) RegisterFeatureDelegate(code FeatureCode, delegate frontend.FeatureDelegate)

RegisterFeatureDelegate should be called by the frontend.

type ILogger

type ILogger interface {
	Log(level LogLevel, subsystem string, message string)
}

type InitContext

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

InitContext contains necessary objects for component initialization.

func (InitContext) GetEngine

func (c InitContext) GetEngine() *AmphionEngine

func (InitContext) GetLogger

func (c InitContext) GetLogger() *Logger

func (InitContext) GetRenderer

func (c InitContext) GetRenderer() *rendering.ARenderer

func (InitContext) GetRenderingNode added in v0.2.4

func (c InitContext) GetRenderingNode() *rendering.Node

func (InitContext) GetSceneObject

func (c InitContext) GetSceneObject() *SceneObject

type InputFileData added in v0.1.1

type InputFileData struct {
	Name string
	Data []byte
	Mime string
}

Represents file data returned as a result of the user selecting file or dragging it.

type InputManager added in v0.2.0

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

func GetInputManager added in v0.2.0

func GetInputManager() *InputManager

GetInputManager returns the current input manager.

func (*InputManager) GetCursorPosition added in v0.2.0

func (m *InputManager) GetCursorPosition() a.IntVector2

func (*InputManager) IsKeyPressed added in v0.2.5

func (m *InputManager) IsKeyPressed(name KeyName) bool

type KeyEventData added in v0.2.5

type KeyEventData struct {
	Key, Code string
}

Deprecated

type KeyName added in v0.2.5

type KeyName string
const (
	KeyUnknown      KeyName = "Unknown"
	KeyLeftShift    KeyName = "LeftShift"
	KeyRightShift   KeyName = "RightShift"
	KeyLeftAlt      KeyName = "LeftAlt"
	KeyRightAlt     KeyName = "RightAlt"
	KeyLeftSuper    KeyName = "LeftSuper"
	KeyRightSuper   KeyName = "RightSuper"
	KeyLeftControl  KeyName = "LeftControl"
	KeyRightControl KeyName = "RightControl"
	KeySpace        KeyName = "Space"
	KeyEnter        KeyName = "Enter"
	KeyNumEnter     KeyName = "NumEnter"
	KeyBackspace    KeyName = "Backspace"
	KeyLeftArrow    KeyName = "LeftArrow"
	KeyRightArrow   KeyName = "RightArrow"
	KeyUpArrow      KeyName = "UpArrow"
	KeyDownArrow    KeyName = "DownArrow"
	KeyInsert       KeyName = "Insert"
	KeyDelete       KeyName = "Delete"
	KeyHome         KeyName = "Home"
	KeyEnd          KeyName = "End"
	KeyPageUp       KeyName = "PageUp"
	KeyPageDown     KeyName = "PageDown"
	KeyCapsLock     KeyName = "CapsLock"
	KeyTab          KeyName = "Tab"
	KeyEscape       KeyName = "Escape"
	KeyFn           KeyName = "Fn"
)

type Layout

type Layout interface {
	Component
	LayoutChildren()
}

type LogLevel

type LogLevel uint
const (
	Info    LogLevel = 0
	Warning LogLevel = 1
	Error   LogLevel = 2
)

type Logger

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

func GetLoggerForPlatform

func GetLoggerForPlatform(p common.Platform) *Logger

func (*Logger) Error

func (logger *Logger) Error(subsystem interface{}, message string)

func (*Logger) Info

func (logger *Logger) Info(subsystem interface{}, message string)

func (*Logger) Warning

func (logger *Logger) Warning(subsystem interface{}, message string)

type Message

type Message struct {
	Sender interface{}
	Code   byte
	Data   interface{}
}

func NewMessage

func NewMessage(sender interface{}, code byte, data interface{}) Message

func (Message) ToString

func (m Message) ToString() string

type MessageDispatcher

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

func NewMessageDispatcher

func NewMessageDispatcher(root MessageListener) *MessageDispatcher

func (*MessageDispatcher) AddListener

func (d *MessageDispatcher) AddListener(listener MessageListener, parent MessageListener)

Adds listener into the message tree

func (*MessageDispatcher) Dispatch

func (d *MessageDispatcher) Dispatch(message Message, maxDepth int)

Sends message from the root down in the message tree

func (*MessageDispatcher) DispatchDirectly

func (d *MessageDispatcher) DispatchDirectly(listener MessageListener, message Message)

func (*MessageDispatcher) DispatchDown

func (d *MessageDispatcher) DispatchDown(from MessageListener, message Message, maxDepth int)

Sends this message up in the message tree

func (*MessageDispatcher) DispatchUp

func (d *MessageDispatcher) DispatchUp(from MessageListener, message Message)

Sends specified message down in the message tree.

func (*MessageDispatcher) RemoveListener

func (d *MessageDispatcher) RemoveListener(listener MessageListener)

Removes listener from message tree. You cannot remove the root element.

type MessageListener

type MessageListener interface {
	// Receives a message and returns whether to continue message propagation or not
	OnMessage(message Message) bool
}

Interface for receiving messages from dispatcher

type MessageListenerComponent

type MessageListenerComponent interface {
	Component
	MessageListener
}

type MouseButton added in v0.2.5

type MouseButton byte
const (
	MouseUnknown MouseButton = iota
	MouseLeft
	MouseRight
	MouseMiddle
	MouseBack
	MouseForward
)

type MouseEventData added in v0.1.5

type MouseEventData struct {
	SceneObject   *SceneObject
	MousePosition a.IntVector2
	MouseButton   MouseButton
}

MouseEventData represents the data of mouse related event. Contains mouse coordinates, SceneObject, that was clicked and the mouse button.

type SceneContext added in v0.1.7

type SceneContext struct {
	Args a.SiMap
	// contains filtered or unexported fields
}

This struct holds data related to a scene.

func GetSceneContext added in v0.2.0

func GetSceneContext() *SceneContext

GetSceneContext returns the current scene's context.

type SceneObject

type SceneObject struct {
	Transform Transform
	// contains filtered or unexported fields
}

SceneObject is an object in the scene. The scene itself is also a SceneObject.

func FindObjectByName added in v0.2.0

func FindObjectByName(name string, includeDirty ...bool) *SceneObject

FindObjectByName searches for an object with the specified name through all the current scene object tree. See SceneObject.FindObjectByName.

func GetCurrentScene added in v0.2.0

func GetCurrentScene() *SceneObject

GetCurrentScene returns the currently displaying scene object.

func LoadPrefab added in v0.1.1

func LoadPrefab(resId a.ResId) (*SceneObject, error)

LoadPrefab - shortcut for (engine *AmphionEngine) LoadPrefab(resId int) (*SceneObject, error).

func NewSceneObject

func NewSceneObject(name string) *SceneObject

NewSceneObject creates a new instance of scene object. Can be used only with engine running.

func NewSceneObjectForTesting added in v0.2.0

func NewSceneObjectForTesting(name string, components ...Component) *SceneObject

NewSceneObjectForTesting creates a new instance of scene object without engine running. Can be used for testing purposes. Do not use in actual Amphion apps!

func (*SceneObject) AddChild

func (o *SceneObject) AddChild(object *SceneObject)

AddChild adds a child object to this scene object.

func (*SceneObject) AddComponent

func (o *SceneObject) AddComponent(component Component) Component

AddComponent adds a component to this scene object. Returns the given component.

func (*SceneObject) AddNewChild added in v0.2.7

func (o *SceneObject) AddNewChild(name string) *SceneObject

AddNewChild creates a new scene object with the given name and adds it as a child to the current object.

func (*SceneObject) Copy added in v0.2.1

func (o *SceneObject) Copy(copyName string) *SceneObject

Copy creates a new scene object with all components and children of the receiver. The new object is dirty. It is enabled if the receiver is enabled.

func (*SceneObject) DebugString added in v0.1.12

func (o *SceneObject) DebugString() string

DebugString return string for debugging.

func (*SceneObject) DecodeFromYaml

func (o *SceneObject) DecodeFromYaml(data []byte) error

func (*SceneObject) DumpToJson added in v0.2.0

func (o *SceneObject) DumpToJson() ([]byte, error)

func (*SceneObject) DumpToMap added in v0.2.0

func (o *SceneObject) DumpToMap() a.SiMap

func (*SceneObject) EncodeToJson added in v0.2.0

func (o *SceneObject) EncodeToJson() ([]byte, error)

func (*SceneObject) EncodeToYaml

func (o *SceneObject) EncodeToYaml() ([]byte, error)

func (*SceneObject) FindComponentByName added in v0.2.0

func (o *SceneObject) FindComponentByName(name string, includeDirty ...bool) Component

FindComponentByName searches for a component with the specified name through all the scene object tree. Returns the first suitable component. Returns nil if no component with the name was found. By default the search does not include dirty components. To also include dirty components pass true as the second argument.

func (*SceneObject) FindObjectByName added in v0.2.0

func (o *SceneObject) FindObjectByName(name string, includeDirty ...bool) *SceneObject

FindObjectByName searches for an object with the specified name through all the scene object tree. Returns the first suitable object. Returns nil if no object with the name was found. By default the search does not include dirty objects. To also include dirty objects pass true as the second argument.

func (*SceneObject) ForEachChild added in v0.2.0

func (o *SceneObject) ForEachChild(action func(object *SceneObject), includeDirty ...bool)

ForEachChild cycles through all direct children of the scene object, calling the specified action for each of them. The method skips dirty objects.

func (*SceneObject) ForEachComponent

func (o *SceneObject) ForEachComponent(action func(component Component))

ForEachComponent iterates over each component attached to the object, calling the action function for each of them. The method skips dirty components.

func (*SceneObject) ForEachObject

func (o *SceneObject) ForEachObject(action func(object *SceneObject), includeDirty ...bool)

ForEachObject traverses the scene object tree, calling the action function for each of the objects. The action is also called for the object on which the method was called. The method skips dirty objects.

func (*SceneObject) FromMap

func (o *SceneObject) FromMap(siMap a.SiMap)

func (*SceneObject) GetChildAt added in v0.2.7

func (o *SceneObject) GetChildAt(index int) *SceneObject

GetChildAt returns the child scene object at the given index. If there is no child with that index returns nil.

func (*SceneObject) GetChildByName

func (o *SceneObject) GetChildByName(name string) *SceneObject

GetChildByName finds scene object in the list of children of the current object. Returns nil if no object with the specified name was not found.

func (*SceneObject) GetChildren

func (o *SceneObject) GetChildren() []*SceneObject

GetChildren returns the list of children of this scene object. Modifying the returned list wont modify the actual list of children of this scene object.

func (*SceneObject) GetChildrenCount added in v0.2.1

func (o *SceneObject) GetChildrenCount() int

GetChildrenCount returns the number of children of this object.

func (*SceneObject) GetComponentByName

func (o *SceneObject) GetComponentByName(n string, includeDirty ...bool) Component

GetComponentByName searches for component with the specified name throughout the components attached to this object. The parameter n can be on of the following:

- full component name, e.g. github.com/cadmean-ru/amphion/engine/builtin.TextView,

- short component name, e.g. TextView,

- regex string.

If there are multiple components with the same name returns the first. Returns nil if no component with the name n was found or it has not been initialized or is disabled.

func (*SceneObject) GetComponentContainers added in v0.2.0

func (o *SceneObject) GetComponentContainers() []*ComponentContainer

GetComponentContainers returns the list of containers, that makes possible to enable/disable specific components.

func (*SceneObject) GetComponents

func (o *SceneObject) GetComponents(includeDirty ...bool) []Component

GetComponents returns a slice of all components attached to the object. Modifying the returned list will not change the actual list of components of this scene object.

func (*SceneObject) GetComponentsByName

func (o *SceneObject) GetComponentsByName(n string, includeDirty ...bool) []Component

GetComponentsByName searches for all components with the specified name throughout the components attached to this object. The parameter n can be on of the following:

- full component name, e.g. github.com/cadmean-ru/amphion/engine/builtin.TextView,

- short component name, e.g. TextView,

- regex string.

Returns empty slice if no components with the name n was found. Components that have not been initialized or are disabled will not be included.

func (*SceneObject) GetId

func (o *SceneObject) GetId() int

GetId returns the id of the object in the scene. The id is not guaranteed to remain the same over time and serves for internal engine purposes. For identification use object's name.

func (*SceneObject) GetName

func (o *SceneObject) GetName() string

GetName returns the name of the scene object.

func (*SceneObject) GetParent

func (o *SceneObject) GetParent() *SceneObject

GetParent returns the parent object of this scene object. Returns nil if no parent object.

func (*SceneObject) GetRenderingNode added in v0.3.4

func (o *SceneObject) GetRenderingNode() *rendering.Node

func (*SceneObject) HasBoundary

func (o *SceneObject) HasBoundary() bool

HasBoundary checks if the scene object has any boundary components.

func (*SceneObject) HasViews added in v0.2.4

func (o *SceneObject) HasViews() bool

HasViews checks if the scene object has any view components.

func (*SceneObject) IsDirty added in v0.2.0

func (o *SceneObject) IsDirty() bool

IsDirty checks if the scene object is dirty. An object is considered dirty if it has not been initialized or if it is disabled or it will be deleted in the next update. It is not safe to work with a dirty object.

func (*SceneObject) IsEnabled

func (o *SceneObject) IsEnabled() bool

IsEnabled returns if this object is currently enabled or not.

func (*SceneObject) IsFocused

func (o *SceneObject) IsFocused() bool

IsFocused checks if the scene object is currently focused.

func (*SceneObject) IsHovered added in v0.1.7

func (o *SceneObject) IsHovered() bool

IsHovered checks if the cursor is over the scene object.

func (*SceneObject) IsPointInsideBoundaries

func (o *SceneObject) IsPointInsideBoundaries(point a.Vector3) bool

func (*SceneObject) IsPointInsideBoundaries2D

func (o *SceneObject) IsPointInsideBoundaries2D(point a.Vector3) bool

func (*SceneObject) IsVisibleInScene added in v0.1.7

func (o *SceneObject) IsVisibleInScene() bool

func (*SceneObject) OnMessage

func (o *SceneObject) OnMessage(message Message) bool

func (*SceneObject) Redraw added in v0.1.3

func (o *SceneObject) Redraw()

Redraw forces all views of this object to redraw and requests rendering.

func (*SceneObject) RemoveAllChildren added in v0.2.1

func (o *SceneObject) RemoveAllChildren()

RemoveAllChildren removes all children from the receiver scene object.

func (*SceneObject) RemoveAllComponents added in v0.2.1

func (o *SceneObject) RemoveAllComponents()

RemoveAllComponents removes all components of the scene object.

func (*SceneObject) RemoveChild

func (o *SceneObject) RemoveChild(object *SceneObject)

RemoveChild removes the specified child from this scene object.

func (*SceneObject) RemoveComponent added in v0.2.1

func (o *SceneObject) RemoveComponent(comp Component)

RemoveComponent removes the given component from the scene object.

func (*SceneObject) RemoveComponentByName added in v0.2.1

func (o *SceneObject) RemoveComponentByName(name string)

RemoveComponentByName removes a component with the given name from the scene object& If there are more than one component with the same name only the first encountered component will be removed.

func (*SceneObject) RemoveFromScene added in v0.2.1

func (o *SceneObject) RemoveFromScene()

RemoveFromScene removes the scene object from the current scene. After that the object is considered dirty.

func (*SceneObject) RenderTraverse added in v0.2.4

func (o *SceneObject) RenderTraverse(action func(node *rendering.Node), afterChildrenAction func(node *rendering.Node))

func (*SceneObject) SetEnabled

func (o *SceneObject) SetEnabled(enabled bool)

SetEnabled sets the enabled state of this object as specified.

func (*SceneObject) SetParent added in v0.2.1

func (o *SceneObject) SetParent(newParent *SceneObject)

SetParent changes the parent of the scene object to the specified object. Can be used to move a child from one object to another.

func (*SceneObject) SetPosition added in v0.1.1

func (o *SceneObject) SetPosition(v a.Vector3)

SetPosition sets the position of this object equal to the specified vector, requesting rendering.

func (*SceneObject) SetPositionXy added in v0.1.3

func (o *SceneObject) SetPositionXy(x, y float32)

SetPositionXy sets the position of this object equal to a new vector with specified coordinates, requesting rendering.

func (*SceneObject) SetPositionXyz added in v0.1.1

func (o *SceneObject) SetPositionXyz(x, y, z float32)

SetPositionXyz sets the position of this object equal to a new vector with specified coordinates, requesting rendering.

func (*SceneObject) SetSize added in v0.1.1

func (o *SceneObject) SetSize(v a.Vector3)

SetSize Set the size of this object equal to the specified vector, requesting rendering.

func (*SceneObject) SetSizeXy added in v0.1.7

func (o *SceneObject) SetSizeXy(x, y float32)

SetSizeXy Set the size of this object equal to a new vector with specified coordinates, requesting rendering.

func (*SceneObject) SetSizeXyz added in v0.1.1

func (o *SceneObject) SetSizeXyz(x, y, z float32)

SetSizeXyz Set the size of this object equal to a new vector with specified coordinates, requesting rendering.

func (*SceneObject) ToMap

func (o *SceneObject) ToMap() a.SiMap

func (*SceneObject) ToString

func (o *SceneObject) ToString() string

ToString returns the string representation of the scene object.

func (*SceneObject) Traverse added in v0.2.0

func (o *SceneObject) Traverse(action func(object *SceneObject) bool, includeDirty ...bool)

Traverse traverses the scene object tree (pre-order), calling the action function for each of the objects. If action returns false interrupts the process. By default the method skips dirty objects. To also include dirty objects pass true as the second argument.

type ScreenOrientation added in v0.3.4

type ScreenOrientation int
const (
	OrientationUnknown ScreenOrientation = iota
	OrientationStraight
	OrientationReverse
	OrientationLeft
	OrientationRight
)

type StatefulComponent

type StatefulComponent interface {
	GetInstanceState() a.SiMap
	SetInstanceState(state a.SiMap)
}

StatefulComponent is an interface for components, that can persist state.

type Task

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

func NewTask

func NewTask(runner TaskRunner, callback TaskCallback, errorCallback TaskErrorCallback) *Task

type TaskBuilder

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

func NewTaskBuilder

func NewTaskBuilder() *TaskBuilder

func (*TaskBuilder) Build

func (b *TaskBuilder) Build() *Task

func (*TaskBuilder) Err

func (b *TaskBuilder) Err(callback TaskErrorCallback) *TaskBuilder

func (*TaskBuilder) Run

func (b *TaskBuilder) Run(runner TaskRunner) *TaskBuilder

func (*TaskBuilder) Then added in v0.1.1

func (b *TaskBuilder) Then(callback TaskCallback) *TaskBuilder

type TaskCallback

type TaskCallback func(res interface{})

type TaskErrorCallback

type TaskErrorCallback func(err error)

type TaskRunner

type TaskRunner func() (interface{}, error)

type TasksRoutine

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

func (*TasksRoutine) RunTask

func (r *TasksRoutine) RunTask(task *Task)

type Transform

type Transform struct {
	Position a.Vector3
	Pivot    a.Vector3
	Rotation a.Vector3
	Size     a.Vector3

	SceneObject *SceneObject
	// contains filtered or unexported fields
}

Transform describes how a scene object is positioned on the screen.

func NewTransform2D added in v0.2.0

func NewTransform2D(object *SceneObject) Transform

NewTransform2D creates a new transform with default values.

func NewTransformFromMap

func NewTransformFromMap(siMap a.SiMap) Transform

func (Transform) Equals added in v0.3.4

func (t Transform) Equals(other Transform) bool

func (*Transform) FromMap

func (t *Transform) FromMap(siMap a.SiMap)

func (Transform) GetGlobalPosition

func (t Transform) GetGlobalPosition() a.Vector3

GetGlobalPosition calculates the actual global position in the scene.

func (Transform) GetGlobalRect

func (t Transform) GetGlobalRect() *common.RectBoundary

GetGlobalRect calculates global rect of this transform.

func (Transform) GetGlobalTopLeftPosition

func (t Transform) GetGlobalTopLeftPosition() a.Vector3

GetGlobalTopLeftPosition calculates global position of the top left point of the bounding box.

func (Transform) GetLocalPosition

func (t Transform) GetLocalPosition() a.Vector3

GetLocalPosition calculates the actual local position related to this transform's parent.

func (Transform) GetParent

func (t Transform) GetParent() *Transform

GetParent returns the parent transform of the current transform.

func (Transform) GetRect

func (t Transform) GetRect() *common.RectBoundary

GetRect calculates local rect of this transform.

func (Transform) GetSize added in v0.1.1

func (t Transform) GetSize() a.Vector3

GetSize calculates the actual size of the Transform replacing the special values.

func (Transform) GetTopLeftPosition

func (t Transform) GetTopLeftPosition() a.Vector3

GetTopLeftPosition calculates local position of the top left point of the bounding box.

func (Transform) ToMap

func (t Transform) ToMap() a.SiMap

func (*Transform) ToRenderingTransform added in v0.1.1

func (t *Transform) ToRenderingTransform() rendering.Transform

ToRenderingTransform calculates a transform that is ready to be rendered on screen with all absolute values in pixels calculated.

type UpdateContext

type UpdateContext struct {
	DeltaTime float32
}

UpdateContext contains info about current update cycle

type UpdatingComponent

type UpdatingComponent interface {
	Component
	OnUpdate(ctx UpdateContext)
}

UpdatingComponent is an interface for components that can receive updates.

type ViewComponent

type ViewComponent interface {
	Component
	OnDraw(ctx DrawingContext)
	ShouldDraw() bool
	Redraw()
}

ViewComponent is an interface for views.

type ViewImpl added in v0.1.1

type ViewImpl struct {
	ShouldRedraw bool
	Context      InitContext
	PrimitiveId  int
	Engine       *AmphionEngine
	SceneObject  *SceneObject
}

ViewImpl is a basic view component implementation.

func (*ViewImpl) OnDraw added in v0.1.1

func (v *ViewImpl) OnDraw(_ DrawingContext)

func (*ViewImpl) OnInit added in v0.1.1

func (v *ViewImpl) OnInit(ctx InitContext)

func (*ViewImpl) OnMessage added in v0.1.1

func (v *ViewImpl) OnMessage(message Message) bool

func (*ViewImpl) OnStart added in v0.1.1

func (v *ViewImpl) OnStart()

func (*ViewImpl) OnStop added in v0.1.1

func (v *ViewImpl) OnStop()

func (*ViewImpl) Redraw added in v0.1.1

func (v *ViewImpl) Redraw()

func (*ViewImpl) ShouldDraw added in v0.2.4

func (v *ViewImpl) ShouldDraw() bool

Directories

Path Synopsis
Package builtin provides a set of basic components.
Package builtin provides a set of basic components.
This package is a wrapper around github.com/cadmean-ru/goRPCKit library adapted for Amphion tasks system.
This package is a wrapper around github.com/cadmean-ru/goRPCKit library adapted for Amphion tasks system.

Jump to

Keyboard shortcuts

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