mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-30 07:06:18 -04:00
fixed all gocognit
lint errors (#848)
* reduced ItemFactory.NewItem complexity * d2compression/wav.go: suppressing gocognit lint error, suppressing gocyclo lint error * d2maprenderer/renderer.go: reducing complexity of rnderPass2 and renderPass3
This commit is contained in:
parent
aa9f6be411
commit
dd0c148784
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
// WavDecompress decompresses wav files
|
// WavDecompress decompresses wav files
|
||||||
//nolint:gomnd // binary decode magic
|
//nolint:gomnd // binary decode magic
|
||||||
func WavDecompress(data []byte, channelCount int) []byte { //nolint:funlen // can't reduce
|
func WavDecompress(data []byte, channelCount int) []byte { //nolint:funlen,gocognit,gocyclo // can't reduce
|
||||||
Array1 := []int{0x2c, 0x2c}
|
Array1 := []int{0x2c, 0x2c}
|
||||||
Array2 := make([]int, channelCount)
|
Array2 := make([]int, channelCount)
|
||||||
|
|
||||||
|
@ -82,11 +82,9 @@ func (f *ItemFactory) SetSeed(seed int64) {
|
|||||||
|
|
||||||
// NewItem creates a new item instance from the given codes
|
// NewItem creates a new item instance from the given codes
|
||||||
func (f *ItemFactory) NewItem(codes ...string) (*Item, error) {
|
func (f *ItemFactory) NewItem(codes ...string) (*Item, error) {
|
||||||
var item *Item
|
|
||||||
|
|
||||||
var common, set, unique string
|
var common, set, unique string
|
||||||
|
|
||||||
var prefixes, suffixes []string
|
prefixes, suffixes := make([]string, 0), make([]string, 0)
|
||||||
|
|
||||||
for _, code := range codes {
|
for _, code := range codes {
|
||||||
if found := f.asset.Records.Item.All[code]; found != nil {
|
if found := f.asset.Records.Item.All[code]; found != nil {
|
||||||
@ -105,28 +103,24 @@ func (f *ItemFactory) NewItem(codes ...string) (*Item, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if found := f.asset.Records.Item.Magic.Prefix[code]; found != nil {
|
if found := f.asset.Records.Item.Magic.Prefix[code]; found != nil {
|
||||||
if prefixes == nil {
|
|
||||||
prefixes = make([]string, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
prefixes = append(prefixes, code)
|
prefixes = append(prefixes, code)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if found := f.asset.Records.Item.Magic.Suffix[code]; found != nil {
|
if found := f.asset.Records.Item.Magic.Suffix[code]; found != nil {
|
||||||
if suffixes == nil {
|
|
||||||
suffixes = make([]string, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
suffixes = append(suffixes, code)
|
suffixes = append(suffixes, code)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if common != "" { // we will at least have a regular item
|
if common == "" {
|
||||||
item = &Item{CommonCode: common}
|
return nil, errors.New("cannot create item")
|
||||||
|
}
|
||||||
|
|
||||||
|
item := &Item{
|
||||||
|
factory: f,
|
||||||
|
CommonCode: common,
|
||||||
|
}
|
||||||
|
|
||||||
if set != "" { // it's a set item
|
if set != "" { // it's a set item
|
||||||
item.SetItemCode = set
|
item.SetItemCode = set
|
||||||
@ -138,26 +132,17 @@ func (f *ItemFactory) NewItem(codes ...string) (*Item, error) {
|
|||||||
return item.init(), nil
|
return item.init(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if prefixes != nil {
|
if len(prefixes) > 0 {
|
||||||
if len(prefixes) > 0 { // it's a magic or rare item
|
|
||||||
item.PrefixCodes = prefixes
|
item.PrefixCodes = prefixes
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if suffixes != nil {
|
if len(suffixes) > 0 {
|
||||||
if len(suffixes) > 0 { // it's a magic or rare item
|
|
||||||
item.SuffixCodes = suffixes
|
item.SuffixCodes = suffixes
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
item.factory = f
|
|
||||||
|
|
||||||
return item.init(), nil
|
return item.init(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("cannot create item")
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewProperty creates a property
|
// NewProperty creates a property
|
||||||
func (f *ItemFactory) NewProperty(code string, values ...int) *Property {
|
func (f *ItemFactory) NewProperty(code string, values ...int) *Property {
|
||||||
record := f.asset.Records.Properties[code]
|
record := f.asset.Records.Properties[code]
|
||||||
|
@ -206,7 +206,30 @@ func (mr *MapRenderer) renderPass2(target d2interface.Surface, startX, startY, e
|
|||||||
for tileX := startX; tileX < endX; tileX++ {
|
for tileX := startX; tileX < endX; tileX++ {
|
||||||
mr.viewport.PushTranslationWorld(float64(tileX), float64(tileY))
|
mr.viewport.PushTranslationWorld(float64(tileX), float64(tileY))
|
||||||
|
|
||||||
tileEnt := make([]d2interface.MapEntity, 0)
|
tileEnt := mr.getEntitiesBelowWalls(tileX, tileY)
|
||||||
|
|
||||||
|
for subY := 0; subY < 5; subY++ {
|
||||||
|
for subX := 0; subX < 5; subX++ {
|
||||||
|
for _, mapEntity := range tileEnt {
|
||||||
|
pos := mapEntity.GetPosition()
|
||||||
|
if (int(pos.SubTileOffset().X()) != subX) || (int(pos.SubTileOffset().Y()) != subY) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
target.PushTranslation(mr.viewport.GetTranslationScreen())
|
||||||
|
mapEntity.Render(target)
|
||||||
|
target.Pop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mr.viewport.PopTranslation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mr *MapRenderer) getEntitiesBelowWalls(tileX, tileY int) []d2interface.MapEntity {
|
||||||
|
entities := make([]d2interface.MapEntity, 0)
|
||||||
|
|
||||||
// need to add render culling
|
// need to add render culling
|
||||||
// https://github.com/OpenDiablo2/OpenDiablo2/issues/821
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/821
|
||||||
@ -223,27 +246,10 @@ func (mr *MapRenderer) renderPass2(target d2interface.Surface, startX, startY, e
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
tileEnt = append(tileEnt, mapEntity)
|
entities = append(entities, mapEntity)
|
||||||
}
|
}
|
||||||
|
|
||||||
for subY := 0; subY < 5; subY++ {
|
return entities
|
||||||
for subX := 0; subX < 5; subX++ {
|
|
||||||
for _, mapEntity := range tileEnt {
|
|
||||||
pos := mapEntity.GetPosition()
|
|
||||||
if (int(pos.SubTileOffset().X()) != subX) || (int(pos.SubTileOffset().Y()) != subY) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
target.PushTranslation(mr.viewport.GetTranslationScreen())
|
|
||||||
mapEntity.Render(target)
|
|
||||||
target.Pop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mr.viewport.PopTranslation()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upper wall tiles and entities above walls.
|
// Upper wall tiles and entities above walls.
|
||||||
@ -254,36 +260,18 @@ func (mr *MapRenderer) renderPass3(target d2interface.Surface, startX, startY, e
|
|||||||
mr.viewport.PushTranslationWorld(float64(tileX), float64(tileY))
|
mr.viewport.PushTranslationWorld(float64(tileX), float64(tileY))
|
||||||
mr.renderTilePass2(tile, target)
|
mr.renderTilePass2(tile, target)
|
||||||
|
|
||||||
tileEnt := make([]d2interface.MapEntity, 0)
|
entities := mr.getEntitiesAboveWalls(tileX, tileY)
|
||||||
|
|
||||||
// need to add render culling
|
|
||||||
// https://github.com/OpenDiablo2/OpenDiablo2/issues/821
|
|
||||||
for _, mapEntity := range mr.mapEngine.Entities() {
|
|
||||||
pos := mapEntity.GetPosition()
|
|
||||||
vec := pos.World()
|
|
||||||
entityX, entityY := vec.X(), vec.Y()
|
|
||||||
|
|
||||||
if mapEntity.GetLayer() == 1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if (int(entityX) != tileX) || (int(entityY) != tileY) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
tileEnt = append(tileEnt, mapEntity)
|
|
||||||
}
|
|
||||||
|
|
||||||
for subY := 0; subY < 5; subY++ {
|
for subY := 0; subY < 5; subY++ {
|
||||||
for subX := 0; subX < 5; subX++ {
|
for subX := 0; subX < 5; subX++ {
|
||||||
for _, mapEntity := range tileEnt {
|
for _, entity := range entities {
|
||||||
pos := mapEntity.GetPosition()
|
pos := entity.GetPosition()
|
||||||
if (int(pos.SubTileOffset().X()) != subX) || (int(pos.SubTileOffset().Y()) != subY) {
|
if (int(pos.SubTileOffset().X()) != subX) || (int(pos.SubTileOffset().Y()) != subY) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
target.PushTranslation(mr.viewport.GetTranslationScreen())
|
target.PushTranslation(mr.viewport.GetTranslationScreen())
|
||||||
mapEntity.Render(target)
|
entity.Render(target)
|
||||||
target.Pop()
|
target.Pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,6 +282,30 @@ func (mr *MapRenderer) renderPass3(target d2interface.Surface, startX, startY, e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mr *MapRenderer) getEntitiesAboveWalls(tileX, tileY int) []d2interface.MapEntity {
|
||||||
|
entities := make([]d2interface.MapEntity, 0)
|
||||||
|
|
||||||
|
// need to add render culling
|
||||||
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/821
|
||||||
|
for _, mapEntity := range mr.mapEngine.Entities() {
|
||||||
|
pos := mapEntity.GetPosition()
|
||||||
|
vec := pos.World()
|
||||||
|
entityX, entityY := vec.X(), vec.Y()
|
||||||
|
|
||||||
|
if mapEntity.GetLayer() != 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (int(entityX) != tileX) || (int(entityY) != tileY) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
entities = append(entities, mapEntity)
|
||||||
|
}
|
||||||
|
|
||||||
|
return entities
|
||||||
|
}
|
||||||
|
|
||||||
// Roof tiles.
|
// Roof tiles.
|
||||||
func (mr *MapRenderer) renderPass4(target d2interface.Surface, startX, startY, endX, endY int) {
|
func (mr *MapRenderer) renderPass4(target d2interface.Surface, startX, startY, endX, endY int) {
|
||||||
for tileY := startY; tileY < endY; tileY++ {
|
for tileY := startY; tileY < endY; tileY++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user