From 68c55b41d06125d719a298d023e939ca2d80be2f Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Tue, 5 Nov 2019 23:00:44 -0500 Subject: [PATCH] Added animation data loading and fix build error (#91) * Fixed LevelTypes load * Update ResourcePaths.go * Added DCC loading support * Added animation data. Fixed bitshift version compile issue. --- Common/AnimationData.go | 41 +++++++++++++++++++++++++++++++++++++++++ Common/BitMuncher.go | 10 +++++----- Core/Engine.go | 1 + 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 Common/AnimationData.go diff --git a/Common/AnimationData.go b/Common/AnimationData.go new file mode 100644 index 00000000..554751a0 --- /dev/null +++ b/Common/AnimationData.go @@ -0,0 +1,41 @@ +package Common + +import ( + "log" + "strings" + + "github.com/OpenDiablo2/OpenDiablo2/ResourcePaths" +) + +type AnimationDataRecord struct { + COFName string + FramesPerDirection int + AnimationSpeed int + Flags []byte +} + +var AnimationData map[string][]*AnimationDataRecord + +func LoadAnimationData(fileProvider FileProvider) { + AnimationData = make(map[string][]*AnimationDataRecord) + rawData := fileProvider.LoadFile(ResourcePaths.AnimationData) + streamReader := CreateStreamReader(rawData) + for !streamReader.Eof() { + dataCount := int(streamReader.GetInt32()) + for i := 0; i < dataCount; i++ { + cofNameBytes, _ := streamReader.ReadBytes(8) + data := &AnimationDataRecord{ + COFName: strings.ReplaceAll(string(cofNameBytes), string(0), ""), + FramesPerDirection: int(streamReader.GetInt32()), + AnimationSpeed: int(streamReader.GetInt32()), + } + data.Flags, _ = streamReader.ReadBytes(144) + cofIndex := strings.ToLower(data.COFName) + if _, found := AnimationData[cofIndex]; !found { + AnimationData[cofIndex] = make([]*AnimationDataRecord, 0) + } + AnimationData[cofIndex] = append(AnimationData[cofIndex], data) + } + } + log.Printf("Loaded %d animation data records", len(AnimationData)) +} diff --git a/Common/BitMuncher.go b/Common/BitMuncher.go index 1ef77d40..f7f0c172 100644 --- a/Common/BitMuncher.go +++ b/Common/BitMuncher.go @@ -23,7 +23,7 @@ func CopyBitMuncher(source *BitMuncher) *BitMuncher { } func (v *BitMuncher) GetBit() uint32 { - result := uint32(v.data[v.Offset/8]>>(v.Offset%8)) & 0x01 + result := uint32(v.data[v.Offset/8]>>uint(v.Offset%8)) & 0x01 v.Offset++ v.BitsRead++ return result @@ -51,7 +51,7 @@ func (v *BitMuncher) GetBits(bits int) uint32 { } result := uint32(0) for i := 0; i < bits; i++ { - result |= v.GetBit() << i + result |= v.GetBit() << uint(i) } return result } @@ -68,14 +68,14 @@ func (v *BitMuncher) MakeSigned(value uint32, bits int) int32 { return -int32(value) } // If there is no sign bit, return the value as is - if (value & (1 << (bits - 1))) == 0 { + if (value & (1 << uint(bits-1))) == 0 { return int32(value) } // We need to extend the signed bit out so that the negative value representation still works with the 2s compliment rule. result := uint32(4294967295) for i := byte(0); i < byte(bits); i++ { - if ((value >> i) & 1) == 0 { - result -= uint32(1 << i) + if ((value >> uint(i)) & 1) == 0 { + result -= uint32(1 << uint(i)) } } return int32(result) // Force casting to a signed value diff --git a/Core/Engine.go b/Core/Engine.go index 4b810ca2..b7c6f45b 100644 --- a/Core/Engine.go +++ b/Core/Engine.go @@ -75,6 +75,7 @@ func CreateEngine() *Engine { Common.LoadMissiles(result) Common.LoadSounds(result) Common.LoadObjectLookups() + Common.LoadAnimationData(result) result.SoundManager = Sound.CreateManager(result) result.SoundManager.SetVolumes(result.Settings.BgmVolume, result.Settings.SfxVolume) result.UIManager = UI.CreateManager(result, *result.SoundManager)