1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-04 15:00:42 +00:00

replaced nolint:gomnd directives with "magic numbers'" names

This commit is contained in:
M. Sz 2021-02-06 18:28:01 +01:00
parent ac8794015e
commit 32570d6ae5
3 changed files with 65 additions and 32 deletions

View File

@ -27,6 +27,13 @@ const (
v18 = 18
)
const (
wallZeroBitmask = 0xFFFFFF00
wallZeroOffset = 8
wallTypeBitmask = 0x000000FF
)
// DS1 represents the "stamp" data that is used to build up maps.
type DS1 struct {
Files []string // FilePtr table of file string pointers
@ -452,11 +459,11 @@ func (ds1 *DS1) loadLayerStreams(br *d2datautils.StreamReader) error {
switch layerStreamType {
case d2enum.LayerStreamWall1, d2enum.LayerStreamWall2, d2enum.LayerStreamWall3, d2enum.LayerStreamWall4:
wallIndex := int(layerStreamType) - int(d2enum.LayerStreamWall1)
ds1.Tiles[y][x].Walls[wallIndex].Decode(dw) //nolint:gomnd // Bitmask
ds1.Tiles[y][x].Walls[wallIndex].Decode(dw)
case d2enum.LayerStreamOrientation1, d2enum.LayerStreamOrientation2,
d2enum.LayerStreamOrientation3, d2enum.LayerStreamOrientation4:
wallIndex := int(layerStreamType) - int(d2enum.LayerStreamOrientation1)
c := int32(dw & 0x000000FF) //nolint:gomnd // Bitmask
c := int32(dw & wallTypeBitmask)
if ds1.Version < v7 {
if c < int32(len(dirLookup)) {
@ -465,7 +472,7 @@ func (ds1 *DS1) loadLayerStreams(br *d2datautils.StreamReader) error {
}
ds1.Tiles[y][x].Walls[wallIndex].Type = d2enum.TileType(c)
ds1.Tiles[y][x].Walls[wallIndex].Zero = byte((dw & 0xFFFFFF00) >> 8) //nolint:gomnd // Bitmask
ds1.Tiles[y][x].Walls[wallIndex].Zero = byte((dw & wallZeroBitmask) >> wallZeroOffset)
case d2enum.LayerStreamFloor1, d2enum.LayerStreamFloor2:
floorIndex := int(layerStreamType) - int(d2enum.LayerStreamFloor1)
ds1.Tiles[y][x].Floors[floorIndex].Decode(dw)
@ -575,7 +582,7 @@ func (ds1 *DS1) encodeLayers(sw *d2datautils.StreamWriter) {
d2enum.LayerStreamOrientation3, d2enum.LayerStreamOrientation4:
wallIndex := int(layerStreamType) - int(d2enum.LayerStreamOrientation1)
dw |= uint32(ds1.Tiles[y][x].Walls[wallIndex].Type)
dw |= (uint32(ds1.Tiles[y][x].Walls[wallIndex].Zero) & 0xFFFFFF00) << 8 //nolint:gomnd // Bitmask
dw |= (uint32(ds1.Tiles[y][x].Walls[wallIndex].Zero) & wallZeroBitmask) << wallZeroOffset
sw.PushUint32(dw)
case d2enum.LayerStreamFloor1, d2enum.LayerStreamFloor2:

View File

@ -4,6 +4,32 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils"
)
const (
prop1Bitmask = 0x000000FF
prop1Offset = 0
prop1Length = 8
sequenceBitmask = 0x00003F00
sequenceOffset = 8
sequenceLength = 6
unknown1Bitmask = 0x000FC000
unknown1Offset = 14
unknown1Length = 6
styleBitmask = 0x03F00000
styleOffset = 20
styleLength = 6
unknown2Bitmask = 0x7C000000
unknown2Offset = 26
unknown2Length = 5
hiddenBitmask = 0x80000000
hiddenOffset = 31
hiddenLength = 1
)
// FloorShadowRecord represents a floor or shadow record in a DS1 file.
type FloorShadowRecord struct {
Prop1 byte
@ -24,20 +50,20 @@ func (f *FloorShadowRecord) Hidden() bool {
// Decode decodes floor-shadow record
func (f *FloorShadowRecord) Decode(dw uint32) {
f.Prop1 = byte(dw & 0x000000FF) //nolint:gomnd // Bitmask
f.Sequence = byte((dw & 0x00003F00) >> 8) //nolint:gomnd // Bitmask
f.Unknown1 = byte((dw & 0x000FC000) >> 14) //nolint:gomnd // Bitmask
f.Style = byte((dw & 0x03F00000) >> 20) //nolint:gomnd // Bitmask
f.Unknown2 = byte((dw & 0x7C000000) >> 26) //nolint:gomnd // Bitmask
f.hidden = byte((dw & 0x80000000) >> 31) //nolint:gomnd // Bitmask
f.Prop1 = byte((dw & prop1Bitmask) >> prop1Offset)
f.Sequence = byte((dw & sequenceBitmask) >> sequenceOffset)
f.Unknown1 = byte((dw & unknown1Bitmask) >> unknown1Offset)
f.Style = byte((dw & styleBitmask) >> styleOffset)
f.Unknown2 = byte((dw & unknown2Bitmask) >> unknown2Offset)
f.hidden = byte((dw & hiddenBitmask) >> hiddenOffset)
}
// Encode adds Floor's bits to stream writter given
func (f *FloorShadowRecord) Encode(sw *d2datautils.StreamWriter) {
sw.PushBits32(uint32(f.Prop1), 8)
sw.PushBits32(uint32(f.Sequence), 6)
sw.PushBits32(uint32(f.Unknown1), 6)
sw.PushBits32(uint32(f.Style), 6)
sw.PushBits32(uint32(f.Unknown2), 5)
sw.PushBits32(uint32(f.hidden), 1)
sw.PushBits32(uint32(f.Prop1), prop1Length)
sw.PushBits32(uint32(f.Sequence), sequenceLength)
sw.PushBits32(uint32(f.Unknown1), unknown1Length)
sw.PushBits32(uint32(f.Style), styleLength)
sw.PushBits32(uint32(f.Unknown2), unknown2Length)
sw.PushBits32(uint32(f.hidden), hiddenLength)
}

View File

@ -24,22 +24,22 @@ func (w *WallRecord) Hidden() bool {
return w.hidden > 0
}
// Encode adds wall's record's bytes into stream writer given
func (w *WallRecord) Encode(sw *d2datautils.StreamWriter) {
sw.PushBits32(uint32(w.Prop1), 8)
sw.PushBits32(uint32(w.Sequence), 6)
sw.PushBits32(uint32(w.Unknown1), 6)
sw.PushBits32(uint32(w.Style), 6)
sw.PushBits32(uint32(w.Unknown2), 5)
sw.PushBits32(uint32(w.hidden), 1)
}
// Decode decodes wall record
func (w *WallRecord) Decode(dw uint32) {
w.Prop1 = byte(dw & 0x000000FF) //nolint:gomnd // Bitmask
w.Sequence = byte((dw & 0x00003F00) >> 8) //nolint:gomnd // Bitmask
w.Unknown1 = byte((dw & 0x000FC000) >> 14) //nolint:gomnd // Bitmask
w.Style = byte((dw & 0x03F00000) >> 20) //nolint:gomnd // Bitmask
w.Unknown2 = byte((dw & 0x7C000000) >> 26) //nolint:gomnd // Bitmask
w.hidden = byte((dw & 0x80000000) >> 31) //nolint:gomnd // Bitmask
w.Prop1 = byte((dw & prop1Bitmask) >> prop1Offset)
w.Sequence = byte((dw & sequenceBitmask) >> sequenceOffset)
w.Unknown1 = byte((dw & unknown1Bitmask) >> unknown1Offset)
w.Style = byte((dw & styleBitmask) >> styleOffset)
w.Unknown2 = byte((dw & unknown2Bitmask) >> unknown2Offset)
w.hidden = byte((dw & hiddenBitmask) >> hiddenOffset)
}
// Encode adds wall's record's bytes into stream writer given
func (w *WallRecord) Encode(sw *d2datautils.StreamWriter) {
sw.PushBits32(uint32(w.Prop1), prop1Length)
sw.PushBits32(uint32(w.Sequence), sequenceLength)
sw.PushBits32(uint32(w.Unknown1), unknown1Length)
sw.PushBits32(uint32(w.Style), styleLength)
sw.PushBits32(uint32(w.Unknown2), unknown2Length)
sw.PushBits32(uint32(w.hidden), hiddenLength)
}