1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-31 16:27:18 -04:00

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.
This commit is contained in:
Tim Sarbin 2019-11-05 23:00:44 -05:00 committed by GitHub
parent 26a9d1e8b1
commit 68c55b41d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 5 deletions

41
Common/AnimationData.go Normal file
View File

@ -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))
}

View File

@ -23,7 +23,7 @@ func CopyBitMuncher(source *BitMuncher) *BitMuncher {
} }
func (v *BitMuncher) GetBit() uint32 { 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.Offset++
v.BitsRead++ v.BitsRead++
return result return result
@ -51,7 +51,7 @@ func (v *BitMuncher) GetBits(bits int) uint32 {
} }
result := uint32(0) result := uint32(0)
for i := 0; i < bits; i++ { for i := 0; i < bits; i++ {
result |= v.GetBit() << i result |= v.GetBit() << uint(i)
} }
return result return result
} }
@ -68,14 +68,14 @@ func (v *BitMuncher) MakeSigned(value uint32, bits int) int32 {
return -int32(value) return -int32(value)
} }
// If there is no sign bit, return the value as is // 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) return int32(value)
} }
// We need to extend the signed bit out so that the negative value representation still works with the 2s compliment rule. // We need to extend the signed bit out so that the negative value representation still works with the 2s compliment rule.
result := uint32(4294967295) result := uint32(4294967295)
for i := byte(0); i < byte(bits); i++ { for i := byte(0); i < byte(bits); i++ {
if ((value >> i) & 1) == 0 { if ((value >> uint(i)) & 1) == 0 {
result -= uint32(1 << i) result -= uint32(1 << uint(i))
} }
} }
return int32(result) // Force casting to a signed value return int32(result) // Force casting to a signed value

View File

@ -75,6 +75,7 @@ func CreateEngine() *Engine {
Common.LoadMissiles(result) Common.LoadMissiles(result)
Common.LoadSounds(result) Common.LoadSounds(result)
Common.LoadObjectLookups() Common.LoadObjectLookups()
Common.LoadAnimationData(result)
result.SoundManager = Sound.CreateManager(result) result.SoundManager = Sound.CreateManager(result)
result.SoundManager.SetVolumes(result.Settings.BgmVolume, result.Settings.SfxVolume) result.SoundManager.SetVolumes(result.Settings.BgmVolume, result.Settings.SfxVolume)
result.UIManager = UI.CreateManager(result, *result.SoundManager) result.UIManager = UI.CreateManager(result, *result.SoundManager)