d2maprenderer

package
v0.0.0-...-7f92c57 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package d2maprenderer provides a renderer for the map engine

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

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

Camera is the position of the Camera perspective in orthogonal world space. See viewport.go.

func (*Camera) Advance

func (c *Camera) Advance(elapsed float64)

Advance returns the Camera position

func (*Camera) ClearTarget

func (c *Camera) ClearTarget()

ClearTarget sets the target position

func (*Camera) GetPosition

func (c *Camera) GetPosition() *d2vector.Position

GetPosition returns the Camera position

func (*Camera) MoveBy

func (c *Camera) MoveBy(vector *d2vector.Vector)

MoveBy adds the given vector to the current position of the Camera.

func (*Camera) MoveTargetBy

func (c *Camera) MoveTargetBy(vector *d2vector.Vector)

MoveTargetBy adds the given vector to the current position of the Camera.

func (*Camera) MoveTo

func (c *Camera) MoveTo(position *d2vector.Position)

MoveTo sets the position of the Camera to the given position

func (*Camera) SetTarget

func (c *Camera) SetTarget(target *d2vector.Position)

SetTarget sets the target position

type MapRenderer

type MapRenderer struct {
	Camera Camera // Used to determine where on the map we are rendering

	*d2util.Logger
	// contains filtered or unexported fields
}

MapRenderer manages the game viewport and Camera. It requests tile and entity data from MapEngine and renders it.

func CreateMapRenderer

func CreateMapRenderer(asset *d2asset.AssetManager, renderer d2interface.Renderer,
	mapEngine *d2mapengine.MapEngine,
	term d2interface.Terminal, l d2util.LogLevel, startX, startY float64) *MapRenderer

CreateMapRenderer creates a new MapRenderer, sets the required fields and returns a pointer to it.

func (*MapRenderer) Advance

func (mr *MapRenderer) Advance(elapsed float64)

Advance is called once per frame and maintains the MapRenderer's previous render timestamp and current frame.

func (*MapRenderer) InvalidateImageCache

func (mr *MapRenderer) InvalidateImageCache()

InvalidateImageCache the global region image cache. Call this when you are changing regions.

func (*MapRenderer) MoveCameraBy

func (mr *MapRenderer) MoveCameraBy(vector *d2vector.Vector)

MoveCameraBy adds the given vector to the current position of the Camera.

func (*MapRenderer) MoveCameraTargetBy

func (mr *MapRenderer) MoveCameraTargetBy(vector *d2vector.Vector)

MoveCameraTargetBy adds the given vector to the current position of the Camera.

func (*MapRenderer) MoveCameraTo

func (mr *MapRenderer) MoveCameraTo(position *d2vector.Position)

MoveCameraTo sets the position of the Camera to the given x and y coordinates.

func (*MapRenderer) RegenerateTileCache

func (mr *MapRenderer) RegenerateTileCache()

RegenerateTileCache calls MapRenderer.generateTileCache().

func (*MapRenderer) Render

func (mr *MapRenderer) Render(target d2interface.Surface)

Render determines the width and height of map tiles that should be rendered. The following four render passes are made in succession:

Pass 1: Lower wall tiles, tile shadows and floor tiles.

Pass 2: Entities below walls.

Pass 3: Upper wall tiles and entities above walls.

Pass 4: Roof tiles.

func (*MapRenderer) ScreenToOrtho

func (mr *MapRenderer) ScreenToOrtho(x, y int) (orthoX, orthoY float64)

ScreenToOrtho returns the orthogonal position, without accounting for the isometric angle, for the given screen (pixel) position.

func (*MapRenderer) ScreenToWorld

func (mr *MapRenderer) ScreenToWorld(x, y int) (worldX, worldY float64)

ScreenToWorld returns the world position for the given screen (pixel) position.

func (*MapRenderer) SetCameraPosition

func (mr *MapRenderer) SetCameraPosition(position *d2vector.Position)

SetCameraPosition sets the Camera position

func (*MapRenderer) SetCameraTarget

func (mr *MapRenderer) SetCameraTarget(position *d2vector.Position)

SetCameraTarget sets the Camera target

func (*MapRenderer) SetMapEngine

func (mr *MapRenderer) SetMapEngine(mapEngine *d2mapengine.MapEngine)

SetMapEngine sets the MapEngine this renderer is rendering.

func (*MapRenderer) UnbindTerminalCommands

func (mr *MapRenderer) UnbindTerminalCommands(term d2interface.Terminal) error

UnbindTerminalCommands unbinds commands from the terminal

func (*MapRenderer) ViewportDefault

func (mr *MapRenderer) ViewportDefault()

ViewportDefault resets the viewport to it's default position.

func (*MapRenderer) ViewportToLeft

