From b5c1f5222d308f35c76046bab6c2efc3f8412466 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 1 Feb 2020 17:39:28 -0800 Subject: [PATCH] Move rendering stuff out of d2common into d2render (#281) * Move rendering stuff out of d2common into d2render * Remove d2interface --- d2common/d2interface/audio_provider.go | 7 --- d2common/d2interface/sound_effect.go | 6 -- d2core/d2asset/animation.go | 15 +++-- d2core/d2asset/composite.go | 4 +- d2core/d2audio/d2audio.go | 19 ++++-- .../d2audio/ebiten/ebiten_audio_provider.go | 5 +- .../d2inventory}/inventory_item.go | 2 +- d2core/d2map/animated_entity.go | 4 +- d2core/d2map/engine.go | 7 +-- d2core/d2map/hero.go | 4 +- d2core/d2map/npc.go | 3 +- d2core/d2map/region.go | 38 ++++++------ .../d2render}/composite_mode.go | 2 +- d2core/d2render/d2render.go | 14 ++--- .../d2render/ebiten/composite_mode_helper.go | 60 +++++++++---------- d2core/d2render/ebiten/ebiten_renderer.go | 8 +-- d2core/d2render/ebiten/ebiten_surface.go | 8 +-- d2core/d2render/ebiten/filter_helper.go | 20 +++---- {d2common => d2core/d2render}/filter.go | 2 +- .../d2render}/renderer.go | 12 ++-- {d2common => d2core/d2render}/surface.go | 2 +- d2core/d2scene/d2scene.go | 7 +-- d2core/d2term/d2term.go | 5 +- d2core/d2term/terminal.go | 5 +- d2core/d2ui/button.go | 28 ++++----- d2core/d2ui/checkbox.go | 15 +++-- d2core/d2ui/d2ui.go | 7 +-- d2core/d2ui/drawable.go | 6 +- d2core/d2ui/font.go | 5 +- d2core/d2ui/label.go | 12 ++-- d2core/d2ui/scrollbar.go | 4 +- d2core/d2ui/sprite.go | 6 +- d2core/d2ui/textbox.go | 5 +- d2game/d2game.go | 6 +- d2game/d2gamescene/character_select.go | 3 +- d2game/d2gamescene/credits.go | 3 +- d2game/d2gamescene/game.go | 4 +- d2game/d2gamescene/main_menu.go | 3 +- d2game/d2gamescene/map_engine_testing.go | 4 +- d2game/d2gamescene/select_hero_class.go | 15 +++-- d2game/d2player/game_controls.go | 4 +- d2game/d2player/inventory.go | 4 +- d2game/d2player/inventory_grid.go | 5 +- 43 files changed, 184 insertions(+), 214 deletions(-) delete mode 100644 d2common/d2interface/audio_provider.go delete mode 100644 d2common/d2interface/sound_effect.go rename {d2common/d2interface => d2core/d2inventory}/inventory_item.go (96%) rename {d2common => d2core/d2render}/composite_mode.go (98%) rename {d2common => d2core/d2render}/filter.go (95%) rename {d2common/d2interface => d2core/d2render}/renderer.go (50%) rename {d2common => d2core/d2render}/surface.go (96%) diff --git a/d2common/d2interface/audio_provider.go b/d2common/d2interface/audio_provider.go deleted file mode 100644 index 98f16e19..00000000 --- a/d2common/d2interface/audio_provider.go +++ /dev/null @@ -1,7 +0,0 @@ -package d2interface - -type AudioProvider interface { - PlayBGM(song string) - LoadSoundEffect(sfx string) (SoundEffect, error) - SetVolumes(bgmVolume, sfxVolume float64) -} diff --git a/d2common/d2interface/sound_effect.go b/d2common/d2interface/sound_effect.go deleted file mode 100644 index 343a67aa..00000000 --- a/d2common/d2interface/sound_effect.go +++ /dev/null @@ -1,6 +0,0 @@ -package d2interface - -type SoundEffect interface { - Play() - Stop() -} diff --git a/d2core/d2asset/animation.go b/d2core/d2asset/animation.go index 69ba1999..f5a7826b 100644 --- a/d2core/d2asset/animation.go +++ b/d2core/d2asset/animation.go @@ -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 } } diff --git a/d2core/d2asset/composite.go b/d2core/d2asset/composite.go index 77681bad..dee4173b 100644 --- a/d2core/d2asset/composite.go +++ b/d2core/d2asset/composite.go @@ -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 } diff --git a/d2core/d2audio/d2audio.go b/d2core/d2audio/d2audio.go index ba286a53..25732743 100644 --- a/d2core/d2audio/d2audio.go +++ b/d2core/d2audio/d2audio.go @@ -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 } diff --git a/d2core/d2audio/ebiten/ebiten_audio_provider.go b/d2core/d2audio/ebiten/ebiten_audio_provider.go index 270e7cf4..01563174 100644 --- a/d2core/d2audio/ebiten/ebiten_audio_provider.go +++ b/d2core/d2audio/ebiten/ebiten_audio_provider.go @@ -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 } diff --git a/d2common/d2interface/inventory_item.go b/d2core/d2inventory/inventory_item.go similarity index 96% rename from d2common/d2interface/inventory_item.go rename to d2core/d2inventory/inventory_item.go index 8ce67d57..a47a610c 100644 --- a/d2common/d2interface/inventory_item.go +++ b/d2core/d2inventory/inventory_item.go @@ -1,4 +1,4 @@ -package d2interface +package d2inventory import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" diff --git a/d2core/d2map/animated_entity.go b/d2core/d2map/animated_entity.go index 77d40266..ef4bd116 100644 --- a/d2core/d2map/animated_entity.go +++ b/d2core/d2map/animated_entity.go @@ -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), diff --git a/d2core/d2map/engine.go b/d2core/d2map/engine.go index 04888ca8..1796114e 100644 --- a/d2core/d2map/engine.go +++ b/d2core/d2map/engine.go @@ -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) diff --git a/d2core/d2map/hero.go b/d2core/d2map/hero.go index b1890462..712133c8 100644 --- a/d2core/d2map/hero.go +++ b/d2core/d2map/hero.go @@ -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) } diff --git a/d2core/d2map/npc.go b/d2core/d2map/npc.go index 0a397035..713b7e83 100644 --- a/d2core/d2map/npc.go +++ b/d2core/d2map/npc.go @@ -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) } diff --git a/d2core/d2map/region.go b/d2core/d2map/region.go index 2308bd92..4b24409f 100644 --- a/d2core/d2map/region.go +++ b/d2core/d2map/region.go @@ -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) diff --git a/d2common/composite_mode.go b/d2core/d2render/composite_mode.go similarity index 98% rename from d2common/composite_mode.go rename to d2core/d2render/composite_mode.go index 7f481575..15307ff3 100644 --- a/d2common/composite_mode.go +++ b/d2core/d2render/composite_mode.go @@ -1,4 +1,4 @@ -package d2common +package d2render type CompositeMode int diff --git a/d2core/d2render/d2render.go b/d2core/d2render/d2render.go index 6c34a925..1239e38f 100644 --- a/d2core/d2render/d2render.go +++ b/d2core/d2render/d2render.go @@ -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 } diff --git a/d2core/d2render/ebiten/composite_mode_helper.go b/d2core/d2render/ebiten/composite_mode_helper.go index 8db98306..8ff9eb87 100644 --- a/d2core/d2render/ebiten/composite_mode_helper.go +++ b/d2core/d2render/ebiten/composite_mode_helper.go @@ -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 } diff --git a/d2core/d2render/ebiten/ebiten_renderer.go b/d2core/d2render/ebiten/ebiten_renderer.go index 031a84b8..5ffca872 100644 --- a/d2core/d2render/ebiten/ebiten_renderer.go +++ b/d2core/d2render/ebiten/ebiten_renderer.go @@ -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 { diff --git a/d2core/d2render/ebiten/ebiten_surface.go b/d2core/d2render/ebiten/ebiten_surface.go index 3803776d..0373e729 100644 --- a/d2core/d2render/ebiten/ebiten_surface.go +++ b/d2core/d2render/ebiten/ebiten_surface.go @@ -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 diff --git a/d2core/d2render/ebiten/filter_helper.go b/d2core/d2render/ebiten/filter_helper.go index e4a79086..b0d90b1c 100644 --- a/d2core/d2render/ebiten/filter_helper.go +++ b/d2core/d2render/ebiten/filter_helper.go @@ -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 } diff --git a/d2common/filter.go b/d2core/d2render/filter.go similarity index 95% rename from d2common/filter.go rename to d2core/d2render/filter.go index 7a4d5fdb..8693c00f 100644 --- a/d2common/filter.go +++ b/d2core/d2render/filter.go @@ -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 diff --git a/d2common/d2interface/renderer.go b/d2core/d2render/renderer.go similarity index 50% rename from d2common/d2interface/renderer.go rename to d2core/d2render/renderer.go index 097394e7..80b971a6 100644 --- a/d2common/d2interface/renderer.go +++ b/d2core/d2render/renderer.go @@ -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 diff --git a/d2common/surface.go b/d2core/d2render/surface.go similarity index 96% rename from d2common/surface.go rename to d2core/d2render/surface.go index 51bc0df3..d4d84c51 100644 --- a/d2common/surface.go +++ b/d2core/d2render/surface.go @@ -1,4 +1,4 @@ -package d2common +package d2render import ( "image/color" diff --git a/d2core/d2scene/d2scene.go b/d2core/d2scene/d2scene.go index 2fd3c0ab..57f5c21f 100644 --- a/d2core/d2scene/d2scene.go +++ b/d2core/d2scene/d2scene.go @@ -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 } diff --git a/d2core/d2term/d2term.go b/d2core/d2term/d2term.go index 01fc2163..4b618fbb 100644 --- a/d2core/d2term/d2term.go +++ b/d2core/d2term/d2term.go @@ -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 } diff --git a/d2core/d2term/terminal.go b/d2core/d2term/terminal.go index ebb0a211..5a6bbba6 100644 --- a/d2core/d2term/terminal.go +++ b/d2core/d2term/terminal.go @@ -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 } diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index 03c4044f..283cb8d3 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -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) diff --git a/d2core/d2ui/checkbox.go b/d2core/d2ui/checkbox.go index d817c345..0bc26d5e 100644 --- a/d2core/d2ui/checkbox.go +++ b/d2core/d2ui/checkbox.go @@ -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 { diff --git a/d2core/d2ui/d2ui.go b/d2core/d2ui/d2ui.go index bac3a65f..58845ec8 100644 --- a/d2core/d2ui/d2ui.go +++ b/d2core/d2ui/d2ui.go @@ -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) diff --git a/d2core/d2ui/drawable.go b/d2core/d2ui/drawable.go index 06b35931..93c700ab 100644 --- a/d2core/d2ui/drawable.go +++ b/d2core/d2ui/drawable.go @@ -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) diff --git a/d2core/d2ui/font.go b/d2core/d2ui/font.go index d1f17b3c..bc7520f1 100644 --- a/d2core/d2ui/font.go +++ b/d2core/d2ui/font.go @@ -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) diff --git a/d2core/d2ui/label.go b/d2core/d2ui/label.go index b1a8068c..79876941 100644 --- a/d2core/d2ui/label.go +++ b/d2core/d2ui/label.go @@ -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) } diff --git a/d2core/d2ui/scrollbar.go b/d2core/d2ui/scrollbar.go index 89f7a44a..ed13ee18 100644 --- a/d2core/d2ui/scrollbar.go +++ b/d2core/d2ui/scrollbar.go @@ -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 } diff --git a/d2core/d2ui/sprite.go b/d2core/d2ui/sprite.go index 71fc5ccd..e6b68761 100644 --- a/d2core/d2ui/sprite.go +++ b/d2core/d2ui/sprite.go @@ -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 diff --git a/d2core/d2ui/textbox.go b/d2core/d2ui/textbox.go index 5eb7ad08..d10f3e4d 100644 --- a/d2core/d2ui/textbox.go +++ b/d2core/d2ui/textbox.go @@ -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 } diff --git a/d2game/d2game.go b/d2game/d2game.go index 7a21b4b3..6efc06ae 100644 --- a/d2game/d2game.go +++ b/d2game/d2game.go @@ -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 { diff --git a/d2game/d2gamescene/character_select.go b/d2game/d2gamescene/character_select.go index 0e09cd24..93c1a799 100644 --- a/d2game/d2gamescene/character_select.go +++ b/d2game/d2gamescene/character_select.go @@ -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) diff --git a/d2game/d2gamescene/credits.go b/d2game/d2gamescene/credits.go index b114a055..b4232e0f 100644 --- a/d2game/d2gamescene/credits.go +++ b/d2game/d2gamescene/credits.go @@ -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 { diff --git a/d2game/d2gamescene/game.go b/d2game/d2gamescene/game.go index c03158e3..3f0382e2 100644 --- a/d2game/d2gamescene/game.go +++ b/d2game/d2gamescene/game.go @@ -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) diff --git a/d2game/d2gamescene/main_menu.go b/d2game/d2gamescene/main_menu.go index 0eceb0cd..e772412b 100644 --- a/d2game/d2gamescene/main_menu.go +++ b/d2game/d2gamescene/main_menu.go @@ -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 { diff --git a/d2game/d2gamescene/map_engine_testing.go b/d2game/d2gamescene/map_engine_testing.go index e6afe9d6..d420d9c4 100644 --- a/d2game/d2gamescene/map_engine_testing.go +++ b/d2game/d2gamescene/map_engine_testing.go @@ -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() diff --git a/d2game/d2gamescene/select_hero_class.go b/d2game/d2gamescene/select_hero_class.go index aaf8e4f9..1cc27708 100644 --- a/d2game/d2gamescene/select_hero_class.go +++ b/d2game/d2gamescene/select_hero_class.go @@ -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 } diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index f739fe82..3aae4c0d 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -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() diff --git a/d2game/d2player/inventory.go b/d2game/d2player/inventory.go index 9b224c0e..a14f1b1f 100644 --- a/d2game/d2player/inventory.go +++ b/d2game/d2player/inventory.go @@ -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 } diff --git a/d2game/d2player/inventory_grid.go b/d2game/d2player/inventory_grid.go index 63dd8a0a..2c3b234b 100644 --- a/d2game/d2player/inventory_grid.go +++ b/d2game/d2player/inventory_grid.go @@ -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