Skip to content

Commit

Permalink
Move rendering stuff out of d2common into d2render (OpenDiablo2#281)
Browse files Browse the repository at this point in the history
* Move rendering stuff out of d2common into d2render

* Remove d2interface
  • Loading branch information
FooSoft authored Feb 2, 2020
1 parent 4cbb755 commit b5c1f52
Show file tree
Hide file tree
Showing 43 changed files with 184 additions and 214 deletions.
7 changes: 0 additions & 7 deletions d2common/d2interface/audio_provider.go

This file was deleted.

6 changes: 0 additions & 6 deletions d2common/d2interface/sound_effect.go

This file was deleted.

15 changes: 7 additions & 8 deletions d2core/d2asset/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,7 +27,7 @@ type animationFrame struct {
offsetX int
offsetY int

image d2common.Surface
image d2render.Surface
}

type animationDirection struct {
Expand All @@ -42,7 +41,7 @@ type Animation struct {
lastFrameTime float64
playedCount int

compositeMode d2common.CompositeMode
compositeMode d2render.CompositeMode
colorMod color.Color

playMode playMode
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions d2core/d2asset/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 14 additions & 5 deletions d2core/d2audio/d2audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions d2core/d2audio/ebiten/ebiten_audio_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package d2interface
package d2inventory

import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"

Expand Down
4 changes: 2 additions & 2 deletions d2core/d2map/animated_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 3 additions & 4 deletions d2core/d2map/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ 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"

"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
)

type MapEntity interface {
Render(target d2common.Surface)
Render(target d2render.Surface)
Advance(tickTime float64)
GetPosition() (float64, float64)
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions d2core/d2map/hero.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion d2core/d2map/npc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
Loading

0 comments on commit b5c1f52

Please sign in to comment.