Skip to content

refactor: major refactor of dc6 package#1

Open
gucio321 wants to merge 10 commits into
OpenDiablo2:mainfrom
gucio321:main
Open

refactor: major refactor of dc6 package#1
gucio321 wants to merge 10 commits into
OpenDiablo2:mainfrom
gucio321:main

Conversation

@gucio321

@gucio321 gucio321 commented Aug 19, 2021

Copy link
Copy Markdown

Hi,
some time ago I attempted to refactor d2dc6 package (see https://github.com/gucio321/d2dc6).
In this PR i'm merging the changes, I did.
changelog:

  • add readme
  • add docs dir
  • merge gucio321/d2dc6 refactors
    • split main package into two smaller (extract dc6Frames pkg)
    • put appropriate parts of decoder in a new frames package
    • remove unnecessary fields from both structures (dc6 and dc6Frame)
    • TODO: add encoder (need to rewrite to use gravestench/bitstream)

I hope, that these changes will make the code faster and cleaner.

Comment thread README.md Outdated
Comment thread cmd/dc6-view/main.go Outdated
Comment thread doc.go
Comment on lines -1 to -2
// Package dc6 provides a DC6 animation decoder, used by diablo 2.
package dc6

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we delete this file, then?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure. I suppose that if there are no go package in main dir, this file isn't necessary.
It could be inside of pkg dir

Comment thread pkg/dc6.go
Directions []*Direction
palette color.Palette
}
Termination [terminationSize]byte

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these termination bytes are also artifacts of the encoding, and likely not needed in the decoded struct.

@gucio321 gucio321 Aug 20, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is, that this value isn't the same in certain dc6 files.
from documentation, we can see, that:

 UBYTE termination[4]; // EE EE EE EE or CD CD CD CD 

and it may be of importance for d2 game

Comment thread pkg/dc6.go Outdated
Comment thread pkg/dc6.go

for dir := 0; dir < d.Frames.NumberOfDirections(); dir++ {
for f := 0; f < d.Frames.FramesPerDirection(); f++ {
err = d.Frames.Direction(dir).Frame(f).Load(r, &d.palette)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this.

Why would you need to pass the palette in?

Why is the palette a data member of each frame?

The DC6 should only have a single palette, and the frames should not need a palette to be loaded...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note that it is a pointer to the palette used by dc6, not palette itself.

Maybe the better solution is to add (*Frame).Palette method to set it?

Comment thread pkg/frames/doc.go
Comment thread pkg/frames/frame.go Outdated
Comment thread pkg/frames/frame.go
palette *color.Palette

FrameData []byte
Terminator []byte

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an artifact of the encoding, we don't need to store the termination bytes.

@gucio321

Copy link
Copy Markdown
Author

@gravestench thanks for your reviews! just fixed most of them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants