Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NavMesh.ToWriter() in case you don't need a navmesh file #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

blownengine
Copy link

No description provided.

@blownengine blownengine marked this pull request as ready for review February 5, 2024 11:00
Copy link
Owner

@arl arl left a comment

Choose a reason for hiding this comment

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

Thank you for doing that and sorry for the delay
Please see comments

}

// ToWriter writes binary navigation mesh to io.Writer.
func (m *NavMesh) ToWriter(w io.Writer) error {
Copy link
Owner

Choose a reason for hiding this comment

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

Good idea. It would be even better if the function was called WriteTo and had the following signature:

WriteTo(w Writer) (n int64, err error)

since that would make NavMesh implement the io.WriterTo interface.

Comment on lines +180 to +199
// Returns binary navigation mesh file size.
func (m *NavMesh) Size() int32 {
var header navMeshSetHeader
header.Params = m.Params
hSize := header.Size()

var tilesSize int32 = 0
var tileHeader navMeshTileHeader
for i := int32(0); i < m.MaxTiles; i++ {
tile := &m.Tiles[i]
if tile.DataSize == 0 {
continue
}

tilesSize += int32(tileHeader.Size()) + tile.DataSize
}

return int32(hSize) + tilesSize
}

Copy link
Owner

Choose a reason for hiding this comment

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

What's the use case for that method?
By using the WriteTo method (with the new signature), one also obtains the final file size.
If you're not interested by the data, but just by its size, you could something like

var navMesh *NavMesh
n, err := navMesh.WriteTo(io.discard)
if err {...}
fmt.Println("nav mesh file size:", n)

Let me know if that works for you.

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