func (mr *MapRenderer) ViewportToLeft()

ViewportToLeft moves the viewport to the left.

func (*MapRenderer) ViewportToRight

func (mr *MapRenderer) ViewportToRight()

ViewportToRight moves the viewport to the right.

func (*MapRenderer) WorldToOrtho

func (mr *MapRenderer) WorldToOrtho(x, y float64) (orthoX, orthoY float64)

WorldToOrtho returns the orthogonal position for the given isometric world position.

func (*MapRenderer) WorldToScreen

func (mr *MapRenderer) WorldToScreen(x, y float64) (screenX, screenY int)

WorldToScreen returns the screen (pixel) position for the given isometric world position as two ints.

func (*MapRenderer) WorldToScreenF

func (mr *MapRenderer) WorldToScreenF(x, y float64) (screenX, screenY float64)

WorldToScreenF returns the screen (pixel) position for the given isometric world position as two float64s.

type Viewport

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

Viewport is used for converting vectors between screen (pixel), orthogonal (Camera) and world (isometric) space.

func NewViewport

func NewViewport(x, y, width, height int) *Viewport

NewViewport creates a new Viewport with the given parameters and returns a pointer to it.

func (*Viewport) GetTranslationOrtho

func (v *Viewport) GetTranslationOrtho() (orthoX, orthoY float64)

GetTranslationOrtho returns the viewport's current orthogonal space translation.

func (*Viewport) GetTranslationScreen

func (v *Viewport) GetTranslationScreen() (screenX, screenY int)

GetTranslationScreen returns the viewport's current screen space translation.

func (*Viewport) IsOrthoRectVisible

func (v *Viewport) IsOrthoRectVisible(x1, y1, x2, y2 float64) bool

IsOrthoRectVisible returns false if the given orthogonal position is outside the game screen.

func (*Viewport) IsTileRectVisible

func (v *Viewport) IsTileRectVisible(rect d2geom.Rectangle) bool

IsTileRectVisible returns false if none of the tiles rects are within the game screen.

func (*Viewport) IsTileVisible

func (v *Viewport) IsTileVisible(x, y float64) bool

IsTileVisible returns false if no part of the tile is within the game screen.

func (*Viewport) OrthoToScreen

func (v *Viewport) OrthoToScreen(x, y float64) (screenX, screenY int)

OrthoToScreen returns the screen position for the given orthogonal coordinates as two ints.

func (*Viewport) OrthoToScreenF

func (v *Viewport) OrthoToScreenF(x, y float64) (screenX, screenY float64)

OrthoToScreenF returns the screen position for the given orthogonal coordinates as two float64s.

func (*Viewport) OrthoToWorld

func (v *Viewport) OrthoToWorld(x, y float64) (worldX, worldY float64)

OrthoToWorld returns the world position for the given orthogonal coordinates.

func (*Viewport) PopTranslation

func (v *Viewport) PopTranslation()

PopTranslation pops a translation from the stack.

func (*Viewport) PushTranslationOrtho

func (v *Viewport) PushTranslationOrtho(x, y float64) *Viewport

PushTranslationOrtho adds a new orthogonal translation to the stack.

func (*Viewport) PushTranslationScreen

func (v *Viewport) PushTranslationScreen(x, y int)

PushTranslationScreen adds a new screen translation to the stack, converting it to orthogonal space.

func (*Viewport) PushTranslationWorld

func (v *Viewport) PushTranslationWorld(x, y float64)

PushTranslationWorld adds a new world translation to the stack, converting it to orthogonal space.

func (*Viewport) ScreenToOrtho

func (v *Viewport) ScreenToOrtho(x, y int) (orthoX, orthoY float64)

ScreenToOrtho returns the orthogonal position for the given screen coordinates.

func (*Viewport) ScreenToWorld

func (v *Viewport) ScreenToWorld(x, y int) (worldX, worldY float64)

ScreenToWorld returns the world position for the given screen coordinates.

func (*Viewport) SetCamera

func (v *Viewport) SetCamera(camera *Camera)

SetCamera sets the current Camera to the given value.

func (*Viewport) WorldToOrtho

func (v *Viewport) WorldToOrtho(x, y float64) (orthoX, orthoY float64)

WorldToOrtho returns the orthogonal position for the given world coordinates.

func (*Viewport) WorldToScreen

func (v *Viewport) WorldToScreen(x, y float64) (screenX, screenY int)

WorldToScreen returns the screen space for the given world coordinates as two integers.

func (*Viewport) WorldToScreenF

func (v *Viewport) WorldToScreenF(x, y float64) (screenX, screenY float64)

WorldToScreenF returns the screen space for the given world coordinates as two float64s.

Jump to

Keyboard shortcuts

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