From 0272b593fbc864e4b2b7e13dbc821e05ca7be9be Mon Sep 17 00:00:00 2001 From: Ziemas Date: Wed, 1 Jul 2020 20:02:47 +0200 Subject: [PATCH] Cof direction lookup (#517) Generated these based on the d2dcc direction lookup hopefully they're correct (they seem to be at least) --- .../d2fileformats/d2cof/cof_dir_lookup.go | 49 ++++++++++++++++ .../d2fileformats/d2dcc/dcc_dir_lookup.go | 56 +++++++++---------- d2core/d2asset/composite.go | 18 ++---- 3 files changed, 79 insertions(+), 44 deletions(-) create mode 100644 d2common/d2fileformats/d2cof/cof_dir_lookup.go diff --git a/d2common/d2fileformats/d2cof/cof_dir_lookup.go b/d2common/d2fileformats/d2cof/cof_dir_lookup.go new file mode 100644 index 00000000..5619e09e --- /dev/null +++ b/d2common/d2fileformats/d2cof/cof_dir_lookup.go @@ -0,0 +1,49 @@ +package d2cof + +// Dir64ToCof returns the cof direction based on the actual direction +func Dir64ToCof(direction, numDirections int) int { + var dir4 = [64]int{ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0} + + var dir8 = [64]int{ + 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, + 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, + 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, + 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0} + + var dir16 = [64]int{ + 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, + 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, + 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, + 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 0, 0} + + var dir32 = [64]int{ + 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, + 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, + 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, + 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 0} + + var dir64 = [64]int{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63} + + switch numDirections { + case 4: + return dir4[direction] + case 8: + return dir8[direction] + case 16: + return dir16[direction] + case 32: + return dir32[direction] + case 64: + return dir64[direction] + default: + return 0 + } +} diff --git a/d2common/d2fileformats/d2dcc/dcc_dir_lookup.go b/d2common/d2fileformats/d2dcc/dcc_dir_lookup.go index f2a7d271..6ccd5525 100644 --- a/d2common/d2fileformats/d2dcc/dcc_dir_lookup.go +++ b/d2common/d2fileformats/d2dcc/dcc_dir_lookup.go @@ -3,41 +3,35 @@ package d2dcc // Dir64ToDcc returns the DCC direction based on the actual direction. // Special thanks for Necrolis for these tables! func Dir64ToDcc(direction, numDirections int) int { - var dir4 = []int{0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} + var dir4 = [64]int{ + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0} - var dir8 = []int{0x04, 0x04, 0x04, 0x04, 0x0, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x06, 0x06, 0x06, - 0x06, 0x06, 0x06, 0x06, 0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 0x04} + var dir8 = [64]int{ + 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, + 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, + 6, 6, 6, 6, 2, 2, 2, 2, 2, 2, 2, 2, 7, 7, 7, 7, + 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4} - var dir16 = []int{0x04, 0x04, 0x08, 0x08, 0x8, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x09, 0x09, 0x09, 0x09, 0x05, 0x05, 0x05, 0x05, 0x0A, 0x0A, - 0x0A, 0x0A, 0x01, 0x01, 0x01, 0x01, 0x0B, 0x0B, 0x0B, 0x0B, 0x06, - 0x06, 0x06, 0x06, 0x0C, 0x0C, 0x0C, 0x0C, 0x02, 0x02, 0x02, 0x02, - 0x0D, 0x0D, 0x0D, 0x0D, 0x07, 0x07, 0x07, 0x07, 0x0E, 0x0E, 0x0E, - 0x0E, 0x03, 0x03, 0x03, 0x03, 0x0F, 0x0F, 0x0F, 0x0F, 0x04, 0x04} + var dir16 = [64]int{ + 4, 4, 8, 8, 8, 8, 0, 0, 0, 0, 9, 9, 9, 9, 5, 5, + 5, 5, 10, 10, 10, 10, 1, 1, 1, 1, 11, 11, 11, 11, 6, 6, + 6, 6, 12, 12, 12, 12, 2, 2, 2, 2, 13, 13, 13, 13, 7, 7, + 7, 7, 14, 14, 14, 14, 3, 3, 3, 3, 15, 15, 15, 15, 4, 4} - var dir32 = []int{0x04, 0x10, 0x10, 0x08, 0x8, 0x11, 0x11, 0x00, 0x00, - 0x12, 0x12, 0x09, 0x09, 0x13, 0x13, 0x05, 0x05, 0x14, 0x14, 0x0A, - 0x0A, 0x15, 0x15, 0x01, 0x01, 0x16, 0x16, 0x0B, 0x0B, 0x17, 0x17, - 0x06, 0x06, 0x18, 0x18, 0x0C, 0x0C, 0x19, 0x19, 0x02, 0x02, 0x1A, - 0x1A, 0x0D, 0x0D, 0x1B, 0x1B, 0x07, 0x07, 0x1C, 0x1C, 0x0E, 0x0E, - 0x1D, 0x1D, 0x03, 0x03, 0x1E, 0x1E, 0x0F, 0x0F, 0x1F, 0x1F, 0x04} + var dir32 = [64]int{ + 4, 16, 16, 8, 8, 17, 17, 0, 0, 18, 18, 9, 9, 19, 19, 5, + 5, 20, 20, 10, 10, 21, 21, 1, 1, 22, 22, 11, 11, 23, 23, 6, + 6, 24, 24, 12, 12, 25, 25, 2, 2, 26, 26, 13, 13, 27, 27, 7, + 7, 28, 28, 14, 14, 29, 29, 3, 3, 30, 30, 15, 15, 31, 31, 4} - // 64 direction assets don't actually exist? but here it is anyway. - var dir64 = []int{0x04, 0x20, 0x10, 0x21, 0x8, 0x22, 0x11, 0x23, 0x00, - 0x24, 0x12, 0x25, 0x09, 0x26, 0x13, 0x27, 0x05, 0x28, 0x14, 0x29, - 0x0A, 0x2A, 0x15, 0x2B, 0x01, 0x2C, 0x16, 0x2D, 0x0B, 0x2E, 0x17, - 0x2F, 0x06, 0x30, 0x18, 0x31, 0x0C, 0x32, 0x19, 0x33, 0x02, 0x34, - 0x1A, 0x35, 0x0D, 0x36, 0x1B, 0x37, 0x07, 0x38, 0x1C, 0x39, 0x0E, - 0x3A, 0x1D, 0x3B, 0x03, 0x3C, 0x1E, 0x3D, 0x0F, 0x3E, 0x1F, 0x3F} + var dir64 = [64]int{ + 4, 32, 16, 33, 8, 34, 17, 35, 0, 36, 18, 37, 9, 38, 19, 39, + 5, 40, 20, 41, 10, 42, 21, 43, 1, 44, 22, 45, 11, 46, 23, 47, + 6, 48, 24, 49, 12, 50, 25, 51, 2, 52, 26, 53, 13, 54, 27, 55, + 7, 56, 28, 57, 14, 58, 29, 59, 3, 60, 30, 61, 15, 62, 31, 63} switch numDirections { case 4: diff --git a/d2core/d2asset/composite.go b/d2core/d2asset/composite.go index a3bed613..1d769e3f 100644 --- a/d2core/d2asset/composite.go +++ b/d2core/d2asset/composite.go @@ -3,9 +3,9 @@ package d2asset import ( "errors" "fmt" - "math" "strings" + "github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data" @@ -68,7 +68,7 @@ func (c Composite) GetAnimationMode() string { } func (c *Composite) SetMode(animationMode, weaponClass string, direction int) error { - if c.mode != nil && c.mode.animationMode == animationMode && c.mode.weaponClass == weaponClass && c.mode.direction == direction { + if c.mode != nil && c.mode.animationMode == animationMode && c.mode.weaponClass == weaponClass && c.mode.cofDirection == direction { return nil } @@ -117,7 +117,7 @@ func (c *Composite) ResetPlayedCount() { type compositeMode struct { animationMode string weaponClass string - direction int + cofDirection int directionCount int playedCount int @@ -141,14 +141,6 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int) return nil, err } - // oh god how do i math - offset := (64 / cof.NumberOfDirections) / 2 - entityDirection := int(math.Trunc((float64(direction+offset)-64.0)*(-float64(cof.NumberOfDirections)/-64.0) + float64(cof.NumberOfDirections))) - - if entityDirection >= cof.NumberOfDirections { - entityDirection = 0 - } - animationKey := strings.ToLower(c.object.Token + animationMode + weaponClass) animationData := d2data.AnimationData[animationKey] if len(animationData) == 0 { @@ -158,8 +150,8 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int) mode := &compositeMode{ animationMode: animationMode, weaponClass: weaponClass, - direction: entityDirection, directionCount: cof.NumberOfDirections, + cofDirection: d2cof.Dir64ToCof(direction, cof.NumberOfDirections), layers: make([]*Animation, d2enum.CompositeTypeMax), frameCount: animationData[0].FramesPerDirection, animationSpeed: 1.0 / ((float64(animationData[0].AnimationSpeed) * 25.0) / 256.0), @@ -167,7 +159,7 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int) mode.drawOrder = make([][]d2enum.CompositeType, mode.frameCount) for frame := 0; frame < mode.frameCount; frame++ { - mode.drawOrder[frame] = cof.Priority[mode.direction][frame] + mode.drawOrder[frame] = cof.Priority[mode.cofDirection][frame] } for _, cofLayer := range cof.CofLayers {