-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
// 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 | ||
} | ||
|
There was a problem hiding this comment.
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.
No description provided.