forked from OpenDiablo2/OpenDiablo2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving files around to make more sense (OpenDiablo2#279)
* Prevent input fighting between terminal and other input listeners. * Moving files around, removing exports * Add missing line
- Loading branch information
Showing
49 changed files
with
599 additions
and
704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package d2asset | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/OpenDiablo2/OpenDiablo2/d2common" | ||
) | ||
|
||
const ( | ||
animationBudget = 64 | ||
) | ||
|
||
type animationManager struct { | ||
cache *d2common.Cache | ||
} | ||
|
||
func createAnimationManager() *animationManager { | ||
return &animationManager{d2common.CreateCache(animationBudget)} | ||
} | ||
|
||
func (am *animationManager) loadAnimation(animationPath, palettePath string, transparency int) (*Animation, error) { | ||
cachePath := fmt.Sprintf("%s;%s;%d", animationPath, palettePath, transparency) | ||
if animation, found := am.cache.Retrieve(cachePath); found { | ||
return animation.(*Animation).Clone(), nil | ||
} | ||
|
||
var animation *Animation | ||
switch strings.ToLower(filepath.Ext(animationPath)) { | ||
case ".dc6": | ||
dc6, err := loadDC6(animationPath, palettePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
animation, err = createAnimationFromDC6(dc6) | ||
if err != nil { | ||
return nil, err | ||
} | ||
case ".dcc": | ||
dcc, err := loadDCC(animationPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
palette, err := loadPalette(palettePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
animation, err = createAnimationFromDCC(dcc, palette, transparency) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
default: | ||
return nil, errors.New("unknown animation format") | ||
} | ||
|
||
if err := am.cache.Insert(cachePath, animation.Clone(), 1); err != nil { | ||
return nil, err | ||
} | ||
|
||
return animation, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package d2asset | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof" | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dc6" | ||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dcc" | ||
) | ||
|
||
var ( | ||
ErrHasInit error = errors.New("asset system is already initialized") | ||
ErrNoInit error = errors.New("asset system is not initialized") | ||
) | ||
|
||
type assetManager struct { | ||
archiveManager *archiveManager | ||
fileManager *fileManager | ||
paletteManager *paletteManager | ||
animationManager *animationManager | ||
} | ||
|
||
func loadPalette(palettePath string) (*d2datadict.PaletteRec, error) { | ||
if singleton == nil { | ||
return nil, ErrNoInit | ||
} | ||
|
||
return singleton.paletteManager.loadPalette(palettePath) | ||
} | ||
|
||
func loadDC6(dc6Path, palettePath string) (*d2dc6.DC6File, error) { | ||
dc6Data, err := LoadFile(dc6Path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
paletteData, err := loadPalette(palettePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dc6, err := d2dc6.LoadDC6(dc6Data, *paletteData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &dc6, nil | ||
} | ||
|
||
func loadDCC(dccPath string) (*d2dcc.DCC, error) { | ||
dccData, err := LoadFile(dccPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return d2dcc.LoadDCC(dccData) | ||
} | ||
|
||
func loadCOF(cofPath string) (*d2cof.COF, error) { | ||
cofData, err := LoadFile(cofPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return d2cof.LoadCOF(cofData) | ||
} |
Oops, something went wrong.