1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-18 02:16:23 -05:00

Move rendering stuff out of d2common into d2render (#281)

* Move rendering stuff out of d2common into d2render

* Remove d2interface
This commit is contained in:
Alex Yatskov 2020-02-01 17:39:28 -08:00 committed by GitHub
parent 4cbb755335
commit b5c1f5222d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 184 additions and 214 deletions

View File

@ -1,7 +0,0 @@
package d2interface
type AudioProvider interface {
PlayBGM(song string)
LoadSoundEffect(sfx string) (SoundEffect, error)
SetVolumes(bgmVolume, sfxVolume float64)
}

View File

@ -1,6 +0,0 @@
package d2interface
type SoundEffect interface {
Play()
Stop()
}

View File

@ -5,7 +5,6 @@ import (
"image/color"
"math"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
@ -28,7 +27,7 @@ type animationFrame struct {
offsetX int
offsetY int
image d2common.Surface
image d2render.Surface
}
type animationDirection struct {
@ -42,7 +41,7 @@ type Animation struct {
lastFrameTime float64
playedCount int
compositeMode d2common.CompositeMode
compositeMode d2render.CompositeMode
colorMod color.Color
playMode playMode
@ -84,7 +83,7 @@ func createAnimationFromDCC(dcc *d2dcc.DCC, palette *d2datadict.PaletteRec, tran
}
}
err, image := d2render.NewSurface(frameWidth, frameHeight, d2common.FilterNearest)
err, image := d2render.NewSurface(frameWidth, frameHeight, d2render.FilterNearest)
if err != nil {
return nil, err
}
@ -119,7 +118,7 @@ func createAnimationFromDC6(dc6 *d2dc6.DC6File) (*Animation, error) {
}
for frameIndex, dc6Frame := range dc6.Frames {
err, image := d2render.NewSurface(int(dc6Frame.Width), int(dc6Frame.Height), d2common.FilterNearest)
err, image := d2render.NewSurface(int(dc6Frame.Width), int(dc6Frame.Height), d2render.FilterNearest)
if err != nil {
return nil, err
}
@ -192,7 +191,7 @@ func (a *Animation) Advance(elapsed float64) error {
return nil
}
func (a *Animation) Render(target d2common.Surface) error {
func (a *Animation) Render(target d2render.Surface) error {
direction := a.directions[a.directionIndex]
frame := direction.frames[a.frameIndex]
@ -325,8 +324,8 @@ func (a *Animation) ResetPlayedCount() {
func (a *Animation) SetBlend(blend bool) {
if blend {
a.compositeMode = d2common.CompositeModeLighter
a.compositeMode = d2render.CompositeModeLighter
} else {
a.compositeMode = d2common.CompositeModeSourceOver
a.compositeMode = d2render.CompositeModeSourceOver
}
}

View File

@ -5,11 +5,11 @@ import (
"fmt"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type Composite struct {
@ -45,7 +45,7 @@ func (c *Composite) Advance(elapsed float64) error {
return nil
}
func (c *Composite) Render(target d2common.Surface) error {
func (c *Composite) Render(target d2render.Surface) error {
if c.mode == nil {
return nil
}

View File

@ -2,19 +2,28 @@ package d2audio
import (
"errors"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
var singleton d2interface.AudioProvider
var singleton AudioProvider
var (
ErrHasInit error = errors.New("audio system is already initialized")
ErrNotInit error = errors.New("audio system has not been initialized")
)
type SoundEffect interface {
Play()
Stop()
}
type AudioProvider interface {
PlayBGM(song string)
LoadSoundEffect(sfx string) (SoundEffect, error)
SetVolumes(bgmVolume, sfxVolume float64)
}
// CreateManager creates a sound provider
func Initialize(audioProvider d2interface.AudioProvider) error {
func Initialize(audioProvider AudioProvider) error {
if singleton != nil {
return ErrHasInit
}
@ -31,7 +40,7 @@ func PlayBGM(song string) error {
return nil
}
func LoadSoundEffect(sfx string) (d2interface.SoundEffect, error) {
func LoadSoundEffect(sfx string) (SoundEffect, error) {
if singleton == nil {
return nil, ErrNotInit
}

View File

@ -3,9 +3,8 @@ package ebiten
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
"github.com/hajimehoshi/ebiten/audio/wav"
"github.com/hajimehoshi/ebiten/audio"
@ -72,7 +71,7 @@ func (eap *EbitenAudioProvider) PlayBGM(song string) {
}()
}
func (eap *EbitenAudioProvider) LoadSoundEffect(sfx string) (d2interface.SoundEffect, error) {
func (eap *EbitenAudioProvider) LoadSoundEffect(sfx string) (d2audio.SoundEffect, error) {
result := CreateSoundEffect(sfx, eap.audioContext, eap.sfxVolume) // TODO: Split
return result, nil
}

View File

@ -1,4 +1,4 @@
package d2interface
package d2inventory
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"

View File

@ -4,11 +4,11 @@ import (
"math"
"math/rand"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
// AnimatedEntity represents an entity on the map that can be animated
@ -70,7 +70,7 @@ func (v AnimatedEntity) Wait() bool {
}
// Render draws this animated entity onto the target
func (v *AnimatedEntity) Render(target d2common.Surface) {
func (v *AnimatedEntity) Render(target d2render.Surface) {
target.PushTranslation(
int(v.offsetX)+int((v.subcellX-v.subcellY)*16),
int(v.offsetY)+int(((v.subcellX+v.subcellY)*8)-5),

View File

@ -4,8 +4,7 @@ import (
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
@ -13,7 +12,7 @@ import (
)
type MapEntity interface {
Render(target d2common.Surface)
Render(target d2render.Surface)
Advance(tickTime float64)
GetPosition() (float64, float64)
}
@ -134,7 +133,7 @@ func (me *MapEngine) Advance(tickTime float64) {
}
}
func (me *MapEngine) Render(target d2common.Surface) {
func (me *MapEngine) Render(target d2render.Surface) {
for _, region := range me.regions {
if region.isVisbile(me.viewport) {
region.renderPass1(me.viewport, target)

View File

@ -1,11 +1,11 @@
package d2map
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type Hero struct {
@ -52,7 +52,7 @@ func (v *Hero) Advance(tickTime float64) {
v.AnimatedEntity.Advance(tickTime)
}
func (v *Hero) Render(target d2common.Surface) {
func (v *Hero) Render(target d2render.Surface) {
v.AnimatedEntity.Render(target)
}

View File

@ -4,6 +4,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type NPC struct {
@ -42,7 +43,7 @@ func (v *NPC) SetPaths(paths []d2common.Path) {
v.HasPaths = len(paths) > 0
}
func (v *NPC) Render(target d2common.Surface) {
func (v *NPC) Render(target d2render.Surface) {
v.AnimatedEntity.Render(target)
}

View File

@ -31,7 +31,7 @@ type MapRegion struct {
palette d2datadict.PaletteRec
startX float64
startY float64
imageCacheRecords map[uint32]d2common.Surface
imageCacheRecords map[uint32]d2render.Surface
seed int64
currentFrame int
lastFrameTime float64
@ -41,7 +41,7 @@ func loadRegion(seed int64, tileOffsetX, tileOffsetY int, levelType d2enum.Regio
region := &MapRegion{
levelType: d2datadict.LevelTypes[levelType],
levelPreset: d2datadict.LevelPresets[levelPreset],
imageCacheRecords: map[uint32]d2common.Surface{},
imageCacheRecords: map[uint32]d2render.Surface{},
seed: seed,
}
@ -228,7 +228,7 @@ func (mr *MapRegion) getTileWorldPosition(tileX, tileY int) (float64, float64) {
return float64(tileX + mr.tileRect.Left), float64(tileY + mr.tileRect.Top)
}
func (mr *MapRegion) renderPass1(viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderPass1(viewport *Viewport, target d2render.Surface) {
for tileY := range mr.ds1.Tiles {
for tileX, tile := range mr.ds1.Tiles[tileY] {
worldX, worldY := mr.getTileWorldPosition(tileX, tileY)
@ -241,7 +241,7 @@ func (mr *MapRegion) renderPass1(viewport *Viewport, target d2common.Surface) {
}
}
func (mr *MapRegion) renderPass2(entities []MapEntity, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderPass2(entities []MapEntity, viewport *Viewport, target d2render.Surface) {
for tileY := range mr.ds1.Tiles {
for tileX, tile := range mr.ds1.Tiles[tileY] {
worldX, worldY := mr.getTileWorldPosition(tileX, tileY)
@ -264,7 +264,7 @@ func (mr *MapRegion) renderPass2(entities []MapEntity, viewport *Viewport, targe
}
}
func (mr *MapRegion) renderPass3(viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderPass3(viewport *Viewport, target d2render.Surface) {
for tileY := range mr.ds1.Tiles {
for tileX, tile := range mr.ds1.Tiles[tileY] {
worldX, worldY := mr.getTileWorldPosition(tileX, tileY)
@ -277,7 +277,7 @@ func (mr *MapRegion) renderPass3(viewport *Viewport, target d2common.Surface) {
}
}
func (mr *MapRegion) renderTilePass1(tile d2ds1.TileRecord, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderTilePass1(tile d2ds1.TileRecord, viewport *Viewport, target d2render.Surface) {
for _, wall := range tile.Walls {
if !wall.Hidden && wall.Prop1 != 0 && wall.Type.LowerWall() {
mr.renderWall(wall, viewport, target)
@ -297,7 +297,7 @@ func (mr *MapRegion) renderTilePass1(tile d2ds1.TileRecord, viewport *Viewport,
}
}
func (mr *MapRegion) renderTilePass2(tile d2ds1.TileRecord, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderTilePass2(tile d2ds1.TileRecord, viewport *Viewport, target d2render.Surface) {
for _, wall := range tile.Walls {
if !wall.Hidden && wall.Type.UpperWall() {
mr.renderWall(wall, viewport, target)
@ -305,7 +305,7 @@ func (mr *MapRegion) renderTilePass2(tile d2ds1.TileRecord, viewport *Viewport,
}
}
func (mr *MapRegion) renderTilePass3(tile d2ds1.TileRecord, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderTilePass3(tile d2ds1.TileRecord, viewport *Viewport, target d2render.Surface) {
for _, wall := range tile.Walls {
if wall.Type == d2enum.Roof {
mr.renderWall(wall, viewport, target)
@ -313,8 +313,8 @@ func (mr *MapRegion) renderTilePass3(tile d2ds1.TileRecord, viewport *Viewport,
}
}
func (mr *MapRegion) renderFloor(tile d2ds1.FloorShadowRecord, viewport *Viewport, target d2common.Surface) {
var img d2common.Surface
func (mr *MapRegion) renderFloor(tile d2ds1.FloorShadowRecord, viewport *Viewport, target d2render.Surface) {
var img d2render.Surface
if !tile.Animated {
img = mr.getImageCacheRecord(tile.Style, tile.Sequence, 0, tile.RandomIndex)
} else {
@ -334,7 +334,7 @@ func (mr *MapRegion) renderFloor(tile d2ds1.FloorShadowRecord, viewport *Viewpor
target.Render(img)
}
func (mr *MapRegion) renderWall(tile d2ds1.WallRecord, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderWall(tile d2ds1.WallRecord, viewport *Viewport, target d2render.Surface) {
img := mr.getImageCacheRecord(tile.Style, tile.Sequence, tile.Type, tile.RandomIndex)
if img == nil {
log.Printf("Render called on uncached wall {%v,%v,%v}", tile.Style, tile.Sequence, tile.Type)
@ -350,7 +350,7 @@ func (mr *MapRegion) renderWall(tile d2ds1.WallRecord, viewport *Viewport, targe
target.Render(img)
}
func (mr *MapRegion) renderShadow(tile d2ds1.FloorShadowRecord, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderShadow(tile d2ds1.FloorShadowRecord, viewport *Viewport, target d2render.Surface) {
img := mr.getImageCacheRecord(tile.Style, tile.Sequence, 13, tile.RandomIndex)
if img == nil {
log.Printf("Render called on uncached shadow {%v,%v}", tile.Style, tile.Sequence)
@ -367,7 +367,7 @@ func (mr *MapRegion) renderShadow(tile d2ds1.FloorShadowRecord, viewport *Viewpo
target.Render(img)
}
func (mr *MapRegion) renderDebug(debugVisLevel int, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderDebug(debugVisLevel int, viewport *Viewport, target d2render.Surface) {
for tileY := range mr.ds1.Tiles {
for tileX := range mr.ds1.Tiles[tileY] {
worldX, worldY := mr.getTileWorldPosition(tileX, tileY)
@ -378,7 +378,7 @@ func (mr *MapRegion) renderDebug(debugVisLevel int, viewport *Viewport, target d
}
}
func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *Viewport, target d2common.Surface) {
func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *Viewport, target d2render.Surface) {
if debugVisLevel > 0 {
subtileColor := color.RGBA{80, 80, 255, 100}
tileColor := color.RGBA{255, 255, 255, 255}
@ -446,12 +446,12 @@ func (mr *MapRegion) generateTileCache() {
}
}
func (mr *MapRegion) getImageCacheRecord(style, sequence byte, tileType d2enum.TileType, randomIndex byte) d2common.Surface {
func (mr *MapRegion) getImageCacheRecord(style, sequence byte, tileType d2enum.TileType, randomIndex byte) d2render.Surface {
lookupIndex := uint32(style)<<24 | uint32(sequence)<<16 | uint32(tileType)<<8 | uint32(randomIndex)
return mr.imageCacheRecords[lookupIndex]
}
func (mr *MapRegion) setImageCacheRecord(style, sequence byte, tileType d2enum.TileType, randomIndex byte, image d2common.Surface) {
func (mr *MapRegion) setImageCacheRecord(style, sequence byte, tileType d2enum.TileType, randomIndex byte, image d2render.Surface) {
lookupIndex := uint32(style)<<24 | uint32(sequence)<<16 | uint32(tileType)<<8 | uint32(randomIndex)
mr.imageCacheRecords[lookupIndex] = image
}
@ -494,7 +494,7 @@ func (mr *MapRegion) generateFloorCache(tile *d2ds1.FloorShadowRecord, tileX, ti
}
tileYOffset := d2helper.AbsInt32(tileYMinimum)
tileHeight := d2helper.AbsInt32(tileData[i].Height)
_, image := d2render.NewSurface(int(tileData[i].Width), int(tileHeight), d2common.FilterNearest)
_, image := d2render.NewSurface(int(tileData[i].Width), int(tileHeight), d2render.FilterNearest)
pixels := make([]byte, 4*tileData[i].Width*tileHeight)
mr.decodeTileGfxData(tileData[i].Blocks, &pixels, tileYOffset, tileData[i].Width)
image.ReplacePixels(pixels)
@ -529,7 +529,7 @@ func (mr *MapRegion) generateShadowCache(tile *d2ds1.FloorShadowRecord, tileX, t
return
}
_, image := d2render.NewSurface(int(tileData.Width), int(tileHeight), d2common.FilterNearest)
_, image := d2render.NewSurface(int(tileData.Width), int(tileHeight), d2render.FilterNearest)
pixels := make([]byte, 4*tileData.Width*int32(tileHeight))
mr.decodeTileGfxData(tileData.Blocks, &pixels, tileYOffset, tileData.Width)
image.ReplacePixels(pixels)
@ -590,7 +590,7 @@ func (mr *MapRegion) generateWallCache(tile *d2ds1.WallRecord, tileX, tileY int)
return
}
_, image := d2render.NewSurface(160, int(realHeight), d2common.FilterNearest)
_, image := d2render.NewSurface(160, int(realHeight), d2render.FilterNearest)
pixels := make([]byte, 4*160*realHeight)
mr.decodeTileGfxData(tileData.Blocks, &pixels, tileYOffset, 160)

View File

@ -1,4 +1,4 @@
package d2common
package d2render
type CompositeMode int

View File

@ -4,10 +4,6 @@ import (
"errors"
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
)
@ -17,9 +13,9 @@ var (
ErrInvalidRenderer error = errors.New("invalid rendering system specified")
)
var singleton d2interface.Renderer
var singleton Renderer
func Initialize(rend d2interface.Renderer) error {
func Initialize(rend Renderer) error {
if singleton != nil {
return d2input.ErrHasInit
}
@ -36,7 +32,7 @@ func SetWindowIcon(fileName string) error {
return nil
}
func Run(f func(d2common.Surface) error, width, height int, title string) error {
func Run(f func(Surface) error, width, height int, title string) error {
if singleton == nil {
return ErrNotInit
}
@ -51,14 +47,14 @@ func IsDrawingSkipped() (error, bool) {
return nil, singleton.IsDrawingSkipped()
}
func CreateSurface(surface d2common.Surface) (error, d2common.Surface) {
func CreateSurface(surface Surface) (error, Surface) {
if singleton == nil {
return ErrNotInit, nil
}
return singleton.CreateSurface(surface)
}
func NewSurface(width, height int, filter d2common.Filter) (error, d2common.Surface) {
func NewSurface(width, height int, filter Filter) (error, Surface) {
if singleton == nil {
return ErrNotInit, nil
}

View File

@ -1,72 +1,72 @@
package ebiten
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten"
)
func d2ToEbitenCompositeMode(comp d2common.CompositeMode) ebiten.CompositeMode {
func d2ToEbitenCompositeMode(comp d2render.CompositeMode) ebiten.CompositeMode {
switch comp {
case d2common.CompositeModeSourceOver:
case d2render.CompositeModeSourceOver:
return ebiten.CompositeModeSourceOver
case d2common.CompositeModeClear:
case d2render.CompositeModeClear:
return ebiten.CompositeModeClear
case d2common.CompositeModeCopy:
case d2render.CompositeModeCopy:
return ebiten.CompositeModeCopy
case d2common.CompositeModeDestination:
case d2render.CompositeModeDestination:
return ebiten.CompositeModeDestination
case d2common.CompositeModeDestinationOver:
case d2render.CompositeModeDestinationOver:
return ebiten.CompositeModeDestinationOver
case d2common.CompositeModeSourceIn:
case d2render.CompositeModeSourceIn:
return ebiten.CompositeModeSourceIn
case d2common.CompositeModeDestinationIn:
case d2render.CompositeModeDestinationIn:
return ebiten.CompositeModeDestinationIn
case d2common.CompositeModeSourceOut:
case d2render.CompositeModeSourceOut:
return ebiten.CompositeModeSourceOut
case d2common.CompositeModeDestinationOut:
case d2render.CompositeModeDestinationOut:
return ebiten.CompositeModeDestinationOut
case d2common.CompositeModeSourceAtop:
case d2render.CompositeModeSourceAtop:
return ebiten.CompositeModeSourceAtop
case d2common.CompositeModeDestinationAtop:
case d2render.CompositeModeDestinationAtop:
return ebiten.CompositeModeDestinationAtop
case d2common.CompositeModeXor:
case d2render.CompositeModeXor:
return ebiten.CompositeModeXor
case d2common.CompositeModeLighter:
case d2render.CompositeModeLighter:
return ebiten.CompositeModeLighter
}
return ebiten.CompositeModeSourceOver
}
func ebitenToD2CompositeMode(comp ebiten.CompositeMode) d2common.CompositeMode {
func ebitenToD2CompositeMode(comp ebiten.CompositeMode) d2render.CompositeMode {
switch comp {
case ebiten.CompositeModeSourceOver:
return d2common.CompositeModeSourceOver
return d2render.CompositeModeSourceOver
case ebiten.CompositeModeClear:
return d2common.CompositeModeClear
return d2render.CompositeModeClear
case ebiten.CompositeModeCopy:
return d2common.CompositeModeCopy
return d2render.CompositeModeCopy
case ebiten.CompositeModeDestination:
return d2common.CompositeModeDestination
return d2render.CompositeModeDestination
case ebiten.CompositeModeDestinationOver:
return d2common.CompositeModeDestinationOver
return d2render.CompositeModeDestinationOver
case ebiten.CompositeModeSourceIn:
return d2common.CompositeModeSourceIn
return d2render.CompositeModeSourceIn
case ebiten.CompositeModeDestinationIn:
return d2common.CompositeModeDestinationIn
return d2render.CompositeModeDestinationIn
case ebiten.CompositeModeSourceOut:
return d2common.CompositeModeSourceOut
return d2render.CompositeModeSourceOut
case ebiten.CompositeModeDestinationOut:
return d2common.CompositeModeDestinationOut
return d2render.CompositeModeDestinationOut
case ebiten.CompositeModeSourceAtop:
return d2common.CompositeModeSourceAtop
return d2render.CompositeModeSourceAtop
case ebiten.CompositeModeDestinationAtop:
return d2common.CompositeModeDestinationAtop
return d2render.CompositeModeDestinationAtop
case ebiten.CompositeModeXor:
return d2common.CompositeModeXor
return d2render.CompositeModeXor
case ebiten.CompositeModeLighter:
return d2common.CompositeModeLighter
return d2render.CompositeModeLighter
}
return d2common.CompositeModeSourceOver
return d2render.CompositeModeSourceOver
}

View File

@ -4,7 +4,7 @@ import (
"image"
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2config"
@ -49,7 +49,7 @@ func (r *EbitenRenderer) IsDrawingSkipped() bool {
return ebiten.IsDrawingSkipped()
}
func (r *EbitenRenderer) Run(f func(surface d2common.Surface) error, width, height int, title string) error {
func (r *EbitenRenderer) Run(f func(surface d2render.Surface) error, width, height int, title string) error {
config, err := d2config.Get()
if err != nil {
log.Fatal(err)
@ -65,7 +65,7 @@ func (r *EbitenRenderer) Run(f func(surface d2common.Surface) error, width, heig
}, width, height, config.Scale, title)
}
func (r *EbitenRenderer) CreateSurface(surface d2common.Surface) (error, d2common.Surface) {
func (r *EbitenRenderer) CreateSurface(surface d2render.Surface) (error, d2render.Surface) {
result := &ebitenSurface{
image: surface.(*ebitenSurface).image,
stateCurrent: surfaceState{
@ -76,7 +76,7 @@ func (r *EbitenRenderer) CreateSurface(surface d2common.Surface) (error, d2commo
return nil, result
}
func (r *EbitenRenderer) NewSurface(width, height int, filter d2common.Filter) (error, d2common.Surface) {
func (r *EbitenRenderer) NewSurface(width, height int, filter d2render.Filter) (error, d2render.Surface) {
ebitenFilter := d2ToEbitenFilter(filter)
img, err := ebiten.NewImage(width, height, ebitenFilter)
if err != nil {

View File

@ -4,7 +4,7 @@ import (
"fmt"
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
@ -22,12 +22,12 @@ func (s *ebitenSurface) PushTranslation(x, y int) {
s.stateCurrent.y += y
}
func (s *ebitenSurface) PushCompositeMode(mode d2common.CompositeMode) {
func (s *ebitenSurface) PushCompositeMode(mode d2render.CompositeMode) {
s.stateStack = append(s.stateStack, s.stateCurrent)
s.stateCurrent.mode = d2ToEbitenCompositeMode(mode)
}
func (s *ebitenSurface) PushFilter(filter d2common.Filter) {
func (s *ebitenSurface) PushFilter(filter d2render.Filter) {
s.stateStack = append(s.stateStack, s.stateCurrent)
s.stateCurrent.filter = d2ToEbitenFilter(filter)
}
@ -53,7 +53,7 @@ func (s *ebitenSurface) PopN(n int) {
}
}
func (s *ebitenSurface) Render(sfc d2common.Surface) error {
func (s *ebitenSurface) Render(sfc d2render.Surface) error {
opts := &ebiten.DrawImageOptions{CompositeMode: s.stateCurrent.mode}
opts.GeoM.Translate(float64(s.stateCurrent.x), float64(s.stateCurrent.y))
opts.Filter = s.stateCurrent.filter

View File

@ -1,32 +1,32 @@
package ebiten
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten"
)
func d2ToEbitenFilter(filter d2common.Filter) ebiten.Filter {
func d2ToEbitenFilter(filter d2render.Filter) ebiten.Filter {
switch filter {
case d2common.FilterDefault:
case d2render.FilterDefault:
return ebiten.FilterDefault
case d2common.FilterLinear:
case d2render.FilterLinear:
return ebiten.FilterLinear
case d2common.FilterNearest:
case d2render.FilterNearest:
return ebiten.FilterNearest
}
return ebiten.FilterDefault
}
func ebitenToD2Filter(filter ebiten.Filter) d2common.Filter {
func ebitenToD2Filter(filter ebiten.Filter) d2render.Filter {
switch filter {
case ebiten.FilterDefault:
return d2common.FilterDefault
return d2render.FilterDefault
case ebiten.FilterLinear:
return d2common.FilterLinear
return d2render.FilterLinear
case ebiten.FilterNearest:
return d2common.FilterNearest
return d2render.FilterNearest
}
return d2common.FilterDefault
return d2render.FilterDefault
}

View File

@ -1,4 +1,4 @@
package d2common
package d2render
// Filter represents the type of texture filter to be used when an image is maginified or minified.
type Filter int

View File

@ -1,16 +1,12 @@
package d2interface
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
package d2render
type Renderer interface {
GetRendererName() string
SetWindowIcon(fileName string)
Run(f func(d2common.Surface) error, width, height int, title string) error
Run(f func(Surface) error, width, height int, title string) error
IsDrawingSkipped() bool
CreateSurface(surface d2common.Surface) (error, d2common.Surface)
NewSurface(width, height int, filter d2common.Filter) (error, d2common.Surface)
CreateSurface(surface Surface) (error, Surface)
NewSurface(width, height int, filter Filter) (error, Surface)
IsFullScreen() (bool, error)
SetFullScreen(fullScreen bool) error
SetVSyncEnabled(vsync bool) error

View File

@ -1,4 +1,4 @@
package d2common
package d2render
import (
"image/color"

View File

@ -4,16 +4,15 @@ import (
"math"
"runtime"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
// Scene defines the function necessary for scene management
type Scene interface {
Load() []func()
Unload()
Render(target d2common.Surface)
Render(target d2render.Surface)
Advance(tickTime float64)
}
@ -71,7 +70,7 @@ func Advance(time float64) {
currentScene.Advance(time)
}
func Render(surface d2common.Surface) {
func Render(surface d2render.Surface) {
if currentScene == nil {
return
}

View File

@ -4,9 +4,8 @@ import (
"errors"
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
var (
@ -102,7 +101,7 @@ func UnbindAction(name string) error {
return singleton.unbindAction(name)
}
func Render(surface d2common.Surface) error {
func Render(surface d2render.Surface) error {
if singleton == nil {
return ErrNotInit
}

View File

@ -13,10 +13,9 @@ import (
"strconv"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
const (
@ -241,7 +240,7 @@ func (t *terminal) OnKeyChars(event d2input.KeyCharsEvent) bool {
return handled
}
func (t *terminal) render(surface d2common.Surface) error {
func (t *terminal) render(surface d2render.Surface) error {
if !t.isVisible() {
return nil
}

View File

@ -6,8 +6,6 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
@ -94,11 +92,11 @@ type Button struct {
visible bool
pressed bool
toggled bool
normalSurface d2common.Surface
pressedSurface d2common.Surface
toggledSurface d2common.Surface
pressedToggledSurface d2common.Surface
disabledSurface d2common.Surface
normalSurface d2render.Surface
pressedSurface d2render.Surface
toggledSurface d2render.Surface
pressedToggledSurface d2render.Surface
disabledSurface d2render.Surface
buttonLayout ButtonLayout
onClick func()
}
@ -128,7 +126,7 @@ func CreateButton(buttonType ButtonType, text string) Button {
result.height += h
}
_, result.normalSurface = d2render.NewSurface(int(result.width), int(result.height), d2common.FilterNearest)
_, result.normalSurface = d2render.NewSurface(int(result.width), int(result.height), d2render.FilterNearest)
_, fontHeight := font.GetTextMetrics(text)
textY := int((result.height/2)-(int(fontHeight)/2)) + buttonLayout.TextOffset
@ -138,22 +136,22 @@ func CreateButton(buttonType ButtonType, text string) Button {
font.Render(0, textY, text, color.RGBA{100, 100, 100, 255}, result.normalSurface)
if buttonLayout.AllowFrameChange {
if totalButtonTypes > 1 {
_, result.pressedSurface = d2render.NewSurface(int(result.width), int(result.height), d2common.FilterNearest)
_, result.pressedSurface = d2render.NewSurface(int(result.width), int(result.height), d2render.FilterNearest)
buttonSprite.RenderSegmented(result.pressedSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+1)
font.Render(-2, textY+2, text, color.RGBA{100, 100, 100, 255}, result.pressedSurface)
}
if totalButtonTypes > 2 {
_, result.toggledSurface = d2render.NewSurface(int(result.width), int(result.height), d2common.FilterNearest)
_, result.toggledSurface = d2render.NewSurface(int(result.width), int(result.height), d2render.FilterNearest)
buttonSprite.RenderSegmented(result.toggledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+2)
font.Render(0, textY, text, color.RGBA{100, 100, 100, 255}, result.toggledSurface)
}
if totalButtonTypes > 3 {
_, result.pressedToggledSurface = d2render.NewSurface(int(result.width), int(result.height), d2common.FilterNearest)
_, result.pressedToggledSurface = d2render.NewSurface(int(result.width), int(result.height), d2render.FilterNearest)
buttonSprite.RenderSegmented(result.pressedToggledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+3)
font.Render(0, textY, text, color.RGBA{100, 100, 100, 255}, result.pressedToggledSurface)
}
if buttonLayout.DisabledFrame != -1 {
_, result.disabledSurface = d2render.NewSurface(int(result.width), int(result.height), d2common.FilterNearest)
_, result.disabledSurface = d2render.NewSurface(int(result.width), int(result.height), d2render.FilterNearest)
buttonSprite.RenderSegmented(result.disabledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.DisabledFrame)
font.Render(0, textY, text, color.RGBA{100, 100, 100, 255}, result.disabledSurface)
}
@ -175,9 +173,9 @@ func (v *Button) Activate() {
}
// Render renders the button
func (v *Button) Render(target d2common.Surface) {
target.PushCompositeMode(d2common.CompositeModeSourceAtop)
target.PushFilter(d2common.FilterNearest)
func (v *Button) Render(target d2render.Surface) {
target.PushCompositeMode(d2render.CompositeModeSourceAtop)
target.PushFilter(d2render.FilterNearest)
target.PushTranslation(v.x, v.y)
defer target.PopN(3)

View File

@ -1,7 +1,6 @@
package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
@ -12,8 +11,8 @@ type Checkbox struct {
checkState bool
visible bool
width, height int
Image d2common.Surface
checkedImage d2common.Surface
Image d2render.Surface
checkedImage d2render.Surface
onClick func()
enabled bool
}
@ -32,18 +31,18 @@ func CreateCheckbox(checkState bool) Checkbox {
result.width, result.height, _ = checkboxSprite.GetFrameSize(0)
checkboxSprite.SetPosition(0, 0)
_, result.Image = d2render.NewSurface(int(result.width), int(result.height), d2common.FilterNearest)
_, result.Image = d2render.NewSurface(int(result.width), int(result.height), d2render.FilterNearest)
checkboxSprite.RenderSegmented(result.Image, 1, 1, 0)
_, result.checkedImage = d2render.NewSurface(int(result.width), int(result.height), d2common.FilterNearest)
_, result.checkedImage = d2render.NewSurface(int(result.width), int(result.height), d2render.FilterNearest)
checkboxSprite.RenderSegmented(result.checkedImage, 1, 1, 1)
return result
}
func (v *Checkbox) Render(target d2common.Surface) {
target.PushCompositeMode(d2common.CompositeModeSourceAtop)
func (v *Checkbox) Render(target d2render.Surface) {
target.PushCompositeMode(d2render.CompositeModeSourceAtop)
target.PushTranslation(v.x, v.y)
target.PushFilter(d2common.FilterNearest)
target.PushFilter(d2render.FilterNearest)
defer target.PopN(3)
if v.checkState {

View File

@ -1,10 +1,9 @@
package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten"
)
@ -24,7 +23,7 @@ var cursorButtons CursorButton
var pressedIndex int
var CursorX int
var CursorY int
var clickSfx d2interface.SoundEffect
var clickSfx d2audio.SoundEffect
var waitForLeftMouseUp bool
func Initialize(curSprite *Sprite) {
@ -51,7 +50,7 @@ func WaitForMouseRelease() {
}
// Render renders all of the UI elements
func Render(target d2common.Surface) {
func Render(target d2render.Surface) {
for _, widget := range widgets {
if widget.GetVisible() {
widget.Render(target)

View File

@ -1,12 +1,10 @@
package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
)
import "github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
// Drawable represents an instance that can be drawn
type Drawable interface {
Render(target d2common.Surface)
Render(target d2render.Surface)
Advance(elapsed float64)
GetSize() (width, height int)
SetPosition(x, y int)

View File

@ -5,8 +5,7 @@ import (
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
@ -106,7 +105,7 @@ func (v *Font) GetTextMetrics(text string) (width, height int) {
}
// Render draws the font on the target surface
func (v *Font) Render(x, y int, text string, color color.Color, target d2common.Surface) {
func (v *Font) Render(x, y int, text string, color color.Color, target d2render.Surface) {
v.fontSprite.SetColorMod(color)
v.fontSprite.SetBlend(false)

View File

@ -3,8 +3,6 @@ package d2ui
import (
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
@ -29,7 +27,7 @@ type Label struct {
Height int
Alignment LabelAlignment
font *Font
imageData d2common.Surface
imageData d2render.Surface
Color color.Color
}
@ -44,7 +42,7 @@ func CreateLabel(fontPath, palettePath string) Label {
}
// Render draws the label on the screen
func (v *Label) Render(target d2common.Surface) {
func (v *Label) Render(target d2render.Surface) {
if len(v.text) == 0 {
return
}
@ -57,8 +55,8 @@ func (v *Label) Render(target d2common.Surface) {
x, y = v.X-int(v.Width), v.Y
}
target.PushFilter(d2common.FilterNearest)
target.PushCompositeMode(d2common.CompositeModeSourceAtop)
target.PushFilter(d2render.FilterNearest)
target.PushCompositeMode(d2render.CompositeModeSourceAtop)
target.PushTranslation(x, y)
defer target.PopN(3)
@ -82,7 +80,7 @@ func (v *Label) cacheImage() {
width, height := v.font.GetTextMetrics(v.text)
v.Width = width
v.Height = height
_, v.imageData = d2render.NewSurface(int(width), int(height), d2common.FilterNearest)
_, v.imageData = d2render.NewSurface(int(width), int(height), d2render.FilterNearest)
_, surface := d2render.CreateSurface(v.imageData)
v.font.Render(0, 0, v.text, v.Color, surface)
}

View File

@ -1,9 +1,9 @@
package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten"
)
@ -74,7 +74,7 @@ func (v *Scrollbar) GetLastDirChange() int {
return v.lastDirChange
}
func (v *Scrollbar) Render(target d2common.Surface) {
func (v *Scrollbar) Render(target d2render.Surface) {
if !v.visible || v.maxOffset == 0 {
return
}

View File

@ -4,8 +4,8 @@ import (
"errors"
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2helper"
)
@ -27,7 +27,7 @@ func LoadSprite(animation *d2asset.Animation) (*Sprite, error) {
return &Sprite{animation: animation}, nil
}
func (s *Sprite) Render(target d2common.Surface) error {
func (s *Sprite) Render(target d2render.Surface) error {
_, frameHeight := s.animation.GetCurrentFrameSize()
target.PushTranslation(s.x, s.y-frameHeight)
@ -35,7 +35,7 @@ func (s *Sprite) Render(target d2common.Surface) error {
return s.animation.Render(target)
}
func (s *Sprite) RenderSegmented(target d2common.Surface, segmentsX, segmentsY, frameOffset int) error {
func (s *Sprite) RenderSegmented(target d2render.Surface, segmentsX, segmentsY, frameOffset int) error {
var currentY int
for y := 0; y < segmentsY; y++ {
var currentX int

View File

@ -5,8 +5,7 @@ import (
"time"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/hajimehoshi/ebiten/inpututil"
@ -55,7 +54,7 @@ func repeatingKeyPressed(key ebiten.Key) bool {
return false
}
func (v *TextBox) Render(target d2common.Surface) {
func (v *TextBox) Render(target d2render.Surface) {
if !v.visible {
return
}

View File

@ -5,8 +5,6 @@ import (
"runtime"
"strconv"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
@ -96,7 +94,7 @@ func Advance() {
}
// Draw draws the game
func render(target d2common.Surface) {
func render(target d2render.Surface) {
if d2scene.GetLoadingProgress() < 1.0 {
loadingSprite.SetCurrentFrame(int(d2helper.Max(0,
d2helper.Min(uint32(loadingSprite.GetFrameCount()-1),
@ -137,7 +135,7 @@ func render(target d2common.Surface) {
d2term.Render(target)
}
func update(screen d2common.Surface) error {
func update(screen d2render.Surface) error {
Advance()
err, drawingSkipped := d2render.IsDrawingSkipped()
if err != nil {

View File

@ -10,6 +10,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
@ -195,7 +196,7 @@ func (v *CharacterSelect) onExitButtonClicked() {
func (v *CharacterSelect) Unload() {
}
func (v *CharacterSelect) Render(screen d2common.Surface) {
func (v *CharacterSelect) Render(screen d2render.Surface) {
v.background.RenderSegmented(screen, 4, 3, 0)
v.d2HeroTitle.Render(screen)
actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2)

View File

@ -9,6 +9,7 @@ import (
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
@ -100,7 +101,7 @@ func (v *Credits) Unload() {
}
// Render renders the credits scene
func (v *Credits) Render(screen d2common.Surface) {
func (v *Credits) Render(screen d2render.Surface) {
v.creditsBackground.RenderSegmented(screen, 4, 3, 0)
for _, label := range v.labels {
if label.Available {

View File

@ -3,7 +3,6 @@ package d2gamescene
import (
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
@ -11,6 +10,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2player"
@ -83,7 +83,7 @@ func (v *Game) Unload() {
d2input.UnbindHandler(v.gameControls)
}
func (v Game) Render(screen d2common.Surface) {
func (v Game) Render(screen d2render.Surface) {
screen.Clear(color.Black)
v.mapEngine.Render(screen)
v.gameControls.Render(screen)

View File

@ -9,6 +9,7 @@ import (
"runtime"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
@ -222,7 +223,7 @@ func (v *MainMenu) Unload() {
}
// Render renders the main menu
func (v *MainMenu) Render(screen d2common.Surface) {
func (v *MainMenu) Render(screen d2render.Surface) {
if v.ShowTrademarkScreen {
v.trademarkBackground.RenderSegmented(screen, 4, 3, 0)
} else {

View File

@ -6,8 +6,6 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio"
@ -156,7 +154,7 @@ func (v *MapEngineTest) Unload() {
d2input.UnbindHandler(v)
}
func (v *MapEngineTest) Render(screen d2common.Surface) {
func (v *MapEngineTest) Render(screen d2render.Surface) {
v.mapEngine.Render(screen)
screenX, screenY, _ := d2render.GetCursorPos()

View File

@ -4,9 +4,8 @@ import (
"image"
"image/color"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gamestate"
@ -34,8 +33,8 @@ type HeroRenderInfo struct {
BackWalkSprite *d2ui.Sprite
BackWalkSpriteOverlay *d2ui.Sprite
SelectionBounds image.Rectangle
SelectSfx d2interface.SoundEffect
DeselectSfx d2interface.SoundEffect
SelectSfx d2audio.SoundEffect
DeselectSfx d2audio.SoundEffect
}
func (hri *HeroRenderInfo) Advance(elapsed float64) {
@ -452,7 +451,7 @@ func (v SelectHeroClass) onOkButtonClicked() {
d2scene.SetNextScene(CreateGame(gameState))
}
func (v *SelectHeroClass) Render(screen d2common.Surface) {
func (v *SelectHeroClass) Render(screen d2render.Surface) {
v.bgImage.RenderSegmented(screen, 4, 3, 0)
v.headingLabel.Render(screen)
if v.selectedHero != d2enum.HeroNone {
@ -569,7 +568,7 @@ func (v *SelectHeroClass) updateHeroSelectionHover(hero d2enum.Hero, canSelect b
}
func (v *SelectHeroClass) renderHero(screen d2common.Surface, hero d2enum.Hero) {
func (v *SelectHeroClass) renderHero(screen d2render.Surface, hero d2enum.Hero) {
renderInfo := v.heroRenderInfo[hero]
switch renderInfo.Stance {
case d2enum.HeroStanceIdle:
@ -656,7 +655,7 @@ func setSpriteToFirstFrame(sprite *d2ui.Sprite) {
}
}
func drawSprite(sprite *d2ui.Sprite, target d2common.Surface) {
func drawSprite(sprite *d2ui.Sprite, target d2render.Surface) {
if sprite != nil {
sprite.Render(target)
}
@ -674,7 +673,7 @@ func loadSprite(animationPath, palettePath string) *d2ui.Sprite {
return sprite
}
func loadSoundEffect(sfx string) d2interface.SoundEffect {
func loadSoundEffect(sfx string) d2audio.SoundEffect {
result, _ := d2audio.LoadSoundEffect(sfx)
return result
}

View File

@ -1,11 +1,11 @@
package d2player
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
@ -72,7 +72,7 @@ func (g *GameControls) Load() {
}
// TODO: consider caching the panels to single image that is reused.
func (g *GameControls) Render(target d2common.Surface) {
func (g *GameControls) Render(target d2render.Surface) {
g.inventory.Render(target)
width, height := target.GetSize()

View File

@ -1,10 +1,10 @@
package d2player
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
@ -60,7 +60,7 @@ func (g *Inventory) Load() {
g.grid.Add(items...)
}
func (g *Inventory) Render(target d2common.Surface) {
func (g *Inventory) Render(target d2render.Surface) {
if !g.isOpen {
return
}

View File

@ -6,10 +6,9 @@ import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
)
@ -184,7 +183,7 @@ func (g *ItemGrid) Remove(item InventoryItem) {
g.items = g.items[:n]
}
func (g *ItemGrid) Render(target d2common.Surface) {
func (g *ItemGrid) Render(target d2render.Surface) {
for _, item := range g.items {
if item == nil {
continue