mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-01 08:54:20 -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:
parent
26a9d1e8b1
commit
68c55b41d0
41
Common/AnimationData.go
Normal file
41
Common/AnimationData.go
Normal 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))
|
||||
}
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user